Example #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;
}