Beispiel #1
0
bool EDetail::Update	(LPCSTR name)
{
	m_sRefs				= name;
    // update link
    CEditableObject* R	= Lib.CreateEditObject(name);
    if (!R){
 		ELog.Msg		(mtError,"Can't load detail object '%s'.", name);
        return false;
    }
    if(R->SurfaceCount()!=1){
    	ELog.Msg		(mtError,"Object must contain 1 material.");
	    Lib.RemoveEditObject(R);
    	return false;
    }
	if(R->MeshCount()==0){
    	ELog.Msg		(mtError,"Object must contain 1 mesh.");
	    Lib.RemoveEditObject(R);
    	return false;
    }

    Lib.RemoveEditObject(m_pRefs);
    m_pRefs				= R;

    // fill geometry
    CEditableMesh* M	= *m_pRefs->FirstMesh();
    U16Vec inds;

    // fill vertices
    bv_bb.invalidate();
    u32 idx			= 0;
    for (u32 f_id=0; f_id<M->GetFCount(); f_id++){
        st_Face& F 	= M->GetFaces()[f_id];
    	u16 ind[3];
    	for (int k=0; k<3; k++,idx++){
            Fvector& P  = M->GetVerts()[F.pv[k].pindex];
            st_VMapPt&vm= M->GetVMRefs()[F.pv[k].vmref].pts[0];
            Fvector2& uv= M->GetVMaps()[vm.vmap_index]->getUV(vm.index);
        	ind[k]		= _AddVert	(P,uv.x,uv.y);
	        bv_bb.modify(vertices[ind[k]].P);
        }
        if (isDegenerated(ind))	continue;
        if (isEqual(inds,ind))	continue;
        inds.push_back(ind[0]);
        inds.push_back(ind[1]);
        inds.push_back(ind[2]);
    }
	number_indices 		= inds.size();
	indices				= (u16*)xr_malloc(number_indices*sizeof(u16));
    Memory.mem_copy		(indices,inds.begin(),number_indices*sizeof(u16));

	bv_bb.getsphere		(bv_sphere.P,bv_sphere.R);

    OnDeviceCreate		();

    return true;
}
Beispiel #2
0
bool CEditableObject::GenerateBoneShape(bool bSelOnly)
{
	R_ASSERT(IsSkeleton());
    xr_vector<FvectorVec>	bone_points;
	bone_points.resize		(m_Bones.size());
    for(EditMeshIt mesh_it=FirstMesh();mesh_it!=LastMesh();mesh_it++){
        CEditableMesh* MESH = *mesh_it;
        // generate vertex offset
        MESH->GenerateSVertices	(1);
        for (u32 f_id=0; f_id!=MESH->GetFCount(); f_id++){
            for (int k=0; k<3; k++){
                st_SVert& 		sv = MESH->m_SVertices[f_id*3+k];
                VERIFY			(sv.bones.size()==1);
                u16 b_id 		= sv.bones[0].id;//(sv.bones.size()>1)?(sv.bones[0].w>sv.bones[1].w?sv.bones[0].id:sv.bones[1].id):sv.bones[0].id;
                FvectorVec& P 	= bone_points[b_id];
                bool bFound		= false;
                Fvector p;
				m_Bones[b_id]->_RITransform().transform_tiny(p,sv.offs);
                for (FvectorIt p_it=P.begin(); p_it!=P.end(); p_it++)
                	if (p_it->similar(p)){ 
                    	bFound=true; 
                        break; 
                }
                if (!bFound)	P.push_back(p);       
//		        if (sv.bone1!=BI_NONE) bone_points[sv.bone1].push_back(sv.offs1);
            }
        }
        MESH->UnloadSVertices();
    }

    BoneVec& lst 	= m_Bones;    
    for(BoneIt b_it=lst.begin(); b_it!=lst.end(); b_it++){
    	if (bSelOnly&&!(*b_it)->flags.is(CBone::flSelected)) continue;
        FvectorVec& positions = bone_points[b_it-lst.begin()];
        ComputeOBB_WML	((*b_it)->shape.box,positions);
        ComputeSphere	((*b_it)->shape.sphere,positions);
        ComputeCylinder	((*b_it)->shape.cylinder,(*b_it)->shape.box,positions);
        (*b_it)->center_of_mass.set((*b_it)->shape.sphere.P);
    }
    return true;
}