parent
ab981b76fc
commit
866bf8d694
@ -0,0 +1,57 @@ |
|||||||
|
/* |
||||||
|
* To change this license header, choose License Headers in Project Properties. |
||||||
|
* To change this template file, choose Tools | Templates |
||||||
|
* and open the template in the editor. |
||||||
|
*/ |
||||||
|
package com.jme3.gde.scenecomposer.gizmo.light; |
||||||
|
|
||||||
|
import com.jme3.light.Light; |
||||||
|
import com.jme3.math.Vector3f; |
||||||
|
import com.jme3.scene.control.BillboardControl; |
||||||
|
import java.lang.reflect.InvocationTargetException; |
||||||
|
import java.lang.reflect.Method; |
||||||
|
import org.openide.util.Exceptions; |
||||||
|
|
||||||
|
/** |
||||||
|
* Updates the marker's position whenever the light has moved. It is also a |
||||||
|
* BillboardControl, so this marker always faces the camera |
||||||
|
*/ |
||||||
|
public class LightGizmoControl extends BillboardControl { |
||||||
|
|
||||||
|
private final Vector3f lastPos = new Vector3f(); |
||||||
|
private Vector3f lightPos; |
||||||
|
|
||||||
|
LightGizmoControl(Light light) { |
||||||
|
super(); |
||||||
|
|
||||||
|
try { |
||||||
|
Method getPosition = light.getClass().getMethod("getPosition"); |
||||||
|
lightPos = (Vector3f) getPosition.invoke(light); |
||||||
|
} catch (NoSuchMethodException ex) { |
||||||
|
//light type doesn't have a get position method, silancing the exception
|
||||||
|
} catch (SecurityException ex) { |
||||||
|
Exceptions.printStackTrace(ex); |
||||||
|
} catch (IllegalAccessException ex) { |
||||||
|
Exceptions.printStackTrace(ex); |
||||||
|
} catch (IllegalArgumentException ex) { |
||||||
|
Exceptions.printStackTrace(ex); |
||||||
|
} catch (InvocationTargetException ex) { |
||||||
|
Exceptions.printStackTrace(ex); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void controlUpdate(float f) { |
||||||
|
super.controlUpdate(f); |
||||||
|
|
||||||
|
if (!lightPos.equals(lastPos)) { |
||||||
|
if (getSpatial() != null) { |
||||||
|
lastPos.set(lightPos); |
||||||
|
getSpatial().setLocalTranslation(lastPos); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,66 @@ |
|||||||
|
/* |
||||||
|
* To change this license header, choose License Headers in Project Properties. |
||||||
|
* To change this template file, choose Tools | Templates |
||||||
|
* and open the template in the editor. |
||||||
|
*/ |
||||||
|
package com.jme3.gde.scenecomposer.gizmo.light; |
||||||
|
|
||||||
|
import com.jme3.asset.AssetManager; |
||||||
|
import com.jme3.environment.util.BoundingSphereDebug; |
||||||
|
import com.jme3.light.Light; |
||||||
|
import com.jme3.light.LightProbe; |
||||||
|
import com.jme3.material.Material; |
||||||
|
import com.jme3.material.RenderState; |
||||||
|
import com.jme3.renderer.queue.RenderQueue; |
||||||
|
import com.jme3.scene.Geometry; |
||||||
|
import com.jme3.scene.Node; |
||||||
|
import com.jme3.scene.Spatial; |
||||||
|
import com.jme3.scene.shape.Quad; |
||||||
|
import com.jme3.scene.shape.Sphere; |
||||||
|
import com.jme3.texture.Texture; |
||||||
|
|
||||||
|
/** |
||||||
|
* Handles the creation of the appropriate light gizmo according to the light type. |
||||||
|
* @author Nehon |
||||||
|
*/ |
||||||
|
public class LightGizmoFactory { |
||||||
|
|
||||||
|
public static Spatial createGizmo(AssetManager assetManager, Light light){ |
||||||
|
switch (light.getType()){ |
||||||
|
case Probe: |
||||||
|
return createLightProbeGizmo(assetManager, light); |
||||||
|
default: |
||||||
|
return createDefaultGizmo(assetManager, light); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private static Spatial createDefaultGizmo(AssetManager assetManager, Light light){ |
||||||
|
Quad q = new Quad(0.5f, 0.5f); |
||||||
|
Geometry g = new Geometry(light.getName(), q); |
||||||
|
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); |
||||||
|
Texture tex = assetManager.loadTexture("com/jme3/gde/scenecomposer/lightbulb32.png"); |
||||||
|
mat.setTexture("ColorMap", tex); |
||||||
|
mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha); |
||||||
|
g.setMaterial(mat); |
||||||
|
g.addControl(new LightGizmoControl(light)); |
||||||
|
g.setQueueBucket(RenderQueue.Bucket.Transparent); |
||||||
|
return g; |
||||||
|
} |
||||||
|
|
||||||
|
private static Spatial createLightProbeGizmo(AssetManager assetManager, Light light){ |
||||||
|
Node debugNode = new Node("Environment debug Node"); |
||||||
|
Sphere s = new Sphere(16, 16, 0.5f); |
||||||
|
Geometry debugGeom = new Geometry(light.getName(), s); |
||||||
|
Material debugMaterial = new Material(assetManager, "Common/MatDefs/Misc/reflect.j3md"); |
||||||
|
debugGeom.setMaterial(debugMaterial); |
||||||
|
Spatial debugBounds = BoundingSphereDebug.createDebugSphere(assetManager); |
||||||
|
|
||||||
|
debugNode.attachChild(debugGeom); |
||||||
|
debugNode.attachChild(debugBounds); |
||||||
|
debugNode.addControl(new LightProbeGizmoControl((LightProbe)light)); |
||||||
|
|
||||||
|
return debugNode; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,59 @@ |
|||||||
|
/* |
||||||
|
* To change this license header, choose License Headers in Project Properties. |
||||||
|
* To change this template file, choose Tools | Templates |
||||||
|
* and open the template in the editor. |
||||||
|
*/ |
||||||
|
package com.jme3.gde.scenecomposer.gizmo.light; |
||||||
|
|
||||||
|
import com.jme3.bounding.BoundingSphere; |
||||||
|
import com.jme3.environment.util.LightsDebugState; |
||||||
|
import com.jme3.light.LightProbe; |
||||||
|
import com.jme3.material.Material; |
||||||
|
import com.jme3.math.Vector3f; |
||||||
|
import com.jme3.renderer.RenderManager; |
||||||
|
import com.jme3.renderer.ViewPort; |
||||||
|
import com.jme3.scene.Geometry; |
||||||
|
import com.jme3.scene.Node; |
||||||
|
import com.jme3.scene.control.AbstractControl; |
||||||
|
|
||||||
|
/** |
||||||
|
* Updates the marker's position whenever the light probe has moved. |
||||||
|
* Also update the gizmo radius according to the probe radius. |
||||||
|
*/ |
||||||
|
public class LightProbeGizmoControl extends AbstractControl{ |
||||||
|
|
||||||
|
private final Vector3f lastPos = new Vector3f(); |
||||||
|
private final LightProbe lightProbe; |
||||||
|
|
||||||
|
LightProbeGizmoControl(LightProbe light) { |
||||||
|
lightProbe = light; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void controlUpdate(float f) { |
||||||
|
|
||||||
|
if (!lightProbe.getPosition().equals(lastPos)) { |
||||||
|
if (getSpatial() != null) { |
||||||
|
lastPos.set(lightProbe.getPosition()); |
||||||
|
getSpatial().setLocalTranslation(lastPos); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
Geometry probeGeom = (Geometry) ((Node) getSpatial()).getChild(0); |
||||||
|
Material m = probeGeom.getMaterial(); |
||||||
|
if (lightProbe.isReady()) { |
||||||
|
m.setTexture("CubeMap", lightProbe.getPrefilteredEnvMap()); |
||||||
|
} |
||||||
|
Geometry probeRadius = (Geometry) ((Node) getSpatial()).getChild(1); |
||||||
|
probeRadius.setLocalScale(((BoundingSphere) lightProbe.getBounds()).getRadius()); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void controlRender(RenderManager rm, ViewPort vp) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue