How to change GraphNode's children position or rotation

for example,i want to import a model of car which has a lot of nodes(parts),and i plan to change children’s position or rotation,likes this

,so that i can achieve car’s show of Dismantling and merging

this is my project’s link:https://playcanvas.com/project/643550/overview/my--first-webvr.

it’s a VR scene.

This does not directly answer your question, but the way we currently deal with this is to bring each mesh that needs to be animated/moved in as a separate mesh and then create a unique entity for it.

I am hoping that someone will have an answer to how to deal with the child nodes separately by their nodes though. Being able to address child nodes directly might be useful for reducing clutter. OTOH, if you need to attach any other components to the “child”, then it would have to be a unique entity anyway.

Each sub mesh in the model gets imported as a graphNode so you can do findByName on the entity that has the model component to find the sub meshes by name.

thanks a lot for your help,i solved this problem by F12 in debug webPage,which i could see the relationship of all nodes,

.first, i just wrote this line: “this.targetEntity.children[0].children[0].children[i].localPosition = new pc.Vec3( pos.x>0?(pos.x+1):(pos.x-1) ,pos.y>0?(pos.y-1):(pos.y+1) ,pos.z>0?(pos.z+1):(pos.z-1))”,but it didn’t work,so my friend told me that i have to refresh your change.and i added this two lines :"this.targetEntity.children[0].children[0].children[i]._dirtifyLocal();
this.targetEntity.children[0].children[0].children[i]._sync();"yeah, it finally really changed my children’s position.

today,i try this line: this.targetEntity.children[0].children[0].children[i].setLocalPosition(new pc.Vec3(90,10,10));,it also worked,didn’t need refreshing

it shuld be a way ,i will try it.thank you ,bro

Yes, use setLocalPosition. That is public API.

Do not use localPosition, _dirtifyLocal or _sync. Those are private and internal.

sometimes it makes me confused,it does exist,but i can’t see the api when i write the script,just like “setLocalPosition”,

,so i have to check
the Documents.hope it improving.

Interesting. Note that if you change “targetEntity” to simply “entity” that you get a different API reference from the auto-complete. I guess the issue is that the autocomplete may have a hard time determining the appropriate context at times?

2 Likes

thanks,my friend,i got it.