Some wip stuff

This commit is contained in:
Sollace 2022-12-29 22:22:46 +01:00
parent 332baf583b
commit e69076d19a
7 changed files with 123 additions and 31 deletions

View file

@ -8,7 +8,7 @@ import org.joml.Vector4f;
import com.minelittlepony.common.client.gui.GameGui; import com.minelittlepony.common.client.gui.GameGui;
import com.minelittlepony.unicopia.ability.magic.spell.*; import com.minelittlepony.unicopia.ability.magic.spell.*;
import com.minelittlepony.unicopia.client.FlowingText; import com.minelittlepony.unicopia.client.FlowingText;
import com.minelittlepony.unicopia.client.particle.SphereModel; import com.minelittlepony.unicopia.client.render.model.SphereModel;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.network.Channel; import com.minelittlepony.unicopia.network.Channel;

View file

@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.client.particle;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import com.minelittlepony.unicopia.client.render.model.SphereModel;
import com.minelittlepony.unicopia.particle.SphereParticleEffect; import com.minelittlepony.unicopia.particle.SphereParticleEffect;
import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumer;

View file

@ -14,6 +14,7 @@ import net.minecraft.util.math.Vec3d;
import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.client.render.RenderLayers; import com.minelittlepony.unicopia.client.render.RenderLayers;
import com.minelittlepony.unicopia.client.render.model.SphereModel;
import com.minelittlepony.unicopia.particle.SphereParticleEffect; import com.minelittlepony.unicopia.particle.SphereParticleEffect;
import com.minelittlepony.unicopia.particle.ParticleHandle.Attachment; import com.minelittlepony.unicopia.particle.ParticleHandle.Attachment;
import com.minelittlepony.unicopia.particle.ParticleHandle.Link; import com.minelittlepony.unicopia.particle.ParticleHandle.Link;

View file

@ -1,7 +1,7 @@
package com.minelittlepony.unicopia.client.render.entity; package com.minelittlepony.unicopia.client.render.entity;
import com.minelittlepony.unicopia.client.particle.SphereModel;
import com.minelittlepony.unicopia.client.render.RenderLayers; import com.minelittlepony.unicopia.client.render.RenderLayers;
import com.minelittlepony.unicopia.client.render.model.SphereModel;
import com.minelittlepony.unicopia.entity.FairyEntity; import com.minelittlepony.unicopia.entity.FairyEntity;
import net.minecraft.client.render.*; import net.minecraft.client.render.*;
import net.minecraft.client.render.entity.EntityRendererFactory; import net.minecraft.client.render.entity.EntityRendererFactory;

View file

@ -0,0 +1,40 @@
package com.minelittlepony.unicopia.client.render.model;
import java.util.ArrayList;
import java.util.List;
import org.joml.Matrix4f;
import org.joml.Vector4f;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.math.MatrixStack;
public class BakedModel {
private static final Vector4f drawVert = new Vector4f();
protected final List<Vertex> vertices = new ArrayList<>();
protected void addVertex(Vector4f vertex) {
addVertex(vertex.x, vertex.y, vertex.z, 0, 0);
}
protected void addVertex(float x, float y, float z, float u, float v) {
vertices.add(new Vertex(x, y, z, u, v));
}
public final void render(MatrixStack matrices, VertexConsumer vertexWriter, int light, int overlay, float scale, float r, float g, float b, float a) {
scale = Math.abs(scale);
if (scale < 0.001F) {
return;
}
Matrix4f model = matrices.peek().getPositionMatrix();
for (Vertex vertex : vertices) {
drawVert.set(vertex.x() * scale, vertex.y() * scale, vertex.z() * scale, 1);
drawVert.mul(model);
vertexWriter.vertex(drawVert.x, drawVert.y, drawVert.z, r, g, b, a, vertex.u(), vertex.v(), overlay, light, 0, 0, 0);
}
}
record Vertex(float x, float y, float z, float u, float v) {}
}

View file

@ -0,0 +1,71 @@
package com.minelittlepony.unicopia.client.render.model;
public class CrystalModel extends BakedModel {
public CrystalModel(int x, int z, int height) {
// top
buildFace((xx, xz) -> {
addVertex(
x * xx,
xx * 2 + xz * 2,
z * xz,
xx, xz
);
});
// north
buildFace((xx, xy) -> {
addVertex(
x * xx,
height * xy - (xx * (xy - 1)) * 2F,
0,
xx, xy
);
});
// south
buildFace((xx, xy) -> {
addVertex(
x * xx,
height * xy - (xy - 1) * 2 - (xx * (xy - 1)) * 2F,
z,
xx, xy
);
});
// east
buildFace((zz, xy) -> {
addVertex(
0,
height * xy - (zz * (xy - 1)) * 2F,
z * zz,
zz, xy
);
});
// west
buildFace((zz, xy) -> {
addVertex(
x,
height * xy - (xy - 1) * 2 - (zz * (xy - 1)) * 2F,
z * zz,
zz, xy
);
});
// bottom
buildFace((xx, xz) -> {
addVertex(
x * xx,
height,
z * xz,
xx, xz
);
});
}
static void buildFace(BiFloatConsumer consumer) {
consumer.accept(0, 0);
consumer.accept(1, 0);
consumer.accept(1, 1);
consumer.accept(0, 1);
}
interface BiFloatConsumer {
void accept(float a, float b);
}
}

View file

@ -1,54 +1,33 @@
package com.minelittlepony.unicopia.client.particle; package com.minelittlepony.unicopia.client.render.model;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.joml.Matrix4f;
import org.joml.Vector4f; import org.joml.Vector4f;
import com.minelittlepony.unicopia.client.gui.DrawableUtil; import com.minelittlepony.unicopia.client.gui.DrawableUtil;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.client.util.math.MatrixStack;
public class SphereModel { public class SphereModel extends BakedModel {
public static final SphereModel SPHERE = new SphereModel(40, 40, DrawableUtil.TAU); public static final SphereModel SPHERE = new SphereModel(40, 40, DrawableUtil.TAU);
public static final SphereModel DISK = new SphereModel(40, 2, DrawableUtil.PI); public static final SphereModel DISK = new SphereModel(40, 2, DrawableUtil.PI);
public static final SphereModel HEXAGON = new SphereModel(3, 2, DrawableUtil.TAU); public static final SphereModel HEXAGON = new SphereModel(3, 2, DrawableUtil.TAU);
public static final SphereModel PRISM = new SphereModel(6, 6, DrawableUtil.TAU); public static final SphereModel PRISM = new SphereModel(6, 6, DrawableUtil.TAU);
private final List<Vector4f> vertices = new ArrayList<>();
private final Vector4f drawVert = new Vector4f();
public SphereModel(double rings, double sectors, double azimuthRange) { public SphereModel(double rings, double sectors, double azimuthRange) {
double zenithIncrement = DrawableUtil.PI / rings; double zenithIncrement = DrawableUtil.PI / rings;
double azimuthIncrement = DrawableUtil.TAU / sectors; double azimuthIncrement = DrawableUtil.TAU / sectors;
compileVertices(azimuthRange, zenithIncrement, azimuthIncrement, vertices::add); compileVertices(azimuthRange, zenithIncrement, azimuthIncrement, this::addVertex);
}
public final void render(MatrixStack matrices, VertexConsumer vertexWriter, int light, int overlay, float radius, float r, float g, float b, float a) {
radius = Math.abs(radius);
if (radius < 0.001F) {
return;
}
Matrix4f model = matrices.peek().getPositionMatrix();
for (Vector4f vertex : vertices) {
drawVert.set(vertex.x * radius, vertex.y * radius, vertex.z * radius, vertex.w);
drawVert.mul(model);
vertexWriter.vertex(drawVert.x, drawVert.y, drawVert.z, r, g, b, a, 0, 0, overlay, light, 0, 0, 0);
}
} }
private static void compileVertices(double azimuthRange, double zenithIncrement, double azimuthIncrement, Consumer<Vector4f> collector) { private static void compileVertices(double azimuthRange, double zenithIncrement, double azimuthIncrement, Consumer<Vector4f> collector) {
Vector4f vector = new Vector4f();
for (double zenith = 0; zenith < DrawableUtil.PI; zenith += zenithIncrement) { for (double zenith = 0; zenith < DrawableUtil.PI; zenith += zenithIncrement) {
for (double azimuth = 0; azimuth < azimuthRange; azimuth += azimuthIncrement) { for (double azimuth = 0; azimuth < azimuthRange; azimuth += azimuthIncrement) {
collector.accept(convertToCartesianCoord(new Vector4f(), 1, zenith, azimuth)); collector.accept(convertToCartesianCoord(vector, 1, zenith, azimuth));
collector.accept(convertToCartesianCoord(new Vector4f(), 1, zenith + zenithIncrement, azimuth)); collector.accept(convertToCartesianCoord(vector, 1, zenith + zenithIncrement, azimuth));
collector.accept(convertToCartesianCoord(new Vector4f(), 1, zenith + zenithIncrement, azimuth + azimuthIncrement)); collector.accept(convertToCartesianCoord(vector, 1, zenith + zenithIncrement, azimuth + azimuthIncrement));
collector.accept(convertToCartesianCoord(new Vector4f(), 1, zenith, azimuth + azimuthIncrement)); collector.accept(convertToCartesianCoord(vector, 1, zenith, azimuth + azimuthIncrement));
} }
} }
} }