Bone animation :

- Fixed squashing flickering when changing animation
- Fixed scale computation when blending
- Ogre loader can now properly load scales from ogre xml files

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@6993 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent ba4265b77a
commit 67a7c1cf22
  1. 3
      engine/src/core/com/jme3/animation/Bone.java
  2. 3
      engine/src/core/com/jme3/animation/BoneTrack.java
  3. 33
      engine/src/ogre/com/jme3/scene/plugins/ogre/SkeletonLoader.java

@ -413,6 +413,7 @@ public final class Bone implements Savable {
localPos.set(initialPos).addLocal(translation);
localRot.set(initialRot).multLocal(rotation);
if (scale != null) {
localScale.set(initialScale).multLocal(scale);
}
@ -440,7 +441,7 @@ public final class Bone implements Savable {
//scale
if (scale != null) {
tmpV2.set(initialScale).addLocal(translation);
tmpV2.set(initialScale).multLocal(scale);
localScale.interpolate(tmpV2, weight);
}

@ -158,9 +158,8 @@ public final class BoneTrack implements Savable {
int i;
for (i = 0; i < lastFrame && times[i] < time; i++) {
startFrame = i;
endFrame = i + 1;
}
//i is now startFrame+1;
endFrame = i ;
float blend = (time - times[startFrame])
/ (times[endFrame] - times[startFrame]);

@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.scene.plugins.ogre;
import com.jme3.animation.Bone;
@ -42,13 +41,12 @@ import com.jme3.asset.AssetManager;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.util.xml.SAXUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Stack;
import java.util.logging.Logger;
@ -62,31 +60,24 @@ import org.xml.sax.helpers.XMLReaderFactory;
public class SkeletonLoader extends DefaultHandler implements AssetLoader {
private static final Logger logger = Logger.getLogger(SceneLoader.class.getName());
private AssetManager assetManager;
private Stack<String> elementStack = new Stack<String>();
private HashMap<Integer, Bone> indexToBone = new HashMap<Integer, Bone>();
private HashMap<String, Bone> nameToBone = new HashMap<String, Bone>();
private BoneTrack track;
private ArrayList<BoneTrack> tracks = new ArrayList<BoneTrack>();
private BoneAnimation animation;
private ArrayList<BoneAnimation> animations;
private Bone bone;
private Skeleton skeleton;
private ArrayList<Float> times = new ArrayList<Float>();
private ArrayList<Vector3f> translations = new ArrayList<Vector3f>();
private ArrayList<Quaternion> rotations = new ArrayList<Quaternion>();
private ArrayList<Vector3f> scales = new ArrayList<Vector3f>();
private float time = -1;
private Vector3f position;
private Quaternion rotation;
private Vector3f scale;
private float angle;
private Vector3f axis;
@ -149,7 +140,7 @@ public class SkeletonLoader extends DefaultHandler implements AssetLoader {
}
public void endElement(String uri, String name, String qName) {
if (qName.equals("translate") || qName.equals("position")){
if (qName.equals("translate") || qName.equals("position") || qName.equals("scale")) {
} else if (qName.equals("axis")) {
} else if (qName.equals("rotate") || qName.equals("rotation")) {
rotation = new Quaternion();
@ -193,6 +184,11 @@ public class SkeletonLoader extends DefaultHandler implements AssetLoader {
times.add(time);
translations.add(position);
rotations.add(rotation);
if (scale != null) {
scales.add(scale);
}else{
scales.add(new Vector3f(1,1,1));
}
time = -1;
position = null;
@ -201,12 +197,16 @@ public class SkeletonLoader extends DefaultHandler implements AssetLoader {
} else if (qName.equals("keyframes")) {
if (times.size() > 0) {
float[] timesArray = new float[times.size()];
for (int i = 0; i < timesArray.length; i++)
for (int i = 0; i < timesArray.length; i++) {
timesArray[i] = times.get(i);
}
Vector3f[] transArray = translations.toArray(new Vector3f[translations.size()]);
Quaternion[] rotArray = rotations.toArray(new Quaternion[rotations.size()]);
track.setKeyframes(timesArray, transArray, rotArray);
Vector3f[] scalesArray = scales.toArray(new Vector3f[scales.size()]);
track.setKeyframes(timesArray, transArray, rotArray, scalesArray);
//track.setKeyframes(timesArray, transArray, rotArray);
} else {
track = null;
}
@ -214,6 +214,7 @@ public class SkeletonLoader extends DefaultHandler implements AssetLoader {
times.clear();
translations.clear();
rotations.clear();
scales.clear();
} else if (qName.equals("skeleton")) {
nameToBone.clear();
}
@ -232,8 +233,9 @@ public class SkeletonLoader extends DefaultHandler implements AssetLoader {
track = null;
tracks.clear();
animation = null;
if (animations != null)
if (animations != null) {
animations.clear();
}
bone = null;
skeleton = null;
@ -277,5 +279,4 @@ public class SkeletonLoader extends DefaultHandler implements AssetLoader {
in.close();
return obj;
}
}

Loading…
Cancel
Save