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
This commit is contained in:
parent
ba4265b77a
commit
67a7c1cf22
@ -413,6 +413,7 @@ public final class Bone implements Savable {
|
|||||||
|
|
||||||
localPos.set(initialPos).addLocal(translation);
|
localPos.set(initialPos).addLocal(translation);
|
||||||
localRot.set(initialRot).multLocal(rotation);
|
localRot.set(initialRot).multLocal(rotation);
|
||||||
|
|
||||||
if (scale != null) {
|
if (scale != null) {
|
||||||
localScale.set(initialScale).multLocal(scale);
|
localScale.set(initialScale).multLocal(scale);
|
||||||
}
|
}
|
||||||
@ -440,7 +441,7 @@ public final class Bone implements Savable {
|
|||||||
|
|
||||||
//scale
|
//scale
|
||||||
if (scale != null) {
|
if (scale != null) {
|
||||||
tmpV2.set(initialScale).addLocal(translation);
|
tmpV2.set(initialScale).multLocal(scale);
|
||||||
localScale.interpolate(tmpV2, weight);
|
localScale.interpolate(tmpV2, weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,9 +158,8 @@ public final class BoneTrack implements Savable {
|
|||||||
int i;
|
int i;
|
||||||
for (i = 0; i < lastFrame && times[i] < time; i++) {
|
for (i = 0; i < lastFrame && times[i] < time; i++) {
|
||||||
startFrame = i;
|
startFrame = i;
|
||||||
|
endFrame = i + 1;
|
||||||
}
|
}
|
||||||
//i is now startFrame+1;
|
|
||||||
endFrame = i ;
|
|
||||||
|
|
||||||
float blend = (time - times[startFrame])
|
float blend = (time - times[startFrame])
|
||||||
/ (times[endFrame] - times[startFrame]);
|
/ (times[endFrame] - times[startFrame]);
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.jme3.scene.plugins.ogre;
|
package com.jme3.scene.plugins.ogre;
|
||||||
|
|
||||||
import com.jme3.animation.Bone;
|
import com.jme3.animation.Bone;
|
||||||
@ -42,13 +41,12 @@ import com.jme3.asset.AssetManager;
|
|||||||
import com.jme3.math.Quaternion;
|
import com.jme3.math.Quaternion;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.util.xml.SAXUtil;
|
import com.jme3.util.xml.SAXUtil;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -62,31 +60,24 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
|||||||
public class SkeletonLoader extends DefaultHandler implements AssetLoader {
|
public class SkeletonLoader extends DefaultHandler implements AssetLoader {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(SceneLoader.class.getName());
|
private static final Logger logger = Logger.getLogger(SceneLoader.class.getName());
|
||||||
|
|
||||||
private AssetManager assetManager;
|
private AssetManager assetManager;
|
||||||
private Stack<String> elementStack = new Stack<String>();
|
private Stack<String> elementStack = new Stack<String>();
|
||||||
|
|
||||||
private HashMap<Integer, Bone> indexToBone = new HashMap<Integer, Bone>();
|
private HashMap<Integer, Bone> indexToBone = new HashMap<Integer, Bone>();
|
||||||
private HashMap<String, Bone> nameToBone = new HashMap<String, Bone>();
|
private HashMap<String, Bone> nameToBone = new HashMap<String, Bone>();
|
||||||
|
|
||||||
private BoneTrack track;
|
private BoneTrack track;
|
||||||
private ArrayList<BoneTrack> tracks = new ArrayList<BoneTrack>();
|
private ArrayList<BoneTrack> tracks = new ArrayList<BoneTrack>();
|
||||||
|
|
||||||
private BoneAnimation animation;
|
private BoneAnimation animation;
|
||||||
private ArrayList<BoneAnimation> animations;
|
private ArrayList<BoneAnimation> animations;
|
||||||
|
|
||||||
private Bone bone;
|
private Bone bone;
|
||||||
private Skeleton skeleton;
|
private Skeleton skeleton;
|
||||||
|
|
||||||
private ArrayList<Float> times = new ArrayList<Float>();
|
private ArrayList<Float> times = new ArrayList<Float>();
|
||||||
private ArrayList<Vector3f> translations = new ArrayList<Vector3f>();
|
private ArrayList<Vector3f> translations = new ArrayList<Vector3f>();
|
||||||
private ArrayList<Quaternion> rotations = new ArrayList<Quaternion>();
|
private ArrayList<Quaternion> rotations = new ArrayList<Quaternion>();
|
||||||
|
private ArrayList<Vector3f> scales = new ArrayList<Vector3f>();
|
||||||
private float time = -1;
|
private float time = -1;
|
||||||
private Vector3f position;
|
private Vector3f position;
|
||||||
private Quaternion rotation;
|
private Quaternion rotation;
|
||||||
private Vector3f scale;
|
private Vector3f scale;
|
||||||
|
|
||||||
private float angle;
|
private float angle;
|
||||||
private Vector3f axis;
|
private Vector3f axis;
|
||||||
|
|
||||||
@ -149,7 +140,7 @@ public class SkeletonLoader extends DefaultHandler implements AssetLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void endElement(String uri, String name, String qName) {
|
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("axis")) {
|
||||||
} else if (qName.equals("rotate") || qName.equals("rotation")) {
|
} else if (qName.equals("rotate") || qName.equals("rotation")) {
|
||||||
rotation = new Quaternion();
|
rotation = new Quaternion();
|
||||||
@ -193,6 +184,11 @@ public class SkeletonLoader extends DefaultHandler implements AssetLoader {
|
|||||||
times.add(time);
|
times.add(time);
|
||||||
translations.add(position);
|
translations.add(position);
|
||||||
rotations.add(rotation);
|
rotations.add(rotation);
|
||||||
|
if (scale != null) {
|
||||||
|
scales.add(scale);
|
||||||
|
}else{
|
||||||
|
scales.add(new Vector3f(1,1,1));
|
||||||
|
}
|
||||||
|
|
||||||
time = -1;
|
time = -1;
|
||||||
position = null;
|
position = null;
|
||||||
@ -201,12 +197,16 @@ public class SkeletonLoader extends DefaultHandler implements AssetLoader {
|
|||||||
} else if (qName.equals("keyframes")) {
|
} else if (qName.equals("keyframes")) {
|
||||||
if (times.size() > 0) {
|
if (times.size() > 0) {
|
||||||
float[] timesArray = new float[times.size()];
|
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);
|
timesArray[i] = times.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
Vector3f[] transArray = translations.toArray(new Vector3f[translations.size()]);
|
Vector3f[] transArray = translations.toArray(new Vector3f[translations.size()]);
|
||||||
Quaternion[] rotArray = rotations.toArray(new Quaternion[rotations.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 {
|
} else {
|
||||||
track = null;
|
track = null;
|
||||||
}
|
}
|
||||||
@ -214,6 +214,7 @@ public class SkeletonLoader extends DefaultHandler implements AssetLoader {
|
|||||||
times.clear();
|
times.clear();
|
||||||
translations.clear();
|
translations.clear();
|
||||||
rotations.clear();
|
rotations.clear();
|
||||||
|
scales.clear();
|
||||||
} else if (qName.equals("skeleton")) {
|
} else if (qName.equals("skeleton")) {
|
||||||
nameToBone.clear();
|
nameToBone.clear();
|
||||||
}
|
}
|
||||||
@ -232,8 +233,9 @@ public class SkeletonLoader extends DefaultHandler implements AssetLoader {
|
|||||||
track = null;
|
track = null;
|
||||||
tracks.clear();
|
tracks.clear();
|
||||||
animation = null;
|
animation = null;
|
||||||
if (animations != null)
|
if (animations != null) {
|
||||||
animations.clear();
|
animations.clear();
|
||||||
|
}
|
||||||
|
|
||||||
bone = null;
|
bone = null;
|
||||||
skeleton = null;
|
skeleton = null;
|
||||||
@ -277,5 +279,4 @@ public class SkeletonLoader extends DefaultHandler implements AssetLoader {
|
|||||||
in.close();
|
in.close();
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user