====== Example Code ======
The easiest way to access vertex data that's been compiled in 5.x mode is to declare static structures for each geometry type and typecast away from the void* representing the compiled data (but the SDrawCall::GetProperty() functions will still work also). The section below details the vertex declarations the Compiler application generates for each geometry type.
----
===== Static Vertex Declarations====
These are the recommended vertex declarations to use for accessing 5.x-compiled vertex data. Note that vertex data is always stored as full 32-bit floats in this mode.
///////////////////////////////////////////////////////////////////////
// Structure S5xBranchVertex
//
// Compiler output of format in 5.x compatibility mode
//
// ATTR0 [ posi.x(0) posi.y(4) posi.z(8) texd.x(12) ] (32-bit floats)
// ATTR1 [ norm.x(16) norm.y(20) norm.z(24) texd.y(28) ] (32-bit floats)
// ATTR2 [ hint.x(32) texl.x(36) texl.y(40) aocc.x(44) ] (32-bit floats)
// ATTR3 [ tang.x(48) tang.y(52) tang.z(56) bsdt.x(60) ] (32-bit floats)
// ATTR4 [ bsdf.x(64) bsdf.y(68) bsdf.z(72) bsdt.y(76) ] (32-bit floats)
// ATTR5 [ lodp.x(80) lodp.y(84) lodp.z(88) ] (32-bit floats)
// ATTR6 [ wbrn.x(92) wbrn.y(96) wbrn.z(100) wbrn.w(104) ] (32-bit floats)
struct S5xBranchVertex
{
// attr0
st_float32 m_afPos[3];
st_float32 m_fDiffuseTexCoordU;
// attr1
st_float32 m_afNormal[3];
st_float32 m_fDiffuseTexCoordV;
// attr2
st_float32 m_fGeometryTypeHint;
st_float32 m_fDetailTexCoordU;
st_float32 m_fDetailTexCoordV;
st_float32 m_fAmbientOcclusion;
// attr3
st_float32 m_afTangent[3];
st_float32 m_fBranchSeamDetailTexCoordU;
// attr4
st_float32 m_fBranchSeamDiffuseTexCoordU;
st_float32 m_fBranchSeamDiffuseTexCoordV;
st_float32 m_fBranchSeamBlendWeight;
st_float32 m_fBranchSeamDetailTexCoordV;
// attr5
st_float32 m_afLodPos[3];
// attr6
st_float32 m_afBranchWindData[4];
};
///////////////////////////////////////////////////////////////////////
// Structure S5xFrondAndCapVertex
//
// Compiler output of format in 5.x compatibility mode
//
// ATTR0 [ posi.x(0) posi.y(4) posi.z(8) texd.x(12) ] (32-bit floats)
// ATTR1 [ norm.x(16) norm.y(20) norm.z(24) texd.y(28) ] (32-bit floats)
// ATTR2 [ hint.x(32) tang.x(36) tang.y(40) tang.z(44) ] (32-bit floats)
// ATTR3 [ aocc.x(48) lodp.x(52) lodp.y(56) lodp.z(60) ] (32-bit floats)
// ATTR4 [ wbrn.x(64) wbrn.y(68) wbrn.z(72) wbrn.w(76) ] (32-bit floats)
// ATTR5 [ wext.x(80) wext.y(84) wext.z(88) ] (32-bit floats)
struct S5xFrondAndCapVertex
{
// attr0
st_float32 m_afPos[3];
st_float32 m_fDiffuseTexCoordU;
// attr1
st_float32 m_afNormal[3];
st_float32 m_fDiffuseTexCoordV;
// attr2
st_float32 m_fGeometryTypeHint;
st_float32 m_afTangent[3];
// attr3
st_float32 m_fAmbientOcclusion;
st_float32 m_afLodPos[3];
// attr4
st_float32 m_afBranchWindData[4];
// attr5
st_float32 m_afExtendedWindData[3];
};
///////////////////////////////////////////////////////////////////////
// Structure S5xLeafVertex
//
// Compiler output of format in 5.x compatibility mode
//
// ATTR0 [ posi.x(0) posi.y(4) posi.z(8) texd.x(12) ] (32-bit floats)
// ATTR1 [ norm.x(16) norm.y(20) norm.z(24) texd.y(28) ] (32-bit floats)
// ATTR2 [ hint.x(32) tang.x(36) tang.y(40) tang.z(44) ] (32-bit floats)
// ATTR3 [ aocc.x(48) lodp.x(52) lodp.y(56) lodp.z(60) ] (32-bit floats)
// ATTR4 [ wbrn.x(64) wbrn.y(68) wbrn.z(72) wbrn.w(76) ] (32-bit floats)
// ATTR5 [ lanc.x(80) lanc.y(84) lanc.z(88) wflg.x(92) ] (32-bit floats)
// ATTR6 [ wext.x(96) wext.y(100) wext.z(104) ] (32-bit floats)
struct S5xLeafVertex
{
// attr0
st_float32 m_afPos[3];
st_float32 m_fDiffuseTexCoordU;
// attr1
st_float32 m_afNormal[3];
st_float32 m_fDiffuseTexCoordV;
// attr2
st_float32 m_fGeometryTypeHint;
st_float32 m_afTangent[3];
// attr3
st_float32 m_fAmbientOcclusion;
st_float32 m_afLodPos[3];
// attr4
st_float32 m_afLeafAnchorPoint[3];
st_float32 m_fWindFlag;
// attr5
st_float32 m_afBranchWindData[4];
// attr6
st_float32 m_afExtendedWindData[3];
};
///////////////////////////////////////////////////////////////////////
// Structure S5xFacingLeafVertex
//
// Compiler output of format in 5.x compatibility mode
//
// ATTR0 [ posi.x(0) posi.y(4) posi.z(8) texd.x(12) ] (32-bit floats)
// ATTR1 [ norm.x(16) norm.y(20) norm.z(24) texd.y(28) ] (32-bit floats)
// ATTR2 [ hint.x(32) tang.x(36) tang.y(40) tang.z(44) ] (32-bit floats)
// ATTR3 [ aocc.x(48) lfcc.x(52) lfcc.y(56) lfcc.z(60) ] (32-bit floats)
// ATTR4 [ wbrn.x(64) wbrn.y(68) wbrn.z(72) wbrn.w(76) ] (32-bit floats)
// ATTR5 [ wflg.x(80) lfcc.x(84) lfcc.y(88) lfcc.z(92) ] (32-bit floats)
// ATTR6 [ lfls.x(96) lfso.x(100) ] (32-bit floats)
struct S5xFacingLeafVertex
{
// attr0
st_float32 m_afPos[3];
st_float32 m_fDiffuseTexCoordU;
// attr1
st_float32 m_afNormal[3];
st_float32 m_fDiffuseTexCoordV;
// attr2
st_float32 m_fGeometryTypeHint;
st_float32 m_afTangent[3];
// attr3
st_float32 m_fAmbientOcclusion;
st_float32 m_afCorner[3];
// attr4
st_float32 m_afBranchWindData[4];
// attr5
st_float32 m_fWindFlag;
st_float32 m_afLeafCardCorner[3];
// attr6
st_float32 m_fLodScalar;
st_float32 m_fSelfShadowOffset;
};
///////////////////////////////////////////////////////////////////////
// Structure S5xRigidMeshes
//
// Compiler output of format in 5.x compatibility mode
//
// ATTR0 [ posi.x(0) posi.y(4) posi.z(8) texd.x(12) ] (32-bit floats)
// ATTR1 [ norm.x(16) norm.y(20) norm.z(24) texd.y(28) ] (32-bit floats)
// ATTR2 [ hint.x(32) tang.x(36) tang.y(40) tang.z(44) ] (32-bit floats)
// ATTR3 [ aocc.x(48) ] (32-bit floats)
// ATTR4 [ wbrn.x(52) wbrn.y(56) wbrn.z(60) wbrn.w(64) ] (32-bit floats)
struct S5xRigidMeshes
{
// attr0
st_float32 m_afPos[3];
st_float32 m_fDiffuseTexCoordU;
// attr1
st_float32 m_afNormal[3];
st_float32 m_fDiffuseTexCoordV;
// attr2
st_float32 m_fGeometryTypeHint;
st_float32 m_afTangent[3];
// attr3
st_float32 m_fAmbientOcclusion;
// attr4
st_float32 m_afBranchWindData[4];
};
///////////////////////////////////////////////////////////////////////
// Structure S5xGrass
//
// Compiler output of format in 5.x compatibility mode
//
// ATTR0 [ posi.x(0) posi.y(4) posi.z(8) texd.x(12) ] (32-bit floats)
// ATTR1 [ norm.x(16) norm.y(20) norm.z(24) texd.y(28) ] (32-bit floats)
// ATTR2 [ hint.x(32) tang.x(36) tang.y(40) tang.z(44) ] (32-bit floats)
// ATTR3 [ aocc.x(48) lanc.x(52) lanc.y(56) lanc.z(60) ] (32-bit floats)
// ATTR4 [ wbrn.x(64) wbrn.y(68) wbrn.z(72) wbrn.w(76) ] (32-bit floats)
// ATTR5 [ wext.x(80) wext.y(84) wext.z(88) wflg.x(92) ] (32-bit floats)
// ATTR6 [ lfcc.x(96) lfcc.y(100) lfcc.z(104) lfls.x(108) ] (32-bit floats)
// ATTR7 [ lfso.x(112) ] (32-bit floats)
struct S5xGrass
{
// attr0
st_float32 m_afPos[3];
st_float32 m_fDiffuseTexCoordU;
// attr1
st_float32 m_afNormal[3];
st_float32 m_fDiffuseTexCoordV;
// attr2
st_float32 m_fGeometryTypeHint;
st_float32 m_afTangent[3];
// attr3
st_float32 m_fAmbientOcclusion;
st_float32 m_afLeafAnchorPoint[3];
// attr4
st_float32 m_afBranchWindData[4];
// attr5
st_float32 m_afExtendedWindData[3];
st_float32 m_fWindFlag;
// attr6
st_float32 m_afLeafCardCorner[3];
st_float32 m_fLodScalar;
// attr7
st_float32 m_fSelfShadowOffset;
};
----
===== Example Vertex Access =====
The following example loads an arbitrary SRT model and prints the position values of the branch vertices using a static vertex branch declaration. Note that within the second for-loop, the code checks that 5.x mode is active and that the geometry type is branches. If frond geometry, for example, were accessed using the branch vertex structure, things would explode mightily.
|^**Note:** While accessing 5.x-compiled data using static vertex declarations is certainly convenient, there's no reason SDrawCall::GetProperty() couldn't be [[accessing_3d_geometry|used]] alternatively.^|
///////////////////////////////////////////////////////////////////////
// Accessing5xVertexData
void Accessing5xVertexData(void)
{
const char* pFilename = EXAMPLE_TREE1;
// load SRT file
CCore* pTree = Internal_LoadSrtFile(pFilename);
if (pTree)
{
// access tree's geometry
const SGeometry* pGeometry = pTree->GetGeometry( );
// each tree may have multiple LOD levels
for (int i = 0; i < pGeometry->m_nNumLods; ++i)
{
const SLod& sLod = pGeometry->m_pLods[i];
// each LOD has a number of "draw calls" which is simply a set
// of geometries that share the same material/render state
for (int j = 0; j < sLod.m_nNumDrawCalls; ++j)
{
const SDrawCall& sDrawCall = sLod.m_pDrawCalls[j];
// examine render state to make sure 5.x mode was used and
// that it has branch geometry (just for this example)
assert(sDrawCall.m_pRenderState);
if (sDrawCall.m_pRenderState->Is5xModeActive( ) &&
sDrawCall.m_pRenderState->m_bBranchesPresent)
{
// access as raw byte pointer
const st_byte* pRawVertexData = static_cast(sDrawCall.m_pVertexData);
// cast to static branch vertex struct
const S5xBranchVertex* pVertices = reinterpret_cast(pRawVertexData);
for (int k = 0; k < sDrawCall.m_nNumVertices; ++k)
{
printf("pos: (%g, %g, %g)\n",
pVertices[k].m_afPos[0], pVertices[k].m_afPos[1], pVertices[k].m_afPos[2]);
}
}
}
}
st_delete(pTree);
}
}