Search in sources :

Example 1 with NewtonianParticleInfluencer

use of com.jme3.effect.influencers.NewtonianParticleInfluencer 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)

Aggregations

ParticleEmitter (com.jme3.effect.ParticleEmitter)1 EmptyParticleInfluencer (com.jme3.effect.influencers.EmptyParticleInfluencer)1 NewtonianParticleInfluencer (com.jme3.effect.influencers.NewtonianParticleInfluencer)1 ParticleInfluencer (com.jme3.effect.influencers.ParticleInfluencer)1 EmitterMeshConvexHullShape (com.jme3.effect.shapes.EmitterMeshConvexHullShape)1 EmitterMeshFaceShape (com.jme3.effect.shapes.EmitterMeshFaceShape)1 EmitterMeshVertexShape (com.jme3.effect.shapes.EmitterMeshVertexShape)1 ColorRGBA (com.jme3.math.ColorRGBA)1 DynamicArray (com.jme3.scene.plugins.blender.file.DynamicArray)1 Pointer (com.jme3.scene.plugins.blender.file.Pointer)1 Structure (com.jme3.scene.plugins.blender.file.Structure)1