Menu

Sharing CoordinateNode with IndexedFaceSet

2019-01-03
2019-01-03
  • Pete Sergeant

    Pete Sergeant - 2019-01-03

    Happy New Year everyone, may CGE go from strength to strength!

    Can anyone help with a little understanding. I'm creating multiple meshes (IndexedFaceSets), each has a different shape/appearance/texture. I've been constructing each mesh with its own CoordinateNode.

    However, there is about 70% commonality in the vertices in each set of coordinates. Can I create just one CoordinateNode with all the possible vertices, and then assign this to each of the meshes - obviously setting the vertex indices appropriately. Is this approach faster/slower?

     
  • EugeneLoza

    EugeneLoza - 2019-01-03

    Hi, Pete Sergeant!
    Happy New Year to you too! :)

    Can I create just one CoordinateNode with all the possible vertices, and then assign this to each of the meshes - obviously setting the vertex indices appropriately

    Yes, you can. I didn't test it but as far as I understand it won't be neither faster nor slower. However, memory usage will be definitely lower this way as the same memory will be reused. That said:

    However, there is about 70% commonality in the vertices in each set of coordinates.

    If you assign a single TCoordinateNode to multiple TIndexedFaceSetNodes they will contain not copies, but references to the same TCoordinateNode. In other words, if you change it (add/remove/change a point) it will be changed in all TIndexedFaceSetNodes. You might want to make copies, not references, by using DeepCopy function if you want to change TCoordinateNodes to be slightly different for different objects, see https://castle-engine.io/apidoc/html/X3DNodes.TX3DNode.html#DeepCopy .

     
  • Pete Sergeant

    Pete Sergeant - 2019-01-03

    Thanks Eugene, much appreciated; I'd not thought about the memory issue. Also the referencing (single change/updates all) is appealing, so I won't bother with deep copying.

     
  • Michalis Kamburelis

    Right now there will not be a speed difference in how we render two different shapes with a refence to the same TCoordinateNode node. This may change some day!

    Still, as Eugene writes, you will have better memory (RAM) usage in case you use the same TCoordinateNode many times. This gain can be very significant in larger scenes / with lots of sharing, so I would encourage to share TCoordinateNode instances where possible :) Eventually, it can also lead to better speed of some operations, since your application just uses less memory, processor cache is better utilized etc.

    This "sharing" corresponds also to X3D (and VRML) concept of DEF / USE of nodes. An example in VRML 2.0 is on https://github.com/castle-engine/demo-models/blob/master/vrml_engine_doc_simple_examples/reuse_coordinate.wrl . This example uses the same Coordinate node in X3D (which is exactly TCoordinateNode in Pascal) 3 times, by doing USE TowerCoordinates.

     

Anonymous
Anonymous

Add attachments
Cancel