Skip to content

Commit

Permalink
Allowed disabling based on texture id
Browse files Browse the repository at this point in the history
  • Loading branch information
xTracr committed May 3, 2024
1 parent 590c69a commit 29f634b
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 75 deletions.
22 changes: 10 additions & 12 deletions common/src/main/java/com/xtracr/realcamera/RealCameraCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.xtracr.realcamera.util.MathUtil;
import com.xtracr.realcamera.util.VertexRecorder;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.util.math.MatrixStack;
Expand All @@ -19,8 +18,6 @@
import org.joml.Matrix4f;
import org.joml.Vector3f;

import java.util.function.BiFunction;

public class RealCameraCore {
private static final VertexRecorder recorder = new VertexRecorder();
public static BindingTarget currentTarget = new BindingTarget();
Expand Down Expand Up @@ -100,15 +97,16 @@ public static void renderCameraEntity(VertexConsumerProvider vertexConsumers) {
.rotate(RotationAxis.POSITIVE_Y.rotationDegrees(yaw + 180.0f))
.transpose().invert();
Matrix4f positionMatrix = new Matrix4f(normalMatrix).translate(offset.subtract(pos).toVector3f());
BiFunction<RenderLayer, VertexRecorder.Vertex[], VertexRecorder.Vertex[]> function = (renderLayer, vertices) -> {
double depth = currentTarget.disablingDepth;
int count = vertices.length;
VertexRecorder.Vertex[] quad = new VertexRecorder.Vertex[count];
for (int i = 0; i < count; i++) quad[i] = vertices[i].transform(positionMatrix, normalMatrix);
for (VertexRecorder.Vertex vertex : quad) if (vertex.z() < -depth) return quad;
return null;
};
recorder.drawByAnother(vertexConsumers, renderLayer -> true, function);
recorder.drawByAnother(vertexConsumers,
renderLayer -> currentTarget.disabledTextureIds.stream().noneMatch(renderLayer.toString()::contains),
(renderLayer, vertices) -> {
double depth = currentTarget.disablingDepth;
int count = vertices.length;
VertexRecorder.Vertex[] quad = new VertexRecorder.Vertex[count];
for (int i = 0; i < count; i++) quad[i] = vertices[i].transform(positionMatrix, normalMatrix);
for (VertexRecorder.Vertex vertex : quad) if (vertex.z() < -depth) return quad;
return null;
});
}

public static void computeCamera() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import net.minecraft.util.math.MathHelper;

import java.util.ArrayList;
import java.util.List;

public class BindingTarget {
protected static final List<BindingTarget> defaultTargets = List.of(createDefaultTarget("minecraft_head", "minecraft:textures/entity/player/", 5, false),
createDefaultTarget("skin_head", "minecraft:skins/", 5, false),
createDefaultTarget("minecraft_head_2", "minecraft:textures/entity/player/", 0, true),
createDefaultTarget("skin_head_2", "minecraft:skins/", 0, true));
public List<String> disabledTextureIds = new ArrayList<>();
public final String name, textureId;
public final int priority;
public final float forwardU, forwardV, upwardU, upwardV, posU, posV, disablingDepth;
Expand Down Expand Up @@ -45,7 +47,9 @@ public BindingTarget(String name, String textureId, int priority, float forwardU
}

private static BindingTarget createDefaultTarget(String name, String textureId, int priority, boolean shouldBind) {
return new BindingTarget(name, textureId, priority, 0.1875f, 0.2f, 0.1875f, 0.075f, 0.1875f, 0.2f, 0.2f, shouldBind, true, shouldBind, shouldBind, 1, -0.12, 0, 0, 0, 0, 0);
BindingTarget target = new BindingTarget(name, textureId, priority, 0.1875f, 0.2f, 0.1875f, 0.075f, 0.1875f, 0.2f, 0.2f, shouldBind, true, shouldBind, shouldBind, 1, -0.12, 0, 0, 0, 0, 0);
target.disabledTextureIds.add("minecraft:textures/entity/enderdragon/dragon.png");
return target;
}

public boolean isEmpty() {
Expand Down
38 changes: 24 additions & 14 deletions common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.util.List;

public class ModelAnalyser extends VertexRecorder {
private static final int quadArgb = 0x6F3333CC, forwardArgb = 0xFF00CC00, upwardArgb = 0xFFCC0000, leftArgb = 0xFF0000CC;
private static final int focusedArgb = 0x7FFFFFFF, sideArgb = 0x3FFFFFFF;
private final BindingTarget target;
private final Matrix3f normal = new Matrix3f();
private final Vector3f position = new Vector3f();
Expand Down Expand Up @@ -99,20 +101,24 @@ public Vec2f getFocusedUV() {
return new Vec2f(u / quad.length, v / quad.length);
}

public void previewEffect(DrawContext context, int entitySize, int forwardArgb, int upwardArgb, int leftArgb) {
drawByAnother(context.getVertexConsumers());
public void previewEffect(DrawContext context, int entitySize, boolean canSelect, boolean hideDisabled, String disabledTextureId) {
drawByAnother(context.getVertexConsumers(),
renderLayer -> !canSelect || hideDisabled || disabledTextureId.isEmpty() || !renderLayer.toString().contains(disabledTextureId),
(renderLayer, vertices) -> vertices);
context.draw();
if (canSelect) drawFocused(context);
if (normal.m00() == 0 && normal.m11() == 0 && normal.m22() == 0) return;
Vec3d start = new Vec3d(position);
drawNormal(context, start, new Vec3d(normal.m20(), normal.m21(), -normal.m22()), entitySize / 3, forwardArgb);
drawNormal(context, start, new Vec3d(normal.m10(), normal.m11(), -normal.m12()), entitySize / 6, upwardArgb);
drawNormal(context, start, new Vec3d(normal.m00(), normal.m01(), -normal.m02()), entitySize / 6, leftArgb);
}

public void drawModelWithNormals(DrawContext context, int entitySize, int quadArgb, int forwardArgb, int upwardArgb, int faceArgb, int sideArgb) {
drawByAnother(context.getVertexConsumers());
public void drawModelWithNormals(DrawContext context, int entitySize) {
drawByAnother(context.getVertexConsumers(), renderLayer -> true, (renderLayer, vertices) -> vertices);
context.draw();
drawPolyhedron(context, faceArgb, sideArgb);
drawPolyhedron(context);
drawFocused(context);
if (currentRecord == null) return;
Vertex[] quad;
if ((quad = getQuad(currentRecord, target.posU, target.posV)) != null)
Expand All @@ -123,11 +129,20 @@ public void drawModelWithNormals(DrawContext context, int entitySize, int quadAr
drawNormal(context, getPos(quad, target.upwardU, target.upwardV), quad[0].normal(), entitySize / 2, upwardArgb);
}

private void drawPolyhedron(DrawContext context, int argb1, int argb2) {
private void drawFocused(DrawContext context) {
if (focusedIndex == -1 || focusedRecord == null) return;
Vertex[] focused = focusedRecord.vertices()[focusedIndex];
drawQuad(context, focused, focusedArgb, 1100);
int size = focused.length;
Vertex[] reversed = new Vertex[size];
for (int i = 0; i < size; i++) reversed[i] = focused[size - 1 - i];
drawQuad(context, reversed, focusedArgb, 1100);
}

private void drawPolyhedron(DrawContext context) {
if (focusedIndex == -1 || focusedRecord == null) return;
Vertex[] highlight = focusedRecord.vertices()[focusedIndex];
List<Vertex[]> polyhedron = new ArrayList<>();
polyhedron.add(highlight);
polyhedron.add(focusedRecord.vertices()[focusedIndex]);
List<Integer> indexes = new ArrayList<>(List.of(focusedIndex));
Vertex[][] vertices = focusedRecord.vertices();
boolean added;
Expand All @@ -151,12 +166,7 @@ private void drawPolyhedron(DrawContext context, int argb1, int argb2) {
if (!indexes.contains(i)) break;
resultIndexes.add(i);
}
resultIndexes.forEach(i -> drawQuad(context, vertices[i], argb2, 1000));
drawQuad(context, highlight, argb1, 1100);
size = highlight.length;
Vertex[] reversed = new Vertex[size];
for (int i = 0; i < size; i++) reversed[i] = highlight[size - 1 - i];
drawQuad(context, reversed, argb1, 1100);
resultIndexes.forEach(i -> drawQuad(context, vertices[i], sideArgb, 1000));
}

record Triple(double depth, BuiltRecord record, int index) {}
Expand Down
Loading

0 comments on commit 29f634b

Please sign in to comment.