tuning of shapes

This commit is contained in:
gnembon committed 2020-06-03 22:49:23 -03:00
1 parent f14fcbba9f
commit 5285eb33d6
3 files changed
+89 -48

No files matched your search

@@ -393,7 +393,11 @@ public class ShapeDispatcher
public static class Sphere extends ExpiringShape
{
private final Set<String> required = ImmutableSet.of("center", "radius");
private final Map<String, Value> optional = ImmutableMap.of("width", new NumericValue(2.0), "level", Value.ZERO);
private final Map<String, Value> optional = ImmutableMap.of(
"width", new NumericValue(2.0),
"level", Value.ZERO,
"fill", new NumericValue(0xffffff00)
);
@Override
protected Set<String> requiredParams() { return Sets.union(super.requiredParams(), required); }
@Override
@@ -410,6 +414,9 @@ public class ShapeDispatcher
int subdivisions;
float lineWidth;
protected float fr, fg, fb, fa;
protected int fillColor;
@Override
protected void init(Map<String, Value> options)
{
@@ -426,6 +433,11 @@ public class ShapeDispatcher
subdivisions = Math.max(10, (int)(10*Math.sqrt(radius)));
}
lineWidth = NumericValue.asNumber(options.getOrDefault("width", optional.get("width"))).getFloat();
fillColor = NumericValue.asNumber(options.getOrDefault("fill", optional.get("fill"))).getInt();
this.fr = (float)(fillColor >> 24 & 0xFF) / 255.0F;
this.fg = (float)(fillColor >> 16 & 0xFF) / 255.0F;
this.fb = (float)(fillColor >> 8 & 0xFF) / 255.0F;
this.fa = (float)(fillColor & 0xFF) / 255.0F;
}
@Override
@@ -461,7 +473,7 @@ public class ShapeDispatcher
hash = 31*hash + Float.hashCode(radius);
hash = 31*hash + level;
hash = 31*hash + Float.hashCode(lineWidth);
if (fa != 0.0) hash = 31*hash + fillColor;
return hash;
}
}
@@ -685,7 +697,7 @@ public class ShapeDispatcher
public static class FillColorParam extends ColorParam
{
@Override
public boolean appliesTo(ExpiringShape shape) { return shape instanceof Box; }
public boolean appliesTo(ExpiringShape shape) { return shape instanceof Box || shape instanceof Sphere; }
@Override
public String identify() { return "fill"; }
}
@@ -693,7 +705,7 @@ public class ShapeDispatcher
public static class FromParam extends Vec3Param
{
@Override
public boolean appliesTo(ExpiringShape shape) { return (shape instanceof Line) || (shape instanceof Box); }
public boolean appliesTo(ExpiringShape shape) { return shape instanceof Line || shape instanceof Box; }
@Override
public boolean roundsUpForBlocks() { return false; }
@Override
@@ -9,7 +9,6 @@ import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
@@ -50,45 +49,49 @@ public class ShapesRenderer
DimensionType dimensionType = iWorld.getDimension().getType();
if (shapes.get(dimensionType).isEmpty()) return;
long currentTime = client.world.getTime();
RenderSystem.disableTexture();
RenderSystem.enableDepthTest();
RenderSystem.depthFunc(515);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
//RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO);
RenderSystem.shadeModel(7425);
//RenderSystem.shadeModel(7425);
RenderSystem.shadeModel(GL11.GL_FLAT);
RenderSystem.enableAlphaTest();
RenderSystem.defaultAlphaFunc();
Entity entity = this.client.gameRenderer.getCamera().getFocusedEntity();
//RenderSystem.alphaFunc(GL11.GL_GREATER, 0.005F);
RenderSystem.disableCull();
RenderSystem.disableLighting();
RenderSystem.depthMask(false);
RenderSystem.polygonOffset(-3f, -3f);
RenderSystem.enablePolygonOffset();
//Entity entity = this.client.gameRenderer.getCamera().getFocusedEntity();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuffer();
double d = 0.0D - cameraY;
double e = 256.0D - cameraY;
RenderSystem.disableTexture();
//RenderSystem.disableBlend();
double f = (double)(entity.chunkX << 4) - cameraX;
double g = (double)(entity.chunkZ << 4) - cameraZ;
// render
synchronized (shapes)
{
shapes.get(dimensionType).int2ObjectEntrySet().removeIf(
entry -> entry.getValue().isExpired(currentTime)
);
shapes.get(dimensionType).values().forEach(
s -> s.render(tessellator, bufferBuilder, (float) cameraX, (float) cameraY, (float) cameraZ)
);
shapes.get(dimensionType).values().forEach(
s -> s.render2pass(tessellator, bufferBuilder, (float) cameraX, (float) cameraY, (float) cameraZ)
);
//lines
shapes.get(dimensionType).values().forEach(
s -> s.render(tessellator, bufferBuilder, (float) cameraX, (float) cameraY, (float) cameraZ)
);
}
RenderSystem.lineWidth(1.0F);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.enableTexture();
RenderSystem.shadeModel(7424);
}
public void addShape(CompoundTag tag)
{
//CarpetSettings.LOG.error("Received tag: "+tag.asString());
ShapeDispatcher.ExpiringShape shape = ShapeDispatcher.fromTag(tag);
if (shape == null) return;
BiFunction<MinecraftClient, ShapeDispatcher.ExpiringShape, RenderedShape<? extends ShapeDispatcher.ExpiringShape >> shapeFactory;
@@ -160,14 +163,13 @@ public class ShapesRenderer
@Override
public void render(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz)
{
if (shape.a == 0.0) return;
RenderSystem.lineWidth(shape.lineWidth);
drawBoxWireGLLines(tessellator, bufferBuilder,
shape.x1 - cx-renderEpsilon, shape.y1 - cy-renderEpsilon, shape.z1 - cz-renderEpsilon,
shape.x2 - cx+renderEpsilon, shape.y2 - cy+renderEpsilon, shape.z2 - cz+renderEpsilon,
shape.r, shape.g, shape.b, shape.a, shape.r, shape.g, shape.b
);
tessellator.draw();
}
@Override
public void render2pass(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz)
@@ -211,12 +213,23 @@ public class ShapesRenderer
@Override
public void render(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz)
{
if (shape.a == 0.0) return;
RenderSystem.lineWidth(shape.lineWidth);
drawSphereWireframe(tessellator, bufferBuilder,
shape.cx-cx-renderEpsilon, shape.cy-cy-renderEpsilon, shape.cz-cz-renderEpsilon,
shape.radius, shape.subdivisions,
shape.r, shape.g, shape.b, shape.a);
}
@Override
public void render2pass(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz)
{
if (shape.fa == 0.0) return;
RenderSystem.lineWidth(1.0f);
drawSphereFaces(tessellator, bufferBuilder,
shape.cx-cx-renderEpsilon, shape.cy-cy-renderEpsilon, shape.cz-cz-renderEpsilon,
shape.radius, shape.subdivisions,
shape.fr, shape.fg, shape.fb, shape.fa);
}
}
// some raw shit
@@ -225,10 +238,10 @@ public class ShapesRenderer
builder.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR); // 3
builder.vertex(x1, y1, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next();
tessellator.draw();
}
public static void drawBoxWireGLLines(Tessellator tessellator, BufferBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, float red1, float grn1, float blu1, float alpha, float red2, float grn2, float blu2) {
public static void drawBoxWireGLLines(Tessellator tessellator, BufferBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, float red1, float grn1, float blu1, float alpha, float red2, float grn2, float blu2)
{
builder.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR); // 3
builder.vertex(x1, y1, z1).color(red1, grn2, blu2, alpha).next();
builder.vertex(x2, y1, z1).color(red1, grn2, blu2, alpha).next();
@@ -254,24 +267,26 @@ public class ShapesRenderer
builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y2, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next();
tessellator.draw();
}
public static void drawBoxFaces(Tessellator tessellator, BufferBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, float red1, float grn1, float blu1, float alpha) {
builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR); // 3
public static void drawBoxFaces(Tessellator tessellator, BufferBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, float red1, float grn1, float blu1, float alpha)
{
builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR);
builder.vertex(x1, y1, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y1, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y2, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y2, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y1, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y1, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y2, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y1, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y1, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y1, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y2, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y2, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y2, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y1, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y1, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y1, z2).color(red1, grn1, blu1, alpha).next();
@@ -279,9 +294,9 @@ public class ShapesRenderer
builder.vertex(x2, y2, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y1, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y1, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y1, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y1, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y1, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y1, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y2, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y2, z1).color(red1, grn1, blu1, alpha).next();
@@ -327,4 +342,31 @@ public class ShapesRenderer
}
}
public static void drawSphereFaces(Tessellator tessellator, BufferBuilder builder,
float cx, float cy, float cz,
float r, int subd,
float red, float grn, float blu, float alpha)
{
float pihalf = (float)(Math.PI / 180.0f);
float step = 180f / (subd/2);
for (float i = 0f; i < 359.99f; i += step)
{
float theta = i * pihalf;
float thetaprime = (i + step) * pihalf;
builder.begin(GL11.GL_QUAD_STRIP, VertexFormats.POSITION_COLOR);
for (float j = 0f; j < 179.9f; j += step)
{
float phi = j * pihalf;
float x = r * MathHelper.sin(phi) * MathHelper.cos(theta);
float z = r * MathHelper.sin(phi) * MathHelper.sin(theta);
float y = r * MathHelper.cos(phi);
float xp = r * MathHelper.sin(phi) * MathHelper.cos(thetaprime);
float zp = r * MathHelper.sin(phi) * MathHelper.sin(thetaprime);
builder.vertex(x + cx, y + cy, z + cz).color(red, grn, blu, alpha).next();
builder.vertex(xp + cx, y + cy, zp + cz).color(red, grn, blu, alpha).next();
}
tessellator.draw();
}
}
}