Tweaks to the Vector package, and finalized the Model structure. So I hope.

This commit is contained in:
Caspian Rychlik-Prince 2004-04-19 21:54:58 +00:00
parent f33a019675
commit c41ac67aae
12 changed files with 385 additions and 106 deletions

View File

@ -45,11 +45,15 @@ public class Frame implements Serializable {
/** The new transformations for each Bone in the Skeleton */ /** The new transformations for each Bone in the Skeleton */
private final Matrix4f[] bone; private final Matrix4f[] bone;
/** Frame time */
private final float time;
/** /**
* C'tor * C'tor
* @param bone[] * @param bone[]
*/ */
public Frame(Matrix4f[] bone) { public Frame(float time, Matrix4f[] bone) {
this.time = time;
this.bone = bone; this.bone = bone;
} }
@ -59,4 +63,11 @@ public class Frame implements Serializable {
public Matrix4f[] getBone() { public Matrix4f[] getBone() {
return bone; return bone;
} }
/**
* @return the frame time
*/
public float getTime() {
return time;
}
} }

View File

@ -51,23 +51,34 @@ public class Model implements Serializable {
public static final long serialVersionUID = 1L; public static final long serialVersionUID = 1L;
/** The Mesh */ /** Material */
private final Mesh mesh; private final String material;
/** Vertices */
private final Vertex[] vertex;
/** Triangles */
private final Triangle[] triangle;
/** The animations: a Map of string names to Frame[] arrays */ /** The animations: a Map of string names to Frame[] arrays */
private final Map animation; private final Map animation;
/** /**
* C'tor * C'tor
* @param mesh * @param material
* @param frame * @param vertex
* @param triangle
* @param animation
*/ */
public Model(Mesh mesh, Map animation) { public Model(String material, Vertex[] vertex, Triangle[] triangle, Map animation) {
this.mesh = mesh; this.material = material;
this.vertex = vertex;
this.triangle = triangle;
this.animation = animation; this.animation = animation;
} }
/** /**
* Get a named animation from the Model
* @param name The name of the animation * @param name The name of the animation
* @return the Frames of an animation (or null, if no such animation exists) * @return the Frames of an animation (or null, if no such animation exists)
*/ */
@ -76,10 +87,25 @@ public class Model implements Serializable {
} }
/** /**
* @return the Mesh * @return Returns the material.
*/ */
public Mesh getMesh() { public String getMaterial() {
return mesh; return material;
} }
/**
* @return Returns the triangles.
*/
public Triangle[] getTriangle() {
return triangle;
}
/**
* @return Returns the vertices
*/
public Vertex[] getVertex() {
return vertex;
}
} }

View File

@ -35,58 +35,39 @@ import java.io.Serializable;
/** /**
* $Id$ * $Id$
* * Describes how a bone influences a vertex.
* A Mesh is a collection of Triangles that all share the same material (ie. rendering
* state).
*
* @author $Author$ * @author $Author$
* @version $Revision$ * @version $Revision$
*/ */
public class Mesh implements Serializable { public class Skin implements Serializable {
public static final long serialVersionUID = 1L; public static final long serialVersionUID = 1L;
/** Material */ /** Bone index */
private final String material; private final int bone;
/** Vertices */
private final Vertex[] vertex;
/** Triangles */
private final Triangle[] triangle;
/** Weight */
private final float weight;
/** /**
* C'tor * C'tor
* @param material
* @param vertex
* @param triangle
*/ */
public Mesh(String material, Vertex[] vertex, Triangle[] triangle) { public Skin(int bone, float weight) {
this.material = material; this.bone = bone;
this.vertex = vertex; this.weight = weight;
this.triangle = triangle;
} }
/** /**
* @return Returns the material. * @return Returns the bone index.
*/ */
public String getMaterial() { public int getBone() {
return material; return bone;
} }
/** /**
* @return Returns the triangles. * @return Returns the weight.
*/ */
public Triangle[] getTriangle() { public float getWeight() {
return triangle; return weight;
} }
/**
* @return Returns the vertices
*/
public Vertex[] getVertex() {
return vertex;
}
} }

View File

@ -31,24 +31,59 @@
*/ */
package org.lwjgl.util.model; package org.lwjgl.util.model;
import java.io.Serializable;
/** /**
* $Id$ * $Id$
* @author $Author$ * @author $Author$
* @version $Revision$ * @version $Revision$
*/ */
public class Triangle { public class Triangle implements Serializable {
public static final long serialVersionUID = 1L; public static final long serialVersionUID = 1L;
/** Vertex indices: these look up into the parent Mesh's vertex array */ /** Vertex indices: these look up into the parent Mesh's vertex array */
private int a, b, c; private final int a, b, c;
/** Adjacency, for stripification */ /** Adjacency, for stripification */
private int adjacency; private final int adjacency;
/** /**
* C'tor * C'tor
* @param a
* @param b
* @param c
* @param adjacency
*/ */
public Triangle() { public Triangle(int a, int b, int c, int adjacency) {
this.a = a;
this.b = b;
this.c = c;
this.adjacency = adjacency;
}
/**
* @return Returns the 'a' vertex index
*/
public int getA() {
return a;
}
/**
* @return Returns the 'b' vertex index
*/
public int getB() {
return b;
}
/**
* @return Returns the 'c' vertex index
*/
public int getC() {
return c;
}
/**
* @return Returns the adjacency.
*/
public int getAdjacency() {
return adjacency;
} }
} }

View File

@ -33,10 +33,13 @@ package org.lwjgl.util.model;
import java.io.Serializable; import java.io.Serializable;
import org.lwjgl.util.vector.ReadableVector2f;
import org.lwjgl.util.vector.ReadableVector3f;
/** /**
* $Id$ * $Id$
* *
* A single vertex in a Triangle * A single vertex in a mesh.
* *
* @author $Author$ * @author $Author$
* @version $Revision$ * @version $Revision$
@ -46,44 +49,56 @@ public class Vertex implements Serializable {
public static final long serialVersionUID = 1L; public static final long serialVersionUID = 1L;
/** Coordinates */ /** Coordinates */
private final float x, y, z; private final ReadableVector3f coords;
/** Normal */ /** Normal */
private final float nx, ny, nz; private final ReadableVector3f normal;
/** Texture coordinates */ /** Texture coordinates */
private final float u, v; private final ReadableVector2f texCoords;
/** Bone indices: these look up into the current Frame's bone array */ /** Skin */
private final int[] bone; private final Skin[] skin;
/** Bone weights (always sum to 1.0f) */
private final float[] weight;
/** /**
* C'tor * C'tor
* @param x * @param coords
* @param y * @param normal
* @param z * @param texCoords
* @param nx * @param skin
* @param ny
* @param nz
* @param u
* @param v
* @param bone
* @param weight
*/ */
public Vertex(float x, float y, float z, float nx, float ny, float nz, public Vertex(ReadableVector3f coords, ReadableVector3f normal, ReadableVector2f texCoords, Skin[] skin) {
float u, float v, int[] bone, float[] weight) { this.coords = coords;
this.x = x; this.normal = normal;
this.y = y; this.texCoords = texCoords;
this.z = z; this.skin = skin;
this.nx = nx; }
this.ny = ny;
this.nz = nz; /**
this.u = u; * @return Returns the coords.
this.v = v; */
this.bone = bone; public ReadableVector3f getCoords() {
this.weight = weight; return coords;
}
/**
* @return Returns the normal.
*/
public ReadableVector3f getNormal() {
return normal;
}
/**
* @return Returns the skin.
*/
public Skin[] getSkin() {
return skin;
}
/**
* @return Returns the texCoords.
*/
public ReadableVector2f getTexCoords() {
return texCoords;
} }
} }

View File

@ -34,6 +34,7 @@ package org.lwjgl.util.model.renderer;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.lwjgl.util.model.Frame;
import org.lwjgl.util.model.Model; import org.lwjgl.util.model.Model;
/** /**
@ -63,11 +64,24 @@ public class Renderer {
/** /**
* Render a Model * Render a Model
* @param model The model to render * @param model The model to render
* @param animation The name of the animation
* @param time The time for the animation
*/ */
public void render(Model model) { public void render(Model model, String animation, float time) {
// 1. Set up GL state from the Model's material // 1. Set up GL state from the Model's material
Renderable material = (Renderable) materials.get(model.getMesh().getMaterial()); Renderable material = (Renderable) materials.get(model.getMaterial());
if (material != null) {
material.render();
}
// 2. Get the animation
Frame[] frame = model.getAnimation(animation);
if (frame == null) {
return;
}
// 3. Work out what the nearest frame is to the specified time
} }

View File

@ -43,7 +43,7 @@ import java.nio.FloatBuffer;
* @version $Revision$ * @version $Revision$
*/ */
public class Vector2f extends Vector implements Serializable, ReadableVector2f { public class Vector2f extends Vector implements Serializable, ReadableVector2f, WritableVector2f {
public float x, y; public float x, y;
@ -68,14 +68,12 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f {
set(x, y); set(x, y);
} }
/** /* (non-Javadoc)
* Set values * @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
* @return this
*/ */
public Vector2f set(float x, float y) { public void set(float x, float y) {
this.x = x; this.x = x;
this.y = y; this.y = y;
return this;
} }
/** /**
@ -188,7 +186,8 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f {
if (dest == null) if (dest == null)
return new Vector2f(left.x + right.x, left.y + right.y); return new Vector2f(left.x + right.x, left.y + right.y);
else { else {
return dest.set(left.x + right.x, left.y + right.y); dest.set(left.x + right.x, left.y + right.y);
return dest;
} }
} }
@ -204,7 +203,8 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f {
if (dest == null) if (dest == null)
return new Vector2f(left.x - right.x, left.y - right.y); return new Vector2f(left.x - right.x, left.y - right.y);
else { else {
return dest.set(left.x - right.x, left.y - right.y); dest.set(left.x - right.x, left.y - right.y);
return dest;
} }
} }

View File

@ -43,7 +43,7 @@ import java.nio.FloatBuffer;
* @version $Revision$ * @version $Revision$
*/ */
public class Vector3f extends Vector implements Serializable, ReadableVector3f { public class Vector3f extends Vector implements Serializable, ReadableVector3f, WritableVector3f {
public float x, y, z; public float x, y, z;
@ -68,15 +68,21 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f {
set(x, y, z); set(x, y, z);
} }
/** /* (non-Javadoc)
* Set values * @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
* @return this
*/ */
public Vector3f set(float x, float y, float z) { public void set(float x, float y) {
this.x = x;
this.y = y;
}
/* (non-Javadoc)
* @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
*/
public void set(float x, float y, float z) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
return this;
} }
/** /**
@ -123,7 +129,8 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f {
if (dest == null) if (dest == null)
return new Vector3f(left.x + right.x, left.y + right.y, left.z + right.z); return new Vector3f(left.x + right.x, left.y + right.y, left.z + right.z);
else { else {
return dest.set(left.x + right.x, left.y + right.y, left.z + right.z); dest.set(left.x + right.x, left.y + right.y, left.z + right.z);
return dest;
} }
} }
@ -139,7 +146,8 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f {
if (dest == null) if (dest == null)
return new Vector3f(left.x - right.x, left.y - right.y, left.z - right.z); return new Vector3f(left.x - right.x, left.y - right.y, left.z - right.z);
else { else {
return dest.set(left.x - right.x, left.y - right.y, left.z - right.z); dest.set(left.x - right.x, left.y - right.y, left.z - right.z);
return dest;
} }
} }

View File

@ -43,7 +43,7 @@ import java.nio.FloatBuffer;
* @version $Revision$ * @version $Revision$
*/ */
public class Vector4f extends Vector implements Serializable, ReadableVector4f { public class Vector4f extends Vector implements Serializable, ReadableVector4f, WritableVector4f {
public float x, y, z, w; public float x, y, z, w;
@ -68,16 +68,31 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f {
set(x, y, z, w); set(x, y, z, w);
} }
/** /* (non-Javadoc)
* Set values * @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
* @return this
*/ */
public Vector4f set(float x, float y, float z, float w) { public void set(float x, float y) {
this.x = x;
this.y = y;
}
/* (non-Javadoc)
* @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
*/
public void set(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
/* (non-Javadoc)
* @see org.lwjgl.util.vector.WritableVector4f#set(float, float, float, float)
*/
public void set(float x, float y, float z, float w) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.w = w; this.w = w;
return this;
} }
/** /**
@ -126,7 +141,8 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f {
if (dest == null) if (dest == null)
return new Vector4f(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w); return new Vector4f(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
else { else {
return dest.set(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w); dest.set(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
return dest;
} }
} }
@ -142,7 +158,8 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f {
if (dest == null) if (dest == null)
return new Vector4f(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w); return new Vector4f(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
else { else {
return dest.set(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w); dest.set(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
return dest;
} }
} }
@ -294,6 +311,7 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f {
this.z = z; this.z = z;
} }
/* (Overrides) /* (Overrides)
* @see org.lwjgl.vector.ReadableVector3f#getZ() * @see org.lwjgl.vector.ReadableVector3f#getZ()
*/ */

View File

@ -0,0 +1,61 @@
/*
* Copyright (c) 2003 Shaven Puppy Ltd
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions 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.
*
* * Neither the name of 'Shaven Puppy' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.util.vector;
/**
* $Id$
* Writable interface to Vector2fs
* @author $author$
* @version $revision$
*/
public interface WritableVector2f {
/**
* Set the X value
* @param x
*/
public void setX(float x);
/**
* Set the Y value
* @param y
*/
public void setY(float y);
/**
* Set the X,Y values
* @param x, y
*/
public void set(float x, float y);
}

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2003 Shaven Puppy Ltd
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions 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.
*
* * Neither the name of 'Shaven Puppy' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.util.vector;
/**
* $Id$
* Writable interface to Vector3fs
* @author $author$
* @version $revision$
*/
public interface WritableVector3f extends WritableVector2f {
/**
* Set the Z value
* @param z
*/
public void setZ(float z);
/**
* Set the X,Y,Z values
* @param x, y, z
*/
public void set(float x, float y, float z);
}

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2003 Shaven Puppy Ltd
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions 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.
*
* * Neither the name of 'Shaven Puppy' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.util.vector;
/**
* $Id$
* Writable interface to Vector4fs
* @author $author$
* @version $revision$
*/
public interface WritableVector4f extends WritableVector3f {
/**
* Set the W value
* @param w
*/
public void setW(float w);
/**
* Set the X,Y,Z,W values
* @param x, y, z, w
*/
public void set(float x, float y, float z, float w);
}