Search in sources :

Example 1 with Type

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

the class MotionPath method setPathSplineType.

/**
     * sets the type of spline used for the path interpolation for this path
     * @param pathSplineType
     */
public void setPathSplineType(SplineType pathSplineType) {
    spline.setType(pathSplineType);
    if (debugNode != null) {
        Node parent = debugNode.getParent();
        debugNode.removeFromParent();
        debugNode.detachAllChildren();
        debugNode = null;
        attachDebugNode(parent);
    }
}
Also used : Node(com.jme3.scene.Node)

Example 2 with Type

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

the class GeometryBatchFactory method alignBuffers.

/**
     * Will ensure that all the geometries' meshes of the n sub graph have the 
     * same types of buffers
     * @param n the node to gather geometries from
     * @param option the align options 
     * @see AlignOption
     * 
     * Very experimental for now.
     */
public static void alignBuffers(Node n, AlignOption option) {
    List<Geometry> geoms = new ArrayList<Geometry>();
    gatherGeoms(n, geoms);
    //gather buffer types
    Map<VertexBuffer.Type, VertexBuffer> types = new EnumMap<VertexBuffer.Type, VertexBuffer>(VertexBuffer.Type.class);
    Map<VertexBuffer.Type, Integer> typesCount = new EnumMap<VertexBuffer.Type, Integer>(VertexBuffer.Type.class);
    for (Geometry geom : geoms) {
        for (VertexBuffer buffer : geom.getMesh().getBufferList()) {
            if (types.get(buffer.getBufferType()) == null) {
                types.put(buffer.getBufferType(), buffer);
                logger.log(Level.FINE, buffer.getBufferType().toString());
            }
            Integer count = typesCount.get(buffer.getBufferType());
            if (count == null) {
                count = 0;
            }
            count++;
            typesCount.put(buffer.getBufferType(), count);
        }
    }
    switch(option) {
        case RemoveUnalignedBuffers:
            for (Geometry geom : geoms) {
                for (VertexBuffer buffer : geom.getMesh().getBufferList()) {
                    Integer count = typesCount.get(buffer.getBufferType());
                    if (count != null && count < geoms.size()) {
                        geom.getMesh().clearBuffer(buffer.getBufferType());
                        logger.log(Level.FINE, "removing {0} from {1}", new Object[] { buffer.getBufferType(), geom.getName() });
                    }
                }
            }
            break;
        case CreateMissingBuffers:
            for (Geometry geom : geoms) {
                for (VertexBuffer.Type type : types.keySet()) {
                    if (geom.getMesh().getBuffer(type) == null) {
                        VertexBuffer vb = new VertexBuffer(type);
                        Buffer b;
                        switch(type) {
                            case Index:
                            case BoneIndex:
                            case HWBoneIndex:
                                b = BufferUtils.createIntBuffer(geom.getMesh().getVertexCount() * types.get(type).getNumComponents());
                                break;
                            case InterleavedData:
                                b = BufferUtils.createByteBuffer(geom.getMesh().getVertexCount() * types.get(type).getNumComponents());
                                break;
                            default:
                                b = BufferUtils.createFloatBuffer(geom.getMesh().getVertexCount() * types.get(type).getNumComponents());
                        }
                        vb.setupData(types.get(type).getUsage(), types.get(type).getNumComponents(), types.get(type).getFormat(), b);
                        geom.getMesh().setBuffer(vb);
                        logger.log(Level.FINE, "geom {0} misses buffer {1}. Creating", new Object[] { geom.getName(), type });
                    }
                }
            }
            break;
    }
}
Also used : FloatBuffer(java.nio.FloatBuffer) ShortBuffer(java.nio.ShortBuffer) IndexBuffer(com.jme3.scene.mesh.IndexBuffer) IntBuffer(java.nio.IntBuffer) Buffer(java.nio.Buffer) Type(com.jme3.scene.VertexBuffer.Type) Type(com.jme3.scene.VertexBuffer.Type)

Example 3 with Type

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

the class ParticlesHelper method toParticleEmitter.

@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();
        // P - point, L - line, N - None, B - Bilboard
        char nameSuffix;
        switch(drawAs) {
            case PART_DRAW_NOT:
                nameSuffix = 'N';
                // no need to generate particles in this case
                totPart = 0;
                break;
            case PART_DRAW_BB:
                nameSuffix = 'B';
                break;
            case PART_DRAW_OB:
            case PART_DRAW_GR:
                nameSuffix = 'P';
                // TODO: support groups and aobjects
                LOGGER.warning("Neither object nor group particles supported yet! Using point representation instead!");
                break;
            case PART_DRAW_LINE:
                nameSuffix = 'L';
                // TODO: support lines
                LOGGER.warning("Lines not yet supported! Using point representation instead!");
            default:
                // all others are rendered as points in blender
                nameSuffix = 'P';
        }
        result = new ParticleEmitter(particleSettings.getName() + nameSuffix, Type.Triangle, totPart);
        if (nameSuffix == 'N') {
            // no need to set anything else
            return result;
        }
        // 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 // TODO: support other influencers
            PART_PHYS_KEYED:
                LOGGER.warning("Boids and Keyed particles physic not yet supported! Empty influencer used!");
            case PART_PHYS_NO:
            default:
                influencer = new EmptyParticleInfluencer();
        }
        result.setParticleInfluencer(influencer);
    }
    return result;
}
Also used : ParticleEmitter(com.jme3.effect.ParticleEmitter) EmptyParticleInfluencer(com.jme3.effect.influencers.EmptyParticleInfluencer) Pointer(com.jme3.scene.plugins.blender.file.Pointer) EmitterMeshVertexShape(com.jme3.effect.shapes.EmitterMeshVertexShape) EmitterMeshFaceShape(com.jme3.effect.shapes.EmitterMeshFaceShape) NewtonianParticleInfluencer(com.jme3.effect.influencers.NewtonianParticleInfluencer) ColorRGBA(com.jme3.math.ColorRGBA) EmitterMeshConvexHullShape(com.jme3.effect.shapes.EmitterMeshConvexHullShape) DynamicArray(com.jme3.scene.plugins.blender.file.DynamicArray) Structure(com.jme3.scene.plugins.blender.file.Structure) EmptyParticleInfluencer(com.jme3.effect.influencers.EmptyParticleInfluencer) ParticleInfluencer(com.jme3.effect.influencers.ParticleInfluencer) NewtonianParticleInfluencer(com.jme3.effect.influencers.NewtonianParticleInfluencer)

Example 4 with Type

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

the class CombinedTexture method isWithoutAlpha.

/**
     * This method determines if the given texture has no alpha channel.
     * 
     * @param texture
     *            the texture to check for alpha channel
     * @return <b>true</b> if the texture has no alpha channel and <b>false</b>
     *         otherwise
     */
private boolean isWithoutAlpha(TextureData textureData, BlenderContext blenderContext) {
    ColorBand colorBand = new ColorBand(textureData.textureStructure, blenderContext);
    if (!colorBand.hasTransparencies()) {
        int type = ((Number) textureData.textureStructure.getFieldValue("type")).intValue();
        if (type == TextureHelper.TEX_MAGIC) {
            return true;
        }
        if (type == TextureHelper.TEX_VORONOI) {
            int voronoiColorType = ((Number) textureData.textureStructure.getFieldValue("vn_coltype")).intValue();
            // voronoiColorType == 0:
            return voronoiColorType != 0;
        // intensity, voronoiColorType
        // != 0: col1, col2 or col3
        }
        if (type == TextureHelper.TEX_CLOUDS) {
            int sType = ((Number) textureData.textureStructure.getFieldValue("stype")).intValue();
            // sType==0: without colors, sType==1: with
            return sType == 1;
        // colors
        }
        // checking the flat textures for alpha values presence
        if (type == TextureHelper.TEX_IMAGE) {
            Image image = textureData.texture.getImage();
            switch(image.getFormat()) {
                case BGR8:
                case DXT1:
                case Luminance16F:
                case Luminance32F:
                case Luminance8:
                case RGB111110F:
                case RGB16F:
                case RGB32F:
                case RGB565:
                case RGB8:
                    // these types have no alpha by definition
                    return true;
                case ABGR8:
                case DXT1A:
                case DXT3:
                case DXT5:
                case Luminance16FAlpha16F:
                case Luminance8Alpha8:
                case RGBA16F:
                case RGBA32F:
                case RGBA8:
                case ARGB8:
                case BGRA8:
                case // with these types it is better to make sure if the texture is or is not transparent
                RGB5A1:
                    PixelInputOutput pixelInputOutput = PixelIOFactory.getPixelIO(image.getFormat());
                    TexturePixel pixel = new TexturePixel();
                    int depth = image.getDepth() == 0 ? 1 : image.getDepth();
                    for (int layerIndex = 0; layerIndex < depth; ++layerIndex) {
                        for (int x = 0; x < image.getWidth(); ++x) {
                            for (int y = 0; y < image.getHeight(); ++y) {
                                pixelInputOutput.read(image, layerIndex, pixel, x, y);
                                if (pixel.alpha < 1.0f) {
                                    return false;
                                }
                            }
                        }
                    }
                    return true;
                default:
                    throw new IllegalStateException("Unknown image format: " + image.getFormat());
            }
        }
    }
    return false;
}
Also used : PixelInputOutput(com.jme3.scene.plugins.blender.textures.io.PixelInputOutput) Image(com.jme3.texture.Image) BufferedImage(java.awt.image.BufferedImage)

Example 5 with Type

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

the class TextureHelper method getTexture.

/**
     * This class returns a texture read from the file or from packed blender
     * data. The returned texture has the name set to the value of its blender
     * type.
     * 
     * @param textureStructure
     *            texture structure filled with data
     * @param blenderContext
     *            the blender context
     * @return the texture that can be used by JME engine
     * @throws BlenderFileException
     *             this exception is thrown when the blend file structure is
     *             somehow invalid or corrupted
     */
public Texture getTexture(Structure textureStructure, Structure mTex, BlenderContext blenderContext) throws BlenderFileException {
    Texture result = (Texture) blenderContext.getLoadedFeature(textureStructure.getOldMemoryAddress(), LoadedDataType.FEATURE);
    if (result != null) {
        return result;
    }
    if ("ID".equals(textureStructure.getType())) {
        LOGGER.fine("Loading texture from external blend file.");
        return (Texture) this.loadLibrary(textureStructure);
    }
    int type = ((Number) textureStructure.getFieldValue("type")).intValue();
    int imaflag = ((Number) textureStructure.getFieldValue("imaflag")).intValue();
    switch(type) {
        case // (it is first because probably this will be most commonly used)
        TEX_IMAGE:
            Pointer pImage = (Pointer) textureStructure.getFieldValue("ima");
            if (pImage.isNotNull()) {
                Structure image = pImage.fetchData().get(0);
                Texture loadedTexture = this.loadImageAsTexture(image, imaflag, blenderContext);
                if (loadedTexture != null) {
                    result = loadedTexture;
                    this.applyColorbandAndColorFactors(textureStructure, result.getImage(), blenderContext);
                }
            }
            break;
        case TEX_CLOUDS:
        case TEX_WOOD:
        case TEX_MARBLE:
        case TEX_MAGIC:
        case TEX_BLEND:
        case TEX_STUCCI:
        case TEX_NOISE:
        case TEX_MUSGRAVE:
        case TEX_VORONOI:
        case TEX_DISTNOISE:
            result = new GeneratedTexture(textureStructure, mTex, textureGeneratorFactory.createTextureGenerator(type), blenderContext);
            break;
        case // No texture, do nothing
        TEX_NONE:
            break;
        case TEX_POINTDENSITY:
        case TEX_VOXELDATA:
        case TEX_PLUGIN:
        case TEX_ENVMAP:
        case TEX_OCEAN:
            LOGGER.log(Level.WARNING, "Unsupported texture type: {0} for texture: {1}", new Object[] { type, textureStructure.getName() });
            break;
        default:
            throw new BlenderFileException("Unknown texture type: " + type + " for texture: " + textureStructure.getName());
    }
    if (result != null) {
        result.setName(textureStructure.getName());
        result.setWrap(WrapMode.Repeat);
        // decide if the mipmaps will be generated
        switch(blenderContext.getBlenderKey().getMipmapGenerationMethod()) {
            case ALWAYS_GENERATE:
                result.setMinFilter(MinFilter.Trilinear);
                break;
            case NEVER_GENERATE:
                break;
            case GENERATE_WHEN_NEEDED:
                if ((imaflag & 0x04) != 0) {
                    result.setMinFilter(MinFilter.Trilinear);
                }
                break;
            default:
                throw new IllegalStateException("Unknown mipmap generation method: " + blenderContext.getBlenderKey().getMipmapGenerationMethod());
        }
        if (type != TEX_IMAGE) {
            // only generated textures should have this key
            result.setKey(new GeneratedTextureKey(textureStructure.getName()));
        }
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.log(Level.FINE, "Adding texture {0} to the loaded features with OMA = {1}", new Object[] { result.getName(), textureStructure.getOldMemoryAddress() });
        }
        blenderContext.addLoadedFeatures(textureStructure.getOldMemoryAddress(), LoadedDataType.STRUCTURE, textureStructure);
        blenderContext.addLoadedFeatures(textureStructure.getOldMemoryAddress(), LoadedDataType.FEATURE, result);
    }
    return result;
}
Also used : BlenderFileException(com.jme3.scene.plugins.blender.file.BlenderFileException) Pointer(com.jme3.scene.plugins.blender.file.Pointer) GeneratedTextureKey(com.jme3.asset.GeneratedTextureKey) Structure(com.jme3.scene.plugins.blender.file.Structure) Texture(com.jme3.texture.Texture)

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