mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 09:44:24 +00:00
Gap-free object rotation
- Rotations off the right angles fill every target cell from the nearest source block - Source blocks that no target cell samples still place at their rotated position - Right-angle rotations keep the direct transform - Markers, canopy and tile data follow their resampled source blocks - Datapack export bakes off-angle variants with the same resampler - The unused rotateCopy paths are removed - Placement goldens match the resampled output
This commit is contained in:
1 parent
2462330787
commit
b0860f94fc
14 files changed
+874
-189
No files matched your search
+174
@@ -6,12 +6,15 @@ import art.arcane.iris.pack.datapack.export.TemplateBlock;
|
||||
import art.arcane.iris.pack.datapack.export.TemplateVolume;
|
||||
import art.arcane.iris.pack.datapack.export.VanillaBlockState;
|
||||
import art.arcane.iris.pack.datapack.export.compile.WeightedState;
|
||||
import art.arcane.volmlib.util.nbt.tag.CompoundTag;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
@@ -22,6 +25,8 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ObjectVariantBakerTest {
|
||||
private static final String NAMESPACE = "iris_export";
|
||||
private static final String LEAVES = "minecraft:oak_leaves[distance=1,persistent=true,waterlogged=false]";
|
||||
private static final long RIGHT_ANGLE_GOLDEN = 0x5db739a5b940bf1dL;
|
||||
|
||||
@Test
|
||||
public void variantBakingIsDeterministic() throws IOException {
|
||||
@@ -245,6 +250,171 @@ public class ObjectVariantBakerTest {
|
||||
assertEquals(2, lifted.roots().reach());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diagonalTurnsFillSolidCanopiesWithoutHoles() {
|
||||
for (double degrees : new double[]{45, 135}) {
|
||||
assertSolid(leafDisc(6, 3), degrees, (x, z) -> x * x + z * z <= 25D);
|
||||
assertSolid(leafBox(4, 3), degrees, (x, z) -> Math.abs(x) <= 3.75D && Math.abs(z) <= 3.75D);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diagonalTurnsKeepEveryThinTrunkColumn() {
|
||||
int[][] columns = {{2, 0}, {0, 2}, {-2, 0}, {3, 1}};
|
||||
List<TemplateBlock> blocks = new ArrayList<>();
|
||||
for (int[] column : columns) {
|
||||
for (int y = 0; y < 6; y++) {
|
||||
blocks.add(block(column[0] + 3, y, column[1] + 3, "minecraft:oak_log[axis=y]"));
|
||||
}
|
||||
}
|
||||
TemplateVolume trunks = new TemplateVolume(7, 6, 7, blocks);
|
||||
for (double degrees : new double[]{45, 135, 225, 315}) {
|
||||
BakedVariant variant = turned(trunks, new VariantSpec.Rotation(0, degrees, 0));
|
||||
Map<Long, int[]> heights = new HashMap<>();
|
||||
for (TemplateBlock block : variant.volume().blocks()) {
|
||||
int x = anchoredX(variant, block);
|
||||
int z = anchoredZ(variant, block);
|
||||
heights.computeIfAbsent(cell(x, 0, z), ignored -> new int[]{x, z, 0})[2]++;
|
||||
}
|
||||
double cos = Math.cos(Math.toRadians(degrees));
|
||||
double sin = Math.sin(Math.toRadians(degrees));
|
||||
for (int[] column : columns) {
|
||||
long forward = cell((int) Math.round(cos * column[0] + sin * column[1]), 0,
|
||||
(int) Math.round(-sin * column[0] + cos * column[1]));
|
||||
boolean kept = false;
|
||||
for (Map.Entry<Long, int[]> output : heights.entrySet()) {
|
||||
int[] value = output.getValue();
|
||||
assertEquals(degrees + " degrees cut a trunk column short", 6, value[2]);
|
||||
boolean samples = (int) Math.round(cos * value[0] - sin * value[1]) == column[0]
|
||||
&& (int) Math.round(sin * value[0] + cos * value[1]) == column[1];
|
||||
kept |= samples || output.getKey() == forward;
|
||||
}
|
||||
assertTrue(degrees + " degrees lost the trunk column at " + column[0] + "," + column[1], kept);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rightAngleTurnsKeepTheirExactLayout() {
|
||||
CompoundTag chest = new CompoundTag();
|
||||
chest.putString("id", "minecraft:chest");
|
||||
TemplateVolume volume = new TemplateVolume(4, 4, 4, List.of(
|
||||
block(0, 0, 0, "minecraft:stone"),
|
||||
block(3, 0, 1, "minecraft:stone"),
|
||||
block(1, 1, 2, "minecraft:oak_log[axis=x]"),
|
||||
block(2, 2, 0, "minecraft:oak_stairs[facing=north,half=bottom,shape=outer_left,waterlogged=false]"),
|
||||
new TemplateBlock(3, 1, 3, VanillaBlockState.parse("minecraft:chest[facing=east,type=single,waterlogged=false]"), chest),
|
||||
block(1, 3, 1, "minecraft:oak_leaves[distance=1,persistent=false,waterlogged=false]"),
|
||||
block(0, 2, 3, "minecraft:oak_slab[type=bottom,waterlogged=false]")));
|
||||
TreeRoots roots = new TreeRoots(List.of(block(0, 0, 0, "minecraft:stone")), 2);
|
||||
StringBuilder layout = new StringBuilder();
|
||||
for (double scale : new double[]{1, 1.5}) {
|
||||
for (int x = 0; x < 360; x += 90) {
|
||||
for (int y = 0; y < 360; y += 90) {
|
||||
for (int z = 0; z < 360; z += 90) {
|
||||
VariantSpec spec = VariantSpec.builder().scale(scale).rotation(new VariantSpec.Rotation(x, y, z)).build();
|
||||
describe(layout, new ObjectVariantBaker().bake("iris_export:object/turn/a", new ObjectSource(volume, -1, roots), spec));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(RIGHT_ANGLE_GOLDEN, fnv(layout));
|
||||
}
|
||||
|
||||
private static void assertSolid(TemplateVolume source, double degrees, Interior interior) {
|
||||
BakedVariant variant = turned(source, new VariantSpec.Rotation(0, degrees, 0));
|
||||
Set<Long> covered = new HashSet<>();
|
||||
for (TemplateBlock block : variant.volume().blocks()) {
|
||||
assertTrue(degrees + " degrees wrote a cell twice",
|
||||
covered.add(cell(anchoredX(variant, block), anchoredY(variant, block), anchoredZ(variant, block))));
|
||||
}
|
||||
double cos = Math.cos(Math.toRadians(degrees));
|
||||
double sin = Math.sin(Math.toRadians(degrees));
|
||||
int reach = Math.max(source.sizeX(), source.sizeZ());
|
||||
for (int y = 0; y < source.sizeY(); y++) {
|
||||
for (int x = -reach; x <= reach; x++) {
|
||||
for (int z = -reach; z <= reach; z++) {
|
||||
if (interior.contains(cos * x - sin * z, sin * x + cos * z)) {
|
||||
assertTrue(degrees + " degrees left a hole at " + x + "," + y + "," + z, covered.contains(cell(x, y, z)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static BakedVariant turned(TemplateVolume source, VariantSpec.Rotation rotation) {
|
||||
return new ObjectVariantBaker().bake("iris_export:object/turn/b", new ObjectSource(source, 0, TreeRoots.NONE),
|
||||
VariantSpec.builder().rotation(rotation).build());
|
||||
}
|
||||
|
||||
private static int anchoredX(BakedVariant variant, TemplateBlock block) {
|
||||
return block.x() - (variant.volume().sizeX() - 1) / 2;
|
||||
}
|
||||
|
||||
private static int anchoredY(BakedVariant variant, TemplateBlock block) {
|
||||
return block.y() + variant.baseY();
|
||||
}
|
||||
|
||||
private static int anchoredZ(BakedVariant variant, TemplateBlock block) {
|
||||
return block.z() - (variant.volume().sizeZ() - 1) / 2;
|
||||
}
|
||||
|
||||
private static TemplateVolume leafDisc(int radius, int height) {
|
||||
List<TemplateBlock> blocks = new ArrayList<>();
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = -radius; x <= radius; x++) {
|
||||
for (int z = -radius; z <= radius; z++) {
|
||||
if (x * x + z * z <= radius * radius) {
|
||||
blocks.add(block(x + radius, y, z + radius, LEAVES));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new TemplateVolume(radius * 2 + 1, height, radius * 2 + 1, blocks);
|
||||
}
|
||||
|
||||
private static TemplateVolume leafBox(int half, int height) {
|
||||
List<TemplateBlock> blocks = new ArrayList<>();
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = -half; x <= half; x++) {
|
||||
for (int z = -half; z <= half; z++) {
|
||||
blocks.add(block(x + half, y, z + half, LEAVES));
|
||||
}
|
||||
}
|
||||
}
|
||||
return new TemplateVolume(half * 2 + 1, height, half * 2 + 1, blocks);
|
||||
}
|
||||
|
||||
private static void describe(StringBuilder layout, BakedVariant variant) {
|
||||
TemplateVolume volume = variant.volume();
|
||||
layout.append(variant.id()).append(' ').append(volume.sizeX()).append('x').append(volume.sizeY()).append('x')
|
||||
.append(volume.sizeZ()).append(" base=").append(variant.baseY()).append('\n');
|
||||
for (TemplateBlock block : volume.blocks()) {
|
||||
layout.append(block.x()).append(',').append(block.y()).append(',').append(block.z()).append(' ')
|
||||
.append(block.state().canonical()).append(' ')
|
||||
.append(block.nbt() == null ? "-" : block.nbt().getString("id")).append('\n');
|
||||
}
|
||||
layout.append("roots reach=").append(variant.roots().reach()).append('\n');
|
||||
for (TemplateBlock cell : variant.roots().cells()) {
|
||||
layout.append(cell.x()).append(',').append(cell.y()).append(',').append(cell.z()).append(' ')
|
||||
.append(cell.state().canonical()).append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
private static long fnv(CharSequence text) {
|
||||
long hash = 0xcbf29ce484222325L;
|
||||
for (int index = 0; index < text.length(); index++) {
|
||||
hash ^= text.charAt(index);
|
||||
hash *= 0x100000001b3L;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
private static long cell(int x, int y, int z) {
|
||||
return (((long) x & 0x1FFFFFL) << 42) | (((long) y & 0x1FFFFFL) << 21) | ((long) z & 0x1FFFFFL);
|
||||
}
|
||||
|
||||
private static TemplateVolume tree() {
|
||||
List<TemplateBlock> blocks = new ArrayList<>();
|
||||
for (int y = 0; y < 5; y++) {
|
||||
@@ -271,4 +441,8 @@ public class ObjectVariantBakerTest {
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
private interface Interior {
|
||||
boolean contains(double x, double z);
|
||||
}
|
||||
}
|
||||
@@ -56,66 +56,6 @@ public class IrisObjectTransformsTileTest {
|
||||
IrisPlatforms.unbind();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rotationOmitsUnsupportedBlocksAndTheirTiles() {
|
||||
IrisObject source = new IrisObject(3, 1, 1);
|
||||
NativeBlockState unsupported = state("minecraft:wall_torch");
|
||||
source.setUnsigned(0, 0, 0, unsupported);
|
||||
source.setUnsignedTile(0, 0, 0, tile("minecraft:wall_torch", "omitted"));
|
||||
source.setUnsigned(1, 0, 0, state("minecraft:chest"));
|
||||
source.setUnsignedTile(1, 0, 0, tile("minecraft:chest", "kept"));
|
||||
source.setUnsigned(2, 0, 0, state("minecraft:stone"));
|
||||
IrisObjectRotation.StateRotator previous = IrisObjectRotation.bindPlatformRotator(
|
||||
(rotation, block, x, y, z) -> block == unsupported ? null : block);
|
||||
IrisObject rotated;
|
||||
try {
|
||||
rotated = source.rotateCopy(IrisObjectRotation.of(0, 90, 0));
|
||||
} finally {
|
||||
IrisObjectRotation.restorePlatformRotator(previous);
|
||||
}
|
||||
|
||||
assertEquals(2, rotated.getBlocks().size());
|
||||
assertEquals(1, rotated.getStates().size());
|
||||
for (Map.Entry<IrisBlockVector, TileData> entry : rotated.getStates()) {
|
||||
assertEquals("minecraft:chest", rotated.getBlocks().get(entry.getKey()).materialKey());
|
||||
assertEquals("kept", entry.getValue().getProperties().get("name"));
|
||||
}
|
||||
assertEquals(3, source.getBlocks().size());
|
||||
assertEquals(2, source.getStates().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fractionalRotationKeepsTileDataOnlyForTheWinningBlock() {
|
||||
IrisObject source = new IrisObject(9, 1, 9);
|
||||
for (int x = 0; x < 9; x++) {
|
||||
for (int z = 0; z < 9; z++) {
|
||||
boolean chest = (x + z) % 2 == 0;
|
||||
source.setUnsigned(x, 0, z, state(chest ? "minecraft:chest" : "minecraft:stone"));
|
||||
if (chest) {
|
||||
source.setUnsignedTile(x, 0, z, tile("minecraft:chest", x + ":" + z));
|
||||
}
|
||||
}
|
||||
}
|
||||
IrisObjectRotation.StateRotator previous = IrisObjectRotation.bindPlatformRotator(
|
||||
(rotation, block, x, y, z) -> block);
|
||||
IrisObject rotated;
|
||||
try {
|
||||
rotated = source.rotateCopy(IrisObjectRotation.of(0, 45, 0));
|
||||
} finally {
|
||||
IrisObjectRotation.restorePlatformRotator(previous);
|
||||
}
|
||||
|
||||
assertTrue(rotated.getBlocks().size() < source.getBlocks().size());
|
||||
for (Map.Entry<IrisBlockVector, TileData> entry : rotated.getStates()) {
|
||||
assertEquals("minecraft:chest", rotated.getBlocks().get(entry.getKey()).materialKey());
|
||||
}
|
||||
for (Map.Entry<IrisBlockVector, NativeBlockState> entry : rotated.getBlocks()) {
|
||||
if (entry.getValue().materialKey().equals("minecraft:chest")) {
|
||||
assertNotNull(rotated.getStates().get(entry.getKey()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scalingWaitsForMatchingGeometryAndVolume() throws Exception {
|
||||
assertConsistentScaling(false);
|
||||
|
||||
@@ -1,11 +1,23 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.generation.geometry.IrisBlockVector;
|
||||
import art.arcane.iris.pack.datapack.export.TemplateBlock;
|
||||
import art.arcane.iris.pack.datapack.export.TemplateVolume;
|
||||
import art.arcane.iris.pack.datapack.export.VanillaBlockState;
|
||||
import art.arcane.iris.pack.datapack.export.compile.object.BakedVariant;
|
||||
import art.arcane.iris.pack.datapack.export.compile.object.ObjectSource;
|
||||
import art.arcane.iris.pack.datapack.export.compile.object.ObjectVariantBaker;
|
||||
import art.arcane.iris.pack.datapack.export.compile.object.TreeRoots;
|
||||
import art.arcane.iris.pack.datapack.export.compile.object.VariantSpec;
|
||||
import art.arcane.iris.testsupport.KeyedBlockState;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
@@ -91,7 +103,11 @@ public class ObjectPlacementBakeTest {
|
||||
distinct.add(ObjectPlacementBake.Key.of(spin, false, translate));
|
||||
assertSame(first.palette(), bake.palette());
|
||||
assertTrue(object.placementBakes.size() <= 32);
|
||||
assertTransformed(object, spin, translate, bake);
|
||||
if (spin.axisAligned) {
|
||||
assertTransformed(object, spin, false, translate, bake);
|
||||
} else {
|
||||
assertResampled(object, spin, translate, bake);
|
||||
}
|
||||
if (placement == 2000) {
|
||||
settled = new HashMap<>(object.placementBakes);
|
||||
}
|
||||
@@ -104,13 +120,240 @@ public class ObjectPlacementBakeTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertTransformed(IrisObject object, SpinKernel spin, IrisBlockVector translate, ObjectPlacementBake bake) {
|
||||
@Test
|
||||
public void diagonalYawTurnsFillEverySolidInteriorCellExactlyOnce() {
|
||||
IrisObject disc = leafDisc(6, 3);
|
||||
IrisObject box = leafBox(4, 3);
|
||||
IrisObjectRotation diagonal = yawRotation(45D);
|
||||
for (int degrees : new int[]{45, 135}) {
|
||||
SpinKernel spin = new SpinKernel(diagonal, 0, degrees, 0);
|
||||
assertSolidCoverage(ObjectPlacementBake.of(disc, spin, false, null), degrees, 6, 3,
|
||||
(x, z) -> x * x + z * z <= 25D);
|
||||
assertSolidCoverage(ObjectPlacementBake.of(box, spin, false, null), degrees, 6, 3,
|
||||
(x, z) -> Math.abs(x) <= 3.75D && Math.abs(z) <= 3.75D);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diagonalYawTurnsKeepEveryThinTrunkColumn() {
|
||||
IrisObject object = new IrisObject(7, 6, 7);
|
||||
KeyedBlockState log = new KeyedBlockState("minecraft:oak_log[axis=y]");
|
||||
int[][] columns = {{2, 0}, {0, 2}, {-2, 0}, {3, 1}};
|
||||
for (int[] column : columns) {
|
||||
for (int y = 0; y < 6; y++) {
|
||||
object.getBlocks().put(new IrisBlockVector(column[0], y, column[1]), log);
|
||||
}
|
||||
}
|
||||
IrisObjectRotation diagonal = yawRotation(45D);
|
||||
for (int degrees : new int[]{45, 135, 225, 315}) {
|
||||
SpinKernel spin = new SpinKernel(diagonal, 0, degrees, 0);
|
||||
ObjectPlacementBake bake = ObjectPlacementBake.of(object, spin, false, null);
|
||||
Set<Long> covered = new HashSet<>();
|
||||
Set<Long> sampled = new HashSet<>();
|
||||
for (int index = 0; index < bake.count(); index++) {
|
||||
assertTrue(covered.add(cell(bake.offsetX(index), bake.offsetY(index), bake.offsetZ(index))));
|
||||
IrisBlockVector inverse = new IrisBlockVector(bake.offsetX(index), bake.offsetY(index), bake.offsetZ(index));
|
||||
spin.inverseRotate(inverse);
|
||||
sampled.add(cell((int) Math.round(inverse.getX()), (int) Math.round(inverse.getY()), (int) Math.round(inverse.getZ())));
|
||||
}
|
||||
for (IrisBlockVector source : object.getBlocks().keys()) {
|
||||
IrisBlockVector forward = source.clone();
|
||||
spin.rotate(forward);
|
||||
boolean represented = sampled.contains(cell(source.getBlockX(), source.getBlockY(), source.getBlockZ()))
|
||||
|| covered.contains(cell((int) Math.round(forward.getX()), (int) Math.round(forward.getY()),
|
||||
(int) Math.round(forward.getZ())));
|
||||
assertTrue(degrees + " degrees dropped trunk block " + source, represented);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quarterTurnsKeepTheForwardTransform() {
|
||||
IrisObject object = leafDisc(6, 3);
|
||||
object.getBlocks().put(new IrisBlockVector(7, 1, -2), new KeyedBlockState("minecraft:oak_log[axis=x]"));
|
||||
IrisBlockVector translate = new IrisBlockVector(1.5D, -2D, 0.25D);
|
||||
IrisObjectRotation[] rotations = {new IrisObjectRotation(), yawRotation(45D)};
|
||||
for (IrisObjectRotation rotation : rotations) {
|
||||
for (int degrees = 0; degrees < 360; degrees += 90) {
|
||||
SpinKernel spin = new SpinKernel(rotation, 0, degrees, 0);
|
||||
assertTransformed(object, spin, false, null, ObjectPlacementBake.of(object, spin, false, null));
|
||||
assertTransformed(object, spin, true, translate, ObjectPlacementBake.of(object, spin, true, translate));
|
||||
}
|
||||
}
|
||||
for (int degrees = 90; degrees < 360; degrees += 90) {
|
||||
SpinKernel spin = new SpinKernel(IrisObjectRotation.of(0D, degrees, 0D), 0, 0, 0);
|
||||
assertTransformed(object, spin, false, null, ObjectPlacementBake.of(object, spin, false, null));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void datapackVariantsMatchPlacementAtNonRightAngles() {
|
||||
IrisObject object = new IrisObject(13, 5, 13);
|
||||
KeyedBlockState leaves = new KeyedBlockState("minecraft:oak_leaves[distance=1,persistent=true]");
|
||||
for (int y = 0; y <= 2; y++) {
|
||||
for (int x = -6; x <= 6; x++) {
|
||||
for (int z = -6; z <= 6; z++) {
|
||||
if (x * x + z * z <= 36) {
|
||||
object.getBlocks().put(new IrisBlockVector(x, y, z), leaves);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int y = -2; y <= 1; y++) {
|
||||
object.getBlocks().put(new IrisBlockVector(0, y, 0), new KeyedBlockState("minecraft:oak_log[axis=y]"));
|
||||
object.getBlocks().put(new IrisBlockVector(4, y, -3), new KeyedBlockState("minecraft:birch_log[axis=y]"));
|
||||
}
|
||||
object.getBlocks().put(new IrisBlockVector(-5, 2, 2), new KeyedBlockState("minecraft:gold_block"));
|
||||
object.getBlocks().put(new IrisBlockVector(2, -2, 5), new KeyedBlockState("minecraft:stone"));
|
||||
List<TemplateBlock> blocks = new ArrayList<>();
|
||||
for (IrisBlockVector key : object.getBlocks().keys()) {
|
||||
blocks.add(new TemplateBlock(key.getBlockX() + object.getCenter().getX(), key.getBlockY() + object.getCenter().getY(),
|
||||
key.getBlockZ() + object.getCenter().getZ(), VanillaBlockState.parse(object.getBlocks().get(key).key()), null));
|
||||
}
|
||||
ObjectSource source = new ObjectSource(new TemplateVolume(object.getW(), object.getH(), object.getD(), blocks), 0,
|
||||
TreeRoots.NONE);
|
||||
double[][] angles = {{0D, 45D, 0D}, {0D, 135D, 0D}, {0D, 30D, 0D}, {20D, 45D, 0D}, {0D, 60D, 15D}};
|
||||
for (double[] angle : angles) {
|
||||
IrisObjectRotation rotation = IrisObjectRotation.of(angle[0], angle[1], angle[2]);
|
||||
SpinKernel spin = new SpinKernel(rotation, 0, 0, 0);
|
||||
ObjectPlacementBake bake = ObjectPlacementBake.of(object, spin, false, null);
|
||||
int lift = rotation.rotate(new IrisBlockVector(0, object.getCenter().getY(), 0), 0, 0, 0).getBlockY();
|
||||
Set<String> placed = new HashSet<>();
|
||||
for (int index = 0; index < bake.count(); index++) {
|
||||
String key = bake.palette()[bake.paletteIndex(index)].key();
|
||||
placed.add(bake.offsetX(index) + "," + (bake.offsetY(index) + lift) + "," + bake.offsetZ(index) + " "
|
||||
+ key.substring(0, key.indexOf('[') < 0 ? key.length() : key.indexOf('[')));
|
||||
}
|
||||
BakedVariant variant = new ObjectVariantBaker().bake("iris_export:object/parity/a", source,
|
||||
VariantSpec.builder().rotation(new VariantSpec.Rotation(angle[0], angle[1], angle[2])).build());
|
||||
Set<String> exported = new HashSet<>();
|
||||
TemplateVolume volume = variant.volume();
|
||||
for (TemplateBlock block : volume.blocks()) {
|
||||
exported.add((block.x() - (volume.sizeX() - 1) / 2) + "," + (block.y() + variant.baseY()) + ","
|
||||
+ (block.z() - (volume.sizeZ() - 1) / 2) + " " + block.state().name());
|
||||
}
|
||||
assertEquals(Arrays.toString(angle), placed, exported);
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertResampled(IrisObject object, SpinKernel spin, IrisBlockVector translate, ObjectPlacementBake bake) {
|
||||
double[] exact = bake.exact(object, spin);
|
||||
Set<Long> forward = new HashSet<>();
|
||||
for (IrisBlockVector source : object.getBlocks().keys()) {
|
||||
IrisBlockVector moved = source.clone();
|
||||
spin.rotate(moved);
|
||||
moved.add(translate);
|
||||
forward.add(cell((int) Math.round(moved.getX()), (int) Math.round(moved.getY()), (int) Math.round(moved.getZ())));
|
||||
}
|
||||
Set<Long> covered = new HashSet<>();
|
||||
Set<Long> sampled = new HashSet<>();
|
||||
for (int index = 0; index < bake.count(); index++) {
|
||||
long target = cell(bake.offsetX(index), bake.offsetY(index), bake.offsetZ(index));
|
||||
assertTrue(covered.add(target));
|
||||
IrisBlockVector inverse = new IrisBlockVector(bake.offsetX(index), bake.offsetY(index), bake.offsetZ(index));
|
||||
inverse.subtract(translate);
|
||||
spin.inverseRotate(inverse);
|
||||
IrisBlockVector nearest = new IrisBlockVector((int) Math.round(inverse.getX()), (int) Math.round(inverse.getY()),
|
||||
(int) Math.round(inverse.getZ()));
|
||||
NativeBlockState state = bake.palette()[bake.paletteIndex(index)];
|
||||
NativeBlockState nearestState = object.getBlocks().get(nearest);
|
||||
if (nearestState != null) {
|
||||
assertSame(nearestState, state);
|
||||
sampled.add(cell(nearest.getBlockX(), nearest.getBlockY(), nearest.getBlockZ()));
|
||||
} else {
|
||||
assertTrue(forward.contains(target));
|
||||
}
|
||||
assertEquals(bake.offsetY(index), bake.layerY(index));
|
||||
assertEquals(bake.offsetX(index), exact[index * 3], 0D);
|
||||
assertEquals(bake.offsetY(index), exact[index * 3 + 1], 0D);
|
||||
assertEquals(bake.offsetZ(index), exact[index * 3 + 2], 0D);
|
||||
}
|
||||
for (IrisBlockVector source : object.getBlocks().keys()) {
|
||||
IrisBlockVector moved = source.clone();
|
||||
spin.rotate(moved);
|
||||
moved.add(translate);
|
||||
assertTrue(sampled.contains(cell(source.getBlockX(), source.getBlockY(), source.getBlockZ()))
|
||||
|| covered.contains(cell((int) Math.round(moved.getX()), (int) Math.round(moved.getY()),
|
||||
(int) Math.round(moved.getZ()))));
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertSolidCoverage(ObjectPlacementBake bake, int degrees, int radius, int height, Interior interior) {
|
||||
Map<Long, Integer> covered = new HashMap<>();
|
||||
for (int index = 0; index < bake.count(); index++) {
|
||||
covered.merge(cell(bake.offsetX(index), bake.offsetY(index), bake.offsetZ(index)), 1, Integer::sum);
|
||||
}
|
||||
double cos = Math.cos(Math.toRadians(degrees));
|
||||
double sin = Math.sin(Math.toRadians(degrees));
|
||||
int reach = radius * 2;
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = -reach; x <= reach; x++) {
|
||||
for (int z = -reach; z <= reach; z++) {
|
||||
int writes = covered.getOrDefault(cell(x, y, z), 0);
|
||||
assertTrue(degrees + " degrees wrote cell " + x + "," + y + "," + z + " " + writes + " times", writes <= 1);
|
||||
if (interior.contains(cos * x - sin * z, sin * x + cos * z)) {
|
||||
assertEquals(degrees + " degrees left a hole at " + x + "," + y + "," + z, 1, writes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static long cell(int x, int y, int z) {
|
||||
return (((long) x & 0x1FFFFFL) << 42) | (((long) y & 0x1FFFFFL) << 21) | ((long) z & 0x1FFFFFL);
|
||||
}
|
||||
|
||||
private static IrisObjectRotation yawRotation(double interval) {
|
||||
IrisObjectRotation rotation = new IrisObjectRotation();
|
||||
rotation.setYAxis(new IrisAxisRotationClamp(true, false, 0D, 0D, interval));
|
||||
return rotation;
|
||||
}
|
||||
|
||||
private static IrisObject leafDisc(int radius, int height) {
|
||||
IrisObject object = new IrisObject(radius * 2 + 1, height, radius * 2 + 1);
|
||||
KeyedBlockState leaves = new KeyedBlockState("minecraft:oak_leaves[distance=1,persistent=true]");
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = -radius; x <= radius; x++) {
|
||||
for (int z = -radius; z <= radius; z++) {
|
||||
if (x * x + z * z <= radius * radius) {
|
||||
object.getBlocks().put(new IrisBlockVector(x, y, z), leaves);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
private static IrisObject leafBox(int half, int height) {
|
||||
IrisObject object = new IrisObject(half * 2 + 1, height, half * 2 + 1);
|
||||
KeyedBlockState leaves = new KeyedBlockState("minecraft:oak_leaves[distance=1,persistent=true]");
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = -half; x <= half; x++) {
|
||||
for (int z = -half; z <= half; z++) {
|
||||
object.getBlocks().put(new IrisBlockVector(x, y, z), leaves);
|
||||
}
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
private interface Interior {
|
||||
boolean contains(double x, double z);
|
||||
}
|
||||
|
||||
private static void assertTransformed(IrisObject object, SpinKernel spin, boolean ceilingHang, IrisBlockVector translate,
|
||||
ObjectPlacementBake bake) {
|
||||
double[] exact = bake.exact(object, spin);
|
||||
int index = 0;
|
||||
for (IrisBlockVector source : object.getBlocks().keys()) {
|
||||
IrisBlockVector expected = source.clone();
|
||||
spin.rotate(expected);
|
||||
expected.add(translate);
|
||||
if (ceilingHang) {
|
||||
expected.setY(-expected.getBlockY());
|
||||
}
|
||||
if (translate != null) {
|
||||
expected.add(translate);
|
||||
}
|
||||
assertEquals((int) Math.round(expected.getX()), bake.offsetX(index));
|
||||
assertEquals((int) Math.round(expected.getY()), bake.offsetY(index));
|
||||
assertEquals((int) Math.round(expected.getZ()), bake.offsetZ(index));
|
||||
|
||||
@@ -63,9 +63,9 @@ public class ObjectPlacementGoldenTest {
|
||||
|
||||
private static final int OBJECTS = 200;
|
||||
private static final int SEEDS = 5;
|
||||
private static final long GOLDEN = 0x0b870e7696a055b0L;
|
||||
private static final long MARKER_GOLDEN = 0x60b4bbf1144b239cL;
|
||||
private static final long HIGH_VARIANT_GOLDEN = 0x998044b16f7f1f6fL;
|
||||
private static final long GOLDEN = 0x930e130dc51b6f67L;
|
||||
private static final long MARKER_GOLDEN = 0x67ae55d574c3894eL;
|
||||
private static final long HIGH_VARIANT_GOLDEN = 0xdd61791b0f7e4d37L;
|
||||
|
||||
private static final List<String> PALETTE = List.of(
|
||||
"minecraft:stone",
|
||||
|
||||
@@ -297,21 +297,6 @@ public class TreeGroundingPlacementTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rotatedCopiesKeepMetadataOnTheirActualRootBlocks() {
|
||||
IrisObject source = tree(true);
|
||||
Map<Position, NativeBlockState> original = snapshot(source);
|
||||
TreeGrounding grounding = source.getTreeGrounding();
|
||||
for (int angle : new int[]{45, 90, 180, 270}) {
|
||||
IrisObject rotated = source.rotateCopy(IrisObjectRotation.of(0, angle, 0));
|
||||
|
||||
assertGroundingMatchesBlocks(rotated);
|
||||
assertEquals(3, rotated.getTreeGrounding().maxExtension());
|
||||
assertEquals(original, snapshot(source));
|
||||
assertSame(grounding, source.getTreeGrounding());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shrinkwrapMovesRootMetadataAndInvalidatesItsFootprint() {
|
||||
IrisObject source = tree(true);
|
||||
@@ -397,7 +382,6 @@ public class TreeGroundingPlacementTest {
|
||||
IrisObject shrunk = source.copy();
|
||||
shrunk.shrinkwrap();
|
||||
for (IrisObject transformed : List.of(source.copy(), shrunk,
|
||||
source.rotateCopy(IrisObjectRotation.of(0, 90, 0)),
|
||||
source.scaled(2, IrisObjectPlacementScaleInterpolator.NONE),
|
||||
source.scaledAroundOrigin(2, IrisObjectPlacementScaleInterpolator.NONE))) {
|
||||
assertGroundingMatchesBlocks(transformed);
|
||||
|
||||
Reference in new issue
Block a user