Jump to content

Need help with wheel rotation


wexing
 Share

Recommended Posts

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();
    });
});

 

 

Link to comment
Share on other sites

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(..))?

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...