Initial commit.

master
Ondřej Hruška 9 years ago
commit f9100f0f0a
  1. 36
      .classpath
  2. 5
      .gitignore
  3. 17
      .project
  4. 11
      .settings/org.eclipse.jdt.core.prefs
  5. BIN
      lib/OpenAL32.dll
  6. BIN
      lib/OpenAL64.dll
  7. BIN
      lib/jinput-dx8.dll
  8. BIN
      lib/jinput-dx8_64.dll
  9. BIN
      lib/jinput-raw.dll
  10. BIN
      lib/jinput-raw_64.dll
  11. BIN
      lib/jinput.jar
  12. BIN
      lib/jogg-0.0.7.jar
  13. BIN
      lib/jorbis-0.0.15.jar
  14. BIN
      lib/libjinput-linux.so
  15. BIN
      lib/libjinput-linux64.so
  16. BIN
      lib/libjinput-osx.jnilib
  17. BIN
      lib/liblwjgl.jnilib
  18. BIN
      lib/liblwjgl.so
  19. BIN
      lib/liblwjgl64.so
  20. BIN
      lib/libopenal.so
  21. BIN
      lib/libopenal64.so
  22. BIN
      lib/lwjgl-source-2.8.4.zip
  23. BIN
      lib/lwjgl.dll
  24. BIN
      lib/lwjgl.jar
  25. BIN
      lib/lwjgl64.dll
  26. BIN
      lib/lwjgl_util.jar
  27. BIN
      lib/slick-util-src.zip
  28. BIN
      lib/slick-util.jar
  29. 11
      res/models/turtle.mtl
  30. 3558
      res/models/turtle.obj
  31. BIN
      res/models/turtle.png
  32. BIN
      res/models/turtle.wings
  33. BIN
      res/models/turtle.xcf
  34. 11
      res/models/turtle2.mtl
  35. 3558
      res/models/turtle2.obj
  36. BIN
      res/models/turtle2.wings
  37. 86
      src/com/mykaruga/models/Models.java
  38. 67
      src/com/mykaruga/models/wavefront/loader/Face.java
  39. 37
      src/com/mykaruga/models/wavefront/loader/LineParserFactory.java
  40. 50
      src/com/mykaruga/models/wavefront/loader/Material.java
  41. 33
      src/com/mykaruga/models/wavefront/loader/NormalParser.java
  42. 300
      src/com/mykaruga/models/wavefront/loader/RenderModel.java
  43. 35
      src/com/mykaruga/models/wavefront/loader/TextureCoordinate.java
  44. 45
      src/com/mykaruga/models/wavefront/loader/Vertex.java
  45. 15
      src/com/mykaruga/models/wavefront/parser/CommentParser.java
  46. 19
      src/com/mykaruga/models/wavefront/parser/DefaultParser.java
  47. 19
      src/com/mykaruga/models/wavefront/parser/LineParser.java
  48. 41
      src/com/mykaruga/models/wavefront/parser/mtl/KdMapParser.java
  49. 35
      src/com/mykaruga/models/wavefront/parser/mtl/KdParser.java
  50. 74
      src/com/mykaruga/models/wavefront/parser/mtl/MaterialFileParser.java
  51. 27
      src/com/mykaruga/models/wavefront/parser/mtl/MaterialParser.java
  52. 24
      src/com/mykaruga/models/wavefront/parser/mtl/MtlLineParserFactory.java
  53. 98
      src/com/mykaruga/models/wavefront/parser/obj/FaceParser.java
  54. 21
      src/com/mykaruga/models/wavefront/parser/obj/FreeFormParser.java
  55. 27
      src/com/mykaruga/models/wavefront/parser/obj/MaterialParser.java
  56. 29
      src/com/mykaruga/models/wavefront/parser/obj/ObjLineParserFactory.java
  57. 37
      src/com/mykaruga/models/wavefront/parser/obj/TextureCooParser.java
  58. 34
      src/com/mykaruga/models/wavefront/parser/obj/VertexParser.java
  59. 152
      src/com/porcupine/color/HSV.java
  60. 336
      src/com/porcupine/color/RGB.java
  61. 729
      src/com/porcupine/coord/Coord.java
  62. 159
      src/com/porcupine/coord/CoordI.java
  63. 639
      src/com/porcupine/coord/Rect.java
  64. 283
      src/com/porcupine/coord/Vec.java
  65. 64
      src/com/porcupine/ion/AbstractIonList.java
  66. 75
      src/com/porcupine/ion/AbstractIonMap.java
  67. 261
      src/com/porcupine/ion/Ion.java
  68. 144
      src/com/porcupine/ion/IonList.java
  69. 143
      src/com/porcupine/ion/IonMap.java
  70. 57
      src/com/porcupine/ion/IonMarks.java
  71. 41
      src/com/porcupine/ion/Ionizable.java
  72. 16
      src/com/porcupine/ion/IonizableOptional.java
  73. 208
      src/com/porcupine/ion/StreamUtils.java
  74. 804
      src/com/porcupine/math/Calc.java
  75. 91
      src/com/porcupine/math/Polar.java
  76. 95
      src/com/porcupine/math/PolarDeg.java
  77. 174
      src/com/porcupine/math/Range.java
  78. 52
      src/com/porcupine/mutable/AbstractMutable.java
  79. 28
      src/com/porcupine/mutable/MBoolean.java
  80. 28
      src/com/porcupine/mutable/MDouble.java
  81. 29
      src/com/porcupine/mutable/MFloat.java
  82. 28
      src/com/porcupine/mutable/MInt.java
  83. 28
      src/com/porcupine/mutable/MString.java
  84. 132
      src/com/porcupine/struct/Struct2.java
  85. 172
      src/com/porcupine/struct/Struct3.java
  86. 213
      src/com/porcupine/struct/Struct4.java
  87. 256
      src/com/porcupine/struct/Struct5.java
  88. 295
      src/com/porcupine/struct/Struct6.java
  89. 336
      src/com/porcupine/struct/Struct7.java
  90. 377
      src/com/porcupine/struct/Struct8.java
  91. 54
      src/com/porcupine/time/FpsMeter.java
  92. 130
      src/com/porcupine/time/Timer.java
  93. 36
      src/com/porcupine/util/FileSuffixFilter.java
  94. 182
      src/com/porcupine/util/FileUtils.java
  95. 1062
      src/com/porcupine/util/PropertyManager.java
  96. 104
      src/com/porcupine/util/StringUtils.java
  97. 51
      src/com/porcupine/util/VarargsParser.java
  98. 368
      src/net/spritegen/App.java
  99. 57
      src/net/spritegen/Constants.java
  100. 90
      src/net/spritegen/SetupLoader.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry exported="true" kind="lib" path="lib/jinput.jar">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="SpriteGen/lib"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="lib/jogg-0.0.7.jar">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="SpriteGen/lib"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="lib/jorbis-0.0.15.jar">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="SpriteGen/lib"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="lib/lwjgl_util.jar">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="SpriteGen/lib"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="lib/lwjgl.jar">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="SpriteGen/lib"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="lib/slick-util.jar">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="SpriteGen/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>

5
.gitignore vendored

@ -0,0 +1,5 @@
/bin/
/target/
*.log
.attach_pid*
*~

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SpriteGen</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,11 @@
# Exported from Wings 3D 1.4.1
newmtl turtle_auv
Ns 100.0
d 1.0
illum 2
Kd 1.0 1.0 1.0
Ka 1.0 1.0 1.0
Ks 1.0 1.0 1.0
Ke 0.0 0.0 0.0
map_Kd turtle.png

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

Binary file not shown.

@ -0,0 +1,11 @@
# Exported from Wings 3D 1.4.1
newmtl turtle_auv
Ns 100.0
d 1.0
illum 2
Kd 1.0 1.0 1.0
Ka 1.0 1.0 1.0
Ks 1.0 1.0 1.0
Ke 0.0 0.0 0.0
map_Kd turtle.png

File diff suppressed because it is too large Load Diff

Binary file not shown.

@ -0,0 +1,86 @@
package com.mykaruga.models;
import static org.lwjgl.opengl.GL11.*;
import java.io.File;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.spritegen.App;
import net.spritegen.Constants;
import net.spritegen.textures.TextureManager;
import net.spritegen.util.Utils;
import com.mykaruga.models.wavefront.loader.RenderModel;
import com.porcupine.math.Calc;
import com.porcupine.math.Calc.Buffers;
public class Models {
public static RenderModel turtle;
public static void load() {
turtle = new RenderModel(App.modelFile.getAbsolutePath());
}
private static int beginList = -1;
private static int endList = -1;
public static void renderBegin() {
if (beginList == -1) {
beginList = glGenLists(1);
glNewList(beginList, GL_COMPILE);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable(GL_TEXTURE_2D);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_CULL_FACE);
float spec = (float) App.cfg.mat_specular;
float amb = (float) App.cfg.mat_ambient;
float diff = (float) App.cfg.mat_diffuse;
FloatBuffer buff = Calc.Buffers.alloc(4);
Calc.Buffers.fill(buff, amb, amb, amb, 1.0f);
glMaterial(GL_FRONT, GL_AMBIENT, Buffers.mkFillBuff(amb, amb, amb, 1f));
buff.clear();
Calc.Buffers.fill(buff, spec, spec, spec, 1.0f);
glLight(GL_LIGHT0, GL_SPECULAR, buff);
glMaterial(GL_FRONT, GL_SPECULAR, Buffers.mkFillBuff(spec, spec, spec, 1f));
buff.clear();
Calc.Buffers.fill(buff, diff, diff, diff, 1.0f);
glLight(GL_LIGHT0, GL_DIFFUSE, buff);
glMaterial(GL_FRONT, GL_DIFFUSE, Buffers.mkFillBuff(diff, diff, diff, 1f));
glMaterialf(GL_FRONT, GL_SHININESS, 8);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glColor4d(1, 1, 1, 1);
glEndList();
}
glCallList(beginList);
}
public static void renderEnd() {
if (endList == -1) {
endList = glGenLists(1);
glNewList(endList, GL_COMPILE);
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_CULL_FACE);
TextureManager.unbind();
glDisable(GL_TEXTURE_2D);
glEndList();
}
glCallList(endList);
}
}

@ -0,0 +1,67 @@
package com.mykaruga.models.wavefront.loader;
public class Face {
public static final int GL_TRIANGLES = 3;
public static final int GL_QUADS = 4;
private Vertex[] vertices;
private Vertex[] normals;
private TextureCoordinate[] textures;
private Material material;
private int type;
public Face copy() {
Face f = new Face();
f.setVertices(vertices);
f.setNormals(normals);
f.setTextures(textures);
f.setMaterial(material);
return f;
}
public Vertex[] getVertices() {
return vertices;
}
public void setVertices(Vertex[] vertices) {
this.vertices = vertices;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public Vertex[] getNormals() {
return normals;
}
public void setNormals(Vertex[] normals) {
this.normals = normals;
}
public TextureCoordinate[] getTextures() {
return textures;
}
public void setTextures(TextureCoordinate[] textures) {
this.textures = textures;
}
public Material getMaterial() {
return material;
}
public void setMaterial(Material material) {
this.material = material;
}
}

@ -0,0 +1,37 @@
package com.mykaruga.models.wavefront.loader;
import java.util.Hashtable;
import com.mykaruga.models.wavefront.parser.DefaultParser;
import com.mykaruga.models.wavefront.parser.LineParser;
public abstract class LineParserFactory {
protected Hashtable<String, LineParser> parsers = new Hashtable<String, LineParser>();
protected RenderModel object = null;
public LineParser getLineParser(String line) {
if (line == null) return null;
line = line.replaceAll(" ", " ");
line = line.replaceAll(" ", "");
String[] lineWords = line.split(" ");
if (lineWords.length < 1) return new DefaultParser();
String lineType = lineWords[0];
LineParser parser = parsers.get(lineType);
if (parser == null) {
parser = new DefaultParser();
}
parser.setWords(lineWords);
return parser;
}
}

@ -0,0 +1,50 @@
package com.mykaruga.models.wavefront.loader;
import org.newdawn.slick.opengl.Texture;
public class Material {
private Texture texture;
private Vertex Kd;
private String name;
public Material(String name) {
this.name = name;
}
public Material(Material other) {
//this.texture = other.texture;
this.Kd = other.Kd;
this.name = other.name;
}
public Texture getTexture() {
return texture;
}
public Material setTexture(Texture texture) {
this.texture = texture;
return this;
}
public Vertex getKd() {
return Kd;
}
public void setKa(Vertex kd) {
Kd = kd;
}
@Override
public String toString() {
return "MAT." + name;
}
public String getName() {
return name;
}
}

@ -0,0 +1,33 @@
package com.mykaruga.models.wavefront.loader;
import com.mykaruga.models.wavefront.parser.LineParser;
public class NormalParser extends LineParser {
Vertex vertex = null;
public NormalParser() {}
@Override
public void parse() {
vertex = new Vertex();
try {
vertex.setX(Float.parseFloat(words[1]));
vertex.setY(Float.parseFloat(words[2]));
vertex.setZ(Float.parseFloat(words[3]));
} catch (Exception e) {
throw new RuntimeException("NormalParser Error");
}
}
@Override
public void incoporateResults(RenderModel wavefrontObject) {
wavefrontObject.getNormals().add(vertex);
}
}

@ -0,0 +1,300 @@
package com.mykaruga.models.wavefront.loader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Map.Entry;
import net.spritegen.textures.TextureManager;
import net.spritegen.util.Log;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.util.ResourceLoader;
import com.mykaruga.models.wavefront.parser.LineParser;
import com.mykaruga.models.wavefront.parser.obj.ObjLineParserFactory;
/**
* OBJ 3D object loaded and pre-rendered.
*
* @author Fabien Sanglard
*/
public class RenderModel {
private static final boolean DEBUG = true;
public String replTexture = null;
private ArrayList<Vertex> vertices = new ArrayList<Vertex>();
private ArrayList<Vertex> normals = new ArrayList<Vertex>();
private ArrayList<TextureCoordinate> textures = new ArrayList<TextureCoordinate>();
private ArrayList<Face> faces = new ArrayList<Face>();
private ObjLineParserFactory parserFactory;
private Hashtable<String, Material> materials = new Hashtable<String, Material>();
// This variable is used for both parsing and rendition
private Material currentMaterial;
private String contextfolder = "";
public double radius = 0;
/**
* Load object with alternate texture.
*
* @param fileName
* @param textureName
*/
public RenderModel(String fileName, String textureName) {
this.replTexture = textureName;
int lastSlashIndex = fileName.lastIndexOf('/');
if (lastSlashIndex != -1) this.contextfolder = fileName.substring(0, lastSlashIndex + 1);
lastSlashIndex = fileName.lastIndexOf('\\');
if (lastSlashIndex != -1) this.contextfolder = fileName.substring(0, lastSlashIndex + 1);
parse(fileName);
calculateRadius();
}
// /**
// * Load object with alternate texture.
// *
// * @param fileName
// * @param textureName
// */
// public RenderModel(RenderModel other, String textureName) {
// this.vertices = other.vertices;
// this.normals = other.normals;
// this.textures = other.textures;
// this.contextfolder = other.contextfolder;
// this.radius = other.radius;
//
// String pathToTextureBinary = getContextfolder() + textureName;
// Texture texture = TextureManager.load(pathToTextureBinary);
// for (Entry<String, Material> e : other.materials.entrySet()) {
// materials.put(e.getKey(), new Material(e.getValue()).setTexture(texture));
// }
// for (Face f : other.faces) {
// Face f2;
// faces.add(f2 = f.copy());
// f2.setMaterial(materials.get(f2.getMaterial().getName()));
// }
//
// }
public RenderModel(String fileName) {
int lastSlashIndex = fileName.lastIndexOf('/');
if (lastSlashIndex != -1) this.contextfolder = fileName.substring(0, lastSlashIndex + 1);
lastSlashIndex = fileName.lastIndexOf('\\');
if (lastSlashIndex != -1) this.contextfolder = fileName.substring(0, lastSlashIndex + 1);
parse(fileName);
calculateRadius();
}
private void calculateRadius() {
double currentNorm = 0;
for (Vertex vertex : vertices) {
currentNorm = vertex.norm();
if (currentNorm > radius) radius = currentNorm;
}
}
public String getContextfolder() {
return contextfolder;
}
public void parse(String fileName) {
parserFactory = new ObjLineParserFactory(this);
InputStream fileInput = ResourceLoader.getResourceAsStream(fileName);
if (fileInput == null) {
// Could not find the file in the jar.
try {
File file = new File(fileName);
if (file.exists()) fileInput = new FileInputStream(file);
} catch (Exception e2) {
e2.printStackTrace();
}
}
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(fileInput));
String currentLine = null;
while ((currentLine = in.readLine()) != null)
parseLine(currentLine);
in.close();
} catch (Exception e) {
Log.e("Error reading file " + fileName, e);
throw new RuntimeException(e);
}
//
// Log.finest("Loaded OBJ from file " + fileName);
// Log.finest(getVertices().size() + " vertices.");
// Log.finest(getNormals().size() + " normals.");
// Log.finest(getTextures().size() + " textures coordinates.");
// Log.finest(getFaces().size() + " faces.");
}
private int lineCounter = 0;
private void parseLine(String currentLine) {
if ("".equals(currentLine)) return;
LineParser parser = parserFactory.getLineParser(currentLine);
try {
parser.parse();
parser.incoporateResults(this);
} catch (Throwable t) {
Log.e("ERROR at line " + lineCounter + " : " + currentLine, t);
System.exit(1);
}
lineCounter++;
}
public int displayListId = 0;
public void render() {
if (displayListId != 0) {
GL11.glCallList(displayListId);
return;
}
displayListId = GL11.glGenLists(1);
GL11.glNewList(displayListId, GL11.GL_COMPILE);
Face face = null;
Material material = new Material("__non_existant");
for (int i = 0; i < getFaces().size(); i++) {
face = getFaces().get(i);
if (!material.equals(face.getMaterial())) {
// Set texture and setColor
material = face.getMaterial();
if (material == null) {
Log.w("No material in model!");
} else if (material.getTexture() != null) {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, material.getTexture().getTextureID());
} else
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
if (material != null && material.getKd() != null)
GL11.glColor3f(material.getKd().getX(), material.getKd().getY(), material.getKd().getZ());
}
if (face.getType() == Face.GL_TRIANGLES) {
GL11.glBegin(GL11.GL_TRIANGLES);
} else if (face.getType() == Face.GL_QUADS) {
GL11.glBegin(GL11.GL_QUADS);
} else {
GL11.glBegin(GL11.GL_POLYGON);
}
Vertex vertex = null;
Vertex normal = null;
TextureCoordinate textureCoo = null;
for (int j = 0; j < face.getVertices().length; j++) {
vertex = face.getVertices()[j];
if (j < face.getNormals().length && face.getNormals()[j] != null) {
normal = face.getNormals()[j];
GL11.glNormal3f(normal.getX(), normal.getY(), normal.getZ());
}
if (j < face.getTextures().length && face.getTextures()[j] != null) {
textureCoo = face.getTextures()[j];
GL11.glTexCoord2f(textureCoo.getU(), textureCoo.getV());
//GL11.glTexCoord2f(textureCoo.getV(),textureCoo.getU());
}
GL11.glVertex3f(vertex.getX(), vertex.getY(), vertex.getZ());
}
GL11.glEnd();
}
GL11.glEndList();
}
public void setMaterials(Hashtable<String, Material> materials) {
this.materials = materials;
}
public void setTextures(ArrayList<TextureCoordinate> textures) {
this.textures = textures;
}
public ArrayList<TextureCoordinate> getTextures() {
return textures;
}
public void setVertices(ArrayList<Vertex> vertices) {
this.vertices = vertices;
}
public ArrayList<Vertex> getVertices() {
return vertices;
}
public void setFaces(ArrayList<Face> faces) {
this.faces = faces;
}
public ArrayList<Face> getFaces() {
return faces;
}
public void setNormals(ArrayList<Vertex> normals) {
this.normals = normals;
}
public ArrayList<Vertex> getNormals() {
return normals;
}
public Hashtable<String, Material> getMaterials() {
return this.materials;
}
public Material getCurrentMaterial() {
return currentMaterial;
}
public void setCurrentMaterial(Material currentMaterial) {
this.currentMaterial = currentMaterial;
}
}

@ -0,0 +1,35 @@
package com.mykaruga.models.wavefront.loader;
public class TextureCoordinate {
private float u;
private float v;
private float w;
public float getU() {
return u;
}
public void setU(float u) {
this.u = u;
}
public float getV() {
return v;
}
public void setV(float v) {
this.v = v;
}
public float getW() {
return w;
}
public void setW(float w) {
this.w = w;
}
}

@ -0,0 +1,45 @@
package com.mykaruga.models.wavefront.loader;
public class Vertex {
private float x;
private float y;
private float z;
public Vertex(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
public Vertex() {}
public float getX() {
return x;
}
public void setX(float x) {
this.x = x;
}
public float getY() {
return y;
}
public void setY(float y) {
this.y = y;
}
public float getZ() {
return z;
}
public void setZ(float z) {
this.z = z;
}
public double norm() {
return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2));
}
}

@ -0,0 +1,15 @@
package com.mykaruga.models.wavefront.parser;
import com.mykaruga.models.wavefront.loader.RenderModel;
public class CommentParser extends LineParser {
@Override
public void incoporateResults(RenderModel wavefrontObject) {}
@Override
public void parse() {}
}

@ -0,0 +1,19 @@
package com.mykaruga.models.wavefront.parser;
import com.mykaruga.models.wavefront.loader.RenderModel;
public class DefaultParser extends LineParser {
public DefaultParser() {}
@Override
public void parse() {
}
@Override
public void incoporateResults(RenderModel wavefrontObject) {}
}

@ -0,0 +1,19 @@
package com.mykaruga.models.wavefront.parser;
import com.mykaruga.models.wavefront.loader.RenderModel;
public abstract class LineParser {
protected String[] words = null;
public void setWords(String[] words) {
this.words = words;
}
public abstract void parse();
public abstract void incoporateResults(RenderModel wavefrontObject);
}

@ -0,0 +1,41 @@
package com.mykaruga.models.wavefront.parser.mtl;
import net.spritegen.textures.TextureManager;
import org.newdawn.slick.opengl.Texture;
import com.mykaruga.models.wavefront.loader.Material;
import com.mykaruga.models.wavefront.loader.RenderModel;
import com.mykaruga.models.wavefront.parser.LineParser;
public class KdMapParser extends LineParser {
private Texture texture = null;
private RenderModel object = null;
private String textureFileName = null;
public KdMapParser(RenderModel object) {
this.object = object;
}
@Override
public void incoporateResults(RenderModel wavefrontObject) {
if (texture != null) {
Material currentMaterial = wavefrontObject.getCurrentMaterial();
currentMaterial.setTexture(texture);
}
}
@Override
public void parse() {
String textureFileName = words[words.length - 1];
String pathToTextureBinary = object.getContextfolder() + (object.replTexture == null ? textureFileName : object.replTexture);
// load texture, if already loaded, use the same instance.
texture = TextureManager.load(pathToTextureBinary);
}
}

@ -0,0 +1,35 @@
package com.mykaruga.models.wavefront.parser.mtl;
import com.mykaruga.models.wavefront.loader.Material;
import com.mykaruga.models.wavefront.loader.RenderModel;
import com.mykaruga.models.wavefront.loader.Vertex;
import com.mykaruga.models.wavefront.parser.LineParser;
public class KdParser extends LineParser {
Vertex kd = null;
@Override
public void incoporateResults(RenderModel wavefrontObject) {
Material currentMaterial = wavefrontObject.getCurrentMaterial();
currentMaterial.setKa(kd);
}
@Override
public void parse() {
kd = new Vertex();
try {
kd.setX(Float.parseFloat(words[1]));
kd.setY(Float.parseFloat(words[2]));
kd.setZ(Float.parseFloat(words[3]));
} catch (Exception e) {
throw new RuntimeException("VertexParser Error");
}
}
}

@ -0,0 +1,74 @@
package com.mykaruga.models.wavefront.parser.mtl;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Hashtable;
import org.newdawn.slick.util.ResourceLoader;
import com.mykaruga.models.wavefront.loader.Material;
import com.mykaruga.models.wavefront.loader.RenderModel;
import com.mykaruga.models.wavefront.parser.LineParser;
public class MaterialFileParser extends LineParser {
Hashtable<String, Material> materials = new Hashtable<String, Material>();
private RenderModel object;
private MtlLineParserFactory parserFactory = null;
public MaterialFileParser(RenderModel object) {
this.object = object;
this.parserFactory = new MtlLineParserFactory(object);
}
@Override
public void incoporateResults(RenderModel wavefrontObject) {
// Material are directly added by the parser, no need to do anything here...
}
@Override
public void parse() {
String filename = words[1];
String pathToMTL = object.getContextfolder() + filename;
InputStream fileInput = ResourceLoader.getResourceAsStream(pathToMTL);
if (fileInput == null) {
// Could not find the file in the jar.
try {
File file = new File(pathToMTL);
if (file.exists()) fileInput = new FileInputStream(file);
} catch (Exception e2) {
e2.printStackTrace();
}
}
try {
BufferedReader in = new BufferedReader(new InputStreamReader(fileInput));
String currentLine = null;
while ((currentLine = in.readLine()) != null) {
LineParser parser = parserFactory.getLineParser(currentLine);
parser.parse();
parser.incoporateResults(object);
}
if (in != null) in.close();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Error parsing " + pathToMTL);
}
}
}

@ -0,0 +1,27 @@
package com.mykaruga.models.wavefront.parser.mtl;
import com.mykaruga.models.wavefront.loader.Material;
import com.mykaruga.models.wavefront.loader.RenderModel;
import com.mykaruga.models.wavefront.parser.LineParser;
public class MaterialParser extends LineParser {
String materialName = "";
@Override
public void incoporateResults(RenderModel wavefrontObject) {
Material newMaterial = new Material(materialName);
wavefrontObject.getMaterials().put(materialName, newMaterial);
wavefrontObject.setCurrentMaterial(newMaterial);
}
@Override
public void parse() {
materialName = words[1];
}
}

@ -0,0 +1,24 @@
package com.mykaruga.models.wavefront.parser.mtl;
import com.mykaruga.models.wavefront.loader.LineParserFactory;
import com.mykaruga.models.wavefront.loader.RenderModel;
import com.mykaruga.models.wavefront.parser.CommentParser;
public class MtlLineParserFactory extends LineParserFactory {
public MtlLineParserFactory(RenderModel object) {
this.object = object;
parsers.put("newmtl", new MaterialParser());
parsers.put("Kd", new KdParser());
parsers.put("map_Kd", new KdMapParser(object));
parsers.put("#", new CommentParser());
}
}

@ -0,0 +1,98 @@
package com.mykaruga.models.wavefront.parser.obj;
import com.mykaruga.models.wavefront.loader.Face;
import com.mykaruga.models.wavefront.loader.RenderModel;
import com.mykaruga.models.wavefront.loader.TextureCoordinate;
import com.mykaruga.models.wavefront.loader.Vertex;
import com.mykaruga.models.wavefront.parser.LineParser;
public class FaceParser extends LineParser {
private Face face;
private Vertex[] vertices;
private Vertex[] normals;
private TextureCoordinate[] textures;
private RenderModel object = null;
public FaceParser(RenderModel object) {
this.object = object;
}
@Override
public void parse() {
face = new Face();
normals = new Vertex[words.length - 1];
textures = new TextureCoordinate[words.length - 1];
switch (words.length) {
case 4:
parseTriangles();
break;
case 5:
parseQuad();
break;
default:
parsePolygon();
}
}
private void parseTriangles() {
face.setType(Face.GL_TRIANGLES);
parseLine(3);
}
private void parsePolygon() {
face.setType(words.length - 1);
parseLine(words.length - 1);
}
private void parseLine(int vertexCount) {
String[] rawFaces = null;
int currentValue;
vertices = new Vertex[vertexCount];
for (int i = 1; i <= vertexCount; i++) {
rawFaces = words[i].split("/");
// v
currentValue = Integer.parseInt(rawFaces[0]);
vertices[i - 1] = object.getVertices().get(currentValue - 1); // -1 because references starts at 1
if (rawFaces.length == 1) continue;
if (!"".equals(rawFaces[1]) && rawFaces.length == 3) {
currentValue = Integer.parseInt(rawFaces[1]);
if (currentValue <= object.getTextures().size()) // This is to compensate the fact that if no texture is in the obj file, sometimes '1' is put instead of 'blank' (we find coord1/1/coord3 instead of coord1//coord3 or coord1/coord3)
textures[i - 1] = object.getTextures().get(currentValue - 1); // -1 because references starts at 1
}
currentValue = Integer.parseInt(rawFaces[rawFaces.length - 1]);
normals[i - 1] = object.getNormals().get(currentValue - 1); // -1 because references starts at 1
}
}
private void parseQuad() {
face.setType(Face.GL_QUADS);
parseLine(4);
}
@Override
public void incoporateResults(RenderModel wavefrontObject) {
face.setNormals(this.normals);
face.setVertices(this.vertices);
face.setTextures(this.textures);
if (wavefrontObject.getCurrentMaterial() != null) {
face.setMaterial(wavefrontObject.getCurrentMaterial());
}
wavefrontObject.getFaces().add(face);
}
static int faceC = 0;
}

@ -0,0 +1,21 @@
package com.mykaruga.models.wavefront.parser.obj;
import com.mykaruga.models.wavefront.loader.RenderModel;
import com.mykaruga.models.wavefront.parser.LineParser;
public class FreeFormParser extends LineParser {
public FreeFormParser() {}
@Override
public void parse() {
}
@Override
public void incoporateResults(RenderModel wavefrontObject) {}
}

@ -0,0 +1,27 @@
package com.mykaruga.models.wavefront.parser.obj;
import com.mykaruga.models.wavefront.loader.Material;
import com.mykaruga.models.wavefront.loader.RenderModel;
import com.mykaruga.models.wavefront.parser.LineParser;
public class MaterialParser extends LineParser {
String materialName = "";
@Override
public void parse() {
materialName = words[1];
}
@Override
public void incoporateResults(RenderModel wavefrontObject) {
Material newMaterial = wavefrontObject.getMaterials().get(materialName);
wavefrontObject.setCurrentMaterial(newMaterial);
}
}

@ -0,0 +1,29 @@
package com.mykaruga.models.wavefront.parser.obj;
import com.mykaruga.models.wavefront.loader.LineParserFactory;
import com.mykaruga.models.wavefront.loader.NormalParser;
import com.mykaruga.models.wavefront.loader.RenderModel;
import com.mykaruga.models.wavefront.parser.CommentParser;
import com.mykaruga.models.wavefront.parser.mtl.MaterialFileParser;
public class ObjLineParserFactory extends LineParserFactory {
public ObjLineParserFactory(RenderModel object) {
this.object = object;
parsers.put("v", new VertexParser());
parsers.put("vn", new NormalParser());
parsers.put("vp", new FreeFormParser());
parsers.put("vt", new TextureCooParser());
parsers.put("f", new FaceParser(object));
parsers.put("#", new CommentParser());
parsers.put("mtllib", new MaterialFileParser(object));
parsers.put("usemtl", new MaterialParser());
}
}

@ -0,0 +1,37 @@
package com.mykaruga.models.wavefront.parser.obj;
import com.mykaruga.models.wavefront.loader.RenderModel;
import com.mykaruga.models.wavefront.loader.TextureCoordinate;
import com.mykaruga.models.wavefront.parser.LineParser;
public class TextureCooParser extends LineParser {
private TextureCoordinate coordinate = null;
public TextureCooParser() {}
@Override
public void parse() {
coordinate = new TextureCoordinate();
try {
if (words.length >= 2) coordinate.setU(Float.parseFloat(words[1]));
if (words.length >= 3) coordinate.setV(1 - Float.parseFloat(words[2])); // OBJ origin is at upper left, OpenGL origin is at lower left.
if (words.length >= 4) coordinate.setW(Float.parseFloat(words[3]));
} catch (Exception e) {
throw new RuntimeException("TextureParser Error");
}
}
@Override
public void incoporateResults(RenderModel wavefrontObject) {
wavefrontObject.getTextures().add(coordinate);
}
}

@ -0,0 +1,34 @@
package com.mykaruga.models.wavefront.parser.obj;
import com.mykaruga.models.wavefront.loader.RenderModel;
import com.mykaruga.models.wavefront.loader.Vertex;
import com.mykaruga.models.wavefront.parser.LineParser;
public class VertexParser extends LineParser {
Vertex vertex = null;
public VertexParser() {}
@Override
public void parse() {
vertex = new Vertex();
try {
vertex.setX(Float.parseFloat(words[1]));
vertex.setY(Float.parseFloat(words[2]));
vertex.setZ(Float.parseFloat(words[3]));
} catch (Exception e) {
throw new RuntimeException("VertexParser Error");
}
}
@Override
public void incoporateResults(RenderModel wavefrontObject) {
wavefrontObject.getVertices().add(vertex);
}
}

@ -0,0 +1,152 @@
package com.porcupine.color;
import java.awt.Color;
import com.porcupine.math.Calc;
/**
* HSV color
*
* @author MightyPork
*/
public class HSV {
/** H */
public double h;
/** S */
public double s;
/** V */
public double v;
/**
* Create black color 0,0,0
*/
public HSV() {}
/**
* Color from HSV 0-1
*
* @param h
* @param s
* @param v
*/
public HSV(Number h, Number s, Number v) {
this.h = h.doubleValue();
this.s = s.doubleValue();
this.v = v.doubleValue();
norm();
}
/**