Change Object parent in Three.js using JSON file

I’m using same technique explained in this example: https://threejs.org/examples/#webgl_animation_keyframes_json

I defined a JSON file that contains all objects, geometries and animations. However, I couldn’t find the way to specify in the animation a change of object’s parent. Also, by looking at the documentationI don’t see any ObjectKeyframeTrack (or similar) which would be nice to set an object’s parent.

My questions is referring the JSON file format, not using the API, to do this.

In any case, other approaches are welcome as well.

(I posted same question on StackOverFlow: https://stackoverflow.com/questions/49610320/change-object-parent-in-three-js-using-json-file)

You can only define the affinity of a keyframe track to its object (e.g. a bone). The definition of the object (scene) hierarchy happens in the “object” property of the JSON file.

Also see: https://threejs.org/docs/#api/animation/KeyframeTrack.name

You mean that I can set the “parent” property of an object using names? I tried by using a string key frame (not sure if the type is “sting”):
(this is a Track in the JSON file)
(…)
{
“type”: “string”,
“name”: “MyChildrenObjectName.parent”,
“keys”: [{
“value”: “SomeOtherParent”,
“time”: 0
}
, {
“value”: “OriginalParent”,
“time”: 40
},
{
“value”: “SomeOtherParent”,
“time”: 200
}]
}

This breaks all and nothing is shown. Can you please explain me a bit more?

Thank you.

No, you don’t set any parent relationship in the animation data at all. This is done in the “objects” property.

So you cannot change it during the animation?

You mean when the JSON is already parsed and the animation clip is playing?

No, before its parsed or before the clip is playing.
In general, is it possible to specify in the JSON file that at some given time, one object change its parent?

No, that’s not possible. The defined scene hierarchy is static.

1 Like

Thanks. That answers my questions.

I have to admit that i’ve misunderstood your original question a little bit, sry :blush:

But i’m glad that we could clarify everything.

I would say I was the one who explained it all wrong, thanks for the patience and answers.