util and core cleanup

- Consolidate/audit utility classes
 - Move more towards sane vertex types
This commit is contained in:
Jozufozu 2021-12-22 00:22:43 -08:00
parent aa96a28f0b
commit b8034b4b2e
14 changed files with 126 additions and 175 deletions

View file

@ -25,8 +25,8 @@ import javax.annotation.Nullable;
import org.apache.commons.lang3.tuple.MutablePair; import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import com.jozufozu.flywheel.light.GridAlignedBB; import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.jozufozu.flywheel.light.ImmutableBox; import com.jozufozu.flywheel.util.box.ImmutableBox;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllInteractionBehaviours; import com.simibubi.create.AllInteractionBehaviours;
import com.simibubi.create.AllMovementBehaviours; import com.simibubi.create.AllMovementBehaviours;

View file

@ -1,8 +1,8 @@
package com.simibubi.create.content.contraptions.components.structureMovement; package com.simibubi.create.content.contraptions.components.structureMovement;
import com.jozufozu.flywheel.light.GPULightVolume; import com.jozufozu.flywheel.light.GPULightVolume;
import com.jozufozu.flywheel.light.GridAlignedBB; import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.jozufozu.flywheel.light.ImmutableBox; import com.jozufozu.flywheel.util.box.ImmutableBox;
import com.jozufozu.flywheel.light.LightListener; import com.jozufozu.flywheel.light.LightListener;
import com.jozufozu.flywheel.light.LightProvider; import com.jozufozu.flywheel.light.LightProvider;
import com.jozufozu.flywheel.light.LightUpdater; import com.jozufozu.flywheel.light.LightUpdater;

View file

@ -1,7 +1,7 @@
package com.simibubi.create.content.contraptions.components.structureMovement; package com.simibubi.create.content.contraptions.components.structureMovement;
import com.jozufozu.flywheel.light.GridAlignedBB; import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.jozufozu.flywheel.light.ImmutableBox; import com.jozufozu.flywheel.util.box.ImmutableBox;
import com.jozufozu.flywheel.light.LightProvider; import com.jozufozu.flywheel.light.LightProvider;
import com.jozufozu.flywheel.light.MovingListener; import com.jozufozu.flywheel.light.MovingListener;
import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.AllConfigs;

View file

@ -1,6 +1,6 @@
package com.simibubi.create.content.contraptions.components.structureMovement.bearing; package com.simibubi.create.content.contraptions.components.structureMovement.bearing;
import com.jozufozu.flywheel.light.GridAlignedBB; import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter;

View file

@ -8,29 +8,21 @@ import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance;
import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.instancing.ConditionalInstance; import com.jozufozu.flywheel.core.instancing.ConditionalInstance;
import com.jozufozu.flywheel.core.materials.oriented.OrientedData; import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
import com.jozufozu.flywheel.core.model.Model;
import com.jozufozu.flywheel.util.ModelReader;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Quaternion; import com.mojang.math.Quaternion;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.AllStitchedTextures;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.VecHelper;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.LightLayer; import net.minecraft.world.level.LightLayer;
import net.minecraft.world.phys.Vec3;
public class GlueInstance extends EntityInstance<SuperGlueEntity> implements ITickableInstance { public class GlueInstance extends EntityInstance<SuperGlueEntity> implements ITickableInstance {
private static final boolean USE_ATLAS = false;
private static final ResourceLocation TEXTURE = Create.asResource("textures/entity/super_glue/slime.png"); private static final ResourceLocation TEXTURE = Create.asResource("textures/entity/super_glue/slime.png");
private final Quaternion rotation; private final Quaternion rotation;
@ -51,9 +43,9 @@ public class GlueInstance extends EntityInstance<SuperGlueEntity> implements ITi
} }
private Instancer<OrientedData> getInstancer(MaterialManager materialManager, SuperGlueEntity entity) { private Instancer<OrientedData> getInstancer(MaterialManager materialManager, SuperGlueEntity entity) {
MaterialGroup group = USE_ATLAS ? materialManager.defaultCutout() : materialManager.cutout(RenderType.entityCutout(TEXTURE)); MaterialGroup group = GlueModel.USE_ATLAS ? materialManager.defaultCutout() : materialManager.cutout(RenderType.entityCutout(TEXTURE));
return group.material(Materials.ORIENTED).model(entity.getType(), GlueModel::new); return group.material(Materials.ORIENTED).model(entity.getType(), GlueModel::get);
} }
@Override @Override
@ -94,144 +86,4 @@ public class GlueInstance extends EntityInstance<SuperGlueEntity> implements ITi
|| AllItems.SUPER_GLUE.isIn(player.getOffhandItem()); || AllItems.SUPER_GLUE.isIn(player.getOffhandItem());
} }
public static class GlueModel implements Model, ModelReader {
@Override
public String name() {
return "glue";
}
public void buffer(VertexConsumer buffer) {
Vec3 diff = Vec3.atLowerCornerOf(Direction.SOUTH.getNormal());
Vec3 extension = diff.normalize()
.scale(1 / 32f - 1 / 128f);
Vec3 plane = VecHelper.axisAlingedPlaneOf(diff);
Direction.Axis axis = Direction.getNearest(diff.x, diff.y, diff.z)
.getAxis();
Vec3 start = Vec3.ZERO.subtract(extension);
Vec3 end = Vec3.ZERO.add(extension);
plane = plane.scale(1 / 2f);
Vec3 a1 = plane.add(start);
Vec3 b1 = plane.add(end);
plane = VecHelper.rotate(plane, -90, axis);
Vec3 a2 = plane.add(start);
Vec3 b2 = plane.add(end);
plane = VecHelper.rotate(plane, -90, axis);
Vec3 a3 = plane.add(start);
Vec3 b3 = plane.add(end);
plane = VecHelper.rotate(plane, -90, axis);
Vec3 a4 = plane.add(start);
Vec3 b4 = plane.add(end);
float minU;
float maxU;
float minV;
float maxV;
if (USE_ATLAS) {
TextureAtlasSprite sprite = AllStitchedTextures.SUPER_GLUE.get();
minU = sprite.getU0();
maxU = sprite.getU1();
minV = sprite.getV0();
maxV = sprite.getV1();
} else {
minU = minV = 0;
maxU = maxV = 1;
}
// inside quad
buffer.vertex(a1.x, a1.y, a1.z).normal(0, 0, -1f).uv(maxU, minV).endVertex();
buffer.vertex(a2.x, a2.y, a2.z).normal(0, 0, -1f).uv(maxU, maxV).endVertex();
buffer.vertex(a3.x, a3.y, a3.z).normal(0, 0, -1f).uv(minU, maxV).endVertex();
buffer.vertex(a4.x, a4.y, a4.z).normal(0, 0, -1f).uv(minU, minV).endVertex();
// outside quad
buffer.vertex(b4.x, b4.y, b4.z).normal(0, 0, 1f).uv(minU, minV).endVertex();
buffer.vertex(b3.x, b3.y, b3.z).normal(0, 0, 1f).uv(minU, maxV).endVertex();
buffer.vertex(b2.x, b2.y, b2.z).normal(0, 0, 1f).uv(maxU, maxV).endVertex();
buffer.vertex(b1.x, b1.y, b1.z).normal(0, 0, 1f).uv(maxU, minV).endVertex();
}
@Override
public int vertexCount() {
return 8;
}
@Override
public ModelReader getReader() {
return this;
}
@Override
public int getVertexCount() {
return 8;
}
@Override
public float getX(int index) {
return 0;
}
@Override
public float getY(int index) {
return 0;
}
@Override
public float getZ(int index) {
return 0;
}
@Override
public byte getR(int index) {
return (byte) 0xFF;
}
@Override
public byte getG(int index) {
return (byte) 0xFF;
}
@Override
public byte getB(int index) {
return (byte) 0xFF;
}
@Override
public byte getA(int index) {
return (byte) 0xFF;
}
@Override
public float getU(int index) {
return 0;
}
@Override
public float getV(int index) {
return 0;
}
@Override
public int getLight(int index) {
return 0;
}
@Override
public float getNX(int index) {
return 0;
}
@Override
public float getNY(int index) {
return 0;
}
@Override
public float getNZ(int index) {
return index > 4 ? -1 : 1;
}
}
} }

View file

@ -0,0 +1,99 @@
package com.simibubi.create.content.contraptions.components.structureMovement.glue;
import com.jozufozu.flywheel.core.model.Model;
import com.jozufozu.flywheel.core.vertex.PosTexNormalVertexListUnsafe;
import com.jozufozu.flywheel.core.vertex.PosTexNormalWriter;
import com.jozufozu.flywheel.core.vertex.VertexList;
import com.mojang.blaze3d.platform.MemoryTracker;
import com.simibubi.create.AllStitchedTextures;
import com.simibubi.create.foundation.utility.VecHelper;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.Direction;
import net.minecraft.world.phys.Vec3;
public class GlueModel implements Model {
public static final GlueModel INSTANCE = new GlueModel();
static final boolean USE_ATLAS = false;
public static GlueModel get() {
return INSTANCE;
}
private final PosTexNormalVertexListUnsafe reader;
private GlueModel() {
PosTexNormalWriter writer = new PosTexNormalWriter(MemoryTracker.create(size()));
createGlueModel(writer);
reader = writer.intoReader();
}
@Override
public String name() {
return "glue";
}
@Override
public int vertexCount() {
return 8;
}
@Override
public VertexList getReader() {
return reader;
}
public static void createGlueModel(PosTexNormalWriter buffer) {
Vec3 diff = Vec3.atLowerCornerOf(Direction.SOUTH.getNormal());
Vec3 extension = diff.normalize()
.scale(1 / 32f - 1 / 128f);
Vec3 plane = VecHelper.axisAlingedPlaneOf(diff);
Direction.Axis axis = Direction.getNearest(diff.x, diff.y, diff.z)
.getAxis();
Vec3 start = Vec3.ZERO.subtract(extension);
Vec3 end = Vec3.ZERO.add(extension);
plane = plane.scale(1 / 2f);
Vec3 a1 = plane.add(start);
Vec3 b1 = plane.add(end);
plane = VecHelper.rotate(plane, -90, axis);
Vec3 a2 = plane.add(start);
Vec3 b2 = plane.add(end);
plane = VecHelper.rotate(plane, -90, axis);
Vec3 a3 = plane.add(start);
Vec3 b3 = plane.add(end);
plane = VecHelper.rotate(plane, -90, axis);
Vec3 a4 = plane.add(start);
Vec3 b4 = plane.add(end);
float minU;
float maxU;
float minV;
float maxV;
if (USE_ATLAS) {
TextureAtlasSprite sprite = AllStitchedTextures.SUPER_GLUE.get();
minU = sprite.getU0();
maxU = sprite.getU1();
minV = sprite.getV0();
maxV = sprite.getV1();
} else {
minU = minV = 0;
maxU = maxV = 1;
}
// inside quad
buffer.putVertex((float) a1.x, (float) a1.y, (float) a1.z, 0, 0, -1, maxU, minV);
buffer.putVertex((float) a2.x, (float) a2.y, (float) a2.z, 0, 0, -1, maxU, maxV);
buffer.putVertex((float) a3.x, (float) a3.y, (float) a3.z, 0, 0, -1, minU, maxV);
buffer.putVertex((float) a4.x, (float) a4.y, (float) a4.z, 0, 0, -1, minU, minV);
// outside quad
buffer.putVertex((float) b4.x, (float) b4.y, (float) b4.z, 0, 0, 1f, minU, minV);
buffer.putVertex((float) b3.x, (float) b3.y, (float) b3.z, 0, 0, 1f, minU, maxV);
buffer.putVertex((float) b2.x, (float) b2.y, (float) b2.z, 0, 0, 1f, maxU, maxV);
buffer.putVertex((float) b1.x, (float) b1.y, (float) b1.z, 0, 0, 1f, maxU, minV);
}
}

View file

@ -1,6 +1,6 @@
package com.simibubi.create.content.contraptions.components.structureMovement.piston; package com.simibubi.create.content.contraptions.components.structureMovement.piston;
import com.jozufozu.flywheel.light.GridAlignedBB; import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;

View file

@ -7,8 +7,8 @@ import com.jozufozu.flywheel.core.instancing.ConditionalInstance;
import com.jozufozu.flywheel.core.instancing.GroupInstance; import com.jozufozu.flywheel.core.instancing.GroupInstance;
import com.jozufozu.flywheel.core.instancing.SelectInstance; import com.jozufozu.flywheel.core.instancing.SelectInstance;
import com.jozufozu.flywheel.core.materials.oriented.OrientedData; import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
import com.jozufozu.flywheel.light.GridAlignedBB; import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.jozufozu.flywheel.light.ImmutableBox; import com.jozufozu.flywheel.util.box.ImmutableBox;
import com.jozufozu.flywheel.light.LightPacking; import com.jozufozu.flywheel.light.LightPacking;
import com.jozufozu.flywheel.light.LightProvider; import com.jozufozu.flywheel.light.LightProvider;
import com.jozufozu.flywheel.light.LightUpdater; import com.jozufozu.flywheel.light.LightUpdater;

View file

@ -1,6 +1,6 @@
package com.simibubi.create.content.contraptions.components.structureMovement.pulley; package com.simibubi.create.content.contraptions.components.structureMovement.pulley;
import com.jozufozu.flywheel.light.GridAlignedBB; import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter;

View file

@ -1,6 +1,6 @@
package com.simibubi.create.content.contraptions.components.structureMovement.render; package com.simibubi.create.content.contraptions.components.structureMovement.render;
import com.jozufozu.flywheel.light.GridAlignedBB; import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter;

View file

@ -8,7 +8,7 @@ import com.jozufozu.flywheel.backend.RenderLayer;
import com.jozufozu.flywheel.backend.gl.GlTextureUnit; import com.jozufozu.flywheel.backend.gl.GlTextureUnit;
import com.jozufozu.flywheel.backend.gl.GlVertexArray; import com.jozufozu.flywheel.backend.gl.GlVertexArray;
import com.jozufozu.flywheel.event.RenderLayerEvent; import com.jozufozu.flywheel.event.RenderLayerEvent;
import com.jozufozu.flywheel.util.TextureBinder; import com.jozufozu.flywheel.util.Textures;
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
import com.simibubi.create.foundation.render.AllProgramSpecs; import com.simibubi.create.foundation.render.AllProgramSpecs;
import com.simibubi.create.foundation.render.CreateContexts; import com.simibubi.create.foundation.render.CreateContexts;
@ -44,7 +44,7 @@ public class FlwContraptionManager extends ContraptionRenderManager<RenderedCont
layer.setupRenderState(); layer.setupRenderState();
TextureBinder.bindActiveTextures(); Textures.bindActiveTextures();
ContraptionProgram structureShader = CreateContexts.STRUCTURE.getProgram(AllProgramSpecs.STRUCTURE); ContraptionProgram structureShader = CreateContexts.STRUCTURE.getProgram(AllProgramSpecs.STRUCTURE);

View file

@ -13,8 +13,8 @@ import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
import com.jozufozu.flywheel.light.GridAlignedBB; import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.jozufozu.flywheel.light.ImmutableBox; import com.jozufozu.flywheel.util.box.ImmutableBox;
import com.jozufozu.flywheel.light.LightListener; import com.jozufozu.flywheel.light.LightListener;
import com.jozufozu.flywheel.light.LightProvider; import com.jozufozu.flywheel.light.LightProvider;
import com.jozufozu.flywheel.light.LightUpdater; import com.jozufozu.flywheel.light.LightUpdater;

View file

@ -2,7 +2,6 @@ package com.simibubi.create.foundation.render;
import com.jozufozu.flywheel.backend.gl.attrib.CommonAttributes; import com.jozufozu.flywheel.backend.gl.attrib.CommonAttributes;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.core.Formats;
public class AllInstanceFormats { public class AllInstanceFormats {
@ -27,7 +26,8 @@ public class AllInstanceFormats {
.build(); .build();
private static VertexFormat.Builder kineticInstance() { private static VertexFormat.Builder kineticInstance() {
return Formats.litInstance() return VertexFormat.builder()
.addAttributes(CommonAttributes.LIGHT, CommonAttributes.RGBA)
.addAttributes(CommonAttributes.VEC3, CommonAttributes.FLOAT, CommonAttributes.FLOAT); .addAttributes(CommonAttributes.VEC3, CommonAttributes.FLOAT, CommonAttributes.FLOAT);
} }
} }

View file

@ -1,7 +1,7 @@
package com.simibubi.create.foundation.render; package com.simibubi.create.foundation.render;
import com.jozufozu.flywheel.util.BlockFormatReader; import com.jozufozu.flywheel.core.vertex.BlockVertexList;
import com.jozufozu.flywheel.util.ModelReader; import com.jozufozu.flywheel.core.vertex.VertexList;
import com.jozufozu.flywheel.util.transform.Rotate; import com.jozufozu.flywheel.util.transform.Rotate;
import com.jozufozu.flywheel.util.transform.Scale; import com.jozufozu.flywheel.util.transform.Scale;
import com.jozufozu.flywheel.util.transform.TStack; import com.jozufozu.flywheel.util.transform.TStack;
@ -32,7 +32,7 @@ import net.minecraftforge.client.model.pipeline.LightUtil;
public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperByteBuffer>, Rotate<SuperByteBuffer>, TStack<SuperByteBuffer> { public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperByteBuffer>, Rotate<SuperByteBuffer>, TStack<SuperByteBuffer> {
private final ModelReader template; private final VertexList template;
// Vertex Position // Vertex Position
private final PoseStack transforms; private final PoseStack transforms;
@ -64,7 +64,7 @@ public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperB
private static final Long2IntMap WORLD_LIGHT_CACHE = new Long2IntOpenHashMap(); private static final Long2IntMap WORLD_LIGHT_CACHE = new Long2IntOpenHashMap();
public SuperByteBuffer(BufferBuilder buf) { public SuperByteBuffer(BufferBuilder buf) {
template = new BlockFormatReader(buf); template = new BlockVertexList(buf);
transforms = new PoseStack(); transforms = new PoseStack();
transforms.pushPose(); transforms.pushPose();
} }