Skip to content

Commit d92151c

Browse files
authored
Add files via upload
1 parent 8793765 commit d92151c

File tree

8 files changed

+854
-0
lines changed

8 files changed

+854
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2009-2026 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+
33+
package com.jme3.vectoreffect;
34+
35+
import com.jme3.app.state.AppStateManager;
36+
import java.util.ArrayList;
37+
38+
/**
39+
* @author yaRnMcDonuts
40+
*/
41+
42+
public abstract class AbstractVectorEffect implements VectorEffect {
43+
44+
protected VectorGroup vectorsToModify;
45+
private final ArrayList<Runnable> onFinishedCallbacks = new ArrayList<>();
46+
protected boolean isFinished = false;
47+
48+
public AbstractVectorEffect(){
49+
50+
}
51+
52+
public AbstractVectorEffect(VectorGroup vectorsToModify) {
53+
this.vectorsToModify = vectorsToModify;
54+
}
55+
56+
@Override
57+
public void setIsFinished(boolean isFinished) {
58+
this.isFinished = isFinished;
59+
if (isFinished) {
60+
for(Runnable r : onFinishedCallbacks) {
61+
r.run();
62+
}
63+
onFinishedCallbacks.clear();
64+
}
65+
}
66+
67+
@Override
68+
public VectorGroup getVectorsToModify(){
69+
return vectorsToModify;
70+
}
71+
72+
@Override
73+
public boolean isFinished() {
74+
return isFinished;
75+
}
76+
77+
78+
@Override
79+
public void reset() {
80+
isFinished = false;
81+
}
82+
83+
84+
public void registerRunnableOnFinish(Runnable runnable) {
85+
onFinishedCallbacks.add(runnable);
86+
}
87+
88+
@Override
89+
public void update(float tpf){
90+
91+
}
92+
93+
// convenience registration method so users can avoid repeatedly writing this AppState fetching code
94+
public void convenienceRegister(AppStateManager stateManager) {
95+
if(stateManager != null){
96+
VectorEffectManagerState vectorEffectManagerState = stateManager.getState(VectorEffectManagerState.class);
97+
if(vectorEffectManagerState != null){
98+
vectorEffectManagerState.registerVectorEffect(this);
99+
}
100+
}
101+
}
102+
103+
104+
}
105+

vectoreffect/EaseVectorEffect.java

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* Copyright (c) 2009-2026 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+
33+
package com.jme3.vectoreffect;
34+
35+
import com.jme3.math.EaseFunction;
36+
import com.jme3.math.Easing;
37+
import com.jme3.math.Vector4f;
38+
39+
/**
40+
*
41+
* @author yaRnMcDonuts
42+
*/
43+
public final class EaseVectorEffect extends AbstractVectorEffect implements VectorEffect {
44+
45+
private VectorGroup targetVectors;
46+
private VectorGroup startVectors;
47+
48+
private float duration = 0f;
49+
private float easeTimer = 0f;
50+
private float delay = 0f;
51+
private float delayTimer = 0f;
52+
53+
private EaseFunction easeFunction = Easing.linear;
54+
55+
private final Vector4f tempTargetVec = new Vector4f();
56+
private final Vector4f tempStartVec = new Vector4f();
57+
58+
59+
public EaseVectorEffect(VectorGroup vectorToModify) {
60+
super(vectorToModify);
61+
}
62+
63+
public EaseVectorEffect(VectorGroup vectorToModify, VectorGroup targetVector, float duration) {
64+
this(vectorToModify);
65+
setEaseToValueOverDuration(duration, targetVector);
66+
}
67+
68+
public EaseVectorEffect(VectorGroup vectorToModify, VectorGroup targetVector, float duration,
69+
float delay) {
70+
this(vectorToModify);
71+
setEaseToValueOverDuration(duration, targetVector);
72+
setDelayTime(delay);
73+
}
74+
75+
public EaseVectorEffect(VectorGroup vectorToModify, VectorGroup targetVector, float duration,
76+
EaseFunction easeFunction) {
77+
this(vectorToModify, targetVector, duration);
78+
setEaseFunction(easeFunction);
79+
}
80+
81+
public EaseVectorEffect(VectorGroup vectorToModify, VectorGroup targetVector, float duration,
82+
EaseFunction easeFunction, float delay) {
83+
this(vectorToModify, targetVector, duration);
84+
setEaseFunction(easeFunction);
85+
setDelayTime(delay);
86+
}
87+
88+
89+
@Override
90+
public void update(float tpf) {
91+
super.update(tpf);
92+
93+
if (delayTimer <= delay) {
94+
delayTimer += tpf;
95+
return;
96+
}
97+
98+
if (startVectors == null) {
99+
startVectors = vectorsToModify.clone();
100+
}
101+
102+
easeTimer += tpf;
103+
float t = Math.min(easeTimer / duration, 1f);
104+
105+
float easedT = easeFunction.apply(t);
106+
107+
for(int v = 0; v < vectorsToModify.getSize(); v++){
108+
109+
int targetIndex = Math.min(v, targetVectors.getSize() - 1); //allows multiple vectors to share a lesser number of targets if desired
110+
targetVectors.getAsVector4(targetIndex, tempTargetVec);
111+
startVectors.getAsVector4(v, tempStartVec);
112+
tempTargetVec.subtractLocal(tempStartVec);
113+
tempTargetVec.multLocal(easedT);
114+
115+
vectorsToModify.updateVectorObject(tempStartVec.addLocal(tempTargetVec), v);
116+
}
117+
118+
if (t >= 1f) {
119+
super.setIsFinished(true);
120+
}
121+
}
122+
123+
public EaseVectorEffect setEaseToValueOverDuration(float dur, VectorGroup targetVector) {
124+
this.targetVectors = targetVector;
125+
duration = dur;
126+
startVectors = null;
127+
return this;
128+
}
129+
130+
public void setDelayTime(float delay) {
131+
this.delay = delay;
132+
}
133+
134+
public void setEaseFunction(EaseFunction func) {
135+
this.easeFunction = func;
136+
}
137+
138+
@Override
139+
public void reset() {
140+
delayTimer = 0;
141+
easeTimer = 0;
142+
startVectors = null;
143+
super.reset();
144+
}
145+
146+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2009-2026 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 com.jme3.vectoreffect;
33+
34+
import com.jme3.math.Vector4f;
35+
import com.jme3.math.FastNoiseLite;
36+
import com.jme3.math.FastNoiseLite.NoiseType;
37+
38+
/**
39+
*
40+
* @author yaRnMcDonuts
41+
*/
42+
public class NoiseVectorEffect extends AbstractVectorEffect implements VectorEffect {
43+
44+
private FastNoiseLite noiseGenerator;
45+
46+
private VectorGroup noiseMagnitudes;
47+
private VectorGroup originalVectorValues;
48+
49+
private final Vector4f tempNoiseVariationVec = new Vector4f();
50+
private final Vector4f tempOriginalVec = new Vector4f();
51+
52+
public float speed = 1;
53+
private float timeAccrued = 0;
54+
55+
public NoiseVectorEffect(VectorGroup vectorObject, VectorGroup noiseMagnitude) {
56+
this(vectorObject, noiseMagnitude, NoiseType.OpenSimplex2, 0.5f);
57+
}
58+
59+
public NoiseVectorEffect(VectorGroup vectorObject, VectorGroup noiseMagnitude, NoiseType noiseType,
60+
float frequency) {
61+
super(vectorObject);
62+
63+
this.noiseMagnitudes = noiseMagnitude;
64+
noiseGenerator = new FastNoiseLite();
65+
noiseGenerator.SetFrequency(frequency);
66+
noiseGenerator.SetNoiseType(noiseType);
67+
68+
}
69+
70+
@Override
71+
public void update(float tpf) {
72+
super.update(tpf);
73+
74+
if(originalVectorValues == null){
75+
originalVectorValues = vectorsToModify.clone();
76+
}
77+
78+
timeAccrued += tpf;
79+
float noiseReturnVal = noiseGenerator.GetNoise(timeAccrued * speed, 12.671f + timeAccrued * speed * 0.92173f, 19.54f + timeAccrued * speed * 0.68913f);
80+
81+
for(int v = 0; v < vectorsToModify.getSize(); v++){
82+
int magnitudeIndex = Math.min(v, noiseMagnitudes.getSize() - 1); //allows multiple vectors to share the same magnitude if desired
83+
noiseMagnitudes.getAsVector4(magnitudeIndex, tempNoiseVariationVec);
84+
85+
tempNoiseVariationVec.multLocal(noiseReturnVal);
86+
originalVectorValues.getAsVector4(v, tempOriginalVec);
87+
88+
vectorsToModify.updateVectorObject(tempOriginalVec.addLocal(tempNoiseVariationVec), v);
89+
}
90+
}
91+
92+
public FastNoiseLite getNoiseGenerator() {
93+
return noiseGenerator;
94+
}
95+
96+
public void setSpeed(float speed) {
97+
this.speed = speed;
98+
}
99+
100+
@Override
101+
public void reset() {
102+
super.reset();
103+
originalVectorValues = null;
104+
}
105+
}

0 commit comments

Comments
 (0)