示例#1
0
// Build default indices array.
void ModelRenderer::BuildIndices(
		const CModelDefPtr& mdef,
		const VertexArrayIterator<u16>& Indices)
{
	size_t idxidx = 0;
	SModelFace* faces = mdef->GetFaces();

	for (size_t j = 0; j < mdef->GetNumFaces(); ++j) {
		SModelFace& face=faces[j];
		Indices[idxidx++]=face.m_Verts[0];
		Indices[idxidx++]=face.m_Verts[1];
		Indices[idxidx++]=face.m_Verts[2];
	}
}
示例#2
0
float PSModel::BackToFrontIndexSort(const CMatrix3D& worldToCam)
{
    static std::vector<IntFloatPair> IndexSorter;

    CModelDefPtr mdef = m_Model->GetModelDef();
    size_t numFaces = mdef->GetNumFaces();
    const SModelFace* faces = mdef->GetFaces();

    if (IndexSorter.size() < numFaces)
        IndexSorter.resize(numFaces);

    VertexArrayIterator<CVector3D> Position = m_Position.GetIterator<CVector3D>();
    CVector3D tmpvtx;

    for(size_t i = 0; i < numFaces; ++i)
    {
        tmpvtx = Position[faces[i].m_Verts[0]];
        tmpvtx += Position[faces[i].m_Verts[1]];
        tmpvtx += Position[faces[i].m_Verts[2]];
        tmpvtx *= 1.0f/3.0f;

        tmpvtx = worldToCam.Transform(tmpvtx);
        float distsqrd = SQR(tmpvtx.X)+SQR(tmpvtx.Y)+SQR(tmpvtx.Z);

        IndexSorter[i].first = (int)i;
        IndexSorter[i].second = distsqrd;
    }

    std::sort(IndexSorter.begin(),IndexSorter.begin()+numFaces,SortFacesByDist());

    // now build index list
    size_t idxidx = 0;
    for (size_t i = 0; i < numFaces; ++i) {
        const SModelFace& face = faces[IndexSorter[i].first];
        m_Indices[idxidx++] = (u16)(face.m_Verts[0]);
        m_Indices[idxidx++] = (u16)(face.m_Verts[1]);
        m_Indices[idxidx++] = (u16)(face.m_Verts[2]);
    }

    return IndexSorter[0].second;
}