示例#1
0
bool Model::ImportUVCoords (Model* other, IProgressCtl &progctl)
{
	vector <MdlObject*> objects=GetObjectList ();
	MdlObject *srcobj = other->root;

	vector <Vector3> pverts;

	int numPl = 0, curPl=0;
	for (int a=0;a<objects.size();a++)
		numPl += objects[a]->poly.size();
	
	for (int a=0;a<objects.size();a++) {
		MdlObject *obj = objects[a];
		Matrix objTransform;
		obj->GetFullTransform(objTransform);

		// give each polygon an independent set of vertices, this will be optimized back to normal later
		vector <Vertex> nverts;
		for (int b=0;b<obj->poly.size();b++) {
			Poly *pl = obj->poly[b];
			for (int v=0;v<pl->verts.size();v++) {
				nverts.push_back (obj->verts[pl->verts[v]]);
				pl->verts[v]=nverts.size()-1;
			}
		}
		obj->verts=nverts;

		// match our polygons with the ones of the other model
		for (int b=0;b<obj->poly.size();b++) {
			Poly *pl = obj->poly[b];

			pverts.clear();
			for (int pv=0;pv<pl->verts.size();pv++) {
				Vector3 tpos;
				objTransform.apply (&obj->verts [pl->verts[pv]].pos, &tpos);
				pverts.push_back (tpos);
			}

			int startVertex;
			int bestpl = MatchPolygon (srcobj,pverts,startVertex);
			if (bestpl >= 0) {
				// copy texture coordinates from rt->poly[bestpl] to pl
				Poly *src = srcobj->poly [bestpl];
				for (int v=0;v<src->verts.size();v++) {
					Vertex &dstvrt = obj->verts[pl->verts[(v + startVertex)%pl->verts.size()]];
					dstvrt.tc[0] = srcobj->verts[src->verts[v]].tc[0];
				}
			}

			progctl.Update ((float)(curPl++) / numPl);
		}
		obj->Optimize ();
		obj->InvalidateRenderData();
	}

	return true;
}
示例#2
0
void Model::CalculateRadius ()
{
	vector<MdlObject*> objs = GetObjectList();
	radius=0.0f;
	for (int o=0;o<objs.size();o++) {
		MdlObject *obj = objs[o];
		Matrix objTransform;
		obj->GetFullTransform(objTransform);
		for(int v=0;v<obj->verts.size();v++){
			Vector3 tpos;
			objTransform.apply(&obj->verts[v].pos,&tpos);
			float r= (tpos-mid).length();
			if (radius < r) radius=r;
		}
	}
}