com.jme3.effect.shapes.EmitterShape Java Examples

The following examples show how to use com.jme3.effect.shapes.EmitterShape. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmitterShapePropertyBuilder.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected void buildForImpl(@NotNull final Object object, @Nullable final Object parent,
                            @NotNull final VBox container, @NotNull final ModelChangeConsumer changeConsumer) {

    if (!(object instanceof EmitterShape)) return;

    final EmitterShape shape = (EmitterShape) object;

    if (shape instanceof EmitterPointShape) {
        createControls(container, changeConsumer, (EmitterPointShape) object);
    } else if (shape instanceof EmitterBoxShape) {
        createControls(container, changeConsumer, (EmitterBoxShape) object);
    } else if (shape instanceof EmitterSphereShape) {
        createControls(container, changeConsumer, (EmitterSphereShape) object);
    }
}
 
Example #2
Source File: SceneExplorerProperty.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public SceneExplorerProperty(T instance, Class valueType, String getter, String setter, ScenePropertyChangeListener listener) throws NoSuchMethodException {
    super(instance, valueType, getter, setter);
    addPropertyChangeListener(listener);
    if (valueType == Vector3f.class) {
        setPropertyEditorClass(Vector3fPropertyEditor.class);
    } else if (valueType == Quaternion.class) {
        setPropertyEditorClass(QuaternionPropertyEditor.class);
    } else if (valueType == Matrix3f.class) {
        setPropertyEditorClass(Matrix3fPropertyEditor.class);
    } else if (valueType == ColorRGBA.class) {
        setPropertyEditorClass(ColorRGBAPropertyEditor.class);
    } else if (valueType == EmitterShape.class) {
        setPropertyEditorClass(EmitterShapePropertyEditor.class);
    } else if (valueType == Vector2f.class) {
        setPropertyEditorClass(Vector2fPropertyEditor.class);
    }

    for (SceneExplorerPropertyEditor di : Lookup.getDefault().lookupAll(SceneExplorerPropertyEditor.class)) {
        di.setEditor(valueType, this);
    }
}
 
Example #3
Source File: NewtonianParticleInfluencer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void influenceParticle(Particle particle, EmitterShape emitterShape) {
    emitterShape.getRandomPointAndNormal(particle.position, particle.velocity);
    // influencing the particle's velocity
    if (surfaceTangentFactor == 0.0f) {
        particle.velocity.multLocal(normalVelocity);
    } else {
        // calculating surface tangent (velocity contains the 'normal' value)
        temp.set(particle.velocity.z * surfaceTangentFactor, particle.velocity.y * surfaceTangentFactor, -particle.velocity.x * surfaceTangentFactor);
        if (surfaceTangentRotation != 0.0f) {// rotating the tangent
            Matrix3f m = new Matrix3f();
            m.fromAngleNormalAxis(FastMath.PI * surfaceTangentRotation, particle.velocity);
            temp = m.multLocal(temp);
        }
        // applying normal factor (this must be done first)
        particle.velocity.multLocal(normalVelocity);
        // adding tangent vector
        particle.velocity.addLocal(temp);
    }
    if (velocityVariation != 0.0f) {
        this.applyVelocityVariation(particle);
    }
}
 
Example #4
Source File: NewtonianParticleInfluencer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void influenceParticle(Particle particle, EmitterShape emitterShape) {
    emitterShape.getRandomPointAndNormal(particle.position, particle.velocity);
    // influencing the particle's velocity
    if (surfaceTangentFactor == 0.0f) {
        particle.velocity.multLocal(normalVelocity);
    } else {
        // calculating surface tangent (velocity contains the 'normal' value)
        temp.set(particle.velocity.z * surfaceTangentFactor, particle.velocity.y * surfaceTangentFactor, -particle.velocity.x * surfaceTangentFactor);
        if (surfaceTangentRotation != 0.0f) {// rotating the tangent
            Matrix3f m = new Matrix3f();
            m.fromAngleNormalAxis(FastMath.PI * surfaceTangentRotation, particle.velocity);
            temp = m.multLocal(temp);
        }
        // applying normal factor (this must be done first)
        particle.velocity.multLocal(normalVelocity);
        // adding tangent vector
        particle.velocity.addLocal(temp);
    }
    if (velocityVariation != 0.0f) {
        this.applyVelocityVariation(particle);
    }
}
 
Example #5
Source File: ChangeEmitterShapeOperation.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
private void switchShape(final @NotNull ModelChangeConsumer editor) {

        final EmitterShape shape = emitter.getShape();
        final EmitterShape newShape = prevShape;
        prevShape = shape;
        emitter.setShape(newShape);

        EXECUTOR_MANAGER.addFxTask(() -> editor.notifyFxReplaced(emitter, prevShape, newShape, true, true));
    }
 
Example #6
Source File: EmitterShapePropertyEditor.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void notifyListeners(EmitterShape before, EmitterShape after) {
    for (Iterator<PropertyChangeListener> it = listeners.iterator(); it.hasNext();) {
        PropertyChangeListener propertyChangeListener = it.next();
        //TODO: check what the "programmatic name" is supposed to be here.. for now its Quaternion
        propertyChangeListener.propertyChange(new PropertyChangeEvent(this, null, before, after));
    }
}
 
Example #7
Source File: ParticlesModifier.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Node apply(Node node, BlenderContext blenderContext) {
    if (invalid) {
        LOGGER.log(Level.WARNING, "Particles modifier is invalid! Cannot be applied to: {0}", node.getName());
        return node;
    }

    MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
    ParticleEmitter emitter = particleEmitter.clone();

    // veryfying the alpha function for particles' texture
    Integer alphaFunction = MaterialHelper.ALPHA_MASK_HYPERBOLE;
    char nameSuffix = emitter.getName().charAt(emitter.getName().length() - 1);
    if (nameSuffix == 'B' || nameSuffix == 'N') {
        alphaFunction = MaterialHelper.ALPHA_MASK_NONE;
    }
    // removing the type suffix from the name
    emitter.setName(emitter.getName().substring(0, emitter.getName().length() - 1));

    // applying emitter shape
    EmitterShape emitterShape = emitter.getShape();
    List<Mesh> meshes = new ArrayList<Mesh>();
    for (Spatial spatial : node.getChildren()) {
        if (spatial instanceof Geometry) {
            Mesh mesh = ((Geometry) spatial).getMesh();
            if (mesh != null) {
                meshes.add(mesh);
                Material material = materialHelper.getParticlesMaterial(((Geometry) spatial).getMaterial(), alphaFunction, blenderContext);
                emitter.setMaterial(material);// TODO: divide into several pieces
            }
        }
    }
    if (meshes.size() > 0 && emitterShape instanceof EmitterMeshVertexShape) {
        ((EmitterMeshVertexShape) emitterShape).setMeshes(meshes);
    }

    node.attachChild(emitter);
    return node;
}
 
Example #8
Source File: CreateSphereShapeEmitterAction.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected @NotNull EmitterShape createEmitterShape(@NotNull final VarTable vars) {
    final Vector3f center = vars.get(PROPERTY_CENTER);
    final float radius = vars.getFloat(PROPERTY_RADIUS);
    return new EmitterSphereShape(center, radius);
}
 
Example #9
Source File: CreateMeshVertexShapeEmitterAction.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected @NotNull EmitterShape createEmitterShape(@NotNull final VarTable vars) {
    final Geometry geometry = vars.get(PROPERTY_GEOMETRY);
    final List<Mesh> meshes = singletonList(geometry.getMesh());
    return createEmitterShape(meshes);
}
 
Example #10
Source File: AbstractCreateShapeEmitterAction.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Handle the result from the dialog.
 *
 * @param vars the table with variables.
 */
@FxThread
private void handleResult(@NotNull final VarTable vars) {

    final TreeNode<?> treeNode = getNode();
    final ParticleEmitter element = (ParticleEmitter) treeNode.getElement();
    final EmitterShape emitterShape = createEmitterShape(vars);

    final NodeTree<?> nodeTree = getNodeTree();
    final ChangeConsumer changeConsumer = notNull(nodeTree.getChangeConsumer());
    changeConsumer.execute(new ChangeEmitterShapeOperation(emitterShape, element));
}
 
Example #11
Source File: ParticleEmitterTreeNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
public @NotNull Array<TreeNode<?>> getChildren(@NotNull final NodeTree<?> nodeTree) {

    final ParticleEmitter element = getElement();
    final TreeNode<ParticleInfluencer> influencerTreeNode = FACTORY_REGISTRY.createFor(element.getParticleInfluencer());
    final TreeNode<EmitterShape> shapeTreeNode = FACTORY_REGISTRY.createFor(element.getShape());

    final Array<TreeNode<?>> children = ArrayFactory.newArray(TreeNode.class);
    if (influencerTreeNode != null) children.add(influencerTreeNode);
    if (shapeTreeNode != null) children.add(shapeTreeNode);
    children.addAll(super.getChildren(nodeTree));

    return children;
}
 
Example #12
Source File: CreateBoxShapeEmitterAction.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected @NotNull EmitterShape createEmitterShape(@NotNull final VarTable vars) {
    final Vector3f min = vars.get(PROPERTY_MIN);
    final Vector3f max = vars.get(PROPERTY_MAX);
    return new EmitterBoxShape(min, max);
}
 
Example #13
Source File: JmeParticleEmitter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected Sheet createSheet() {
    //TODO: multithreading..
    Sheet sheet = super.createSheet();
    Sheet.Set set = Sheet.createPropertiesSet();
    set.setDisplayName("ParticleEmitter");
    set.setName(ParticleEmitter.class.getName());
    ParticleEmitter obj = geom;//getLookup().lookup(Spatial.class);
    if (obj == null) {
        return sheet;
    }


    set.put(createButtonProperty());
    set.put(makeProperty(obj, boolean.class, "isEnabled", "setEnabled", "Enabled"));
    set.put(makeProperty(obj, ParticleMesh.Type.class, "getMeshType", "setMeshType", "Mesh Type"));
    set.put(makeProperty(obj, EmitterShape.class, "getShape", "setShape", "Emitter Shape"));
    set.put(makeProperty(obj, int.class, "getMaxNumParticles", "setNumParticles", "Num Particles"));
    set.put(makeProperty(obj, float.class, "getParticlesPerSec", "setParticlesPerSec", "Particles Per Sec"));
    set.put(makeProperty(obj, ColorRGBA.class, "getStartColor", "setStartColor", "Start Color"));
    set.put(makeProperty(obj, ColorRGBA.class, "getEndColor", "setEndColor", "End Color"));
    set.put(makeProperty(obj, float.class, "getStartSize", "setStartSize", "Start Size"));
    set.put(makeProperty(obj, float.class, "getEndSize", "setEndSize", "End Size"));
    set.put(makeProperty(obj, float.class, "getHighLife", "setHighLife", "High Life"));
    set.put(makeProperty(obj, float.class, "getLowLife", "setLowLife", "Low Life"));
    set.put(makeProperty(obj, Vector3f.class, "getGravity", "setGravity", "Gravity"));
    set.put(makeEmbedProperty(obj.getParticleInfluencer(), ParticleInfluencer.class, Vector3f.class, "getInitialVelocity", "setInitialVelocity", "Initial Velocity"));
    set.put(makeEmbedProperty(obj.getParticleInfluencer(), ParticleInfluencer.class, float.class, "getVelocityVariation", "setVelocityVariation", "Velocity Variation"));
    set.put(makeProperty(obj, Vector3f.class, "getFaceNormal", "setFaceNormal", "Face Normal"));
    set.put(makeProperty(obj, boolean.class, "isFacingVelocity", "setFacingVelocity", "Facing Velocity"));
    set.put(makeProperty(obj, boolean.class, "isRandomAngle", "setRandomAngle", "Random Angle"));
    set.put(makeProperty(obj, boolean.class, "isInWorldSpace", "setInWorldSpace", "World Space"));
    set.put(makeProperty(obj, float.class, "getRotateSpeed", "setRotateSpeed", "Rotate Speed"));
    set.put(makeProperty(obj, boolean.class, "isSelectRandomImage", "setSelectRandomImage", "Select Random Image"));
    set.put(makeProperty(obj, int.class, "getImagesX", "setImagesX", "Images X"));
    set.put(makeProperty(obj, int.class, "getImagesY", "setImagesY", "Images Y"));
    sheet.put(set);

    return sheet;

}
 
Example #14
Source File: ChangeEmitterShapeOperation.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
public ChangeEmitterShapeOperation(@NotNull final EmitterShape newShape, @NotNull final ParticleEmitter emitter) {
    this.prevShape = newShape;
    this.emitter = emitter;
}
 
Example #15
Source File: EmitterShapePropertyEditor.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setValue(Object value) {
    if (value instanceof EmitterShape) {
        emitter = (EmitterShape) value;
    }
}
 
Example #16
Source File: EmptyParticleInfluencer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void influenceParticle(Particle particle, EmitterShape emitterShape) {
}
 
Example #17
Source File: EmitterShapeTreeNode.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
public EmitterShapeTreeNode(@NotNull final EmitterShape element, final long objectId) {
    super(element, objectId);
}
 
Example #18
Source File: DefaultParticleInfluencer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void influenceParticle(Particle particle, EmitterShape emitterShape) {
    emitterShape.getRandomPoint(particle.position);
    this.applyVelocityVariation(particle);
}
 
Example #19
Source File: ParticleEmitter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public EmitterShape getShape() {
    return shape;
}
 
Example #20
Source File: ParticleEmitter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setShape(EmitterShape shape) {
    this.shape = shape;
}
 
Example #21
Source File: EmitterShapeTreeNode.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@Override
@FromAnyThread
public @NotNull String getName() {
    final EmitterShape element = getElement();
    return element.getClass().getSimpleName();
}
 
Example #22
Source File: MyParticleEmitter.java    From OpenRTS with MIT License 4 votes vote down vote up
@Override
public EmitterShape getShape() {
    return shape;
}
 
Example #23
Source File: MyParticleEmitter.java    From OpenRTS with MIT License 4 votes vote down vote up
@Override
public void setShape(EmitterShape shape) {
    this.shape = shape;
}
 
Example #24
Source File: EmptyParticleInfluencer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void influenceParticle(Particle particle, EmitterShape emitterShape) {
}
 
Example #25
Source File: DefaultParticleInfluencer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void influenceParticle(Particle particle, EmitterShape emitterShape) {
    emitterShape.getRandomPoint(particle.position);
    this.applyVelocityVariation(particle);
}
 
Example #26
Source File: ParticleEmitter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public EmitterShape getShape() {
    return shape;
}
 
Example #27
Source File: ParticleEmitter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setShape(EmitterShape shape) {
    this.shape = shape;
}
 
Example #28
Source File: CreatePointShapeEmitterAction.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@Override
@FxThread
protected @NotNull EmitterShape createEmitterShape(@NotNull final VarTable vars) {
    final Vector3f point = vars.get(PROPERTY_POINT);
    return new EmitterPointShape(point);
}
 
Example #29
Source File: ParticleInfluencer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * This method influences the particle.
 * @param particle
 *        particle to be influenced
 * @param emitterShape
 *        the shape of it emitter
 */
void influenceParticle(Particle particle, EmitterShape emitterShape);
 
Example #30
Source File: ParticleInfluencer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * This method influences the particle.
 * @param particle
 *        particle to be influenced
 * @param emitterShape
 *        the shape of it emitter
 */
void influenceParticle(Particle particle, EmitterShape emitterShape);