com.jme3.light.Light Java Examples

The following examples show how to use com.jme3.light.Light. 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: LightControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void spatialToLight(Light light) {

        final Vector3f worldTranslation = spatial.getWorldTranslation();

        if (light instanceof PointLight) {
            ((PointLight) light).setPosition(worldTranslation);
            return;
        }

        final TempVars vars = TempVars.get();
        final Vector3f vec = vars.vect1;

        if (light instanceof DirectionalLight) {
            ((DirectionalLight) light).setDirection(vec.set(worldTranslation).multLocal(-1.0f));
        }

        if (light instanceof SpotLight) {
            final SpotLight spotLight = (SpotLight) light;
            spotLight.setPosition(worldTranslation);
            spotLight.setDirection(spatial.getWorldRotation().multLocal(vec.set(Vector3f.UNIT_Y).multLocal(-1)));
        }

        vars.release();
    }
 
Example #2
Source File: RemoveLightAction.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected void process() {
    super.process();

    final TreeNode<?> node = getNode();
    final Object element = node.getElement();

    if (!(element instanceof Light)) return;

    final Light light = (Light) element;

    final NodeTree<ModelChangeConsumer> nodeTree = getNodeTree();
    final TreeNode<?> parentNode = nodeTree.findParent(node);
    if (parentNode == null) return;

    final Object parent = parentNode.getElement();
    if (!(parent instanceof Node)) return;

    final ModelChangeConsumer changeConsumer = notNull(nodeTree.getChangeConsumer());
    changeConsumer.execute(new RemoveLightOperation(light, (Node) parent));
}
 
Example #3
Source File: SceneComposerToolController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void addMarkers(Node parent) {
    
    for (Light light : parent.getLocalLightList())
        addLightMarker(light);
    
    if (parent instanceof AudioNode) {
        addAudioMarker((AudioNode)parent);
    }
    
    for (Spatial s : parent.getChildren()) {
        if (s instanceof Node)
            addMarkers((Node)s);
        else {
            //TODO later if we include other types of non-spatial markers
        }
    }
}
 
Example #4
Source File: AbstractCreateLightAction.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected void process() {
    super.process();

    final NodeTree<?> nodeTree = getNodeTree();

    final Light light = createLight();
    if (light.getName() == null) {
        light.setName("");
    }

    final TreeNode<?> treeNode = getNode();
    final Node element = (Node) treeNode.getElement();

    final ChangeConsumer changeConsumer = notNull(nodeTree.getChangeConsumer());
    changeConsumer.execute(new AddLightOperation(light, element));
}
 
Example #5
Source File: AbstractSceneFileEditor.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
public void notifyFxAddedChild(@NotNull final Object parent, @NotNull final Object added, final int index,
                               final boolean needSelect) {

    final MA editor3DPart = getEditor3DPart();
    final ModelNodeTree modelNodeTree = getModelNodeTree();
    modelNodeTree.notifyAdded(parent, added, index);

    if (added instanceof Light) {
        editor3DPart.addLight((Light) added);
    } else if (added instanceof AudioNode) {
        editor3DPart.addAudioNode((AudioNode) added);
    } else if (added instanceof Spatial) {
        handleAddedObject((Spatial) added);
    }

    if (needSelect) {
        EXECUTOR_MANAGER.addJmeTask(() -> EXECUTOR_MANAGER.addFxTask(() -> modelNodeTree.selectSingle(added)));
    }
}
 
Example #6
Source File: AbstractSceneFileEditor.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
public void notifyFxRemovedChild(@NotNull final Object parent, @NotNull final Object removed) {

    final MA editor3DPart = getEditor3DPart();
    final ModelNodeTree modelNodeTree = getModelNodeTree();
    modelNodeTree.notifyRemoved(parent, removed);

    if (removed instanceof Light) {
        editor3DPart.removeLight((Light) removed);
    } else if (removed instanceof AudioNode) {
        editor3DPart.removeAudioNode((AudioNode) removed);
    } else if (removed instanceof Spatial) {
        handleRemovedObject((Spatial) removed);
    }
}
 
Example #7
Source File: NodeUtils.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Collect all lights.
 *
 * @param spatial   the spatial.
 * @param container the container.
 */
@FromAnyThread
public static void addLight(@NotNull Spatial spatial, @NotNull Array<Light> container) {

    var lightList = spatial.getLocalLightList();
    lightList.forEach(container::add);

    if (!(spatial instanceof Node)) {
        return;
    }

    var node = (Node) spatial;

    for (var children : node.getChildren()) {
        addLight(children, container);
    }
}
 
Example #8
Source File: LightPropertyBuilder.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 DirectionalLight) {
        buildForDirectionLight((DirectionalLight) object, container, changeConsumer);
    } else if (object instanceof SpotLight) {
        buildForSpotLight((SpotLight) object, container, changeConsumer);
    } else if (object instanceof PointLight) {
        buildForPointLight((PointLight) object, container, changeConsumer);
    }

    if (object instanceof Light) {
        buildForLight((Light) object, container, changeConsumer);
    }
}
 
Example #9
Source File: AbstractSceneEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * The process of removing a light.
 */
@JmeThread
private void removeLightImpl(@NotNull final Light light) {

    final Node node = LIGHT_MODEL_TABLE.get(light.getType());
    if (node == null) {
        return;
    }

    final ObjectDictionary<Light, EditorLightNode> cachedLights = getCachedLights();
    final EditorLightNode lightModel = cachedLights.get(light);
    if (lightModel == null) {
        return;
    }

    lightModel.setLight(null);

    final Node lightNode = getLightNode();
    lightNode.detachChild(lightModel);
    lightNode.detachChild(notNull(lightModel.getModel()));

    getLightNodes().fastRemove(lightModel);
}
 
Example #10
Source File: JmeMesh.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected Sheet createSheet() {
    //TODO: multithreading..
    Sheet sheet = Sheet.createDefault();
    Sheet.Set set = Sheet.createPropertiesSet();
    set.setDisplayName("Mesh");
    set.setName(Light.class.getName());
    Mesh obj = mesh;
    if (obj == null) {
        return sheet;
    }

    set.put(makeProperty(obj, int.class, "getId", "setId", "Id"));
    set.put(makeProperty(obj, Mesh.Mode.class, "getMode", "setMode", "Mode"));
    set.put(makeProperty(obj, float.class, "getPointSize", "setPointSize", "Point Size"));

    sheet.put(set);
    return sheet;

}
 
Example #11
Source File: LightControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void spatialTolight(Light light) {
    if (light instanceof PointLight) {
        ((PointLight) light).setPosition(spatial.getWorldTranslation());
    }
    TempVars vars = TempVars.get();

    if (light instanceof DirectionalLight) {
        ((DirectionalLight) light).setDirection(vars.vect1.set(spatial.getWorldTranslation()).multLocal(-1.0f));
    }

    if (light instanceof SpotLight) {
        ((SpotLight) light).setPosition(spatial.getWorldTranslation());            
        ((SpotLight) light).setDirection(spatial.getWorldRotation().multLocal(vars.vect1.set(Vector3f.UNIT_Y).multLocal(-1)));
    }
    vars.release();

}
 
Example #12
Source File: JmeLight.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected Sheet createSheet() {
    //TODO: multithreading..
    Sheet sheet = Sheet.createDefault();
    Sheet.Set set = Sheet.createPropertiesSet();
    set.setDisplayName("Light");
    set.setName(Light.class.getName());
    Light obj = light;
    if (obj == null) {
        return sheet;
    }

    set.put(makeProperty(obj, ColorRGBA.class, "getColor", "setColor", "Color"));


    sheet.put(set);
    return sheet;

}
 
Example #13
Source File: ShadowCamera.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Updates the camera view direction and position based on the light
 */
public void updateLightCamera(Camera lightCam) {
    if (target.getType() == Light.Type.Directional) {
        DirectionalLight dl = (DirectionalLight) target;
        lightCam.setParallelProjection(true);
        lightCam.setLocation(Vector3f.ZERO);
        lightCam.lookAtDirection(dl.getDirection(), Vector3f.UNIT_Y);
        lightCam.setFrustum(-1, 1, -1, 1, 1, -1);
    } else {
        PointLight pl = (PointLight) target;
        lightCam.setParallelProjection(false);
        lightCam.setLocation(pl.getPosition());
        // direction will have to be calculated automatically
        lightCam.setFrustumPerspective(45, 1, 1, 300);
    }
}
 
Example #14
Source File: RemoveElementsOperation.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@JmeThread
protected void undoImpl(@NotNull final ModelChangeConsumer editor) {
    EXECUTOR_MANAGER.addJmeTask(() -> {

        for (final Element element : elements) {

            final Object toRestore = element.getElement();

            if (toRestore instanceof Spatial) {
                restoreSpatial(element, (Spatial) toRestore);
            } else if (toRestore instanceof Light) {
                restoreLight(element, (Light) toRestore);
            } else if (toRestore instanceof Animation) {
                restoreAnimation(element, (Animation) toRestore);
            } else if (toRestore instanceof Control) {
                restoreControl(element, (Control) toRestore);
            }
        }

        EXECUTOR_MANAGER.addFxTask(() -> {
            elements.forEach(editor, (element, consumer) ->
                    consumer.notifyFxAddedChild(element.getParent(), element.getElement(), element.getIndex(), false));
        });
    });
}
 
Example #15
Source File: RemoveElementsOperation.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@JmeThread
protected void redoImpl(@NotNull final ModelChangeConsumer editor) {
    EXECUTOR_MANAGER.addJmeTask(() -> {

        for (final Element element : elements) {

            final Object toRemove = element.getElement();

            if (toRemove instanceof Spatial) {
                removeSpatial(element, (Spatial) toRemove);
            } else if (toRemove instanceof Light) {
                removeLight(element, (Light) toRemove);
            } else if (toRemove instanceof Animation) {
                removeAnimation(element, (Animation) toRemove);
            } else if (toRemove instanceof Control) {
                removeControl(element, (Control) toRemove);
            }
        }

        EXECUTOR_MANAGER.addFxTask(() -> {
            elements.forEach(editor, (element, consumer) ->
                    consumer.notifyFxRemovedChild(element.getParent(), element.getElement()));
        });
    });
}
 
Example #16
Source File: CreateAmbientLightAction.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected @NotNull Light createLight() {
    final AmbientLight ambientLight = new AmbientLight();
    ambientLight.setName(Messages.MODEL_NODE_TREE_ACTION_AMBIENT_LIGHT);
    return ambientLight;
}
 
Example #17
Source File: Material.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ColorRGBA getAmbientColor(LightList lightList) {
    ambientLightColor.set(0, 0, 0, 1);
    for (int j = 0; j < lightList.size(); j++) {
        Light l = lightList.get(j);
        if (l instanceof AmbientLight) {
            ambientLightColor.addLocal(l.getColor());
        }
    }
    ambientLightColor.a = 1.0f;
    return ambientLightColor;
}
 
Example #18
Source File: AbstractSceneEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * The process of adding a light.
 */
@JmeThread
private void addLightImpl(@NotNull final Light light) {

    final Node node = LIGHT_MODEL_TABLE.get(light.getType());
    if (node == null) return;

    final ObjectDictionary<Light, EditorLightNode> cachedLights = getCachedLights();

    final Camera camera = EditorUtil.getGlobalCamera();
    final EditorLightNode lightModel = notNull(cachedLights.get(light, () -> {

        final Node model = (Node) node.clone();
        model.setLocalScale(0.03F);

        final EditorLightNode result = new EditorLightNode(camera);
        result.setModel(model);

        final Geometry geometry = NodeUtils.findGeometry(model, "White");

        if (geometry == null) {
            LOGGER.warning(this, "not found geometry for the node " + geometry);
            return null;
        }

        final Material material = geometry.getMaterial();
        material.setColor("Color", light.getColor());

        return result;
    }));

    lightModel.setLight(light);
    lightModel.sync();

    final Node lightNode = getLightNode();
    lightNode.attachChild(lightModel);
    lightNode.attachChild(lightModel.getModel());

    getLightNodes().add(lightModel);
}
 
Example #19
Source File: NewLightPopup.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void addLightUndo(final Spatial undoParent, final Light undoLight) {
    //add undo
    if (undoParent != null && undoLight != null) {
        Lookup.getDefault().lookup(SceneUndoRedoManager.class).addEdit(this, new AbstractUndoableSceneEdit() {

            @Override
            public void sceneUndo() throws CannotUndoException {
                undoParent.removeLight(undoLight);
            }

            @Override
            public void sceneRedo() throws CannotRedoException {
                undoParent.addLight(undoLight);
            }

            @Override
            public void awtRedo() {
                dataObject.setModified(true);
                jmeNode.refresh(true);
            }

            @Override
            public void awtUndo() {
                dataObject.setModified(true);
                jmeNode.refresh(true);
            }
        });
    }
}
 
Example #20
Source File: LightPropertyBuilder.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@FxThread
private void buildForLight(@NotNull final Light object, @NotNull final VBox container,
                           @NotNull final ModelChangeConsumer changeConsumer) {

    final ColorRGBA color = object.getColor();

    final ColorPropertyControl<ModelChangeConsumer, Light> radiusControl =
            new ColorPropertyControl<>(color, Messages.MODEL_PROPERTY_COLOR, changeConsumer);
    radiusControl.setApplyHandler(Light::setColor);
    radiusControl.setSyncHandler(Light::getColor);
    radiusControl.setEditObject(object);

    FXUtils.addToPane(radiusControl, container);
}
 
Example #21
Source File: JmeVehicleWheel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected Sheet createSheet() {
    //TODO: multithreading..
    Sheet sheet = Sheet.createDefault();
    Sheet.Set set = Sheet.createPropertiesSet();
    set.setDisplayName("VehicleWheel");
    set.setName(Light.class.getName());
    VehicleWheel obj = wheel;
    if (obj == null) {
        return sheet;
    }

    set.put(makeProperty(obj, Vector3f.class, "getLocation", "Location"));
    set.put(makeProperty(obj, Vector3f.class, "getAxle", "Axis"));
    set.put(makeProperty(obj, Vector3f.class, "getDirection", "Direction"));
    set.put(makeProperty(obj, boolean.class, "isFrontWheel", "setFrontWheel", "Front Wheel"));
    set.put(makeProperty(obj, float.class, "getFrictionSlip", "setFrictionSlip", "Friction Slip"));
    set.put(makeProperty(obj, float.class, "getMaxSuspensionForce", "setMaxSuspensionForce", "Max Suspension Force"));
    set.put(makeProperty(obj, float.class, "getMaxSuspensionTravelCm", "setMaxSuspensionTravelCm", "Max Suspension Travel"));
    set.put(makeProperty(obj, float.class, "getRadius", "setRadius", "Radius"));
    set.put(makeProperty(obj, float.class, "getRestLength", "setRestLength", "Rest Length"));
    set.put(makeProperty(obj, float.class, "getRollInfluence", "setRollInfluence", "Roll Influence"));
    set.put(makeProperty(obj, float.class, "getSuspensionStiffness", "setSuspensionStiffness", "Suspension Stiffness"));
    set.put(makeProperty(obj, float.class, "getWheelsDampingCompression", "setWheelsDampingCompression", "Damping Compression"));
    set.put(makeProperty(obj, float.class, "getWheelsDampingRelaxation", "setWheelsDampingRelaxation", "Damping Relaxation"));

    sheet.put(set);
    return sheet;

}
 
Example #22
Source File: SceneComposerToolController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected LightMarker(Light light) {
    this.light = light;
    Quad q = new Quad(0.5f, 0.5f);
    this.setMesh(q);
    this.setMaterial(getLightMarkerMaterial());
    this.addControl(new LightMarkerControl());
    this.setQueueBucket(Bucket.Transparent);
}
 
Example #23
Source File: AbstractSceneFileEditor.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a added model.
 *
 * @param model the model
 */
@FxThread
protected void handleAddedObject(@NotNull final Spatial model) {

    final MA editor3DPart = getEditor3DPart();
    final Array<Light> lights = ArrayFactory.newArray(Light.class);
    final Array<AudioNode> audioNodes = ArrayFactory.newArray(AudioNode.class);

    NodeUtils.addLight(model, lights);
    NodeUtils.addAudioNodes(model, audioNodes);

    lights.forEach(editor3DPart, (light, part) -> part.addLight(light));
    audioNodes.forEach(editor3DPart, (audioNode, part) -> part.addAudioNode(audioNode));
}
 
Example #24
Source File: AbstractSceneFileEditor.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a removed model.T
 *
 * @param model the model
 */
@FxThread
protected void handleRemovedObject(@NotNull final Spatial model) {

    final MA editor3DPart = getEditor3DPart();
    final Array<Light> lights = ArrayFactory.newArray(Light.class);
    final Array<AudioNode> audioNodes = ArrayFactory.newArray(AudioNode.class);

    NodeUtils.addLight(model, lights);
    NodeUtils.addAudioNodes(model, audioNodes);

    lights.forEach(editor3DPart, (light, part) -> part.removeLight(light));
    audioNodes.forEach(editor3DPart, (audioNode, part) -> part.removeAudioNode(audioNode));
}
 
Example #25
Source File: LightControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);
    controlDir = ic.readEnum(CONTROL_DIR_NAME, ControlDirection.class, ControlDirection.SpatialToLight);
    light = (Light) ic.readSavable(LIGHT_NAME, null);
}
 
Example #26
Source File: StaticPassLightingLogic.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Shader makeCurrent(AssetManager assetManager, RenderManager renderManager,
        EnumSet<Caps> rendererCaps, LightList lights, DefineList defines) {

    // TODO: if it ever changes that render isn't called
    // right away with the same geometry after makeCurrent, it would be
    // a problem.
    // Do a radix sort.
    tempDirLights.clear();
    tempPointLights.clear();
    tempSpotLights.clear();
    for (Light light : lights) {
        switch (light.getType()) {
            case Directional:
                tempDirLights.add((DirectionalLight) light);
                break;
            case Point:
                tempPointLights.add((PointLight) light);
                break;
            case Spot:
                tempSpotLights.add((SpotLight) light);
                break;
        }
    }

    defines.set(numDirLightsDefineId, tempDirLights.size());
    defines.set(numPointLightsDefineId, tempPointLights.size());
    defines.set(numSpotLightsDefineId, tempSpotLights.size());

    return techniqueDef.getShader(assetManager, rendererCaps, defines);
}
 
Example #27
Source File: SceneComposerToolController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Adds a marker for the light to the scene if it does not exist yet
 */
public void addLightMarker(Light light) {
    if (!(light instanceof PointLight) && !(light instanceof SpotLight))
        return; // only handle point and spot lights
    
    Spatial s = nonSpatialMarkersNode.getChild(light.getName());
    if (s != null) {
        // update location maybe? Remove old and replace with new?
        return;
    }
    
    LightMarker lm = new LightMarker(light);
    nonSpatialMarkersNode.attachChild(lm);
}
 
Example #28
Source File: LightControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);
    controlDir = ic.readEnum(CONTROL_DIR_NAME, ControlDirection.class, ControlDirection.SpatialToLight);
    light = (Light)ic.readSavable(LIGHT_NAME, null);
}
 
Example #29
Source File: WaterFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private DirectionalLight findLight(Node node) {
    for (Light light : node.getWorldLightList()) {
        if (light instanceof DirectionalLight) {
            return (DirectionalLight) light;
        }
    }
    for (Spatial child : node.getChildren()) {
        if (child instanceof Node) {
            return findLight((Node) child);
        }
    }

    return null;
}
 
Example #30
Source File: WaterFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private DirectionalLight findLight(Node node) {
    for (Light light : node.getWorldLightList()) {
        if (light instanceof DirectionalLight) {
            return (DirectionalLight) light;
        }
    }
    for (Spatial child : node.getChildren()) {
        if (child instanceof Node) {
            return findLight((Node) child);
        }
    }

    return null;
}