Attaching items to hierarchical fbx animation (project code available))

I’m trying to add a entity to a hierarchical fbx animation (no bones) at runtime.

After adding the garage door model, the entity hierarchy look like:

RootNode

  • Locator BAKED FROM PATH
    – Panel_Top_Retopo (2)
    — Panel_Middle_Retopo
    ---- Panel_Bottom_Retopo

I want to add a entity called “handle” to “Panel_Middle_Retopo” and have it animate along with the rest of garage.

I created a stub PlayCanvas engine project hiliting the issue. It’s available at:

http://www.jhinrichs.com/examples/example.zip

Here’s the code in question:

function addHandle(){
//add handle to garage door
var handle = new pc.Entity();
handle.addComponent(“model”);
handle.model.model = app.assets.find(“handle.json”).resource;
garage.addChild(handle); //<–this works, handle appears on the stage

console.log(garage.children);

//parent handle to the middle panel of garage door
var parent = garage.findByName("Panel_Middle_Retopo");
handle.reparent(parent); // <--this line makes the handle "disappear"

}

Feels like this should work, but maybe I am misunderstanding how Playcanvas works with FBX. Maybe you can only attach objects to a bone in a bone based animation? I’d appreciate any suggestions or help with this issue.

P.S. this post is related to a recent post I had about hiding/showing entities in a FBX animation. Since the focus has changed a little I created a new post.

The reparent probably retains the local position, rotation and scale so if it had an offset of 10m on the Y axis from it’s original parent, it will have the same offset to the new parent.

If you store the world position and rotation before the reparent and re apply after, that should work.

Everything should be at 0…rot, scale, pos = 1, but went and changed the code to the below. Same deal though…handle disappears when I do the reparent.

function addHandle(){
//add handle to garage door
var handle = new pc.Entity();
handle.addComponent(“model”);
handle.model.model = app.assets.find(“handle.json”).resource;
var pos = handle.getLocalPosition();
var rot = handle.getLocalRotation();
var scale = handle.getLocalScale();

garage.addChild(handle);

//parent handle to the middle panel of garage door
var parent = garage.findByName("Panel_Middle_Retopo");
handle.reparent(parent); // <--this line makes the handle "disappear"

handle.setLocalPosition(pos);
handle.setLocalRotation(rot);
handle.setLocalScale(scale);

console.log(garage);

}

Have you tried drawing a debug line from the parent (or known position like 0, 0, 0 in the world) to where the handle is after the reparent?

Try the world position, not the local.

Yau,

Thanks again. You put me on the right track. It was a scale position deal. Check out the scale and position values in the code below though. Weird values to get it appear where it should…leads me to believe the way the model was created/or translate to FBX out of Modo is the culprit. I’ll have to be careful on how I create the assets in the future.

var handle = r3d.createObject(“handle.json”);
var parent = this.hero.findByName(“Panel_Middle_Retopo”);
var child = handle.findByName(“Handle”);

    this.hero.addChild(handle);
    handle.reparent(parent);
    child.setLocalScale(0.05, 0.5, 0.05);
    child.setPosition(0, 2.5, 0.09);