Beispiel #1
0
iGraphic* CreatePath(float fromx,float fromy, float fromz, 
		   float tox,float toy, float toz){
    VertexList<Vertex>* vertexList = 
     (VertexList<Vertex>*)CreateVertexList<Vertex>(LINE_LIST, 1);
        vertexList->add(Vertex(Vector((float)fromx, (float)fromy, (float)fromz),Vector( 0, 1, 0)));
		vertexList->add(Vertex(Vector((float)tox, (float)toy, (float)toz),Vector( 0, 1, 0)));
	return vertexList;
}
Beispiel #2
0
// CreateGrid builds a grid-like line list of n by n lines in the x-z plane
//
iGraphic* CreateGrid(float min, float max, int n) {
    
    VertexList<Vertex>* vertexList = 
     (VertexList<Vertex>*)CreateVertexList<Vertex>(LINE_LIST, 2*n+2);

    float x = (min + max) / 2;
    min -= x;
    max -= x;
    float cur = min, inc = (max - min) / float(n - 1);
    for (int i = 0; i < n; i++, cur += inc) {
        // in the local x direction
        vertexList->add(Vertex(Vector(min, 0, cur), Vector(0, 1, 0)));
        vertexList->add(Vertex(Vector(max, 0, cur), Vector(0, 1, 0)));
        // in the local z direction
        vertexList->add(Vertex(Vector(cur, 0, min), Vector(0, 1, 0)));
        vertexList->add(Vertex(Vector(cur, 0, max), Vector(0, 1, 0)));
    }

    return vertexList;
}
Beispiel #3
0
// TriangleList reads a triangle list from file
//
iGraphic* TriangleList(const wchar_t* file, const Colour& colour) {
    
    iGraphic* graphic = nullptr;

	// construct filename with path
	int len = strlen(file) + strlen(ASSET_DIRECTORY) + 1;
	wchar_t* absFile = new wchar_t[len + 1];
	::nameWithDir(absFile, ASSET_DIRECTORY, file, len);

    // open file for input
    std::wifstream in(absFile, std::ios::in);
    delete [] absFile;

    float x, y, z, xc = 0, yc = 0, zc = 0;
    unsigned no = 0;

    // count the number of records
    while (in) { 
        in >> x >> y >> z;
        xc += x;
        yc += y;
        zc += z;
        no++;
    }
    in.clear();
    in.seekg(0);
    if (no) {
        VertexList<LitVertex>* vertexList = 
         (VertexList<LitVertex>*)CreateVertexList<LitVertex>(TRIANGLE_LIST, no);
        xc /= no;
        yc /= no;
        zc /= no;
        for (unsigned i = 0; i < no; i++) {
            in >> x >> y >> z;
            vertexList->add(LitVertex(Vector(x - xc, y - yc, (z - zc) * MODEL_Z_AXIS), 
                colour));
        }
        graphic = vertexList;
    }
    
    return graphic;
}
	//bool MeshXMLExporter::streamSubmesh(std::ostream &of, IGameNode *node, std::string &mtlName) {
	bool MeshXMLExporter::streamSubmesh(std::ostream &of, IGameObject *obj, std::string &mtlName) {
		
		//IGameObject* obj = node->GetIGameObject();
		if (obj->GetIGameType() != IGameMesh::IGAME_MESH)
			return false;

		// InitializeData() is important -- it performs all of the WSM/time eval for us; no face data without it
//		obj->InitializeData();
		IGameMesh* mesh = (IGameMesh*) obj;
		int vertCount = mesh->GetNumberOfVerts();
		int faceCount = mesh->GetNumberOfFaces();

		Tab<int> matIds = mesh->GetActiveMatIDs();
		Tab<DWORD> smGrpIds = mesh->GetActiveSmgrps();
		Tab<int> texMaps = mesh->GetActiveMapChannelNum();

		of << "\t\t<submesh ";
		
		if (mtlName.length() > 0)
			of << "material=\"" << mtlName << "\" ";

		of << "usesharedvertices=\"false\" use32bitindexes=\"";
		of << (vertCount > 65535);
		of << "\">" << std::endl;

		// *************** Export Face List ***************
		of << "\t\t\t<faces count=\"" << faceCount << "\">" << std::endl;

		//std::vector<UVVert

		// iterate the face list, putting vertices in the list for this submesh
		VertexList vertexList;

		for (int i=0; i<faceCount; i++) {

			of << "\t\t\t\t<face";
			FaceEx* face = mesh->GetFace(i);

			// do this for each vertex on the face
			for (int vi=0; vi<3; vi++) {
				Point3 p = mesh->GetVertex(face->vert[vi]);

				Vertex v(p.x, p.y, p.z);

				if (m_config.getExportVertexColours()) {
					Point3 c = mesh->GetColorVertex(face->vert[vi]);
					float a = mesh->GetAlphaVertex(face->vert[vi]);

					v.setColour(c.x, c.y, c.z, a);
				}

				Point3 n = mesh->GetNormal(face, vi);
				v.setNormal(n.x, n.y, n.z);

				// get each set of texcoords for this vertex
				for (int ch=0; ch < texMaps.Count(); ch++) {

					Point3 tv;
					DWORD indices[3];

					if (mesh->GetMapFaceIndex(texMaps[ch], i, indices))
						tv = mesh->GetMapVertex(texMaps[ch], indices[vi]);
					else
						tv = mesh->GetMapVertex(texMaps[ch], face->vert[vi]);

					v.addTexCoord(texMaps[ch], tv.x, tv.y, tv.z);
				}

				int actualVertexIndex = vertexList.add(v);

				of << " v" << vi + 1 << "=\"" << actualVertexIndex << "\"";
			}
 
			of << " />" << std::endl;
		}

		of << "\t\t\t</faces>" << std::endl;
		// *************** End Export Face List ***************


		// *************** Export Geometry ***************
		of << "\t\t\t<geometry vertexcount=\"" << vertexList.size() << "\">" << std::endl;

		// *************** Export Vertex Buffer ***************
		bool exportNormals = true;

		of << std::boolalpha;
		of << "\t\t\t\t<vertexbuffer positions=\"true\" normals=\"" << exportNormals << "\" colours_diffuse=\"" << m_config.getExportVertexColours() << "\" texture_coords=\"" << texMaps.Count() << "\"";
		
		for (int i=0; i<texMaps.Count(); i++)
			of << " texture_coords_dimensions_" << i << "=\"2\"";
		
		of << ">" << std::endl;

		int numVerts = vertexList.size();
		for (int i=0; i < numVerts; i++) 
		{
			const Vertex& v = vertexList.front();

			of << "\t\t\t\t\t<vertex>" << std::endl;
			of << std::showpoint;

			const Ogre::Vector3& p = v.getPosition();
			float x = p.x;
			float y = p.y;
			float z = p.z;

			of << "\t\t\t\t\t\t<position x=\"" << x << "\" y=\"" << y << "\" z=\"" << z << "\" />" << std::endl;

			if (m_config.getExportVertexColours()) 
			{

				float r = v.getColour().r;
				float g = v.getColour().g;
				float b = v.getColour().b;

				of << "\t\t\t\t\t\t<colour_diffuse value=\"\t" << r << "\t" << g << "\t" << b << "\" />" << std::endl;
			}

			if (exportNormals) {

				const Ogre::Vector3& n = v.getNormal();
				float x = n.x;
				float y = n.y;
				float z = n.z;

				of << "\t\t\t\t\t\t<normal x=\"" << x << "\" y=\"" << y << "\" z=\"" << z << "\" />" << std::endl;
			}

			// output the tex coords for each map used
			for (int ti=0; ti<texMaps.Count(); ti++) {
				int texMap = texMaps[ti];

				const Ogre::Vector3& uvw = v.getUVW(texMap); 

				switch (m_config.getTexCoord2D()) {
					case OgreMax::UV:
						of << "\t\t\t\t\t\t<texcoord u=\"" << uvw.x << "\" v=\"" << (1.0 - uvw.y) << "\" />" << std::endl; 
						break;
					case OgreMax::VW:
						of << "\t\t\t\t\t\t<texcoord v=\"" << uvw.y << "\" w=\"" << (1.0 - uvw.z) << "\" />" << std::endl; 
						break;
					case OgreMax::WU:
						of << "\t\t\t\t\t\t<texcoord w=\"" << uvw.z << "\" u=\"" << (1.0 - uvw.x) << "\" />" << std::endl; 
						break;
				}
			}
			
			of << std::noshowpoint;
			of << "\t\t\t\t\t</vertex>" << std::endl;
			vertexList.pop();
		}

		of << "\t\t\t\t</vertexbuffer>" << std::endl;
		// *************** End Export Vertex Buffer ***************

		of << "\t\t\t</geometry>" << std::endl;
		// *************** End Export Geometry ***********

		of << "\t\t</submesh>" << std::endl;

		// this skin extraction code based on an article found here:
		// http://www.cfxweb.net/modules.php?name=News&file=article&sid=1029
/*		Object *oRef = node->GetObjectRef();

		if (oRef->SuperClassID() == GEN_DERIVOB_CLASS_ID) {
			IDerivedObject *dObj = (IDerivedObject *)oRef;
			Modifier *oMod = dObj->GetModifier(0);

			if (oMod->ClassID() == SKIN_CLASSID) {

				// flag the export of a skeleton link element
				m_createSkeletonLink = true;

				// stream the boneassignments element
				streamBoneAssignments(of, oMod, node);
			}
		}

		of << "\t\t</submesh>" << std::endl;

		if (obj != tri)
			delete tri;
*/
//		node->ReleaseIGameObject();
		return true;
	}