wexing Posted September 7, 2017 Share Posted September 7, 2017 Hey(sorry for bad english), i started learning babylon framework few days ago and encountered one problem. I have some vehicles model from internet, and trying to spin his wheel unsuccessfullly. Wheel is rotating but unfortunately his pivot isn't correct. How shoud i fix that? Here is example: www.baloo.lt. And here is my code(cound't put it on playground becouse of external 3d model): var canvas = document.getElementById('canvas'); var engine = new BABYLON.Engine(canvas, true); engine.enableOfflineSupport = false; // Dont require a manifest file var createScene = function(){ var scene = new BABYLON.Scene(engine); scene.clearColor = new BABYLON.Color3.White(); BABYLON.SceneLoader.ImportMesh("","lamb/","lamborghini-aventador-irridescent-paint.babylon", scene, function(newMeshes) { scene.car = newMeshes[0]; camera.target = scene.car; scene.internalMesh = scene.getMeshByID("FR_Wheel"); scene.registerBeforeRender(function () { scene.internalMesh.rotate (BABYLON.Axis.Z, 0.14, BABYLON.Space.LOCAL); }); //scene.internalMesh.setPivotMatrix(BABYLON.Matrix.Translation(scene.internalMesh.x, scene.internalMesh.y, scene.internalMesh.z)); console.log(scene.internalMesh.position); console.log(scene.internalMesh) }); var camera = new BABYLON.ArcRotateCamera("arcCam", BABYLON.Tools.ToRadians(45), BABYLON.Tools.ToRadians(45), 10.0, BABYLON.Vector3(1, 2, 1),scene); camera.lowerBetaLimit = 0.1; camera.upperBetaLimit = (Math.PI / 2) * 0.99; camera.lowerRadiusLimit = 5; camera.attachControl(canvas, true); var light = new BABYLON.PointLight("pointLight",new BABYLON.Vector3( 0, 0, 0),scene); light.parent = camera; light.diffuse = new BABYLON.Color3(1,1,1); var light2 = new BABYLON.PointLight("pointLight",new BABYLON.Vector3( 0, 10, 0),scene); light.parent = camera; light.diffuse = new BABYLON.Color3(1,1,1); return scene; } var scene = createScene(); engine.runRenderLoop(function(){ scene.render(); }); }); Quote Link to comment Share on other sites More sharing options...
brianzinn Posted September 7, 2017 Share Posted September 7, 2017 Hi, Nice car Without looking at your .babylon file - are you sure 'fr_wheel' is the wheel itself and not a parent of the wheel? Otherwise, have you considered changing, if you use a 3d model program, the center origin/point of the wheel in the model? Quote Link to comment Share on other sites More sharing options...
wexing Posted September 8, 2017 Author Share Posted September 8, 2017 Thank you for reply I think you are right, just dowloaded blender app and checked this model. It seems that wheel have child, but how to reach it on babylon? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted September 8, 2017 Share Posted September 8, 2017 Hi Wexing. After the model is loaded, you can use: var mything = scene.getMeshByName(meshname); The BabylonJS Scene Object has a ton of fun knobs and switches. It might be the beefiest object in all of Babylonia. Quote Link to comment Share on other sites More sharing options...
brianzinn Posted September 8, 2017 Share Posted September 8, 2017 From the Blender screenshot it looks like your center of origin is in the middle of the wheel (I think the red+blue arrows go from your pivot point). Now, looks like you have two meshes with same name and the parent of the wheel has the same name. I think you will have something like "front_wheel_1" or something as the one that you want. did you inspect all the values in your variable "newMeshes" (the .name property should be passed into scene.getMeshByName(..))? 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.