Added wrapper tags
This commit is contained in:
parent
e123997fc2
commit
00f82d6353
|
@ -39,13 +39,6 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.lwjgl.util.Color;
|
import org.lwjgl.util.Color;
|
||||||
import org.lwjgl.util.model.*;
|
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.Matrix4f;
|
||||||
import org.lwjgl.util.vector.Vector2f;
|
import org.lwjgl.util.vector.Vector2f;
|
||||||
import org.lwjgl.util.vector.Vector3f;
|
import org.lwjgl.util.vector.Vector3f;
|
||||||
|
@ -121,7 +114,11 @@ public class XMLLoader {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private BonedVertex[] loadBonedVertices() throws Exception {
|
private BonedVertex[] loadBonedVertices() throws Exception {
|
||||||
List vertexElements = XMLUtil.getChildren(src.getDocumentElement(), "vertex");
|
Element verticesElement = XMLUtil.getChild(src.getDocumentElement(), "vertices");
|
||||||
|
if (verticesElement == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List vertexElements = XMLUtil.getChildren(verticesElement, "vertex");
|
||||||
if (vertexElements.size() != numVertices) {
|
if (vertexElements.size() != numVertices) {
|
||||||
throw new Exception("Vertex count incorrect, got "+vertexElements.size()+", expected "+numVertices);
|
throw new Exception("Vertex count incorrect, got "+vertexElements.size()+", expected "+numVertices);
|
||||||
}
|
}
|
||||||
|
@ -140,7 +137,11 @@ public class XMLLoader {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private Vector2f[] loadSkin() throws Exception {
|
private Vector2f[] loadSkin() throws Exception {
|
||||||
List skinElements = XMLUtil.getChildren(src.getDocumentElement(), "skin");
|
Element skinElement = XMLUtil.getChild(src.getDocumentElement(), "skin");
|
||||||
|
if (skinElement == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List skinElements = XMLUtil.getChildren(skinElement, "texcoord");
|
||||||
if (skinElements.size() == 0) {
|
if (skinElements.size() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -150,8 +151,8 @@ public class XMLLoader {
|
||||||
Vector2f[] skins = new Vector2f[skinElements.size()];
|
Vector2f[] skins = new Vector2f[skinElements.size()];
|
||||||
int skinCount = 0;
|
int skinCount = 0;
|
||||||
for (Iterator i = skinElements.iterator(); i.hasNext(); ) {
|
for (Iterator i = skinElements.iterator(); i.hasNext(); ) {
|
||||||
Element skinElement = (Element) i.next();
|
Element texCoordElement = (Element) i.next();
|
||||||
skins[skinCount++] = loadTexCoord(skinElement);
|
skins[skinCount++] = loadTexCoord(texCoordElement);
|
||||||
}
|
}
|
||||||
return skins;
|
return skins;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +163,12 @@ public class XMLLoader {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private Color[] loadColor() throws Exception {
|
private Color[] loadColor() throws Exception {
|
||||||
List colorElements = XMLUtil.getChildren(src.getDocumentElement(), "color");
|
Element colorsElement = XMLUtil.getChild(src.getDocumentElement(), "colors");
|
||||||
|
if (colorsElement == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
List colorElements = XMLUtil.getChildren(colorsElement, "color");
|
||||||
if (colorElements.size() == 0) {
|
if (colorElements.size() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -184,7 +190,11 @@ public class XMLLoader {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private Triangle[] loadTriangles() throws Exception {
|
private Triangle[] loadTriangles() throws Exception {
|
||||||
List triangleElements = XMLUtil.getChildren(src.getDocumentElement(), "triangle");
|
Element meshElement = XMLUtil.getChild(src.getDocumentElement(), "mesh");
|
||||||
|
if (meshElement == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List triangleElements = XMLUtil.getChildren(meshElement, "triangle");
|
||||||
Triangle[] triangles = new Triangle[triangleElements.size()];
|
Triangle[] triangles = new Triangle[triangleElements.size()];
|
||||||
int triangleCount = 0;
|
int triangleCount = 0;
|
||||||
for (Iterator i = triangleElements.iterator(); i.hasNext(); ) {
|
for (Iterator i = triangleElements.iterator(); i.hasNext(); ) {
|
||||||
|
@ -200,11 +210,15 @@ public class XMLLoader {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private Map loadBoneAnimations() throws Exception {
|
private Map loadBoneAnimations() throws Exception {
|
||||||
List animationElements = XMLUtil.getChildren(src.getDocumentElement(), "animation");
|
Element animationElement = XMLUtil.getChild(src.getDocumentElement(), "animation");
|
||||||
Map animations = new HashMap(animationElements.size());
|
if (animationElement == null) {
|
||||||
for (Iterator i = animationElements.iterator(); i.hasNext(); ) {
|
return null;
|
||||||
Element animationElement = (Element) i.next();
|
}
|
||||||
animations.put(XMLUtil.getString(animationElement, "name"), loadBonedAnimation(animationElement));
|
List sequenceElements = XMLUtil.getChildren(src.getDocumentElement(), "sequence");
|
||||||
|
Map animations = new HashMap(sequenceElements.size());
|
||||||
|
for (Iterator i = sequenceElements.iterator(); i.hasNext(); ) {
|
||||||
|
Element sequenceElement = (Element) i.next();
|
||||||
|
animations.put(XMLUtil.getString(sequenceElement, "name"), loadBonedAnimation(sequenceElement));
|
||||||
}
|
}
|
||||||
return animations;
|
return animations;
|
||||||
}
|
}
|
||||||
|
@ -215,11 +229,15 @@ public class XMLLoader {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private Map loadMeshAnimations() throws Exception {
|
private Map loadMeshAnimations() throws Exception {
|
||||||
List animationElements = XMLUtil.getChildren(src.getDocumentElement(), "animation");
|
Element animationElement = XMLUtil.getChild(src.getDocumentElement(), "animation");
|
||||||
Map animations = new HashMap(animationElements.size());
|
if (animationElement == null) {
|
||||||
for (Iterator i = animationElements.iterator(); i.hasNext(); ) {
|
return null;
|
||||||
Element animationElement = (Element) i.next();
|
}
|
||||||
animations.put(XMLUtil.getString(animationElement, "name"), loadMeshAnimation(animationElement));
|
List sequenceElements = XMLUtil.getChildren(src.getDocumentElement(), "sequence");
|
||||||
|
Map animations = new HashMap(sequenceElements.size());
|
||||||
|
for (Iterator i = sequenceElements.iterator(); i.hasNext(); ) {
|
||||||
|
Element sequenceElement = (Element) i.next();
|
||||||
|
animations.put(XMLUtil.getString(sequenceElement, "name"), loadMeshAnimation(sequenceElement));
|
||||||
}
|
}
|
||||||
return animations;
|
return animations;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,28 @@ import org.w3c.dom.NodeList;
|
||||||
*/
|
*/
|
||||||
final class XMLUtil {
|
final class XMLUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a single child element
|
||||||
|
* @param child
|
||||||
|
* @return the single child element, or null
|
||||||
|
* @throws Exception if the child is present multiple times
|
||||||
|
*/
|
||||||
|
public static Element getChild(Element element, String child) throws Exception {
|
||||||
|
NodeList nodes = element.getChildNodes();
|
||||||
|
Element ret = null;
|
||||||
|
for (int i = 0; i < nodes.getLength(); i ++) {
|
||||||
|
Node childNode = (Node) nodes.item(i);
|
||||||
|
if (childNode.getNodeName().equals(child) && childNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
|
if (ret != null) {
|
||||||
|
throw new Exception("Child element '"+child+"' present multiple times");
|
||||||
|
} else {
|
||||||
|
ret = (Element) childNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name The name of the child elements you want
|
* @param name The name of the child elements you want
|
||||||
* @return a List of child Elements
|
* @return a List of child Elements
|
||||||
|
|
Loading…
Reference in New Issue