Skip to content

Commit 5e65a6f

Browse files
committed
bring shapes to somewhat usable state, still broken and not pretty, missing culling control, text renders or not.
1 parent 976d614 commit 5e65a6f

File tree

1 file changed

+44
-31
lines changed

1 file changed

+44
-31
lines changed

src/main/java/carpet/script/utils/ShapesRenderer.java

+44-31
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ else if (shape.align == 1)
524524
text_x = (float) (-textRenderer.width(shape.value.getString()));
525525
}
526526
MultiBufferSource.BufferSource immediate = MultiBufferSource.immediate(new ByteBufferBuilder(RenderType.TRANSIENT_BUFFER_SIZE));
527+
// text doesn't appear if backgroud is set
528+
///script run draw_shape('label', 100, 'pos', [200, 100, 200], 'text', 'Hewwo World!', 'color', 0xffffffff, 'fill', 0x33333333)
527529
textRenderer.drawInBatch(shape.value, text_x, 0.0F, shape.textcolor, false, matrices.last().pose(), immediate, Font.DisplayMode.NORMAL, shape.textbck, 15728880);
528530
immediate.endBatch();
529531
matrices.popPose();
@@ -616,8 +618,8 @@ public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, do
616618
}
617619
}
618620

619-
private static void drawWithShader(MeshData mesh) {
620-
RenderType.debugLineStrip(1.0).draw(mesh);
621+
private static void drawWithShader(MeshData mesh, RenderType type) {
622+
type.draw(mesh);
621623
//VertexBuffer buffre = mesh.drawState().format().getImmediateDrawVertexBuffer();
622624
//buffre.bind();
623625
//buffre.upload(mesh);
@@ -630,6 +632,17 @@ public static class RenderedPolyface extends RenderedShape<ShapeDispatcher.Polyf
630632
private static final VertexFormat.Mode[] faceIndices = new VertexFormat.Mode[]{
631633
Mode.LINES, Mode.LINE_STRIP, Mode.DEBUG_LINES, Mode.DEBUG_LINE_STRIP, Mode.TRIANGLES, Mode.TRIANGLE_STRIP, Mode.TRIANGLE_FAN, Mode.QUADS};
632634

635+
private static final RenderType [] renderTypes = new RenderType[] {
636+
RenderType.debugLineStrip(1),
637+
RenderType.debugLineStrip(1),
638+
RenderType.debugLineStrip(1),
639+
RenderType.debugLineStrip(1),
640+
RenderType.debugLineStrip(1), // TODO wrong
641+
RenderType.debugLineStrip(1), // TODO wrong
642+
RenderType.debugLineStrip(1),
643+
RenderType.debugQuads()
644+
};
645+
633646
public RenderedPolyface(Minecraft client, ShapeDispatcher.ExpiringShape shape)
634647
{
635648
super(client, (ShapeDispatcher.Polyface) shape);
@@ -662,7 +675,7 @@ public void renderFaces(Tesselator tesselator, double cx, double cy, double cz,
662675
}
663676
builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.fr, shape.fg, shape.fb, shape.fa);
664677
}
665-
drawWithShader(builder.buildOrThrow());
678+
drawWithShader(builder.buildOrThrow(), renderTypes[shape.mode]);
666679

667680
////RenderSystem.disableCull();
668681
////RenderSystem.depthMask(false);
@@ -698,7 +711,7 @@ public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, do
698711
builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a);
699712
}
700713
builder.addVertex((float) (vec0.x() - cx), (float) (vec0.y() - cy), (float) (vec0.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a);
701-
drawWithShader(builder.buildOrThrow());
714+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
702715
if (shape.inneredges)
703716
{
704717
BufferBuilder builderr = tesselator.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR);
@@ -713,7 +726,7 @@ public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, do
713726
builderr.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a);
714727
builderr.addVertex((float) (vec0.x() - cx), (float) (vec0.y() - cy), (float) (vec0.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a);
715728
}
716-
drawWithShader(builderr.buildOrThrow());
729+
drawWithShader(builderr.buildOrThrow(), RenderType.debugLineStrip(1));
717730
}
718731
return;
719732
}
@@ -758,7 +771,7 @@ public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, do
758771
builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a);
759772
}
760773
}
761-
drawWithShader(builder.buildOrThrow());
774+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
762775
return;
763776
}
764777
if (shape.mode == 4)
@@ -792,7 +805,7 @@ public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, do
792805
builder.addVertex((float) (vecC.x() - cx), (float) (vecC.y() - cy), (float) (vecC.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a);
793806
builder.addVertex((float) (vecA.x() - cx), (float) (vecA.y() - cy), (float) (vecA.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a);
794807
}
795-
drawWithShader(builder.buildOrThrow());
808+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
796809
}
797810
}
798811
}
@@ -881,7 +894,7 @@ public static void drawLine(Tesselator tesselator, float x1, float y1, float z1,
881894
BufferBuilder builder = tesselator.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR);
882895
builder.addVertex(x1, y1, z1).setColor(red1, grn1, blu1, alpha);
883896
builder.addVertex(x2, y2, z2).setColor(red1, grn1, blu1, alpha);
884-
drawWithShader(builder.buildOrThrow());
897+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
885898
}
886899

887900
public static void drawBoxWireGLLines(
@@ -934,7 +947,7 @@ public static void drawBoxWireGLLines(
934947
builder.addVertex(x2, y2, z1).setColor(red1, grn1, blu1, alpha);
935948
builder.addVertex(x2, y2, z2).setColor(red1, grn1, blu1, alpha);
936949
}
937-
drawWithShader(builder.buildOrThrow());
950+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
938951
}
939952

940953
public static void drawBoxFaces(
@@ -995,7 +1008,7 @@ public static void drawBoxFaces(
9951008
builder.addVertex(x1, y2, z2).setColor(red1, grn1, blu1, alpha);
9961009
}
9971010
}
998-
drawWithShader(builder.buildOrThrow());
1011+
drawWithShader(builder.buildOrThrow(), RenderType.debugQuads());
9991012
}
10001013

10011014
public static void drawCylinderWireframe(Tesselator tesselator,
@@ -1028,7 +1041,7 @@ public static void drawCylinderWireframe(Tesselator tesselator,
10281041
float z = r * Mth.sin(theta);
10291042
builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha);
10301043
}
1031-
drawWithShader(builder.buildOrThrow());
1044+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
10321045
}
10331046

10341047
if (!isFlat)
@@ -1046,7 +1059,7 @@ public static void drawCylinderWireframe(Tesselator tesselator,
10461059
builder.addVertex(cx + x, cy + h, cz - z).setColor(red, grn, blu, alpha);
10471060
builder.addVertex(cx - x, cy + h, cz + z).setColor(red, grn, blu, alpha);
10481061
builder.addVertex(cx - x, cy + 0, cz + z).setColor(red, grn, blu, alpha);
1049-
drawWithShader(builder.buildOrThrow());
1062+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
10501063
}
10511064
}
10521065
else
@@ -1060,7 +1073,7 @@ public static void drawCylinderWireframe(Tesselator tesselator,
10601073
builder.addVertex(cx - x, cy, cz + z).setColor(red, grn, blu, alpha);
10611074
builder.addVertex(cx + x, cy, cz - z).setColor(red, grn, blu, alpha);
10621075
}
1063-
drawWithShader(builder.buildOrThrow());
1076+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
10641077
}
10651078

10661079
}
@@ -1078,7 +1091,7 @@ else if (axis == Direction.Axis.X)
10781091
float y = r * Mth.sin(theta);
10791092
builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha);
10801093
}
1081-
drawWithShader(builder.buildOrThrow());
1094+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
10821095
}
10831096

10841097
if (!isFlat)
@@ -1095,7 +1108,7 @@ else if (axis == Direction.Axis.X)
10951108
builder.addVertex(cx + 0, cy + y, cz - z).setColor(red, grn, blu, alpha);
10961109
builder.addVertex(cx + h, cy + y, cz - z).setColor(red, grn, blu, alpha);
10971110
builder.addVertex(cx + h, cy - y, cz + z).setColor(red, grn, blu, alpha);
1098-
drawWithShader(builder.buildOrThrow());
1111+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
10991112
}
11001113
}
11011114
else
@@ -1109,7 +1122,7 @@ else if (axis == Direction.Axis.X)
11091122
builder.addVertex(cx, cy - y, cz + z).setColor(red, grn, blu, alpha);
11101123
builder.addVertex(cx, cy + y, cz - z).setColor(red, grn, blu, alpha);
11111124
}
1112-
drawWithShader(builder.buildOrThrow());
1125+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
11131126
}
11141127
}
11151128
else if (axis == Direction.Axis.Z)
@@ -1126,7 +1139,7 @@ else if (axis == Direction.Axis.Z)
11261139
float x = r * Mth.sin(theta);
11271140
builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha);
11281141
}
1129-
drawWithShader(builder.buildOrThrow());
1142+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
11301143
}
11311144
if (!isFlat)
11321145
{
@@ -1142,7 +1155,7 @@ else if (axis == Direction.Axis.Z)
11421155
builder.addVertex(cx - x, cy + y, cz + 0).setColor(red, grn, blu, alpha);
11431156
builder.addVertex(cx - x, cy + y, cz + h).setColor(red, grn, blu, alpha);
11441157
builder.addVertex(cx + x, cy - y, cz + h).setColor(red, grn, blu, alpha);
1145-
drawWithShader(builder.buildOrThrow());
1158+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
11461159
}
11471160
}
11481161
else
@@ -1156,7 +1169,7 @@ else if (axis == Direction.Axis.Z)
11561169
builder.addVertex(cx + x, cy - y, cz).setColor(red, grn, blu, alpha);
11571170
builder.addVertex(cx - x, cy + y, cz).setColor(red, grn, blu, alpha);
11581171
}
1159-
drawWithShader(builder.buildOrThrow());
1172+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
11601173
}
11611174

11621175
}
@@ -1183,7 +1196,7 @@ public static void drawCylinderFaces(Tesselator tesselator,
11831196
float z = r * Mth.sin(theta);
11841197
builder.addVertex(x + cx, cy, z + cz).setColor(red, grn, blu, alpha);
11851198
}
1186-
drawWithShader(builder.buildOrThrow());
1199+
drawWithShader(builder.buildOrThrow(), RenderType.debugTriangleFan());
11871200
if (!isFlat)
11881201
{
11891202
BufferBuilder builderr = tesselator.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR);
@@ -1195,7 +1208,7 @@ public static void drawCylinderFaces(Tesselator tesselator,
11951208
float z = r * Mth.sin(theta);
11961209
builderr.addVertex(x + cx, cy + h, z + cz).setColor(red, grn, blu, alpha);
11971210
}
1198-
drawWithShader(builderr.buildOrThrow());
1211+
drawWithShader(builderr.buildOrThrow(), RenderType.debugTriangleFan());
11991212

12001213
BufferBuilder builderrr = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); // quad strip to quads
12011214
float xp = r * 1;
@@ -1212,7 +1225,7 @@ public static void drawCylinderFaces(Tesselator tesselator,
12121225
xp = x;
12131226
zp = z;
12141227
}
1215-
drawWithShader(builderrr.buildOrThrow());
1228+
drawWithShader(builderrr.buildOrThrow(), RenderType.debugQuads());
12161229
}
12171230

12181231
}
@@ -1227,7 +1240,7 @@ else if (axis == Direction.Axis.X)
12271240
float z = r * Mth.sin(theta);
12281241
builder.addVertex(cx, cy + y, z + cz).setColor(red, grn, blu, alpha);
12291242
}
1230-
drawWithShader(builder.buildOrThrow());
1243+
drawWithShader(builder.buildOrThrow(), RenderType.debugTriangleFan());
12311244
if (!isFlat)
12321245
{
12331246
BufferBuilder builderr = tesselator.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR);
@@ -1239,7 +1252,7 @@ else if (axis == Direction.Axis.X)
12391252
float z = r * Mth.sin(theta);
12401253
builderr.addVertex(cx + h, cy + y, cz + z).setColor(red, grn, blu, alpha);
12411254
}
1242-
drawWithShader(builderr.buildOrThrow());
1255+
drawWithShader(builderr.buildOrThrow(), RenderType.debugTriangleFan());
12431256

12441257
BufferBuilder builderrr = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); // quad strip to quads
12451258
float yp = r * 1;
@@ -1256,7 +1269,7 @@ else if (axis == Direction.Axis.X)
12561269
yp = y;
12571270
zp = z;
12581271
}
1259-
drawWithShader(builderrr.buildOrThrow());
1272+
drawWithShader(builderrr.buildOrThrow(), RenderType.debugQuads());
12601273
}
12611274
}
12621275
else if (axis == Direction.Axis.Z)
@@ -1270,7 +1283,7 @@ else if (axis == Direction.Axis.Z)
12701283
float y = r * Mth.sin(theta);
12711284
builder.addVertex(x + cx, cy + y, cz).setColor(red, grn, blu, alpha);
12721285
}
1273-
drawWithShader(builder.buildOrThrow());
1286+
drawWithShader(builder.buildOrThrow(), RenderType.debugTriangleFan());
12741287
if (!isFlat)
12751288
{
12761289
BufferBuilder builderr = tesselator.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR);
@@ -1282,7 +1295,7 @@ else if (axis == Direction.Axis.Z)
12821295
float y = r * Mth.sin(theta);
12831296
builderr.addVertex(x + cx, cy + y, cz + h).setColor(red, grn, blu, alpha);
12841297
}
1285-
drawWithShader(builderr.buildOrThrow());
1298+
drawWithShader(builderr.buildOrThrow(), RenderType.debugTriangleFan());
12861299

12871300
BufferBuilder builderrr = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); // quad strip to quads
12881301
float xp = r;
@@ -1299,7 +1312,7 @@ else if (axis == Direction.Axis.Z)
12991312
xp = x;
13001313
yp = y;
13011314
}
1302-
drawWithShader(builderrr.buildOrThrow());
1315+
drawWithShader(builderrr.buildOrThrow(), RenderType.debugQuads());
13031316
}
13041317
}
13051318
}
@@ -1324,7 +1337,7 @@ public static void drawSphereWireframe(Tesselator tesselator,
13241337
float y = r * Mth.cos(phi);
13251338
builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha);
13261339
}
1327-
drawWithShader(builder.buildOrThrow());
1340+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
13281341
}
13291342
for (int j = 0; j <= num_steps180; j++)
13301343
{
@@ -1339,7 +1352,7 @@ public static void drawSphereWireframe(Tesselator tesselator,
13391352
float y = r * Mth.cos(phi);
13401353
builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha);
13411354
}
1342-
drawWithShader(builder.buildOrThrow());
1355+
drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1));
13431356
}
13441357

13451358
}
@@ -1381,7 +1394,7 @@ public static void drawSphereFaces(Tesselator tesselator,
13811394
zbp = zp;
13821395
yp = y;
13831396
}
1384-
drawWithShader(builder.buildOrThrow());
1397+
drawWithShader(builder.buildOrThrow(), RenderType.debugQuads());
13851398
}
13861399
}
13871400
}

0 commit comments

Comments
 (0)