Search code examples
x3dvrml

Visualize points as spheres without creating a sphere for each point


My data consists of at least 30k points each one of which I want to be visualized as a sphere, so I would see thousands of spheres forming a shape. I tried using VRML, because it looks very simple, but the file gets way too big because it consist of repetitions of the text bellow, one for each point:

# 'X_32228'
Transform {
    translation 96.0 85.0 76.0
    children [
        Shape {
            appearance Appearance { material Material {} }
            geometry Sphere { radius 1 }
        }
    ]
}

How can I create one sphere and replicate it on the different points? or more in general, how can I reduce the size of the output file? even if it's on a different format (like X3D).


Solution

  • You can achieve what you want by using the PROTO mechanism.

    PROTO SmallSphere [  
        exposedField SFVec3f SmallSphere_translation 0 0 0  
    ] 
    {  
    Transform {
        translation IS SmallSphere_translation
        children [
            Shape {
                appearance Appearance { material Material {} }
                geometry Sphere { radius 1 }
            }
        ]
    }
    

    The above code basically creates a PROTO (something like a class in Object Oriented Programming) from your Transform where the translation is variable. Then, you have to create instances of it as follows:

    SmallSphere { SmallSphere_translation 96.0 85.0 76.0 }
    SmallSphere { SmallSphere_translation 3.0 8.0 6.0 }
    SmallSphere { SmallSphere_translation 936.0 385.0 746.0 }
    

    ... as many as you want, where the translation is the parameter that you change from one instance to another. If you need some other fields to be changed with the instance you just have to follow the above example. For example of you want the radius of the sphere to be variable you would have to create your PROTO as follows:

    PROTO SmallSphere [  
        exposedField SFVec3f SmallSphere_translation 0 0 0  
        exposedField SFFloat SmallSphere_radius 2.0
    ] 
    {  
    Transform {
        translation IS SmallSphere_translation
        children [
            Shape {
                appearance Appearance { material Material {} }
                geometry Sphere { radius IS SmallSpehere_radius }
            }
        ]
    }
    

    Please note that SmallSphere_translation and SmallSphere_radius are names chosen by me. You can name these fields as you want.