Jump to content

Can't import Blender parent relationship


Carlos R
 Share

Recommended Posts

Greetings to everyone,

I've been using BabylonJs and Blender for a while but a i can't use the parent relationship between a camera and another mesh.

Here is the code:

// Load the .babylon fileBABYLON.SceneLoader.Load("./", "parent2.babylon", engine, function(newScene) {            scene = newScene;            scene.executeWhenReady(function() {                var myCam = scene.activeCamera;                myCam.ellipsoid = new BABYLON.Vector3(1, 1.5, 1);                myCam.checkCollisions = true;                myCam.applyGravity = true;                myCam.attachControl(canvas);                scene.activeCamera = myCam;                var ground = BABYLON.Mesh.CreatePlane("ground", 60.0, scene);                var materialPlan = new BABYLON.StandardMaterial("texturePlane", scene);                materialPlan.diffuseTexture = new BABYLON.Texture("baldosa.jpg", scene);                materialPlan.diffuseTexture.uScale = 5.0;                materialPlan.diffuseTexture.vScale = 5.0;                materialPlan.backFaceCulling = false;                ground.material = materialPlan;                ground.position = new BABYLON.Vector3(0, 0, 0);                ground.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0);                ground.checkCollisions = true;                scene.collisionsEnabled = true;                scene.gravity = new BABYLON.Vector3(0, -9.81, 0);

Here you can see an example: http://192.241.181.27/parent/index2.html

Here you can check all the files: http://192.241.181.27/parent/

 

I also try to use this, but it fails. http://www.html5gamedevs.com/topic/7985-babylonjs-tutorials-learn-by-creating-a-complete-game/?p=49241

Link to comment
Share on other sites

I've been using BabylonJs and Blender for a while but a i can't use the parent relationship between a camera and another mesh.

 

 

Carlos, the "parenting" of objects in Blender does not, as far as I know, get carried over in the .babylon file. But it is quite simple to do that in your script.

 

After the

scene.executeWhenReady(function() {

  Add this code

// Get the Cube and the Camera from the scene filemyCube = scene.getMeshByName("Cube");myCam = scene.getCameraByName("Camera");// parent  the camera to the cubemyCam.parent = myCube;//or parent the cube to the camera// myCube.parent = myCam;

Here is an example: Camera Animation A cube has been animated along a path, and the camera is attached to it.

 

 

I also try to use this, but it fails. http://www.html5game...e-game/?p=49241

 

 

It is working fine - the blue cube is parented to the camera - so its view is constant. The red cube is not parented - so as you rotate the camera its position on screen changes.

 

For a better idea, try changing the line:

camSensor.scaling = new BABYLON.Vector3(.35, .25, .25);

to

camSensor.scaling = new BABYLON.Vector3(.05, .05, .05);

The blue cube is stuck to the camera.

 

Hope that helps, and welcome to the forum :)

 

cheers, gryff :)

Link to comment
Share on other sites

it works when the parent is the box and the child is the camera but no viceversa :/.

 

Carlos, I'm not sure why that should be.  In the example you use above taken from the Temechon thread:

 

I also try to use this, but it fails. http://www.html5game...e-game/?p=49241

 

look at the code again:

  camSensor.parent = myCam;

the cube that is the acting as the "camSensor" has a parent that is the camera.

 

I have another example somewhere set up like that - will look for it and post it.

 

cheers, gryff :)

 

Link to comment
Share on other sites

Carlos, here is an example where all the meshes, including the cube that will act as the camera sensor for mesh intersections, and the camera come from the .babylon file

 

Zone Actions2

 

(Move camera towards a corner - watch the lights turn on and off.)

 

 After the

camSensor = newScene.getMeshByName("Cube");

the cube is scaled and positioned, then parented to the camera.

camSensor.scaling = new BABYLON.Vector3(.05, .05, .05);camSensor.position = new BABYLON.Vector3(0, -0.150, 1);camSensor.parent = myCam;

The cube that will be parented to the camera is just created at 0,0,0 in Blender.

 

Feel free to grab all the files and play with them.

 

cheers, gryff :)

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