GeometryAttributesHelpers.kl

Types

GeometryAttributes (object)

The GeometryAttributes object is a generic container that contains a named set of GeometryAttribute. Each GeometryAttribute is an array containing values of a specific type. For example, the “positions” attribute is typically a Vec3Attribute containing Vec3 elements.

All Geometry types, such as the PolygonMesh, contain a GeometryAttributes container which can be retrieved using the Geometry.getAttributes interface method. However, it is the geometry that controls the order and meaning of the attribute elements within the GeometryAttribute array. For example, the PolygonMesh maintains information about how the values are shared.

注釈

Attributes needs to be uniquely identified by a name. The GeometryAttributes cannot contain multiple attributes with the same name, even if the type differs.

Attribute versioning

In order to allow for optimal performance and multithreading, attributes contain a version number (UInt32) which has to be explicitly incremented after value modifications. However, if the size of the attribute array changes, the version will be automatically incremented. Attribute clients, such as InlineDrawing, can then detect value changes efficiently in order to update their state.

注釈

This versioning strategy favors performance over simplicity. Another choice could have been to automatically increase the version when detecting a value difference. Another could have been to let the clients compare values to their last state using a copy or a hash of the values. However, these would have caused performance overhead that could be relatively important in some situations.

Similarly, the GeometryAttributes.keysVersion member defines a version for the set of attributes, which will get incremented only if attributes get added or removed from the container, but not upon attribute resize or value changes.

Members

UInt32 keysVersion Version of the attribute set. This is incremented only if attributes are added or removed, and not if values are changed or values array is resized.
UInt32 attributesValueVersion  
Ref<GeometryAttribute> positionsAttribute Fast access to the positions attribute, if it exists. Note: might be Vec3Attribute or Vec3_dAttribute depending on the precision.
Ref<GeometryAttribute> normalsAttribute Fast access to normals attribute, if it exists.
String debugName Name to be used by descriptions
/*
** Example: GeometryAttributes
*/

require Geometry;

function reportAttributes( Geometry geom ) {
  // Get the attributes container from the geometry
  Ref<GeometryAttributes> attributes = geom.getAttributes();
  report('Number of attributes: ' + attributes.attributeCount());
  report('Number of elements: ' + attributes.size());

  // Iterate over the attributes
  GeometryAttributesIterator iter = attributes.getAttributesIterator();
  Ref<GeometryAttribute> attribute = null;
  while( attribute = iter.getNext() )
   report( 'Attribute ' + attribute.getName() + ' of type ' + attribute.type() );
}

operator entry() {
  PolygonMesh p();
  p.addSphere(  Xfo(), 1.0, 3, true, true );
  reportAttributes(p);
}

/*
** Output:

Number of attributes: 3
Number of elements: 77
Attribute positions of type Vec3Attribute
Attribute normals of type Vec3Attribute
Attribute uvs0 of type Vec2Attribute

*/

Methods

  GeometryAttributes ( in GeometryAttributes other )
  GeometryAttributes ()
  attachNewAttribute ! ( in Ref<GeometryAttribute> attribute )
Size attributeCount ? ()
  clear ! ()
GeometryAttributes clone ? ()
  cloneMembersTo ? ( io GeometryAttributes that )
  copy ! ( in Ref<GeometryAttributes> other )
  copyValue ? ( in Size sourceIndex, in Size targetIndex )
  copyValues ! ( in Ref<GeometryAttributes> sourceAttributes, in Size sourceIndex, in Size count, in Size targetIndex, in Boolean createMissingSourceAttributes )
Ref<GeometryAttribute> getAttribute ? ( in String name )
Ref<GeometryAttribute> getAttribute ? ( in String name, in Type expectedAttributeType )
String getAttributeListDesc ? ()
GeometryAttributesIterator getAttributesIterator ? ()
String getDesc ? ( in Boolean useUnitTestPrint )
String getDesc ? ()
Ref<Vec3Attribute> getNormals ? ()
Ref<GeometryAttribute> getOrCreateAttribute ! ( in String name, in Type attributeType )
Ref<ColorAttribute> getOrCreateColorAttribute ! ( in String name )
Ref<IntegerAttribute> getOrCreateIntegerAttribute ! ( in String name )
Ref<Mat33Attribute> getOrCreateMat33Attribute ! ( in String name )
Ref<Mat44Attribute> getOrCreateMat44Attribute ! ( in String name )
Ref<Vec3Attribute> getOrCreateNormals ! ()
Ref<Vec3Attribute> getOrCreatePositions ! ()
Ref<Vec3_dAttribute> getOrCreatePositions_d ! ()
Ref<QuatAttribute> getOrCreateQuatAttribute ! ( in String name )
Ref<RGBAAttribute> getOrCreateRGBAAttribute ! ( in String name )
Ref<RGBAttribute> getOrCreateRGBAttribute ! ( in String name )
Ref<ScalarAttribute> getOrCreateScalarAttribute ! ( in String name )
Ref<ScalarConstantArrayAttribute> getOrCreateScalarConstantArrayAttribute ! ( in String name )
Ref<SkinningAttribute> getOrCreateSkinningAttribute ! ( in String name )
Ref<UInt16ConstantArrayAttribute> getOrCreateUInt16ConstantArrayAttribute ! ( in String name )
Ref<UInt32Attribute> getOrCreateUInt32Attribute ! ( in String name )
Ref<Vec2Attribute> getOrCreateVec2Attribute ! ( in String name )
Ref<Vec3Attribute> getOrCreateVec3Attribute ! ( in String name )
Ref<Vec3_dAttribute> getOrCreateVec3_dAttribute ! ( in String name )
Ref<Vec4Attribute> getOrCreateVec4Attribute ! ( in String name )
Vec3 getPosition ? ( in Size index )
Vec3_d getPosition_d ? ( in Size index )
Ref<Vec3Attribute> getPositions ? ()
Ref<Vec3_dAttribute> getPositions_d ? ()
Boolean has ? ( in String name )
Boolean has ? ( in String name, in Type attributeType )
Boolean hasFloat64Positions ? ()
  incrementAttributesValueVersion ! ()
  linearCombine ? ( in LocalL16UInt32Array sourceIndices, in LocalL16ScalarArray sourceWeights, in Size targetIndex )
  removeAttribute ! ( in String name )
  resize ! ( in Size newCount )
  setPosition ? ( in Size index, in Vec3 pos )
  setPosition ? ( in Size index, in Vec3_d pos )
Size size ? ()