jagenjo / litescene.js

A WebGL 3D Engine library with component-based node hierarchy. Used by WebGLStudio
MIT License
367 stars 65 forks source link

multi-parenting ? #12

Open andreasplesch opened 5 years ago

andreasplesch commented 5 years ago

As far as I can see, the scene graph allows for exactly one parent for each node, as most do. Is that correct ?

I was looking at how litescene.js could work with X3D (VRML) for import/export or as a player. X3D (and SVG) have a concept of (DEF) nodes with can be reused as USE nodes elsewhere in the graph. They are placed not as copies or clones but just exist in multiple places, and therefore can have multiple parents.

Could such multi-parenting be simulated with components or prefabs ?

Instancing is similar but in X3D the DEF/USE concept applies to any node.

For importing and playing one could just make clones, I suppose. Do the clones keep a relationship with their originals ?

jagenjo commented 5 years ago

THe problem is that the system wasnt designed with that purpose in mind so it would imply to rework lots of parts to work that way.

But you can always develop a X3D component that inside has all the X3D features and co-live with my own system. Then when my system sends a message to the component it could redirect it to wherever.

andreasplesch commented 5 years ago

Ok, I think I can see the idea. Manage the X3D scene inside a component but still use things like primitives or materials or Transforms or renderers from litescene. Can these be used outside of a SceneNode ? Or can a SceneNode be used outside of a Scene ?

How would one set up another scene type ? I guess I should look at https://github.com/jagenjo/litescene.js/blob/master/src/scene.js

andreasplesch commented 5 years ago

https://github.com/jagenjo/litescene.js/blob/master/src/scene.js#L1770 looks like prefabs instances are references to the same prefab. https://github.com/jagenjo/litescene.js/blob/master/guides/prefabs.md So this is pretty close but I guess prefabs are supposed to be static, eg. should not/can not be modified during playing ?