Search in sources :

Example 31 with Type

use of com.jme3.effect.ParticleMesh.Type in project jmonkeyengine by jMonkeyEngine.

the class SceneMaterialLoader method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attribs) throws SAXException {
    if (qName.equals("externals")) {
        checkTopNode("scene");
        // Has an externals block, create material list.
        materialList = new MaterialList();
    } else if (qName.equals("item")) {
        checkTopNode("externals");
        if (!attribs.getValue("type").equals("material")) {
            // This is not a material external. Ignore it.
            ignoreItem = true;
        }
    } else if (qName.equals("file")) {
        checkTopNode("item");
        if (!ignoreItem) {
            String materialPath = attribs.getValue("name");
            String materialName = new File(materialPath).getName();
            String matFile = folderName + materialName;
            try {
                MaterialList loadedMaterialList = (MaterialList) assetManager.loadAsset(new OgreMaterialKey(matFile));
                materialList.putAll(loadedMaterialList);
            } catch (AssetNotFoundException ex) {
                logger.log(Level.WARNING, "Cannot locate material file: {0}", matFile);
            }
        }
    }
    elementStack.push(qName);
}
Also used : MaterialList(com.jme3.material.MaterialList) OgreMaterialKey(com.jme3.scene.plugins.ogre.matext.OgreMaterialKey) AssetNotFoundException(com.jme3.asset.AssetNotFoundException) File(java.io.File)

Example 32 with Type

use of com.jme3.effect.ParticleMesh.Type in project jmonkeyengine by jMonkeyEngine.

the class BlenderLoader method load.

@Override
public Spatial load(AssetInfo assetInfo) throws IOException {
    try {
        BlenderContext blenderContext = this.setup(assetInfo);
        AnimationHelper animationHelper = blenderContext.getHelper(AnimationHelper.class);
        animationHelper.loadAnimations();
        BlenderKey blenderKey = blenderContext.getBlenderKey();
        LoadedFeatures loadedFeatures = new LoadedFeatures();
        for (FileBlockHeader block : blenderContext.getBlocks()) {
            switch(block.getCode()) {
                case BLOCK_OB00:
                    ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
                    Node object = (Node) objectHelper.toObject(block.getStructure(blenderContext), blenderContext);
                    if (LOGGER.isLoggable(Level.FINE)) {
                        LOGGER.log(Level.FINE, "{0}: {1}--> {2}", new Object[] { object.getName(), object.getLocalTranslation().toString(), object.getParent() == null ? "null" : object.getParent().getName() });
                    }
                    if (object.getParent() == null) {
                        loadedFeatures.objects.add(object);
                    }
                    if (object instanceof LightNode && ((LightNode) object).getLight() != null) {
                        loadedFeatures.lights.add(((LightNode) object).getLight());
                    } else if (object instanceof CameraNode && ((CameraNode) object).getCamera() != null) {
                        loadedFeatures.cameras.add(((CameraNode) object).getCamera());
                    }
                    break;
                case // Scene
                BLOCK_SC00:
                    loadedFeatures.sceneBlocks.add(block);
                    break;
                case // Material
                BLOCK_MA00:
                    MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
                    MaterialContext materialContext = materialHelper.toMaterialContext(block.getStructure(blenderContext), blenderContext);
                    loadedFeatures.materials.add(materialContext);
                    break;
                case // Mesh
                BLOCK_ME00:
                    MeshHelper meshHelper = blenderContext.getHelper(MeshHelper.class);
                    TemporalMesh temporalMesh = meshHelper.toTemporalMesh(block.getStructure(blenderContext), blenderContext);
                    loadedFeatures.meshes.add(temporalMesh);
                    break;
                case // Image
                BLOCK_IM00:
                    TextureHelper textureHelper = blenderContext.getHelper(TextureHelper.class);
                    Texture image = textureHelper.loadImageAsTexture(block.getStructure(blenderContext), 0, blenderContext);
                    if (image != null && image.getImage() != null) {
                        // render results are stored as images but are not being loaded
                        loadedFeatures.images.add(image);
                    }
                    break;
                case BLOCK_TE00:
                    Structure textureStructure = block.getStructure(blenderContext);
                    int type = ((Number) textureStructure.getFieldValue("type")).intValue();
                    if (type == TextureHelper.TEX_IMAGE) {
                        TextureHelper texHelper = blenderContext.getHelper(TextureHelper.class);
                        Texture texture = texHelper.getTexture(textureStructure, null, blenderContext);
                        if (texture != null) {
                            // null is returned when texture has no image
                            loadedFeatures.textures.add(texture);
                        }
                    } else {
                        LOGGER.fine("Only image textures can be loaded as unlinked assets. Generated textures will be applied to an existing object.");
                    }
                    break;
                case // World
                BLOCK_WO00:
                    LandscapeHelper landscapeHelper = blenderContext.getHelper(LandscapeHelper.class);
                    Structure worldStructure = block.getStructure(blenderContext);
                    String worldName = worldStructure.getName();
                    if (blenderKey.getUsedWorld() == null || blenderKey.getUsedWorld().equals(worldName)) {
                        Light ambientLight = landscapeHelper.toAmbientLight(worldStructure);
                        if (ambientLight != null) {
                            loadedFeatures.objects.add(new LightNode(null, ambientLight));
                            loadedFeatures.lights.add(ambientLight);
                        }
                        loadedFeatures.sky = landscapeHelper.toSky(worldStructure);
                        loadedFeatures.backgroundColor = landscapeHelper.toBackgroundColor(worldStructure);
                        Filter fogFilter = landscapeHelper.toFog(worldStructure);
                        if (fogFilter != null) {
                            loadedFeatures.filters.add(landscapeHelper.toFog(worldStructure));
                        }
                    }
                    break;
                case BLOCK_AC00:
                    LOGGER.fine("Loading unlinked animations is not yet supported!");
                    break;
                default:
                    LOGGER.log(Level.FINEST, "Ommiting the block: {0}.", block.getCode());
            }
        }
        LOGGER.fine("Baking constraints after every feature is loaded.");
        ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class);
        constraintHelper.bakeConstraints(blenderContext);
        LOGGER.fine("Loading scenes and attaching them to the root object.");
        for (FileBlockHeader sceneBlock : loadedFeatures.sceneBlocks) {
            loadedFeatures.scenes.add(this.toScene(sceneBlock.getStructure(blenderContext), blenderContext));
        }
        LOGGER.fine("Creating the root node of the model and applying loaded nodes of the scene and loaded features to it.");
        Node modelRoot = new Node(blenderKey.getName());
        for (Node scene : loadedFeatures.scenes) {
            modelRoot.attachChild(scene);
        }
        if (blenderKey.isLoadUnlinkedAssets()) {
            LOGGER.fine("Setting loaded content as user data in resulting sptaial.");
            Map<String, Map<String, Object>> linkedData = new HashMap<String, Map<String, Object>>();
            Map<String, Object> thisFileData = new HashMap<String, Object>();
            thisFileData.put("scenes", loadedFeatures.scenes == null ? new ArrayList<Object>() : loadedFeatures.scenes);
            thisFileData.put("objects", loadedFeatures.objects == null ? new ArrayList<Object>() : loadedFeatures.objects);
            thisFileData.put("meshes", loadedFeatures.meshes == null ? new ArrayList<Object>() : loadedFeatures.meshes);
            thisFileData.put("materials", loadedFeatures.materials == null ? new ArrayList<Object>() : loadedFeatures.materials);
            thisFileData.put("textures", loadedFeatures.textures == null ? new ArrayList<Object>() : loadedFeatures.textures);
            thisFileData.put("images", loadedFeatures.images == null ? new ArrayList<Object>() : loadedFeatures.images);
            thisFileData.put("animations", loadedFeatures.animations == null ? new ArrayList<Object>() : loadedFeatures.animations);
            thisFileData.put("cameras", loadedFeatures.cameras == null ? new ArrayList<Object>() : loadedFeatures.cameras);
            thisFileData.put("lights", loadedFeatures.lights == null ? new ArrayList<Object>() : loadedFeatures.lights);
            thisFileData.put("filters", loadedFeatures.filters == null ? new ArrayList<Object>() : loadedFeatures.filters);
            thisFileData.put("backgroundColor", loadedFeatures.backgroundColor);
            thisFileData.put("sky", loadedFeatures.sky);
            linkedData.put("this", thisFileData);
            linkedData.putAll(blenderContext.getLinkedFeatures());
            modelRoot.setUserData("linkedData", linkedData);
        }
        return modelRoot;
    } catch (BlenderFileException e) {
        throw new IOException(e.getLocalizedMessage(), e);
    } catch (Exception e) {
        throw new IOException("Unexpected importer exception occured: " + e.getLocalizedMessage(), e);
    } finally {
        this.clear(assetInfo);
    }
}
Also used : HashMap(java.util.HashMap) LightNode(com.jme3.scene.LightNode) Node(com.jme3.scene.Node) CameraNode(com.jme3.scene.CameraNode) CameraNode(com.jme3.scene.CameraNode) ArrayList(java.util.ArrayList) Texture(com.jme3.texture.Texture) LandscapeHelper(com.jme3.scene.plugins.blender.landscape.LandscapeHelper) LightNode(com.jme3.scene.LightNode) Light(com.jme3.light.Light) TextureHelper(com.jme3.scene.plugins.blender.textures.TextureHelper) BlenderKey(com.jme3.asset.BlenderKey) Structure(com.jme3.scene.plugins.blender.file.Structure) ObjectHelper(com.jme3.scene.plugins.blender.objects.ObjectHelper) AnimationHelper(com.jme3.scene.plugins.blender.animations.AnimationHelper) FileBlockHeader(com.jme3.scene.plugins.blender.file.FileBlockHeader) BlenderFileException(com.jme3.scene.plugins.blender.file.BlenderFileException) IOException(java.io.IOException) ConstraintHelper(com.jme3.scene.plugins.blender.constraints.ConstraintHelper) BlenderFileException(com.jme3.scene.plugins.blender.file.BlenderFileException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) TemporalMesh(com.jme3.scene.plugins.blender.meshes.TemporalMesh) Filter(com.jme3.post.Filter) MaterialHelper(com.jme3.scene.plugins.blender.materials.MaterialHelper) MaterialContext(com.jme3.scene.plugins.blender.materials.MaterialContext) HashMap(java.util.HashMap) Map(java.util.Map) MeshHelper(com.jme3.scene.plugins.blender.meshes.MeshHelper)

Example 33 with Type

use of com.jme3.effect.ParticleMesh.Type in project jmonkeyengine by jMonkeyEngine.

the class AnimationHelper method getCurveType.

/**
     * This method returns the type of the ipo curve.
     * 
     * @param structure
     *            the structure must contain the 'rna_path' field and
     *            'array_index' field (the type is not important here)
     * @param blenderContext
     *            the blender context
     * @return the type of the curve
     */
public int getCurveType(Structure structure, BlenderContext blenderContext) {
    // reading rna path first
    BlenderInputStream bis = blenderContext.getInputStream();
    int currentPosition = bis.getPosition();
    Pointer pRnaPath = (Pointer) structure.getFieldValue("rna_path");
    FileBlockHeader dataFileBlock = blenderContext.getFileBlock(pRnaPath.getOldMemoryAddress());
    bis.setPosition(dataFileBlock.getBlockPosition());
    String rnaPath = bis.readString();
    bis.setPosition(currentPosition);
    int arrayIndex = ((Number) structure.getFieldValue("array_index")).intValue();
    // determining the curve type
    if (rnaPath.endsWith("location")) {
        return Ipo.AC_LOC_X + arrayIndex;
    }
    if (rnaPath.endsWith("rotation_quaternion")) {
        return Ipo.AC_QUAT_W + arrayIndex;
    }
    if (rnaPath.endsWith("scale")) {
        return Ipo.AC_SIZE_X + arrayIndex;
    }
    if (rnaPath.endsWith("rotation") || rnaPath.endsWith("rotation_euler")) {
        return Ipo.OB_ROT_X + arrayIndex;
    }
    LOGGER.log(Level.WARNING, "Unknown curve rna path: {0}", rnaPath);
    return -1;
}
Also used : FileBlockHeader(com.jme3.scene.plugins.blender.file.FileBlockHeader) BlenderInputStream(com.jme3.scene.plugins.blender.file.BlenderInputStream) Pointer(com.jme3.scene.plugins.blender.file.Pointer)

Example 34 with Type

use of com.jme3.effect.ParticleMesh.Type in project jmonkeyengine by jMonkeyEngine.

the class CameraHelper method toCamera249.

/**
     * This method converts the given structure to jme camera. Should be used form blender 2.49.
     * 
     * @param structure
     *            camera structure
     * @return jme camera object
     * @throws BlenderFileException
     *             an exception is thrown when there are problems with the
     *             blender file
     */
private Camera toCamera249(Structure structure) throws BlenderFileException {
    Camera camera = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_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 = 0;
    float clipsta = ((Number) structure.getFieldValue("clipsta")).floatValue();
    float clipend = ((Number) structure.getFieldValue("clipend")).floatValue();
    if (type == 0) {
        aspect = ((Number) structure.getFieldValue("lens")).floatValue();
    } else {
        aspect = ((Number) structure.getFieldValue("ortho_scale")).floatValue();
    }
    camera.setFrustumPerspective(aspect, camera.getWidth() / camera.getHeight(), clipsta, clipend);
    camera.setName(structure.getName());
    return camera;
}
Also used : Camera(com.jme3.renderer.Camera)

Example 35 with Type

use of com.jme3.effect.ParticleMesh.Type in project jmonkeyengine by jMonkeyEngine.

the class Field method fill.

/**
     * This method fills the field wth data read from the input stream.
     * @param blenderInputStream
     *            the stream we read data from
     * @throws BlenderFileException
     *             an exception is thrown when the blend file is somehow invalid or corrupted
     */
public void fill(BlenderInputStream blenderInputStream) throws BlenderFileException {
    int dataToRead = 1;
    if (tableSizes != null && tableSizes.length > 0) {
        for (int size : tableSizes) {
            if (size <= 0) {
                throw new BlenderFileException("The field " + name + " has invalid table size: " + size);
            }
            dataToRead *= size;
        }
    }
    DataType dataType = pointerLevel == 0 ? DataType.getDataType(type, blenderContext) : DataType.POINTER;
    switch(dataType) {
        case POINTER:
            if (dataToRead == 1) {
                Pointer pointer = new Pointer(pointerLevel, function, blenderContext);
                pointer.fill(blenderInputStream);
                value = pointer;
            } else {
                Pointer[] data = new Pointer[dataToRead];
                for (int i = 0; i < dataToRead; ++i) {
                    Pointer pointer = new Pointer(pointerLevel, function, blenderContext);
                    pointer.fill(blenderInputStream);
                    data[i] = pointer;
                }
                value = new DynamicArray<Pointer>(tableSizes, data);
            }
            break;
        case CHARACTER:
            // and characters are very often used as byte number stores instead of real chars
            if (dataToRead == 1) {
                value = Byte.valueOf((byte) blenderInputStream.readByte());
            } else {
                Character[] data = new Character[dataToRead];
                for (int i = 0; i < dataToRead; ++i) {
                    data[i] = Character.valueOf((char) blenderInputStream.readByte());
                }
                value = new DynamicArray<Character>(tableSizes, data);
            }
            break;
        case SHORT:
            if (dataToRead == 1) {
                value = Integer.valueOf(blenderInputStream.readShort());
            } else {
                Number[] data = new Number[dataToRead];
                for (int i = 0; i < dataToRead; ++i) {
                    data[i] = Integer.valueOf(blenderInputStream.readShort());
                }
                value = new DynamicArray<Number>(tableSizes, data);
            }
            break;
        case INTEGER:
            if (dataToRead == 1) {
                value = Integer.valueOf(blenderInputStream.readInt());
            } else {
                Number[] data = new Number[dataToRead];
                for (int i = 0; i < dataToRead; ++i) {
                    data[i] = Integer.valueOf(blenderInputStream.readInt());
                }
                value = new DynamicArray<Number>(tableSizes, data);
            }
            break;
        case LONG:
            if (dataToRead == 1) {
                value = Long.valueOf(blenderInputStream.readLong());
            } else {
                Number[] data = new Number[dataToRead];
                for (int i = 0; i < dataToRead; ++i) {
                    data[i] = Long.valueOf(blenderInputStream.readLong());
                }
                value = new DynamicArray<Number>(tableSizes, data);
            }
            break;
        case FLOAT:
            if (dataToRead == 1) {
                value = Float.valueOf(blenderInputStream.readFloat());
            } else {
                Number[] data = new Number[dataToRead];
                for (int i = 0; i < dataToRead; ++i) {
                    data[i] = Float.valueOf(blenderInputStream.readFloat());
                }
                value = new DynamicArray<Number>(tableSizes, data);
            }
            break;
        case DOUBLE:
            if (dataToRead == 1) {
                value = Double.valueOf(blenderInputStream.readDouble());
            } else {
                Number[] data = new Number[dataToRead];
                for (int i = 0; i < dataToRead; ++i) {
                    data[i] = Double.valueOf(blenderInputStream.readDouble());
                }
                value = new DynamicArray<Number>(tableSizes, data);
            }
            break;
        case VOID:
            break;
        case STRUCTURE:
            if (dataToRead == 1) {
                Structure structure = blenderContext.getDnaBlockData().getStructure(type);
                structure.fill(blenderContext.getInputStream());
                value = structure;
            } else {
                Structure[] data = new Structure[dataToRead];
                for (int i = 0; i < dataToRead; ++i) {
                    Structure structure = blenderContext.getDnaBlockData().getStructure(type);
                    structure.fill(blenderContext.getInputStream());
                    data[i] = structure;
                }
                value = new DynamicArray<Structure>(tableSizes, data);
            }
            break;
        default:
            throw new IllegalStateException("Unimplemented filling of type: " + type);
    }
}
Also used : DataType(com.jme3.scene.plugins.blender.file.Structure.DataType)

Aggregations

ArrayList (java.util.ArrayList)18 Structure (com.jme3.scene.plugins.blender.file.Structure)12 Vector3f (com.jme3.math.Vector3f)11 Pointer (com.jme3.scene.plugins.blender.file.Pointer)10 IOException (java.io.IOException)10 List (java.util.List)9 ColorRGBA (com.jme3.math.ColorRGBA)8 Texture (com.jme3.texture.Texture)8 Geometry (com.jme3.scene.Geometry)6 Image (com.jme3.texture.Image)6 BoundingBox (com.jme3.bounding.BoundingBox)5 BoundingSphere (com.jme3.bounding.BoundingSphere)5 Light (com.jme3.light.Light)5 TemporalMesh (com.jme3.scene.plugins.blender.meshes.TemporalMesh)5 Uniform (com.jme3.shader.Uniform)5 Material (com.jme3.material.Material)4 Quaternion (com.jme3.math.Quaternion)4 Transform (com.jme3.math.Transform)4 Mesh (com.jme3.scene.Mesh)4 BlenderFileException (com.jme3.scene.plugins.blender.file.BlenderFileException)4