Search in sources :

Example 31 with Structure

use of com.jme3.scene.plugins.blender.file.Structure in project jmonkeyengine by jMonkeyEngine.

the class AnimationHelper method loadAnimations.

/**
     * Loads all animations that are stored in the blender file. The animations are not yet applied to the scene features.
     * This should be called before objects are loaded.
     * @throws BlenderFileException
     *             an exception is thrown when problems with blender file reading occur
     */
public void loadAnimations() throws BlenderFileException {
    LOGGER.info("Loading animations that will be later applied to scene features.");
    List<FileBlockHeader> actionHeaders = blenderContext.getFileBlocks(BlockCode.BLOCK_AC00);
    if (actionHeaders != null) {
        for (FileBlockHeader header : actionHeaders) {
            Structure actionStructure = header.getStructure(blenderContext);
            LOGGER.log(Level.INFO, "Found animation: {0}.", actionStructure.getName());
            blenderContext.addAction(this.getTracks(actionStructure, blenderContext));
        }
    }
}
Also used : FileBlockHeader(com.jme3.scene.plugins.blender.file.FileBlockHeader) Structure(com.jme3.scene.plugins.blender.file.Structure)

Example 32 with Structure

use of com.jme3.scene.plugins.blender.file.Structure in project jmonkeyengine by jMonkeyEngine.

the class AnimationHelper method fromIpoStructure.

/**
     * This method creates an ipo object used for interpolation calculations.
     * 
     * @param ipoStructure
     *            the structure with ipo definition
     * @param blenderContext
     *            the blender context
     * @return the ipo object
     * @throws BlenderFileException
     *             this exception is thrown when the blender file is somehow
     *             corrupted
     */
public Ipo fromIpoStructure(Structure ipoStructure, BlenderContext blenderContext) throws BlenderFileException {
    Structure curvebase = (Structure) ipoStructure.getFieldValue("curve");
    // preparing bezier curves
    Ipo result = null;
    // IpoCurve
    List<Structure> curves = curvebase.evaluateListBase();
    if (curves.size() > 0) {
        BezierCurve[] bezierCurves = new BezierCurve[curves.size()];
        int frame = 0;
        for (Structure curve : curves) {
            Pointer pBezTriple = (Pointer) curve.getFieldValue("bezt");
            List<Structure> bezTriples = pBezTriple.fetchData();
            int type = ((Number) curve.getFieldValue("adrcode")).intValue();
            bezierCurves[frame++] = new BezierCurve(type, bezTriples, 2);
        }
        curves.clear();
        result = new Ipo(bezierCurves, fixUpAxis, blenderContext.getBlenderVersion());
        Long ipoOma = ipoStructure.getOldMemoryAddress();
        blenderContext.addLoadedFeatures(ipoOma, LoadedDataType.STRUCTURE, ipoStructure);
        blenderContext.addLoadedFeatures(ipoOma, LoadedDataType.FEATURE, result);
    }
    return result;
}
Also used : ConstIpo(com.jme3.scene.plugins.blender.animations.Ipo.ConstIpo) Pointer(com.jme3.scene.plugins.blender.file.Pointer) Structure(com.jme3.scene.plugins.blender.file.Structure) BezierCurve(com.jme3.scene.plugins.blender.curves.BezierCurve)

Example 33 with Structure

use of com.jme3.scene.plugins.blender.file.Structure in project jmonkeyengine by jMonkeyEngine.

the class AnimationHelper method getTracks250.

/**
     * This method retuns the bone tracks for animation for blender version 2.50
     * and higher.
     * 
     * @param actionStructure
     *            the structure containing the tracks
     * @param blenderContext
     *            the blender context
     * @return a list of tracks for the specified animation
     * @throws BlenderFileException
     *             an exception is thrown when there are problems with the blend
     *             file
     */
private BlenderAction getTracks250(Structure actionStructure, BlenderContext blenderContext) throws BlenderFileException {
    LOGGER.log(Level.FINE, "Getting tracks!");
    Structure groups = (Structure) actionStructure.getFieldValue("groups");
    // bActionGroup
    List<Structure> actionGroups = groups.evaluateListBase();
    BlenderAction blenderAction = new BlenderAction(actionStructure.getName(), blenderContext.getBlenderKey().getFps());
    int lastFrame = 1;
    for (Structure actionGroup : actionGroups) {
        String name = actionGroup.getFieldValue("name").toString();
        List<Structure> channels = ((Structure) actionGroup.getFieldValue("channels")).evaluateListBase();
        BezierCurve[] bezierCurves = new BezierCurve[channels.size()];
        int channelCounter = 0;
        for (Structure c : channels) {
            int type = this.getCurveType(c, blenderContext);
            Pointer pBezTriple = (Pointer) c.getFieldValue("bezt");
            List<Structure> bezTriples = pBezTriple.fetchData();
            bezierCurves[channelCounter++] = new BezierCurve(type, bezTriples, 2);
        }
        Ipo ipo = new Ipo(bezierCurves, fixUpAxis, blenderContext.getBlenderVersion());
        lastFrame = Math.max(lastFrame, ipo.getLastFrame());
        blenderAction.featuresTracks.put(name, ipo);
    }
    blenderAction.stopFrame = lastFrame;
    return blenderAction;
}
Also used : ConstIpo(com.jme3.scene.plugins.blender.animations.Ipo.ConstIpo) Pointer(com.jme3.scene.plugins.blender.file.Pointer) Structure(com.jme3.scene.plugins.blender.file.Structure) BezierCurve(com.jme3.scene.plugins.blender.curves.BezierCurve)

Example 34 with Structure

use of com.jme3.scene.plugins.blender.file.Structure in project jmonkeyengine by jMonkeyEngine.

the class CameraHelper method toCamera250.

/**
     * This method converts the given structure to jme camera. Should be used form blender 2.5+.
     * 
     * @param structure
     *            camera structure
     * @param sceneStructure
     *            scene structure
     * @return jme camera object
     * @throws BlenderFileException
     *             an exception is thrown when there are problems with the
     *             blender file
     */
private Camera toCamera250(Structure structure, Structure sceneStructure) throws BlenderFileException {
    int width = DEFAULT_CAM_WIDTH;
    int height = DEFAULT_CAM_HEIGHT;
    if (sceneStructure != null) {
        Structure renderData = (Structure) sceneStructure.getFieldValue("r");
        width = ((Number) renderData.getFieldValue("xsch")).shortValue();
        height = ((Number) renderData.getFieldValue("ysch")).shortValue();
    }
    Camera camera = new Camera(width, height);
    int type = ((Number) structure.getFieldValue("type")).intValue();
    if (type != 0 && type != 1) {
        LOGGER.log(Level.WARNING, "Unknown camera type: {0}. Perspective camera is being used!", type);
        type = 0;
    }
    // type==0 - perspective; type==1 - orthographic; perspective is used as default
    camera.setParallelProjection(type == 1);
    float aspect = width / (float) height;
    // Vertical field of view in degrees
    float fovY;
    float clipsta = ((Number) structure.getFieldValue("clipsta")).floatValue();
    float clipend = ((Number) structure.getFieldValue("clipend")).floatValue();
    if (type == 0) {
        // Convert lens MM to vertical degrees in fovY, see Blender rna_Camera_angle_get()
        // Default sensor size prior to 2.60 was 32.
        float sensor = 32.0f;
        boolean sensorVertical = false;
        Number sensorFit = (Number) structure.getFieldValue("sensor_fit");
        if (sensorFit != null) {
            // If sensor_fit is vert (2), then sensor_y is used
            sensorVertical = sensorFit.byteValue() == 2;
            String sensorName = "sensor_x";
            if (sensorVertical) {
                sensorName = "sensor_y";
            }
            sensor = ((Number) structure.getFieldValue(sensorName)).floatValue();
        }
        float focalLength = ((Number) structure.getFieldValue("lens")).floatValue();
        float fov = 2.0f * FastMath.atan(sensor / 2.0f / focalLength);
        if (sensorVertical) {
            fovY = fov * FastMath.RAD_TO_DEG;
        } else {
            // Convert fov from horizontal to vertical
            fovY = 2.0f * FastMath.atan(FastMath.tan(fov / 2.0f) / aspect) * FastMath.RAD_TO_DEG;
        }
    } else {
        // This probably is not correct.
        fovY = ((Number) structure.getFieldValue("ortho_scale")).floatValue();
    }
    camera.setFrustumPerspective(fovY, aspect, clipsta, clipend);
    camera.setName(structure.getName());
    return camera;
}
Also used : Camera(com.jme3.renderer.Camera) Structure(com.jme3.scene.plugins.blender.file.Structure)

Example 35 with Structure

use of com.jme3.scene.plugins.blender.file.Structure in project jmonkeyengine by jMonkeyEngine.

the class MikktspaceTangentGenerator method MergeVertsSlow.

//TODO Nehon: Used only if an array failed to be allocated... Can't happen in Java...
static void MergeVertsSlow(int[] piTriList_in_and_out, final MikkTSpaceContext mikkTSpace, final int[] pTable, final int iEntries) {
    // this can be optimized further using a tree structure or more hashing.
    for (int e = 0; e < iEntries; e++) {
        int i = pTable[e];
        final int index = piTriList_in_and_out[i];
        final Vector3f vP = getPosition(mikkTSpace, index);
        final Vector3f vN = getNormal(mikkTSpace, index);
        final Vector3f vT = getTexCoord(mikkTSpace, index);
        boolean bNotFound = true;
        int e2 = 0, i2rec = -1;
        while (e2 < e && bNotFound) {
            final int i2 = pTable[e2];
            final int index2 = piTriList_in_and_out[i2];
            final Vector3f vP2 = getPosition(mikkTSpace, index2);
            final Vector3f vN2 = getNormal(mikkTSpace, index2);
            final Vector3f vT2 = getTexCoord(mikkTSpace, index2);
            i2rec = i2;
            if (vP.equals(vP2) && vN.equals(vN2) && vT.equals(vT2)) {
                bNotFound = false;
            } else {
                ++e2;
            }
        }
        // merge if previously found
        if (!bNotFound) {
            piTriList_in_and_out[i] = piTriList_in_and_out[i2rec];
        }
    }
}
Also used : Vector3f(com.jme3.math.Vector3f)

Aggregations

Structure (com.jme3.scene.plugins.blender.file.Structure)34 Pointer (com.jme3.scene.plugins.blender.file.Pointer)30 ArrayList (java.util.ArrayList)16 Vector3f (com.jme3.math.Vector3f)8 BlenderFileException (com.jme3.scene.plugins.blender.file.BlenderFileException)7 DynamicArray (com.jme3.scene.plugins.blender.file.DynamicArray)7 FileBlockHeader (com.jme3.scene.plugins.blender.file.FileBlockHeader)7 List (java.util.List)6 Map (java.util.Map)6 TemporalMesh (com.jme3.scene.plugins.blender.meshes.TemporalMesh)5 ObjectHelper (com.jme3.scene.plugins.blender.objects.ObjectHelper)5 HashMap (java.util.HashMap)5 ColorRGBA (com.jme3.math.ColorRGBA)4 Node (com.jme3.scene.Node)4 Texture (com.jme3.texture.Texture)4 CameraNode (com.jme3.scene.CameraNode)3 LightNode (com.jme3.scene.LightNode)3 Spatial (com.jme3.scene.Spatial)3 AnimationHelper (com.jme3.scene.plugins.blender.animations.AnimationHelper)3 ConstIpo (com.jme3.scene.plugins.blender.animations.Ipo.ConstIpo)3