Search in sources :

Example 6 with Track

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);
}
Also used : BoneTrack(com.jme3.animation.BoneTrack) Animation(com.jme3.animation.Animation) Bone(com.jme3.animation.Bone)

Example 7 with Track

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();
    }
}
Also used : SpatialTrack(com.jme3.animation.SpatialTrack) Animation(com.jme3.animation.Animation) SpatialTrack(com.jme3.animation.SpatialTrack) BoneTrack(com.jme3.animation.BoneTrack) Track(com.jme3.animation.Track)

Example 8 with Track

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;
}
Also used : TouchEvent(com.jme3.input.event.TouchEvent)

Example 9 with Track

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);
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f)

Example 10 with Track

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);
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Savable(com.jme3.export.Savable)

Aggregations

BoneTrack (com.jme3.animation.BoneTrack)9 Vector3f (com.jme3.math.Vector3f)9 Quaternion (com.jme3.math.Quaternion)7 Animation (com.jme3.animation.Animation)5 SpatialTrack (com.jme3.animation.SpatialTrack)5 Spatial (com.jme3.scene.Spatial)5 HashMap (java.util.HashMap)5 Bone (com.jme3.animation.Bone)4 Track (com.jme3.animation.Track)4 Skeleton (com.jme3.animation.Skeleton)2 Node (com.jme3.scene.Node)2 Map (java.util.Map)2 AnimChannel (com.jme3.animation.AnimChannel)1 AnimControl (com.jme3.animation.AnimControl)1 AudioNode (com.jme3.audio.AudioNode)1 ParticleEmitter (com.jme3.effect.ParticleEmitter)1 InputCapsule (com.jme3.export.InputCapsule)1 OutputCapsule (com.jme3.export.OutputCapsule)1 Savable (com.jme3.export.Savable)1 TouchEvent (com.jme3.input.event.TouchEvent)1