Skip to content

Commit ba6672b

Browse files
authored
Add Example
1 parent a4dfa6c commit ba6672b

1 file changed

Lines changed: 211 additions & 0 deletions

File tree

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
/*
2+
* Copyright (c) 2009-2021 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package jme3test.effect;
33+
34+
import com.jme3.vectoreffect.EaseVectorEffect;
35+
import com.jme3.vectoreffect.VectorEffectManagerState;
36+
import com.jme3.vectoreffect.SequencedVectorEffect;
37+
import com.jme3.app.SimpleApplication;
38+
import com.jme3.light.PointLight;
39+
import com.jme3.material.Material;
40+
import com.jme3.math.ColorRGBA;
41+
import com.jme3.math.Easing;
42+
import com.jme3.math.FastMath;
43+
import com.jme3.post.FilterPostProcessor;
44+
import com.jme3.post.filters.BloomFilter;
45+
import com.jme3.scene.Geometry;
46+
import com.jme3.scene.shape.Quad;
47+
import com.jme3.scene.shape.Sphere;
48+
import com.jme3.system.AppSettings;
49+
import java.awt.DisplayMode;
50+
import java.awt.GraphicsDevice;
51+
import java.awt.GraphicsEnvironment;
52+
53+
/**
54+
*
55+
* @author yaRnMcDonuts
56+
*/
57+
public class VectorEffectSimpleTest extends SimpleApplication {
58+
59+
private ColorRGBA colorToShift = new ColorRGBA(0.0f, 0.0f, 1.0f, 1.0f);
60+
61+
private VectorEffectManagerState vectorEffectManagerState;
62+
63+
public static void main(String[] args) {
64+
VectorEffectSimpleTest app = new VectorEffectSimpleTest();
65+
AppSettings settings = new AppSettings(true);
66+
app.setSettings(settings);
67+
app.start();
68+
}
69+
70+
71+
@Override
72+
public void simpleInitApp() {
73+
restart();
74+
flyCam.setMoveSpeed(10f);
75+
76+
vectorEffectManagerState = new VectorEffectManagerState();
77+
stateManager.attach(vectorEffectManagerState);
78+
79+
initBloom();
80+
initPbrRoom(13);
81+
82+
initLightAndEmissiveSphere();
83+
84+
//initiate VectorEffectManagerState
85+
vectorEffectManagerState = new VectorEffectManagerState();
86+
stateManager.attach(vectorEffectManagerState);
87+
vectorEffectManagerState.setEnabled(true);
88+
89+
//create gradient effect :
90+
SequencedVectorEffect colorGradientEffect = new SequencedVectorEffect(
91+
new EaseVectorEffect(colorToShift, ColorRGBA.Cyan, 0.75f),
92+
new EaseVectorEffect(colorToShift, ColorRGBA.Yellow, 0.75f),
93+
new EaseVectorEffect(colorToShift, ColorRGBA.Blue, 0.75f ),
94+
new EaseVectorEffect(colorToShift, ColorRGBA.Magenta, 0.75f),
95+
new EaseVectorEffect(colorToShift, ColorRGBA.Green, 0.75f),
96+
new EaseVectorEffect(colorToShift, ColorRGBA.Red, 0.75f)
97+
);
98+
99+
//create red flashing effect :
100+
SequencedVectorEffect blinkEffect = new SequencedVectorEffect(
101+
new EaseVectorEffect(colorToShift, ColorRGBA.Black, 0.25f, Easing.inOutQuad),
102+
new EaseVectorEffect(colorToShift, ColorRGBA.Red, 0.175f, Easing.outQuart)
103+
);
104+
blinkEffect.setRepeatNumberOfTimes(10);
105+
106+
107+
//put both effects into a looping SequencedVectorEffect
108+
SequencedVectorEffect finalLoopingEffect = new SequencedVectorEffect(colorGradientEffect, blinkEffect);
109+
finalLoopingEffect.setLooping(true);
110+
111+
//register the effect:
112+
vectorEffectManagerState.registerVectorEffect(finalLoopingEffect);
113+
114+
}
115+
116+
private void initBloom() {
117+
118+
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
119+
BloomFilter bloom = new BloomFilter(BloomFilter.GlowMode.Scene);
120+
bloom.setBloomIntensity(5f);
121+
bloom.setExposurePower(4.5f);
122+
bloom.setExposureCutOff(0.2f);
123+
bloom.setBlurScale(2);
124+
fpp.addFilter(bloom);
125+
viewPort.addProcessor(fpp);
126+
}
127+
128+
private void initLightAndEmissiveSphere(){
129+
130+
131+
//make point light
132+
PointLight light = new PointLight();
133+
light.setRadius(10);
134+
colorToShift = light.getColor();
135+
136+
//make sphere with Emissive color
137+
Sphere sphereMesh = new Sphere(32, 32, 0.5f);
138+
Geometry glowingSphere = new Geometry("ShakingSphere", sphereMesh);
139+
140+
Material sphereMat = new Material(assetManager, "Common/MatDefs/Light/PBRLighting.j3md");
141+
sphereMat.setColor("BaseColor", ColorRGBA.DarkGray);
142+
sphereMat.setFloat("Roughness", 0.04f);
143+
sphereMat.setFloat("Metallic", 0.98f);
144+
sphereMat.setBoolean("UseVertexColor", false);
145+
glowingSphere.setMaterial(sphereMat);
146+
147+
148+
//assign the same colorToShift vector to both the light and emissive value (important not to clone)
149+
light.setColor(colorToShift);
150+
sphereMat.setColor("Emissive", colorToShift);
151+
152+
153+
rootNode.attachChild(glowingSphere);
154+
rootNode.addLight(light);
155+
156+
157+
}
158+
159+
public void initPbrRoom(float size) {
160+
161+
162+
float half = size * 0.5f;
163+
164+
165+
Material wallMat = new Material(assetManager, "Common/MatDefs/Light/PBRLighting.j3md");
166+
167+
wallMat.setColor("BaseColor", new ColorRGBA(1,1,1, 1f));
168+
wallMat.setFloat("Roughness", 0.12f);
169+
wallMat.setFloat("Metallic", 0.02f);
170+
171+
// Floor
172+
Geometry floor = new Geometry("Floor",
173+
new Quad(size, size));
174+
floor.setMaterial(wallMat);
175+
floor.rotate(-FastMath.HALF_PI, 0, 0);
176+
floor.setLocalTranslation(-half, -half, half);
177+
rootNode.attachChild(floor);
178+
179+
// Ceiling
180+
Geometry ceiling = new Geometry("Ceiling",
181+
new Quad(size, size));
182+
ceiling.setMaterial(wallMat);
183+
ceiling.rotate(FastMath.HALF_PI, 0, 0);
184+
ceiling.setLocalTranslation(-half, size-half, -half);
185+
rootNode.attachChild(ceiling);
186+
187+
// Back wall
188+
Geometry backWall = new Geometry("BackWall",
189+
new Quad(size, size));
190+
backWall.setMaterial(wallMat);
191+
backWall.setLocalTranslation(-half, -half, -half);
192+
rootNode.attachChild(backWall);
193+
194+
// Left wall
195+
Geometry leftWall = new Geometry("LeftWall",
196+
new Quad(size, size));
197+
leftWall.setMaterial(wallMat);
198+
leftWall.rotate(0, FastMath.HALF_PI, 0);
199+
leftWall.setLocalTranslation(-half, -half, half);
200+
rootNode.attachChild(leftWall);
201+
202+
// Right wall
203+
Geometry rightWall = new Geometry("RightWall",
204+
new Quad(size, size));
205+
rightWall.setMaterial(wallMat);
206+
rightWall.rotate(0, -FastMath.HALF_PI, 0);
207+
rightWall.setLocalTranslation(half, -half, -half);
208+
rootNode.attachChild(rightWall);
209+
210+
}
211+
}

0 commit comments

Comments
 (0)