Jump to content

Babylon loader variable


3dObject
 Share

Recommended Posts

I have two LoadAssetContainer functions, one for car and one for tire. I want to define a variable between them. my sample codes. 

var car = BABYLON.SceneLoader.LoadAssetContainer("/assets/", "mersedes.obj", scene, function (container) {
    
    var meshes = container.meshes;
  
    var materials = container.materials;
  
  container.addAllToScene();
 
});

 

var tire = BABYLON.SceneLoader.LoadAssetContainer("/assets/", "teker.obj", scene, function (container) {
  var meshes = container.meshes;
  var materials = container.materials;
  meshes[5].position.set(0.15,-0.035,-0.3);
  meshes[0].position.set(0.15,-0.035,-0.3);

  
  var onSolTecer = meshes[5].clone("onSol");
  var onSolDisq = meshes[0].clone("onSol");
  onSolTecer.position.x = -0.15;
  onSolDisq.position.x = -0.15;
  
  var deggre = Math.PI;
  onSolTecer.rotation = new BABYLON.Vector3(0, deggre, 0);
  onSolDisq.rotation = new BABYLON.Vector3(0, deggre, 0);
  
    
    
  window.addEventListener("keydown", function(event) {
  if(event.keyCode === 68){
    arxaSagTeker.rotation = new BABYLON.Vector3(0, 0.3 , 0);
    arxaSagDisq.rotation = new BABYLON.Vector3(0, 0.3, 0);
    arxaSolTeker.rotation = new BABYLON.Vector3(0, deggre + 0.3, 0);
    arxaSolDisk.rotation = new BABYLON.Vector3(0, deggre + 0.3, 0);
  }
  
  if(event.keyCode === 65){
    arxaSagTeker.rotation = new BABYLON.Vector3(0, -0.3 , 0);
    arxaSagDisq.rotation = new BABYLON.Vector3(0, -0.3, 0);
    arxaSolTeker.rotation = new BABYLON.Vector3(0, deggre - 0.3, 0);
    arxaSolDisk.rotation = new BABYLON.Vector3(0, deggre - 0.3, 0);
  }
});

window.addEventListener("keyup", function(event) {
  if(event.keyCode === 68){
    arxaSagTeker.rotation = new BABYLON.Vector3(0, 0 , 0);
    arxaSagDisq.rotation = new BABYLON.Vector3(0, 0, 0);
    arxaSolTeker.rotation = new BABYLON.Vector3(0, deggre , 0);
    arxaSolDisk.rotation = new BABYLON.Vector3(0, deggre, 0);
  }
  
  if(event.keyCode === 65){
    arxaSagTeker.rotation = new BABYLON.Vector3(0, 0 , 0);
    arxaSagDisq.rotation = new BABYLON.Vector3(0, 0, 0);
    arxaSolTeker.rotation = new BABYLON.Vector3(0, deggre , 0);
    arxaSolDisk.rotation = new BABYLON.Vector3(0, deggre, 0);
  }
});
  
  var arxaSagTeker = meshes[5].clone("onSagTeker");
  var arxaSagDisq = meshes[0].clone("onSagTeker");
  arxaSagTeker.position.z = 0.24;
  arxaSagDisq.position.z = 0.24;
  
  
  var arxaSolTeker = arxaSagTeker.clone("arxaSolTeker");
  var arxaSolDisk = arxaSagDisq.clone("arxaSolDisk");
  arxaSolTeker.position.x = -0.15;
  arxaSolDisk.position.x = -0.15;
  arxaSolTeker.rotation = new BABYLON.Vector3(0, deggre , 0);
  arxaSolDisk.rotation = new BABYLON.Vector3(0, deggre, 0);
  
  
  scene.registerAfterRender(function () {
     meshes[5].rotate(BABYLON.Axis.X, Math.PI / 150, BABYLON.Space.LOCAL);
     meshes[0].rotate(BABYLON.Axis.X, Math.PI / 150, BABYLON.Space.LOCAL);
     
     onSolTecer.rotate(BABYLON.Axis.X, -Math.PI / 150, BABYLON.Space.LOCAL);
     onSolDisq.rotate(BABYLON.Axis.X, -Math.PI / 150, BABYLON.Space.LOCAL);
     
     arxaSolTeker.rotate(BABYLON.Axis.X, -Math.PI / 150, BABYLON.Space.LOCAL);
     arxaSolDisk.rotate(BABYLON.Axis.X, -Math.PI / 150, BABYLON.Space.LOCAL);
     
     arxaSagTeker.rotate(BABYLON.Axis.X, Math.PI / 150, BABYLON.Space.LOCAL);
     arxaSagDisq.rotate(BABYLON.Axis.X, Math.PI / 150, BABYLON.Space.LOCAL);
    
  })
  

  container.addAllToScene();
  
});

I tried so many ways but none of them worked

In my 2nd problem this

tire.parent = car;

I could not assign this to the changed one

console.log(car);

an empty object returns

How can I define that

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...