Jump to content
Macha

Array Detail Attribute

Recommended Posts

I make a detail attribute called orids

 	const char *        attName= "orids";
	GA_RWAttributeRef   oridsAtt      = gdp->findIntTuple(GA_ATTRIB_GLOBAL, attName, setSize);    
	if (!oridsAtt.isValid())
	{
	    oridsAtt = gdp->addIntTuple(GA_ATTRIB_GLOBAL, attName, setSize);           
	}             
    	GA_RWHandleI oridsHandle(oridsAtt.getAttribute());

and I want to populate it from values that I have stored in a set. I probably have to convert the set to an array, but whatever I try, I cannot set the values except for the first array item. For example, as a test, this will just set the first array item to 5 and leave all others on 0:

	GA_Size		gasize(setSize);
	GA_Offset 	gaoffset;
	int	test[] = {1,2,3,4,5};
	oridsHandle.setBlock(gaoffset, gasize, test);

I also tried looping over the set and setting the attribute that way:

	int i=0;
	for (set<int>::iterator it=oridsSet.begin();it!=oridsSet.end(); ++it)
	{
		oridsHandle.set(GA_Offset(i++),*it);
	}

But again, it only sets the value in the very first array position.

 

 

How do I set array detail attributes?

Edited by Macha

Share this post


Link to post
Share on other sites

Hi,

 

  I have set vertex array attribute with this call successfully.

 

        gdp->setAttributeFromArray()

 

  Give that a try.

 

Cheers

Share this post


Link to post
Share on other sites

 

int i=0;

for (set<int>::iterator it=oridsSet.begin();it!=oridsSet.end(); ++it) {

    oridsHandle.set(GA_Offset(0), i++, *it);

}

 

Edited by edward
Edited w/bug fix

Share this post


Link to post
Share on other sites

Thanks, that looks like it works! (with i++)

Edited by Macha

Share this post


Link to post
Share on other sites

Edward, I too ran into this problem, and though your solution works, I have a big block of data that I'm writing to the node and would like, for performance reasons, to write it as a block. Is there a reason why the GA_RWHandleI::setBlock method writes all the values as the same? Is it a bug in the hdk implementation?

 

Thanks.

Fernando.

Share this post


Link to post
Share on other sites

No, it's not a bug. setBlock() sets the data from the range [source, source + nelements) to the *elements* [startoff to startoff + nelements) using the given source stride and component. If you had a point attribute, then this would set the attribute values for nelements number of points. In the case of the detail (aka global) attribute, there is only ONE element. So it doesn't make sense to use setBlock(). In this case we have an attribute of length setSize which we want to set all of its components.

 

Here's a rough pic.

 

post-209-0-92804700-1414552563_thumb.png

Share this post


Link to post
Share on other sites

Thank you for your explanation, that makes sense. My question then is, if I have a large number of floats that I want to add to an object (they are weights for a deformation algorithm, so they are not particular to any point but to the whole mesh), what would be the fastest way to do it without setting them one by one inside a loop?

Share this post


Link to post
Share on other sites

Weights for a deformation algorithm should be per point. But anyhow, there's nothing wrong with doing loops.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×