Skip to content

Commit

Permalink
Merge branch 'fix-geometry-winding-direction' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tsengyushiang committed Jun 25, 2024
2 parents c70406e + 0ed8669 commit db840b5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class RoomBufferGeometry extends THREE.BufferGeometry {
constructor() {
super();
this.aabbArray = [];
this.PLANE_THICKNESS = 8e-2;
this.planeArray = [];
this.floorVertices = [];
}
Expand Down Expand Up @@ -36,16 +37,41 @@ class RoomBufferGeometry extends THREE.BufferGeometry {
return data;
});
const planeVertices = this.planeArray.flatMap(([min, max]) => {
const vertexVectors = [
new THREE.Vector3(min[0], min[1], min[2]),
new THREE.Vector3(max[0], min[1], max[2]),
new THREE.Vector3(max[0], max[1], max[2]),
new THREE.Vector3(min[0], max[1], min[2]),
new THREE.Vector3(min[0], min[1], min[2]),
new THREE.Vector3(max[0], max[1], max[2]),
];
const rotationMat = new THREE.Matrix4().lookAt(
new THREE.Vector3(min[0], 0, min[2]),
new THREE.Vector3(max[0], 0, max[2]),
new THREE.Vector3(0, 1, 0)
);
const quaternion = new THREE.Quaternion().setFromRotationMatrix(
rotationMat
);

const depth = new THREE.Vector2(
max[0] - min[0],
max[2] - min[2]
).length();
const height = max[1] - min[1];

return vertexVectors.flatMap((vec) => vec.toArray());
const aabbGeometry = new THREE.BoxGeometry(
this.PLANE_THICKNESS,
height,
depth
);
aabbGeometry.applyQuaternion(quaternion);
aabbGeometry.translate(
(max[0] + min[0]) / 2,
(max[1] + min[1]) / 2,
(max[2] + min[2]) / 2
);

const vertices = [...aabbGeometry.attributes.position.array];
const index = [...aabbGeometry.getIndex().array];
const data = index.flatMap((index) => [
vertices[index * 3],
vertices[index * 3 + 1],
vertices[index * 3 + 2],
]);
return data;
});

this.setAttribute(
Expand Down Expand Up @@ -76,6 +102,12 @@ class RoomBufferGeometry extends THREE.BufferGeometry {
[1, 0, -1],
[-1, 0, 1],
[-1, 0, -1],
[1, 0, 1],
[1, 0, -1],
[-1, 0, 1],
[1, 0, -1],
[-1, 0, -1],
[-1, 0, 1],
].flatMap(([x, y, z]) => [(x * width) / 2, y, (z * length) / 2]);
this._updateGeometry();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class HeatmapMaterial extends THREE.ShaderMaterial {
HeatmapMaterial._getUniformLimitation();

super({
side: THREE.DoubleSide,
uniforms: {
isSignalIndex: {
value: false,
Expand Down
6 changes: 3 additions & 3 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ const furnitureAABBs = [
],
[
// bed
[-8.4, 0, -3.5],
[-2.1, 1.0, -9.55],
[-8.4, 0, -3.5],
],
[
//cabinet
[-0.75, 0, -2.9],
[1.02, 1.0, -9.55],
[-0.75, 0, -2.9],
],
];

Expand All @@ -93,14 +93,14 @@ const getPlanes = (percentage) => {

return [
[
[-7.1, 3, 0.73],
[
-7.1 +
2.5 * Math.cos(MAX_ANGLE * percentage + MIN_ANGLE * (1 - percentage)),
0,
0.73 +
2.5 * Math.sin(MAX_ANGLE * percentage + MIN_ANGLE * (1 - percentage)),
],
[-7.1, 3, 0.73],
],
[
[4.05, 0, -0.6],
Expand Down

0 comments on commit db840b5

Please sign in to comment.