You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(134) |
Sep
(52) |
Oct
(13) |
Nov
(342) |
Dec
(163) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2003 |
Jan
(44) |
Feb
(62) |
Mar
(158) |
Apr
(38) |
May
(70) |
Jun
(58) |
Jul
(104) |
Aug
(207) |
Sep
(83) |
Oct
(122) |
Nov
(23) |
Dec
(49) |
| 2004 |
Jan
(119) |
Feb
(132) |
Mar
(192) |
Apr
(140) |
May
(77) |
Jun
(74) |
Jul
(201) |
Aug
(63) |
Sep
(102) |
Oct
(70) |
Nov
(173) |
Dec
(78) |
| 2005 |
Jan
(174) |
Feb
(197) |
Mar
(105) |
Apr
(59) |
May
(77) |
Jun
(43) |
Jul
(21) |
Aug
(18) |
Sep
(47) |
Oct
(37) |
Nov
(74) |
Dec
(50) |
| 2006 |
Jan
(44) |
Feb
(19) |
Mar
(32) |
Apr
(24) |
May
(31) |
Jun
(55) |
Jul
(138) |
Aug
(28) |
Sep
(12) |
Oct
(41) |
Nov
(58) |
Dec
(24) |
| 2007 |
Jan
(28) |
Feb
(14) |
Mar
(10) |
Apr
(68) |
May
(30) |
Jun
(26) |
Jul
(18) |
Aug
(63) |
Sep
(19) |
Oct
(29) |
Nov
(20) |
Dec
(10) |
| 2008 |
Jan
(38) |
Feb
(7) |
Mar
(37) |
Apr
(120) |
May
(41) |
Jun
(36) |
Jul
(39) |
Aug
(24) |
Sep
(28) |
Oct
(30) |
Nov
(36) |
Dec
(75) |
| 2009 |
Jan
(46) |
Feb
(22) |
Mar
(50) |
Apr
(70) |
May
(134) |
Jun
(105) |
Jul
(75) |
Aug
(34) |
Sep
(38) |
Oct
(34) |
Nov
(19) |
Dec
(20) |
| 2010 |
Jan
(11) |
Feb
(20) |
Mar
(65) |
Apr
(83) |
May
(104) |
Jun
(73) |
Jul
(78) |
Aug
(57) |
Sep
(43) |
Oct
(35) |
Nov
(9) |
Dec
(4) |
| 2011 |
Jan
(21) |
Feb
(11) |
Mar
(18) |
Apr
(10) |
May
(18) |
Jun
(15) |
Jul
(48) |
Aug
(25) |
Sep
(17) |
Oct
(45) |
Nov
(15) |
Dec
(12) |
| 2012 |
Jan
(21) |
Feb
(9) |
Mar
(12) |
Apr
(9) |
May
(9) |
Jun
(5) |
Jul
(1) |
Aug
(10) |
Sep
(12) |
Oct
(1) |
Nov
(28) |
Dec
(5) |
| 2013 |
Jan
(4) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2014 |
Jan
|
Feb
(1) |
Mar
(1) |
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
| 2015 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
| 2016 |
Jan
(2) |
Feb
(1) |
Mar
(1) |
Apr
(1) |
May
(2) |
Jun
|
Jul
(1) |
Aug
(2) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
|
|
|
|
|
1
|
2
|
3
(9) |
|
4
(28) |
5
(1) |
6
(9) |
7
(9) |
8
|
9
(7) |
10
|
|
11
(1) |
12
(18) |
13
(8) |
14
|
15
|
16
(2) |
17
(2) |
|
18
(17) |
19
(5) |
20
(5) |
21
(12) |
22
(1) |
23
|
24
|
|
25
|
26
(1) |
27
|
28
|
29
(3) |
30
(2) |
|
|
From: Caspian Rychlik-P. <ci...@us...> - 2004-04-20 21:03:16
|
Update of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/util/model/loader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22844/src/java/org/lwjgl/util/model/loader Modified Files: Loader.java XMLUtil.java Log Message: Index: Loader.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/util/model/loader/Loader.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Loader.java 20 Apr 2004 20:39:51 -0000 1.3 +++ Loader.java 20 Apr 2004 21:02:40 -0000 1.4 @@ -64,6 +64,12 @@ /** The source document */ private final Document src; + /** Expected number of vertices */ + private int numVertices; + + /** Expected number of bones */ + private int numBones; + /** * C'tor */ @@ -78,13 +84,15 @@ */ public Model load() throws Exception { String material = XMLUtil.getString(src.getDocumentElement(), "material"); + numVertices = XMLUtil.getInt(src.getDocumentElement(), "vertices"); if (XMLUtil.getString(src.getDocumentElement(), "type").equals("boned")) { // It's a boned model + numBones = XMLUtil.getInt(src.getDocumentElement(), "bones", 0); return new BonedModel( material, loadTriangles(), loadSkin(), - loadBoneAnimations(XMLUtil.getInt(src.getDocumentElement(), "bones", 0)), + loadBoneAnimations(), loadBonedVertices() ); } else if (XMLUtil.getString(src.getDocumentElement(), "type").equals("meshed")) { @@ -107,6 +115,9 @@ */ private BonedVertex[] loadBonedVertices() throws Exception { List vertexElements = XMLUtil.getChildren(src.getDocumentElement(), "vertex"); + if (vertexElements.size() != numVertices) { + throw new Exception("Vertex count incorrect, got "+vertexElements.size()+", expected "+numVertices); + } BonedVertex[] vertices = new BonedVertex[vertexElements.size()]; int vertexCount = 0; for (Iterator i = vertexElements.iterator(); i.hasNext(); ) { @@ -123,6 +134,12 @@ */ private Vector2f[] loadSkin() throws Exception { List skinElements = XMLUtil.getChildren(src.getDocumentElement(), "skin"); + if (skinElements.size() == 0) { + return null; + } + if (skinElements.size() != numVertices) { + throw new Exception("Skin count incorrect, got "+skinElements.size()+", expected "+numVertices); + } Vector2f[] skins = new Vector2f[skinElements.size()]; int skinCount = 0; for (Iterator i = skinElements.iterator(); i.hasNext(); ) { @@ -150,16 +167,15 @@ /** * Load all the bone animations - * @param numBones The number of bones in the animations * @return Map of animation names to BoneFrame[] animations * @throws Exception */ - private Map loadBoneAnimations(int numBones) throws Exception { + private Map loadBoneAnimations() throws Exception { List animationElements = XMLUtil.getChildren(src.getDocumentElement(), "animation"); Map animations = new HashMap(animationElements.size()); for (Iterator i = animationElements.iterator(); i.hasNext(); ) { Element animationElement = (Element) i.next(); - animations.put(XMLUtil.getString(animationElement, "name"), loadBonedAnimation(animationElement, numBones)); + animations.put(XMLUtil.getString(animationElement, "name"), loadBonedAnimation(animationElement)); } return animations; } @@ -187,11 +203,16 @@ */ private BonedVertex loadBonedVertex(Element vertexElement) throws Exception { List weightElements = XMLUtil.getChildren(vertexElement, "weight"); - Weight[] weights = new Weight[weightElements.size()]; - int weightCount = 0; - for (Iterator i = weightElements.iterator(); i.hasNext(); ) { - Element weightElement = (Element) i.next(); - weights[weightCount++] = loadWeight(weightElement); + Weight[] weights; + if (weightElements.size() == 0) { + weights = null; + } else { + weights = new Weight[weightElements.size()]; + int weightCount = 0; + for (Iterator i = weightElements.iterator(); i.hasNext(); ) { + Element weightElement = (Element) i.next(); + weights[weightCount++] = loadWeight(weightElement); + } } return new BonedVertex( @@ -200,11 +221,13 @@ XMLUtil.getFloat(vertexElement, "y"), XMLUtil.getFloat(vertexElement, "z") ), - new Vector3f( - XMLUtil.getFloat(vertexElement, "nx"), - XMLUtil.getFloat(vertexElement, "ny"), - XMLUtil.getFloat(vertexElement, "nz") - ), + XMLUtil.hasAttribute(vertexElement, "nx") ? + new Vector3f( + XMLUtil.getFloat(vertexElement, "nx"), + XMLUtil.getFloat(vertexElement, "ny"), + XMLUtil.getFloat(vertexElement, "nz") + ) + : null, weights ); } @@ -222,11 +245,13 @@ XMLUtil.getFloat(vertexElement, "y"), XMLUtil.getFloat(vertexElement, "z") ), - new Vector3f( - XMLUtil.getFloat(vertexElement, "nx"), - XMLUtil.getFloat(vertexElement, "ny"), - XMLUtil.getFloat(vertexElement, "nz") - ) + XMLUtil.hasAttribute(vertexElement, "nx") ? + new Vector3f( + XMLUtil.getFloat(vertexElement, "nx"), + XMLUtil.getFloat(vertexElement, "ny"), + XMLUtil.getFloat(vertexElement, "nz") + ) + : null ); } @@ -237,8 +262,12 @@ * @throws Exception */ private Weight loadWeight(Element element) throws Exception { + int bone = XMLUtil.getInt(element, "bone"); + if (bone < 0 || bone >= numBones) { + throw new Exception("Bone index out of range"); + } return new Weight( - XMLUtil.getInt(element, "bone"), + bone, XMLUtil.getFloat(element, "weight") ); } @@ -246,14 +275,31 @@ /** * Load a Triangle from XML * @param element + * @param numVertices * @return a Triangle * @throws Exception */ private Triangle loadTriangle(Element element) throws Exception { + // Perform sanity checks + int a = XMLUtil.getInt(element, "a"); + if (a < 0 || a >= numVertices) { + throw new Exception("'a' is out of range"); + } + int b = XMLUtil.getInt(element, "b"); + if (b < 0 || b >= numVertices) { + throw new Exception("'b' is out of range"); + } + int c = XMLUtil.getInt(element, "c"); + if (c < 0 || c >= numVertices) { + throw new Exception("'c' is out of range"); + } + if (a == b || a == c || b == c) { + throw new Exception("Degenerate triangle"); + } return new Triangle( - XMLUtil.getInt(element, "a"), - XMLUtil.getInt(element, "b"), - XMLUtil.getInt(element, "c"), + a, + b, + c, XMLUtil.getInt(element, "adjacency", 0) ); } @@ -274,17 +320,16 @@ /** * Load a boned Animation from XML * @param element - * @param numBones * @return BoneFrame[] * @throws Exception */ - private BoneFrame[] loadBonedAnimation(Element element, int numBones) throws Exception { + private BoneFrame[] loadBonedAnimation(Element element) throws Exception { List frameElements = XMLUtil.getChildren(element, "frame"); BoneFrame[] frames = new BoneFrame[frameElements.size()]; int frameCount = 0; for (Iterator i = frameElements.iterator(); i.hasNext(); ) { Element frameElement = (Element) i.next(); - frames[frameCount++] = loadBoneFrame(frameElement, numBones); + frames[frameCount++] = loadBoneFrame(frameElement); } return frames; } @@ -309,11 +354,10 @@ /** * Load a Frame from XML * @param element - * @param numBones * @return BoneFrame * @throws Exception */ - private BoneFrame loadBoneFrame(Element element, int numBones) throws Exception { + private BoneFrame loadBoneFrame(Element element) throws Exception { List boneElements = XMLUtil.getChildren(element, "bone"); if (boneElements.size() != numBones) { throw new Exception("Expected "+numBones+" bones in frame, only got "+boneElements.size()); @@ -339,6 +383,9 @@ private MeshFrame loadMeshFrame(Element element) throws Exception { List vertexElements = XMLUtil.getChildren(element, "vertex"); Vertex[] vertices = new Vertex[vertexElements.size()]; + if (vertices.length != numVertices) { + throw new Exception("Vertex count incorrect"); + } int vertexCount = 0; for (Iterator i = vertexElements.iterator(); i.hasNext(); ) { Element vertexElement = (Element) i.next(); Index: XMLUtil.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/util/model/loader/XMLUtil.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- XMLUtil.java 20 Apr 2004 19:40:54 -0000 1.1 +++ XMLUtil.java 20 Apr 2004 21:02:40 -0000 1.2 @@ -153,6 +153,17 @@ return s; } + /** + * @return true if the specified attribute is present and not empty or null in the element + */ + static boolean hasAttribute(Element element, String attribute) { + String s = element.getAttribute(attribute); + if (s == null || "".equals(s)) + return false; + else + return true; + } + } |
|
From: Caspian Rychlik-P. <ci...@us...> - 2004-04-20 20:41:08
|
Update of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/util/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18455/src/java/org/lwjgl/util/model Modified Files: Frame.java Vertex.java Model.java Added Files: MeshedModel.java MeshFrame.java BoneFrame.java BonedModel.java BonedVertex.java Weight.java Removed Files: Skin.java Log Message: Now does meshed models as well as boned ones Index: Frame.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/util/model/Frame.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Frame.java 19 Apr 2004 21:54:57 -0000 1.3 +++ Frame.java 20 Apr 2004 20:39:50 -0000 1.4 @@ -33,41 +33,31 @@ import java.io.Serializable; -import org.lwjgl.util.vector.Matrix4f; - /** - * A Frame describes a set of new positions for Bones. + * $Id$ + * The base class for animation frames. + * @author $Author$ + * @version $Revision$ */ -public class Frame implements Serializable { +public abstract class Frame implements Serializable { public static final long serialVersionUID = 1L; - /** The new transformations for each Bone in the Skeleton */ - private final Matrix4f[] bone; - /** Frame time */ private final float time; /** * C'tor - * @param bone[] + * @param time */ - public Frame(float time, Matrix4f[] bone) { + public Frame(float time) { this.time = time; - this.bone = bone; - } - - /** - * @return the Bones - */ - public Matrix4f[] getBone() { - return bone; } /** * @return the frame time */ - public float getTime() { + public final float getTime() { return time; } } Index: Model.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/util/model/Model.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Model.java 19 Apr 2004 21:54:57 -0000 1.3 +++ Model.java 20 Apr 2004 20:39:50 -0000 1.4 @@ -35,45 +35,45 @@ import java.io.Serializable; import java.util.Map; +import org.lwjgl.util.vector.Vector2f; + /** * $Id$ * - * A simple animated, skinned, boned 3D model, consisting of a single mesh - * with a single material. The model's internal format is optimised for RAM storage; - * no metadata is held in memory - in other words this is not a good class to use - * for, say, a 3d modelling application. + * Base class for the two kinds of model supported. A Model has a single "material" + * and a single triangular mesh with a single skin, and any number of animations. * * @author $Author$ * @version $Revision$ */ -public class Model implements Serializable { +public abstract class Model implements Serializable { public static final long serialVersionUID = 1L; /** Material */ private final String material; - /** Vertices */ - private final Vertex[] vertex; - /** Triangles */ private final Triangle[] triangle; + /** Skin */ + private final Vector2f[] skin; + /** The animations: a Map of string names to Frame[] arrays */ private final Map animation; /** * C'tor * @param material - * @param vertex * @param triangle + * @param skin[] * @param animation */ - public Model(String material, Vertex[] vertex, Triangle[] triangle, Map animation) { + public Model(String material, Triangle[] triangle, Vector2f[] skin, Map animation) { this.material = material; - this.vertex = vertex; this.triangle = triangle; + this.skin = skin; this.animation = animation; } @@ -82,30 +82,29 @@ * @param name The name of the animation * @return the Frames of an animation (or null, if no such animation exists) */ - public Frame[] getAnimation(String name) { - return (Frame[]) animation.get(name); + public final BoneFrame[] getAnimation(String name) { + return (BoneFrame[]) animation.get(name); } /** * @return Returns the material. */ - public String getMaterial() { + public final String getMaterial() { return material; } /** * @return Returns the triangles. */ - public Triangle[] getTriangle() { + public final Triangle[] getTriangle() { return triangle; } /** - * @return Returns the vertices + * @return Returns the skin. */ - public Vertex[] getVertex() { - return vertex; + public final Vector2f[] getSkin() { + return skin; } - } --- NEW FILE: BoneFrame.java --- /* * 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.model; import org.lwjgl.util.vector.Matrix4f; /** * $Id: BoneFrame.java,v 1.1 2004/04/20 20:39:50 cix_foo Exp $ * A BoneFrame describes a set of new positions for Bones in an animation. * @author $Author: cix_foo $ * @version $Revision: 1.1 $ */ public class BoneFrame extends Frame { public static final long serialVersionUID = 1L; /** The new transformations for each Bone in the Skeleton */ private final Matrix4f[] bone; /** * C'tor * @param time * @param bone[] */ public BoneFrame(float time, Matrix4f[] bone) { super(time); this.bone = bone; } /** * @return the Bones */ public Matrix4f[] getBone() { return bone; } } --- NEW FILE: Weight.java --- /* * 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.model; import java.io.Serializable; /** * $Id: Weight.java,v 1.1 2004/04/20 20:39:50 cix_foo Exp $ * Describes how a bone influences a vertex. * @author $Author: cix_foo $ * @version $Revision: 1.1 $ */ public class Weight implements Serializable { public static final long serialVersionUID = 1L; /** Bone index */ private final int bone; /** Weight */ private final float weight; /** * C'tor */ public Weight(int bone, float weight) { this.bone = bone; this.weight = weight; } /** * @return Returns the bone index. */ public int getBone() { return bone; } /** * @return Returns the weight. */ public float getWeight() { return weight; } } --- NEW FILE: MeshFrame.java --- /* * 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.model; /** * $Id: MeshFrame.java,v 1.1 2004/04/20 20:39:49 cix_foo Exp $ * A MeshFrame describes a set of new positions for Vertices in an animation. * @author $Author: cix_foo $ * @version $Revision: 1.1 $ */ public class MeshFrame extends Frame { public static final long serialVersionUID = 1L; /** The vertices */ private final Vertex[] vertex; /** * C'tor * @param time * @param bone[] */ public MeshFrame(float time, Vertex[] vertex) { super(time); this.vertex = vertex; } /** * @return the Vertices */ public Vertex[] getVertex() { return vertex; } } --- NEW FILE: MeshedModel.java --- /* * Copyright (c) 2002 Light Weight Java Game Library Project * 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 'Light Weight Java Game Library' 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.model; import java.util.Map; import org.lwjgl.util.vector.Vector2f; /** * $Id: MeshedModel.java,v 1.1 2004/04/20 20:39:47 cix_foo Exp $ * * A simple animated 3d mesh, consisting of multiple vertex positions. * with a single material. The model's internal format is optimised for RAM storage; * no metadata is held in memory - in other words this is not a good class to use * for, say, a 3d modelling application. * * @author $Author: cix_foo $ * @version $Revision: 1.1 $ */ public class MeshedModel extends Model { public static final long serialVersionUID = 1L; /** * C'tor * @param material * @param triangle * @param skin[] * @param animation */ public MeshedModel(String material, Triangle[] triangle, Vector2f[] skin, Map animation) { super(material, triangle, skin, animation); } } --- NEW FILE: BonedVertex.java --- /* * 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.model; import org.lwjgl.util.vector.ReadableVector3f; /** * $Id: BonedVertex.java,v 1.1 2004/04/20 20:39:50 cix_foo Exp $ * * A BonedVerex is a Vertex influenced by bone Weights * * @author $Author: cix_foo $ * @version $Revision: 1.1 $ */ public class BonedVertex extends Vertex { public static final long serialVersionUID = 1L; /** Bone weights */ private final Weight[] weight; /** * C'tor * @param coords * @param normal * @param skin */ public BonedVertex(ReadableVector3f coords, ReadableVector3f normal, Weight[] skin) { super(coords, normal); this.weight = skin; } /** * @return Returns the skin. */ public Weight[] getWeight() { return weight; } } Index: Vertex.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/util/model/Vertex.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Vertex.java 19 Apr 2004 21:54:57 -0000 1.3 +++ Vertex.java 20 Apr 2004 20:39:50 -0000 1.4 @@ -33,7 +33,6 @@ import java.io.Serializable; -import org.lwjgl.util.vector.ReadableVector2f; import org.lwjgl.util.vector.ReadableVector3f; /** @@ -54,24 +53,14 @@ /** Normal */ private final ReadableVector3f normal; - /** Texture coordinates */ - private final ReadableVector2f texCoords; - - /** Skin */ - private final Skin[] skin; - /** * C'tor * @param coords * @param normal - * @param texCoords - * @param skin */ - public Vertex(ReadableVector3f coords, ReadableVector3f normal, ReadableVector2f texCoords, Skin[] skin) { + public Vertex(ReadableVector3f coords, ReadableVector3f normal) { this.coords = coords; this.normal = normal; - this.texCoords = texCoords; - this.skin = skin; } /** @@ -87,18 +76,4 @@ public ReadableVector3f getNormal() { return normal; } - - /** - * @return Returns the skin. - */ - public Skin[] getSkin() { - return skin; - } - - /** - * @return Returns the texCoords. - */ - public ReadableVector2f getTexCoords() { - return texCoords; - } } --- NEW FILE: BonedModel.java --- /* * Copyright (c) 2002 Light Weight Java Game Library Project * 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 'Light Weight Java Game Library' 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.model; import java.util.Map; import org.lwjgl.util.vector.Vector2f; /** * $Id: BonedModel.java,v 1.1 2004/04/20 20:39:50 cix_foo Exp $ * * A simple animated, skinned, boned 3D model, consisting of a single mesh * with a single material. The model's internal format is optimised for RAM storage; * no metadata is held in memory - in other words this is not a good class to use * for, say, a 3d modelling application. * * @author $Author: cix_foo $ * @version $Revision: 1.1 $ */ public class BonedModel extends Model { public static final long serialVersionUID = 1L; /** Vertices */ private final BonedVertex[] vertex; /** * C'tor * @param material * @param triangle * @param skin[] * @param animation * @param vertex */ public BonedModel(String material, Triangle[] triangle, Vector2f[] skin, Map animation, BonedVertex[] vertex) { super(material, triangle, skin, animation); this.vertex = vertex; } /** * @return Returns the vertices */ public BonedVertex[] getVertex() { return vertex; } } --- Skin.java DELETED --- |
|
From: Caspian Rychlik-P. <ci...@us...> - 2004-04-20 20:40:37
|
Update of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/util/model/renderer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18455/src/java/org/lwjgl/util/model/renderer Modified Files: Renderer.java Log Message: Now does meshed models as well as boned ones Index: Renderer.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/util/model/renderer/Renderer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Renderer.java 19 Apr 2004 21:54:58 -0000 1.3 +++ Renderer.java 20 Apr 2004 20:39:52 -0000 1.4 @@ -34,8 +34,8 @@ import java.util.HashMap; import java.util.Map; -import org.lwjgl.util.model.Frame; -import org.lwjgl.util.model.Model; +import org.lwjgl.util.model.BoneFrame; +import org.lwjgl.util.model.BonedModel; /** * $Id$ @@ -67,7 +67,7 @@ * @param animation The name of the animation * @param time The time for the animation */ - public void render(Model model, String animation, float time) { + public void render(BonedModel model, String animation, float time) { // 1. Set up GL state from the Model's material Renderable material = (Renderable) materials.get(model.getMaterial()); @@ -76,7 +76,7 @@ } // 2. Get the animation - Frame[] frame = model.getAnimation(animation); + BoneFrame[] frame = model.getAnimation(animation); if (frame == null) { return; } |
|
From: Caspian Rychlik-P. <ci...@us...> - 2004-04-20 20:40:36
|
Update of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/util/model/loader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18455/src/java/org/lwjgl/util/model/loader Modified Files: Loader.java Log Message: Now does meshed models as well as boned ones Index: Loader.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/util/model/loader/Loader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Loader.java 20 Apr 2004 19:40:54 -0000 1.2 +++ Loader.java 20 Apr 2004 20:39:51 -0000 1.3 @@ -36,11 +36,14 @@ import java.util.List; import java.util.Map; -import org.lwjgl.util.model.Frame; -import org.lwjgl.util.model.Model; -import org.lwjgl.util.model.Skin; +import org.lwjgl.util.model.*; +import org.lwjgl.util.model.BoneFrame; +import org.lwjgl.util.model.BonedModel; +import org.lwjgl.util.model.BonedVertex; +import org.lwjgl.util.model.MeshedModel; import org.lwjgl.util.model.Triangle; import org.lwjgl.util.model.Vertex; +import org.lwjgl.util.model.Weight; import org.lwjgl.util.vector.Matrix4f; import org.lwjgl.util.vector.Vector2f; import org.lwjgl.util.vector.Vector3f; @@ -74,31 +77,62 @@ * @throws Exception */ public Model load() throws Exception { - return new Model( - XMLUtil.getString(src.getDocumentElement(), "material"), - loadVertices(), - loadTriangles(), - loadAnimations(XMLUtil.getInt(src.getDocumentElement(), "bones")) - ); + String material = XMLUtil.getString(src.getDocumentElement(), "material"); + if (XMLUtil.getString(src.getDocumentElement(), "type").equals("boned")) { + // It's a boned model + return new BonedModel( + material, + loadTriangles(), + loadSkin(), + loadBoneAnimations(XMLUtil.getInt(src.getDocumentElement(), "bones", 0)), + loadBonedVertices() + ); + } else if (XMLUtil.getString(src.getDocumentElement(), "type").equals("meshed")) { + // It's a mesh keyframe model + return new MeshedModel( + material, + loadTriangles(), + loadSkin(), + loadMeshAnimations() + ); + } else { + throw new Exception("Unsupported model type."); + } } /** - * Load all the Vertices + * Load all the BonedVertices * @return Vertex[] * @throws Exception */ - private Vertex[] loadVertices() throws Exception { + private BonedVertex[] loadBonedVertices() throws Exception { List vertexElements = XMLUtil.getChildren(src.getDocumentElement(), "vertex"); - Vertex[] vertices = new Vertex[vertexElements.size()]; + BonedVertex[] vertices = new BonedVertex[vertexElements.size()]; int vertexCount = 0; for (Iterator i = vertexElements.iterator(); i.hasNext(); ) { Element vertexElement = (Element) i.next(); - vertices[vertexCount++] = loadVertex(vertexElement); + vertices[vertexCount++] = loadBonedVertex(vertexElement); } return vertices; } /** + * Load the skin + * @return Vector2f[] + * @throws Exception + */ + private Vector2f[] loadSkin() throws Exception { + List skinElements = XMLUtil.getChildren(src.getDocumentElement(), "skin"); + Vector2f[] skins = new Vector2f[skinElements.size()]; + int skinCount = 0; + for (Iterator i = skinElements.iterator(); i.hasNext(); ) { + Element skinElement = (Element) i.next(); + skins[skinCount++] = loadTexCoord(skinElement); + } + return skins; + } + + /** * Load all the Triangles * @return Triangle[] * @throws Exception @@ -115,17 +149,32 @@ } /** - * Load all the animations + * Load all the bone animations * @param numBones The number of bones in the animations - * @return Map of animation names to Frame[] animations + * @return Map of animation names to BoneFrame[] animations * @throws Exception */ - private Map loadAnimations(int numBones) throws Exception { + private Map loadBoneAnimations(int numBones) throws Exception { List animationElements = XMLUtil.getChildren(src.getDocumentElement(), "animation"); Map animations = new HashMap(animationElements.size()); for (Iterator i = animationElements.iterator(); i.hasNext(); ) { Element animationElement = (Element) i.next(); - animations.put(XMLUtil.getString(animationElement, "name"), loadAnimation(animationElement, numBones)); + animations.put(XMLUtil.getString(animationElement, "name"), loadBonedAnimation(animationElement, numBones)); + } + return animations; + } + + /** + * Load all the mesh keyframe animations + * @return Map of animation names to MeshFrame[] animations + * @throws Exception + */ + private Map loadMeshAnimations() throws Exception { + List animationElements = XMLUtil.getChildren(src.getDocumentElement(), "animation"); + Map animations = new HashMap(animationElements.size()); + for (Iterator i = animationElements.iterator(); i.hasNext(); ) { + Element animationElement = (Element) i.next(); + animations.put(XMLUtil.getString(animationElement, "name"), loadMeshAnimation(animationElement)); } return animations; } @@ -136,16 +185,16 @@ * @return a Vertex * @throws Exception */ - private Vertex loadVertex(Element vertexElement) throws Exception { - List skinElements = XMLUtil.getChildren(vertexElement, "skin"); - Skin[] skins = new Skin[skinElements.size()]; - int skinCount = 0; - for (Iterator i = skinElements.iterator(); i.hasNext(); ) { - Element skinElement = (Element) i.next(); - skins[skinCount++] = loadSkin(skinElement); + private BonedVertex loadBonedVertex(Element vertexElement) throws Exception { + List weightElements = XMLUtil.getChildren(vertexElement, "weight"); + Weight[] weights = new Weight[weightElements.size()]; + int weightCount = 0; + for (Iterator i = weightElements.iterator(); i.hasNext(); ) { + Element weightElement = (Element) i.next(); + weights[weightCount++] = loadWeight(weightElement); } - return new Vertex( + return new BonedVertex( new Vector3f( XMLUtil.getFloat(vertexElement, "x"), XMLUtil.getFloat(vertexElement, "y"), @@ -156,22 +205,39 @@ XMLUtil.getFloat(vertexElement, "ny"), XMLUtil.getFloat(vertexElement, "nz") ), - new Vector2f( - XMLUtil.getFloat(vertexElement, "u"), - XMLUtil.getFloat(vertexElement, "v") - ), - skins + weights ); } /** - * Load a Skin from XML + * Load a Vertex from XML + * @param vertexElement + * @return a Vertex + * @throws Exception + */ + private Vertex loadMeshVertex(Element vertexElement) throws Exception { + return new Vertex( + new Vector3f( + XMLUtil.getFloat(vertexElement, "x"), + XMLUtil.getFloat(vertexElement, "y"), + XMLUtil.getFloat(vertexElement, "z") + ), + new Vector3f( + XMLUtil.getFloat(vertexElement, "nx"), + XMLUtil.getFloat(vertexElement, "ny"), + XMLUtil.getFloat(vertexElement, "nz") + ) + ); + } + + /** + * Load a Weight from XML * @param element * @return a Skin * @throws Exception */ - private Skin loadSkin(Element element) throws Exception { - return new Skin( + private Weight loadWeight(Element element) throws Exception { + return new Weight( XMLUtil.getInt(element, "bone"), XMLUtil.getFloat(element, "weight") ); @@ -193,19 +259,49 @@ } /** - * Load an Animation from XML + * Load a texture coordinate from XML + * @param element + * @return a Vector2f + * @throws Exception + */ + private Vector2f loadTexCoord(Element element) throws Exception { + return new Vector2f( + XMLUtil.getFloat(element, "u"), + XMLUtil.getFloat(element, "v") + ); + } + + /** + * Load a boned Animation from XML * @param element * @param numBones - * @return Frame[] + * @return BoneFrame[] * @throws Exception */ - private Frame[] loadAnimation(Element element, int numBones) throws Exception { + private BoneFrame[] loadBonedAnimation(Element element, int numBones) throws Exception { List frameElements = XMLUtil.getChildren(element, "frame"); - Frame[] frames = new Frame[frameElements.size()]; + BoneFrame[] frames = new BoneFrame[frameElements.size()]; int frameCount = 0; for (Iterator i = frameElements.iterator(); i.hasNext(); ) { Element frameElement = (Element) i.next(); - frames[frameCount++] = loadFrame(frameElement, numBones); + frames[frameCount++] = loadBoneFrame(frameElement, numBones); + } + return frames; + } + + /** + * Load a mesh Animation from XML + * @param element + * @return MeshFrame[] + * @throws Exception + */ + private MeshFrame[] loadMeshAnimation(Element element) throws Exception { + List frameElements = XMLUtil.getChildren(element, "frame"); + MeshFrame[] frames = new MeshFrame[frameElements.size()]; + int frameCount = 0; + for (Iterator i = frameElements.iterator(); i.hasNext(); ) { + Element frameElement = (Element) i.next(); + frames[frameCount++] = loadMeshFrame(frameElement); } return frames; } @@ -214,10 +310,10 @@ * Load a Frame from XML * @param element * @param numBones - * @return Frame + * @return BoneFrame * @throws Exception */ - private Frame loadFrame(Element element, int numBones) throws Exception { + private BoneFrame loadBoneFrame(Element element, int numBones) throws Exception { List boneElements = XMLUtil.getChildren(element, "bone"); if (boneElements.size() != numBones) { throw new Exception("Expected "+numBones+" bones in frame, only got "+boneElements.size()); @@ -228,13 +324,33 @@ Element boneElement = (Element) i.next(); bones[boneCount++] = loadBone(boneElement); } - return new Frame( + return new BoneFrame( XMLUtil.getFloat(element, "time", 0.0f), bones ); } /** + * Load a Frame from XML + * @param element + * @return MeshFrame + * @throws Exception + */ + private MeshFrame loadMeshFrame(Element element) throws Exception { + List vertexElements = XMLUtil.getChildren(element, "vertex"); + Vertex[] vertices = new Vertex[vertexElements.size()]; + int vertexCount = 0; + for (Iterator i = vertexElements.iterator(); i.hasNext(); ) { + Element vertexElement = (Element) i.next(); + vertices[vertexCount++] = loadMeshVertex(vertexElement); + } + return new MeshFrame( + XMLUtil.getFloat(element, "time", 0.0f), + vertices + ); + } + + /** * Load a Bone from XML * @param element * @return a Matrix4f |
|
From: Caspian Rychlik-P. <ci...@us...> - 2004-04-20 19:41:34
|
Update of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/util/model/loader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6212/src/java/org/lwjgl/util/model/loader Modified Files: Loader.java Added Files: XMLUtil.java Log Message: XML Loader's done Index: Loader.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/util/model/loader/Loader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Loader.java 18 Apr 2004 19:30:32 -0000 1.1 +++ Loader.java 20 Apr 2004 19:40:54 -0000 1.2 @@ -31,13 +31,27 @@ */ package org.lwjgl.util.model.loader; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.lwjgl.util.model.Frame; import org.lwjgl.util.model.Model; +import org.lwjgl.util.model.Skin; +import org.lwjgl.util.model.Triangle; +import org.lwjgl.util.model.Vertex; +import org.lwjgl.util.vector.Matrix4f; +import org.lwjgl.util.vector.Vector2f; +import org.lwjgl.util.vector.Vector3f; import org.w3c.dom.Document; +import org.w3c.dom.Element; /** * $Id$ * - * Loads a Model from an XML document. + * Loads a Model from an XML document. Construct with an XML Document as the argument, + * and then retrieve the Model by calling load(). * * @author $Author$ * @version $Revision$ @@ -60,6 +74,191 @@ * @throws Exception */ public Model load() throws Exception { + return new Model( + XMLUtil.getString(src.getDocumentElement(), "material"), + loadVertices(), + loadTriangles(), + loadAnimations(XMLUtil.getInt(src.getDocumentElement(), "bones")) + ); } + /** + * Load all the Vertices + * @return Vertex[] + * @throws Exception + */ + private Vertex[] loadVertices() throws Exception { + List vertexElements = XMLUtil.getChildren(src.getDocumentElement(), "vertex"); + Vertex[] vertices = new Vertex[vertexElements.size()]; + int vertexCount = 0; + for (Iterator i = vertexElements.iterator(); i.hasNext(); ) { + Element vertexElement = (Element) i.next(); + vertices[vertexCount++] = loadVertex(vertexElement); + } + return vertices; + } + + /** + * Load all the Triangles + * @return Triangle[] + * @throws Exception + */ + private Triangle[] loadTriangles() throws Exception { + List triangleElements = XMLUtil.getChildren(src.getDocumentElement(), "triangle"); + Triangle[] triangles = new Triangle[triangleElements.size()]; + int triangleCount = 0; + for (Iterator i = triangleElements.iterator(); i.hasNext(); ) { + Element triangleElement = (Element) i.next(); + triangles[triangleCount++] = loadTriangle(triangleElement); + } + return triangles; + } + + /** + * Load all the animations + * @param numBones The number of bones in the animations + * @return Map of animation names to Frame[] animations + * @throws Exception + */ + private Map loadAnimations(int numBones) throws Exception { + List animationElements = XMLUtil.getChildren(src.getDocumentElement(), "animation"); + Map animations = new HashMap(animationElements.size()); + for (Iterator i = animationElements.iterator(); i.hasNext(); ) { + Element animationElement = (Element) i.next(); + animations.put(XMLUtil.getString(animationElement, "name"), loadAnimation(animationElement, numBones)); + } + return animations; + } + + /** + * Load a Vertex from XML + * @param vertexElement + * @return a Vertex + * @throws Exception + */ + private Vertex loadVertex(Element vertexElement) throws Exception { + List skinElements = XMLUtil.getChildren(vertexElement, "skin"); + Skin[] skins = new Skin[skinElements.size()]; + int skinCount = 0; + for (Iterator i = skinElements.iterator(); i.hasNext(); ) { + Element skinElement = (Element) i.next(); + skins[skinCount++] = loadSkin(skinElement); + } + + return new Vertex( + new Vector3f( + XMLUtil.getFloat(vertexElement, "x"), + XMLUtil.getFloat(vertexElement, "y"), + XMLUtil.getFloat(vertexElement, "z") + ), + new Vector3f( + XMLUtil.getFloat(vertexElement, "nx"), + XMLUtil.getFloat(vertexElement, "ny"), + XMLUtil.getFloat(vertexElement, "nz") + ), + new Vector2f( + XMLUtil.getFloat(vertexElement, "u"), + XMLUtil.getFloat(vertexElement, "v") + ), + skins + ); + } + + /** + * Load a Skin from XML + * @param element + * @return a Skin + * @throws Exception + */ + private Skin loadSkin(Element element) throws Exception { + return new Skin( + XMLUtil.getInt(element, "bone"), + XMLUtil.getFloat(element, "weight") + ); + } + + /** + * Load a Triangle from XML + * @param element + * @return a Triangle + * @throws Exception + */ + private Triangle loadTriangle(Element element) throws Exception { + return new Triangle( + XMLUtil.getInt(element, "a"), + XMLUtil.getInt(element, "b"), + XMLUtil.getInt(element, "c"), + XMLUtil.getInt(element, "adjacency", 0) + ); + } + + /** + * Load an Animation from XML + * @param element + * @param numBones + * @return Frame[] + * @throws Exception + */ + private Frame[] loadAnimation(Element element, int numBones) throws Exception { + List frameElements = XMLUtil.getChildren(element, "frame"); + Frame[] frames = new Frame[frameElements.size()]; + int frameCount = 0; + for (Iterator i = frameElements.iterator(); i.hasNext(); ) { + Element frameElement = (Element) i.next(); + frames[frameCount++] = loadFrame(frameElement, numBones); + } + return frames; + } + + /** + * Load a Frame from XML + * @param element + * @param numBones + * @return Frame + * @throws Exception + */ + private Frame loadFrame(Element element, int numBones) throws Exception { + List boneElements = XMLUtil.getChildren(element, "bone"); + if (boneElements.size() != numBones) { + throw new Exception("Expected "+numBones+" bones in frame, only got "+boneElements.size()); + } + Matrix4f[] bones = new Matrix4f[boneElements.size()]; + int boneCount = 0; + for (Iterator i = boneElements.iterator(); i.hasNext(); ) { + Element boneElement = (Element) i.next(); + bones[boneCount++] = loadBone(boneElement); + } + return new Frame( + XMLUtil.getFloat(element, "time", 0.0f), + bones + ); + } + + /** + * Load a Bone from XML + * @param element + * @return a Matrix4f + * @throws Exception + */ + private Matrix4f loadBone(Element element) throws Exception { + Matrix4f ret = new Matrix4f(); + ret.m00 = XMLUtil.getFloat(element, "m00"); + ret.m01 = XMLUtil.getFloat(element, "m01"); + ret.m02 = XMLUtil.getFloat(element, "m02"); + ret.m03 = XMLUtil.getFloat(element, "m03"); + ret.m10 = XMLUtil.getFloat(element, "m10"); + ret.m11 = XMLUtil.getFloat(element, "m11"); + ret.m12 = XMLUtil.getFloat(element, "m12"); + ret.m13 = XMLUtil.getFloat(element, "m13"); + ret.m20 = XMLUtil.getFloat(element, "m20"); + ret.m21 = XMLUtil.getFloat(element, "m21"); + ret.m22 = XMLUtil.getFloat(element, "m22"); + ret.m23 = XMLUtil.getFloat(element, "m23"); + ret.m30 = XMLUtil.getFloat(element, "m30", 0.0f); + ret.m31 = XMLUtil.getFloat(element, "m31", 0.0f); + ret.m32 = XMLUtil.getFloat(element, "m32", 0.0f); + ret.m33 = XMLUtil.getFloat(element, "m33", 1.0f); + return ret; + } + } --- NEW FILE: XMLUtil.java --- /* * 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.model.loader; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** * Some simple XML utilities * @author cas */ final class XMLUtil { /** * @param name The name of the child elements you want * @return a List of child Elements */ static List getChildren(Element element, String name) throws Exception { NodeList nodes = element.getChildNodes(); ArrayList ret = new ArrayList(nodes.getLength()); for (int i = 0; i < nodes.getLength(); i ++) { Node childNode = (Node) nodes.item(i); if (childNode.getNodeName().equals(name) && childNode.getNodeType() == Node.ELEMENT_NODE) { ret.add(childNode); } } return ret; } /** * A convenience method for getting float values out of XML elements * @param attribute The name of the attribute * @throws NumberFormatException If the supplied attribute is not a number * @throws Exception if the value is missing * @return the parsed float value */ static float getFloat(Element element, String attribute) throws Exception { String s = element.getAttribute(attribute); if (s == null || "".equals(s)) throw new Exception("Attribute '"+attribute+"' has not been specified for "+element.getNodeName()); else return Float.parseFloat(s); } /** * A convenience method for getting float values out of XML elements * @param attribute The name of the attribute * @param defaultValue The default value to return if no default is specified * @throws NumberFormatException If the supplied attribute is not a number * @return the parsed float value */ static float getFloat(Element element, String attribute, float defaultValue) throws Exception { String s = element.getAttribute(attribute); if (s == null || "".equals(s)) return defaultValue; else return Float.parseFloat(s); } /** * A convenience method for getting integer values out of XML elements * @param attribute The name of the attribute * @throws NumberFormatException If the supplied attribute is not a number * @throws Exception if the value is missing * @return the parsed integer value */ static int getInt(Element element, String attribute) throws Exception { String s = element.getAttribute(attribute); if (s == null || "".equals(s)) throw new Exception("Attribute '"+attribute+"' has not been specified for "+element.getNodeName()); else return Integer.parseInt(s); } /** * A convenience method for getting integer values out of XML elements * @param attribute The name of the attribute * @param defaultValue The default value to return if no default is specified * @throws NumberFormatException If the supplied attribute is not a number * @return the parsed integer value */ static int getInt(Element element, String attribute, int defaultValue) throws Exception { String s = element.getAttribute(attribute); if (s == null || "".equals(s)) return defaultValue; else return Integer.parseInt(s); } /** * A convenience method for getting string values out of XML elements * @param attribute The name of the attribute * @return the string value, which will not be null * @throws Exception the value is not specified */ static String getString(Element element, String attribute) throws Exception { String s = element.getAttribute(attribute); if (s == null || "".equals(s)) throw new Exception("Attribute '"+attribute+"' has not been specified for "+element.getNodeName()); else return s; } /** * A convenience method for getting string values out of XML elements * @param attribute The name of the attribute * @param defaultValue The default value to return if no default is specified * @return the string value, which will not be null */ static String getString(Element element, String attribute, String defaultValue) throws Exception { String s = element.getAttribute(attribute); if (s == null || "".equals(s)) return defaultValue; else return s; } } |