Skip to content

Commit

Permalink
Add copyright and javadoc, fix some merging issues
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed Aug 8, 2023
1 parent 3ebf29e commit edf7e05
Show file tree
Hide file tree
Showing 9 changed files with 396 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,45 @@
import com.jme3.texture.Image.Format;

/**
* SmartLightProbe
* A control that automatically handles environment bake and rebake including
* only tagged spatials.
*
* @author Riccardo Balbo
*/
public class EnvironmentProbeControl extends LightProbe implements Control {

private RenderManager renderManager;
private AssetManager assetManager;
private int envMapSize;
private Spatial spatial;
private boolean BAKE_NEEDED = true;


RenderManager renderManager;
AssetManager assetManager;
int envMapSize;
Spatial spatial;
boolean BAKE_NEEDED=true;
Function<Geometry,Boolean> filter=(s)->{
return s.getUserData("tags.env")!=null;
private Function<Geometry, Boolean> filter = (s) -> {
return s.getUserData("tags.env") != null;
};

public static void tag(Spatial s){
if(s instanceof Node){
Node n=(Node)s;
for(Spatial sx:n.getChildren()){
/**
* Tag spatial as part of the environment. Only tagged spatials will be
* rendered in the environment map.
*
* @param s
* the spatial
*/
public static void tag(Spatial s) {
if (s instanceof Node) {
Node n = (Node) s;
for (Spatial sx : n.getChildren()) {
tag(sx);
}
}else if(s instanceof Geometry){
} else if (s instanceof Geometry) {
s.setUserData("tags.env", true);
}
}

public EnvironmentProbeControl(RenderManager rm,AssetManager am, int size){
renderManager=rm;
assetManager=am;
envMapSize=size;
public EnvironmentProbeControl(RenderManager rm, AssetManager am, int size) {
renderManager = rm;
assetManager = am;
envMapSize = size;
}

@Override
Expand All @@ -55,9 +64,9 @@ public Control cloneForSpatial(Spatial spatial) {

@Override
public void setSpatial(Spatial spatial) {

spatial.addLight(this);
this.spatial=spatial;
this.spatial = spatial;

}

Expand All @@ -67,30 +76,28 @@ public void update(float tpf) {
}

@Override
public void render(RenderManager rm, ViewPort vp) {
if(BAKE_NEEDED){
BAKE_NEEDED=false;
public void render(RenderManager rm, ViewPort vp) {
if (BAKE_NEEDED) {
BAKE_NEEDED = false;
rebakeNow();
}
}

public void rebake(){
BAKE_NEEDED=true;
/**
* Schedule a rebake of the environment map.
*/
public void rebake() {
BAKE_NEEDED = true;
}

void rebakeNow() {
System.out.println("BAKE");

IBLGLEnvBakerLight baker = new IBLGLEnvBakerLight(renderManager, assetManager, Format.RGB16F, Format.Depth,
envMapSize, envMapSize);


baker.bakeEnvironment(spatial, Vector3f.ZERO, 0.001f, 1000f,filter);
IBLGLEnvBakerLight baker = new IBLGLEnvBakerLight(renderManager, assetManager, Format.RGB16F, Format.Depth, envMapSize, envMapSize);

baker.bakeEnvironment(spatial, Vector3f.ZERO, 0.001f, 1000f, filter);
baker.bakeSpecularIBL();
baker.bakeSphericalHarmonicsCoefficients();


// probe.setPosition(Vector3f.ZERO);
setPrefilteredMap(baker.getSpecularIBL());
setNbMipMaps(getPrefilteredEnvMap().getImage().getMipMapSizes().length);
setShCoeffs(baker.getSphericalHarmonicsCoefficients());
Expand All @@ -100,5 +107,5 @@ void rebakeNow() {
baker.clean();

}

}
31 changes: 18 additions & 13 deletions jme3-core/src/main/java/com/jme3/environment/LightProbeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,36 @@
/**
* Creates LightProbes within a scene, given an EnvironmentCamera.
*
* Since this process can take a long time, you can provide a JobProgressListener that
* will be notified of the ongoing generation process when calling the makeProbe method.
* Since this process can take a long time, you can provide a
* JobProgressListener that will be notified of the ongoing generation process
* when calling the makeProbe method.
*
* The process is as follows:
* 1. Create an EnvironmentCamera
* 2. give it a position in the scene
* 3. call {@link LightProbeFactory#makeProbe(com.jme3.environment.EnvironmentCamera, com.jme3.scene.Spatial)}
* 4. add the created LightProbe to a node with the {@link Node#addLight(com.jme3.light.Light) } method.
* The process is as follows: 1. Create an EnvironmentCamera 2. give it a
* position in the scene 3. call
* {@link LightProbeFactory#makeProbe(com.jme3.environment.EnvironmentCamera, com.jme3.scene.Spatial)}
* 4. add the created LightProbe to a node with the
* {@link Node#addLight(com.jme3.light.Light) } method.
*
* Optionally for step 3 call
* {@link #makeProbe(com.jme3.environment.EnvironmentCamera, com.jme3.scene.Spatial, com.jme3.environment.generation.JobProgressListener)}
* with a {@link JobProgressListener} to be notified of the progress of the generation process.
* with a {@link JobProgressListener} to be notified of the progress of the
* generation process.
*
* The generation will be split in several threads for faster generation.
* The generation will be split in several threads for faster generation.
*
* This class is entirely thread safe and can be called from any thread.
* This class is entirely thread safe and can be called from any thread.
*
* Note that in case you are using a {@link JobProgressListener}, all its
* methods will be called inside an app.enqueue callable.
* This means that it's completely safe to modify the scenegraph within the
* Listener method, but also means that the event will be delayed until next update loop.
* methods will be called inside an app.enqueue callable. This means that it's
* completely safe to modify the scenegraph within the Listener method, but also
* means that the event will be delayed until next update loop.
*
* @deprecated Use LightProbeFactory2 or EnvironmentProbeControl whenever possible.
* @see EnvironmentCamera
* @author bouquet
*/

@Deprecated
public class LightProbeFactory {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,24 @@
import com.jme3.scene.Spatial;
import com.jme3.texture.Image.Format;


/**
* A faster version of LightProbeFactory that uses accelerated Baking.
* @author Riccardo Balbo
*/
public class LightProbeFactory2 {


/**
* Creates a LightProbe with the giver EnvironmentCamera in the given scene.
* @param rm The RenderManager
* @param am The AssetManager
* @param size The size of the probe
* @param pos The position of the probe
* @param frustumNear The near frustum of the probe
* @param frustumFar The far frustum of the probe
* @param scene The scene to bake
* @return The baked LightProbe
*/
public static LightProbe makeProbe(RenderManager rm,
AssetManager am, int size,Vector3f pos, float frustumNear,float frustumFar,Spatial scene) {
IBLGLEnvBakerLight baker=new IBLGLEnvBakerLight(rm,
Expand Down
23 changes: 21 additions & 2 deletions jme3-core/src/main/java/com/jme3/environment/baker/EnvBaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,31 @@
import com.jme3.texture.TextureCubeMap;

/**
* And environment baker. It bakes the environment. ( ͡° ͜ʖ ͡°)
* And environment baker. It bakes the environment.
*
* @author Riccardo Balbo
*/
public interface EnvBaker {
public void bakeEnvironment(Spatial scene, Vector3f position, float frustumNear, float frustumFar,Function<Geometry,Boolean> filter);
/**
* Bake the environment
* @param scene The scene to bake
* @param position The position of the camera
* @param frustumNear The near frustum
* @param frustumFar The far frustum
* @param filter A filter to select which geometries to bake
*/
public void bakeEnvironment(Spatial scene, Vector3f position, float frustumNear, float frustumFar, Function<Geometry, Boolean> filter);

/**
* Get the environment map
* @return The environment map
*/
public TextureCubeMap getEnvMap();

/**
* Clean the environment baker
* This method should be called when the baker is no longer needed
* It will clean up all the resources
*/
public void clean();
}
Loading

0 comments on commit edf7e05

Please sign in to comment.