46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
|
import * as THREE from 'three';
|
||
|
|
||
|
import * as Types from "../../../../types/world/worldTypes";
|
||
|
|
||
|
function hideWalls(
|
||
|
visibility: Types.Boolean,
|
||
|
scene: THREE.Scene,
|
||
|
camera: THREE.Camera
|
||
|
): void {
|
||
|
|
||
|
////////// Altering the visibility of the Walls when the world direction of the wall is facing the camera //////////
|
||
|
|
||
|
const v = new THREE.Vector3();
|
||
|
const u = new THREE.Vector3();
|
||
|
|
||
|
if (visibility === true) {
|
||
|
for (const children of scene.children) {
|
||
|
if (children.name === "Walls" && children.children[0]?.children.length > 0) {
|
||
|
children.children[0].children.forEach((child: any) => {
|
||
|
if (child.children[0]?.userData.WallType === "RoomWall") {
|
||
|
child.children[0].getWorldDirection(v);
|
||
|
camera.getWorldDirection(u);
|
||
|
if (child.children[0].material) {
|
||
|
child.children[0].material.visible = (2 * v.dot(u)) >= -0.5;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
for (const children of scene.children) {
|
||
|
if (children.name === "Walls" && children.children[0]?.children.length > 0) {
|
||
|
children.children[0].children.forEach((child: any) => {
|
||
|
if (child.children[0]?.userData.WallType === "RoomWall") {
|
||
|
if (child.children[0].material) {
|
||
|
child.children[0].material.visible = true;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default hideWalls;
|