GeometryAttributes.kl¶
Interfaces¶
GeometryAttribute (interface)¶
Interface required on an attribute in order to be contained in a GeometryAttributes container.
The GeometryAttribute interface contains the methods required by the GeometryAttributes container for managing the attribute values. By abstracting the attribute content, Geometry types can resize, duplicate or compare values without having a specific knowledge of the various attribute types. For example, this allows the PolygonMesh to manage attribute sharing, and it allows the GetAttributeAtLocation helper function to interpolate surface attribute values.
While various type implementations are provided, such as Vec3Attribute and ColorAttribute, this interface allows to add other custom attribute types to a GeometryAttributes container.
The GeometryAttribute requires specific data to be stored along the attribute values, such as a name, version and containerIndex.
注釈
The attribute version has to be incremented after any modification(s) to the attribute values. See Attribute versioning for more information.
Functions¶
Boolean | checkConsistency ? () |
convertToCPU ! () | |
convertToGPU ! () | |
copyFrom ! ( in Ref<Object> otherAttr ) | |
copyValue ! ( in Ref<Object> sourceAttr, in Size sourceIndex, in Size targetIndex ) | |
copyValue ! ( in Size sourceIndex, in Size targetIndex ) | |
Data | data ? () |
Boolean | equalValues ? ( in Size index1, in Size index2 ) |
String | getDesc ? ( in Boolean useUnitTestPrint ) |
String | getDesc ? () |
UInt32 | getElementsMemType ? () |
String | getName ? () |
Size | getScalarValueSize ? () |
UInt32 | getVersion ? () |
incrementVersion ! () | |
linearCombine ! ( in Ref<Object> sourceAttr, in LocalL16UInt32Array sourceIndices, in LocalL16ScalarArray sourceWeights, in Size targetIndex ) | |
resize ! ( in Size count ) | |
setFromScalar ! ( in Size index, in LocalL16ScalarArray value ) | |
Size | size ? () |
String | truncateDecimalsPrint ? ( in Size index, in UInt32 n ) |
String | unitTestPrint ? ( in Size index ) |
String | valueDesc ? ( in Size index ) |
Functions in detail¶
Boolean GeometryAttribute.checkConsistency? ()
バージョン 2.4.0 で追加.
Checks the attribute data consistency.
GeometryAttribute.convertToCPU! ()
GeometryAttribute.convertToGPU! ()
GeometryAttribute.copyFrom! ( in Ref<Object> otherAttr )
Sets the whole content of the attribute from the other attribute. The other attribute will be of the same type.
GeometryAttribute.copyValue! ( in Ref<Object> sourceAttr, in Size sourceIndex, in Size targetIndex )
Replaces the value located at targetIndex with source attribute’s value located at sourceIndex. The source attribute will be of the same type.
GeometryAttribute.copyValue! ( in Size sourceIndex, in Size targetIndex )
Replaces the value located at targetIndex with the value located at sourceIndex
Data GeometryAttribute.data? ()
Returns a raw pointer to contiguous attribute data, if applicable, and an uninitialized Data otherwise.
Boolean GeometryAttribute.equalValues? ( in Size index1, in Size index2 )
Return true if two values are logically equal.
String GeometryAttribute.getDesc? ( in Boolean useUnitTestPrint )
Returns a description of the attribute, including all values.
String GeometryAttribute.getDesc? ()
Returns a description of the attribute, including all values.
UInt32 GeometryAttribute.getElementsMemType? ()
String GeometryAttribute.getName? ()
Returns the name of the attribute.
Size GeometryAttribute.getScalarValueSize? ()
If all attribute values can be expressed as a constant Scalar array, returns the constant number of elements, 0 otherwise.
UInt32 GeometryAttribute.getVersion? ()
Returns the attribute values version. See Attribute versioning for more information.
GeometryAttribute.incrementVersion! ()
Increment attribute values’ version.
This must be called after value(s) have been modified. For better performance, it can be called only after all changes are finished. See Attribute versioning for more information.
GeometryAttribute.linearCombine! ( in Ref<Object> sourceAttr, in LocalL16UInt32Array sourceIndices, in LocalL16ScalarArray sourceWeights, in Size targetIndex )
Sets the value located at targetIndex as a linear combination of other values.
GeometryAttribute.resize! ( in Size count )
Resizes the attribute array.
GeometryAttribute.setFromScalar! ( in Size index, in LocalL16ScalarArray value )
If applicable, sets an attribute value from an array of Scalars. This array must have a size of GeometryAttribute.getScalarValueSize .
Size GeometryAttribute.size? ()
Returns the size of the attribute array.
String GeometryAttribute.truncateDecimalsPrint? ( in Size index, in UInt32 n )
Returns a description of the value, keeping the first n decimals (Float32 or Float64 based values).
String GeometryAttribute.unitTestPrint? ( in Size index )
Returns a numerically stable description of the value
String GeometryAttribute.valueDesc? ( in Size index )
Returns a description of the value
Types¶
GeometryAttributesIterator (struct)¶
An iterator for enumerating attributes contained in a GeometryAttributes .
Methods¶
GeometryAttributesIterator ( in GeometryAttributesIterator other ) | |
GeometryAttributesIterator () | |
GeometryAttributesIterator | clone ? () |
Ref<GeometryAttribute> | getNext ! () |
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
*/