@@ -4,11 +4,9 @@
|
|
4
4
|
import { getParam } from "../engine/engine_utils.js";
|
5
5
|
import { serializable } from "../engine/engine_serialization_decorator.js";
|
6
6
|
import { Vector3 } from "three";
|
7
|
-
import { isDevEnvironment } from "../engine/debug/index.js";
|
8
|
-
import { GuidsMap } from "../engine/engine_types.js";
|
9
7
|
|
10
|
-
const debug = getParam("
|
11
|
-
const noLods = getParam("
|
8
|
+
const debug = getParam("debuglods");
|
9
|
+
const noLods = getParam("nolods");
|
12
10
|
|
13
11
|
enum LODFadeMode {
|
14
12
|
None = 0,
|
@@ -59,17 +57,15 @@
|
|
59
57
|
private _lodsHandler?: Array<THREE.LOD>;
|
60
58
|
|
61
59
|
start(): void {
|
60
|
+
if (debug)
|
61
|
+
console.log("LODGROUP", this.name, this.lodModels, this);
|
62
62
|
if (noLods) return;
|
63
63
|
if (this._lodsHandler) return;
|
64
64
|
if (!this.gameObject) return;
|
65
|
-
if (debug)
|
66
|
-
console.log(this);
|
67
65
|
|
68
66
|
if (this.lodModels && Array.isArray(this.lodModels)) {
|
69
|
-
let maxDistance = 0;
|
70
67
|
const renderers: Renderer[] = [];
|
71
68
|
for (const model of this.lodModels) {
|
72
|
-
maxDistance = Math.max(model.distance, maxDistance);
|
73
69
|
const lod = new LOD(model);
|
74
70
|
this._lods.push(lod);
|
75
71
|
for (const rend of lod.renderers) {
|
@@ -85,41 +81,32 @@
|
|
85
81
|
}
|
86
82
|
const empty = new THREE.Object3D();
|
87
83
|
empty.name = "Cull " + this.name;
|
88
|
-
if (debug)
|
89
|
-
console.log(renderers);
|
90
84
|
for (let i = 0; i < renderers.length; i++) {
|
91
85
|
const rend = renderers[i];
|
92
86
|
const handler = this._lodsHandler[i];
|
93
87
|
const obj = rend.gameObject;
|
94
|
-
let maxDistance = 0;
|
95
|
-
let lodDistanceDiff = 0;
|
96
88
|
if (debug)
|
97
89
|
console.log(i, obj.name);
|
98
90
|
for (const lod of this._lods) {
|
91
|
+
const dist = lod.model.distance;
|
99
92
|
|
100
93
|
// get object to be lodded, it can be empty
|
101
94
|
let object: THREE.Object3D | null = null;
|
102
|
-
if (lod.renderers.includes(rend))
|
95
|
+
if (lod.renderers.includes(rend)) {
|
96
|
+
object = obj;
|
97
|
+
}
|
103
98
|
else {
|
104
99
|
object = empty;
|
105
100
|
}
|
106
|
-
if (debug)
|
107
|
-
console.log("add", lod.model.distance, object.name);
|
108
101
|
|
109
|
-
const dist = lod.model.distance;
|
110
|
-
lodDistanceDiff = dist - maxDistance;
|
111
|
-
maxDistance = Math.max(dist, maxDistance);
|
112
102
|
if (object.type === "Group") {
|
113
|
-
console.warn(
|
103
|
+
console.warn(`LODGroup ${this.name}: Group or MultiMaterial object's are not supported as LOD object: ${object.name}`);
|
114
104
|
continue;
|
115
105
|
}
|
116
|
-
|
106
|
+
if (debug)
|
107
|
+
console.log("LEVEL", object.name, dist);
|
108
|
+
this.onAddLodLevel(handler, object, lod.model.distance);
|
117
109
|
}
|
118
|
-
const cullDistance = maxDistance + lodDistanceDiff;
|
119
|
-
if (debug) {
|
120
|
-
console.log("cull", cullDistance);
|
121
|
-
}
|
122
|
-
this.onAddLodLevel(handler, empty, cullDistance);
|
123
110
|
}
|
124
111
|
}
|
125
112
|
}
|
@@ -140,7 +127,7 @@
|
|
140
127
|
console.warn("LODGroup component must be on parent object and not mesh directly at the moment", obj.name, obj)
|
141
128
|
return;
|
142
129
|
}
|
143
|
-
lod.addLevel(obj, dist * this._distanceFactor);
|
130
|
+
lod.addLevel(obj, dist * this._distanceFactor, .01);
|
144
131
|
const setting = { lod: lod, levelIndex: lod.levels.length - 1, distance: dist };
|
145
132
|
this._settings.push(setting)
|
146
133
|
}
|
@@ -6,7 +6,7 @@
|
|
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, Mesh, ShadowMaterial } from "three";
|
9
|
+
import { Camera as ThreeCamera, Box3, Object3D, PerspectiveCamera, Vector2, Vector3, Box3Helper, GridHelper, Mesh, ShadowMaterial, RGBA_ASTC_10x10_Format } 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";
|
@@ -17,6 +17,7 @@
|
|
17
17
|
|
18
18
|
const freeCam = getParam("freecam");
|
19
19
|
const debugCameraFit = getParam("debugcamerafit");
|
20
|
+
const smoothcam = getParam("smoothcam")
|
20
21
|
|
21
22
|
const disabledKeys = { LEFT: "", UP: "", RIGHT: "", BOTTOM: "" };
|
22
23
|
let defaultKeys: any = undefined;
|
@@ -206,9 +207,11 @@
|
|
206
207
|
}
|
207
208
|
}
|
208
209
|
this._syncedTransform = GameObject.getComponent(this.gameObject, SyncedTransform) ?? undefined;
|
209
|
-
if (
|
210
|
-
|
211
|
-
|
210
|
+
// if we autofit in onEnable then DragControls will trigger fitting every time (because they disable OrbitControls)
|
211
|
+
// that's confusing and not what we want
|
212
|
+
// if (this._didStart) {
|
213
|
+
// if (this.autoFit) this.fitCamera()
|
214
|
+
// }
|
212
215
|
}
|
213
216
|
|
214
217
|
onDisable() {
|
@@ -308,14 +311,20 @@
|
|
308
311
|
if (this.debugLog)
|
309
312
|
this._controls.domElement = this.context.renderer.domElement;
|
310
313
|
this._controls.enabled = !this._shouldDisable && this._camera === this.context.mainCameraComponent && !this.context.isInXR;
|
311
|
-
this._controls.enableDamping = this.enableDamping;
|
312
314
|
this._controls.keys = this.enableKeys ? defaultKeys : disabledKeys;
|
313
315
|
this._controls.autoRotate = this.autoRotate;
|
314
316
|
this._controls.autoRotateSpeed = this.autoRotateSpeed;
|
315
317
|
this._controls.enableZoom = this.enableZoom;
|
318
|
+
this._controls.enableDamping = this.enableDamping;
|
316
319
|
this._controls.dampingFactor = this.dampingFactor;
|
317
320
|
this._controls.enablePan = this.enablePan;
|
318
321
|
this._controls.enableRotate = this.enableRotate;
|
322
|
+
if (typeof smoothcam === "number" || smoothcam === true) {
|
323
|
+
this._controls.enableDamping = true;
|
324
|
+
const factor = typeof smoothcam === "number" ? smoothcam : .99;
|
325
|
+
this._controls.dampingFactor = Math.max(.001, 1 - Math.min(1, factor));
|
326
|
+
console.log(this._controls.dampingFactor)
|
327
|
+
}
|
319
328
|
//@ts-ignore
|
320
329
|
// this._controls.zoomToCursor = this.zoomToCursor;
|
321
330
|
if (!this.context.isInXR)
|
@@ -6,6 +6,7 @@
|
|
6
6
|
import { Camera } from "../Camera.js";
|
7
7
|
import { PostProcessingEffect } from "./PostProcessingEffect.js";
|
8
8
|
import { Constructor } from "../../engine/engine_types.js";
|
9
|
+
import { N8AOPostPass } from "n8ao";
|
9
10
|
|
10
11
|
const debug = getParam("debugpost");
|
11
12
|
|
@@ -189,6 +190,13 @@
|
|
189
190
|
return aidx - bidx;
|
190
191
|
});
|
191
192
|
if (debug) console.log("After ordering effects", [...this._effects]);
|
193
|
+
for (let i = 0; i < effects.length; i++) {
|
194
|
+
const effect = effects[i] as any;
|
195
|
+
if (effect?.configuration?.gammaCorrection !== undefined) {
|
196
|
+
const isLast = i === effects.length - 1;
|
197
|
+
effect.configuration.gammaCorrection = isLast;
|
198
|
+
}
|
199
|
+
}
|
192
200
|
}
|
193
201
|
}
|
194
202
|
|
@@ -197,6 +205,7 @@
|
|
197
205
|
NormalPass,
|
198
206
|
DepthDownsamplingPass,
|
199
207
|
SSAOEffect,
|
208
|
+
N8AOPostPass,
|
200
209
|
DepthOfFieldEffect,
|
201
210
|
BloomEffect,
|
202
211
|
SelectiveBloomEffect,
|