Search code examples
x3dx3dom

x3d drawing a pyramid


Hello fellow programmers. I have to say I just started drawing figures on x3d and I'm really needing to constroy a pyramid for a project of mine. Yet nothing I search seems to help me as I cannot understand the logic beyond how the figures are drawn just from looking at code from other people.

I managed to draw a cone using some keywords i found like : "bottomRadius", "height", etc...

But have no idea how I could convert something like this to a pyramid, what keywords should I be aware of that could help me draw the base triangle isntead of a circle like the cone does with the keyword bottomRadius?


Solution

  • Use IndexedFaceSet's coord to define points in space that you can connect (create triangles) using the coordIndex. e.g.:

       Shape {
            geometry IndexedFaceSet {  
            coord Coordinate {      
            point [ 
                1 0 0,
                0 1 0,
                0 0 1,
                0 0 0,
            ]}
            coordIndex [ 
            0,1,2,-1 #face1
            0,1,3,-1 #face2
            0,2,3,-1 #face3
            1,2,3,-1 #face4
            ]
            color Color {
            color [ 1 0 0,0 1 0,0 0 1,1 0 1,]}
            colorPerVertex TRUE
            }
    
        }