Package com.jme3.scene.plugins.blender.file

Examples of com.jme3.scene.plugins.blender.file.Structure


                    textureData.uvCoordinatesName = null;
                }

                Pointer pTex = (Pointer) textureData.mtex.getFieldValue("tex");
                if (pTex.isNotNull()) {
                    Structure tex = pTex.fetchData().get(0);
                    textureData.textureStructure = tex;
                    texturesList.add(textureData);
                }
            }
        }
View Full Code Here


    @SuppressWarnings("unchecked")
    public ParticleEmitter toParticleEmitter(Structure particleSystem) throws BlenderFileException {
        ParticleEmitter result = null;
        Pointer pParticleSettings = (Pointer) particleSystem.getFieldValue("part");
        if (pParticleSettings.isNotNull()) {
            Structure particleSettings = pParticleSettings.fetchData().get(0);

            int totPart = ((Number) particleSettings.getFieldValue("totpart")).intValue();

            // draw type will be stored temporarily in the name (it is used during modifier applying operation)
            int drawAs = ((Number) particleSettings.getFieldValue("draw_as")).intValue();
            char nameSuffix;// P - point, L - line, N - None, B - Bilboard
            switch (drawAs) {
                case PART_DRAW_NOT:
                    nameSuffix = 'N';
                    totPart = 0;// no need to generate particles in this case
                    break;
                case PART_DRAW_BB:
                    nameSuffix = 'B';
                    break;
                case PART_DRAW_OB:
                case PART_DRAW_GR:
                    nameSuffix = 'P';
                    LOGGER.warning("Neither object nor group particles supported yet! Using point representation instead!");// TODO: support groups and aobjects
                    break;
                case PART_DRAW_LINE:
                    nameSuffix = 'L';
                    LOGGER.warning("Lines not yet supported! Using point representation instead!");// TODO: support lines
                default:// all others are rendered as points in blender
                    nameSuffix = 'P';
            }
            result = new ParticleEmitter(particleSettings.getName() + nameSuffix, Type.Triangle, totPart);
            if (nameSuffix == 'N') {
                return result;// no need to set anything else
            }

            // setting the emitters shape (the shapes meshes will be set later during modifier applying operation)
            int from = ((Number) particleSettings.getFieldValue("from")).intValue();
            switch (from) {
                case PART_FROM_VERT:
                    result.setShape(new EmitterMeshVertexShape());
                    break;
                case PART_FROM_FACE:
                    result.setShape(new EmitterMeshFaceShape());
                    break;
                case PART_FROM_VOLUME:
                    result.setShape(new EmitterMeshConvexHullShape());
                    break;
                default:
                    LOGGER.warning("Default shape used! Unknown emitter shape value ('from' parameter: " + from + ')');
            }

            // reading acceleration
            DynamicArray<Number> acc = (DynamicArray<Number>) particleSettings.getFieldValue("acc");
            result.setGravity(-acc.get(0).floatValue(), -acc.get(1).floatValue(), -acc.get(2).floatValue());

            // setting the colors
            result.setEndColor(new ColorRGBA(1f, 1f, 1f, 1f));
            result.setStartColor(new ColorRGBA(1f, 1f, 1f, 1f));

            // reading size
            float sizeFactor = nameSuffix == 'B' ? 1.0f : 0.3f;
            float size = ((Number) particleSettings.getFieldValue("size")).floatValue() * sizeFactor;
            result.setStartSize(size);
            result.setEndSize(size);

            // reading lifetime
            int fps = blenderContext.getBlenderKey().getFps();
            float lifetime = ((Number) particleSettings.getFieldValue("lifetime")).floatValue() / fps;
            float randlife = ((Number) particleSettings.getFieldValue("randlife")).floatValue() / fps;
            result.setLowLife(lifetime * (1.0f - randlife));
            result.setHighLife(lifetime);

            // preparing influencer
            ParticleInfluencer influencer;
            int phystype = ((Number) particleSettings.getFieldValue("phystype")).intValue();
            switch (phystype) {
                case PART_PHYS_NEWTON:
                    influencer = new NewtonianParticleInfluencer();
                    ((NewtonianParticleInfluencer) influencer).setNormalVelocity(((Number) particleSettings.getFieldValue("normfac")).floatValue());
                    ((NewtonianParticleInfluencer) influencer).setVelocityVariation(((Number) particleSettings.getFieldValue("randfac")).floatValue());
                    ((NewtonianParticleInfluencer) influencer).setSurfaceTangentFactor(((Number) particleSettings.getFieldValue("tanfac")).floatValue());
                    ((NewtonianParticleInfluencer) influencer).setSurfaceTangentRotation(((Number) particleSettings.getFieldValue("tanphase")).floatValue());
                    break;
                case PART_PHYS_BOIDS:
                case PART_PHYS_KEYED:// TODO: support other influencers
                    LOGGER.warning("Boids and Keyed particles physic not yet supported! Empty influencer used!");
                case PART_PHYS_NO:
View Full Code Here

        }
        subType = ((Number) idPropertyStructure.getFieldValue("subtype")).intValue();
        type = ((Number) idPropertyStructure.getFieldValue("type")).intValue();

        // reading the data
        Structure data = (Structure) idPropertyStructure.getFieldValue("data");
        int len = ((Number) idPropertyStructure.getFieldValue("len")).intValue();
        switch (type) {
            case IDP_STRING: {
                Pointer pointer = (Pointer) data.getFieldValue("pointer");
                BlenderInputStream bis = blenderContext.getInputStream();
                FileBlockHeader dataFileBlock = blenderContext.getFileBlock(pointer.getOldMemoryAddress());
                bis.setPosition(dataFileBlock.getBlockPosition());
                value = bis.readString();
                break;
            }
            case IDP_INT:
                int intValue = ((Number) data.getFieldValue("val")).intValue();
                value = Integer.valueOf(intValue);
                break;
            case IDP_FLOAT:
                int floatValue = ((Number) data.getFieldValue("val")).intValue();
                value = Float.valueOf(Float.intBitsToFloat(floatValue));
                break;
            case IDP_ARRAY: {
                Pointer pointer = (Pointer) data.getFieldValue("pointer");
                BlenderInputStream bis = blenderContext.getInputStream();
                FileBlockHeader dataFileBlock = blenderContext.getFileBlock(pointer.getOldMemoryAddress());
                bis.setPosition(dataFileBlock.getBlockPosition());
                int elementAmount = dataFileBlock.getSize();
                switch (subType) {
                    case IDP_INT:
                        elementAmount /= 4;
                        int[] intList = new int[elementAmount];
                        for (int i = 0; i < elementAmount; ++i) {
                            intList[i] = bis.readInt();
                        }
                        value = intList;
                        break;
                    case IDP_FLOAT:
                        elementAmount /= 4;
                        float[] floatList = new float[elementAmount];
                        for (int i = 0; i < elementAmount; ++i) {
                            floatList[i] = bis.readFloat();
                        }
                        value = floatList;
                        break;
                    case IDP_DOUBLE:
                        elementAmount /= 8;
                        double[] doubleList = new double[elementAmount];
                        for (int i = 0; i < elementAmount; ++i) {
                            doubleList[i] = bis.readDouble();
                        }
                        value = doubleList;
                        break;
                    default:
                        throw new IllegalStateException("Invalid array subtype: " + subType);
                }
            }
            case IDP_GROUP:
                Structure group = (Structure) data.getFieldValue("group");
                List<Structure> dataList = group.evaluateListBase();
                List<Properties> subProperties = new ArrayList<Properties>(len);
                for (Structure d : dataList) {
                    Properties properties = new Properties();
                    properties.load(d, blenderContext);
                    subProperties.add(properties);
View Full Code Here

        }

        meshContext.setVertexReferenceMap(meshBuilder.getVertexReferenceMap());

        LOGGER.fine("Reading vertices groups (from the Object structure).");
        Structure parent = blenderContext.peekParent();
        Structure defbase = (Structure) parent.getFieldValue("defbase");
        List<Structure> defs = defbase.evaluateListBase();
        String[] verticesGroups = new String[defs.size()];
        int defIndex = 0;
        for (Structure def : defs) {
            verticesGroups[defIndex++] = def.getFieldValue("name").toString();
        }
View Full Code Here

        boolean visible = (restrictflag & 0x01) != 0;

        Pointer pParent = (Pointer) objectStructure.getFieldValue("parent");
        Object parent = blenderContext.getLoadedFeature(pParent.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
        if (parent == null && pParent.isNotNull()) {
            Structure parentStructure = pParent.fetchData().get(0);
            parent = this.toObject(parentStructure, blenderContext);
        }

        Transform t = this.getTransformation(objectStructure, blenderContext);
        LOGGER.log(Level.FINE, "Importing object of type: {0}", objectType);
        Node result = null;
        try {
            switch (objectType) {
                case EMPTY:
                case ARMATURE:
                    // need to use an empty node to properly create
                    // parent-children relationships between nodes
                    result = new Node(name);
                    break;
                case MESH:
                    result = new Node(name);
                    MeshHelper meshHelper = blenderContext.getHelper(MeshHelper.class);
                    Pointer pMesh = (Pointer) objectStructure.getFieldValue("data");
                    List<Structure> meshesArray = pMesh.fetchData();
                    List<Geometry> geometries = meshHelper.toMesh(meshesArray.get(0), blenderContext);
                    if (geometries != null) {
                        for (Geometry geometry : geometries) {
                            result.attachChild(geometry);
                        }
                    }
                    break;
                case SURF:
                case CURVE:
                    result = new Node(name);
                    Pointer pCurve = (Pointer) objectStructure.getFieldValue("data");
                    if (pCurve.isNotNull()) {
                        CurvesHelper curvesHelper = blenderContext.getHelper(CurvesHelper.class);
                        Structure curveData = pCurve.fetchData().get(0);
                        List<Geometry> curves = curvesHelper.toCurve(curveData, blenderContext);
                        for (Geometry curve : curves) {
                            result.attachChild(curve);
                        }
                    }
View Full Code Here

        TempVars tempVars = TempVars.get();

        Matrix4f parentInv = tempVars.tempMat4;
        Pointer pParent = (Pointer) objectStructure.getFieldValue("parent");
        if (pParent.isNotNull()) {
            Structure parentObjectStructure = (Structure) blenderContext.getLoadedFeature(pParent.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_STRUCTURE);
            this.getMatrix(parentObjectStructure, "obmat", fixUpAxis, parentInv).invertLocal();
        } else {
            parentInv.loadIdentity();
        }
View Full Code Here

    public ColorBand(Structure tex, BlenderContext blenderContext) {
        int flag = ((Number) tex.getFieldValue("flag")).intValue();
        if ((flag & GeneratedTexture.TEX_COLORBAND) != 0) {
            Pointer pColorband = (Pointer) tex.getFieldValue("coba");
            try {
                Structure colorbandStructure = pColorband.fetchData().get(0);
                cursorsAmount = ((Number) colorbandStructure.getFieldValue("tot")).intValue();
                ipoType = ((Number) colorbandStructure.getFieldValue("ipotype")).intValue();
                data = new ColorBandData[cursorsAmount];
                DynamicArray<Structure> data = (DynamicArray<Structure>) colorbandStructure.getFieldValue("data");
                for (int i = 0; i < cursorsAmount; ++i) {
                    this.data[i] = new ColorBandData(data.get(i));
                }
            } catch (BlenderFileException e) {
                LOGGER.log(Level.WARNING, "Cannot fetch the colorband structure. The reason: {0}", e.getLocalizedMessage());
View Full Code Here

            // indicates if the material with the specified number should have a texture attached
            Map<String, List<Vector2f>> uvs = this.loadUVCoordinates(meshStructure, false);
            Map<String, Vector2f[]> uvCoordinatesForFace = new HashMap<String, Vector2f[]>();
            int[] vertexColorIndex = verticesColors == null ? null : new int[3];
            for (int i = 0; i < mFaces.size(); ++i) {
                Structure mFace = mFaces.get(i);
                int materialNumber = ((Number) mFace.getFieldValue("mat_nr")).intValue();
                boolean smooth = (((Number) mFace.getFieldValue("flag")).byteValue() & 0x01) != 0x00;
                if (uvs != null) {
                    // uvs always must be added wheater we have texture or not
                    for (Entry<String, List<Vector2f>> entry : uvs.entrySet()) {
                        Vector2f[] uvCoordsForASingleFace = new Vector2f[3];
                        uvCoordsForASingleFace[0] = entry.getValue().get(i * 4);
                        uvCoordsForASingleFace[1] = entry.getValue().get(i * 4 + 1);
                        uvCoordsForASingleFace[2] = entry.getValue().get(i * 4 + 2);
                        uvCoordinatesForFace.put(entry.getKey(), uvCoordsForASingleFace);
                    }
                }

                int v1 = ((Number) mFace.getFieldValue("v1")).intValue();
                int v2 = ((Number) mFace.getFieldValue("v2")).intValue();
                int v3 = ((Number) mFace.getFieldValue("v3")).intValue();
                int v4 = ((Number) mFace.getFieldValue("v4")).intValue();
                if (vertexColorIndex != null) {
                    vertexColorIndex[0] = i * 4;
                    vertexColorIndex[1] = i * 4 + 1;
                    vertexColorIndex[2] = i * 4 + 2;
                }
View Full Code Here

    @SuppressWarnings("unchecked")
    private Map<String, List<Vector2f>> loadUVCoordinates(Structure meshStructure, boolean useBMesh) throws BlenderFileException {
        Map<String, List<Vector2f>> result = new HashMap<String, List<Vector2f>>();
        if (useBMesh) {
            // in this case the UV's are assigned to vertices (an array is the same length as the vertex array)
            Structure loopData = (Structure) meshStructure.getFieldValue("ldata");
            Pointer pLoopDataLayers = (Pointer) loopData.getFieldValue("layers");
            List<Structure> loopDataLayers = pLoopDataLayers.fetchData();
            for (Structure structure : loopDataLayers) {
                Pointer p = (Pointer) structure.getFieldValue("data");
                if (p.isNotNull() && ((Number) structure.getFieldValue("type")).intValue() == MeshHelper.UV_DATA_LAYER_TYPE_BMESH) {
                    String uvSetName = structure.getFieldValue("name").toString();
                    List<Structure> uvsStructures = p.fetchData();
                    List<Vector2f> uvs = new ArrayList<Vector2f>(uvsStructures.size());
                    for (Structure uvStructure : uvsStructures) {
                        DynamicArray<Number> loopUVS = (DynamicArray<Number>) uvStructure.getFieldValue("uv");
                        uvs.add(new Vector2f(loopUVS.get(0).floatValue(), loopUVS.get(1).floatValue()));
                    }
                    result.put(uvSetName, uvs);
                }
            }
        } else {
            // in this case UV's are assigned to faces (the array has the same legnth as the faces count)
            Structure facesData = (Structure) meshStructure.getFieldValue("fdata");
            Pointer pFacesDataLayers = (Pointer) facesData.getFieldValue("layers");
            List<Structure> facesDataLayers = pFacesDataLayers.fetchData();
            for (Structure structure : facesDataLayers) {
                Pointer p = (Pointer) structure.getFieldValue("data");
                if (p.isNotNull() && ((Number) structure.getFieldValue("type")).intValue() == MeshHelper.UV_DATA_LAYER_TYPE_FMESH) {
                    String uvSetName = structure.getFieldValue("name").toString();
View Full Code Here

     * @throws BlenderFileException
     *             an exception is thrown when the blend file is somehow corrupted
     */
    protected Properties loadProperties(Structure structure, BlenderContext blenderContext) throws BlenderFileException {
        Properties properties = null;
        Structure id = (Structure) structure.getFieldValue("ID");
        if (id != null) {
            Pointer pProperties = (Pointer) id.getFieldValue("properties");
            if (pProperties.isNotNull()) {
                Structure propertiesStructure = pProperties.fetchData().get(0);
                properties = new Properties();
                properties.load(propertiesStructure, blenderContext);
            }
        }
        return properties;
View Full Code Here

TOP

Related Classes of com.jme3.scene.plugins.blender.file.Structure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.