SkinningAttribute.kl

Types

SkinningAttributeData (struct)

A simple struct that holds the data for the SkinningAttribute. This struct can be moved to the GPU wholesale, and its methods will also continue to work on the GPU. This is a workaround untill objects are supported on the GPU. currently only structs are supported, so we move the data and important fucntions to the struct, and add the struct to objct as a member.

Members

Size count  
UInt32ArrayAllocator weightsAllocator  
UInt16[] ids  
UInt32[] offsets  
UInt16[] counts  

Methods

  SkinningAttributeData ( in SkinningAttributeData other )
  SkinningAttributeData ()
SkinningAttributeData clone ? ()
  cloneMembersTo ? ( io SkinningAttributeData that )
  copyFrom ! ( in SkinningAttributeData other )
  copyValue ! ( in Size sourceIndex, in Size targetIndex )
  copyValue ! ( in SkinningAttributeData source, in Size sourceIndex, in Size targetIndex )
Boolean equalValues ? ( in Size index1, in Size index2 )
  getLinearCombination ? ( in LocalL16UInt32Array sourceIndices, in LocalL16ScalarArray sourceWeights, out LocalL16UInt32Array skinIds, out LocalL16ScalarArray skinWeights )
  getPair ? ( in UInt32 index, in UInt32 offset, out UInt16 id, out Scalar weight )
UInt16 getPairCount ? ( in UInt32 index )
  getPairs ? ( in UInt32 index, out LocalL16UInt32Array skinIds, out LocalL16ScalarArray skinWeights )
  linearCombine ! ( in Ref<Object> sourceAttr, in LocalL16UInt32Array sourceIndices, in LocalL16ScalarArray sourceWeights, in Size targetIndex )
Size memUsage ? ()
  normalize ! ( in Size index )
  resize ! ( in Size count )
  setPair ! ( in UInt32 index, in UInt32 offset, in UInt16 id, in Scalar weight )
  setPairCount ! ( in UInt32 index, in UInt16 pairCount )
  setPairs ! ( in UInt32 index, in LocalL16UInt32Array skinIds, in LocalL16ScalarArray skinWeights )
Size size ? ()

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 ? ()

SkinningAttribute (object)

brief The SkinningAttribute contains multiple pairs of id and weight per index. For an index, id-weight pairs can be set one by one or in batch. It provides, too, helpers such as SkinningAttribute.normalize to set weight sum to 1.0. By implementing methods such as GeometryAttribute.LinearCombination, it can properly support modeling operations.

Various strategies are used to lower memory consumption and increase performance:

  • contiguous memory storage in a few buffers to lower memory fragmentation and minimize memory allocations
  • counts per index is implicit if values are appended in order (0 to N-1)
  • ids are stored UInt16, which lowers memory usage and still allows for up to 64K deformer ids

Members

UInt32 version  
String name  
UInt32 containerIndex  
StatisticsAutoRegisterMember autoStats  
Size count  
Ref<GeometryAttributes> container  
SkinningAttributeData internalData  
UInt32 memoryLocation  
/*
** Example: SkinningAttribute
*/

require Geometry;
  
operator entry() {

      SkinningAttribute skinningAttr = SkinningAttribute();
      
      //Create 2 skinned items
      skinningAttr.resize(2);
      
      //Item 0: 2 id-weight pairs:
      //  pair 0 = [20:0.25]
      //  pair 1 = [21:0.75]
      skinningAttr.setPairCount( 0, 2 );
      skinningAttr.setPair( 0, 0, 20, 0.25 );
      skinningAttr.setPair( 0, 1, 21, 0.75 );
      
      //Item 1: set 3 id-weight pairs in batch = [30:0.5, 31:0.5, 32:0.25]
      LocalL16UInt32Array indices;
      indices.push(30);
      indices.push(31);
      indices.push(32);
      
      LocalL16ScalarArray weights;
      weights.push(0.5);
      weights.push(0.5);
      weights.push(0.25);
      
      skinningAttr.setPairs(1, indices, weights);
      
      Scalar weight;
      UInt16 id;
      for( Size i = 0; i < skinningAttr.getPairCount(0); ++i ) {
        skinningAttr.getPair( 0, i, id, weight );
        report("Item0: pair" + i + ": id="+id+" weight="+weight);
      }
      
      skinningAttr.getPairs(1, indices, weights);
      report("Item1: ids="+indices.getString()+" weights="+weights.getString());
      
      skinningAttr.normalize(0);
      skinningAttr.normalize(1);
      report("Values after normalize:");
      report( skinningAttr.getDesc( true) );
  
}

/*
** Output:

Item0: pair0: id=20 weight=+0.25
Item0: pair1: id=21 weight=+0.75
Item1: ids=[30, 31, 32] weights=[+0.5, +0.5, +0.25]
Values after normalize:
Attribute:  nb elements = 2
  values:[ 
    [20:+0.25, 21:+0.75] 
    [30:+0.400024, 31:+0.400024, 32:+0.200012] 
  ]


*/

Methods

  SkinningAttribute ( in SkinningAttribute other )
  SkinningAttribute ()
Boolean checkConsistency ? ()
SkinningAttribute clone ? ()
  cloneMembersTo ? ( io SkinningAttribute that )
  convertToCPU ! ()
  convertToGPU ! ()
  copyValue ! ( in Ref<Object> sourceAttr, in Size sourceIndex, in Size targetIndex )
  copyValue ! ( in Size sourceIndex, in Size targetIndex )
UInt16[] counts ? ()
Data data ? ()
Boolean equalValues ? ( in Size index1, in Size index2 )
UInt32 getElementsMemType ? ()
  getLinearCombination ? ( in LocalL16UInt32Array sourceIndices, in LocalL16ScalarArray sourceWeights, out LocalL16UInt32Array skinIds, out LocalL16ScalarArray skinWeights )
  getPair ? ( in UInt32 index, in UInt32 offset, out UInt16 id, out Scalar weight )
UInt16 getPairCount ? ( in UInt32 index )
  getPairs ? ( in UInt32 index, out LocalL16UInt32Array skinIds, out LocalL16ScalarArray skinWeights )
Size getScalarValueSize ? ()
UInt16[] ids ? ()
  linearCombine ! ( in Ref<Object> sourceAttr, in LocalL16UInt32Array sourceIndices, in LocalL16ScalarArray sourceWeights, in Size targetIndex )
  normalize ! ( in Size index )
UInt32[] offsets ? ()
  resize ! ( in Size count )
  setFromScalar ! ( in Size index, in LocalL16ScalarArray value )
  setPair ! ( in UInt32 index, in UInt32 offset, in UInt16 id, in Scalar weight )
  setPairCount ! ( in UInt32 index, in UInt16 pairCount )
  setPairs ! ( in UInt32 index, in LocalL16UInt32Array skinIds, in LocalL16ScalarArray skinWeights )
String truncateDecimalsPrint ? ( in Size index, in UInt32 n )
String unitTestPrint ? ( in Size index )
String valueDesc ? ( in Size index )
UInt32ArrayAllocator weightsAllocator ? ()