Skip to content

Commit

Permalink
[#133] Height-calculation adjustments - end of this iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielxs01 committed Feb 29, 2024
1 parent 0c52c35 commit 6b47d9d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ public void validate(Consumer<String> invalid, ContentPack contentPack) {
}
}else if(Arrays.stream(flares).anyMatch(flare -> flare.getObjPath() == null)){
invalid.accept("Unable to determine obj path for the flares, add/check obj paths");
}else if(Arrays.stream(flares).anyMatch(flare -> base.get(flare.getObjPath()).length != 1)){
invalid.accept("Flare has obj path that is not distinct (exists more than once), this sadly doesn't work.");
}

if (objTextures.isEmpty()) {
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/net/landofrails/landofsignals/utils/FlareUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,16 @@ private static void cacheFlare(Flare flare, List<Flare> cachedFlares, ContentPac
final String flareId = flare.getId();
final OBJModel model = TileSignPartRender.cache().get(objPath);

// TODO hopefully this work :O
float[] modelTranslation = sign.getBase().get(flare.getObjPath())[0].getBlock().getTranslation();
float[] modelScaling = sign.getBase().get(flare.getObjPath())[0].getBlock().getScaling();

String errMsg = String.format("Uh oh. Did not find obj_path %s in model %s for flare %s", flare.getObjPath(), sign.getUniqueId(), flareId);
if(model == null)
throw new RuntimeException(errMsg);

//

cacheFlare(flare, flareId, model, objPath);
cacheFlare(flare, flareId, model, objPath, modelTranslation, modelScaling);
cachedFlares.add(flare);
}

Expand All @@ -122,12 +124,13 @@ private static void cacheFlare(Flare flare, Map<String, List<Flare>> stateFlares
final String objPath = signal.getModel();
final OBJModel model = TileSignalPartRender.cache().get(objPath);

//

cacheFlare(flare, flareId, model, objPath);
float[] modelTranslation = signal.getTranslation();
float[] modelScaling = signal.getScaling();

//

cacheFlare(flare, flareId, model, objPath, modelTranslation, modelScaling);

String[] flareStates = flare.getStates();
if(flare.isAlwaysOn())
flareStates = signal.getStates(); // All states
Expand Down Expand Up @@ -216,7 +219,7 @@ public static void renderFlares(Flare[] flares, Vec3i pos, int blockRotate, Vec3
}
}

private static void cacheFlare(Flare flare, String flareId, OBJModel model, String objPath){
private static void cacheFlare(Flare flare, String flareId, OBJModel model, String objPath, float[] modelTranslation, float[] modelScaling){
Predicate<Map.Entry<String, OBJGroup>> isLightFlare = group -> group.getKey().startsWith(flareId);
String errMsg = String.format("Uh oh. Did not find group(s) %s in model %s", flareId, objPath);
Map<String, OBJGroup> flareGroups = model.groups.entrySet().stream().filter(isLightFlare).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
Expand All @@ -231,7 +234,7 @@ private static void cacheFlare(Flare flare, String flareId, OBJModel model, Stri
double maxX = flareGroupsOBJGroups.stream().mapToDouble(g -> g.max.x).max().getAsDouble();
double minX = flareGroupsOBJGroups.stream().mapToDouble(g -> g.min.x).min().getAsDouble();

double scale = Math.max(maxZ - minZ, maxX - minX);
double scale = Math.max((maxZ - minZ) * modelScaling[2], (maxX - minX) * modelScaling[0]);

//

Expand All @@ -243,7 +246,7 @@ private static void cacheFlare(Flare flare, String flareId, OBJModel model, Stri
Vec3d centerOfLightFlare = model.centerOfGroups(flareGroups.keySet());
Vec3d modelOffset = centerOfLightFlare.subtract(centerOfModel);
modelOffset = new Vec3d(modelOffset.x, modelOffset.y, -modelOffset.z - flareOffset);
Vec3d flareCenterOffset = new Vec3d(0.5f, centerOfModel.y,0.5f);; // new Vec3d(0.5f, 0.5f,0.5f); // FIXME Set position to center of block => Is this correct for blocks with a height of over 1?
Vec3d flareCenterOffset = new Vec3d(modelTranslation[0], modelTranslation[1], modelTranslation[2]);
Vec3d combinedOffset = flareCenterOffset.add(modelOffset);

//
Expand Down

0 comments on commit 6b47d9d

Please sign in to comment.