kaitek666 Posted April 3, 2017 Share Posted April 3, 2017 Hey. Here's my class: var rockraider; // [...] class RockRaider { constructor(xpos,zpos) { var raider; this.xpos = xpos; this.zpos = zpos; /*this.rotation = rotation;*/ raider = loader.addMeshTask("build", "", "CanvasRR0/", "rockraider.obj"); raider.onSuccess = function(t) { t.loadedMeshes.forEach(function(m) { m.position.x = xpos; //-75 m.position.z = zpos; //-50 m.rotation.y = Math.PI/2; //dev m.rotation.x = 0; m.scaling = new BABYLON.Vector3(2,2,2); }); }; this.raider = raider; setTimeout(function() { raider.loadedMeshes.forEach(function(m) { m.material.emissiveColor = new BABYLON.Color3(.1, .1, .1); }); }, 3000); } moveTo() { this.raider.loadedMeshes.forEach(function(m) { m.position.x = 100; }); } } //dev rockraider = new RockRaider(125,200); And here's my question: Why doesn't my model move when I call function rockraider.moveTo();? Instead, only one element of it moves. I used a forEach(). In first case (in above code, under 3000ms timeout) it worked, but in second it didn't. Why? Thanks Kajtek Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 4, 2017 Share Posted April 4, 2017 Hi K. Just a quick look... umm... don't you need 'moveTo()' to be this.moveTo() or maybe this.raider.moveTo()? Not sure. Our 6-mesh 'Dude' is still walking (positioning) okay, but that's a different type of loader and different type of model. You know how it works, Kajtek... put console.log(info) messages EVERYWHERE. Check your loaded meshes, make sure m HAS a .position property for moveTo() to use. Make that NEGATIVE 100... because the model starts at X = +125. Make sure you can SEE the mesh move... by increasing the move-amount. One segment of a mesh... moves when you call moveTo()? Can you please tell us about your rockraider.obj? How many mesh/subMesh? Perhaps share it with us? (thx either way) Sorry, not very helpful, am I? I'm not very experienced with importing. I'll keep thinking. You insert console.log(m) and look at it in your browser f12 dev tools object inspector (by clicking on the word 'object' in the console). (You probably know all this already). Your emissiveColor change at 3000 ms works fine, huh? hmm. kaitek666 1 Quote Link to comment Share on other sites More sharing options...
kaitek666 Posted April 4, 2017 Author Share Posted April 4, 2017 Tried everything, really! The solution I found was to convert .obj to .babylon and import it using SceneLoader.ImportMesh like you did in example above. Thanks for giving me idea to Import mesh instead of giving it to loader Much thanks, @Wingnut!! Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.