LightProbe maps can now be re rendered in the engine and in the SDK

define_list_fix
Nehon 9 years ago
parent 20ec2f0797
commit e438ad0928
  1. 45
      jme3-core/src/main/java/com/jme3/environment/LightProbeFactory.java
  2. 6
      sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeLight.java
  3. 44
      sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeLightProbe.java
  4. 99
      sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeLightProbeButtonProperty.java
  5. 42
      sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeLightProbeProgressHandler.java
  6. 29
      sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/NewLightPopup.java

@ -127,6 +127,51 @@ public class LightProbeFactory {
return probe; return probe;
} }
/**
* Updates a LightProbe with the giver EnvironmentCamera in the given scene.
*
* Note that this is an assynchronous process that will run on multiple threads.
* The process is thread safe.
* The created lightProbe will only be marked as ready when the rendering process is done.
*
* The JobProgressListener will be notified of the progress of the generation.
* Note that you can also use a {@link JobProgressAdapter}.
*
* @see LightProbe
* @see EnvironmentCamera
* @see JobProgressListener
*
* @param probe the Light probe to update
* @param envCam the EnvironmentCamera
* @param scene the Scene
* @param listener the listener of the genration progress.
* @return the created LightProbe
*/
public static LightProbe updateProbe(final LightProbe probe, final EnvironmentCamera envCam, Spatial scene, final JobProgressListener<LightProbe> listener) {
envCam.setPosition(probe.getPosition());
probe.setReady(false);
if(probe.getIrradianceMap() == null) {
probe.getIrradianceMap().getImage().dispose();
probe.getPrefilteredEnvMap().getImage().dispose();
}
probe.setIrradianceMap(EnvMapUtils.createIrradianceMap(envCam.getSize(), envCam.getImageFormat()));
probe.setPrefilteredMap(EnvMapUtils.createPrefilteredEnvMap(envCam.getSize(), envCam.getImageFormat()));
envCam.snapshot(scene, new JobProgressAdapter<TextureCubeMap>() {
@Override
public void done(TextureCubeMap map) {
generatePbrMaps(map, probe, envCam.getApplication(), listener);
}
});
return probe;
}
/** /**
* Internally called to generate the maps. * Internally called to generate the maps.
* This method will spawn 7 thread (one for the IrradianceMap, and one for each face of the prefiltered env map). * This method will spawn 7 thread (one for the IrradianceMap, and one for each face of the prefiltered env map).

@ -150,6 +150,12 @@ public class JmeLight extends AbstractSceneExplorerNode {
} }
} }
public Spatial getSpatial() {
return spatial;
}
public Class getExplorerObjectClass() { public Class getExplorerObjectClass() {
return Light.class; return Light.class;
} }

@ -34,7 +34,11 @@ package com.jme3.gde.core.sceneexplorer.nodes;
import com.jme3.light.LightProbe; import com.jme3.light.LightProbe;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import java.beans.PropertyEditor;
import java.lang.reflect.InvocationTargetException;
import org.openide.nodes.PropertySupport;
import org.openide.nodes.Sheet; import org.openide.nodes.Sheet;
/** /**
@ -70,12 +74,16 @@ public class JmeLightProbe extends JmeLight{
set.put(makeProperty(obj, Vector3f.class, "getPosition", "setPosition", "Position")); set.put(makeProperty(obj, Vector3f.class, "getPosition", "setPosition", "Position"));
set.put(makeEmbedProperty(obj.getBounds(), obj.getBounds().getClass(), float.class, "getRadius", "setRadius", "Radius")); set.put(makeEmbedProperty(obj.getBounds(), obj.getBounds().getClass(), float.class, "getRadius", "setRadius", "Radius"));
set.put(createButtonProperty());
sheet.put(set); sheet.put(set);
return sheet; return sheet;
} }
public LightProbe getLightProbe() {
return lightProbe;
}
@Override @Override
public Class getExplorerObjectClass() { public Class getExplorerObjectClass() {
return LightProbe.class; return LightProbe.class;
@ -86,4 +94,38 @@ public class JmeLightProbe extends JmeLight{
return JmeLightProbe.class; return JmeLightProbe.class;
} }
protected void setModified(){
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
fireSave(true);
}
});
}
private Property createButtonProperty() {
return new PropertySupport.ReadWrite<Object>("update", Object.class, "Refresh maps", "Click here to refresh environment maps ") {
JmeLightProbeButtonProperty pe;
@Override
public Object getValue() throws IllegalAccessException, InvocationTargetException {
return "";
}
@Override
public PropertyEditor getPropertyEditor() {
if (pe == null) {
pe = new JmeLightProbeButtonProperty(JmeLightProbe.this, (Node)getSpatial());
pe.attachEnv(pe.env);
}
return pe;
}
@Override
public void setValue(Object t) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
}
};
}
} }

@ -0,0 +1,99 @@
package com.jme3.gde.core.sceneexplorer.nodes;
import com.jme3.environment.EnvironmentCamera;
import com.jme3.environment.LightProbeFactory;
import com.jme3.environment.generation.JobProgressAdapter;
import com.jme3.gde.core.scene.SceneApplication;
import com.jme3.gde.core.scene.controller.SceneToolController;
import com.jme3.gde.core.util.ButtonInplaceEditor;
import com.jme3.light.LightProbe;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyEditorSupport;
import java.util.concurrent.Callable;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.ProgressHandleFactory;
import org.openide.explorer.propertysheet.ExPropertyEditor;
import org.openide.explorer.propertysheet.InplaceEditor;
import org.openide.explorer.propertysheet.PropertyEnv;
/**
*
* @author Nehon
*/
public class JmeLightProbeButtonProperty extends PropertyEditorSupport implements ExPropertyEditor, InplaceEditor.Factory {
JmeLightProbe probe;
Node node;
public JmeLightProbeButtonProperty(JmeLightProbe pe, Node node) {
super();
this.node = node;
this.probe = pe;
}
PropertyEnv env;
@Override
public void attachEnv(PropertyEnv env) {
this.env = env;
env.registerInplaceEditorFactory(this);
}
private ButtonInplaceEditor ed = null;
@Override
public InplaceEditor getInplaceEditor() {
if (ed == null) {
ed = new ButtonInplaceEditor("Refresh");
ed.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SceneApplication.getApplication().enqueue(new Callable<Object>() {
@Override
public Object call() throws Exception {
EnvironmentCamera envCam = SceneApplication.getApplication().getStateManager().getState(EnvironmentCamera.class);
SceneToolController toolController = SceneApplication.getApplication().getStateManager().getState(SceneToolController.class);
if (toolController != null) {
envCam.setPosition(toolController.getCursorLocation());
} else {
envCam.setPosition(new Vector3f(0, 0, 0));
}
LightProbeFactory.updateProbe(probe.getLightProbe(), envCam, node, new JmeLightProbeProgressHandler());
probe.setModified();
return null;
}
});
}
});
}
return ed;
}
@Override
public boolean isPaintable() {
return true;
}
@Override
public void paintValue(Graphics gfx, Rectangle box) {
if (ed == null) {
getInplaceEditor();
}
ed.setSize(box.width, box.height);
ed.doLayout();
Graphics g = gfx.create(box.x, box.y, box.width, box.height);
ed.setOpaque(false);
ed.paint(g);
g.dispose();
probe.refresh(false);
}
}

@ -0,0 +1,42 @@
package com.jme3.gde.core.sceneexplorer.nodes;
import com.jme3.environment.generation.JobProgressAdapter;
import com.jme3.light.LightProbe;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.ProgressHandleFactory;
/**
*
* @author Nehon
*/
public class JmeLightProbeProgressHandler extends JobProgressAdapter<LightProbe> {
int lastProgress;
ProgressHandle handle = ProgressHandleFactory.createHandle("Generating environment maps");
@Override
public void start() {
handle.start(100);
}
@Override
public void progress(double value) {
lastProgress = (int) (value * 100);
handle.progress(lastProgress);
}
@Override
public void step(String message) {
handle.progress(message, lastProgress);
}
@Override
public void done(LightProbe t) {
handle.finish();
}
}

@ -37,6 +37,7 @@ import com.jme3.environment.LightProbeFactory;
import com.jme3.environment.generation.JobProgressAdapter; import com.jme3.environment.generation.JobProgressAdapter;
import com.jme3.gde.core.scene.SceneApplication; import com.jme3.gde.core.scene.SceneApplication;
import com.jme3.gde.core.scene.controller.SceneToolController; import com.jme3.gde.core.scene.controller.SceneToolController;
import com.jme3.gde.core.sceneexplorer.nodes.JmeLightProbeProgressHandler;
import com.jme3.gde.core.sceneexplorer.nodes.JmeSpatial; import com.jme3.gde.core.sceneexplorer.nodes.JmeSpatial;
import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit; import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit;
import com.jme3.gde.core.undoredo.SceneUndoRedoManager; import com.jme3.gde.core.undoredo.SceneUndoRedoManager;
@ -197,33 +198,7 @@ public class NewLightPopup extends AbstractAction implements Presenter.Popup {
} else { } else {
envCam.setPosition(new Vector3f(0, 0, 0)); envCam.setPosition(new Vector3f(0, 0, 0));
} }
LightProbe lightProbe = LightProbeFactory.makeProbe(envCam, node, new JobProgressAdapter<LightProbe>() { LightProbe lightProbe = LightProbeFactory.makeProbe(envCam, node, new JmeLightProbeProgressHandler());
int lastProgress;
ProgressHandle handle = ProgressHandleFactory.createHandle("Generating environment maps");
@Override
public void start() {
handle.start(100);
}
@Override
public void progress(double value) {
lastProgress = (int)(value * 100);
handle.progress(lastProgress);
}
@Override
public void step(String message) {
handle.progress(message,lastProgress);
}
@Override
public void done(LightProbe t) {
handle.finish();
}
});
node.addLight(lightProbe); node.addLight(lightProbe);
((BoundingSphere)lightProbe.getBounds()).setRadius(10); ((BoundingSphere)lightProbe.getBounds()).setRadius(10);
addLightUndo(node, lightProbe); addLightUndo(node, lightProbe);

Loading…
Cancel
Save