Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
8bcfc6b2
Commit
8bcfc6b2
authored
Jun 19, 2026
by
Matthias Betz
Browse files
Add MeshAccumulator building interleaved vertex arrays
parent
24c5c355
Changes
2
Hide whitespace changes
Inline
Side-by-side
CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/gl/MeshAccumulator.java
0 → 100644
View file @
8bcfc6b2
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
();
}
}
CityDoctorParent/Extensions/CityDoctorGUI/src/test/java/de/hft/stuttgart/citydoctor2/gui/gl/MeshAccumulatorTest.java
0 → 100644
View file @
8bcfc6b2
package
de.hft.stuttgart.citydoctor2.gui.gl
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
de.hft.stuttgart.citydoctor2.math.Triangle3d
;
import
de.hft.stuttgart.citydoctor2.math.Vector3d
;
import
org.junit.Test
;
public
class
MeshAccumulatorTest
{
@Test
public
void
emitsNineFloatsAndThreeIdsPerTriangleRecentered
()
{
MeshAccumulator
acc
=
new
MeshAccumulator
(
new
Vector3d
(
1
,
0
,
0
));
Triangle3d
t
=
new
Triangle3d
(
new
Vector3d
(
1
,
0
,
0
),
new
Vector3d
(
2
,
0
,
0
),
new
Vector3d
(
1
,
1
,
0
));
acc
.
addTriangle
(
t
,
7
,
0.5f
,
0.25f
,
0.125f
);
assertEquals
(
3
,
acc
.
vertexCount
());
assertArrayEquals
(
new
float
[]{
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
,
0
},
acc
.
positions
(),
1
e
-
6
f
);
assertArrayEquals
(
new
float
[]{
0.5f
,
0.25f
,
0.125f
,
0.5f
,
0.25f
,
0.125f
,
0.5f
,
0.25f
,
0.125f
},
acc
.
colors
(),
1
e
-
6
f
);
assertArrayEquals
(
new
int
[]{
7
,
7
,
7
},
acc
.
ids
());
}
@Test
public
void
accumulatesMultipleTriangles
()
{
MeshAccumulator
acc
=
new
MeshAccumulator
(
new
Vector3d
(
0
,
0
,
0
));
Triangle3d
t
=
new
Triangle3d
(
new
Vector3d
(
0
,
0
,
0
),
new
Vector3d
(
1
,
0
,
0
),
new
Vector3d
(
0
,
1
,
0
));
acc
.
addTriangle
(
t
,
1
,
1
,
1
,
1
);
acc
.
addTriangle
(
t
,
2
,
0
,
0
,
0
);
assertEquals
(
6
,
acc
.
vertexCount
());
assertEquals
(
18
,
acc
.
positions
().
length
);
assertArrayEquals
(
new
int
[]{
1
,
1
,
1
,
2
,
2
,
2
},
acc
.
ids
());
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment