use of com.jme3.animation.Skeleton in project jmonkeyengine by jMonkeyEngine.
the class MeshLoader method compileModel.
private Node compileModel() {
Node model = new Node(meshName + "-ogremesh");
for (int i = 0; i < geoms.size(); i++) {
Geometry g = geoms.get(i);
Mesh m = g.getMesh();
// New code for buffer extract
if (sharedMesh != null && usesSharedMesh.get(i)) {
m.extractVertexData(sharedMesh);
}
model.attachChild(geoms.get(i));
}
if (animData != null) {
for (int i = 0; i < geoms.size(); i++) {
Geometry g = geoms.get(i);
Mesh m = geoms.get(i).getMesh();
//FIXME the parameter is now useless.
//It was !HADWARE_SKINNING before, but since toggleing
//HW skinning does not happen at load time it was always true.
//We should use something similar as for the HWBoneIndex and
//HWBoneWeight : create the vertex buffers empty so that they
//are put in the cache, and really populate them the first time
//software skinning is used on the mesh.
m.generateBindPose(true);
}
// Put the animations in the AnimControl
HashMap<String, Animation> anims = new HashMap<String, Animation>();
ArrayList<Animation> animList = animData.anims;
for (int i = 0; i < animList.size(); i++) {
Animation anim = animList.get(i);
anims.put(anim.getName(), anim);
}
AnimControl ctrl = new AnimControl(animData.skeleton);
ctrl.setAnimations(anims);
model.addControl(ctrl);
// Put the skeleton in the skeleton control
SkeletonControl skeletonControl = new SkeletonControl(animData.skeleton);
// This will acquire the targets from the node
model.addControl(skeletonControl);
}
return model;
}
use of com.jme3.animation.Skeleton in project jmonkeyengine by jMonkeyEngine.
the class SkeletonLoader method endElement.
public void endElement(String uri, String name, String qName) {
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();
axis.normalizeLocal();
rotation.fromAngleNormalAxis(angle, axis);
angle = 0;
axis = null;
} else if (qName.equals("bone")) {
bone.setBindTransforms(position, rotation, scale);
bone = null;
position = null;
rotation = null;
scale = null;
} else if (qName.equals("bonehierarchy")) {
Bone[] bones = new Bone[indexToBone.size()];
// also assign the bones to the bonelist
for (Map.Entry<Integer, Bone> entry : indexToBone.entrySet()) {
Bone bone = entry.getValue();
bones[entry.getKey()] = bone;
}
indexToBone.clear();
skeleton = new Skeleton(bones);
} else if (qName.equals("animation")) {
animations.add(animation);
animation = null;
} else if (qName.equals("track")) {
if (track != null) {
// if track has keyframes
tracks.add(track);
track = null;
}
} else if (qName.equals("tracks")) {
BoneTrack[] trackList = tracks.toArray(new BoneTrack[tracks.size()]);
animation.setTracks(trackList);
tracks.clear();
} else if (qName.equals("keyframe")) {
assert time >= 0;
assert position != null;
assert rotation != null;
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;
rotation = null;
scale = null;
} else if (qName.equals("keyframes")) {
if (times.size() > 0) {
float[] timesArray = new float[times.size()];
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()]);
Vector3f[] scalesArray = scales.toArray(new Vector3f[scales.size()]);
track.setKeyframes(timesArray, transArray, rotArray, scalesArray);
//track.setKeyframes(timesArray, transArray, rotArray);
} else {
track = null;
}
times.clear();
translations.clear();
rotations.clear();
scales.clear();
} else if (qName.equals("skeleton")) {
nameToBone.clear();
}
assert elementStack.peek().equals(qName);
elementStack.pop();
}
Aggregations