FIXED: Custom Attributes in Cplusplus SOP?

it’s more likely that I’m just doing something dumb, but figured this was the best place for this post. i’m working on a Cplusplus SOP, and seem to be getting garbage values when trying to read from float and int attributes (which i’ve confirmed to be reasonable with a SOP to DAT). here’s a representative snippet of my code:

void
BulletSOP::addSOPGeometry(OP_SOPInput const* sopGeom)
{
        CustomAttribInfo const* massAttr = sopGeom->getCustomAttribute("mass");
	CustomAttribInfo const* objIdAttr = sopGeom->getCustomAttribute("objId");

	if (!(massAttr &&
		  massAttr->attribType == AttribType::Float &&
		  massAttr->numComponents == 1) ||

		!(objIdAttr &&
		  objIdAttr->attribType == AttribType::Int &&
		  objIdAttr->numComponents == 1))
	{
		_errorString = "expected point attributes mass[1] and/or objId[1](int) not found";
		return;
	}

	Position const* sopPoints = sopGeom->getPointPositions();

	for (int p = 0; p < sopGeom->getNumPrimitives(); ++p)
	{
		PrimitiveInfo const& primInfo = sopGeom->getPrimitive(p);

		// XXX only point attrs are supported, assume constant
		int32_t firstIndex = primInfo.pointIndices[0];
		int32_t objId = objIdAttr->intData[firstIndex];
 
      // ...

      float mass = massAttr->floatData[firstIndex];

i’m using an Info DAT to output the objId and mass values i’ve seen, and while i’m only input 0 or 1 for objId or mass, i’m getting values all over the place in the Info DAT (and the behavior of my SOP is consistent with this). i’ve confirmed that outputting hardcoded constants to the Info DAT works as expected, so i’m pretty sure i’m not messing that up.

any ideas what’s going wrong? unfortunately the SimpleShapes example only shows copying the input custom attrs to output, so i don’t have any reference for how to index individual values.

thanks for any ideas!

i’ve confirmed that SimpleShapesSOP will correctly pass through custom attributes present on the input, so the data must be in there.

however, when i look at the result of this:

	CustomAttribInfo const* massAttr = sopGeom->getCustomAttribute("mass");
	CustomAttribInfo const* objIdAttr = sopGeom->getCustomAttribute("objId");

	std::stringstream info;

	for (int p = 0; p < sopGeom->getNumPoints(); ++p)
	{
		info << "(" << p << " " << objIdAttr->intData[p] << " " << massAttr->floatData[p] << ") ";
	}

	_infoString = info.str().c_str();

i can’t see any sort of pattern in the intData or floatData that seems to correspond to the values i’m feeding in (e.g. every n’th value is equal to the custom attr value i set). the layout of this data is a total mystery to me…

ps. this is in builds 2018.20700 and 2018.20310 on Windows 10. for now i’m able to workaround this by stuffing my custom attrs into the color attr, but it’d be great to get some hints on how to actually use custom attrs!

Hi,

This issue will be fixed in our next build. I’ll let you know once it’s fixed. Thanks for reporting this.

This issue is fixed. You should be able to get the changes from our next experimental build. Thanks.

awesome, thanks for the quick response!!

Hi,

I know I’m resurrecting an old thread here, but has this bug been fixed? I’m trying to access custom attributes inside a c++ sop, and I can only seem to access the value from the first point.

I’m doing the following on geometry with 4 points, where the density attribute should be {.25, .5, .75, 1}

const SOP_CustomAttribData* densityAttr = sinput->getCustomAttribute("density");
for (int p = 0; p < sinput->getNumPoints(); ++p)
{
	float A = densityAttr->floatData[p];
}

I get the correct value of .25 when p=0. But when p=1,2,3, I get incorrect values.

Is there a work around for this? Or an equivalent to the getColors() or getNormals() functions which return an array of all point attribute values?

Thanks

Just a small bump.

Does anyone have information if this bug is still around? Or is there a way to get custom attributes from all the points in the incoming sop?

@ajk48n, I’ll look into this. Thanks!

This issue is fixed and will be available in our next official build.
Thanks for the report!

That’s great to hear! Thanks for the quick fix. Will attributes be accessed by index, or will there be a function that returns an array of all the values?

There is no new function. It’s the same as before. All the float values are in “floatData” and the ints can be accessed from “intData”.

Example:
Assume we have 3 vertices and 2 types of float attributes: one has 1 component (a), and the other has 2 components (bx and by);
the way the float data is stored for all points is as below:

a0, bx0, by0, a1, bx1, by1, a2, bx2, by2