public static void writeMeshToObj(String objPath, String mtlPath, Mesh mesh)
			throws IOException {
		// obj
		PrintWriter writer = new PrintWriter(new FileWriter(objPath));
		Vector3d[] vertices = mesh.getLocalVertices();
		Triangle[] triangles = mesh.getLocalTriangles();

		writer.println("mtllib "
				+ mtlPath.substring(mtlPath.lastIndexOf(File.separator) + 1));
		for (Vector3d vertex : vertices) {
			writer.println("v " + vertex.x + " " + vertex.y + " " + vertex.z);
		}
		writer.println("usemtl Material");
		for (Triangle triangle : triangles) {
			writer.println("f " + (triangle.v0 + 1) + " "
					+ (triangle.v1 + 1) + " " + (triangle.v2 + 1));
		}
		
		writer.close();

		// mtl
		writer = new PrintWriter(new FileWriter(mtlPath));
		Material material = mesh.getShape().getAppearance().getMaterial();
		Color3f ambientColour = new Color3f();
		material.getAmbientColor(ambientColour);
		Color3f diffuseColour = new Color3f();
		material.getDiffuseColor(diffuseColour);
		Color3f specularColour = new Color3f();
		material.getSpecularColor(specularColour);
		Color3f emissiveColour = new Color3f();
		material.getEmissiveColor(emissiveColour);
		float shininess = material.getShininess();

		writer.println("newmtl Material");
		writer.println("Ns " + shininess);
		writer.println("Ka " + ambientColour.x + " " + ambientColour.y + " "
				+ ambientColour.z);
		writer.println("Kd " + diffuseColour.x + " " + diffuseColour.y + " "
				+ diffuseColour.z);
		writer.println("Ks " + specularColour.x + " " + specularColour.y + " "
				+ specularColour.z);
		writer.close();
	}