2017-07-18 4 views
0

J'ai simple Fichier OBJ avec différents éléments avec ID uniques. Vous devez charger ce modèle dans Babylon.js en réattribuant des matériaux par ces ID.Babylon.js OBJ Loader Affectation de matériaux par ID

OBJ 
| 
|- Head 
|- Body 
|- RightLeg 
|- LeftLeg 
| 
|... 

material1 for Head 
material2 for Body 
... 

Je sais comment le faire dans Three.js, mais pour Babylon.JS je ne trouve pas aucune solution.

similaires au code Three.js:

loader.load(OBJ_URL, function (object) { 

     object.traverse(function (child) { 

      if (child instanceof THREE.Mesh) { 

       if(child.name == "{name}") { assign material } 

      } 

     }); 

}, onProgress, onError); 

Répondre

0

Il devrait être quelque chose comme ça, mais c'est glitch:

obj.onSuccess = function (task) { 

      group = new BABYLON.Mesh.CreateBox("sunglasses", 1E-9, scene); 
      var parts = []; 

      for(var i = 0, l = task.loadedMeshes.length; i < l; i++){ 

       parts.push(task.loadedMeshes[i]); 
       parts[parts.length - 1].material = materials[hierarchy[i].material]; 
       parts[parts.length - 1].parent = group; 

      } 

      group.rotation = modelAdjusment.rotation; 
      group.scaling = modelAdjusment.scaling; 
      group.position = modelAdjusment.position; 

      scene.addMesh(group); 
      group.alphaIndex = 1; 

};