Skip to content

Commit be46130

Browse files
committed
scenecomposer : added new gizmos for lights and audio node
1 parent 8743b77 commit be46130

18 files changed

+1359
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.jme3.gde.scenecomposer.gizmo;
7+
8+
import com.jme3.asset.AssetManager;
9+
import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
10+
import com.jme3.gde.core.sceneexplorer.nodes.JmeAudioNode;
11+
import com.jme3.gde.core.sceneexplorer.nodes.JmeLight;
12+
import com.jme3.gde.scenecomposer.gizmo.audio.AudioGizmoFactory;
13+
import com.jme3.gde.scenecomposer.gizmo.light.LightGizmoFactory;
14+
import com.jme3.scene.Spatial;
15+
16+
/**
17+
*
18+
* @author dokthar
19+
*/
20+
public class GizmoFactory {
21+
22+
public static Spatial createGizmo(AssetManager assetManager, AbstractSceneExplorerNode node) {
23+
if (node instanceof JmeLight) {
24+
return LightGizmoFactory.createGizmo(assetManager, (JmeLight) node);
25+
} else if (node instanceof JmeAudioNode) {
26+
return AudioGizmoFactory.createGizmo(assetManager, (JmeAudioNode) node);
27+
}
28+
29+
return null;
30+
}
31+
32+
}
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.jme3.gde.scenecomposer.gizmo;
7+
8+
import com.jme3.math.Matrix3f;
9+
import com.jme3.math.Quaternion;
10+
import com.jme3.math.Transform;
11+
import com.jme3.math.Vector3f;
12+
import com.jme3.scene.Node;
13+
import com.jme3.scene.Spatial;
14+
15+
/**
16+
*
17+
* @author dokthar
18+
*/
19+
public abstract class NodeCallback extends Node {
20+
21+
private final boolean applyTranslation;
22+
private final boolean applyRotation;
23+
private final boolean applyScale;
24+
25+
public NodeCallback(String name) {
26+
this(name, true, true, true);
27+
}
28+
29+
public NodeCallback(String name, boolean applyTranslation, boolean applyRotation, boolean applyScale) {
30+
super(name);
31+
this.applyTranslation = applyTranslation;
32+
this.applyRotation = applyRotation;
33+
this.applyScale = applyScale;
34+
}
35+
36+
@Override
37+
public void setLocalRotation(Matrix3f rotation) {
38+
onRotation(getLocalRotation(), new Quaternion().fromRotationMatrix(rotation));
39+
if (applyRotation) {
40+
super.setLocalRotation(rotation);
41+
}
42+
}
43+
44+
@Override
45+
public void setLocalRotation(Quaternion quaternion) {
46+
onRotation(getLocalRotation(), quaternion);
47+
if (applyRotation) {
48+
super.setLocalRotation(quaternion);
49+
}
50+
}
51+
52+
@Override
53+
public void setLocalScale(Vector3f localScale) {
54+
onResize(getLocalScale(), localScale);
55+
if (applyScale) {
56+
super.setLocalScale(localScale);
57+
}
58+
}
59+
60+
@Override
61+
public void setLocalScale(float localScale) {
62+
onResize(getLocalScale(), new Vector3f(localScale, localScale, localScale));
63+
if (applyScale) {
64+
super.setLocalScale(localScale);
65+
}
66+
}
67+
68+
@Override
69+
public void setLocalScale(float x, float y, float z) {
70+
onResize(getLocalScale(), new Vector3f(x, y, z));
71+
if (applyScale) {
72+
super.setLocalScale(x, y, z);
73+
}
74+
}
75+
76+
@Override
77+
public void setLocalTransform(Transform t) {
78+
onTranslation(getLocalTranslation(), t.getTranslation());
79+
onRotation(getLocalRotation(), t.getRotation());
80+
onResize(getLocalScale(), t.getScale());
81+
82+
if (applyRotation || applyScale || applyTranslation) {
83+
super.setLocalTransform(t);
84+
}
85+
}
86+
87+
@Override
88+
public void setLocalTranslation(Vector3f localTranslation) {
89+
onTranslation(getLocalTranslation(), localTranslation);
90+
if (applyTranslation) {
91+
super.setLocalTranslation(localTranslation);
92+
}
93+
}
94+
95+
@Override
96+
public void setLocalTranslation(float x, float y, float z) {
97+
onTranslation(getLocalTranslation(), new Vector3f(x, y, z));
98+
if (applyTranslation) {
99+
super.setLocalTranslation(x, y, z);
100+
}
101+
}
102+
103+
@Override
104+
public Spatial move(Vector3f offset) {
105+
onTranslation(getLocalTranslation(), getLocalTranslation().add(offset));
106+
if (applyTranslation) {
107+
super.move(offset);
108+
}
109+
return this;
110+
}
111+
112+
@Override
113+
public Spatial move(float x, float y, float z) {
114+
onTranslation(getLocalTranslation(), getLocalTranslation().add(x, y, z));
115+
if (applyTranslation) {
116+
super.move(x, y, z);
117+
}
118+
return this;
119+
}
120+
121+
@Override
122+
public Spatial rotate(Quaternion rot) {
123+
onRotation(getLocalRotation(), getLocalRotation().mult(rot));
124+
if (applyRotation) {
125+
super.rotate(rot);
126+
}
127+
return this;
128+
}
129+
130+
@Override
131+
public Spatial scale(float s) {
132+
onResize(getLocalScale(), getLocalScale().mult(s));
133+
if (applyScale) {
134+
super.scale(s);
135+
}
136+
return this;
137+
}
138+
139+
@Override
140+
public Spatial scale(float x, float y, float z) {
141+
onResize(getLocalScale(), getLocalScale().mult(new Vector3f(x, y, z)));
142+
if (applyScale) {
143+
super.scale(x, y, z);
144+
}
145+
return this;
146+
}
147+
148+
public void silentLocalTranslation(Vector3f translation) {
149+
super.setLocalTranslation(translation);
150+
}
151+
152+
public void silentLocalRotation(Quaternion rotation) {
153+
super.setLocalRotation(rotation);
154+
}
155+
156+
public void silentLocalScale(Vector3f scale) {
157+
super.setLocalScale(scale);
158+
}
159+
160+
public abstract void onTranslation(Vector3f oldTranslation, Vector3f newTranslation);
161+
162+
public abstract void onResize(Vector3f oldScale, Vector3f newScale);
163+
164+
public abstract void onRotation(Quaternion oldRotation, Quaternion newRotation);
165+
166+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.jme3.gde.scenecomposer.gizmo.audio;
7+
8+
import com.jme3.asset.AssetManager;
9+
import com.jme3.audio.AudioNode;
10+
import com.jme3.gde.core.sceneexplorer.nodes.JmeAudioNode;
11+
import com.jme3.material.Material;
12+
import com.jme3.material.RenderState;
13+
import com.jme3.math.Vector3f;
14+
import com.jme3.renderer.RenderManager;
15+
import com.jme3.renderer.ViewPort;
16+
import com.jme3.renderer.queue.RenderQueue;
17+
import com.jme3.scene.Geometry;
18+
import com.jme3.scene.Node;
19+
import com.jme3.scene.Spatial;
20+
import com.jme3.scene.control.BillboardControl;
21+
import com.jme3.scene.control.Control;
22+
import com.jme3.scene.shape.Quad;
23+
import com.jme3.texture.Texture;
24+
25+
/**
26+
*
27+
* @author dokthar
28+
*/
29+
public class AudioGizmoFactory {
30+
31+
private Material audioMarkerMaterial;
32+
33+
public static Spatial createGizmo(AssetManager assetManager, JmeAudioNode node) {
34+
AudioNode audio = node.getLookup().lookup(AudioNode.class);
35+
if (audio == null) {
36+
return null;
37+
}
38+
39+
return createAudioGizmo(assetManager, node, audio);
40+
41+
// This marker is not part of the scene, but is part of the tools node.
42+
//return audio;
43+
}
44+
45+
private static Spatial createAudioGizmo(AssetManager assetManager, JmeAudioNode node, AudioNode audio) {
46+
Node gizmo = new Node("Audio node Gizmo");
47+
Spatial marker = createAudioMarker(assetManager);
48+
gizmo.attachChild(marker);
49+
50+
gizmo.addControl(new AudioMarkerControl(audio));
51+
return gizmo;
52+
}
53+
54+
/**
55+
* Updates the marker's position whenever the audio node has moved. It is
56+
* also a BillboardControl, so this marker always faces the camera
57+
*/
58+
protected static class AudioMarkerControl extends BillboardControl {
59+
60+
private final AudioNode audio;
61+
private final Vector3f lastPos = new Vector3f();
62+
private final Vector3f audioPos;
63+
64+
AudioMarkerControl(AudioNode a) {
65+
super();
66+
audio = a;
67+
audioPos = audio.getPosition();
68+
}
69+
70+
@Override
71+
protected void controlUpdate(float f) {
72+
super.controlUpdate(f);
73+
Spatial marker = getSpatial();
74+
if (marker != null && !audioPos.equals(lastPos)) {
75+
lastPos.set(audioPos);
76+
marker.getParent().worldToLocal(lastPos, lastPos);
77+
marker.setLocalTranslation(lastPos);
78+
}
79+
}
80+
81+
@Override
82+
protected void controlRender(RenderManager rm, ViewPort vp) {
83+
super.controlRender(rm, vp);
84+
}
85+
}
86+
87+
/**
88+
* A marker on the screen that shows where an audio node is.
89+
*/
90+
protected static Geometry createAudioMarker(AssetManager assetManager) {
91+
Quad q = new Quad(0.5f, 0.5f);
92+
Geometry audioMarker = new Geometry("light bulb", q);
93+
audioMarker.move(-q.getHeight() / 2f, -q.getWidth() / 2f, 0);
94+
95+
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
96+
Texture tex = assetManager.loadTexture("com/jme3/gde/scenecomposer/audionode.gif");
97+
mat.setTexture("ColorMap", tex);
98+
mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
99+
audioMarker.setMaterial(mat);
100+
audioMarker.setQueueBucket(RenderQueue.Bucket.Transparent);
101+
102+
return audioMarker;
103+
}
104+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.jme3.gde.scenecomposer.gizmo.light;
7+
8+
import com.jme3.bounding.BoundingSphere;
9+
import com.jme3.bounding.BoundingVolume;
10+
import com.jme3.gde.core.sceneexplorer.nodes.JmeDirectionalLight;
11+
import com.jme3.gde.scenecomposer.gizmo.NodeCallback;
12+
import com.jme3.light.DirectionalLight;
13+
import com.jme3.math.Quaternion;
14+
import com.jme3.math.Vector3f;
15+
16+
/**
17+
*
18+
* @author dokthar
19+
*/
20+
public class DirectionalLightGizmo extends NodeCallback {
21+
22+
private Vector3f initalDirection;
23+
private JmeDirectionalLight jmeLight;
24+
private DirectionalLight light;
25+
26+
public DirectionalLightGizmo(JmeDirectionalLight jmelight) {
27+
super("directional light gizmo", true, true, false);
28+
jmeLight = jmelight;
29+
light = jmeLight.getLookup().lookup(DirectionalLight.class);
30+
initalDirection = light.getDirection().clone();
31+
}
32+
33+
@Override
34+
public void onTranslation(Vector3f oldTranslation, Vector3f newTranslation) {
35+
}
36+
37+
@Override
38+
public void onResize(Vector3f oldScale, Vector3f newScale) {
39+
}
40+
41+
@Override
42+
public void onRotation(Quaternion oldRotation, Quaternion newRotation) {
43+
light.setDirection(newRotation.mult(initalDirection));
44+
jmeLight.setValue("direction", light.getDirection());
45+
}
46+
47+
private final BoundingSphere bv = new BoundingSphere(10f, getWorldTranslation());
48+
49+
@Override
50+
public BoundingVolume getWorldBound() {
51+
return bv;
52+
}
53+
54+
}

0 commit comments

Comments
 (0)