@needle-tools/engine 2.60.2-pre → 2.60.3-pre
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 +3 -0
- package/dist/needle-engine.js +151 -144
- package/dist/needle-engine.umd.cjs +11 -11
- package/lib/engine/engine_types.d.ts +1 -1
- package/lib/engine-components/Camera.d.ts +3 -3
- package/lib/engine-components/Camera.js +17 -4
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/ui/Canvas.js +6 -4
- package/lib/engine-components/ui/Canvas.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/engine/engine_types.ts +1 -1
- package/src/engine-components/Camera.ts +26 -13
- package/src/engine-components/ui/Canvas.ts +6 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/engine",
|
|
3
|
-
"version": "2.60.
|
|
3
|
+
"version": "2.60.3-pre",
|
|
4
4
|
"description": "Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development, and can be deployed anywhere. It is flexible, extensible, and collaboration and XR come naturally.",
|
|
5
5
|
"main": "dist/needle-engine.umd.cjs",
|
|
6
6
|
"module": "dist/needle-engine.js",
|
|
@@ -154,7 +154,7 @@ export declare interface ICamera extends IComponent {
|
|
|
154
154
|
backgroundBlurriness: number | undefined;
|
|
155
155
|
clearFlags: number;
|
|
156
156
|
aspect: number;
|
|
157
|
-
fieldOfView
|
|
157
|
+
fieldOfView?: number;
|
|
158
158
|
screenPointToRay(x: number, y: number, ray?: Ray): Ray;
|
|
159
159
|
}
|
|
160
160
|
|
|
@@ -31,13 +31,22 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
31
31
|
return (this.context.domWidth / this.context.domHeight);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
get fieldOfView(): number
|
|
34
|
+
get fieldOfView(): number | undefined {
|
|
35
|
+
if (this._cam instanceof PerspectiveCamera) {
|
|
36
|
+
return this._cam.fov;
|
|
37
|
+
}
|
|
38
|
+
return this._fov;
|
|
39
|
+
}
|
|
35
40
|
@serializable()
|
|
36
|
-
set fieldOfView(val) {
|
|
41
|
+
set fieldOfView(val: number | undefined) {
|
|
37
42
|
const changed = this._fov != val;
|
|
38
43
|
this._fov = val;
|
|
39
44
|
if (changed && this._cam) {
|
|
40
45
|
if (this._cam instanceof PerspectiveCamera) {
|
|
46
|
+
if (this._fov === undefined) {
|
|
47
|
+
console.error("Can not set undefined fov on PerspectiveCamera");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
41
50
|
this._cam.fov = this._fov;
|
|
42
51
|
this._cam.updateProjectionMatrix();
|
|
43
52
|
}
|
|
@@ -100,28 +109,28 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
100
109
|
|
|
101
110
|
@serializable()
|
|
102
111
|
public set backgroundBlurriness(val: number | undefined) {
|
|
103
|
-
if(val === this._backgroundBlurriness) return;
|
|
112
|
+
if (val === this._backgroundBlurriness) return;
|
|
104
113
|
if (val === undefined)
|
|
105
114
|
this._backgroundBlurriness = undefined;
|
|
106
115
|
else
|
|
107
116
|
this._backgroundBlurriness = Math.min(Math.max(val, 0), 1);
|
|
108
117
|
this.applyClearFlagsIfIsActiveCamera();
|
|
109
118
|
}
|
|
110
|
-
public get backgroundBlurriness()
|
|
119
|
+
public get backgroundBlurriness(): number | undefined {
|
|
111
120
|
return this._backgroundBlurriness;
|
|
112
121
|
}
|
|
113
122
|
private _backgroundBlurriness?: number;
|
|
114
123
|
|
|
115
124
|
@serializable()
|
|
116
125
|
public set backgroundIntensity(val: number | undefined) {
|
|
117
|
-
if(val === this._backgroundIntensity) return;
|
|
126
|
+
if (val === this._backgroundIntensity) return;
|
|
118
127
|
if (val === undefined)
|
|
119
128
|
this._backgroundIntensity = undefined;
|
|
120
129
|
else
|
|
121
130
|
this._backgroundIntensity = Math.min(Math.max(val, 0), 10);
|
|
122
131
|
this.applyClearFlagsIfIsActiveCamera();
|
|
123
132
|
}
|
|
124
|
-
public get backgroundIntensity()
|
|
133
|
+
public get backgroundIntensity(): number | undefined {
|
|
125
134
|
return this._backgroundIntensity;
|
|
126
135
|
}
|
|
127
136
|
private _backgroundIntensity?: number;
|
|
@@ -143,7 +152,7 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
143
152
|
}
|
|
144
153
|
|
|
145
154
|
private _backgroundColor?: RGBAColor;
|
|
146
|
-
private _fov
|
|
155
|
+
private _fov?: number;
|
|
147
156
|
private _cam: THREE.PerspectiveCamera | THREE.OrthographicCamera | null = null;
|
|
148
157
|
private _clearFlags: ClearFlags = ClearFlags.SolidColor;
|
|
149
158
|
private _skybox?: CameraSkybox;
|
|
@@ -161,7 +170,7 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
161
170
|
const origin = Camera._origin;
|
|
162
171
|
origin.set(x, y, -1);
|
|
163
172
|
this.context.input.convertScreenspaceToRaycastSpace(origin);
|
|
164
|
-
if(debugscreenpointtoray) console.log("screenPointToRay", x.toFixed(2), y.toFixed(2), "now:", origin.x.toFixed(2), origin.y.toFixed(2), "isInXR:" + this.context.isInXR);
|
|
173
|
+
if (debugscreenpointtoray) console.log("screenPointToRay", x.toFixed(2), y.toFixed(2), "now:", origin.x.toFixed(2), origin.y.toFixed(2), "isInXR:" + this.context.isInXR);
|
|
165
174
|
origin.z = -1;
|
|
166
175
|
origin.unproject(cam);
|
|
167
176
|
const dir = Camera._direction.set(origin.x, origin.y, origin.z);
|
|
@@ -182,13 +191,13 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
182
191
|
console.warn("Camera has no source - the camera should be exported inside a gltf", this.name);
|
|
183
192
|
}
|
|
184
193
|
|
|
185
|
-
if(debugscreenpointtoray){
|
|
194
|
+
if (debugscreenpointtoray) {
|
|
186
195
|
window.addEventListener("pointerdown", evt => {
|
|
187
196
|
const px = evt.clientX;
|
|
188
197
|
const py = evt.clientY;
|
|
189
198
|
console.log("touch", px.toFixed(2), py.toFixed(2))
|
|
190
199
|
const ray = this.screenPointToRay(px, py);
|
|
191
|
-
const randomHex = "#" + Math.floor(Math.random()*16777215).toString(16);
|
|
200
|
+
const randomHex = "#" + Math.floor(Math.random() * 16777215).toString(16);
|
|
192
201
|
Gizmos.DrawRay(ray.origin, ray.direction, randomHex, 10);
|
|
193
202
|
});
|
|
194
203
|
}
|
|
@@ -218,12 +227,15 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
218
227
|
if (cameraAlreadyCreated) {
|
|
219
228
|
cam = this.gameObject as any;
|
|
220
229
|
cam?.layers.enableAll();
|
|
230
|
+
if (cam instanceof PerspectiveCamera)
|
|
231
|
+
this._fov = cam.fov;
|
|
221
232
|
}
|
|
222
233
|
else
|
|
223
234
|
cam = this.gameObject.children[0] as THREE.PerspectiveCamera | THREE.OrthographicCamera | null;
|
|
224
235
|
if (cam && cam.isCamera) {
|
|
225
236
|
if (cam.type === "PerspectiveCamera") {
|
|
226
|
-
|
|
237
|
+
if (this._fov)
|
|
238
|
+
cam.fov = this._fov;
|
|
227
239
|
cam.near = this._nearClipPlane;
|
|
228
240
|
cam.far = this._farClipPlane;
|
|
229
241
|
cam.updateProjectionMatrix();
|
|
@@ -231,7 +243,8 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
231
243
|
}
|
|
232
244
|
else if (!this.orthographic) {
|
|
233
245
|
cam = new PerspectiveCamera(this.fieldOfView, window.innerWidth / window.innerHeight, this._nearClipPlane, this._farClipPlane);
|
|
234
|
-
|
|
246
|
+
if (this.fieldOfView)
|
|
247
|
+
cam.fov = this.fieldOfView;
|
|
235
248
|
this.gameObject.add(cam);
|
|
236
249
|
}
|
|
237
250
|
else {
|
|
@@ -337,7 +350,7 @@ class CameraSkybox {
|
|
|
337
350
|
if (!this._skybox) {
|
|
338
351
|
console.warn("Failed to load/find skybox texture", this);
|
|
339
352
|
}
|
|
340
|
-
else if(this.context.scene.background !== this._skybox) {
|
|
353
|
+
else if (this.context.scene.background !== this._skybox) {
|
|
341
354
|
if (debug)
|
|
342
355
|
console.log("Set skybox", this._camera, this._skybox);
|
|
343
356
|
this._skybox.encoding = sRGBEncoding;
|
|
@@ -159,11 +159,13 @@ export class Canvas extends UIRootComponent {
|
|
|
159
159
|
|
|
160
160
|
// console.log(this.shadowComponent)
|
|
161
161
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
if (camera.fieldOfView) {
|
|
163
|
+
const w = Math.tan(Mathf.toRadians(camera.fieldOfView) * pos) * (camera.aspect * 1.333333);
|
|
164
|
+
const h = w * (this.context.domHeight / this.context.domWidth);
|
|
165
|
+
canvas.scale.x = -w;
|
|
166
|
+
canvas.scale.y = h;
|
|
166
167
|
|
|
168
|
+
}
|
|
167
169
|
// const rects = this.gameObject.getComponentsInChildren(BaseUIComponent);
|
|
168
170
|
// for (const rect of rects) {
|
|
169
171
|
// rect.set({ width: this.context.domWidth * .5, height: 100 })
|