Jump to content

Store Computed GDP


Recommended Posts

Hi guys. I' looking for solution how to add some functionality similar to capture sop. There is Capture Frame parameter in this sop, which allows to compute capture weights data in specified frame, while reuse this data in other frames. I'd like to add this functionality into my sop. I think it should look something like this (in pseudo code):

class MySopClass
{
.
.
    GU_Detail *initGDP;
.
.
}

cookMySop(....)
{
.
.
    if(frame != initFrame && initGDP.isValid())
    {
        gdp->copy(*initGDP);
    }
    else
    {
        //Compute things
        initGDP = gdp;
    }
}

So, basically i need to recompute gdp only in initFrame (frame 1 for example), store this gdp in initGDP, and reuse it in other frames. Of course there is no isValid() method in gdp. So i can't be sure is my gdp "isValid". Is this a right approach?:unsure:

Any help? Thx!

Link to comment
Share on other sites

  • 2 weeks later...

Hi again. I'm stuck with this problem guys...

Once more: I need to compute primitive attribute only in frame 1, and then, just "hold" these values, in other frames.Ok, i know, that to do that i need a copy of GU_Detail. And if i make one in frame 1, and then just do: gdp->copy(*init_gdp), i get my frame 1 geometry on all other frames, and off course it's not animated, since it's just copied from frame 1. :) So i thought i need to copy only attribute data somehow, from init_gdp to my current gdp. So i found this in HDK Docs:

		for (GA_AttributeDict::iterator it = init_gdp.getAttributes().getDict(GA_ATTRIB_PRIMITIVE).begin(GA_SCOPE_PUBLIC);
			!it.atEnd(); ++it)
		{

			GA_Attribute *a = it.attrib();
			gdp->getAttributes().cloneAttribute(GA_ATTRIB_PRIMITIVE, "udim", *a, true);
		}

But this code only copies "attributes definitions", i.e. i get no attrib data. Don't know why it happens. So, here is my cookMySop:

And yes, this SOP is for assigning id's for Foundry Mari textures :)

long f = context.getFrame();
	fpreal now = context.getTime();
	lockInputs(context);
	duplicateSource(0, context);

	if (f == INITFRAME(now))
	{
		GA_RWAttributeRef udim_ref = gdp->addStringTuple(GA_ATTRIB_PRIMITIVE, "udim", 1);
		GA_RWHandleS udim_h(udim_ref.getAttribute());

		GA_ROHandleV3 uv_h(gdp, GA_ATTRIB_VERTEX, "uv");
		if (uv_h.isInvalid())
		{
			cout << "Vertex UV attribute not found";
			UT_ERROR_ABORT;
		}

		const GA_Primitive *prim;
		const GA_PrimitiveList &primList = gdp->getPrimitiveList();
		unsigned short int udim = 0;
		char udim_str[4];

		for (GA_Iterator pr_it(gdp->getPrimitiveRange()); !pr_it.atEnd(); ++pr_it)
		{
			GA_Offset prim_offset = pr_it.getOffset();
			prim = primList.get(prim_offset);		
			GA_Range vtx_range = prim->getVertexRange();
			GA_Offset vtx_offset = vtx_range.begin().getOffset();
			UT_Vector3	uv(uv_h.get(vtx_offset));
			udim = (int)(ceil(uv[0]) + floor(uv[1])*10) + 1000;
			sprintf(udim_str, "%d", udim);
			udim_h.set(prim_offset, udim_str);
		}

		init_gdp.clear();
		init_gdp.copy(*gdp);

	}

	else
	{

		for (GA_AttributeDict::iterator it = init_gdp.getAttributes().getDict(GA_ATTRIB_PRIMITIVE).begin(GA_SCOPE_PUBLIC);
			!it.atEnd(); ++it)
		{

			GA_Attribute *a = it.attrib();
			gdp->getAttributes().cloneAttribute(GA_ATTRIB_PRIMITIVE, "udim", *a, true);
		}
	}

Also, i found something interesting here:GA_AIF_Merge This seems to be a solution, but this attribute interface is pure virtual, and i have no idea how to implement it. :blink: Any help?

That's it for now, thx.

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