Skip to content

Commit

Permalink
[#133] Implemented scaling - (!) not fully tested.
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielxs01 committed Dec 16, 2023
1 parent 4fa5580 commit aff21c9
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cam72cam.mod.ModCore;
import cam72cam.mod.math.Vec3d;
import cam72cam.mod.model.obj.OBJGroup;
import cam72cam.mod.model.obj.OBJModel;
import cam72cam.mod.render.StandardModel;
import cam72cam.mod.render.obj.OBJRender;
Expand Down Expand Up @@ -207,17 +208,17 @@ private static void renderFlares(String id, ContentPackSignal signal, TileSignal

final String objPath = signal.getModel();
final OBJModel model = cache.get(objPath);
Predicate<String> isLightFlare = group -> group.startsWith(flareId); // TODO Preload this as well?
Predicate<Map.Entry<String, OBJGroup>> isLightFlare = group -> group.getKey().startsWith(flareId); // TODO Preload this as well?
String errMsg = String.format("Uh oh. Did not find %s in model %s", flareId, objPath);
String flareGroup = model.groups().stream().filter(isLightFlare).findFirst().orElseThrow(() -> new RuntimeException(errMsg));
Map.Entry<String, OBJGroup> flareGroup = model.groups.entrySet().stream().filter(isLightFlare).findFirst().orElseThrow(() -> new RuntimeException(errMsg));

float red = flare.getRenderColor()[0];
float green = flare.getRenderColor()[1];
float blue = flare.getRenderColor()[2];
float intensity = flare.getIntensity();

int flareRotation = Integer.parseInt(retrieveRotation.apply(flareGroup));
int flarePitch = Integer.parseInt(retrievePitch.apply(flareGroup));
int flareRotation = Integer.parseInt(retrieveRotation.apply(flareGroup.getKey()));
int flarePitch = Integer.parseInt(retrievePitch.apply(flareGroup.getKey()));

Identifier lightTex = new Identifier(LandOfSignals.MODID, "textures/light/antivignette.png");

Expand All @@ -232,7 +233,7 @@ private static void renderFlares(String id, ContentPackSignal signal, TileSignal
flareState.color((float)Math.sqrt(red), (float)Math.sqrt(green), (float)Math.sqrt(blue), 1 - (intensity/3f));

Vec3d centerOfModel = model.centerOfGroups(model.groups());
Vec3d centerOfLightFlare = model.centerOfGroups(Collections.singleton(flareGroup));
Vec3d centerOfLightFlare = model.centerOfGroups(Collections.singleton(flareGroup.getKey()));

Vec3d flareOffset = new Vec3d(0.5f, 0.5f,0.5f); // Set position to center of block
flareState.translate(flareOffset);
Expand All @@ -244,6 +245,9 @@ private static void renderFlares(String id, ContentPackSignal signal, TileSignal
modelOffset = new Vec3d(modelOffset.x, modelOffset.y, -modelOffset.z - 0.45); // 0.45 implement custom offset?
flareState.translate(modelOffset); // move it towards the position of the light flare

double scale = Math.max(flareGroup.getValue().max.z - flareGroup.getValue().min.z, flareGroup.getValue().max.x - flareGroup.getValue().min.x);
flareState.scale(scale, scale, scale);

DirectDraw buffer = new DirectDraw();
buffer.vertex(-1, -1, 0).uv(0, 0);
buffer.vertex(-1, 1, 0).uv(0, 1);
Expand Down

0 comments on commit aff21c9

Please sign in to comment.