mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-13 05:54:01 +01:00
Get some bounding spheres at home
- Compute bounding spheres with the AABB method. Should be pretty well suited for funny block game. - Remove Miniball from dependencies.
This commit is contained in:
parent
d84c5dc3e8
commit
5fc4a74860
18
build.gradle
18
build.gradle
@ -74,21 +74,6 @@ repositories {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix for loading non-mod libraries in dev-env, used for Miniball.
|
|
||||||
// https://gist.github.com/SizableShrimp/66b22f1b24c255e1491c8d98d3f11f83
|
|
||||||
// v--------------------------------------------------------------------v
|
|
||||||
configurations {
|
|
||||||
library
|
|
||||||
implementation.extendsFrom library
|
|
||||||
}
|
|
||||||
|
|
||||||
minecraft.runs.configureEach {
|
|
||||||
lazyToken('minecraft_classpath') {
|
|
||||||
configurations.library.copyRecursive().resolve().collect { it.absolutePath }.join(File.pathSeparator)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ^--------------------------------------------------------------------^
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
|
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
|
||||||
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
||||||
@ -96,9 +81,6 @@ dependencies {
|
|||||||
compileOnly fg.deobf("maven.modrinth:embeddium:0.2.10+mc1.20.1")
|
compileOnly fg.deobf("maven.modrinth:embeddium:0.2.10+mc1.20.1")
|
||||||
compileOnly fg.deobf("maven.modrinth:oculus:1.20.1-1.6.9")
|
compileOnly fg.deobf("maven.modrinth:oculus:1.20.1-1.6.9")
|
||||||
|
|
||||||
jarJar(group: 'com.dreizak', name: 'miniball', version: '[1.0.3,2.0.0)')
|
|
||||||
library 'com.dreizak:miniball:1.0.3'
|
|
||||||
|
|
||||||
// https://discord.com/channels/313125603924639766/725850371834118214/910619168821354497
|
// https://discord.com/channels/313125603924639766/725850371834118214/910619168821354497
|
||||||
// Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings
|
// Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings
|
||||||
// This allows 'Settings > Build, Execution, and Deployment > Build Tools > Gradle > Build and run using' set to IntelliJ to work correctly
|
// This allows 'Settings > Build, Execution, and Deployment > Build Tools > Gradle > Build and run using' set to IntelliJ to work correctly
|
||||||
|
@ -4,12 +4,11 @@ import java.lang.reflect.Field;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.joml.Vector3f;
|
||||||
import org.joml.Vector4f;
|
import org.joml.Vector4f;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import com.dreizak.miniball.highdim.Miniball;
|
|
||||||
import com.dreizak.miniball.model.PointSet;
|
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
import com.jozufozu.flywheel.api.model.Mesh;
|
import com.jozufozu.flywheel.api.model.Mesh;
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexList;
|
import com.jozufozu.flywheel.api.vertex.VertexList;
|
||||||
@ -37,6 +36,7 @@ public final class ModelUtil {
|
|||||||
* Meant to be used for virtual rendering.
|
* Meant to be used for virtual rendering.
|
||||||
*/
|
*/
|
||||||
public static final BlockRenderDispatcher VANILLA_RENDERER = createVanillaRenderer();
|
public static final BlockRenderDispatcher VANILLA_RENDERER = createVanillaRenderer();
|
||||||
|
private static final float BOUNDING_SPHERE_EPSILON = 1e-4f;
|
||||||
|
|
||||||
private ModelUtil() {
|
private ModelUtil() {
|
||||||
}
|
}
|
||||||
@ -128,33 +128,47 @@ public final class ModelUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Vector4f computeBoundingSphere(VertexList vertexList) {
|
public static Vector4f computeBoundingSphere(VertexList vertexList) {
|
||||||
return computeBoundingSphere(new PointSet() {
|
var center = computeCenterOfAABBContaining(vertexList);
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return vertexList.vertexCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
var radius = computeMaxDistanceTo(vertexList, center) + BOUNDING_SPHERE_EPSILON;
|
||||||
public int dimension() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return new Vector4f(center, radius);
|
||||||
public double coord(int i, int dim) {
|
|
||||||
return switch (dim) {
|
|
||||||
case 0 -> vertexList.x(i);
|
|
||||||
case 1 -> vertexList.y(i);
|
|
||||||
case 2 -> vertexList.z(i);
|
|
||||||
default -> throw new IllegalArgumentException("Invalid dimension: " + dim);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector4f computeBoundingSphere(PointSet points) {
|
private static float computeMaxDistanceTo(VertexList vertexList, Vector3f pos) {
|
||||||
var miniball = new Miniball(points);
|
float farthestDistanceSquared = -1;
|
||||||
double[] center = miniball.center();
|
|
||||||
double radius = miniball.radius();
|
for (int i = 0; i < vertexList.vertexCount(); i++) {
|
||||||
return new Vector4f((float) center[0], (float) center[1], (float) center[2], (float) radius);
|
var distanceSquared = pos.distanceSquared(vertexList.x(i), vertexList.y(i), vertexList.z(i));
|
||||||
|
|
||||||
|
if (distanceSquared > farthestDistanceSquared) {
|
||||||
|
farthestDistanceSquared = distanceSquared;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (float) Math.sqrt(farthestDistanceSquared);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Vector3f computeCenterOfAABBContaining(VertexList vertexList) {
|
||||||
|
var min = new Vector3f(Float.MAX_VALUE);
|
||||||
|
var max = new Vector3f(Float.MIN_VALUE);
|
||||||
|
|
||||||
|
for (int i = 0; i < vertexList.vertexCount(); i++) {
|
||||||
|
float x = vertexList.x(i);
|
||||||
|
float y = vertexList.y(i);
|
||||||
|
float z = vertexList.z(i);
|
||||||
|
|
||||||
|
// JOML's min/max methods don't accept floats :whywheel:
|
||||||
|
min.x = Math.min(min.x, x);
|
||||||
|
min.y = Math.min(min.y, y);
|
||||||
|
min.z = Math.min(min.z, z);
|
||||||
|
|
||||||
|
max.x = Math.max(max.x, x);
|
||||||
|
max.y = Math.max(max.y, y);
|
||||||
|
max.z = Math.max(max.z, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
return min.add(max)
|
||||||
|
.mul(0.5f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user