Jump to content

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


adwilson
 Share

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.

Link to comment
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. 

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