Beispiel #1
0
void CEditableMesh::GenerateSVertices(u32 influence)
{
	if (!m_Parent->IsSkeleton())return;

    m_SVertRefs++;
    if (m_SVertInfl!=influence) UnloadSVertices(true);
    if (m_SVertices) 	return;
	m_SVertices			= xr_alloc<st_SVert>(m_FaceCount*3);
    m_SVertInfl			= influence;

//	CSMotion* active_motion=m_Parent->ResetSAnimation();
    m_Parent->CalculateAnimation(0);

    // generate normals
	GenerateFNormals	();
	GenerateVNormals	();

    for (u32 f_id=0; f_id<m_FaceCount; f_id++){
        st_Face& F 		= m_Faces[f_id];
        for (int k=0; k<3; k++){
	    	st_SVert& SV			= m_SVertices[f_id*3+k];
	    	Fvector&  N				= m_VNormals[f_id*3+k];
            st_FaceVert& fv 		= F.pv[k];
	    	Fvector&  P 			= m_Verts[fv.pindex];
            st_VMapPtLst& vmpt_lst 	= m_VMRefs[fv.vmref];
            st_VertexWB		wb;
            for (u8 vmpt_id=0; vmpt_id!=vmpt_lst.count; vmpt_id++){
                st_VMap& VM = *m_VMaps[vmpt_lst.pts[vmpt_id].vmap_index];
                if (VM.type==vmtWeight){
                    wb.push_back(st_WB(m_Parent->GetBoneIndexByWMap(VM.name.c_str()),VM.getW(vmpt_lst.pts[vmpt_id].index)));
                    if (wb.back().bone==BI_NONE){
                        ELog.DlgMsg	(mtError,"Can't find bone assigned to weight map %s",*VM.name);
                        FATAL("Editor crashed.");
                        return;
                    }
                }else if(VM.type==vmtUV){	
//                 	R_ASSERT2(!uv,"More than 1 uv per vertex found.");
                    SV.uv.set(VM.getUV(vmpt_lst.pts[vmpt_id].index));
                }
            }

            VERIFY(m_SVertInfl<=4);
            
            wb.prepare_weights(m_SVertInfl);

            SV.offs	= P;
            SV.norm	= N;
            SV.bones.resize(wb.size());
            for (u8 k=0; k<(u8)SV.bones.size(); k++){	SV.bones[k].id=wb[k].bone; SV.bones[k].w=wb[k].weight; }
        }
	}

    // restore active motion
	UnloadFNormals	();
	UnloadVNormals	();
}
Beispiel #2
0
//----------------------------------------------------
void CEditableMesh::Transform(const Fmatrix& parent)
{
	// transform position
	for(u32 k=0; k<m_VertCount; k++)
		parent.transform_tiny(m_Verts[k]);
    // RecomputeBBox
	RecomputeBBox	();
    // update normals & cform
#ifdef _EDITOR
	UnloadRenderBuffers	();
	UnloadCForm		();
#endif
    UnloadFNormals	(true);
    UnloadVNormals	(true);
    UnloadSVertices	(true);
}
Beispiel #3
0
void CEditableMesh::Clear()           
{
#ifdef _EDITOR
	UnloadRenderBuffers	();
#endif
    UnloadAdjacency		();
    UnloadCForm			();
    UnloadFNormals		();
    UnloadVNormals		();
    UnloadSVertices		();

	VERIFY				(m_FNormalsRefs==0 && m_VNormalsRefs==0 && m_AdjsRefs==0 && m_SVertRefs==0);

    xr_free				(m_Verts);
    xr_free				(m_Faces);
	for (VMapIt vm_it=m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++)
		xr_delete		(*vm_it);
    m_VMaps.clear		();
    m_SurfFaces.clear	();
	for (VMRefsIt ref_it=m_VMRefs.begin(); ref_it!=m_VMRefs.end(); ref_it++)
		xr_free			(ref_it->pts);
    m_VMRefs.clear		();
}
Beispiel #4
0
void CEditableMesh::Optimize(BOOL NoOpt)
{
	if (!NoOpt){
#ifdef _EDITOR
    	UnloadRenderBuffers	();
		UnloadCForm     	();
#endif
        UnloadFNormals   	(true);
        UnloadVNormals   	(true);
       	UnloadSVertices  	(true);
       	UnloadAdjacency		(true);
    	
		// clear static data
		for (int x=0; x<MX+1; x++)
			for (int y=0; y<MY+1; y++)
    			for (int z=0; z<MZ+1; z++)
            		VM[x][y][z].clear();
		VMscale.set(m_Box.max.x-m_Box.min.x+EPS_S, m_Box.max.y-m_Box.min.y+EPS_S, m_Box.max.z-m_Box.min.z+EPS_S);
		VMmin.set(m_Box.min.x, m_Box.min.y, m_Box.min.z);

		VMeps.set(VMscale.x/MX/2,VMscale.y/MY/2,VMscale.z/MZ/2);
		VMeps.x = (VMeps.x<EPS_L)?VMeps.x:EPS_L;
		VMeps.y = (VMeps.y<EPS_L)?VMeps.y:EPS_L;
		VMeps.z = (VMeps.z<EPS_L)?VMeps.z:EPS_L;

		m_NewPoints.clear();
		m_NewPoints.reserve(m_VertCount);
                                                
		boolVec 	faces_mark;
		faces_mark.resize(m_FaceCount,false);
        int			i_del_face 		= 0;
		for (u32 k=0; k<m_FaceCount; k++){
    		if (!OptimizeFace(m_Faces[k])){
				faces_mark[k]		= true;
                i_del_face			++;
            }
		}

        m_VertCount		= m_NewPoints.size();
        xr_free			(m_Verts);
        m_Verts			= xr_alloc<Fvector>(m_VertCount);
		Memory.mem_copy	(m_Verts,&*m_NewPoints.begin(),m_NewPoints.size()*sizeof(Fvector));

		if (i_del_face){
	        st_Face* 	old_faces 	= m_Faces;
	        u32* 		old_sg 		= m_SGs;

            m_Faces		= xr_alloc<st_Face>	(m_FaceCount-i_del_face);
            m_SGs		= xr_alloc<u32>		(m_FaceCount-i_del_face);
            
            u32 new_dk	= 0;
            for (u32 dk=0; dk<m_FaceCount; dk++){
            	if (faces_mark[dk]){
                    for (SurfFacesPairIt plp_it=m_SurfFaces.begin(); plp_it!=m_SurfFaces.end(); plp_it++){
                        IntVec& 	pol_lst = plp_it->second;
                        for (int k=0; k<int(pol_lst.size()); k++){
                            int& f = pol_lst[k];
                            if (f>(int)dk){ f--;
                            }else if (f==(int)dk){
                                pol_lst.erase(pol_lst.begin()+k);
                                k--;
                            }
                        }
                    }
                	continue;
                } 
            	m_Faces[new_dk]	= old_faces[dk];
            	m_SGs[new_dk]	= old_sg[dk];
				new_dk++;
            }
            m_FaceCount	= m_FaceCount-i_del_face;
            xr_free		(old_faces);
            xr_free		(old_sg);
		}
	}
}