@needle-tools/engine 3.16.0-beta → 3.16.2-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/needle-engine.js +4720 -4702
- package/dist/needle-engine.light.js +4676 -4658
- package/dist/needle-engine.light.min.js +307 -307
- package/dist/needle-engine.light.umd.cjs +282 -282
- package/dist/needle-engine.min.js +308 -308
- package/dist/needle-engine.umd.cjs +283 -283
- package/lib/engine/engine_context.js +1 -1
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_types.d.ts +1 -0
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine-components/Camera.d.ts +3 -0
- package/lib/engine-components/Camera.js +10 -0
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/CameraUtils.js +33 -23
- package/lib/engine-components/CameraUtils.js.map +1 -1
- package/lib/engine-components/Renderer.js +2 -1
- package/lib/engine-components/Renderer.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/engine_context.ts +1 -1
- package/src/engine/engine_types.ts +1 -0
- package/src/engine-components/Camera.ts +9 -0
- package/src/engine-components/CameraUtils.ts +38 -26
- package/src/engine-components/Renderer.ts +2 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OrbitControls } from "./OrbitControls.js";
|
|
2
2
|
import { addNewComponent, getOrAddComponent } from "../engine/engine_components.js";
|
|
3
3
|
import { Object3D } from "three";
|
|
4
|
-
import { ICamera } from "../engine/engine_types.js";
|
|
4
|
+
import { ICamera, IContext } from "../engine/engine_types.js";
|
|
5
5
|
import { RGBAColor } from "./js-extensions/RGBAColor.js";
|
|
6
6
|
import { ContextEvent, ContextRegistry } from "../engine/engine_context_registry.js";
|
|
7
7
|
import { getCameraController } from "../engine/engine_camera.js";
|
|
@@ -14,28 +14,35 @@ const debug = getParam("debugmissingcamera");
|
|
|
14
14
|
ContextRegistry.registerCallback(ContextEvent.MissingCamera, (evt) => {
|
|
15
15
|
if (debug) console.warn("Creating missing camera")
|
|
16
16
|
const scene = evt.context.scene;
|
|
17
|
-
const srcId = "unknown";
|
|
18
17
|
|
|
19
18
|
const cameraObject = new Object3D();
|
|
19
|
+
cameraObject.name = "Default Fallback Camera"
|
|
20
20
|
scene.add(cameraObject);
|
|
21
21
|
|
|
22
22
|
const camInstance = new Camera();
|
|
23
|
+
camInstance.sourceId = evt.files?.[0]?.src ?? "unknown"
|
|
24
|
+
// Set the clearFlags to a skybox
|
|
25
|
+
camInstance.clearFlags = 1;
|
|
26
|
+
camInstance.backgroundColor = new RGBAColor(0.5, 0.5, 0.5, 1);
|
|
27
|
+
camInstance.fieldOfView = 35;
|
|
28
|
+
// TODO: can we store the backgroundBlurriness in the gltf file somewhere except inside the camera?
|
|
29
|
+
// e.g. when we export a scene from blender without a camera in the scene
|
|
30
|
+
camInstance.backgroundBlurriness = .125; // same as in blender 0.5
|
|
23
31
|
const cam = addNewComponent(cameraObject, camInstance, true) as ICamera;
|
|
24
|
-
cam.sourceId = srcId;
|
|
25
|
-
cam.clearFlags = 2;
|
|
26
|
-
cam.backgroundColor = new RGBAColor(0.5, 0.5, 0.5, 1);
|
|
27
|
-
cam.fieldOfView = 35;
|
|
28
32
|
|
|
29
33
|
cameraObject.position.x = 0;
|
|
30
34
|
cameraObject.position.y = 1;
|
|
31
35
|
cameraObject.position.z = 2;
|
|
32
36
|
|
|
37
|
+
|
|
38
|
+
createDefaultCameraControls(evt.context, cam);
|
|
39
|
+
|
|
33
40
|
return cam;
|
|
34
41
|
});
|
|
35
42
|
|
|
36
43
|
ContextRegistry.registerCallback(ContextEvent.ContextCreated, (evt) => {
|
|
37
44
|
if (!evt.context.mainCamera) {
|
|
38
|
-
if(debug) console.log("Will not auto-fit because a default camera exists");
|
|
45
|
+
if (debug) console.log("Will not auto-fit because a default camera exists");
|
|
39
46
|
return;
|
|
40
47
|
}
|
|
41
48
|
|
|
@@ -47,27 +54,32 @@ ContextRegistry.registerCallback(ContextEvent.ContextCreated, (evt) => {
|
|
|
47
54
|
// Check if something else already acts as a camera controller
|
|
48
55
|
const existing = getCameraController(evt.context.mainCamera);
|
|
49
56
|
if (existing?.isCameraController === true) {
|
|
50
|
-
if(debug) console.log("Will not auto-fit because a camera controller exists");
|
|
57
|
+
if (debug) console.log("Will not auto-fit because a camera controller exists");
|
|
51
58
|
return;
|
|
52
59
|
}
|
|
60
|
+
createDefaultCameraControls(evt.context);
|
|
61
|
+
}
|
|
62
|
+
})
|
|
53
63
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
ctx.pre_render_callbacks.
|
|
68
|
-
|
|
69
|
-
else {
|
|
70
|
-
console.warn("Missing camera object, can not add orbit controls")
|
|
64
|
+
function createDefaultCameraControls(context: IContext, cam?: ICamera) {
|
|
65
|
+
|
|
66
|
+
cam = cam ?? context.mainCameraComponent;
|
|
67
|
+
const cameraObject = cam?.gameObject;
|
|
68
|
+
if (debug) console.log("Creating default camera controls", cam?.name)
|
|
69
|
+
if (cameraObject) {
|
|
70
|
+
const orbit = getOrAddComponent(cameraObject, OrbitControls) as OrbitControls;
|
|
71
|
+
orbit.sourceId = cam?.sourceId ?? "unknown";
|
|
72
|
+
const autoRotate = context.domElement.getAttribute("auto-rotate");
|
|
73
|
+
orbit.autoRotate = autoRotate !== undefined && (autoRotate === "" || autoRotate === "true")
|
|
74
|
+
orbit.autoRotateSpeed = 0.5;
|
|
75
|
+
const ctx = context;
|
|
76
|
+
const fitCamera = () => {
|
|
77
|
+
ctx.pre_render_callbacks.splice(ctx.pre_render_callbacks.indexOf(fitCamera), 1);
|
|
78
|
+
orbit.fitCamera();
|
|
71
79
|
}
|
|
80
|
+
ctx.pre_render_callbacks.push(fitCamera);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
console.warn("Missing camera object, can not add orbit controls")
|
|
72
84
|
}
|
|
73
|
-
}
|
|
85
|
+
}
|
|
@@ -622,7 +622,8 @@ export class Renderer extends Behaviour implements IRenderer {
|
|
|
622
622
|
|
|
623
623
|
if (material.envMapIntensity !== undefined) {
|
|
624
624
|
const factor = this.hasLightmap ? Math.PI : 1;
|
|
625
|
-
|
|
625
|
+
const environmentIntensity = this.context.mainCameraComponent?.environmentIntensity ?? 1;
|
|
626
|
+
material.envMapIntensity = Math.max(0, environmentIntensity * this.context.sceneLighting.environmentIntensity / factor);
|
|
626
627
|
}
|
|
627
628
|
// if (this._reflectionProbe?.texture) {
|
|
628
629
|
// material.envMap = this._reflectionProbe.texture;
|