This template class encapsulates ICEAttribute data as a 2D array. CICEAttributeDataArray2D objects are read-only and can be filled with the methods supplied with the ICEAttribute class. CICEAttributeDataArray2D is zero-based and can be one of the following types:
All types are associated to specific ICEAttribute 2D types. Therefore, you need to declare the right array object type that matches the ICEAttribute data type you want to access. Otherwise a runtime error will occur and the returned array will be empty.
using namespace XSI; X3DObject cone = CreatePrim( L"Cone", L"MeshSurface", L"", L""); Create2DSkeleton( 2.95, 3.34, -0.33, 4.73, 0.0, 0.0, -5.71, 0, 0, 4, CValue(""), CValue("")); AppendBone( L"eff", 3.70, -3.02, 0.30, L""); XSI::siConstructionMode mode = siConstructionModeModeling; ApplyFlexEnv( L"cone;bone,bone1,eff", true, mode ); SelectObj( L"cone.polymsh.cls.EnvelopWeightCls.Envelope_Weights", L"", L"" ); // Make sure to generate the data first cone.GetActivePrimitive().GetGeometry(0); Application xsi; ProjectItem envProp = xsi.GetSelection()[0]; ICEAttribute attr = envProp.GetICEAttributeFromName( L"EnvelopeWeightsPerDeformer" ); CICEAttributeDataArray2DFloat weight2D; attr.GetDataArray2D( weight2D ); for( ULONG i=0; i<weight2D.GetCount( ); i++ ) { CICEAttributeDataArray< float > weights; weight2D.GetSubArray( i, weights ); for( ULONG j=0; j<weights.GetCount( ); j++ ) { xsi.LogMessage( CString( weights[ j ] ) ); } } // Helpers CValue CreatePrim( const CString& in_presetobj, const CString& in_geometrytype, const CString& in_name, const CString& in_parent ) { CValueArray args(4); CValue retval; args[0]= in_presetobj; args[1]= in_geometrytype; args[2]= in_name; args[3]= in_parent; Application app; app.ExecuteCommand( L"CreatePrim", args, retval ); return retval; } CValue Create2DSkeleton( const CValue& in_rx, const CValue& in_ry, const CValue& in_rz, const CValue& in_ex, const CValue& in_ey, const CValue& in_ez, const CValue& in_nx, const CValue& in_ny, const CValue& in_nz, const CValue& in_viewtype, CValue& out_bone, CValue& out_effector ) { CValueArray args(12); CValue retval; args[0]= in_rx; args[1]= in_ry; args[2]= in_rz; args[3]= in_ex; args[4]= in_ey; args[5]= in_ez; args[6]= in_nx; args[7]= in_ny; args[8]= in_nz; args[9]= in_viewtype; Application app; app.ExecuteCommand( L"Create2DSkeleton", args, retval ); out_bone = args[10]; out_effector = args[11]; return retval; } CValue AppendBone( const CValue& in_inputobjs, const CValue& in_ex, const CValue& in_ey, const CValue& in_ez, bool in_pin ) { CValueArray args(5); CValue retval; args[0]= in_inputobjs; args[1]= in_ex; args[2]= in_ey; args[3]= in_ez; args[4]= in_pin; Application app; app.ExecuteCommand( L"AppendBone", args, retval ); return retval; } CValue ApplyFlexEnv( const CValue& in_connectionset, bool in_assignnewdeformers, XSI::siConstructionMode & io_constructionmode ) { CValueArray args(3); CValue retval; args[0]= in_connectionset; args[1]= in_assignnewdeformers; args[2]= io_constructionmode; Application app; app.ExecuteCommand( L"ApplyFlexEnv", args, retval ); io_constructionmode = (XSI::siConstructionMode)(LONG)args[2]; return retval; } void SelectObj( const CValue& in_selectionlist, const CString& in_hierarchylevel, bool in_checkobjectselectability ) { CValueArray args(3); CValue retval; args[0]= in_selectionlist; args[1]= in_hierarchylevel; args[2]= in_checkobjectselectability; Application app; CStatus st = app.ExecuteCommand( L"SelectObj", args, retval ); return; }
using namespace XSI; CValue CreatePrim( const CString& in_presetobj, const CString& in_geometrytype, const CString& in_name, const CString& in_parent ) { CValueArray args(4); CValue retval; args[0]= in_presetobj; args[1]= in_geometrytype; args[2]= in_name; args[3]= in_parent; Application app; app.ExecuteCommand( L"CreatePrim", args, retval ); return retval; } template < class T > class CICEAttributeData2D { public: static void Log( ICEAttribute& attr ) { Application xsi; xsi.LogMessage( L"*******************************************************************" ); xsi.LogMessage( L"Name: " + attr.GetName() ); xsi.LogMessage( L"DataType: " + CString(attr.GetDataType()) ); CICEAttributeDataArray2D< T > data2D; attr.GetDataArray2D( data2D ); for( ULONG i=0; i<data2D.GetCount( ); i++ ) { CICEAttributeDataArray< T > data; data2D.GetSubArray( i, data ); for( ULONG j=0; j<data.GetCount( ); j++ ) { xsi.LogMessage( CString( j ) + " " + CString( data[ j ] ) ); } } } static void SetData( const X3DObject & in_Obj, XSI::siICENodeDataType in_DataType, const CString& in_csDataName, const T in_Value ) { ICEAttribute attr = in_Obj.GetActivePrimitive().GetGeometry().AddICEAttribute( in_csDataName, in_DataType, XSI::siICENodeStructureArray, XSI::siICENodeContextComponent0D ); CICEAttributeDataArray2D< T > data2D; attr.GetDataArray2D( data2D ); CICEAttributeDataArray< T > data; ULONG subArraySize = 6; // This can be any number. data2D.ResizeSubArray( 0 ,subArraySize ,data ); T l_Values[subArraySize] = { in_Value, in_Value, in_Value, in_Value, in_Value, in_Value }; memcpy( &data[0], &l_Values[0], subArraySize * sizeof(T) ); CICEAttributeData2D<T>::Log( attr ); } }; template < > class CICEAttributeData2D< bool > { public: static void Log( ICEAttribute& attr ) { Application xsi; xsi.LogMessage( L"*******************************************************************" ); xsi.LogMessage( L"Name: " + attr.GetName() ); xsi.LogMessage( L"DataType: " + CString(attr.GetDataType()) ); CICEAttributeDataArray2D< bool > data2D; attr.GetDataArray2D( data2D ); for( ULONG i=0; i<data2D.GetCount( ); i++ ) { CICEAttributeDataArray< bool > data; data2D.GetSubArray( i, data ); for( ULONG j=0; j<data.GetCount( ); j++ ) { xsi.LogMessage( CString( j ) + " " + CString( data[ j ] ) ); } } } static void SetData( const X3DObject & in_Obj, XSI::siICENodeDataType in_DataType, const CString& in_csDataName, const bool in_Value ) { ICEAttribute attr = in_Obj.GetActivePrimitive().GetGeometry().AddICEAttribute( in_csDataName, in_DataType, XSI::siICENodeStructureArray, XSI::siICENodeContextComponent0D ); CICEAttributeDataArray2D< bool > data2D; attr.GetDataArray2D( data2D ); CICEAttributeDataArray< bool > data; ULONG subArraySize = 6; // This can be any number. data2D.ResizeSubArray( 0, subArraySize, data ); data.SetData(0, in_Value); data.SetData(1, !in_Value); data.SetData(2, in_Value); data.SetData(3, !in_Value); data.SetData(4, in_Value); data.SetData(5, !in_Value); CICEAttributeData2D<bool>::Log( attr ); } }; template < > class CICEAttributeData2D< XSI::CString > { public: static void Log( ICEAttribute& attr ) { CICEAttributeDataArray2DString data2D; attr.GetDataArray2D( data2D ); Application xsi; for( ULONG i=0; i<data2D.GetCount( ); i++ ) { CICEAttributeDataArrayString data; data2D.GetSubArray( i, data ); for( ULONG j=0; j<data.GetCount( ); j++ ) { xsi.LogMessage( CString( i ) + " , " + CString( j ) + " : " +data[ j ] ); } } } static void SetData( const X3DObject & in_Cone, XSI::siICENodeDataType in_DataType, const CString& in_csDataName, const XSI::CString in_Value ) { ICEAttribute attr = in_Cone.GetActivePrimitive().GetGeometry().AddICEAttribute( in_csDataName, in_DataType, XSI::siICENodeStructureArray, XSI::siICENodeContextComponent0D ); CICEAttributeDataArray2DString data2D; attr.GetDataArray2D( data2D ); { CICEAttributeDataArrayString data; ULONG subArraySize = 6; // This can be any number. data2D.ResizeSubArray( 0, subArraySize, data ); data.SetData(0, in_Value); data.SetData(2, in_Value); data.SetData(4, in_Value); } { CICEAttributeDataArrayString data; ULONG subArraySize = 24; // This can be any number. data2D.ResizeSubArray( 1, subArraySize, data ); data.SetData(0, in_Value); data.SetData(12, in_Value); data.SetData(60, in_Value); } CICEAttributeData2D<XSI::CString>::Log( attr ); } }; void SetDataArray2D( const X3DObject & in_Cone ) { CICEAttributeData2D<LONG>::SetData( in_Cone, XSI::siICENodeDataLong, "TestLong", 20 ); CICEAttributeData2D<float>::SetData( in_Cone, XSI::siICENodeDataFloat, "Testfloat", -20 ); CICEAttributeData2D<bool>::SetData( in_Cone, XSI::siICENodeDataBool, "TestBOOL", true ); MATH::CVector2f Vec2f( 20, -20); CICEAttributeData2D<MATH::CVector2f>::SetData( in_Cone, XSI::siICENodeDataVector2, "TestVector2", Vec2f ); MATH::CVector3f Vec3f( 20, -20, 20); CICEAttributeData2D<MATH::CVector3f>::SetData( in_Cone, XSI::siICENodeDataVector3, "TestVector3", Vec3f ); MATH::CVector4f Vec4f( 20, -20, 20, -20); CICEAttributeData2D<MATH::CVector4f>::SetData( in_Cone, XSI::siICENodeDataVector4, "TestVector4", Vec4f ); MATH::CQuaternionf Quat( 20, -20, 20 ,20); CICEAttributeData2D<MATH::CQuaternionf>::SetData( in_Cone, XSI::siICENodeDataQuaternion, "TestQuat", Quat ); MATH::CRotationf Rot( 45, -45, 45 ); CICEAttributeData2D<MATH::CRotationf>::SetData( in_Cone, XSI::siICENodeDataRotation, "TestRot", Rot ); MATH::CMatrix3f Mat3( 1, 2, 3, 4, 5, 6, 7, 8, 9); CICEAttributeData2D<MATH::CMatrix3f>::SetData( in_Cone, XSI::siICENodeDataMatrix33, "TestMat3", Mat3 ); MATH::CMatrix4f Mat4( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ); CICEAttributeData2D<MATH::CMatrix4f>::SetData( in_Cone, XSI::siICENodeDataMatrix44, "TestMat4", Mat4 ); MATH::CColor4f Col4( 20, -20, 20, 1); CICEAttributeData2D<MATH::CColor4f>::SetData( in_Cone, XSI::siICENodeDataColor4, "TestCol4", Col4 ); CICEAttributeData2D<CString>::SetData( in_Cone, XSI::siICENodeDataString, "TestString", "hum!" ); } { Application xsi; CreatePrim( L"Cone", L"MeshSurface", L"", L""); Selection selection = xsi.GetSelection(); X3DObject cone = selection[0]; SetDataArray2D( cone ); }
#include <xsi_iceattributedataarray2D.h>
Public Member Functions |
|
CICEAttributeDataArray2D () | |
~CICEAttributeDataArray2D () | |
CStatus | GetSubArray (ULONG in_index, CICEAttributeDataArray< T > &out_dataArray) const |
CStatus | ResizeSubArray (ULONG in_index, ULONG in_ulSize, CICEAttributeDataArray< T > &out_dataArray) |
CICEAttributeDataArray2D | ( | ) | [inline] |
Constructor.
~CICEAttributeDataArray2D | ( | ) | [inline] |
Destructor.
CStatus GetSubArray | ( | ULONG | in_index, |
CICEAttributeDataArray< T > & | out_dataArray | ||
) | const [inline] |
Accessor to the encapsulated array. This operator is called when reading the data so the return value is read-only.
in_index | Index in the array. The index must be smaller than the number of elements in the array, otherwise the result is unpredictable. |
out_dataArray | A read-only reference to a
CICEAttributeDataArray<T> object at a specific
index. |
in_index
or
out_dataArray
is invalid.CStatus ResizeSubArray | ( | ULONG | in_index, |
ULONG | in_ulSize, | ||
CICEAttributeDataArray< T > & | out_dataArray | ||
) | [inline] |
Changes the size of the sub-array at a given index and returns a new array pointing to the resized sub-array. This is only supported for writable attributes and not available for built-in attributes.
in_index | Index in the array. The index must be smaller than the number of elements in the array, otherwise the result is unpredictable. |
out_dataArray | A reference to a CICEAttributeDataArray<T>
object at a specific index. |
in_ulSize | The size of the array. |
in_index
or
out_dataArray
is invalid.