Sign in to follow this  
adwilson

mesh1.parent = mesh2. Bug in Babylon.js or have I misunderstood?

Recommended Posts

Hi Babylon.js forum,

 

I've been particularly setback by a problem I haven't been able to solve for the last day. I have created a stage in Blender, exported it to Babylon. I had two objects I wanted to create a compound imposter and I found createCompoundImpostor() at this site: http://blogs.msdn.com/b/eternalcoding/archive/2013/12/19/create-wonderful-interactive-games-for-the-web-using-webgl-and-a-physics-engine-babylon-js-amp-cannon-js.aspx.

 

It says you have to create a hierarchy so I did, using .parent... except it squashed one of the meshes. I wondered if this was something in my export so I started a new test project in Blender and yet it still squashes a mesh, in particular it squashes the child mesh!

 

Here is a section of my test code

var pushers = {	pusher: null,	rod: null};var loaded = false;BABYLON.SceneLoader.ImportMesh("", "", "Stage-Test-4-TEST001.babylon", scene, function (meshes) {		meshes.forEach(function (mesh) {		if (mesh.id === "Slider_Pusher") {			pushers.pusher = mesh;		} else if (mesh.id === "Slider_Test") {			pushers.rod = mesh;		}	});	pushers.rod.parent = pushers.pusher;	var parts = [		{ mesh: pushers.pusher, impostor: BABYLON.PhysicsEngine.BoxImpostor },		{ mesh: pushers.rod, impostor: BABYLON.PhysicsEngine.BoxImpostor }	]	scene.createCompoundImpostor(parts, {		mass: 1,		friction: 0.1,		restitution: 0.1	});	loaded = true;});

And here are two screenshots, first from Blender and then from my browser

 

WbHz4qq.jpg

 

XBITL96.jpg

 

(Ignore the missing faces in pushers.pusher, that's just a stupid problem I encountered making this setup even though all the normals are consistent in Blender)

 

I just cannot figure out what's going on, the only documentation on the entire Internet on this feature is the 2 lines, 1 quoted line and few lines of code from that page! 

 

I'm using Oimo.js but in cannon.js it did the same thing.

 

Is this a library bug or am I just doing it completely wrong? Does anyone have any working examples they could share?

 

I'm in despair and losing faith!! Haha!

 

Cheers guys.

Share this post


Link to post
Share on other sites

Hello, 

 

The position of the children is set relative to the parent.

If the parent position is (1,1,1), and one of its child position is (1,1,1), then the child will appear at position (2,2,2) (child.position + parent.position).

 

When creating a parenting relation, you have to keep this in mind. In your case, you just have to substract the parent position to the child position.

 

Cheers, 

 

Edit : Same goes with rotation and scaling ! Generally, all transformations done to the parent will be done on the child. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.