Basic model abstraction

- Stop providing a buffered model supplier
 - Instead, provide an IModel supplier
 - IModel exposes basic properties of models
 - IModel exposes a method to copy the model to a VecBuffer
This commit is contained in:
Jozufozu 2021-07-23 12:26:33 -07:00
parent b188f97ae0
commit f06983c339

View file

@ -1,5 +1,6 @@
package com.simibubi.create.content.contraptions.components.structureMovement.glue; package com.simibubi.create.content.contraptions.components.structureMovement.glue;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
import com.jozufozu.flywheel.backend.instancing.ITickableInstance; import com.jozufozu.flywheel.backend.instancing.ITickableInstance;
import com.jozufozu.flywheel.backend.instancing.Instancer; import com.jozufozu.flywheel.backend.instancing.Instancer;
@ -7,12 +8,15 @@ import com.jozufozu.flywheel.backend.material.MaterialManager;
import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance; import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance;
import com.jozufozu.flywheel.backend.material.MaterialGroup; import com.jozufozu.flywheel.backend.material.MaterialGroup;
import com.jozufozu.flywheel.backend.model.BufferedModel; import com.jozufozu.flywheel.backend.model.BufferedModel;
import com.jozufozu.flywheel.backend.model.ElementBuffer;
import com.jozufozu.flywheel.backend.model.IndexedModel; import com.jozufozu.flywheel.backend.model.IndexedModel;
import com.jozufozu.flywheel.backend.state.TextureRenderState; import com.jozufozu.flywheel.backend.state.TextureRenderState;
import com.jozufozu.flywheel.core.Formats; import com.jozufozu.flywheel.core.Formats;
import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.QuadConverter;
import com.jozufozu.flywheel.core.instancing.ConditionalInstance; import com.jozufozu.flywheel.core.instancing.ConditionalInstance;
import com.jozufozu.flywheel.core.materials.OrientedData; import com.jozufozu.flywheel.core.materials.OrientedData;
import com.jozufozu.flywheel.core.model.IModel;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.AllStitchedTextures; import com.simibubi.create.AllStitchedTextures;
import com.simibubi.create.Create; import com.simibubi.create.Create;
@ -54,7 +58,7 @@ 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.defaultSolid() : materialManager.solid(TextureRenderState.get(TEXTURE)); MaterialGroup<?> group = USE_ATLAS ? materialManager.defaultSolid() : materialManager.solid(TextureRenderState.get(TEXTURE));
return group.material(Materials.ORIENTED).model(entity.getType(), GlueInstance::supplyModel); return group.material(Materials.ORIENTED).model(entity.getType(), GlueModel::new);
} }
@Override @Override
@ -95,7 +99,9 @@ public class GlueInstance extends EntityInstance<SuperGlueEntity> implements ITi
|| AllItems.SUPER_GLUE.isIn(player.getOffhandItem()); || AllItems.SUPER_GLUE.isIn(player.getOffhandItem());
} }
public static BufferedModel supplyModel() { public static class GlueModel implements IModel {
@Override
public void buffer(VecBuffer buffer) {
Vector3d diff = Vector3d.atLowerCornerOf(Direction.SOUTH.getNormal()); Vector3d diff = Vector3d.atLowerCornerOf(Direction.SOUTH.getNormal());
Vector3d extension = diff.normalize() Vector3d extension = diff.normalize()
.scale(1 / 32f - 1 / 128f); .scale(1 / 32f - 1 / 128f);
@ -120,8 +126,6 @@ public class GlueInstance extends EntityInstance<SuperGlueEntity> implements ITi
Vector3d a4 = plane.add(start); Vector3d a4 = plane.add(start);
Vector3d b4 = plane.add(end); Vector3d b4 = plane.add(end);
VecBuffer buffer = VecBuffer.allocate(Formats.UNLIT_MODEL.getStride() * 8);
float minU; float minU;
float maxU; float maxU;
float minV; float minV;
@ -149,10 +153,22 @@ public class GlueInstance extends EntityInstance<SuperGlueEntity> implements ITi
buffer.putVec3((float) b3.x, (float) b3.y, (float) b3.z).putVec3((byte) 0, (byte) 0, (byte) 127).putVec2(minU, maxV); buffer.putVec3((float) b3.x, (float) b3.y, (float) b3.z).putVec3((byte) 0, (byte) 0, (byte) 127).putVec2(minU, maxV);
buffer.putVec3((float) b2.x, (float) b2.y, (float) b2.z).putVec3((byte) 0, (byte) 0, (byte) 127).putVec2(maxU, maxV); buffer.putVec3((float) b2.x, (float) b2.y, (float) b2.z).putVec3((byte) 0, (byte) 0, (byte) 127).putVec2(maxU, maxV);
buffer.putVec3((float) b1.x, (float) b1.y, (float) b1.z).putVec3((byte) 0, (byte) 0, (byte) 127).putVec2(maxU, minV); buffer.putVec3((float) b1.x, (float) b1.y, (float) b1.z).putVec3((byte) 0, (byte) 0, (byte) 127).putVec2(maxU, minV);
}
buffer.rewind(); @Override
public int vertexCount() {
return 8;
}
@Override
public VertexFormat format() {
return Formats.UNLIT_MODEL;
}
return IndexedModel.fromSequentialQuads(Formats.UNLIT_MODEL, buffer.unwrap(), 8); @Override
public ElementBuffer createEBO() {
return QuadConverter.getInstance()
.quads2Tris(2);
}
} }
} }