Jump to content

Drawing Geometry in Houdini


Recommended Posts

Hello, I am trying to wrap my head around how to correctly draw geometry in houdini.

I have a set of points that define a primitive, and a list of faces and vertices of how to draw the geometry

but I am having problem putting this information into the detail.

How do I

*add the points to the detail ( I figure this is done with the appendpoints?

*define my vertices

*define my faces.

*How does houdini knows which points are being share so they are not duplicated?

the problem right now is that if I have 16 points to draw a sphere and I do something like

 for(int x=0; x<columns;x++)
                    {
                        for (int y=0; y<rows;y++)
                        **/{
                            //Create face poly

                            GU_PrimPoly *poly;
                            GEO_Point * thisPoint;

                            //first point
                            poly = GU_PrimPoly::build(gdp,4,GU_POLY_CLOSED);
                            int index=getIndexBuffer(x,y,4);
                            thisPoint=poly->getVertex(0).getPt();  
                            thisPoint->setPos(sphere_points[index].getPos());

                            //second point
                            index=getIndexBuffer(x+1,y,4);
                            thisPoint=poly->getVertex(1).getPt();  
                            thisPoint->setPos(sphere_points[index].getPos());


                            //third point
                            index=getIndexBuffer(x+1,y+1,4);
                            thisPoint=poly->getVertex(2).getPt();  
                            thisPoint->setPos(sphere_points[index].getPos());

                            //fourth point
                            index=getIndexBuffer(x,y+1,4);
                            thisPoint=poly->getVertex(3).getPt();  
                            thisPoint->setPos(sphere_points[index].getPos());

                        }

                    } 

I ended up having way more than 16 points, beacuse is creating each polygon with unique points.

How do I specify my list of points vertices and faces?

I appreciate the help in advance.

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

thanks!

I figured it out, the fact that the Houdini asks for the reference to the points instead of a list of points was a bit confusing.

Here it is how it works, (or how I think it works).

//Create an array that will store the points references

               GEO_Point *sphere_points[myTotalPoints];

//Adding points to the detail and storing their references in *sphere_points

                for(int pc=0;pc<myTotalPoints;pc++)
                {
                    //Creating point in the details
                    sphere_points[pc]= gdp->appendPoint();                   
                } 

//Once you have that you need to calculate your points values.(This depends on what you are trying to draw)
//In a sphere soude code example

               for(index;index<spherePointsSize;index++)
                {
                           x=//do some math to calculate x in a sphere
                           y=//do some math to calculate y in a sphere
                           z=//do some math to calculate z in a sphere

                           //Vector to store our result
                           UT_Vector4 P;
                           //Setting vector values
                           P.assign(nx,ny,nz,1);

                           //Setting the position of the points appended before                           
                            sphere_points[i]->setPos(P);

                }

//So far you have a set of points that define a sphere to draw them you need to create a primitive and assigned it vertices values
//drawing sphere

                //Creating a pointer to our new to be primitive polygon

                GEO_PrimPoly* prim_poly_ptr;

               //Drawing loop                 
                for(int fn=0; fn<number_faces; fn++)                    
                {                       
                       //Creating a polygon and setting its size to zero as is shown in the api example
                       //This polygon has no vertices yet
                       prim_poly_ptr = dynamic_cast <GEO_PrimPoly*>(gdp->appendPrimitive(GEOPRIMPOLY));                       
                       prim_poly_ptr->setSize(0);

                       //Now you append  vertices to that primitive polygon and pass them a reference to the point that they correspond from our sphere point list
                       //In this example I draw my sphere as quads since it was easier to procedural mapp the points to an index                 
                       //Point 1
                       prim_poly_ptr->appendVertex(sphere_points[p1_index]);
                       //Point 2
                       prim_poly_ptr->appendVertex(sphere_points[p2_index]);
                       //Point 3
                       prim_poly_ptr->appendVertex(sphere_points[p3_index]);
                       //Point 4
                       prim_poly_ptr->appendVertex(sphere_points[p4_index]);
                       //Closing the primitive to make it a polygon instead of a poly line
                       prim_poly_ptr->close();

               }

Note that this is just to explain how is that houdini interpretes geometry. To calculate the points on the sphere or the mapping between

the faces and the point indexes I recommend you take a look at these two links.

Sphere Mapping

Polygon Mesh

Edited by cgTux
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...