1 /* 2 * Copyright (c) 2009-2010 jMonkeyEngine 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 package com.jme3.scene.plugins.ogre; 34 35 //import static com.jmex.model.XMLUtil.getAttribute; 36 //import static com.jmex.model.XMLUtil.getIntAttribute; 37 // 38 //import java.util.ArrayList; 39 //import java.util.List; 40 //import java.util.Map; 41 // 42 //import org.w3c.dom.Node; 43 // 44 //import com.jme.math.Vector3f; 45 //import com.jmex.model.XMLUtil; 46 //import com.jmex.model.ogrexml.anim.PoseTrack.PoseFrame; 47 48 /** 49 * Utility class used by OgreLoader to load poses and mesh animations. 50 */ 51 public class MeshAnimationLoader { 52 53 // public static void loadMeshAnimations(Node animationsNode, List<Pose> poseList, OgreMesh sharedgeom, List<OgreMesh> submeshes, Map<String, Animation> animations){ 54 // Node animationNode = animationsNode.getFirstChild(); 55 // while (animationNode != null){ 56 // if (animationNode.getNodeName().equals("animation")){ 57 // MeshAnimation mAnim = 58 // loadMeshAnimation(animationNode, poseList, sharedgeom, submeshes); 59 // 60 // Animation anim = animations.get(mAnim.getName()); 61 // if (anim != null){ 62 // anim.setMeshAnimation(mAnim); 63 // }else{ 64 // anim = new Animation(null, mAnim); 65 // animations.put(anim.getName(), anim); 66 // } 67 // } 68 // animationNode = animationNode.getNextSibling(); 69 // } 70 // 71 //// Map<TriMesh, List<Pose>> trimeshPoses = new HashMap<TriMesh, List<Pose>>(); 72 //// 73 //// // find the poses for each mesh 74 //// for (Pose p : poses){ 75 //// List<Pose> poseList = trimeshPoses.get(p.getTarget()); 76 //// if (poseList == null){ 77 //// poseList = new ArrayList<Pose>(); 78 //// trimeshPoses.put(p.getTarget(), poseList); 79 //// } 80 //// 81 //// poseList.add(p); 82 //// } 83 //// 84 //// for (Map.Entry<TriMesh, List<Pose>> poseEntry: trimeshPoses){ 85 //// PoseController 86 //// } 87 // } 88 // 89 // public static MeshAnimation loadMeshAnimation(Node animationNode, List<Pose> poseList, OgreMesh sharedgeom, List<OgreMesh> submeshes){ 90 // String name = XMLUtil.getAttribute(animationNode, "name"); 91 // float length = XMLUtil.getFloatAttribute(animationNode, "length"); 92 // 93 // MeshAnimation anim = new MeshAnimation(name, length); 94 // List<Track> tracks = new ArrayList<Track>(); 95 // 96 // Node tracksNode = XMLUtil.getChildNode(animationNode, "tracks"); 97 // if (tracksNode != null){ 98 // Node trackNode = tracksNode.getFirstChild(); 99 // while (trackNode != null){ 100 // if (trackNode.getNodeName().equals("track")){ 101 // int targetMeshIndex; 102 // if (XMLUtil.getAttribute(trackNode, "target").equals("mesh")){ 103 // targetMeshIndex = -1; 104 // }else{ 105 // if (XMLUtil.getAttribute(trackNode, "index") == null) 106 // targetMeshIndex = 0; 107 // else 108 // targetMeshIndex = getIntAttribute(trackNode, "index"); 109 // } 110 // 111 // if (XMLUtil.getAttribute(trackNode, "type").equals("pose")){ 112 // PoseTrack pt = loadPoseTrack(trackNode, targetMeshIndex, poseList); 113 // tracks.add(pt); 114 // }else{ 115 // throw new UnsupportedOperationException("Morph animations not supported!"); 116 // } 117 // } 118 // 119 // trackNode = trackNode.getNextSibling(); 120 // } 121 // } 122 // 123 // anim.setTracks(tracks.toArray(new Track[0])); 124 // 125 // return anim; 126 // } 127 // 128 // public static List<Pose> loadPoses(Node posesNode, OgreMesh sharedgeom, List<OgreMesh> submeshes){ 129 // List<Pose> poses = new ArrayList<Pose>(); 130 // Node poseNode = posesNode.getFirstChild(); 131 // while (poseNode != null){ 132 // if (poseNode.getNodeName().equals("pose")){ 133 // int targetMeshIndex = 0; 134 // if (getAttribute(poseNode, "target").equals("mesh")){ 135 // targetMeshIndex = -1; 136 // }else{ 137 // if (getAttribute(poseNode, "index") == null) 138 // targetMeshIndex = 0; 139 // else 140 // targetMeshIndex = getIntAttribute(poseNode, "index"); 141 // } 142 // 143 // Pose p = MeshAnimationLoader.loadPose(poseNode, targetMeshIndex); 144 // poses.add(p); 145 // } 146 // 147 // poseNode = poseNode.getNextSibling(); 148 // } 149 // 150 // return poses; 151 // } 152 // 153 // public static Pose loadPose(Node poseNode, int targetMeshIndex){ 154 // String name = XMLUtil.getAttribute(poseNode, "name"); 155 // 156 // List<Vector3f> offsets = new ArrayList<Vector3f>(); 157 // List<Integer> indices = new ArrayList<Integer>(); 158 // 159 // Node poseoffsetNode = poseNode.getFirstChild(); 160 // while (poseoffsetNode != null){ 161 // if (poseoffsetNode.getNodeName().equals("poseoffset")){ 162 // int vertIndex = XMLUtil.getIntAttribute(poseoffsetNode, "index"); 163 // Vector3f offset = new Vector3f(); 164 // offset.x = XMLUtil.getFloatAttribute(poseoffsetNode, "x"); 165 // offset.y = XMLUtil.getFloatAttribute(poseoffsetNode, "y"); 166 // offset.z = XMLUtil.getFloatAttribute(poseoffsetNode, "z"); 167 // 168 // offsets.add(offset); 169 // indices.add(vertIndex); 170 // } 171 // 172 // poseoffsetNode = poseoffsetNode.getNextSibling(); 173 // } 174 // 175 // int[] indicesArray = new int[indices.size()]; 176 // for (int i = 0; i < indicesArray.length; i++){ 177 // indicesArray[i] = indices.get(i); 178 // } 179 // 180 // Pose pose = new Pose(name, 181 // targetMeshIndex, 182 // offsets.toArray(new Vector3f[0]), 183 // indicesArray); 184 // 185 // return pose; 186 // } 187 // 188 // public static PoseTrack loadPoseTrack(Node trackNode, int targetMeshIndex, List<Pose> posesList){ 189 // List<Float> times = new ArrayList<Float>(); 190 // List<PoseFrame> frames = new ArrayList<PoseFrame>(); 191 // 192 // Node keyframesNode = XMLUtil.getChildNode(trackNode, "keyframes"); 193 // Node keyframeNode = keyframesNode.getFirstChild(); 194 // while (keyframeNode != null){ 195 // if (keyframeNode.getNodeName().equals("keyframe")){ 196 // float time = XMLUtil.getFloatAttribute(keyframeNode, "time"); 197 // List<Pose> poses = new ArrayList<Pose>(); 198 // List<Float> weights = new ArrayList<Float>(); 199 // 200 // Node poserefNode = keyframeNode.getFirstChild(); 201 // while (poserefNode != null){ 202 // if (poserefNode.getNodeName().equals("poseref")){ 203 // int poseindex = XMLUtil.getIntAttribute(poserefNode, "poseindex"); 204 // poses.add(posesList.get(poseindex)); 205 // float weight = XMLUtil.getFloatAttribute(poserefNode, "influence"); 206 // weights.add(weight); 207 // } 208 // 209 // poserefNode = poserefNode.getNextSibling(); 210 // } 211 // 212 // // convert poses and weights to arrays and create a PoseFrame 213 // float[] weightsArray = new float[weights.size()]; 214 // for (int i = 0; i < weightsArray.length; i++){ 215 // weightsArray[i] = weights.get(i); 216 // } 217 // PoseFrame frame = new PoseFrame(poses.toArray(new Pose[0]), weightsArray); 218 // 219 // times.add(time); 220 // frames.add(frame); 221 // } 222 // 223 // keyframeNode = keyframeNode.getNextSibling(); 224 // } 225 // 226 // // convert times and frames to arrays and write to the track 227 // float[] timesArray = new float[times.size()]; 228 // for (int i = 0; i < timesArray.length; i++){ 229 // timesArray[i] = times.get(i); 230 // } 231 // 232 // PoseTrack track = new PoseTrack(targetMeshIndex, 233 // timesArray, 234 // frames.toArray(new PoseFrame[0])); 235 // 236 // return track; 237 // } 238 239 } 240