// *************************************************************************** void CShapeInfo::build(const CMeshBase &meshBase, const CMeshGeom &meshGeom) { // Get the vertex buffer const CVertexBuffer &vb=meshGeom.getVertexBuffer(); CVertexBufferRead vba; vb.lock (vba); // For each matrix block uint numBlock=meshGeom.getNbMatrixBlock(); for (uint block=0; block<numBlock; block++) { // For each render pass uint numRenderPass=meshGeom.getNbRdrPass(block); for (uint pass=0; pass<numRenderPass; pass++) { // Get the material const CMaterial &material = meshBase.getMaterial (meshGeom.getRdrPassMaterial ( block, pass)); if (material.getBlend()) continue; // don't test against transparent materials //if (material.getAlphaTest()) continue; // don't test against transparent materials // Get the primitive block const CIndexBuffer &primitive=meshGeom.getRdrPassPrimitiveBlock ( block, pass); // Copy triangles CIndexBufferRead iba; primitive.lock (iba); if (iba.getFormat() == CIndexBuffer::Indices32) { const uint32* triIndex= (const uint32*) iba.getPtr (); uint numTri=primitive.getNumIndexes ()/3; uint tri; for (tri=0; tri<numTri; tri++) { // Vertex CVector v0= *vba.getVertexCoordPointer (triIndex[tri*3]); CVector v1= *vba.getVertexCoordPointer (triIndex[tri*3+1]); CVector v2= *vba.getVertexCoordPointer (triIndex[tri*3+2]); Tris.push_back(NLMISC::CTriangle (v0, v1, v2)); } } else { const uint16* triIndex= (const uint16*) iba.getPtr (); uint numTri=primitive.getNumIndexes ()/3; uint tri; for (tri=0; tri<numTri; tri++) { // Vertex CVector v0= *vba.getVertexCoordPointer (triIndex[tri*3]); CVector v1= *vba.getVertexCoordPointer (triIndex[tri*3+1]); CVector v2= *vba.getVertexCoordPointer (triIndex[tri*3+2]); Tris.push_back(NLMISC::CTriangle (v0, v1, v2)); } } } } }
void FlagVerticesMRM (CMeshMRMGeom &mg, uint InMatID, vector<bool> &verticesNeedRemap) { CVertexBuffer &vertexBuffer = const_cast<CVertexBuffer&>(mg.getVertexBuffer()); // For each matrix block uint matrixBlock; uint nbMatrixBlock=1;//mg.getNbMatrixBlock(); // ASK YOYO for (matrixBlock=0; matrixBlock<nbMatrixBlock; matrixBlock++) { // For each render pass uint renderPass; uint numRenderPass=mg.getNbRdrPass(matrixBlock); for (renderPass=0; renderPass<numRenderPass; renderPass++) { // Render pass material uint32 matId=mg.getRdrPassMaterial(matrixBlock, renderPass); if (matId == InMatID) // Same Material -> Flag all vertices of this pass { // Get primitives const CIndexBuffer &primitiveBlock=mg.getRdrPassPrimitiveBlock(matrixBlock,renderPass); CIndexBufferRead iba; primitiveBlock.lock (iba); // Set of vertex to remap std::set<uint> vertexToRemap; // Remap triangles uint index; if (iba.getFormat() == CIndexBuffer::Indices32) { const uint32 *indexPtr=(const uint32 *)iba.getPtr(); uint32 numIndex=primitiveBlock.getNumIndexes(); for (index=0; index<numIndex; index++) vertexToRemap.insert (indexPtr[index]); } else { const uint16 *indexPtr=(const uint16 *)iba.getPtr(); uint32 numIndex=primitiveBlock.getNumIndexes(); for (index=0; index<numIndex; index++) vertexToRemap.insert (indexPtr[index]); } // Remap the vertex std::set<uint>::iterator iteRemap=vertexToRemap.begin(); while (iteRemap!=vertexToRemap.end()) { // Remap the vertex verticesNeedRemap[*iteRemap] = true; // Next vertex iteRemap++; } } } } }
// *************************************************************************** void CVegetableShape::build(CVegetableShapeBuild &vbuild) { // Must have TexCoord0. nlassert( vbuild.VB.getVertexFormat() & CVertexBuffer::TexCoord0Flag ); // Header //--------- // Lighted ? if(vbuild.Lighted && ( vbuild.VB.getVertexFormat() & CVertexBuffer::NormalFlag) ) Lighted= true; else Lighted= false; // DoubleSided DoubleSided= vbuild.DoubleSided; // PreComputeLighting. PreComputeLighting= Lighted && vbuild.PreComputeLighting; // AlphaBlend: valid only for 2Sided and Unlit (or similar PreComputeLighting) mode AlphaBlend= vbuild.AlphaBlend && DoubleSided && (!Lighted || PreComputeLighting); // BestSidedPreComputeLighting BestSidedPreComputeLighting= PreComputeLighting && vbuild.BestSidedPreComputeLighting; // BendCenterMode BendCenterMode= vbuild.BendCenterMode; // Format of the VB. uint32 format; format= CVertexBuffer::PositionFlag | CVertexBuffer::TexCoord0Flag | CVertexBuffer::TexCoord1Flag; // lighted? if(Lighted) format|= CVertexBuffer::NormalFlag; // set VB. VB.setVertexFormat(format); // Fill triangles. //--------- uint i; // resisz TriangleIndices.resize(vbuild.PB.getNumIndexes()); CIndexBufferRead ibaRead; vbuild.PB.lock (ibaRead); const uint32 *srcTri= (const uint32 *) ibaRead.getPtr(); // fill for(i=0; i<vbuild.PB.getNumIndexes()/3; i++) { TriangleIndices[i*3+0]= *(srcTri++); TriangleIndices[i*3+1]= *(srcTri++); TriangleIndices[i*3+2]= *(srcTri++); } // Fill vertices. //--------- // resize uint32 nbVerts= vbuild.VB.getNumVertices(); VB.setNumVertices(nbVerts); CVertexBufferRead vba; vbuild.VB.lock (vba); CVertexBufferReadWrite vbaOut; VB.lock (vbaOut); // if no vertex color, float maxZ= 0; bool bendFromColor= true; if(! (vbuild.VB.getVertexFormat() & CVertexBuffer::PrimaryColorFlag) ) { // must compute bendWeight from z. bendFromColor= false; // get the maximum Z. for(i=0;i<nbVerts;i++) { float z= (vba.getVertexCoordPointer(i))->z; maxZ= max(z, maxZ); } // if no positive value, bend will always be 0. if(maxZ==0) maxZ= 1; } // For all vertices, fill for(i=0;i<nbVerts;i++) { // Position. const CVector *srcPos= vba.getVertexCoordPointer(i); CVector *dstPos= vbaOut.getVertexCoordPointer(i); *dstPos= *srcPos; // Normal if(Lighted) { const CVector *srcNormal= vba.getNormalCoordPointer(i); CVector *dstNormal= vbaOut.getNormalCoordPointer(i); *dstNormal= *srcNormal; } // Texture. const CUV *srcUV= vba.getTexCoordPointer(i, 0); CUV *dstUV= vbaOut.getTexCoordPointer(i, 0); *dstUV= *srcUV; // Bend. // copy to texture stage 1. CUV *dstUVBend= vbaOut.getTexCoordPointer(i, 1); if(bendFromColor) { // todo hulud d3d vertex color RGBA / BGRA const CRGBA *srcColor= (const CRGBA*)vba.getColorPointer(i); // Copy and scale by MaxBendWeight dstUVBend->U= (srcColor->R / 255.f) * vbuild.MaxBendWeight; } else { float w= srcPos->z / maxZ; w= max(w, 0.f); // Copy and scale by MaxBendWeight dstUVBend->U= w * vbuild.MaxBendWeight; } } // Misc. //--------- // prepare for instanciation InstanceVertices.resize(VB.getNumVertices()); }