示例#1
0
void CEditableObject::OnBindTransformChange()
{
    for(EditMeshIt mesh_it=FirstMesh();mesh_it!=LastMesh();mesh_it++){
        CEditableMesh* MESH = *mesh_it;
        MESH->UnloadSVertices(true);
    }
}
示例#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;
}
示例#3
0
bool CEditableObject::ExportLWO(LPCSTR fname)
{
	CLWMemoryStream* F = xr_new<CLWMemoryStream>();

	LPCSTRVec images;

	F->begin_save();
		// tags
		F->open_chunk(ID_TAGS);
			for (SurfaceIt s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++){
				CSurface* S=*s_it;
				F->w_stringZ(S->_Name());
				S->tag = s_it-m_Surfaces.begin();
				if (FindLPCSTR(images,S->_Texture())<0) images.push_back(S->_Texture());
			}
		F->close_chunk();
		// images
		for (LPCSTRIt im_it=images.begin(); im_it!=images.end(); im_it++){
			F->open_chunk(ID_CLIP);
				F->w_u32(im_it-images.begin());
				F->open_subchunk(ID_STIL);
					F->w_stringZ(*im_it);
				F->close_subchunk();
			F->close_chunk	();
		}
		// surfaces
		for (s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++){
			CSurface* S=*s_it;
			int im_idx=FindLPCSTR(images,S->_Texture());
			R_ASSERT(im_idx>=0);
			LPCSTR vm_name=S->_VMap();
			F->Wsurface(S->_Name(),S->m_Flags.is(CSurface::sf2Sided),(u16)im_idx,(vm_name&&vm_name[0])?vm_name:"Texture",S->_ShaderName(),S->_ShaderXRLCName());
		}
		// meshes/layers
		for (EditMeshIt mesh_it=FirstMesh(); mesh_it!=LastMesh(); mesh_it++){
			CEditableMesh* MESH=*mesh_it;
			F->w_layer(u16(mesh_it-FirstMesh()),MESH->Name().c_str());
			// bounding box
			F->open_chunk(ID_BBOX);
				F->w_vector(MESH->m_Box.min);
				F->w_vector(MESH->m_Box.max);
			F->close_chunk();
			// points
			F->open_chunk(ID_PNTS);
				for (u32 point_id=0; point_id<MESH->GetVCount(); point_id++)
					F->w_vector(MESH->GetVerts()[point_id]);
			F->close_chunk();
			// polygons
			F->open_chunk(ID_POLS);
				F->w_u32(ID_FACE);
				for (u32 f_id=0; f_id<MESH->GetFCount(); f_id++)
					F->w_face3(MESH->GetFaces()[f_id].pv[0].pindex,MESH->GetFaces()[f_id].pv[1].pindex,MESH->GetFaces()[f_id].pv[2].pindex);
			F->close_chunk();
			// surf<->face
			F->open_chunk(ID_PTAG);
				F->w_u32(ID_SURF);
				for (SurfFacesPairIt sf_it=MESH->m_SurfFaces.begin(); sf_it!=MESH->m_SurfFaces.end(); sf_it++){
					IntVec& lst			= sf_it->second;
					for (IntIt i_it=lst.begin(); i_it!=lst.end(); i_it++){
						F->w_vx	(*i_it);
						F->w_u16(WORD(sf_it->first->tag));
					}
				}
			F->close_chunk();
			// vmap&vmad
			for (VMapIt vm_it=MESH->m_VMaps.begin(); vm_it!=MESH->m_VMaps.end(); vm_it++){
				st_VMap* vmap = *vm_it;
				F->begin_vmap(vmap->polymap, (vmap->type==vmtUV)?ID_TXUV:ID_WGHT, vmap->dim, vmap->name.c_str());
					if (vmap->polymap)	for (int k=0; k<vmap->size(); k++) F->w_vmad(vmap->vindices[k],vmap->pindices[k],vmap->dim,vmap->getVMdata(k));
					else				for (int k=0; k<vmap->size(); k++) F->w_vmap(vmap->vindices[k],vmap->dim,vmap->getVMdata(k));
				F->end_vmap();
			}
		}
	F->end_save(fname);

	xr_delete(F);

	return true;
}