diff options
-rw-r--r-- | src/net/java/joglutils/model/geometry/Bounds.java | 129 | ||||
-rw-r--r-- | src/net/java/joglutils/model/geometry/Face.java | 59 | ||||
-rw-r--r-- | src/net/java/joglutils/model/geometry/Material.java | 58 | ||||
-rw-r--r-- | src/net/java/joglutils/model/geometry/Mesh.java | 64 | ||||
-rw-r--r-- | src/net/java/joglutils/model/geometry/Model.java | 196 | ||||
-rw-r--r-- | src/net/java/joglutils/model/geometry/TexCoord.java | 27 | ||||
-rw-r--r-- | src/net/java/joglutils/model/geometry/Vec4.java | 70 |
7 files changed, 603 insertions, 0 deletions
diff --git a/src/net/java/joglutils/model/geometry/Bounds.java b/src/net/java/joglutils/model/geometry/Bounds.java new file mode 100644 index 0000000..42e7b89 --- /dev/null +++ b/src/net/java/joglutils/model/geometry/Bounds.java @@ -0,0 +1,129 @@ +package net.java.joglutils.model.geometry; + +/** + * Provides a instance of a boundary object that stores the maximum and + * minimum extents of a bounding box in 3D space. + * <p> + * + * @version $Id$ + */ +public class Bounds { + + /** A static representation of a large number to be used for initialization of the boundaries */ + public static final float LARGE = Float.MAX_VALUE; + + /** The minimum point of the bounding box */ + public Vec4 min = new Vec4( LARGE, LARGE, LARGE); + + /** The maximum point of the bounding box */ + public Vec4 max = new Vec4(-LARGE, -LARGE, -LARGE); + + /** + * Default constructor that creates an instance of the Bounds object with + * the minimum and maximum bounding points initialized to the largest + * extents expected. + */ + public Bounds() { + // Nothing + } + + /** + * Constructor that initializes the bounding box to the specified bounding + * values passed in as individual x,y,z points + * + * @param x1 The x coordinate of the minimum boundary point + * @param y1 The y coordinate of the minimum boundary point + * @param z1 The z coordinate of the minimum boundary point + * @param x2 The x coordinate of the maximum boundary point + * @param y2 The y coordinate of the maximum boundary point + * @param z2 The z coordinate of the maximum boundary point + */ + public Bounds( float x1, float y1, float z1, + float x2, float y2, float z2 ) { + min.x = x1; + min.y = y1; + min.z = z1; + + max.x = x2; + max.y = y2; + max.z = z2; + } + + /** + * Constructor that initializes the bounding box to the specified bounding + * values passed in as vectors + * + * @param v1 The minimum boundary point specified by a Vec3 object + * @param v2 The maximum boundary point specified by a Vec3 object + */ + public Bounds( Vec4 v1, Vec4 v2 ) { + min.x = v1.x; + min.y = v1.y; + min.z = v1.z; + + max.x = v2.x; + max.y = v2.y; + max.z = v2.z; + } + + /** + * Recalculates the boundary limits based on the coordinates of a point + * passed into it. If any of the coordinates of the passed in point are + * beyond the current bounding box limits then the bounding box is expanded. + * + * @param x The x coordinate of a point used to adjust the boundary box + * @param y The y coordinate of a point used to adjust the boundary box + * @param z The z coordinate of a point used to adjust the boundary box + */ + public void calc( float x, float y, float z ) { + // Compare x component and expand the bounding box as needed + if (x > max.x) { + max.x = x; + } + if (x < min.x) { + min.x = x; + } + + // Compare y component and expand the bounding box as needed + if (y > max.y) { + max.y = y; + } + if (y < min.y) { + min.y = y; + } + + // Compare z component and expand the bounding box as needed + if (z > max.z) { + max.z = z; + } + if (z < min.z) { + min.z = z; + } + } + + /** + * Recalculates the boundary limits based on the coordinates of a point + * passed into it. If any of the coordinates of the passed in point are + * beyond the current bounding box limits then the bounding box is expanded. + * + * @param v The Vec3 instance of a point used to adjust the boundary box + */ + public void calc( Vec4 v ) { + calc(v.x, v.y, v.z); + } + + public float getRadius() { + return 0.5f*(float)Math.sqrt(Math.pow(max.x-min.x, 2) + Math.pow(max.y-min.y, 2) + Math.pow(max.z-min.z, 2)); + } + + /** + * Generates the String to represent a Bounds object in a nice format for + * output purposes. + * + * @return The String representation of a Bounds object + */ + public String toString() { + return "mininum: (" + min.x + ", " + min.y + ", " + min.z + ") " + + "maximum: (" + max.x + ", " + max.y + ", " + max.z + ")"; + } +}
\ No newline at end of file diff --git a/src/net/java/joglutils/model/geometry/Face.java b/src/net/java/joglutils/model/geometry/Face.java new file mode 100644 index 0000000..e05311c --- /dev/null +++ b/src/net/java/joglutils/model/geometry/Face.java @@ -0,0 +1,59 @@ +/*
+ * Copyright (c) 2006 Greg Rodgers All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * The names of Greg Rodgers, Sun Microsystems, Inc. or the names of
+ * contributors may not be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. GREG RODGERS,
+ * SUN MICROSYSTEMS, INC. ("SUN"), AND SUN'S LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL GREG
+ * RODGERS, SUN, OR SUN'S LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
+ * OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
+ * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF GREG
+ * RODGERS OR SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ */
+
+package net.java.joglutils.model.geometry;
+
+public class Face
+{
+ public int vertIndex[];
+ public int coordIndex[];
+ public int normalIndex[];
+
+// public Face() {
+// vertIndex = new int[3];
+// coordIndex = new int[3];
+// normalIndex = new int[3];
+// }
+
+ public Face(int numVertices) {
+ vertIndex = new int[numVertices];
+ coordIndex = new int[numVertices];
+ normalIndex = new int[numVertices];
+ }
+
+ /** MaterialID is associated with a Face - per 3DS specification */
+ public int materialID = 0;
+}
\ No newline at end of file diff --git a/src/net/java/joglutils/model/geometry/Material.java b/src/net/java/joglutils/model/geometry/Material.java new file mode 100644 index 0000000..4085c72 --- /dev/null +++ b/src/net/java/joglutils/model/geometry/Material.java @@ -0,0 +1,58 @@ +/*
+ * Copyright (c) 2006 Greg Rodgers All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * The names of Greg Rodgers, Sun Microsystems, Inc. or the names of
+ * contributors may not be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. GREG RODGERS,
+ * SUN MICROSYSTEMS, INC. ("SUN"), AND SUN'S LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL GREG
+ * RODGERS, SUN, OR SUN'S LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
+ * OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
+ * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF GREG
+ * RODGERS OR SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ */
+
+package net.java.joglutils.model.geometry;
+
+import java.awt.Color;
+
+public class Material
+{
+ public String strName;
+ public String strFile;
+
+ public Color ambientColor;
+ public Color specularColor;
+ public Color diffuseColor;
+ public Color emissive = Color.BLACK;
+ public float shininess;
+ public float shininess2;
+ public float transparency;
+ public int textureId;
+ public float uTile;
+ public float vTile;
+ public float uOffset;
+ public float vOffset;
+}
\ No newline at end of file diff --git a/src/net/java/joglutils/model/geometry/Mesh.java b/src/net/java/joglutils/model/geometry/Mesh.java new file mode 100644 index 0000000..76af31e --- /dev/null +++ b/src/net/java/joglutils/model/geometry/Mesh.java @@ -0,0 +1,64 @@ +/*
+ * Copyright (c) 2006 Greg Rodgers All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * The names of Greg Rodgers, Sun Microsystems, Inc. or the names of
+ * contributors may not be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. GREG RODGERS,
+ * SUN MICROSYSTEMS, INC. ("SUN"), AND SUN'S LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL GREG
+ * RODGERS, SUN, OR SUN'S LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
+ * OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
+ * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF GREG
+ * RODGERS OR SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ */
+
+package net.java.joglutils.model.geometry;
+
+import java.util.Vector;
+
+public class Mesh
+{
+ public int numOfVerts = 0;
+ public int numOfFaces = 0;
+ public int numTexCoords = 0;
+ public int materialID = 0;
+ public boolean hasTexture = false;
+ public String name = null;
+ public int indices = 0;
+ public Vec4 vertices[] = null;
+ public Vec4 normals[] = null;
+ public TexCoord texCoords[] = null;
+ public Face faces[] = null;
+ public Bounds bounds = null;
+
+ public Mesh() {
+ this("default");
+ }
+
+ public Mesh(String name) {
+ this.name = name;
+ bounds = new Bounds();
+ }
+}
\ No newline at end of file diff --git a/src/net/java/joglutils/model/geometry/Model.java b/src/net/java/joglutils/model/geometry/Model.java new file mode 100644 index 0000000..a4781b1 --- /dev/null +++ b/src/net/java/joglutils/model/geometry/Model.java @@ -0,0 +1,196 @@ +/*
+ * Copyright (c) 2006 Greg Rodgers All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * The names of Greg Rodgers, Sun Microsystems, Inc. or the names of
+ * contributors may not be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. GREG RODGERS,
+ * SUN MICROSYSTEMS, INC. ("SUN"), AND SUN'S LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL GREG
+ * RODGERS, SUN, OR SUN'S LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
+ * OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
+ * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF GREG
+ * RODGERS OR SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ */
+
+package net.java.joglutils.model.geometry;
+
+import java.util.Vector;
+
+public class Model
+{
+ protected Vector<Material> materials = new Vector<Material>();
+ protected Vector<Mesh> mesh = new Vector<Mesh>();
+ protected String source;
+
+ protected boolean renderModel = true;
+ protected boolean centerModel = false;
+ protected boolean renderModelBounds = false;
+ protected boolean renderObjectBounds = false;
+ protected boolean unitizeSize = true;
+ protected boolean useTexture = true;
+ protected boolean renderAsWireframe = false;
+ protected boolean useLighting = true;
+
+ /** Bounds of the model */
+ protected Bounds bounds = new Bounds();
+ /** Center point of the model */
+ private Vec4 centerPoint = new Vec4(0.0f, 0.0f, 0.0f);
+
+ // Constructor
+ public Model(String source)
+ {
+ this.source = source;
+ }
+
+ // Add material
+ public void addMaterial(Material mat)
+ {
+ materials.add(mat);
+ }
+
+ // Add a mesh
+ public void addMesh(Mesh obj)
+ {
+ mesh.add(obj);
+ }
+
+ // Get material
+ public Material getMaterial(int index)
+ {
+ return materials.get(index);
+ }
+
+ // Get a a mesh
+ public Mesh getMesh(int index)
+ {
+ return mesh.get(index);
+ }
+
+ // Get the number of meshes
+ public int getNumberOfMeshes()
+ {
+ return mesh.size();
+ }
+
+ // Get the number of materials
+ public int getNumberOfMaterials()
+ {
+ return materials.size();
+ }
+
+ public String getSource() {
+ return source;
+ }
+
+ public boolean isRenderModel() {
+ return renderModel;
+ }
+
+ public void setRenderModel(boolean renderModel) {
+ this.renderModel = renderModel;
+ }
+
+ public boolean isCentered() {
+ return centerModel;
+ }
+
+ public void centerModelOnPosition(boolean centerModel) {
+ this.centerModel = centerModel;
+ }
+
+ public boolean isRenderModelBounds() {
+ return renderModelBounds;
+ }
+
+ public void setRenderModelBounds(boolean renderModelBounds) {
+ this.renderModelBounds = renderModelBounds;
+ }
+
+ public boolean isRenderObjectBounds() {
+ return renderObjectBounds;
+ }
+
+ public void setRenderObjectBounds(boolean renderObjectBounds) {
+ this.renderObjectBounds = renderObjectBounds;
+ }
+
+ /**
+ * Returns the bounds of the model
+ *
+ * @return Bounds of the model
+ */
+ public Bounds getBounds() {
+ return bounds;
+ }
+
+ public void setBounds(Bounds bounds) {
+ this.bounds = bounds;
+ }
+
+ /**
+ * Returns the center of the model bounds
+ *
+ * @return Center of the model
+ */
+ public Vec4 getCenterPoint() {
+ return this.centerPoint;
+ }
+
+ public void setCenterPoint(Vec4 center) {
+ this.centerPoint = center;
+ }
+
+ public boolean isUnitizeSize() {
+ return unitizeSize;
+ }
+
+ public void setUnitizeSize(boolean unitizeSize) {
+ this.unitizeSize = unitizeSize;
+ }
+
+ public boolean isUsingTexture() {
+ return useTexture;
+ }
+
+ public void setUseTexture(boolean useTexture) {
+ this.useTexture = useTexture;
+ }
+
+ public boolean isRenderingAsWireframe() {
+ return renderAsWireframe;
+ }
+
+ public void setRenderAsWireframe(boolean renderAsWireframe) {
+ this.renderAsWireframe = renderAsWireframe;
+ }
+
+ public boolean isUsingLighting() {
+ return useLighting;
+ }
+
+ public void setUseLighting(boolean useLighting) {
+ this.useLighting = useLighting;
+ }
+}
diff --git a/src/net/java/joglutils/model/geometry/TexCoord.java b/src/net/java/joglutils/model/geometry/TexCoord.java new file mode 100644 index 0000000..6c40d6b --- /dev/null +++ b/src/net/java/joglutils/model/geometry/TexCoord.java @@ -0,0 +1,27 @@ +/*
+ * TexCoords.java
+ *
+ * Created on February 28, 2008, 10:29 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package net.java.joglutils.model.geometry;
+
+/**
+ *
+ * @author RodgersGB
+ */
+public class TexCoord {
+ public float u,v;
+
+ public TexCoord() {
+ u = v = 0;
+ }
+
+ public TexCoord(float u, float v) {
+ this.u = u;
+ this.v = v;
+ }
+}
diff --git a/src/net/java/joglutils/model/geometry/Vec4.java b/src/net/java/joglutils/model/geometry/Vec4.java new file mode 100644 index 0000000..0253034 --- /dev/null +++ b/src/net/java/joglutils/model/geometry/Vec4.java @@ -0,0 +1,70 @@ +/*
+ * Copyright (c) 2006 Greg Rodgers All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * The names of Greg Rodgers, Sun Microsystems, Inc. or the names of
+ * contributors may not be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. GREG RODGERS,
+ * SUN MICROSYSTEMS, INC. ("SUN"), AND SUN'S LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL GREG
+ * RODGERS, SUN, OR SUN'S LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
+ * OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
+ * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF GREG
+ * RODGERS OR SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ */
+
+package net.java.joglutils.model.geometry;
+
+public class Vec4
+{
+ public float x,y,z,w;
+
+ public Vec4()
+ {
+ this(0,0,0);
+ }
+
+ public Vec4(float _x, float _y, float _z)
+ {
+ x = _x;
+ y = _y;
+ z = _z;
+ }
+
+ public Vec4(float _x, float _y, float _z, float _w)
+ {
+ x = _x;
+ y = _y;
+ z = _z;
+ w = _w;
+ }
+
+ public Vec4(Vec4 v)
+ {
+ x = v.x;
+ y = v.y;
+ z = v.z;
+ w = v.w;
+ }
+}
\ No newline at end of file |