This class provides access to the render hair information exposed by the hair primitive. This information includes: the vertex positions of each generated render hair, the root/tip radius values, the UVW, weight map and vertex color values for each render hair root location.
CRenderHairAccessor provides a mechanism to access the data in chunks which allows you to optimize the memory allocation required for accessing such a large data set.
Use HairPrimitive::GetRenderHairAccessor to create an instance of CRenderHairAccessor.
- See also:
- HairPrimitive
- Since:
- 5.0
- Example:
- This example demonstrates how to use the render hair accessor to extract the render hair data from a hair primitive.
using namespace XSI;
Application app;
Model root = app.GetActiveSceneRoot();
X3DObject myCone;
root.AddGeometry( L"Cone", L"MeshSurface",L"myCone",myCone);
Material myMat;
myCone.AddMaterial(L"Phong", false, L"myMat", myMat);
Shader sh = myMat.GetShaders().GetItem(0);
Parameter p = sh.GetParameters().GetItem(L"diffuse");
CRef newSource;
CRef prevSource;
p.ConnectFromPreset( L"Image", siTextureShaderFamily, prevSource, newSource );
CValueArray args(7);
CValue outArg;
args[0] = myCone.GetFullName();
args[1] = CString(L"siTxtSpherical");
args[2] = CString(L"siTxtDefaultSpherical");
args[3] = CValue();
args[4] = CString(L"Texture_Projection");
args[5] = CValue();
args[6] = CValue((LONG)XSI::siRelDefault);
app.ExecuteCommand( L"CreateProjection", args, outArg );
args.Resize(3);
args[0] = myCone.GetFullName();
args[1] = CString(L"Sources.Materials.DefaultLib.myMat.Phong.Image.tspace_id");
args[2] = CString(L"Texture_Projection");
app.ExecuteCommand( L"SetInstanceDataValue", args, outArg );
args.Resize(1);
args[0] = myCone;
app.ExecuteCommand( L"ApplyHairOp", args, outArg ) ;
X3DObject myHair = myCone.FindChild( L"Hair", L"", CStringArray() );
args.Resize(2);
args[0] = myHair.GetFullName();
args[1] = CString(L"myCone.polymsh.cls.Texture_Coordinates_AUTO.Texture_Projection");
app.ExecuteCommand( L"PropertyTransfer", args, outArg ) ;
HairPrimitive myHairPrim( myHair.GetActivePrimitive() );
CRenderHairAccessor rha = myHairPrim.GetRenderHairAccessor( 100, 10 );
LONG nReqChunkSize = rha.GetRequestedChunkSize();
app.LogMessage( L"nReqChunkSize: " + CValue(nReqChunkSize).GetAsText() );
LONG nReqHairCount = rha.GetRequestedHairCount();
app.LogMessage( L"nReqHairCount: " + CValue(nReqHairCount).GetAsText() );
LONG nUVs = rha.GetUVCount();
app.LogMessage( L"nUVs: " + CValue(nUVs).GetAsText() );
LONG nChunk = 0;
LONG i=0;
while( rha.Next() )
{
app.LogMessage( L"Chunk: " + CValue(nChunk++).GetAsText() );
CLongArray verticesCountArray;
rha.GetVerticesCount(verticesCountArray);
CFloatArray posVals;
rha.GetVertexPositions(posVals);
LONG k = 0;
app.LogMessage( L"Render hair position values: " );
for (i=0; i<verticesCountArray.GetCount(); i++ )
{
LONG nCount = verticesCountArray[i];
for (LONG j=0; j<nCount; j++ )
{
CString strVals;
strVals=
CValue(posVals[k++]).GetAsText() + CString(L" ") +
CValue(posVals[k++]).GetAsText() + CString(L" ") +
CValue(posVals[k++]).GetAsText() ;
app.LogMessage( CValue(i).GetAsText() + L": " + strVals );
}
}
app.LogMessage( L"Render hair radius values: " );
CFloatArray radVals;
rha.GetVertexRadiusValues(radVals);
k = 0;
for (i=0; i<verticesCountArray.GetCount(); i++ )
{
LONG nCount = verticesCountArray[i];
for (LONG j=0; j<nCount; j++ )
{
app.LogMessage( CValue(i).GetAsText() + L": " +
CValue(radVals[k++]).GetAsText() );
}
}
app.LogMessage( L"Render hair uv values: " );
for (i=0; i<nUVs; i++)
{
app.LogMessage( L" UV: " + rha.GetUVName(i) );
CFloatArray uvVals;
rha.GetUVValues( i, uvVals );
for (LONG j=0,k=0; j<uvVals.GetCount(); j+=3, k++)
{
CString strVals;
strVals =
CValue(uvVals[j+0]).GetAsText() + L" " +
CValue(uvVals[j+1]).GetAsText() + L" " +
CValue(uvVals[j+2]).GetAsText() ;
app.LogMessage( CValue(k).GetAsText() + L": " + strVals );
}
}
}
Returns an array of UVW values for the UV property at the specified index. The values match the render hair root locations on the primitive. The index refers to the position of the property on the primitive.
In general, the size of the returned array is GetRenderHairAccessor::GetChunkHairCount() * 3. However, in the case where render hairs are generated in an area where they get cut due to a cut map or where the density decreases, the number of values returned is smaller.
- Parameters:
-
- Return values:
-
- Returns:
- CStatus::OK success
- See also:
- GetRenderHairAccessor::GetUVCount, GetRenderHairAccessor::GetUVName
Returns an array of vertex color values (RGBA) for the vertex color property at the specified index. The values match the render hair root locations on the primitive. The index refers to the position of the property on the primitive.
In general, the size of the returned array is GetRenderHairAccessor::GetChunkHairCount() * 4. However, in the case where render hairs are generated in an area where they get cut due to a cut map or where the density decreases, the number of values returned is smaller.
- Parameters:
-
- Return values:
-
out_values | RGBA color values ranging from 0.0 to 1.0. |
- Returns:
- CStatus::OK success
- See also:
- GetRenderHairAccessor::GetVertexColorCount, GetRenderHairAccessor::GetVertexColorName
Returns an array of weight map values (W) for the weight map property at the specified index. The values match the render hair root locations on the primitive. The index refers to the position of the property on the primitive.
In general, the size of the returned array is GetRenderHairAccessor::GetChunkHairCount(). However, in the case where render hairs are generated in an area where they get cut due to a cut map or where the density decreases, the number of values returned is smaller.
- Parameters:
-
- Return values:
-
out_values | Weight map values. |
- Returns:
- CStatus::OK success
- See also:
- GetRenderHairAccessor::GetWeightMapCount, GetRenderHairAccessor::GetWeightMapName