@@ -1,9 +1,10 @@
|
|
1
1
|
import { Behaviour, GameObject } from "./Component.js";
|
2
2
|
import { GroundProjectedSkybox as GroundProjection } from 'three/examples/jsm/objects/GroundProjectedSkybox.js';
|
3
3
|
import { serializable } from "../engine/engine_serialization_decorator.js";
|
4
|
-
import { Watch as Watch } from "../engine/engine_utils.js";
|
4
|
+
import { Watch as Watch, getParam } from "../engine/engine_utils.js";
|
5
5
|
import { Texture } from "three";
|
6
6
|
|
7
|
+
const debug = getParam("debuggroundprojection");
|
7
8
|
|
8
9
|
export class GroundProjectedEnv extends Behaviour {
|
9
10
|
|
@@ -78,7 +79,8 @@
|
|
78
79
|
return;
|
79
80
|
}
|
80
81
|
if (!this.env || this.context.scene.environment !== this._lastEnvironment) {
|
81
|
-
|
82
|
+
if (debug)
|
83
|
+
console.log("Create/Update Ground Projection", this.context.scene.environment.name);
|
82
84
|
this.env = new GroundProjection(this.context.scene.environment);
|
83
85
|
}
|
84
86
|
this._lastEnvironment = this.context.scene.environment;
|
@@ -6,13 +6,16 @@
|
|
6
6
|
import { serializable } from "../engine/engine_serialization_decorator.js";
|
7
7
|
import { getParam, isMobileDevice } from "../engine/engine_utils.js";
|
8
8
|
|
9
|
-
import { Camera as ThreeCamera, Box3, Object3D, PerspectiveCamera, Vector2, Vector3, Box3Helper, GridHelper } from "three";
|
9
|
+
import { Camera as ThreeCamera, Box3, Object3D, PerspectiveCamera, Vector2, Vector3, Box3Helper, GridHelper, Mesh, ShadowMaterial } from "three";
|
10
10
|
import { OrbitControls as ThreeOrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
11
11
|
import { AfterHandleInputEvent, EventSystem, EventSystemEvents } from "./ui/EventSystem.js";
|
12
12
|
import { ICameraController } from "../engine/engine_types.js";
|
13
13
|
import { setCameraController } from "../engine/engine_camera.js";
|
14
14
|
import { SyncedTransform } from "./SyncedTransform.js";
|
15
15
|
import { tryGetUIComponent } from "./ui/Utils.js";
|
16
|
+
import { GroundProjectedEnv } from "./GroundProjection.js";
|
17
|
+
import { ShadowCatcher } from "./ShadowCatcher.js";
|
18
|
+
import { GroundProjectedSkybox } from "three/examples/jsm/objects/GroundProjectedSkybox.js";
|
16
19
|
|
17
20
|
const freeCam = getParam("freecam");
|
18
21
|
const debugCameraFit = getParam("debugcamerafit");
|
@@ -389,12 +392,32 @@
|
|
389
392
|
// and thus we're just getting some maximum that will work for sure.
|
390
393
|
|
391
394
|
box.makeEmpty();
|
395
|
+
const emptyChildren = [];
|
396
|
+
function expandByObjectRecursive(obj: Object3D) {
|
397
|
+
let allowExpanding = true;
|
398
|
+
// ignore Box3Helpers
|
399
|
+
if (obj instanceof Box3Helper) allowExpanding = false;
|
400
|
+
if (obj instanceof GridHelper) allowExpanding = false;
|
401
|
+
// ignore GroundProjectedEnv
|
402
|
+
if (obj instanceof GroundProjectedSkybox) allowExpanding = false;
|
403
|
+
// // Ignore shadow catcher geometry
|
404
|
+
if ((obj as Mesh).material instanceof ShadowMaterial) allowExpanding = false;
|
405
|
+
// If we encountered some geometry that should be ignored
|
406
|
+
// Then we don't want to use that for expanding the view
|
407
|
+
if (allowExpanding) {
|
408
|
+
// Temporary override children
|
409
|
+
const children_length = obj.children;
|
410
|
+
obj.children = emptyChildren;
|
411
|
+
box.expandByObject(obj, true);
|
412
|
+
obj.children = children_length;
|
413
|
+
}
|
414
|
+
for (const child of obj.children) {
|
415
|
+
expandByObjectRecursive(child);
|
416
|
+
}
|
417
|
+
}
|
392
418
|
for (const object of objects) {
|
393
|
-
// ignore Box3Helpers
|
394
|
-
if (object instanceof Box3Helper) continue;
|
395
|
-
if (object instanceof GridHelper) continue;
|
396
419
|
object.updateMatrixWorld();
|
397
|
-
|
420
|
+
expandByObjectRecursive(object);
|
398
421
|
}
|
399
422
|
|
400
423
|
camera.updateMatrixWorld();
|