From 684bd739b9dc269ccbfcecf86664f3d724603e27 Mon Sep 17 00:00:00 2001 From: Sjoerd van de Goor Date: Wed, 8 Feb 2023 01:30:12 +0100 Subject: [PATCH 1/7] Slope rotation (unfinished) --- .../volmit/iris/engine/object/IrisObject.java | 28 +++++++++++++++++++ .../engine/object/IrisObjectPlacement.java | 6 ++++ 2 files changed, 34 insertions(+) diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObject.java b/src/main/java/com/volmit/iris/engine/object/IrisObject.java index 8569ba2c7..74a2ac495 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObject.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObject.java @@ -503,6 +503,34 @@ public class IrisObject extends IrisRegistrant { return -1; } + // Rotation calculation + double slopeRotationY = 0; + ProceduralStream heightStream = rdata.getEngine().getComplex().getHeightStream(); + if (config.isRotateTowardsSlope()) { + // TODO: Make this respect object rotation (I have no idea how. So just make sure your objects are sort of square and you'll be fine) + // Whichever side of the rectangle that bounds the object is lowest is the 'direction' of the slope (simply said). + double hNorth = heightStream.get(x, z + ((float)h) / 2); + double hEast = heightStream.get(x + ((float)w) / 2, z); + double hSouth = heightStream.get(x, z - ((float)h) / 2); + double hWest = heightStream.get(x - ((float)w) / 2, z); + double min = Math.min(Math.min(hNorth, hEast), Math.min(hSouth, hWest)); + if (min == hNorth) { + slopeRotationY = 0; + } else if (min == hEast) { + slopeRotationY = 90; + } else if (min == hSouth) { + slopeRotationY = 180; + } else if (min == hWest) { + slopeRotationY = 270; + } + } else if (config.isRotateTowardsSlopePrecise()) { + // I take three points which together make a plane that decently represents the slope beneath the object + double hNorth = heightStream.get(x, z + ((float)h) / 2); + double hEast = heightStream.get(x + ((float)w) / 2, z); + double hSouthWest = heightStream.get(x - ((float)w) / 2, z - ((float)h) / 2); + // TODO: Complex math + } + if (config.isSmartBore()) { ensureSmartBored(placer.isDebugSmartBore()); } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java index 7b7a08562..13e6dd743 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java @@ -64,6 +64,12 @@ public class IrisObjectPlacement { private boolean isDolphinTarget = false; @Desc("The slope at which this object can be placed. Range from 0 to 10 by default. Calculated from the corners of the object.") private IrisSlopeClip slopeCondition = new IrisSlopeClip(); + @Desc("Set to true to add the rotation of the direction of the slope of the terrain (wherever the slope is going down) to the y-axis rotation of the object. See also rotateTowardsSlopePrecise.") + private boolean rotateTowardsSlope = false; + @Desc("By default the 'rotateTowardsSlope' function simply calculates which direction" + + " (North East South or West) is the lowest, resulting in a 0, 90, 180 or 270 degree rotations. " + + "Setting this to true does a precise calculation, which may give unwanted side-effects due to non-90 degree rotations.") + private boolean rotateTowardsSlopePrecise = false; @MinNumber(0) @MaxNumber(1) @Desc("The chance for this to place in a chunk. If you need multiple per chunk, set this to 1 and use density.") From c1cf8e88ee2ff0b540bb7febd2d28912f169f49c Mon Sep 17 00:00:00 2001 From: Sjoerd van de Goor Date: Wed, 8 Feb 2023 01:33:31 +0100 Subject: [PATCH 2/7] That is pretty necessary --- src/main/java/com/volmit/iris/engine/object/IrisObject.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObject.java b/src/main/java/com/volmit/iris/engine/object/IrisObject.java index 74a2ac495..ec57d4863 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObject.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObject.java @@ -40,6 +40,7 @@ import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.scheduling.IrisLock; import com.volmit.iris.util.scheduling.PrecisionStopwatch; +import com.volmit.iris.util.stream.ProceduralStream; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; From 66d07dcaca6c3c05502ceac7fe3145f5f9c9fda9 Mon Sep 17 00:00:00 2001 From: Sjoerd van de Goor Date: Wed, 8 Feb 2023 01:35:18 +0100 Subject: [PATCH 3/7] Revert "Slope condition" This reverts commit d4c0e07b1daf62c526eb1140dce429d1d0939721. --- .../java/com/volmit/iris/engine/object/IrisObject.java | 7 ------- .../com/volmit/iris/engine/object/IrisObjectPlacement.java | 2 -- 2 files changed, 9 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObject.java b/src/main/java/com/volmit/iris/engine/object/IrisObject.java index ec57d4863..c483449f9 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObject.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObject.java @@ -497,13 +497,6 @@ public class IrisObject extends IrisRegistrant { public int place(int x, int yv, int z, IObjectPlacer oplacer, IrisObjectPlacement config, RNG rng, BiConsumer listener, CarveResult c, IrisData rdata) { IObjectPlacer placer = (config.getHeightmap() != null) ? new HeightmapObjectPlacer(oplacer.getEngine() == null ? IrisContext.get().getEngine() : oplacer.getEngine(), rng, x, yv, z, config, oplacer) : oplacer; - // Slope calculation - if (!config.getSlopeCondition().isDefault() && - !config.getSlopeCondition().isValid(rdata.getEngine().getComplex().getSlopeStream().get(x, z))) - { - return -1; - } - // Rotation calculation double slopeRotationY = 0; ProceduralStream heightStream = rdata.getEngine().getComplex().getHeightStream(); diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java index 13e6dd743..fa62c89a5 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java @@ -62,8 +62,6 @@ public class IrisObjectPlacement { private double snow = 0; @Desc("Whether or not this object can be targeted by a dolphin.") private boolean isDolphinTarget = false; - @Desc("The slope at which this object can be placed. Range from 0 to 10 by default. Calculated from the corners of the object.") - private IrisSlopeClip slopeCondition = new IrisSlopeClip(); @Desc("Set to true to add the rotation of the direction of the slope of the terrain (wherever the slope is going down) to the y-axis rotation of the object. See also rotateTowardsSlopePrecise.") private boolean rotateTowardsSlope = false; @Desc("By default the 'rotateTowardsSlope' function simply calculates which direction" + From 5514fd2645f67cd9097dc1fb196d085ebc1f019a Mon Sep 17 00:00:00 2001 From: Sjoerd van de Goor Date: Wed, 8 Feb 2023 01:51:39 +0100 Subject: [PATCH 4/7] Proper ordering --- .../com/volmit/iris/engine/object/IrisObject.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObject.java b/src/main/java/com/volmit/iris/engine/object/IrisObject.java index c483449f9..49107c58e 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObject.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObject.java @@ -500,7 +500,13 @@ public class IrisObject extends IrisRegistrant { // Rotation calculation double slopeRotationY = 0; ProceduralStream heightStream = rdata.getEngine().getComplex().getHeightStream(); - if (config.isRotateTowardsSlope()) { + if (config.isRotateTowardsSlopePrecise()) { + // I take three points which together make a plane that decently represents the slope beneath the object + double hNorth = heightStream.get(x, z + ((float)h) / 2); + double hEast = heightStream.get(x + ((float)w) / 2, z); + double hSouthWest = heightStream.get(x - ((float)w) / 2, z - ((float)h) / 2); + // TODO: Complex math + } else if (config.isRotateTowardsSlope()) { // TODO: Make this respect object rotation (I have no idea how. So just make sure your objects are sort of square and you'll be fine) // Whichever side of the rectangle that bounds the object is lowest is the 'direction' of the slope (simply said). double hNorth = heightStream.get(x, z + ((float)h) / 2); @@ -517,12 +523,6 @@ public class IrisObject extends IrisRegistrant { } else if (min == hWest) { slopeRotationY = 270; } - } else if (config.isRotateTowardsSlopePrecise()) { - // I take three points which together make a plane that decently represents the slope beneath the object - double hNorth = heightStream.get(x, z + ((float)h) / 2); - double hEast = heightStream.get(x + ((float)w) / 2, z); - double hSouthWest = heightStream.get(x - ((float)w) / 2, z - ((float)h) / 2); - // TODO: Complex math } if (config.isSmartBore()) { From e5a7b5d0c60ab28c7b6c44620aa05a9e3ce01f52 Mon Sep 17 00:00:00 2001 From: Sjoerd van de Goor Date: Wed, 15 Feb 2023 13:12:34 +0100 Subject: [PATCH 5/7] Reformulate todo --- src/main/java/com/volmit/iris/engine/object/IrisObject.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObject.java b/src/main/java/com/volmit/iris/engine/object/IrisObject.java index 49107c58e..64b2c4d44 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObject.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObject.java @@ -507,7 +507,7 @@ public class IrisObject extends IrisRegistrant { double hSouthWest = heightStream.get(x - ((float)w) / 2, z - ((float)h) / 2); // TODO: Complex math } else if (config.isRotateTowardsSlope()) { - // TODO: Make this respect object rotation (I have no idea how. So just make sure your objects are sort of square and you'll be fine) + // TODO: Make this respect object rotation. Currently takes the object without rotation to define the corner points. // Whichever side of the rectangle that bounds the object is lowest is the 'direction' of the slope (simply said). double hNorth = heightStream.get(x, z + ((float)h) / 2); double hEast = heightStream.get(x + ((float)w) / 2, z); From e94406fb454bd732781e6f257771db339394117a Mon Sep 17 00:00:00 2001 From: Sjoerd van de Goor Date: Wed, 15 Feb 2023 14:05:34 +0100 Subject: [PATCH 6/7] Implement rotation, remove precise rotation. --- .../volmit/iris/engine/object/IrisObject.java | 20 ++++++------------- .../engine/object/IrisObjectPlacement.java | 7 ++----- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObject.java b/src/main/java/com/volmit/iris/engine/object/IrisObject.java index 64b2c4d44..6a6901c10 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObject.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObject.java @@ -30,10 +30,7 @@ import com.volmit.iris.util.data.B; import com.volmit.iris.util.format.Form; import com.volmit.iris.util.interpolation.IrisInterpolation; import com.volmit.iris.util.json.JSONObject; -import com.volmit.iris.util.math.AxisAlignedBB; -import com.volmit.iris.util.math.BlockPosition; -import com.volmit.iris.util.math.Position2; -import com.volmit.iris.util.math.RNG; +import com.volmit.iris.util.math.*; import com.volmit.iris.util.matter.MatterMarker; import com.volmit.iris.util.parallel.BurstExecutor; import com.volmit.iris.util.parallel.MultiBurst; @@ -500,18 +497,11 @@ public class IrisObject extends IrisRegistrant { // Rotation calculation double slopeRotationY = 0; ProceduralStream heightStream = rdata.getEngine().getComplex().getHeightStream(); - if (config.isRotateTowardsSlopePrecise()) { - // I take three points which together make a plane that decently represents the slope beneath the object - double hNorth = heightStream.get(x, z + ((float)h) / 2); - double hEast = heightStream.get(x + ((float)w) / 2, z); - double hSouthWest = heightStream.get(x - ((float)w) / 2, z - ((float)h) / 2); - // TODO: Complex math - } else if (config.isRotateTowardsSlope()) { - // TODO: Make this respect object rotation. Currently takes the object without rotation to define the corner points. + if (config.isRotateTowardsSlope()) { // Whichever side of the rectangle that bounds the object is lowest is the 'direction' of the slope (simply said). - double hNorth = heightStream.get(x, z + ((float)h) / 2); + double hNorth = heightStream.get(x, z + ((float)d) / 2); double hEast = heightStream.get(x + ((float)w) / 2, z); - double hSouth = heightStream.get(x, z - ((float)h) / 2); + double hSouth = heightStream.get(x, z - ((float)d) / 2); double hWest = heightStream.get(x - ((float)w) / 2, z); double min = Math.min(Math.min(hNorth, hEast), Math.min(hSouth, hWest)); if (min == hNorth) { @@ -524,6 +514,8 @@ public class IrisObject extends IrisRegistrant { slopeRotationY = 270; } } + config.getRotation().setYAxis(new IrisAxisRotationClamp(true, false, slopeRotationY, slopeRotationY, 360)); + config.getRotation().setEnabled(true); if (config.isSmartBore()) { ensureSmartBored(placer.isDebugSmartBore()); diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java index fa62c89a5..adef5eed0 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java @@ -62,12 +62,9 @@ public class IrisObjectPlacement { private double snow = 0; @Desc("Whether or not this object can be targeted by a dolphin.") private boolean isDolphinTarget = false; - @Desc("Set to true to add the rotation of the direction of the slope of the terrain (wherever the slope is going down) to the y-axis rotation of the object. See also rotateTowardsSlopePrecise.") + @Desc("Set to true to add the rotation of the direction of the slope of the terrain (wherever the slope is going down) to the y-axis rotation of the object." + + "Overwrites the y-axis of the rotation settings if set to true, and force-enables it. This is rounded by 90 degrees as to not fuck up your objects.") private boolean rotateTowardsSlope = false; - @Desc("By default the 'rotateTowardsSlope' function simply calculates which direction" + - " (North East South or West) is the lowest, resulting in a 0, 90, 180 or 270 degree rotations. " + - "Setting this to true does a precise calculation, which may give unwanted side-effects due to non-90 degree rotations.") - private boolean rotateTowardsSlopePrecise = false; @MinNumber(0) @MaxNumber(1) @Desc("The chance for this to place in a chunk. If you need multiple per chunk, set this to 1 and use density.") From 2a95edd8602c100729040c893b2365d1ae895970 Mon Sep 17 00:00:00 2001 From: Sjoerd van de Goor Date: Wed, 15 Feb 2023 14:14:26 +0100 Subject: [PATCH 7/7] further documentation and cleaner code --- src/main/java/com/volmit/iris/engine/object/IrisObject.java | 5 +++-- .../com/volmit/iris/engine/object/IrisObjectPlacement.java | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObject.java b/src/main/java/com/volmit/iris/engine/object/IrisObject.java index 6a6901c10..88ff8f719 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObject.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObject.java @@ -495,7 +495,7 @@ public class IrisObject extends IrisRegistrant { IObjectPlacer placer = (config.getHeightmap() != null) ? new HeightmapObjectPlacer(oplacer.getEngine() == null ? IrisContext.get().getEngine() : oplacer.getEngine(), rng, x, yv, z, config, oplacer) : oplacer; // Rotation calculation - double slopeRotationY = 0; + int slopeRotationY = 0; ProceduralStream heightStream = rdata.getEngine().getComplex().getHeightStream(); if (config.isRotateTowardsSlope()) { // Whichever side of the rectangle that bounds the object is lowest is the 'direction' of the slope (simply said). @@ -514,7 +514,8 @@ public class IrisObject extends IrisRegistrant { slopeRotationY = 270; } } - config.getRotation().setYAxis(new IrisAxisRotationClamp(true, false, slopeRotationY, slopeRotationY, 360)); + double newRotation = config.getRotation().getYAxis().getMin() + slopeRotationY; + config.getRotation().setYAxis(new IrisAxisRotationClamp(true, false, newRotation, newRotation, 360)); config.getRotation().setEnabled(true); if (config.isSmartBore()) { diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java index adef5eed0..445a31e05 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java @@ -63,7 +63,7 @@ public class IrisObjectPlacement { @Desc("Whether or not this object can be targeted by a dolphin.") private boolean isDolphinTarget = false; @Desc("Set to true to add the rotation of the direction of the slope of the terrain (wherever the slope is going down) to the y-axis rotation of the object." + - "Overwrites the y-axis of the rotation settings if set to true, and force-enables it. This is rounded by 90 degrees as to not fuck up your objects.") + "Rounded to 90 degrees. Adds the *min* rotation of the y axis as well (to still allow you to rotate objects nicely). Discards *max* and *interval* on *yaxis*") private boolean rotateTowardsSlope = false; @MinNumber(0) @MaxNumber(1)