mirror of
https://github.com/GTNewHorizons/GTNHLib.git
synced 2026-11-28 07:35:51 +00:00
Spotless
This commit is contained in:
1 parent
1a8dae7902
commit
17fa2daf32
53 files changed
+513
-335
No files matched your search
@@ -1,5 +1,11 @@
|
||||
package com.gtnewhorizon.gtnhlib;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraftforge.client.ClientCommandHandler;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.model.ModelISBRH;
|
||||
import com.gtnewhorizon.gtnhlib.client.tooltip.LoreHandler;
|
||||
import com.gtnewhorizon.gtnhlib.commands.ItemInHandCommand;
|
||||
@@ -8,6 +14,7 @@ import com.gtnewhorizon.gtnhlib.compat.Mods;
|
||||
import com.gtnewhorizon.gtnhlib.compat.NotEnoughItemsVersionChecker;
|
||||
import com.gtnewhorizon.gtnhlib.eventbus.EventBusSubscriber;
|
||||
import com.gtnewhorizon.gtnhlib.util.AboveHotbarHUD;
|
||||
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
@@ -15,11 +22,6 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraftforge.client.ClientCommandHandler;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@EventBusSubscriber(side = Side.CLIENT)
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package com.gtnewhorizon.gtnhlib;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.block.BlockTest;
|
||||
import com.gtnewhorizon.gtnhlib.config.ConfigException;
|
||||
import com.gtnewhorizon.gtnhlib.config.ConfigurationManager;
|
||||
@@ -10,6 +16,7 @@ import com.gtnewhorizon.gtnhlib.keybind.SyncedKeybind;
|
||||
import com.gtnewhorizon.gtnhlib.network.NetworkHandler;
|
||||
import com.gtnewhorizon.gtnhlib.network.PacketMessageAboveHotbar;
|
||||
import com.gtnewhorizon.gtnhlib.network.PacketViewDistance;
|
||||
|
||||
import cpw.mods.fml.common.event.FMLConstructionEvent;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
@@ -22,11 +29,6 @@ import cpw.mods.fml.common.event.FMLServerStoppingEvent;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
@EventBusSubscriber
|
||||
public class CommonProxy {
|
||||
@@ -44,7 +46,7 @@ public class CommonProxy {
|
||||
GTNHLib.LOG.error("Failed to register GTNHLib config!", e);
|
||||
}
|
||||
|
||||
if (GTNHLibConfig.enableTestBlocks){
|
||||
if (GTNHLibConfig.enableTestBlocks) {
|
||||
GameRegistry.registerBlock(new BlockTest(), "model_test");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.gtnewhorizon.gtnhlib.block;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.model.ModelISBRH;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.model.ModelISBRH;
|
||||
|
||||
public class BlockTest extends Block {
|
||||
|
||||
public BlockTest() {
|
||||
super(Material.wood);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.gtnewhorizon.gtnhlib.block;
|
||||
|
||||
import java.util.concurrent.locks.StampedLock;
|
||||
|
||||
import it.unimi.dsi.fastutil.Function;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ReferenceLinkedOpenHashMap;
|
||||
import java.util.concurrent.locks.StampedLock;
|
||||
|
||||
/**
|
||||
* Borrowed from ModernFix, because 7.10 can't embed models in blocks easily
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.model;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
@@ -12,6 +10,9 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
|
||||
public interface BakedModel {
|
||||
|
||||
int R_MASK = 0xFF << 16;
|
||||
@@ -44,18 +45,18 @@ public interface BakedModel {
|
||||
/// Provide quads to render. If you need new quads, they should be obtained with the passed supplier,
|
||||
/// [#isDynamic] should be overridden to return true, and you should not keep references to the quads.
|
||||
///
|
||||
/// @param world The world the model is in. Null if not applicable, like in inventory rendering.
|
||||
/// @param x The x-position of the model.
|
||||
/// @param y The y-position of the model.
|
||||
/// @param z The z-position of the model.
|
||||
/// @param block The block to be rendered.
|
||||
/// @param meta The meta value of the rendered object.
|
||||
/// @param dir The direction to get quads from - the returned quads should have the same facing.
|
||||
/// @param random A RNG to use.
|
||||
/// @param color The ABGR packed color to use.
|
||||
/// @param world The world the model is in. Null if not applicable, like in inventory rendering.
|
||||
/// @param x The x-position of the model.
|
||||
/// @param y The y-position of the model.
|
||||
/// @param z The z-position of the model.
|
||||
/// @param block The block to be rendered.
|
||||
/// @param meta The meta value of the rendered object.
|
||||
/// @param dir The direction to get quads from - the returned quads should have the same facing.
|
||||
/// @param random A RNG to use.
|
||||
/// @param color The ABGR packed color to use.
|
||||
/// @param quadPool If [#isDynamic()], the pool to obtain quads from and where the quads should be released
|
||||
/// after use. Ignored otherwise.
|
||||
/// after use. Ignored otherwise.
|
||||
/// @return A list of quads from the model. These are *not* adjusted for the given xyz - that is up to the renderer.
|
||||
List<ModelQuadView> getQuads(@Nullable IBlockAccess world, int x, int y, int z, Block block, int meta,
|
||||
ForgeDirection dir, Random random, int color, @Nullable Supplier<ModelQuadViewMutable> quadPool);
|
||||
ForgeDirection dir, Random random, int color, @Nullable Supplier<ModelQuadViewMutable> quadPool);
|
||||
}
|
||||
@@ -2,11 +2,12 @@ package com.gtnewhorizon.gtnhlib.client.model;
|
||||
|
||||
import static java.lang.Math.toRadians;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.loading.ResourceLoc;
|
||||
import org.jetbrains.annotations.ApiStatus.Internal;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.loading.ResourceLoc;
|
||||
|
||||
/**
|
||||
* Largely mirrors Minecraft's format for specifying models, except we use radians instead of degrees.
|
||||
*
|
||||
@@ -31,7 +32,7 @@ public record JSONVariant(ResourceLoc.ModelLoc model, float x, float y, float z,
|
||||
/// @param weight Used when selecting models. Irrelevant when only one variant is allowed, but must always be
|
||||
/// greater than zero.
|
||||
public static Weighted<JSONVariant> weightedVariant(ResourceLoc.ModelLoc model, int x, int y, int z, boolean uvLock,
|
||||
int weight) {
|
||||
int weight) {
|
||||
final var v = new JSONVariant(model, x, y, z, uvLock);
|
||||
return new Weighted<>(v, weight);
|
||||
}
|
||||
|
||||
@@ -4,15 +4,9 @@ import static com.gtnewhorizon.gtnhlib.client.renderer.util.NormI8.unpackX;
|
||||
import static com.gtnewhorizon.gtnhlib.client.renderer.util.NormI8.unpackY;
|
||||
import static com.gtnewhorizon.gtnhlib.client.renderer.util.NormI8.unpackZ;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.block.BlockState;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.loading.ModelRegistry;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.util.DirectionUtil;
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
@@ -20,9 +14,20 @@ import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.block.BlockState;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.loading.ModelRegistry;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.util.DirectionUtil;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
|
||||
public class ModelISBRH implements ISimpleBlockRenderingHandler {
|
||||
|
||||
/**
|
||||
* Any blocks using a JSON model should return this for {@link Block#getRenderType()}.
|
||||
*/
|
||||
@@ -45,7 +50,8 @@ public class ModelISBRH implements ISimpleBlockRenderingHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId,
|
||||
RenderBlocks renderer) {
|
||||
final Random random = world instanceof World worldIn ? worldIn.rand : RAND;
|
||||
final Tessellator tesselator = Tessellator.instance;
|
||||
final Supplier<ModelQuadViewMutable> sq = null;
|
||||
@@ -90,14 +96,15 @@ public class ModelISBRH implements ISimpleBlockRenderingHandler {
|
||||
return rendered;
|
||||
}
|
||||
|
||||
protected void renderQuad(ModelQuadView quad, float x, float y, float z, Tessellator tessellator, @Nullable IIcon overrideIcon) {
|
||||
protected void renderQuad(ModelQuadView quad, float x, float y, float z, Tessellator tessellator,
|
||||
@Nullable IIcon overrideIcon) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
tessellator.addVertexWithUV(
|
||||
quad.getX(i) + x,
|
||||
quad.getY(i) + y,
|
||||
quad.getZ(i) + z,
|
||||
quad.getTexU(i),
|
||||
quad.getTexV(i));
|
||||
quad.getX(i) + x,
|
||||
quad.getY(i) + y,
|
||||
quad.getZ(i) + z,
|
||||
quad.getTexU(i),
|
||||
quad.getTexV(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.model.baked;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
@@ -15,6 +13,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.BakedModel;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.Weighted;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
@@ -23,7 +23,7 @@ public record MonopartModel(ObjectArrayList<Weighted<BakedModel>> models) implem
|
||||
|
||||
@Override
|
||||
public List<ModelQuadView> getQuads(@Nullable IBlockAccess world, int x, int y, int z, Block block, int meta,
|
||||
ForgeDirection dir, Random random, int color, @Nullable Supplier<ModelQuadViewMutable> quadPool) {
|
||||
ForgeDirection dir, Random random, int color, @Nullable Supplier<ModelQuadViewMutable> quadPool) {
|
||||
return Weighted.selectOne(models, random).getQuads(world, x, y, z, block, meta, dir, random, color, quadPool);
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@ package com.gtnewhorizon.gtnhlib.client.model.baked;
|
||||
|
||||
import static it.unimi.dsi.fastutil.objects.Object2ObjectMaps.unmodifiable;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -19,6 +17,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.BakedModel;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.state.MultipartState.Case.Condition;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
|
||||
@@ -34,7 +34,7 @@ public record MultipartModel(UnmodifiableMap<Condition, BakedModel> piles) imple
|
||||
|
||||
@Override
|
||||
public List<ModelQuadView> getQuads(@Nullable IBlockAccess world, int x, int y, int z, Block block, int meta,
|
||||
ForgeDirection dir, Random random, int color, @Nullable Supplier<ModelQuadViewMutable> quadPool) {
|
||||
ForgeDirection dir, Random random, int color, @Nullable Supplier<ModelQuadViewMutable> quadPool) {
|
||||
final var quads = new ObjectArrayList<ModelQuadView>();
|
||||
Object2ObjectMaps.fastForEach(piles, e -> {
|
||||
if (e.getKey().matches(stateMap(meta)))
|
||||
|
||||
@@ -8,9 +8,6 @@ import static com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties
|
||||
import static com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing.POS_Z;
|
||||
import static com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing.UNASSIGNED;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -26,6 +23,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.BakedModel;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectImmutableList;
|
||||
|
||||
@@ -40,7 +40,7 @@ public record PileOfQuads(SidedQuadStore sidedQuadStore) implements BakedModel {
|
||||
|
||||
@Override
|
||||
public List<ModelQuadView> getQuads(@Nullable IBlockAccess world, int x, int y, int z, Block block, int meta,
|
||||
ForgeDirection dir, Random random, int color, @Nullable Supplier<ModelQuadViewMutable> quadPool) {
|
||||
ForgeDirection dir, Random random, int color, @Nullable Supplier<ModelQuadViewMutable> quadPool) {
|
||||
return sidedQuadStore.getQuads(dir);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,21 @@ import static java.lang.Math.max;
|
||||
import static java.lang.Math.min;
|
||||
import static org.joml.Math.fma;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.BakeData;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.BakedModel;
|
||||
@@ -14,20 +29,9 @@ import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuad;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
public class JSONModel implements UnbakedModel {
|
||||
|
||||
@@ -46,8 +50,8 @@ public class JSONModel implements UnbakedModel {
|
||||
private static final Vector4f DEFAULT_UV = new Vector4f(0, 0, 16, 16);
|
||||
|
||||
public JSONModel(@Nullable ResourceLoc.ModelLoc parentId, boolean useAO,
|
||||
Map<ModelDisplay.Position, ModelDisplay> display, @NotNull Map<String, String> textures,
|
||||
List<ModelElement> elements) {
|
||||
Map<ModelDisplay.Position, ModelDisplay> display, @NotNull Map<String, String> textures,
|
||||
List<ModelElement> elements) {
|
||||
this.parentId = parentId;
|
||||
this.useAO = useAO;
|
||||
this.display = display;
|
||||
@@ -154,8 +158,7 @@ public class JSONModel implements UnbakedModel {
|
||||
final var quad = new ModelQuad();
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
|
||||
final Vector3f vert = mapSideToVertex(from, to, i, f.getName()).mulPosition(rot)
|
||||
.mulPosition(vRot);
|
||||
final Vector3f vert = mapSideToVertex(from, to, i, f.getName()).mulPosition(rot).mulPosition(vRot);
|
||||
quad.setX(i, vert.x);
|
||||
quad.setY(i, vert.y);
|
||||
quad.setZ(i, vert.z);
|
||||
@@ -175,10 +178,10 @@ public class JSONModel implements UnbakedModel {
|
||||
// Set UV
|
||||
// TODO: UV locking
|
||||
final Vector4f uv = Objects.firstNonNull(f.getUv(), DEFAULT_UV);
|
||||
setUV(quad,0, uv.x, uv.y);
|
||||
setUV(quad,1, uv.x, uv.w);
|
||||
setUV(quad,2, uv.z, uv.w);
|
||||
setUV(quad,3, uv.z, uv.y);
|
||||
setUV(quad, 0, uv.x, uv.y);
|
||||
setUV(quad, 1, uv.x, uv.w);
|
||||
setUV(quad, 2, uv.z, uv.w);
|
||||
setUV(quad, 3, uv.z, uv.y);
|
||||
|
||||
// Set the sprite
|
||||
bakeSprite(quad, this.textures.get(f.getTexture()));
|
||||
|
||||
@@ -2,9 +2,10 @@ package com.gtnewhorizon.gtnhlib.client.model.json;
|
||||
|
||||
import static com.gtnewhorizon.gtnhlib.client.model.baked.PileOfQuads.BLANK;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.model.BakeData;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.BakedModel;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MissingModel extends JSONModel {
|
||||
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.model.json;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
@@ -10,14 +19,9 @@ import com.gtnewhorizon.gtnhlib.client.model.loading.ResourceLoc;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.quad.Axis;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.util.DirectionUtil;
|
||||
import com.gtnewhorizon.gtnhlib.util.JsonUtil;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
public class ModelDeserializer implements JsonDeserializer<JSONModel> {
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.gtnewhorizon.gtnhlib.client.model.loading;
|
||||
|
||||
import static com.gtnewhorizon.gtnhlib.client.model.json.MissingModel.MISSING_MODEL;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
@@ -13,15 +15,16 @@ import com.gtnewhorizon.gtnhlib.client.model.json.ModelDeserializer;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.state.MissingState;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.state.StateDeserializer;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.state.StateModelMap;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
/// Handles model loading and caching. All caches are size-based - this means that if a model has enough parents, it may
|
||||
/// exhaust the caches and unload itself before being fully baked. There *probably* won't be any consequences for this
|
||||
/// beyond excessively complex models being loaded multiple times... add a counter if I'm wrong.
|
||||
public class ModelRegistry {
|
||||
|
||||
private static Gson GSON = new GsonBuilder().registerTypeAdapter(StateModelMap.class, new StateDeserializer())
|
||||
.registerTypeAdapter(JSONModel.class, new ModelDeserializer()).create();
|
||||
.registerTypeAdapter(JSONModel.class, new ModelDeserializer()).create();
|
||||
|
||||
/// The first cache. Ideally, every request hits this and gets a baked model.
|
||||
private static final ThreadsafeCache<BlockState, BakedModel> BLOCKSTATE_MODEL_CACHE = new ThreadsafeCache<>(
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.model.loading;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import com.google.gson.Gson;
|
||||
import com.gtnewhorizon.gtnhlib.GTNHLib;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.json.JSONModel;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.state.StateModelMap;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.function.Supplier;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ResourceLoc<T> {
|
||||
|
||||
@@ -40,6 +43,7 @@ public interface ResourceLoc<T> {
|
||||
|
||||
@Desugar
|
||||
record ModelLoc(String owner, String path) implements ResourceLoc<JSONModel> {
|
||||
|
||||
public static ModelLoc fromStr(String id) {
|
||||
final int sepIdx = id.indexOf(':');
|
||||
if (sepIdx < 0) return new ModelLoc("minecraft", id);
|
||||
@@ -64,6 +68,7 @@ public interface ResourceLoc<T> {
|
||||
|
||||
@Desugar
|
||||
record StateLoc(String owner, String path) implements ResourceLoc<StateModelMap> {
|
||||
|
||||
@Override
|
||||
public String prefix() {
|
||||
return "blockstates/";
|
||||
|
||||
@@ -7,6 +7,10 @@ import static com.gtnewhorizon.gtnhlib.util.JsonUtil.loadBool;
|
||||
import static com.gtnewhorizon.gtnhlib.util.JsonUtil.loadInt;
|
||||
import static com.gtnewhorizon.gtnhlib.util.JsonUtil.loadStr;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
@@ -19,12 +23,11 @@ import com.gtnewhorizon.gtnhlib.client.model.state.MultipartState.Case;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.state.MultipartState.Case.Condition;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.state.MultipartState.Case.MultiCon;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.state.MultipartState.Case.StateCon;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectList;
|
||||
import java.lang.reflect.Type;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class StateDeserializer implements JsonDeserializer<StateModelMap> {
|
||||
|
||||
|
||||
@@ -8,14 +8,6 @@ import static com.gtnewhorizon.gtnhlib.client.renderer.cel.util.ModelQuadUtil.TE
|
||||
import static com.gtnewhorizon.gtnhlib.client.renderer.cel.util.ModelQuadUtil.vertexOffset;
|
||||
import static net.minecraft.util.MathHelper.clamp_int;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.blockpos.BlockPos;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuad;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.quad.TessFlags;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.stacks.Vector3dStack;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.vertex.VertexFormat;
|
||||
import com.gtnewhorizon.gtnhlib.util.ObjectPooler;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -23,10 +15,22 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.blockpos.BlockPos;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuad;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.quad.TessFlags;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.stacks.Vector3dStack;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.vertex.VertexFormat;
|
||||
import com.gtnewhorizon.gtnhlib.util.ObjectPooler;
|
||||
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/// To be used in conjunction with the {@link TessellatorManager}. Used to capture the quads generated by the
|
||||
/// {@link Tessellator} across multiple draw calls and make the quad list available for usage.
|
||||
///
|
||||
@@ -110,14 +114,7 @@ public class CapturingTessellator extends Tessellator implements ITessellatorIns
|
||||
if (empty(srcOffset)) continue;
|
||||
|
||||
final ModelQuad quad = quadBuf.getInstance();
|
||||
quad.setState(
|
||||
this.rawBuffer,
|
||||
srcOffset,
|
||||
FLAGS,
|
||||
this.drawMode,
|
||||
-offset.x,
|
||||
-offset.y,
|
||||
-offset.z);
|
||||
quad.setState(this.rawBuffer, srcOffset, FLAGS, this.drawMode, -offset.x, -offset.y, -offset.z);
|
||||
quad.setShaderBlockId(shaderBlockId);
|
||||
this.collectedQuads.add(quad);
|
||||
}
|
||||
@@ -128,8 +125,7 @@ public class CapturingTessellator extends Tessellator implements ITessellatorIns
|
||||
}
|
||||
|
||||
private boolean empty(int srcOffset) {
|
||||
return dataX(srcOffset, 0) == dataX(srcOffset, 1)
|
||||
&& dataX(srcOffset, 1) == dataX(srcOffset, 2)
|
||||
return dataX(srcOffset, 0) == dataX(srcOffset, 1) && dataX(srcOffset, 1) == dataX(srcOffset, 2)
|
||||
&& dataX(srcOffset, 2) == dataX(srcOffset, 3)
|
||||
&& dataY(srcOffset, 0) == dataY(srcOffset, 1)
|
||||
&& dataY(srcOffset, 1) == dataY(srcOffset, 2)
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuad;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.vbo.VertexBuffer;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.vertex.VertexFormat;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class TessellatorManager {
|
||||
|
||||
+21
-15
@@ -1,14 +1,15 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.api.util;
|
||||
|
||||
/**
|
||||
* Provides some utilities for packing and unpacking color components from packed integer colors in ABGR format, which
|
||||
* is used by OpenGL for color vectors.
|
||||
*
|
||||
* | 32 | 24 | 16 | 8 |
|
||||
* | 0110 1100 | 0110 1100 | 0110 1100 | 0110 1100 |
|
||||
* | Alpha | Blue | Green | Red |
|
||||
*/
|
||||
/// Provides some utilities for packing and unpacking color components from packed integer colors in ABGR format, which
|
||||
/// is used by OpenGL for color vectors.
|
||||
///
|
||||
/// |||||
|
||||
/// | --------- | --------- | --------- | ---------- |
|
||||
/// | 32 | 24 | 16 | 8 |
|
||||
/// | 0110 1100 | 0110 1100 | 0110 1100 | 0110 1100 |
|
||||
/// | Alpha | Blue | Green | Red |
|
||||
public class ColorABGR implements ColorU8 {
|
||||
|
||||
private static final int RED_COMPONENT_OFFSET = 0;
|
||||
private static final int GREEN_COMPONENT_OFFSET = 8;
|
||||
private static final int BLUE_COMPONENT_OFFSET = 16;
|
||||
@@ -16,6 +17,7 @@ public class ColorABGR implements ColorU8 {
|
||||
|
||||
/**
|
||||
* Packs the specified color components into ABGR format. The alpha component is fully opaque.
|
||||
*
|
||||
* @param r The red component of the color
|
||||
* @param g The green component of the color
|
||||
* @param b The blue component of the color
|
||||
@@ -26,21 +28,22 @@ public class ColorABGR implements ColorU8 {
|
||||
|
||||
/**
|
||||
* Packs the specified color components into ABGR format.
|
||||
*
|
||||
* @param r The red component of the color
|
||||
* @param g The green component of the color
|
||||
* @param b The blue component of the color
|
||||
* @param a The alpha component of the color
|
||||
*/
|
||||
public static int pack(int r, int g, int b, int a) {
|
||||
return ((a & COMPONENT_MASK) << ALPHA_COMPONENT_OFFSET) |
|
||||
((b & COMPONENT_MASK) << BLUE_COMPONENT_OFFSET) |
|
||||
((g & COMPONENT_MASK) << GREEN_COMPONENT_OFFSET) |
|
||||
((r & COMPONENT_MASK) << RED_COMPONENT_OFFSET);
|
||||
return ((a & COMPONENT_MASK) << ALPHA_COMPONENT_OFFSET) | ((b & COMPONENT_MASK) << BLUE_COMPONENT_OFFSET)
|
||||
| ((g & COMPONENT_MASK) << GREEN_COMPONENT_OFFSET)
|
||||
| ((r & COMPONENT_MASK) << RED_COMPONENT_OFFSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Packs the specified color components into ABGR format.
|
||||
* @param rgb The red/green/blue component of the color
|
||||
*
|
||||
* @param rgb The red/green/blue component of the color
|
||||
* @param alpha The alpha component of the color
|
||||
*/
|
||||
public static int withAlpha(int rgb, float alpha) {
|
||||
@@ -49,7 +52,8 @@ public class ColorABGR implements ColorU8 {
|
||||
|
||||
/**
|
||||
* Packs the specified color components into ABGR format.
|
||||
* @param rgb The red/green/blue component of the color
|
||||
*
|
||||
* @param rgb The red/green/blue component of the color
|
||||
* @param alpha The alpha component of the color
|
||||
*/
|
||||
public static int withAlpha(int rgb, int alpha) {
|
||||
@@ -58,10 +62,12 @@ public class ColorABGR implements ColorU8 {
|
||||
|
||||
/**
|
||||
* Converts the color components from normalized floating point into a packed integer in ABGR format.
|
||||
*
|
||||
* @see ColorABGR#pack(int, int, int, int)
|
||||
*/
|
||||
public static int pack(float r, float g, float b, float a) {
|
||||
return pack(ColorU8.normalizedFloatToByte(r),
|
||||
return pack(
|
||||
ColorU8.normalizedFloatToByte(r),
|
||||
ColorU8.normalizedFloatToByte(g),
|
||||
ColorU8.normalizedFloatToByte(b),
|
||||
ColorU8.normalizedFloatToByte(a));
|
||||
|
||||
+19
-16
@@ -1,15 +1,16 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.api.util;
|
||||
|
||||
/**
|
||||
* Provides some utilities for packing and unpacking color components from packed integer colors in ARGB format. This
|
||||
* packed format is used by most of Minecraft, but special care must be taken to pack it into ABGR format before passing
|
||||
* it to OpenGL attributes.
|
||||
*
|
||||
* | 32 | 24 | 16 | 8 |
|
||||
* | 0110 1100 | 0110 1100 | 0110 1100 | 0110 1100 |
|
||||
* | Alpha | Red | Green | Blue |
|
||||
*/
|
||||
/// Provides some utilities for packing and unpacking color components from packed integer colors in ARGB format. This
|
||||
/// packed format is used by most of Minecraft, but special care must be taken to pack it into ABGR format before passing
|
||||
/// it to OpenGL attributes.
|
||||
///
|
||||
/// |||||
|
||||
/// | --------- | --------- | --------- | ---------- |
|
||||
/// | 32 | 24 | 16 | 8 |
|
||||
/// | 0110 1100 | 0110 1100 | 0110 1100 | 0110 1100 |
|
||||
/// | Alpha | Red | Green | Blue |
|
||||
public class ColorARGB implements ColorU8 {
|
||||
|
||||
private static final int ALPHA_COMPONENT_OFFSET = 24;
|
||||
private static final int RED_COMPONENT_OFFSET = 16;
|
||||
private static final int GREEN_COMPONENT_OFFSET = 8;
|
||||
@@ -17,21 +18,22 @@ public class ColorARGB implements ColorU8 {
|
||||
|
||||
/**
|
||||
* Packs the specified color components into big-endian format for consumption by OpenGL.
|
||||
*
|
||||
* @param r The red component of the color
|
||||
* @param g The green component of the color
|
||||
* @param b The blue component of the color
|
||||
* @param a The alpha component of the color
|
||||
*/
|
||||
public static int pack(int r, int g, int b, int a) {
|
||||
return (a & COMPONENT_MASK) << ALPHA_COMPONENT_OFFSET |
|
||||
(r & COMPONENT_MASK) << RED_COMPONENT_OFFSET |
|
||||
(g & COMPONENT_MASK) << GREEN_COMPONENT_OFFSET |
|
||||
(b & COMPONENT_MASK) << BLUE_COMPONENT_OFFSET;
|
||||
return (a & COMPONENT_MASK) << ALPHA_COMPONENT_OFFSET | (r & COMPONENT_MASK) << RED_COMPONENT_OFFSET
|
||||
| (g & COMPONENT_MASK) << GREEN_COMPONENT_OFFSET
|
||||
| (b & COMPONENT_MASK) << BLUE_COMPONENT_OFFSET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Packs the specified color components into big-endian format for consumption by OpenGL. The alpha
|
||||
* channel is fully opaque.
|
||||
* Packs the specified color components into big-endian format for consumption by OpenGL. The alpha channel is fully
|
||||
* opaque.
|
||||
*
|
||||
* @param r The red component of the color
|
||||
* @param g The green component of the color
|
||||
* @param b The blue component of the color
|
||||
@@ -85,7 +87,8 @@ public class ColorARGB implements ColorU8 {
|
||||
|
||||
/**
|
||||
* Packs the specified color components into ARGB format.
|
||||
* @param rgb The red/green/blue component of the color
|
||||
*
|
||||
* @param rgb The red/green/blue component of the color
|
||||
* @param alpha The alpha component of the color
|
||||
*/
|
||||
public static int withAlpha(int rgb, int alpha) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.api.util;
|
||||
|
||||
public interface ColorU8 {
|
||||
|
||||
/**
|
||||
* The number of bits used for each color component.
|
||||
*/
|
||||
@@ -23,6 +24,7 @@ public interface ColorU8 {
|
||||
|
||||
/**
|
||||
* Converts a normalized float to an integer component.
|
||||
*
|
||||
* @param value The floating point value in the range of 0.0..1.0
|
||||
* @return The integer component of the floating point value in 0..255 range
|
||||
*/
|
||||
@@ -32,6 +34,7 @@ public interface ColorU8 {
|
||||
|
||||
/**
|
||||
* Converts an integer component to a normalized floating point value.
|
||||
*
|
||||
* @param value The integer component in 0..255 range
|
||||
* @return The floating point value of the integer component in the range of 0.0..1.0
|
||||
*/
|
||||
|
||||
@@ -3,15 +3,16 @@ package com.gtnewhorizon.gtnhlib.client.renderer.cel.api.util;
|
||||
import org.joml.Math;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
/**
|
||||
* Provides some utilities for working with packed normal vectors. Each normal component provides 8 bits of
|
||||
* precision in the range of [-1.0,1.0].
|
||||
*
|
||||
* | 32 | 24 | 16 | 8 |
|
||||
* | 0000 0000 | 0110 1100 | 0110 1100 | 0110 1100 |
|
||||
* | Padding | X | Y | Z |
|
||||
*/
|
||||
/// Provides some utilities for working with packed normal vectors. Each normal component provides 8 bits of precision in
|
||||
/// the range of \[-1.0,1.0].
|
||||
///
|
||||
/// |||||
|
||||
/// | --------- | --------- | --------- | ---------- |
|
||||
/// | 32 | 24 | 16 | 8 |
|
||||
/// | 0000 0000 | 0110 1100 | 0110 1100 | 0110 1100 |
|
||||
/// | Padding | X | Y | Z |
|
||||
public class NormI8 {
|
||||
|
||||
private static final int X_COMPONENT_OFFSET = 0;
|
||||
private static final int Y_COMPONENT_OFFSET = 8;
|
||||
private static final int Z_COMPONENT_OFFSET = 16;
|
||||
@@ -34,6 +35,7 @@ public class NormI8 {
|
||||
/**
|
||||
* Packs the specified vector components into a 32-bit integer in XYZ ordering with the 8 bits of padding at the
|
||||
* end.
|
||||
*
|
||||
* @param x The x component of the normal's vector
|
||||
* @param y The y component of the normal's vector
|
||||
* @param z The z component of the normal's vector
|
||||
@@ -57,6 +59,7 @@ public class NormI8 {
|
||||
|
||||
/**
|
||||
* Unpacks the x-component of the packed normal, denormalizing it to a float in the range of -1.0..1.0.
|
||||
*
|
||||
* @param norm The packed normal
|
||||
*/
|
||||
public static float unpackX(int norm) {
|
||||
@@ -65,6 +68,7 @@ public class NormI8 {
|
||||
|
||||
/**
|
||||
* Unpacks the y-component of the packed normal, denormalizing it to a float in the range of -1.0..1.0.
|
||||
*
|
||||
* @param norm The packed normal
|
||||
*/
|
||||
public static float unpackY(int norm) {
|
||||
@@ -73,6 +77,7 @@ public class NormI8 {
|
||||
|
||||
/**
|
||||
* Unpacks the z-component of the packed normal, denormalizing it to a float in the range of -1.0..1.0.
|
||||
*
|
||||
* @param norm The packed normal
|
||||
*/
|
||||
public static float unpackZ(int norm) {
|
||||
|
||||
+9
-6
@@ -3,6 +3,7 @@ package com.gtnewhorizon.gtnhlib.client.renderer.cel.gl.attribute;
|
||||
import lombok.Getter;
|
||||
|
||||
public class GlVertexAttribute {
|
||||
|
||||
@Getter
|
||||
private final GlVertexAttributeFormat format;
|
||||
@Getter
|
||||
@@ -21,17 +22,19 @@ public class GlVertexAttribute {
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* @param format The format used
|
||||
* @param count The number of components in the vertex attribute
|
||||
* @param format The format used
|
||||
* @param count The number of components in the vertex attribute
|
||||
* @param normalized Specifies whether or not fixed-point data values should be normalized (true) or used directly
|
||||
* as fixed-point values (false)
|
||||
* @param pointer The offset to the first component in the attribute
|
||||
* as fixed-point values (false)
|
||||
* @param pointer The offset to the first component in the attribute
|
||||
*/
|
||||
public GlVertexAttribute(GlVertexAttributeFormat format, String name, int count, boolean normalized, int pointer, int stride, boolean intType) {
|
||||
public GlVertexAttribute(GlVertexAttributeFormat format, String name, int count, boolean normalized, int pointer,
|
||||
int stride, boolean intType) {
|
||||
this(format, format.size() * count, count, name, normalized, pointer, stride, intType);
|
||||
}
|
||||
|
||||
protected GlVertexAttribute(GlVertexAttributeFormat format, int size, int count, String name, boolean normalized, int pointer, int stride, boolean intType) {
|
||||
protected GlVertexAttribute(GlVertexAttributeFormat format, int size, int count, String name, boolean normalized,
|
||||
int pointer, int stride, boolean intType) {
|
||||
this.format = format;
|
||||
this.size = size;
|
||||
this.count = count;
|
||||
|
||||
+1
@@ -14,6 +14,7 @@ import com.github.bsideup.jabel.Desugar;
|
||||
*/
|
||||
@Desugar
|
||||
public record GlVertexAttributeFormat(int typeId, int size) {
|
||||
|
||||
public static final GlVertexAttributeFormat FLOAT = new GlVertexAttributeFormat(GL_FLOAT, 4);
|
||||
public static final GlVertexAttributeFormat SHORT = new GlVertexAttributeFormat(GL_SHORT, 2);
|
||||
public static final GlVertexAttributeFormat UNSIGNED_SHORT = new GlVertexAttributeFormat(GL_UNSIGNED_SHORT, 2);
|
||||
|
||||
+34
-12
@@ -1,18 +1,20 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.gl.attribute;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ReferenceLinkedOpenHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ReferenceLinkedOpenHashMap;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
/**
|
||||
* Provides a generic vertex format which contains attributes. Other code can then retrieve
|
||||
* the attributes and work with encoded data in a generic manner without needing to rely on a specific format.
|
||||
* Provides a generic vertex format which contains attributes. Other code can then retrieve the attributes and work with
|
||||
* encoded data in a generic manner without needing to rely on a specific format.
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class GlVertexFormat {
|
||||
|
||||
/**
|
||||
* Magic value that will have GlVertexFormat calculate the next pointer to use.
|
||||
*/
|
||||
@@ -32,6 +34,7 @@ public class GlVertexFormat {
|
||||
|
||||
/**
|
||||
* Returns the {@link GlVertexAttribute} of this vertex format bound to the type {@param name}.
|
||||
*
|
||||
* @throws NullPointerException If the attribute does not exist in this format
|
||||
*/
|
||||
public GlVertexAttribute getAttribute(String name) {
|
||||
@@ -57,11 +60,11 @@ public class GlVertexFormat {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("GlVertexFormat{attributes=%d,stride=%d}",
|
||||
this.attributesKeyed.size(), this.stride);
|
||||
return String.format("GlVertexFormat{attributes=%d,stride=%d}", this.attributesKeyed.size(), this.stride);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private final Reference2ReferenceLinkedOpenHashMap<String, GlVertexAttribute> attributes;
|
||||
private final int stride;
|
||||
|
||||
@@ -72,7 +75,15 @@ public class GlVertexFormat {
|
||||
|
||||
public Builder addAllElements(GlVertexFormat otherFormat) {
|
||||
for (var attribute : otherFormat.getAttributes()) {
|
||||
this.addElement(new GlVertexAttribute(attribute.getFormat(), attribute.getName(), attribute.getCount(), attribute.isNormalized(), attribute.getPointer(), this.stride, attribute.isIntType()));
|
||||
this.addElement(
|
||||
new GlVertexAttribute(
|
||||
attribute.getFormat(),
|
||||
attribute.getName(),
|
||||
attribute.getCount(),
|
||||
attribute.isNormalized(),
|
||||
attribute.getPointer(),
|
||||
this.stride,
|
||||
attribute.isIntType()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -82,11 +93,13 @@ public class GlVertexFormat {
|
||||
return (nextPtr + (ATTRIBUTE_ALIGNMENT - 1)) & ~(ATTRIBUTE_ALIGNMENT - 1);
|
||||
}
|
||||
|
||||
public Builder addElement(String name, int pointer, GlVertexAttributeFormat format, int count, boolean normalized, boolean intType) {
|
||||
public Builder addElement(String name, int pointer, GlVertexAttributeFormat format, int count,
|
||||
boolean normalized, boolean intType) {
|
||||
if (pointer == NEXT_ALIGNED_POINTER) {
|
||||
pointer = this.findNextPointer();
|
||||
}
|
||||
return this.addElement(new GlVertexAttribute(format, name, count, normalized, pointer, this.stride, intType));
|
||||
return this
|
||||
.addElement(new GlVertexAttribute(format, name, count, normalized, pointer, this.stride, intType));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +110,13 @@ public class GlVertexFormat {
|
||||
*/
|
||||
private Builder addElement(GlVertexAttribute attribute) {
|
||||
if (attribute.getPointer() >= this.stride) {
|
||||
throw new IllegalArgumentException("Element " + attribute.getName() + " starts outside vertex format (" + attribute.getPointer() + ", stride is " + this.stride + ")");
|
||||
throw new IllegalArgumentException(
|
||||
"Element " + attribute.getName()
|
||||
+ " starts outside vertex format ("
|
||||
+ attribute.getPointer()
|
||||
+ ", stride is "
|
||||
+ this.stride
|
||||
+ ")");
|
||||
}
|
||||
|
||||
if (attribute.getPointer() + attribute.getSize() > this.stride) {
|
||||
@@ -105,7 +124,8 @@ public class GlVertexFormat {
|
||||
}
|
||||
|
||||
if (this.attributes.put(attribute.getName(), attribute) != null) {
|
||||
throw new IllegalStateException("Generic attribute " + attribute.getName() + " already defined in vertex format");
|
||||
throw new IllegalStateException(
|
||||
"Generic attribute " + attribute.getName() + " already defined in vertex format");
|
||||
}
|
||||
|
||||
return this;
|
||||
@@ -128,8 +148,10 @@ public class GlVertexFormat {
|
||||
GlVertexAttribute prevAttribute = null;
|
||||
|
||||
for (var attribute : allAttributes) {
|
||||
if (prevAttribute != null && attribute.getPointer() < (prevAttribute.getPointer() + prevAttribute.getSize())) {
|
||||
throw new IllegalArgumentException("Attribute " + attribute.getName() + " overlaps with " + prevAttribute.getName());
|
||||
if (prevAttribute != null
|
||||
&& attribute.getPointer() < (prevAttribute.getPointer() + prevAttribute.getSize())) {
|
||||
throw new IllegalArgumentException(
|
||||
"Attribute " + attribute.getName() + " overlaps with " + prevAttribute.getName());
|
||||
}
|
||||
prevAttribute = attribute;
|
||||
}
|
||||
|
||||
+5
-4
@@ -1,6 +1,7 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.impl.common.util;
|
||||
|
||||
public class MathUtil {
|
||||
|
||||
/**
|
||||
* @return True if the specified number is greater than zero and is a power of two, otherwise false
|
||||
*/
|
||||
@@ -21,13 +22,13 @@ public class MathUtil {
|
||||
}
|
||||
|
||||
public static int mojfloor(float f) {
|
||||
int truncated = (int)f;
|
||||
return f < (float)truncated ? truncated - 1 : truncated;
|
||||
int truncated = (int) f;
|
||||
return f < (float) truncated ? truncated - 1 : truncated;
|
||||
}
|
||||
|
||||
public static int mojfloor(double f) {
|
||||
int truncated = (int)f;
|
||||
return f < (double)truncated ? truncated - 1 : truncated;
|
||||
int truncated = (int) f;
|
||||
return f < (double) truncated ? truncated - 1 : truncated;
|
||||
}
|
||||
|
||||
public static int clamp(int value, int min, int max) {
|
||||
|
||||
+9
-5
@@ -1,11 +1,14 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.sprite.SpriteTransparencyLevel;
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface BakedQuadView extends ModelQuadView {
|
||||
|
||||
ModelQuadFacing getNormalFace();
|
||||
|
||||
boolean hasShade();
|
||||
@@ -14,14 +17,15 @@ public interface BakedQuadView extends ModelQuadView {
|
||||
|
||||
int getVerticesCount();
|
||||
|
||||
@Nullable SpriteTransparencyLevel getTransparencyLevel();
|
||||
@Nullable
|
||||
SpriteTransparencyLevel getTransparencyLevel();
|
||||
|
||||
static BakedQuadView of(Object o) {
|
||||
return (BakedQuadView)o;
|
||||
return (BakedQuadView) o;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T> List<? extends BakedQuadView> ofList(List<T> quads) {
|
||||
return (List<? extends BakedQuadView>)(List<?>)quads;
|
||||
return (List<? extends BakedQuadView>) (List<?>) quads;
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -11,14 +11,16 @@ import static com.gtnewhorizon.gtnhlib.client.renderer.cel.util.ModelQuadUtil.VE
|
||||
import static com.gtnewhorizon.gtnhlib.client.renderer.cel.util.ModelQuadUtil.vertexOffset;
|
||||
import static org.lwjgl.opengl.GL11.GL_TRIANGLES;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.util.ModelQuadUtil;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.quad.TessFlags;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/// A simple implementation of the [ModelQuadViewMutable] interface which can provide an on-heap scratch area
|
||||
/// for storing quad vertex data.
|
||||
public class ModelQuad implements ModelQuadViewMutable {
|
||||
|
||||
private final int[] data = new int[VERTEX_SIZE * 4];
|
||||
private int flags;
|
||||
|
||||
@@ -187,7 +189,8 @@ public class ModelQuad implements ModelQuadViewMutable {
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public void setState(int[] rawBuffer, int srcOffset, TessFlags flags, int drawMode, int offsetX, int offsetY, int offsetZ) {
|
||||
public void setState(int[] rawBuffer, int srcOffset, TessFlags flags, int drawMode, int offsetX, int offsetY,
|
||||
int offsetZ) {
|
||||
System.arraycopy(rawBuffer, srcOffset, data, 0, data.length);
|
||||
|
||||
if (!flags.hasColor) clearColors();
|
||||
|
||||
+7
-4
@@ -1,12 +1,13 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFlags;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFlags;
|
||||
|
||||
/**
|
||||
* Provides a read-only view of a model quad. For mutable access to a model quad, see {@link ModelQuadViewMutable}.
|
||||
*/
|
||||
public interface ModelQuadView {
|
||||
|
||||
/**
|
||||
* @return The x-position of the vertex at index {@param idx}
|
||||
*/
|
||||
@@ -38,8 +39,8 @@ public interface ModelQuadView {
|
||||
float getTexV(int idx);
|
||||
|
||||
/**
|
||||
* @return The packed lightmap coordinates for the vertex at index {@param idx},
|
||||
* or zero if regular lighting should be used.
|
||||
* @return The packed lightmap coordinates for the vertex at index {@param idx}, or zero if regular lighting should
|
||||
* be used.
|
||||
*/
|
||||
int getLight(int idx);
|
||||
|
||||
@@ -84,7 +85,9 @@ public interface ModelQuadView {
|
||||
return this.getColorIndex() != -1;
|
||||
}
|
||||
|
||||
default boolean hasAmbientOcclusion() { return true; }
|
||||
default boolean hasAmbientOcclusion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
default int getVanillaLightEmission() {
|
||||
return 0;
|
||||
|
||||
+1
@@ -7,6 +7,7 @@ import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQ
|
||||
* Provides a mutable view to a model quad.
|
||||
*/
|
||||
public interface ModelQuadViewMutable extends ModelQuadView {
|
||||
|
||||
/**
|
||||
* Sets the x-position of the vertex at index {@param idx} to the value {@param x}
|
||||
*/
|
||||
|
||||
+7
-2
@@ -1,10 +1,13 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.api.util.NormI8;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.api.util.NormI8;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public enum ModelQuadFacing {
|
||||
|
||||
POS_X(1, 0, 0, Axis.X),
|
||||
POS_Y(0, 1, 0, Axis.Y),
|
||||
POS_Z(0, 0, 1, Axis.Z),
|
||||
@@ -14,7 +17,8 @@ public enum ModelQuadFacing {
|
||||
UNASSIGNED(0, 0, 0, null);
|
||||
|
||||
public static final ModelQuadFacing[] VALUES = ModelQuadFacing.values();
|
||||
public static final ModelQuadFacing[] DIRECTIONS = Arrays.stream(VALUES).filter(facing -> facing != UNASSIGNED).toArray(ModelQuadFacing[]::new);
|
||||
public static final ModelQuadFacing[] DIRECTIONS = Arrays.stream(VALUES).filter(facing -> facing != UNASSIGNED)
|
||||
.toArray(ModelQuadFacing[]::new);
|
||||
public static final Axis[] AXES = Axis.values();
|
||||
|
||||
public static final int COUNT = VALUES.length;
|
||||
@@ -56,6 +60,7 @@ public enum ModelQuadFacing {
|
||||
}
|
||||
|
||||
public enum Axis {
|
||||
|
||||
X,
|
||||
Y,
|
||||
Z;
|
||||
|
||||
+89
-52
@@ -6,6 +6,7 @@ import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.BakedQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
|
||||
public class ModelQuadFlags {
|
||||
|
||||
/**
|
||||
* Indicates that the quad does not fully cover the given face for the model.
|
||||
*/
|
||||
@@ -17,14 +18,13 @@ public class ModelQuadFlags {
|
||||
public static final int IS_PARALLEL = 0b010;
|
||||
|
||||
/**
|
||||
* Indicates that the quad is aligned to the block grid.
|
||||
* This flag is only set if {@link #IS_PARALLEL} is set.
|
||||
* Indicates that the quad is aligned to the block grid. This flag is only set if {@link #IS_PARALLEL} is set.
|
||||
*/
|
||||
public static final int IS_ALIGNED = 0b100;
|
||||
|
||||
/**
|
||||
* Indicates that the quad should be shaded using vanilla's getShade logic and the light face, rather than
|
||||
* the normals of each vertex.
|
||||
* Indicates that the quad should be shaded using vanilla's getShade logic and the light face, rather than the
|
||||
* normals of each vertex.
|
||||
*/
|
||||
public static final int IS_VANILLA_SHADED = 0b1000;
|
||||
/**
|
||||
@@ -52,58 +52,97 @@ public class ModelQuadFlags {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a quad's vertex ordering matches Minecraft's canonical baked order
|
||||
* for the given face.
|
||||
* Checks whether a quad's vertex ordering matches Minecraft's canonical baked order for the given face.
|
||||
* <p>
|
||||
* Minecraft allows four different permutations of a quad's vertices that will
|
||||
* render identically. However, the baked model pipeline (e.g. ambient occlusion,
|
||||
* lighting interpolation, and back-face culling) assumes a specific ordering
|
||||
* that is hardcoded in the model baking logic. This method verifies
|
||||
* that a quad's vertices are listed in that exact canonical order.
|
||||
* Minecraft allows four different permutations of a quad's vertices that will render identically. However, the
|
||||
* baked model pipeline (e.g. ambient occlusion, lighting interpolation, and back-face culling) assumes a specific
|
||||
* ordering that is hardcoded in the model baking logic. This method verifies that a quad's vertices are listed in
|
||||
* that exact canonical order.
|
||||
* <p>
|
||||
* The canonical order is:
|
||||
* <ul>
|
||||
* <li>Vertices are arranged counter-clockwise (CCW) as seen from outside the block face.</li>
|
||||
* <li>Each face (±X, ±Y, ±Z) starts at a specific corner and proceeds CCW around the face.</li>
|
||||
* <li>For example, the -Y face (DOWN) starts at {@code (minX, minY, maxZ)} and proceeds
|
||||
* through {@code (minX, minY, minZ)}, {@code (maxX, minY, minZ)}, {@code (maxX, minY, maxZ)}.</li>
|
||||
* <li>Vertices are arranged counter-clockwise (CCW) as seen from outside the block face.</li>
|
||||
* <li>Each face (±X, ±Y, ±Z) starts at a specific corner and proceeds CCW around the face.</li>
|
||||
* <li>For example, the -Y face (DOWN) starts at {@code (minX, minY, maxZ)} and proceeds through
|
||||
* {@code (minX, minY, minZ)}, {@code (maxX, minY, minZ)}, {@code (maxX, minY, maxZ)}.</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* This method avoids allocations by comparing directly against the expected coordinates
|
||||
* for each vertex index based on the given {@code face} and bounding box.
|
||||
* This method avoids allocations by comparing directly against the expected coordinates for each vertex index based
|
||||
* on the given {@code face} and bounding box.
|
||||
*
|
||||
* @param face the face direction of the quad; determines which axis is fixed and
|
||||
* which two axes form the quad plane
|
||||
* @return {@code true} if the quad's vertices match Minecraft's canonical baked order
|
||||
* for the given face, {@code false} otherwise
|
||||
* @param face the face direction of the quad; determines which axis is fixed and which two axes form the quad plane
|
||||
* @return {@code true} if the quad's vertices match Minecraft's canonical baked order for the given face,
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
private static boolean canonicalVertexOrder(ModelQuadView quad, ModelQuadFacing face, float minX, float minY, float minZ,
|
||||
float maxX, float maxY, float maxZ) {
|
||||
private static boolean canonicalVertexOrder(ModelQuadView quad, ModelQuadFacing face, float minX, float minY,
|
||||
float minZ, float maxX, float maxY, float maxZ) {
|
||||
return switch (face) {
|
||||
case NEG_Y -> MathUtil.roughlyEqual(quad.getX(0), minX) && MathUtil.roughlyEqual(quad.getY(0), minY) && MathUtil.roughlyEqual(quad.getZ(0), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(1), minX) && MathUtil.roughlyEqual(quad.getY(1), minY) && MathUtil.roughlyEqual(quad.getZ(1), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(2), maxX) && MathUtil.roughlyEqual(quad.getY(2), minY) && MathUtil.roughlyEqual(quad.getZ(2), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(3), maxX) && MathUtil.roughlyEqual(quad.getY(3), minY) && MathUtil.roughlyEqual(quad.getZ(3), maxZ);
|
||||
case POS_Y -> MathUtil.roughlyEqual(quad.getX(0), minX) && MathUtil.roughlyEqual(quad.getY(0), maxY) && MathUtil.roughlyEqual(quad.getZ(0), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(1), minX) && MathUtil.roughlyEqual(quad.getY(1), maxY) && MathUtil.roughlyEqual(quad.getZ(1), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(2), maxX) && MathUtil.roughlyEqual(quad.getY(2), maxY) && MathUtil.roughlyEqual(quad.getZ(2), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(3), maxX) && MathUtil.roughlyEqual(quad.getY(3), maxY) && MathUtil.roughlyEqual(quad.getZ(3), minZ);
|
||||
case NEG_Z -> MathUtil.roughlyEqual(quad.getX(0), maxX) && MathUtil.roughlyEqual(quad.getY(0), maxY) && MathUtil.roughlyEqual(quad.getZ(0), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(1), maxX) && MathUtil.roughlyEqual(quad.getY(1), minY) && MathUtil.roughlyEqual(quad.getZ(1), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(2), minX) && MathUtil.roughlyEqual(quad.getY(2), minY) && MathUtil.roughlyEqual(quad.getZ(2), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(3), minX) && MathUtil.roughlyEqual(quad.getY(3), maxY) && MathUtil.roughlyEqual(quad.getZ(3), minZ);
|
||||
case POS_Z -> MathUtil.roughlyEqual(quad.getX(0), minX) && MathUtil.roughlyEqual(quad.getY(0), maxY) && MathUtil.roughlyEqual(quad.getZ(0), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(1), minX) && MathUtil.roughlyEqual(quad.getY(1), minY) && MathUtil.roughlyEqual(quad.getZ(1), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(2), maxX) && MathUtil.roughlyEqual(quad.getY(2), minY) && MathUtil.roughlyEqual(quad.getZ(2), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(3), maxX) && MathUtil.roughlyEqual(quad.getY(3), maxY) && MathUtil.roughlyEqual(quad.getZ(3), maxZ);
|
||||
case NEG_X -> MathUtil.roughlyEqual(quad.getX(0), minX) && MathUtil.roughlyEqual(quad.getY(0), maxY) && MathUtil.roughlyEqual(quad.getZ(0), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(1), minX) && MathUtil.roughlyEqual(quad.getY(1), minY) && MathUtil.roughlyEqual(quad.getZ(1), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(2), minX) && MathUtil.roughlyEqual(quad.getY(2), minY) && MathUtil.roughlyEqual(quad.getZ(2), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(3), minX) && MathUtil.roughlyEqual(quad.getY(3), maxY) && MathUtil.roughlyEqual(quad.getZ(3), maxZ);
|
||||
case POS_X -> MathUtil.roughlyEqual(quad.getX(0), maxX) && MathUtil.roughlyEqual(quad.getY(0), maxY) && MathUtil.roughlyEqual(quad.getZ(0), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(1), maxX) && MathUtil.roughlyEqual(quad.getY(1), minY) && MathUtil.roughlyEqual(quad.getZ(1), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(2), maxX) && MathUtil.roughlyEqual(quad.getY(2), minY) && MathUtil.roughlyEqual(quad.getZ(2), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(3), maxX) && MathUtil.roughlyEqual(quad.getY(3), maxY) && MathUtil.roughlyEqual(quad.getZ(3), minZ);
|
||||
case NEG_Y -> MathUtil.roughlyEqual(quad.getX(0), minX) && MathUtil.roughlyEqual(quad.getY(0), minY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(0), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(1), minX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(1), minY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(1), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(2), maxX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(2), minY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(2), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(3), maxX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(3), minY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(3), maxZ);
|
||||
case POS_Y -> MathUtil.roughlyEqual(quad.getX(0), minX) && MathUtil.roughlyEqual(quad.getY(0), maxY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(0), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(1), minX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(1), maxY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(1), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(2), maxX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(2), maxY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(2), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(3), maxX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(3), maxY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(3), minZ);
|
||||
case NEG_Z -> MathUtil.roughlyEqual(quad.getX(0), maxX) && MathUtil.roughlyEqual(quad.getY(0), maxY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(0), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(1), maxX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(1), minY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(1), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(2), minX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(2), minY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(2), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(3), minX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(3), maxY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(3), minZ);
|
||||
case POS_Z -> MathUtil.roughlyEqual(quad.getX(0), minX) && MathUtil.roughlyEqual(quad.getY(0), maxY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(0), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(1), minX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(1), minY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(1), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(2), maxX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(2), minY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(2), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(3), maxX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(3), maxY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(3), maxZ);
|
||||
case NEG_X -> MathUtil.roughlyEqual(quad.getX(0), minX) && MathUtil.roughlyEqual(quad.getY(0), maxY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(0), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(1), minX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(1), minY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(1), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(2), minX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(2), minY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(2), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(3), minX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(3), maxY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(3), maxZ);
|
||||
case POS_X -> MathUtil.roughlyEqual(quad.getX(0), maxX) && MathUtil.roughlyEqual(quad.getY(0), maxY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(0), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(1), maxX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(1), minY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(1), maxZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(2), maxX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(2), minY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(2), minZ)
|
||||
&& MathUtil.roughlyEqual(quad.getX(3), maxX)
|
||||
&& MathUtil.roughlyEqual(quad.getY(3), maxY)
|
||||
&& MathUtil.roughlyEqual(quad.getZ(3), minZ);
|
||||
case UNASSIGNED -> false;
|
||||
};
|
||||
}
|
||||
@@ -145,15 +184,13 @@ public class ModelQuadFlags {
|
||||
float py = quad.getY(j);
|
||||
float pz = quad.getZ(j);
|
||||
|
||||
if (MathUtil.roughlyEqual(px, x) &&
|
||||
MathUtil.roughlyEqual(py, y) &&
|
||||
MathUtil.roughlyEqual(pz, z)) {
|
||||
if (MathUtil.roughlyEqual(px, x) && MathUtil.roughlyEqual(py, y) && MathUtil.roughlyEqual(pz, z)) {
|
||||
degenerate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(ColorABGR.unpackAlpha(quad.getColor(i)) != 255) {
|
||||
if (ColorABGR.unpackAlpha(quad.getColor(i)) != 255) {
|
||||
nonOpaqueColor = true;
|
||||
}
|
||||
}
|
||||
@@ -166,7 +203,7 @@ public class ModelQuadFlags {
|
||||
case Z -> minX >= 0.0001f || minY >= 0.0001f || maxX <= 0.9999F || maxY <= 0.9999F;
|
||||
}) || !canonicalVertexOrder(quad, face, minX, minY, minZ, maxX, maxY, maxZ);
|
||||
|
||||
boolean parallel = switch(face.getAxis()) {
|
||||
boolean parallel = switch (face.getAxis()) {
|
||||
case X -> minX == maxX;
|
||||
case Y -> minY == maxY;
|
||||
case Z -> minZ == maxZ;
|
||||
|
||||
+1
@@ -5,6 +5,7 @@ package com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties;
|
||||
* consistent order, eliminating a number of shading issues caused by anisotropy problems.
|
||||
*/
|
||||
public enum ModelQuadOrientation {
|
||||
|
||||
NORMAL(new int[] { 0, 1, 2, 3 }),
|
||||
FLIP(new int[] { 1, 2, 3, 0 });
|
||||
|
||||
|
||||
+1
@@ -1,6 +1,7 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties;
|
||||
|
||||
public enum ModelQuadWinding {
|
||||
|
||||
CLOCKWISE(new int[] { 0, 1, 2, 2, 3, 0 }),
|
||||
COUNTERCLOCKWISE(new int[] { 0, 3, 2, 1, 0, 2 });
|
||||
|
||||
|
||||
@@ -2,13 +2,15 @@ package com.gtnewhorizon.gtnhlib.client.renderer.cel.polyfill;
|
||||
|
||||
import static it.unimi.dsi.fastutil.objects.Object2ObjectMaps.unmodifiable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Maps {
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public static <K, V> Object2ObjectMap<K, V> copyOf(Map<K, V> input) {
|
||||
if (input instanceof Object2ObjectMaps.UnmodifiableMap u) return u;
|
||||
return unmodifiable(new Object2ObjectOpenHashMap<>(input));
|
||||
|
||||
+20
-11
@@ -1,12 +1,16 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.compile.sorting;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.sorting.TranslucentQuadAnalyzer;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.sorting.TranslucentQuadAnalyzer;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
public interface ChunkPrimitiveType {
|
||||
|
||||
default int getIndexBufferSize(int numPrimitives) {
|
||||
return numPrimitives * getIndexBufferElementsPerPrimitive() * 4;
|
||||
}
|
||||
@@ -25,8 +29,10 @@ public interface ChunkPrimitiveType {
|
||||
* Generate a "simple" index buffer for rendering numPrimitives primitives in the order they appear in the vertex
|
||||
* buffer.
|
||||
*
|
||||
* The caller is responsible for providing a buffer of size given by {@link ChunkPrimitiveType#getIndexBufferSize(int)}.
|
||||
* @param indexBuffer a NativeBuffer that should be populated with 32-bit integers
|
||||
* The caller is responsible for providing a buffer of size given by
|
||||
* {@link ChunkPrimitiveType#getIndexBufferSize(int)}.
|
||||
*
|
||||
* @param indexBuffer a NativeBuffer that should be populated with 32-bit integers
|
||||
* @param numPrimitives the number of primitives to generate the buffer for
|
||||
*/
|
||||
void generateSimpleIndexBuffer(ByteBuffer indexBuffer, int numPrimitives);
|
||||
@@ -34,18 +40,21 @@ public interface ChunkPrimitiveType {
|
||||
/**
|
||||
* Generate a sorted index buffer for numPrimitives primitives, with data on the primitives provided in chunkData.
|
||||
* <p>
|
||||
* The caller is responsible for providing a buffer of size given by {@link ChunkPrimitiveType#getIndexBufferSize(int)}.
|
||||
* The caller is responsible for providing a buffer of size given by
|
||||
* {@link ChunkPrimitiveType#getIndexBufferSize(int)}.
|
||||
* <p>
|
||||
* The provided camera position will be subchunk-relative, and thus makes sense to compare directly with the vertex
|
||||
* positions provided in the SortState.
|
||||
* @param indexBuffer a NativeBuffer that should be populated with 32-bit integers
|
||||
*
|
||||
* @param indexBuffer a NativeBuffer that should be populated with 32-bit integers
|
||||
* @param numPrimitives the number of primitives to generate the buffer for
|
||||
* @param chunkData the sorting data for the given primitives
|
||||
* @param x x position of the camera
|
||||
* @param y y position of the camera
|
||||
* @param z z position of the camera
|
||||
* @param chunkData the sorting data for the given primitives
|
||||
* @param x x position of the camera
|
||||
* @param y y position of the camera
|
||||
* @param z z position of the camera
|
||||
*/
|
||||
void generateSortedIndexBuffer(ByteBuffer indexBuffer, int numPrimitives, @Nullable TranslucentQuadAnalyzer.SortState chunkData, float x, float y, float z);
|
||||
void generateSortedIndexBuffer(ByteBuffer indexBuffer, int numPrimitives,
|
||||
@Nullable TranslucentQuadAnalyzer.SortState chunkData, float x, float y, float z);
|
||||
|
||||
default List<String> getDefines() {
|
||||
return ObjectArrayList.of();
|
||||
|
||||
+39
-19
@@ -1,12 +1,16 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.sorting;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.vertex.format.ChunkVertexEncoder;
|
||||
|
||||
import it.unimi.dsi.fastutil.floats.FloatArrayList;
|
||||
import java.util.BitSet;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class TranslucentQuadAnalyzer {
|
||||
|
||||
// X/Y/Z for each quad center
|
||||
private static final int EXPECTED_QUADS = 1000;
|
||||
private final FloatArrayList quadCenters = new FloatArrayList(EXPECTED_QUADS * 3);
|
||||
@@ -19,6 +23,7 @@ public class TranslucentQuadAnalyzer {
|
||||
private boolean hasDistinctNormals;
|
||||
|
||||
public enum Level {
|
||||
|
||||
/**
|
||||
* No sorting is required of the current section.
|
||||
*/
|
||||
@@ -40,13 +45,15 @@ public class TranslucentQuadAnalyzer {
|
||||
}
|
||||
|
||||
public TranslucentQuadAnalyzer() {
|
||||
for(int i = 0; i < 4; i++) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
vertexPositions[i] = new Vector3f();
|
||||
}
|
||||
}
|
||||
|
||||
@Desugar
|
||||
public record SortState(Level level, float[] centers, int centersLength, BitSet normalSigns, Vector3f sharedNormal) {
|
||||
public record SortState(Level level, float[] centers, int centersLength, BitSet normalSigns,
|
||||
Vector3f sharedNormal) {
|
||||
|
||||
public static final SortState NONE = new SortState(Level.NONE, null, 0, null, null);
|
||||
|
||||
public boolean requiresDynamicSorting() {
|
||||
@@ -54,7 +61,7 @@ public class TranslucentQuadAnalyzer {
|
||||
}
|
||||
|
||||
public SortState compactForStorage() {
|
||||
if(this == NONE || requiresDynamicSorting()) {
|
||||
if (this == NONE || requiresDynamicSorting()) {
|
||||
return this;
|
||||
} else {
|
||||
return new SortState(level, null, 0, null, null);
|
||||
@@ -67,10 +74,10 @@ public class TranslucentQuadAnalyzer {
|
||||
}
|
||||
|
||||
private static BitSet cloneBits(BitSet bits) {
|
||||
if(bits.isEmpty()) {
|
||||
if (bits.isEmpty()) {
|
||||
return EMPTY;
|
||||
} else {
|
||||
return (BitSet)bits.clone();
|
||||
return (BitSet) bits.clone();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +85,8 @@ public class TranslucentQuadAnalyzer {
|
||||
// Let globalNormal = (a, b, c). Any plane with this normal vector is denoted by the equation ax + by + cz = d,
|
||||
// for some real number d.
|
||||
//
|
||||
// Next, we know that any quad has either globalNormal or -globalNormal as a normal vector. Suppose a quad q has center (x, y, z).
|
||||
// Next, we know that any quad has either globalNormal or -globalNormal as a normal vector. Suppose a quad q has
|
||||
// center (x, y, z).
|
||||
// We define the "plane extension" of q as the unique plane in 3D space that q resides within. In particular,
|
||||
// any quad's plane extension (when all share parallel normals) is uniquely determined by the choice of d.
|
||||
//
|
||||
@@ -92,10 +100,11 @@ public class TranslucentQuadAnalyzer {
|
||||
float a = globalNormal.x, b = globalNormal.y, c = globalNormal.z;
|
||||
float d = a * centerArray[0] + b * centerArray[1] + c * centerArray[2];
|
||||
int nQuads = quadCenters.size() / 3;
|
||||
for(int quadIdx = 1; quadIdx < nQuads; quadIdx++) {
|
||||
for (int quadIdx = 1; quadIdx < nQuads; quadIdx++) {
|
||||
int centerOff = quadIdx * 3;
|
||||
float candidateD = a * centerArray[centerOff + 0] + b * centerArray[centerOff + 1] + c * centerArray[centerOff + 2];
|
||||
if(Math.abs(candidateD - d) >= 1.0E-5F) {
|
||||
float candidateD = a * centerArray[centerOff + 0] + b * centerArray[centerOff + 1]
|
||||
+ c * centerArray[centerOff + 2];
|
||||
if (Math.abs(candidateD - d) >= 1.0E-5F) {
|
||||
// Different planes
|
||||
return false;
|
||||
}
|
||||
@@ -105,17 +114,18 @@ public class TranslucentQuadAnalyzer {
|
||||
}
|
||||
|
||||
public SortState getSortState() {
|
||||
if(quadCenters.isEmpty()) {
|
||||
if (quadCenters.isEmpty()) {
|
||||
return SortState.NONE;
|
||||
} else {
|
||||
Level sortLevel;
|
||||
|
||||
// Figure out what sort level is required
|
||||
if(hasDistinctNormals) {
|
||||
if (hasDistinctNormals) {
|
||||
// Must use dynamic sort
|
||||
sortLevel = Level.DYNAMIC;
|
||||
} else {
|
||||
// If all quads are on the same plane we can use NONE sorting, otherwise we need to sort statically to put
|
||||
// If all quads are on the same plane we can use NONE sorting, otherwise we need to sort statically to
|
||||
// put
|
||||
// them in the right order
|
||||
sortLevel = areAllQuadsOnSamePlane() ? Level.NONE : Level.STATIC;
|
||||
}
|
||||
@@ -126,10 +136,20 @@ public class TranslucentQuadAnalyzer {
|
||||
finalState = SortState.NONE;
|
||||
} else if (sortLevel.requiresDynamicSorting()) {
|
||||
// Clone everything
|
||||
finalState = new SortState(sortLevel, quadCenters.toArray(new float[0]), quadCenters.size(), cloneBits(normalSigns), new Vector3f(globalNormal));
|
||||
finalState = new SortState(
|
||||
sortLevel,
|
||||
quadCenters.toArray(new float[0]),
|
||||
quadCenters.size(),
|
||||
cloneBits(normalSigns),
|
||||
new Vector3f(globalNormal));
|
||||
} else {
|
||||
// Just make a thin wrapper around our backing objects
|
||||
finalState = new SortState(sortLevel, quadCenters.elements(), quadCenters.size(), normalSigns, globalNormal);
|
||||
finalState = new SortState(
|
||||
sortLevel,
|
||||
quadCenters.elements(),
|
||||
quadCenters.size(),
|
||||
normalSigns,
|
||||
globalNormal);
|
||||
}
|
||||
|
||||
return finalState;
|
||||
@@ -208,10 +228,10 @@ public class TranslucentQuadAnalyzer {
|
||||
centers.add(totalY / 4);
|
||||
centers.add(totalZ / 4);
|
||||
|
||||
if(!hasDistinctNormals) {
|
||||
if (!hasDistinctNormals) {
|
||||
calculateNormal();
|
||||
|
||||
if(globalNormal.x == 0 && globalNormal.y == 0 && globalNormal.z == 0) {
|
||||
if (globalNormal.x == 0 && globalNormal.y == 0 && globalNormal.z == 0) {
|
||||
// No normal has been tracked thus far, choose this one
|
||||
globalNormal.set(currentNormal);
|
||||
} else {
|
||||
@@ -236,7 +256,7 @@ public class TranslucentQuadAnalyzer {
|
||||
int i = currentVertex;
|
||||
vertexPositions[i].set(vertex.x, vertex.y, vertex.z);
|
||||
i++;
|
||||
if(i == 4) {
|
||||
if (i == 4) {
|
||||
captureQuad();
|
||||
i = 0;
|
||||
}
|
||||
|
||||
+3
-1
@@ -1,6 +1,7 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.sprite;
|
||||
|
||||
public enum SpriteTransparencyLevel {
|
||||
|
||||
OPAQUE,
|
||||
TRANSPARENT,
|
||||
TRANSLUCENT;
|
||||
@@ -13,10 +14,11 @@ public enum SpriteTransparencyLevel {
|
||||
}
|
||||
|
||||
public interface Holder {
|
||||
|
||||
SpriteTransparencyLevel embeddium$getTransparencyLevel();
|
||||
|
||||
static SpriteTransparencyLevel getTransparencyLevel(Object o) {
|
||||
return ((Holder)o).embeddium$getTransparencyLevel();
|
||||
return ((Holder) o).embeddium$getTransparencyLevel();
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
-19
@@ -1,29 +1,34 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.terrain;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.polyfill.Maps;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.compile.sorting.ChunkPrimitiveType;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.terrain.material.Material;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.vertex.format.ChunkVertexType;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Singular;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A terrain render pass corresponds to a draw call to render some subset of terrain geometry. Passes are generally
|
||||
* used for fixed configuration that will not change from quad to quad and allow for optimizations to be made
|
||||
* within the terrain shader code at compile time (e.g. omitting the fragment discard conditional entirely on the solid pass).
|
||||
* <p></p>
|
||||
* Geometry that shares the same terrain render pass may still be able to specify some more dynamic properties. See {@link Material}
|
||||
* for more information.
|
||||
* A terrain render pass corresponds to a draw call to render some subset of terrain geometry. Passes are generally used
|
||||
* for fixed configuration that will not change from quad to quad and allow for optimizations to be made within the
|
||||
* terrain shader code at compile time (e.g. omitting the fragment discard conditional entirely on the solid pass).
|
||||
* <p>
|
||||
* </p>
|
||||
* Geometry that shares the same terrain render pass may still be able to specify some more dynamic properties. See
|
||||
* {@link Material} for more information.
|
||||
*/
|
||||
@Accessors(fluent = true)
|
||||
@EqualsAndHashCode
|
||||
public class TerrainRenderPass {
|
||||
|
||||
/**
|
||||
* The friendly name of this render pass.
|
||||
*/
|
||||
@@ -59,16 +64,10 @@ public class TerrainRenderPass {
|
||||
private final Map<String, String> extraDefines;
|
||||
|
||||
@Builder
|
||||
public TerrainRenderPass(String name,
|
||||
PipelineState pipelineState,
|
||||
boolean useReverseOrder,
|
||||
boolean fragmentDiscard,
|
||||
boolean useTranslucencySorting,
|
||||
boolean hasNoLightmap,
|
||||
@NotNull ChunkVertexType vertexType,
|
||||
@NotNull ChunkPrimitiveType primitiveType,
|
||||
@Singular Map<String, String> extraDefines) {
|
||||
if(name == null || name.isEmpty()) {
|
||||
public TerrainRenderPass(String name, PipelineState pipelineState, boolean useReverseOrder, boolean fragmentDiscard,
|
||||
boolean useTranslucencySorting, boolean hasNoLightmap, @NotNull ChunkVertexType vertexType,
|
||||
@NotNull ChunkPrimitiveType primitiveType, @Singular Map<String, String> extraDefines) {
|
||||
if (name == null || name.isEmpty()) {
|
||||
throw new IllegalArgumentException("Name not specified for terrain pass");
|
||||
}
|
||||
Objects.requireNonNull(vertexType);
|
||||
@@ -127,7 +126,9 @@ public class TerrainRenderPass {
|
||||
}
|
||||
|
||||
public interface PipelineState {
|
||||
|
||||
PipelineState DEFAULT = new PipelineState() {
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
|
||||
@@ -140,6 +141,7 @@ public class TerrainRenderPass {
|
||||
};
|
||||
|
||||
void setup();
|
||||
|
||||
void clear();
|
||||
}
|
||||
}
|
||||
+7
-8
@@ -1,9 +1,10 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.terrain.material;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.terrain.TerrainRenderPass;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.terrain.material.parameters.AlphaCutoffParameter;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.terrain.material.parameters.MaterialParameters;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A material provides the full configuration about how a geometry element should render. It corresponds to the vanilla
|
||||
@@ -12,6 +13,7 @@ import java.util.Objects;
|
||||
* efficiency. The material configuration is recovered on the GPU within the render pass.
|
||||
*/
|
||||
public final class Material {
|
||||
|
||||
public final TerrainRenderPass pass;
|
||||
public final int packed;
|
||||
|
||||
@@ -20,9 +22,10 @@ public final class Material {
|
||||
|
||||
/**
|
||||
* Constructs a new Material.
|
||||
* @param pass the {@link TerrainRenderPass} to use for the base configuration
|
||||
*
|
||||
* @param pass the {@link TerrainRenderPass} to use for the base configuration
|
||||
* @param alphaCutoff the alpha level below which fragments should be discarded
|
||||
* @param mipped whether mipmapping should be enabled on geometry rendered with this material
|
||||
* @param mipped whether mipmapping should be enabled on geometry rendered with this material
|
||||
*/
|
||||
public Material(TerrainRenderPass pass, AlphaCutoffParameter alphaCutoff, boolean mipped) {
|
||||
if (alphaCutoff != AlphaCutoffParameter.ZERO && !pass.supportsFragmentDiscard()) {
|
||||
@@ -57,10 +60,6 @@ public final class Material {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Material{" +
|
||||
"pass=" + pass +
|
||||
", alphaCutoff=" + alphaCutoff +
|
||||
", mipped=" + mipped +
|
||||
'}';
|
||||
return "Material{" + "pass=" + pass + ", alphaCutoff=" + alphaCutoff + ", mipped=" + mipped + '}';
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,5 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.terrain.material.parameters;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -9,6 +8,7 @@ import lombok.experimental.Accessors;
|
||||
@Accessors(fluent = true)
|
||||
@Getter
|
||||
public enum AlphaCutoffParameter {
|
||||
|
||||
ZERO(0.0f),
|
||||
ONE_TENTH(0.1f),
|
||||
HALF(0.5f),
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.terrain.material.parameters;
|
||||
|
||||
public class MaterialParameters {
|
||||
|
||||
public static final int OFFSET_USE_MIP = 0;
|
||||
public static final int OFFSET_ALPHA_CUTOFF = 1;
|
||||
|
||||
public static int pack(AlphaCutoffParameter alphaCutoff, boolean useMipmaps) {
|
||||
return (((useMipmaps ? 1 : 0) << OFFSET_USE_MIP) |
|
||||
((alphaCutoff.ordinal()) << OFFSET_ALPHA_CUTOFF));
|
||||
return (((useMipmaps ? 1 : 0) << OFFSET_USE_MIP) | ((alphaCutoff.ordinal()) << OFFSET_ALPHA_CUTOFF));
|
||||
}
|
||||
}
|
||||
+2
@@ -3,9 +3,11 @@ package com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.vertex.format;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.terrain.material.Material;
|
||||
|
||||
public interface ChunkVertexEncoder {
|
||||
|
||||
long write(long ptr, Material material, Vertex vertex, int sectionIndex);
|
||||
|
||||
class Vertex {
|
||||
|
||||
public float x;
|
||||
public float y;
|
||||
public float z;
|
||||
|
||||
+4
-1
@@ -1,11 +1,14 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.vertex.format;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.gl.attribute.GlVertexFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jetbrains.annotations.MustBeInvokedByOverriders;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.gl.attribute.GlVertexFormat;
|
||||
|
||||
public interface ChunkVertexType {
|
||||
|
||||
/**
|
||||
* @return The scale to be applied to vertex coordinates
|
||||
*/
|
||||
|
||||
+18
-22
@@ -1,32 +1,30 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.util;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.api.util.ColorARGB;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.api.util.NormI8;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.vertex.format.ChunkVertexEncoder;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
/// Provides some utilities and constants for interacting with vanilla's model quad vertex format.
|
||||
/// This is the vertex format used by Minecraft 7.10 for chunk meshes and model quads. Internally, it uses integer
|
||||
/// arrays for store baked quad data, and as such the following table provides both the byte and int indices.
|
||||
///
|
||||
/// | Byte Index | Integer Index | Name | Format | Fields |
|
||||
/// | ---------- | ------------- | ------------- | ---------------- | --------------- |
|
||||
/// | 0..11 | 0..2 | Position | 3 floats | x, y, z |
|
||||
/// | 12..19 | 3..4 | Block Texture | 2 floats | u, v |
|
||||
/// | 19..23 | 5 | Color | 4 unsigned bytes | a, b, g, r [^1] |
|
||||
/// | 24..27 | 6 | Normal | 3 unsigned bytes | x, y, z |
|
||||
/// | 28..31 | 7 | Light Texture | 2 shorts | u, v |
|
||||
/// | Byte Index | Integer Index | Name | Format | Fields |
|
||||
/// | ---------- | ------------- | ---- | ------ | ------ |
|
||||
/// | 0..11 | 0..2 | Position | 3 floats | x, y, z |
|
||||
/// | 12..19 | 3..4 | Block Texture | 2 floats | u, v |
|
||||
/// | 19..23 | 5 | Color | 4 unsigned bytes | a, b, g, r \[1] |
|
||||
/// | 24..27 | 6 | Normal | 3 unsigned bytes | x, y, z |
|
||||
/// | 28..31 | 7 | Light Texture | 2 shorts | u, v |
|
||||
///
|
||||
/// [^1]: ABGR on little-endian systems, RGBA on big-endian systems.
|
||||
/// \[1]: ABGR on little-endian systems, RGBA on big-endian systems.
|
||||
public class ModelQuadUtil {
|
||||
|
||||
// Integer indices for vertex attributes, useful for accessing baked quad data
|
||||
public static final int POSITION_INDEX = 0,
|
||||
COLOR_INDEX = 5,
|
||||
TEXTURE_INDEX = 3,
|
||||
LIGHT_INDEX = 7,
|
||||
NORMAL_INDEX = 6;
|
||||
public static final int POSITION_INDEX = 0, COLOR_INDEX = 5, TEXTURE_INDEX = 3, LIGHT_INDEX = 7, NORMAL_INDEX = 6;
|
||||
|
||||
// Size of vertex format in 4-byte integers
|
||||
public static final int VERTEX_SIZE = 8;
|
||||
@@ -92,15 +90,13 @@ public class ModelQuadUtil {
|
||||
}
|
||||
|
||||
public static int mergeNormal(int packedNormal, int calcNormal) {
|
||||
if((packedNormal & 0xFFFFFF) == 0)
|
||||
return calcNormal;
|
||||
if ((packedNormal & 0xFFFFFF) == 0) return calcNormal;
|
||||
return packedNormal;
|
||||
}
|
||||
|
||||
public static int mergeBakedLight(int packedLight, int vanillaLightEmission, int calcLight) {
|
||||
// bail early in most cases
|
||||
if (packedLight == 0 && vanillaLightEmission == 0)
|
||||
return calcLight;
|
||||
if (packedLight == 0 && vanillaLightEmission == 0) return calcLight;
|
||||
|
||||
int psl = (packedLight >> 16) & 0xFF;
|
||||
int csl = (calcLight >> 16) & 0xFF;
|
||||
@@ -122,10 +118,10 @@ public class ModelQuadUtil {
|
||||
return colorA;
|
||||
}
|
||||
// General case (rare): Both colorings, actually perform the multiplication
|
||||
int a = (int)((ColorARGB.unpackAlpha(colorA)/255.0f) * (ColorARGB.unpackAlpha(colorB)/255.0f) * 255.0f);
|
||||
int b = (int)((ColorARGB.unpackBlue(colorA)/255.0f) * (ColorARGB.unpackBlue(colorB)/255.0f) * 255.0f);
|
||||
int g = (int)((ColorARGB.unpackGreen(colorA)/255.0f) * (ColorARGB.unpackGreen(colorB)/255.0f) * 255.0f);
|
||||
int r = (int)((ColorARGB.unpackRed(colorA)/255.0f) * (ColorARGB.unpackRed(colorB)/255.0f) * 255.0f);
|
||||
int a = (int) ((ColorARGB.unpackAlpha(colorA) / 255.0f) * (ColorARGB.unpackAlpha(colorB) / 255.0f) * 255.0f);
|
||||
int b = (int) ((ColorARGB.unpackBlue(colorA) / 255.0f) * (ColorARGB.unpackBlue(colorB) / 255.0f) * 255.0f);
|
||||
int g = (int) ((ColorARGB.unpackGreen(colorA) / 255.0f) * (ColorARGB.unpackGreen(colorB) / 255.0f) * 255.0f);
|
||||
int r = (int) ((ColorARGB.unpackRed(colorA) / 255.0f) * (ColorARGB.unpackRed(colorB) / 255.0f) * 255.0f);
|
||||
return ColorARGB.pack(r, g, b, a);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.cel.util;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.api.util.NormI8;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.render.chunk.vertex.format.ChunkVertexEncoder;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class QuadUtil {
|
||||
|
||||
public static ModelQuadFacing findNormalFace(float x, float y, float z) {
|
||||
if (!Float.isFinite(x) || !Float.isFinite(y) || !Float.isFinite(z)) {
|
||||
return ModelQuadFacing.UNASSIGNED;
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.quad.writers;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
|
||||
public interface IWriteQuads {
|
||||
|
||||
void writeQuad(ModelQuadView quad, ByteBuffer buf);
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.quad.writers;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
|
||||
public class ItemVBOQuadWriter implements IWriteQuads {
|
||||
|
||||
private boolean direct;
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.quad.writers;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
|
||||
public class PositionColorTextureQuadWriter implements IWriteQuads {
|
||||
|
||||
private boolean direct;
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.quad.writers;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
|
||||
public class PositionQuadWriter implements IWriteQuads {
|
||||
|
||||
private boolean direct;
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.quad.writers;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
|
||||
public class PositionTextureColorQuadWriter implements IWriteQuads {
|
||||
|
||||
private boolean direct;
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.quad.writers;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
|
||||
public class PositionTextureQuadWriter implements IWriteQuads {
|
||||
|
||||
private boolean direct;
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.renderer.vertex;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.quad.writers.IWriteQuads;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
|
||||
public class VertexFormat {
|
||||
|
||||
Reference in new issue
Block a user