mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-29 20:19:06 +00:00
Merge pull request #952 from CocoTheOwner/fix-image-math
Fix image mapping math
This commit is contained in:
@@ -32,7 +32,7 @@ import lombok.Data;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
@Snippet("carving")
|
@Snippet("image-map")
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@@ -68,6 +68,7 @@ public class IrisImageMap {
|
|||||||
IrisImage i = imageCache.aquire(() -> data.getImageLoader().load(image));
|
IrisImage i = imageCache.aquire(() -> data.getImageLoader().load(image));
|
||||||
if (i == null) {
|
if (i == null) {
|
||||||
Iris.error("NULL IMAGE FOR " + image);
|
Iris.error("NULL IMAGE FOR " + image);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return IrisInterpolation.getNoise(interpolationMethod, x, z, coordinateScale, (xx, zz) -> rawNoise(i, xx, zz));
|
return IrisInterpolation.getNoise(interpolationMethod, x, z, coordinateScale, (xx, zz) -> rawNoise(i, xx, zz));
|
||||||
@@ -76,11 +77,27 @@ public class IrisImageMap {
|
|||||||
private double rawNoise(IrisImage i, double x, double z) {
|
private double rawNoise(IrisImage i, double x, double z) {
|
||||||
x /= coordinateScale;
|
x /= coordinateScale;
|
||||||
z /= coordinateScale;
|
z /= coordinateScale;
|
||||||
x = isCentered() ? x + ((i.getWidth() / 2D) * coordinateScale) : x;
|
|
||||||
z = isCentered() ? z + ((i.getHeight() / 2D) * coordinateScale) : z;
|
// X and Z are now scaled to the image
|
||||||
x = isTiled() ? x % i.getWidth() : x;
|
|
||||||
z = isTiled() ? z % i.getHeight() : z;
|
// Add half the image width & height if centered
|
||||||
|
if (isCentered()) {
|
||||||
|
x += i.getWidth() / 2D;
|
||||||
|
z += i.getHeight() / 2D;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If tiled modulo over width and height
|
||||||
|
if (isTiled()) {
|
||||||
|
x = x % i.getWidth();
|
||||||
|
x = x < 0 ? x + i.getWidth() : x; // Fix java's negative modulo shit
|
||||||
|
z = z % i.getHeight();
|
||||||
|
z = z < 0 ? z + i.getHeight() : z; // Fix java's negative modulo shit
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve value from image
|
||||||
double v = i.getValue(getChannel(), (int) x, (int) z);
|
double v = i.getValue(getChannel(), (int) x, (int) z);
|
||||||
|
|
||||||
|
// Return value, or 1 - value if inverted (value is in double set [0, 1] so this will return [0, 1])
|
||||||
return isInverted() ? 1D - v : v;
|
return isInverted() ? 1D - v : v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user