Skip to content

Commit

Permalink
XEOK-53 Implement Zone::volume getter
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalDybizbanskiCreoox committed Jul 4, 2024
1 parent 6998dcb commit 45610ff
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/plugins/ZonesPlugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ class Zone extends Component {
this._zoneMesh.highlighted = this._highlighted;

this._zoneMesh.zone = this;
this._volume = null;


const min = idx => Math.min(...pos.map(p => p[idx]));
Expand All @@ -740,6 +741,27 @@ class Zone extends Component {
this._center = math.vec3([ (xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2 ]);
}

get volume() {
if (this._volume === null) {
// Sum the volume of tetrahedrons formed by the origin and face triangles
let volume = 0;
const geo = this._zoneMesh.geometry;
const pts = [ math.vec3(), math.vec3(), math.vec3() ];
for (let i = 0; i < geo.indices.length; i += 3) {
for (let off = 0; off < 3; ++off) {
const p = pts[off];
const pIdx = 3 * geo.indices[i + off];
for (let c = 0; c < 3; ++c) {
p[c] = geo.positions[pIdx + c];
}
}
volume += math.dotVec3(pts[0], math.cross3Vec3(pts[1], pts[2], pts[1]));
}
this._volume = volume / 6;
}
return this._volume;
}

sectionedAverage(sectionPlanes) {
const planeCoords = this._geometry.planeCoordinates.slice();

Expand Down

0 comments on commit 45610ff

Please sign in to comment.