Пример #1
0
void CCustomObject::AnimationDrawPath()
{
    // motion path
	VERIFY (m_Motion);
#ifdef _EDITOR
	if (EPrefs->object_flags.is(epoDrawAnimPath)){
        float fps 				= m_Motion->FPS();
        float min_t				= (float)m_Motion->FrameStart()/fps;
        float max_t				= (float)m_Motion->FrameEnd()/fps;

        Fvector 				T,r;
        u32 clr					= 0xffffffff;
        path_points.clear		();
        for (float t=min_t; (t<max_t)||fsimilar(t,max_t,EPS_L); t+=1/30.f){
            m_Motion->_Evaluate	(t,T,r);
            path_points.push_back(T);
        }

        Device.SetShader		(Device.m_WireShader);
        RCache.set_xform_world	(Fidentity);
        if (!path_points.empty())
        	DU_impl.DrawPrimitiveL		(D3DPT_LINESTRIP,path_points.size()-1,path_points.begin(),path_points.size(),clr,true,false);
        CEnvelope* E 			= m_Motion->Envelope();
        for (KeyIt k_it=E->keys.begin(); k_it!=E->keys.end(); k_it++){
            m_Motion->_Evaluate	((*k_it)->time,T,r);
            if (Device.m_Camera.GetPosition().distance_to_sqr(T)<50.f*50.f){
                DU_impl.DrawCross	(T,0.1f,0.1f,0.1f, 0.1f,0.1f,0.1f, clr,false);
                DU_impl.OutText		(T,AnsiString().sprintf("K: %3.3f",(*k_it)->time).c_str(),0xffffffff,0x00000000);
            }
        }
    }
#endif    
}
Пример #2
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);
		}
	}
}