r2099 - tools/ObjToMap/objtomap
savagex at icculus.org
savagex at icculus.org
Thu Jan 11 11:47:43 EST 2007
Author: savagex
Date: 2007-01-11 11:47:43 -0500 (Thu, 11 Jan 2007)
New Revision: 2099
Modified:
tools/ObjToMap/objtomap/ObjToMap.java
Log:
slightly less horrible version
Modified: tools/ObjToMap/objtomap/ObjToMap.java
===================================================================
--- tools/ObjToMap/objtomap/ObjToMap.java 2007-01-11 09:05:05 UTC (rev 2098)
+++ tools/ObjToMap/objtomap/ObjToMap.java 2007-01-11 16:47:43 UTC (rev 2099)
@@ -82,7 +82,7 @@
String[] facetokens2 = tokens[2].split("/");
String[] facetokens3 = tokens[3].split("/");
- TriFace f = new TriFace();
+ Face f = new Face();
f.material = currentmat;
f.p1 = (Vector3D)points.get(Integer.parseInt(facetokens1[0]) - 1);
f.p2 = (Vector3D)points.get(Integer.parseInt(facetokens2[0]) - 1);
@@ -97,27 +97,15 @@
String[] facetokens3 = tokens[3].split("/");
String[] facetokens4 = tokens[4].split("/");
- // In theory I should use a QuadFace here
- // HOWEVER, thanks to precision issues it's better to break
- // it down into two TriFaces.
- // It seems the Blender .obj exporter doesn't have all 4 points
- // lying on the same plane (precision issue).
- //QuadFace f = new QuadFace();
- /*f.p1 = points.get(Integer.parseInt(facetokens1[0]) - 1);
- f.p2 = points.get(Integer.parseInt(facetokens2[0]) - 1);
- f.p3 = points.get(Integer.parseInt(facetokens3[0]) - 1);
- f.p4 = points.get(Integer.parseInt(facetokens4[0]) - 1);*/
- //faces.add(f);
-
- TriFace f1 = new TriFace();
+ Face f1 = new Face();
f1.material = currentmat;
f1.p1 = (Vector3D)points.get(Integer.parseInt(facetokens1[0]) - 1);
f1.p2 = (Vector3D)points.get(Integer.parseInt(facetokens2[0]) - 1);
f1.p3 = (Vector3D)points.get(Integer.parseInt(facetokens3[0]) - 1);
faces.add(f1);
- TriFace f2 = new TriFace();
+ Face f2 = new Face();
f2.material = currentmat;
f2.p1 = (Vector3D)points.get(Integer.parseInt(facetokens1[0]) - 1);
f2.p2 = (Vector3D)points.get(Integer.parseInt(facetokens3[0]) - 1);
@@ -133,7 +121,6 @@
}
-
}
private void writeMap(String filename, Vector faces) {
@@ -151,8 +138,7 @@
for(int i = 0; i < faces.size(); i++) {
Face f = (Face)faces.get(i);
- String brush = f.generateBrush();
- sb.append(brush);
+ sb.append(f.generateBrush());
}
sb.append("}\n");
@@ -201,18 +187,12 @@
x /= l;
y /= l;
z /= l;
-
}
}
- private interface Face {
- public String generateBrush();
-
- }
-
- private class TriFace implements Face {
+ private class Face {
public Vector3D p1, p2, p3;
public String material;
@@ -234,83 +214,28 @@
// top face, apply texture here
- result += "( " + p3.x + " " + p3.y + " " + p3.z + " ) ( " + p2.x + " " + p2.y + " " + p2.z + " ) ( " + p1.x + " " + p1.y + " " + p1.z + " ) ";
- result += material + " 0 0 0 0.5 0.5 0 0 0\n";
+ result += getMapPlaneString(p3, p2, p1, material);
// bottom face
- result += "( " + p1_.x + " " + p1_.y + " " + p1_.z + " ) ( " + p2_.x + " " + p2_.y + " " + p2_.z + " ) ( " + p3_.x + " " + p3_.y + " " + p3_.z + " ) ";
- result += "common/caulk 0 0 0 0.5 0.5 0 0 0\n";
+ result += getMapPlaneString(p1_, p2_, p3_, "common/caulk");
// extruded side 1
- result += "( " + p1.x + " " + p1.y + " " + p1.z + " ) ( " + p1_.x + " " + p1_.y + " " + p1_.z + " ) ( " + p3_.x + " " + p3_.y + " " + p3_.z + " ) ";
- result += "common/caulk 0 0 0 0.5 0.5 0 0 0\n";
+ result += getMapPlaneString(p1, p1_, p3_, "common/caulk");
// extruded side 2
- result += "( " + p2.x + " " + p2.y + " " + p2.z + " ) ( " + p3.x + " " + p3.y + " " + p3.z + " ) ( " + p3_.x + " " + p3_.y + " " + p3_.z + " ) ";
- result += "common/caulk 0 0 0 0.5 0.5 0 0 0\n";
+ result += getMapPlaneString(p2, p3, p3_, "common/caulk");
// extruded side 3
- result += "( " + p1.x + " " + p1.y + " " + p1.z + " ) ( " + p2.x + " " + p2.y + " " + p2.z + " ) ( " + p2_.x + " " + p2_.y + " " + p2_.z + " ) ";
- result += "common/caulk 0 0 0 0.5 0.5 0 0 0\n";
+ result += getMapPlaneString(p1, p2, p2_, "common/caulk");
-
result += "}\n";
return result;
}
- }
-
- private class QuadFace implements Face {
- public Vector3D p1, p2, p3, p4;
- public String material;
-
- public String generateBrush() {
- String result = "{\n";
-
- Vector3D vector1 = p1.substract(p2);
- Vector3D vector2 = p1.substract(p4);
-
- Vector3D normal = vector1.crossproduct(vector2);
- normal.normalize();
- normal.scale(4.0);
-
- Vector3D p1_, p2_, p3_, p4_;
-
- p1_ = p1.substract(normal);
- p2_ = p2.substract(normal);
- p3_ = p3.substract(normal);
- p4_ = p4.substract(normal);
-
-
- // top face, apply texture here
- result += "( " + p3.x + " " + p3.y + " " + p3.z + " ) ( " + p2.x + " " + p2.y + " " + p2.z + " ) ( " + p1.x + " " + p1.y + " " + p1.z + " ) ";
- result += material + " 0 0 0 0.5 0.5 0 0 0\n";
-
- // bottom face
- result += "( " + p1_.x + " " + p1_.y + " " + p1_.z + " ) ( " + p2_.x + " " + p2_.y + " " + p2_.z + " ) ( " + p3_.x + " " + p3_.y + " " + p3_.z + " ) ";
- result += "common/caulk 0 0 0 0.5 0.5 0 0 0\n";
-
- // extruded side 1
- result += "( " + p1.x + " " + p1.y + " " + p1.z + " ) ( " + p2.x + " " + p2.y + " " + p2.z + " ) ( " + p2_.x + " " + p2_.y + " " + p2_.z + " ) ";
- result += "common/caulk 0 0 0 0.5 0.5 0 0 0\n";
-
- // extruded side 2
- result += "( " + p2.x + " " + p2.y + " " + p2.z + " ) ( " + p3.x + " " + p3.y + " " + p3.z + " ) ( " + p3_.x + " " + p3_.y + " " + p3_.z + " ) ";
- result += "common/caulk 0 0 0 0.5 0.5 0 0 0\n";
-
- // extruded side 3
- result += "( " + p3.x + " " + p3.y + " " + p3.z + " ) ( " + p4.x + " " + p4.y + " " + p4.z + " ) ( " + p4_.x + " " + p4_.y + " " + p4_.z + " ) ";
- result += "common/caulk 0 0 0 0.5 0.5 0 0 0\n";
-
- // extruded side 4
- result += "( " + p1.x + " " + p1.y + " " + p1.z + " ) ( " + p1_.x + " " + p1_.y + " " + p1_.z + " ) ( " + p4_.x + " " + p4_.y + " " + p4_.z + " ) ";
- result += "common/caulk 0 0 0 0.5 0.5 0 0 0\n";
-
-
- result += "}\n";
-
- return result;
+
+ private String getMapPlaneString(Vector3D p1, Vector3D p2, Vector3D p3, String material) {
+ return "( " + p1.x + " " + p1.y + " " + p1.z + " ) ( " + p2.x + " " + p2.y + " " + p2.z + " ) ( " + p3.x + " " + p3.y + " " + p3.z + " ) " + material + " 0 0 0 0.5 0.5 0 0 0\n";
}
}
More information about the nexuiz-commits
mailing list