Skip to content

Commit 0c83cbf

Browse files
Copilotriccardobl
andauthored
Add cross-platform ColorRGBA/Texture2D helpers to ShaderUtils; enable terrain in iOS examples
- Add mix(ColorRGBA, ColorRGBA, float) as cross-platform replacement for removed mix(java.awt.Color, ...) - Add getImageDataFromTexture(Texture2D) as cross-platform replacement for removed getImageDataFromImage(BufferedImage) - Remove jme3test.terrain. from iOS example chooser excluded prefixes - Move jme3-terrain from iosIncludeAwtUnsafeModules conditional to unconditional iOS dependencies Agent-Logs-Url: https://github.com/jMonkeyEngine/jmonkeyengine/sessions/612baf0b-d7a0-4d66-bc40-412519339e72 Co-authored-by: riccardobl <4943530+riccardobl@users.noreply.github.com>
1 parent b54d36f commit 0c83cbf

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

jme3-ios-examples/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ def iosChooserExcludedPrefixes = [
3535
'jme3test.awt.',
3636
'jme3test.bullet.',
3737
'jme3test.niftygui.',
38-
'jme3test.opencl.',
39-
'jme3test.terrain.'
38+
'jme3test.opencl.'
4039
]
4140
def iosChooserExcludedNames = [
4241
'jme3test.app.TestChangeAppIcon',
@@ -311,10 +310,10 @@ dependencies {
311310
implementation project(':jme3-plugins')
312311
implementation project(':jme3-plugins-json')
313312
implementation project(':jme3-plugins-json-gson')
313+
implementation project(':jme3-terrain')
314314

315315
if ((findProperty('iosIncludeAwtUnsafeModules') ?: 'false').toString().toBoolean()) {
316316
implementation project(':jme3-niftygui')
317-
implementation project(':jme3-terrain')
318317
}
319318
}
320319

jme3-terrain/src/main/java/com/jme3/terrain/noise/ShaderUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
*/
3030
package com.jme3.terrain.noise;
3131

32+
import com.jme3.math.ColorRGBA;
33+
import com.jme3.texture.Texture2D;
34+
import java.nio.ByteBuffer;
35+
3236
/**
3337
* Helper class containing useful functions explained in the book:
3438
* Texturing &amp; Modeling - A Procedural Approach
@@ -61,6 +65,14 @@ public static final int mix(final int a, final int b, final float f) {
6165
return (int) ((1 - f) * a + f * b);
6266
}
6367

68+
public static final ColorRGBA mix(final ColorRGBA a, final ColorRGBA b, final float f) {
69+
return new ColorRGBA(
70+
ShaderUtils.mix(a.r, b.r, f),
71+
ShaderUtils.mix(a.g, b.g, f),
72+
ShaderUtils.mix(a.b, b.b, f),
73+
ShaderUtils.mix(a.a, b.a, f));
74+
}
75+
6476
public static final float[] mix(final float[] c1, final float[] c2, final float f) {
6577
return new float[] { ShaderUtils.mix(c1[0], c2[0], f), ShaderUtils.mix(c1[1], c2[1], f), ShaderUtils.mix(c1[2], c2[2], f) };
6678
}
@@ -242,6 +254,10 @@ public static final float length(final float[] v) {
242254
return (float) Math.sqrt(s);
243255
}
244256

257+
public static final ByteBuffer getImageDataFromTexture(final Texture2D texture) {
258+
return texture.getImage().getData(0);
259+
}
260+
245261
public static float frac(float f) {
246262
return f - ShaderUtils.floor(f);
247263
}

0 commit comments

Comments
 (0)