Combine TexturedSphereModel into SphereModel

This commit is contained in:
Sollace 2024-01-26 23:30:22 +00:00
parent 7c7ea1e555
commit 8b7a55d764
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 17 additions and 44 deletions

View file

@ -15,7 +15,7 @@ public class BakedModel {
protected final List<RenderUtil.Vertex> vertices = new ArrayList<>();
protected void addVertex(Vector4f vertex) {
addVertex(vertex.x, vertex.y, vertex.z, 0, 0);
addVertex(vertex.x, vertex.y, vertex.z, (vertex.x + 1) * 0.5F, (vertex.z + 1) * 0.5F);
}
protected void addVertex(float x, float y, float z, float u, float v) {
@ -36,4 +36,19 @@ public class BakedModel {
}
matrices.pop();
}
public final void render(MatrixStack matrices, VertexConsumer buffer, float scale, float r, float g, float b, float a, float uScale, float vScale) {
scale = Math.abs(scale);
if (scale < 0.001F) {
return;
}
matrices.push();
matrices.scale(scale, scale, scale);
for (RenderUtil.Vertex vertex : vertices) {
Vector4f pos = vertex.position(matrices);
buffer.vertex(pos.x, pos.y, pos.z).texture(vertex.u() * uScale, vertex.v() * vScale).color(r, g, b, a).next();
}
matrices.pop();
}
}

View file

@ -1,41 +0,0 @@
package com.minelittlepony.unicopia.client.render.model;
import org.joml.Vector4f;
import com.minelittlepony.unicopia.client.gui.DrawableUtil;
import com.minelittlepony.unicopia.client.render.RenderUtil;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.math.MatrixStack;
public class TexturedSphereModel extends BakedModel {
public static final TexturedSphereModel DISK = new TexturedSphereModel(40, 2, DrawableUtil.PI);
public TexturedSphereModel(double rings, double sectors, double azimuthRange) {
double zenithIncrement = DrawableUtil.PI / rings;
double azimuthIncrement = DrawableUtil.TAU / sectors;
SphereModel.compileVertices(azimuthRange, zenithIncrement, azimuthIncrement, this::addVertex);
}
@Override
protected void addVertex(Vector4f vertex) {
addVertex(vertex.x, vertex.y, vertex.z, vertex.x, vertex.z);
}
public final void render(MatrixStack matrices, VertexConsumer buffer, float scale, float r, float g, float b, float a, float uScale, float vScale) {
scale = Math.abs(scale);
if (scale < 0.001F) {
return;
}
matrices.push();
matrices.scale(scale, scale, scale);
uScale *= 0.5F;
vScale *= 0.5F;
for (RenderUtil.Vertex vertex : vertices) {
Vector4f pos = vertex.position(matrices);
buffer.vertex(pos.x, pos.y, pos.z).texture((vertex.u() + 1) * uScale, (vertex.v() + 1) * vScale).color(r, g, b, a).next();
}
matrices.pop();
}
}

View file

@ -15,7 +15,6 @@ import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.ability.magic.spell.effect.PortalSpell;
import com.minelittlepony.unicopia.client.render.RenderLayers;
import com.minelittlepony.unicopia.client.render.model.SphereModel;
import com.minelittlepony.unicopia.client.render.model.TexturedSphereModel;
import com.minelittlepony.unicopia.entity.EntityReference;
import com.minelittlepony.unicopia.entity.mob.UEntities;
import com.minelittlepony.unicopia.mixin.client.MixinMinecraftClient;
@ -96,7 +95,7 @@ class PortalFrameBuffer implements AutoCloseable {
RenderSystem.setShader(GameRenderer::getPositionTexColorProgram);
RenderSystem._setShaderTexture(0, framebuffer.getColorAttachment());
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
TexturedSphereModel.DISK.render(matrices, buffer, 2F, 1, 1, 1, 1, uScale, vScale);
SphereModel.DISK.render(matrices, buffer, 2F, 1, 1, 1, 1, uScale, vScale);
tessellator.draw();
client.getTextureManager().bindTexture(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE);