Jump to content

Problem creating and saving multiple bezier curves


Recommended Posts

Hi,

  With the following code, I can write out a single bezier curve but anything more than one, the second bezier curves are not in the bgeo file being written out. The point count indicates that it is aware of additional points associated with the second curve.

#include <string>
#include <GU/GU_Detail.h>
#include <GU/GU_PrimRBezCurve.h>
#include <UT/UT_Version.h>
#include <GEO/GEO_Point.h>
#include <OpenEXR/ImathVec.h>
#include <vector>

typedef std::vector<Imath::V3d> V3dContainer;

void create_single_bezier_curve(const std::string& bgeo_filename)
{
    GU_Detail    gdp;
    V3dContainer cvs;

	cvs.push_back(Imath::V3d(0,0,0));
	cvs.push_back(Imath::V3d(1,1,0));
	cvs.push_back(Imath::V3d(2,1,0));
	cvs.push_back(Imath::V3d(3,0,0));

	GA_Size num_points = cvs.size();
    for ( size_t i = 0; i < num_points; ++i )
    {
    	GA_Offset pt = gdp.appendPointOffset();
    	gdp.setPos3(pt,
    			cvs[i][0],
				cvs[i][1],
				cvs[i][2]);
    }

    GU_PrimRBezCurve* bezier_curve =	GU_PrimRBezCurve::build(&gdp,num_points);

	if (bezier_curve)
	{
		for ( size_t i = 0; i < num_points; ++i )
		{
			bezier_curve->setVertexPoint(i,gdp.pointOffset(i));
		}

		gdp.save(bgeo_filename.c_str(), NULL);
	}
}

void create_multilpe_bezier_curves(const std::string& bgeo_filename)
{
    GU_Detail    gdp;
    V3dContainer cvs;

    // Curve 0
	cvs.push_back(Imath::V3d(0,0,0));
	cvs.push_back(Imath::V3d(1,1,0));
	cvs.push_back(Imath::V3d(2,1,0));
	cvs.push_back(Imath::V3d(3,0,0));

    // Curve 1
	double y_offset = 2.0;
	cvs.push_back(Imath::V3d(0,0 + y_offset,0));
	cvs.push_back(Imath::V3d(1,1 + y_offset,0));
	cvs.push_back(Imath::V3d(2,1 + y_offset,0));
	cvs.push_back(Imath::V3d(3,0 + y_offset,0));
	cvs.push_back(Imath::V3d(4,0 + y_offset,0));

	// Store all the points
	GA_Size num_points = cvs.size();
    for ( size_t i = 0; i < num_points; ++i )
    {
    	GA_Offset pt = gdp.appendPointOffset();
    	gdp.setPos3(pt,
    			cvs[i][0],
				cvs[i][1],
				cvs[i][2]);
    }

    // Setup curve 0
	GA_Size num_points_curve_0 = 4;
	GU_PrimRBezCurve* bezier_curve_0 = GU_PrimRBezCurve::build(&gdp,num_points_curve_0);

	if (bezier_curve_0)
	{
		for ( size_t i = 0; i < num_points_curve_0; ++i )
		{
			bezier_curve_0->setVertexPoint(i,gdp.pointOffset(i));
		}

	}

    // Setup curve 1
	GA_Size num_points_curve_1 = 5;
	GA_Offset curve_offset_1 = 4; // because the first 4 points is for curve 0
	GU_PrimRBezCurve* bezier_curve_1 = GU_PrimRBezCurve::build(&gdp,num_points_curve_1);

	if (bezier_curve_1)
	{
		for ( size_t i = 0; i < num_points_curve_1; ++i )
		{
			bezier_curve_1->setVertexPoint(i,gdp.pointOffset(i+curve_offset_1));
			// bezier_curve_1->setVertexPoint(i,curve_offset_1);
		}

	}

	gdp.save(bgeo_filename.c_str(), NULL);

}

int
main(int argc, char *argv[])
{
    create_single_bezier_curve("single_bezier_curve.bgeo");
    create_multilpe_bezier_curves("multiple_bezier_curves.bgeo");
    return 0;
}

 

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...