Commit 6d0d664e authored by Matthias Betz's avatar Matthias Betz
Browse files

Merge remote-tracking branch 'remotes/origin/dev' into dev_baris_aabb_auto_mergeable

parents a7ed4b64 cc4fe260
Pipeline #12443 passed with stage
in 2 minutes and 42 seconds
package de.hft.stuttgart.citydoctor2.gui.gl;
import java.util.List;
import java.util.function.Predicate;
/** Builds the element index set (triangle vertex indices) for the triangles passing the filter. */
public final class IndexSetBuilder {
private IndexSetBuilder() {}
public static int[] build(List<TriangleMeta> metas, Predicate<TriangleMeta> include) {
IntList out = new IntList();
for (TriangleMeta m : metas) {
if (include.test(m)) {
int base = m.triangleIndex() * 3;
out.add(base);
out.add(base + 1);
out.add(base + 2);
}
}
return out.toArray();
}
}
package de.hft.stuttgart.citydoctor2.gui.gl;
import java.util.Arrays;
/** Growable primitive int array. */
public class IntList {
private int[] data;
private int size;
public IntList() { this(1024); }
public IntList(int initialCapacity) { data = new int[Math.max(1, initialCapacity)]; }
public void add(int v) {
if (size + 1 > data.length) {
data = Arrays.copyOf(data, data.length << 1);
}
data[size++] = v;
}
public int get(int index) { return data[index]; }
public int size() { return size; }
public int[] toArray() { return Arrays.copyOf(data, size); }
}
package de.hft.stuttgart.citydoctor2.gui.gl;
import de.hft.stuttgart.citydoctor2.math.Triangle3d;
import de.hft.stuttgart.citydoctor2.math.Vector3d;
/**
* Builds interleaved-by-attribute vertex arrays from triangles. Vertices are stored per triangle corner
* (3 per triangle) so a triangle's vertices occupy a contiguous, predictable range — which lets the
* draw index set be built by triangle without dedup bookkeeping.
*/
public class MeshAccumulator {
private final Vector3d center;
private final FloatList positions = new FloatList();
private final FloatList colors = new FloatList();
private final IntList ids = new IntList();
private int vertexCount;
public MeshAccumulator(Vector3d center) {
this.center = center;
}
public void addTriangle(Triangle3d t, int id, float r, float g, float b) {
addVertex(t.getP1(), id, r, g, b);
addVertex(t.getP2(), id, r, g, b);
addVertex(t.getP3(), id, r, g, b);
}
private void addVertex(Vector3d p, int id, float r, float g, float b) {
positions.add((float) (p.getX() - center.getX()),
(float) (p.getY() - center.getY()),
(float) (p.getZ() - center.getZ()));
colors.add(r, g, b);
ids.add(id);
vertexCount++;
}
public int vertexCount() { return vertexCount; }
public float[] positions() { return positions.toArray(); }
public float[] colors() { return colors.toArray(); }
public int[] ids() { return ids.toArray(); }
}
#version 330 core
flat in int vId;
out vec4 fragColor;
void main() {
int id = vId;
float r = float( id & 0xFF) / 255.0;
float g = float((id >> 8) & 0xFF) / 255.0;
float b = float((id >> 16) & 0xFF) / 255.0;
fragColor = vec4(r, g, b, 1.0);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment