use of com.jme3.animation.Track in project jmonkeyengine by jMonkeyEngine.
the class SkeletonLoader method startElement.
public void startElement(String uri, String localName, String qName, Attributes attribs) throws SAXException {
if (qName.equals("position") || qName.equals("translate")) {
position = SAXUtil.parseVector3(attribs);
} else if (qName.equals("rotation") || qName.equals("rotate")) {
angle = SAXUtil.parseFloat(attribs.getValue("angle"));
} else if (qName.equals("axis")) {
assert elementStack.peek().equals("rotation") || elementStack.peek().equals("rotate");
axis = SAXUtil.parseVector3(attribs);
} else if (qName.equals("scale")) {
scale = SAXUtil.parseVector3(attribs);
} else if (qName.equals("keyframe")) {
assert elementStack.peek().equals("keyframes");
time = SAXUtil.parseFloat(attribs.getValue("time"));
} else if (qName.equals("keyframes")) {
assert elementStack.peek().equals("track");
} else if (qName.equals("track")) {
assert elementStack.peek().equals("tracks");
String boneName = SAXUtil.parseString(attribs.getValue("bone"));
Bone bone = nameToBone.get(boneName);
int index = skeleton.getBoneIndex(bone);
track = new BoneTrack(index);
} else if (qName.equals("boneparent")) {
assert elementStack.peek().equals("bonehierarchy");
String boneName = attribs.getValue("bone");
String parentName = attribs.getValue("parent");
Bone bone = nameToBone.get(boneName);
Bone parent = nameToBone.get(parentName);
parent.addChild(bone);
} else if (qName.equals("bone")) {
assert elementStack.peek().equals("bones");
// insert bone into indexed map
bone = new Bone(attribs.getValue("name"));
int id = SAXUtil.parseInt(attribs.getValue("id"));
indexToBone.put(id, bone);
nameToBone.put(bone.getName(), bone);
} else if (qName.equals("tracks")) {
assert elementStack.peek().equals("animation");
tracks.clear();
} else if (qName.equals("animation")) {
assert elementStack.peek().equals("animations");
String name = SAXUtil.parseString(attribs.getValue("name"));
float length = SAXUtil.parseFloat(attribs.getValue("length"));
animation = new Animation(name, length);
} else if (qName.equals("bonehierarchy")) {
assert elementStack.peek().equals("skeleton");
} else if (qName.equals("animations")) {
assert elementStack.peek().equals("skeleton");
animations = new ArrayList<Animation>();
} else if (qName.equals("bones")) {
assert elementStack.peek().equals("skeleton");
} else if (qName.equals("skeleton")) {
assert elementStack.size() == 0;
}
elementStack.add(qName);
}
use of com.jme3.animation.Track in project jmonkeyengine by jMonkeyEngine.
the class SimulationNode method simulateSpatial.
/**
* Simulates the spatial node.
*/
private void simulateSpatial() {
List<Constraint> constraints = blenderContext.getConstraints(featureOMA);
if (constraints != null && constraints.size() > 0) {
LOGGER.fine("Simulating spatial.");
boolean applyStaticConstraints = true;
if (animations != null) {
for (Animation animation : animations) {
float[] animationTimeBoundaries = this.computeAnimationTimeBoundaries(animation);
int maxFrame = (int) animationTimeBoundaries[0];
float maxTime = animationTimeBoundaries[1];
VirtualTrack vTrack = new VirtualTrack(spatial.getName(), maxFrame, maxTime);
for (Track track : animation.getTracks()) {
for (int frame = 0; frame < maxFrame; ++frame) {
spatial.setLocalTranslation(((SpatialTrack) track).getTranslations()[frame]);
spatial.setLocalRotation(((SpatialTrack) track).getRotations()[frame]);
spatial.setLocalScale(((SpatialTrack) track).getScales()[frame]);
for (Constraint constraint : constraints) {
constraint.apply(frame);
vTrack.setTransform(frame, spatial.getLocalTransform());
}
}
Track newTrack = vTrack.getAsSpatialTrack();
if (newTrack != null) {
animation.removeTrack(track);
animation.addTrack(newTrack);
}
applyStaticConstraints = false;
}
}
}
// object's transformation
if (applyStaticConstraints) {
for (Constraint constraint : constraints) {
constraint.apply(0);
}
}
}
for (SimulationNode child : children) {
child.simulate();
}
}
use of com.jme3.animation.Track in project jmonkeyengine by jMonkeyEngine.
the class AndroidGestureProcessor method onFling.
@Override
public boolean onFling(MotionEvent startEvent, MotionEvent endEvent, float velocityX, float velocityY) {
// Fling happens only once at the end of the gesture (all fingers up).
// Fling returns the velocity of the finger movement in pixels/sec.
// Therefore, the dX and dY values are actually velocity instead of distance values
// Since this does not track the movement, use the start position and velocity values.
// logger.log(Level.INFO, "onFling pointerId: {0}, startAction: {1}, startX: {2}, startY: {3}, endAction: {4}, endX: {5}, endY: {6}, velocityX: {7}, velocityY: {8}",
// new Object[]{touchInput.getPointerId(startEvent), touchInput.getAction(startEvent), startEvent.getX(), startEvent.getY(), touchInput.getAction(endEvent), endEvent.getX(), endEvent.getY(), velocityX, velocityY});
float jmeX = touchInput.getJmeX(startEvent.getX());
float jmeY = touchInput.invertY(touchInput.getJmeY(startEvent.getY()));
TouchEvent touchEvent = touchInput.getFreeTouchEvent();
touchEvent.set(TouchEvent.Type.FLING, jmeX, jmeY, velocityX, velocityY);
touchEvent.setPointerId(touchInput.getPointerId(endEvent));
touchEvent.setTime(endEvent.getEventTime());
touchEvent.setPressure(endEvent.getPressure());
touchInput.addEvent(touchEvent);
return true;
}
use of com.jme3.animation.Track in project jmonkeyengine by jMonkeyEngine.
the class TestBlenderLoader method simpleInitApp.
@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.DarkGray);
//load model with packed images
Spatial ogre = assetManager.loadModel("Blender/2.4x/Sinbad.blend");
rootNode.attachChild(ogre);
//load model with referenced images
Spatial track = assetManager.loadModel("Blender/2.4x/MountainValley_Track.blend");
rootNode.attachChild(track);
// sunset light
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.1f, -0.7f, 1).normalizeLocal());
dl.setColor(new ColorRGBA(0.44f, 0.30f, 0.20f, 1.0f));
rootNode.addLight(dl);
// skylight
dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.6f, -1, -0.6f).normalizeLocal());
dl.setColor(new ColorRGBA(0.10f, 0.22f, 0.44f, 1.0f));
rootNode.addLight(dl);
// white ambient light
dl = new DirectionalLight();
dl.setDirection(new Vector3f(1, -0.5f, -0.1f).normalizeLocal());
dl.setColor(new ColorRGBA(0.80f, 0.70f, 0.80f, 1.0f));
rootNode.addLight(dl);
}
use of com.jme3.animation.Track in project jmonkeyengine by jMonkeyEngine.
the class BinaryExporter method save.
public void save(Savable object, OutputStream os) throws IOException {
// reset some vars
aliasCount = 1;
idCount = 1;
classes.clear();
contentTable.clear();
locationTable.clear();
contentKeys.clear();
// write signature and version
os.write(ByteUtils.convertToBytes(FormatVersion.SIGNATURE));
os.write(ByteUtils.convertToBytes(FormatVersion.VERSION));
int id = processBinarySavable(object);
// write out tag table
int classTableSize = 0;
int classNum = classes.keySet().size();
// make all
int aliasSize = ((int) FastMath.log(classNum, 256) + 1);
// aliases a
// fixed width
os.write(ByteUtils.convertToBytes(classNum));
for (String key : classes.keySet()) {
BinaryClassObject bco = classes.get(key);
// write alias
byte[] aliasBytes = fixClassAlias(bco.alias, aliasSize);
os.write(aliasBytes);
classTableSize += aliasSize;
// jME3 NEW: Write class hierarchy version numbers
os.write(bco.classHierarchyVersions.length);
for (int version : bco.classHierarchyVersions) {
os.write(ByteUtils.convertToBytes(version));
}
classTableSize += 1 + bco.classHierarchyVersions.length * 4;
// write classname size & classname
byte[] classBytes = key.getBytes();
os.write(ByteUtils.convertToBytes(classBytes.length));
os.write(classBytes);
classTableSize += 4 + classBytes.length;
// for each field, write alias, type, and name
os.write(ByteUtils.convertToBytes(bco.nameFields.size()));
for (String fieldName : bco.nameFields.keySet()) {
BinaryClassField bcf = bco.nameFields.get(fieldName);
os.write(bcf.alias);
os.write(bcf.type);
// write classname size & classname
byte[] fNameBytes = fieldName.getBytes();
os.write(ByteUtils.convertToBytes(fNameBytes.length));
os.write(fNameBytes);
classTableSize += 2 + 4 + fNameBytes.length;
}
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
// write out data to a seperate stream
int location = 0;
// keep track of location for each piece
HashMap<String, ArrayList<BinaryIdContentPair>> alreadySaved = new HashMap<String, ArrayList<BinaryIdContentPair>>(contentTable.size());
for (Savable savable : contentKeys) {
// look back at previous written data for matches
String savableName = savable.getClass().getName();
BinaryIdContentPair pair = contentTable.get(savable);
ArrayList<BinaryIdContentPair> bucket = alreadySaved.get(savableName + getChunk(pair));
int prevLoc = findPrevMatch(pair, bucket);
if (prevLoc != -1) {
locationTable.put(pair.getId(), prevLoc);
continue;
}
locationTable.put(pair.getId(), location);
if (bucket == null) {
bucket = new ArrayList<BinaryIdContentPair>();
alreadySaved.put(savableName + getChunk(pair), bucket);
}
bucket.add(pair);
byte[] aliasBytes = fixClassAlias(classes.get(savableName).alias, aliasSize);
out.write(aliasBytes);
location += aliasSize;
BinaryOutputCapsule cap = contentTable.get(savable).getContent();
out.write(ByteUtils.convertToBytes(cap.bytes.length));
// length of bytes
location += 4;
out.write(cap.bytes);
location += cap.bytes.length;
}
// write out location table
// tag/location
int numLocations = locationTable.keySet().size();
os.write(ByteUtils.convertToBytes(numLocations));
int locationTableSize = 0;
for (Integer key : locationTable.keySet()) {
os.write(ByteUtils.convertToBytes(key));
os.write(ByteUtils.convertToBytes(locationTable.get(key)));
locationTableSize += 8;
}
// write out number of root ids - hardcoded 1 for now
os.write(ByteUtils.convertToBytes(1));
// write out root id
os.write(ByteUtils.convertToBytes(id));
// append stream to the output stream
out.writeTo(os);
out = null;
os = null;
if (debug) {
logger.fine("Stats:");
logger.log(Level.FINE, "classes: {0}", classNum);
logger.log(Level.FINE, "class table: {0} bytes", classTableSize);
logger.log(Level.FINE, "objects: {0}", numLocations);
logger.log(Level.FINE, "location table: {0} bytes", locationTableSize);
logger.log(Level.FINE, "data: {0} bytes", location);
}
}
Aggregations