@needle-tools/engine 2.41.0-pre → 2.43.0-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 +24 -0
- package/dist/needle-engine.d.ts +226 -76
- package/dist/needle-engine.js +3847 -433
- package/dist/needle-engine.js.map +4 -4
- package/dist/needle-engine.min.js +51 -51
- package/dist/needle-engine.min.js.map +4 -4
- package/lib/engine/engine_element.js +1 -1
- package/lib/engine/engine_element.js.map +1 -1
- package/lib/engine/engine_element_loading.js +24 -3
- package/lib/engine/engine_element_loading.js.map +1 -1
- package/lib/engine/engine_gizmos.d.ts +8 -22
- package/lib/engine/engine_gizmos.js +37 -3
- package/lib/engine/engine_gizmos.js.map +1 -1
- package/lib/engine/engine_setup.d.ts +3 -0
- package/lib/engine/engine_setup.js +15 -0
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/engine_three_utils.d.ts +17 -1
- package/lib/engine/engine_three_utils.js +104 -54
- package/lib/engine/engine_three_utils.js.map +1 -1
- package/lib/engine/engine_time.js +2 -0
- package/lib/engine/engine_time.js.map +1 -1
- package/lib/engine/engine_types.d.ts +6 -0
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js +42 -0
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js.map +1 -1
- package/lib/engine-components/Animation.js +9 -1
- package/lib/engine-components/Animation.js.map +1 -1
- package/lib/engine-components/AnimationCurve.js +2 -2
- package/lib/engine-components/AnimationCurve.js.map +1 -1
- package/lib/engine-components/AnimatorController.js +4 -1
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/BoxHelperComponent.js +9 -10
- package/lib/engine-components/BoxHelperComponent.js.map +1 -1
- package/lib/engine-components/Camera.d.ts +3 -0
- package/lib/engine-components/Camera.js +17 -9
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/ParticleSystem.d.ts +41 -13
- package/lib/engine-components/ParticleSystem.js +587 -219
- package/lib/engine-components/ParticleSystem.js.map +1 -1
- package/lib/engine-components/ParticleSystemBehaviours.d.ts +0 -0
- package/lib/engine-components/ParticleSystemBehaviours.js +2 -0
- package/lib/engine-components/ParticleSystemBehaviours.js.map +1 -0
- package/lib/engine-components/ParticleSystemModules.d.ts +123 -22
- package/lib/engine-components/ParticleSystemModules.js +377 -60
- package/lib/engine-components/ParticleSystemModules.js.map +1 -1
- package/lib/engine-components/ReflectionProbe.js +29 -11
- package/lib/engine-components/ReflectionProbe.js.map +1 -1
- package/lib/engine-components/Renderer.d.ts +1 -0
- package/lib/engine-components/Renderer.js +4 -2
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +5 -0
- package/lib/engine-components/codegen/components.js +5 -0
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/js-extensions/RGBAColor.d.ts +1 -0
- package/lib/engine-components/js-extensions/RGBAColor.js +7 -0
- package/lib/engine-components/js-extensions/RGBAColor.js.map +1 -1
- package/package.json +3 -2
- package/src/engine/codegen/register_types.js +20 -0
- package/src/engine/dist/engine_three_utils.js +279 -0
- package/src/engine/engine_element.ts +1 -1
- package/src/engine/engine_element_loading.ts +23 -2
- package/src/engine/engine_gizmos.ts +45 -8
- package/src/engine/engine_setup.ts +25 -2
- package/src/engine/engine_three_utils.ts +113 -63
- package/src/engine/engine_time.ts +1 -0
- package/src/engine/engine_types.ts +8 -1
- package/src/engine/extensions/NEEDLE_techniques_webgl.ts +43 -1
- package/src/engine-components/Animation.ts +7 -1
- package/src/engine-components/AnimationCurve.ts +2 -2
- package/src/engine-components/AnimatorController.ts +5 -1
- package/src/engine-components/BoxHelperComponent.ts +12 -15
- package/src/engine-components/Camera.ts +17 -10
- package/src/engine-components/ParticleSystem.ts +660 -258
- package/src/engine-components/ParticleSystemBehaviours.ts +0 -0
- package/src/engine-components/ParticleSystemModules.ts +379 -64
- package/src/engine-components/ReflectionProbe.ts +37 -13
- package/src/engine-components/Renderer.ts +4 -2
- package/src/engine-components/codegen/components.ts +5 -0
- package/src/engine-components/js-extensions/RGBAColor.ts +7 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import * as THREE from "three";
|
|
2
2
|
import { Mathf } from "./engine_math"
|
|
3
|
-
import { Vector3, Quaternion, Uniform } from "three";
|
|
3
|
+
import { WebGLRenderTarget, WebGLRenderer, Vector3, Quaternion, Uniform, Texture, Material, ShaderMaterial, CanvasTexture, AnimationAction } from "three";
|
|
4
4
|
import { CircularBuffer } from "./engine_utils";
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
const flipYQuat: Quaternion = new Quaternion().setFromAxisAngle(new Vector3(0, 1, 0), Math.PI);
|
|
9
8
|
export function lookAtInverse(obj: THREE.Object3D, target: Vector3) {
|
|
10
9
|
|
|
@@ -78,7 +77,7 @@ const _worldScale2: THREE.Vector3 = new THREE.Vector3();
|
|
|
78
77
|
|
|
79
78
|
export function getWorldScale(obj: THREE.Object3D, vec: THREE.Vector3 | null = null): THREE.Vector3 {
|
|
80
79
|
if (!obj) return _worldScale.set(0, 0, 0);
|
|
81
|
-
if (!obj.parent) return _worldScale.copy(obj.
|
|
80
|
+
if (!obj.parent) return _worldScale.copy(obj.scale);
|
|
82
81
|
obj.getWorldScale(vec ?? _worldScale);
|
|
83
82
|
return vec ?? _worldScale;
|
|
84
83
|
}
|
|
@@ -177,42 +176,122 @@ export function logHierarchy(root: THREE.Object3D | null | undefined, collapsibl
|
|
|
177
176
|
}
|
|
178
177
|
|
|
179
178
|
|
|
179
|
+
export function isAnimationAction(obj:object){
|
|
180
|
+
if(obj){
|
|
181
|
+
// this doesnt work :(
|
|
182
|
+
// return obj instanceof AnimationAction;
|
|
183
|
+
// instead we do this:
|
|
184
|
+
const act = obj as AnimationAction;
|
|
185
|
+
return act.blendMode !== undefined && act.clampWhenFinished !== undefined && act.enabled !== undefined && act.fadeIn !== undefined && act.getClip !== undefined;
|
|
186
|
+
}
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
180
191
|
|
|
181
192
|
|
|
193
|
+
export class Graphics {
|
|
194
|
+
private static planeGeometry = new THREE.PlaneGeometry(2, 2, 1, 1);
|
|
195
|
+
private static renderer = new WebGLRenderer({ antialias: false });
|
|
196
|
+
private static perspectiveCam = new THREE.PerspectiveCamera();
|
|
197
|
+
private static scene = new THREE.Scene();
|
|
198
|
+
private static readonly vertex = `
|
|
199
|
+
varying vec2 vUv;
|
|
200
|
+
void main(){
|
|
201
|
+
vUv = uv;
|
|
202
|
+
gl_Position = vec4(position.xy * 1.0,0.,.999999);
|
|
203
|
+
}`;
|
|
204
|
+
private static readonly fragment = `
|
|
205
|
+
uniform sampler2D map;
|
|
206
|
+
varying vec2 vUv;
|
|
207
|
+
void main(){
|
|
208
|
+
vec2 uv = vUv;
|
|
209
|
+
uv.y = 1.0 - uv.y;
|
|
210
|
+
gl_FragColor = texture2D( map, uv);
|
|
211
|
+
// gl_FragColor = vec4(uv.xy, 0, 1);
|
|
212
|
+
}`;
|
|
213
|
+
private static readonly blipMaterial = new ShaderMaterial({
|
|
214
|
+
uniforms: { map: new Uniform(null) },
|
|
215
|
+
vertexShader: this.vertex,
|
|
216
|
+
fragmentShader: this.fragment
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
static createBlitMaterial(fragment: string): ShaderMaterial {
|
|
220
|
+
return new ShaderMaterial({
|
|
221
|
+
uniforms: { map: new Uniform(null) },
|
|
222
|
+
vertexShader: this.vertex,
|
|
223
|
+
fragmentShader: fragment
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
private static readonly mesh = new THREE.Mesh(this.planeGeometry, this.blipMaterial);
|
|
227
|
+
|
|
228
|
+
static copyTexture(texture: Texture, blitMaterial?: ShaderMaterial) {
|
|
229
|
+
const material = blitMaterial ?? this.blipMaterial;
|
|
230
|
+
material.uniforms.map.value = texture;
|
|
231
|
+
material.needsUpdate = true;
|
|
232
|
+
material.uniformsNeedUpdate = true;
|
|
233
|
+
const mesh = this.mesh;
|
|
234
|
+
mesh.material = material;
|
|
235
|
+
mesh.frustumCulled = false;
|
|
236
|
+
this.scene.children.length = 0;
|
|
237
|
+
this.scene.add(mesh);
|
|
238
|
+
this.renderer.setSize(texture.image.width, texture.image.height);
|
|
239
|
+
this.renderer.clear();
|
|
240
|
+
this.renderer.render(this.scene, this.perspectiveCam);
|
|
241
|
+
const tex = new Texture(this.renderer.domElement);
|
|
242
|
+
tex.name = "Copy";
|
|
243
|
+
tex.needsUpdate = true; // < important!
|
|
244
|
+
return tex;
|
|
245
|
+
}
|
|
182
246
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
247
|
+
// static blit(src: Texture, target: Texture, blitMaterial?: ShaderMaterial) {
|
|
248
|
+
// let material = blitMaterial ?? this.blipMaterial;
|
|
249
|
+
// material.uniforms.map.value = src;
|
|
250
|
+
// this.mesh.material = material;
|
|
251
|
+
// this.mesh.frustumCulled = false;
|
|
252
|
+
// this.mesh.matrix.identity();
|
|
253
|
+
// this.scene.children.length = 0;
|
|
254
|
+
// this.scene.add(this.mesh);
|
|
255
|
+
// this.renderer.setSize(src.image.width, src.image.height);
|
|
256
|
+
// this.renderer.clear();
|
|
257
|
+
// this.renderer.render(this.scene, this.perspectiveCam);
|
|
258
|
+
// return new Texture(this.renderer.domElement);
|
|
259
|
+
// }
|
|
260
|
+
|
|
261
|
+
static textureToCanvas(texture: Texture, force: boolean) {
|
|
262
|
+
if (!texture) return null;
|
|
263
|
+
|
|
264
|
+
if (force === true || texture["isCompressedTexture"] === true) {
|
|
265
|
+
texture = copyTexture(texture);
|
|
266
|
+
}
|
|
267
|
+
const image = texture.image;
|
|
268
|
+
if (isImageBitmap(image)) {
|
|
269
|
+
|
|
270
|
+
const canvas = document.createElement('canvas');
|
|
271
|
+
canvas.width = image.width;
|
|
272
|
+
canvas.height = image.height;
|
|
273
|
+
|
|
274
|
+
const context = canvas.getContext('2d');
|
|
275
|
+
if (!context) {
|
|
276
|
+
console.error("Failed getting canvas 2d context");
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
context.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
|
|
280
|
+
return canvas;
|
|
281
|
+
|
|
282
|
+
}
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
205
286
|
|
|
287
|
+
/**@obsolete use Graphics.copyTexture */
|
|
206
288
|
export function copyTexture(texture: THREE.Texture): THREE.Texture {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
renderer.clear();
|
|
214
|
-
renderer.render(scene, perspectiveCam);
|
|
215
|
-
return new THREE.Texture(renderer.domElement);
|
|
289
|
+
return Graphics.copyTexture(texture);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**@obsolete use Graphics.textureToCanvas */
|
|
293
|
+
export function textureToCanvas(texture: THREE.Texture, force: boolean = false): HTMLCanvasElement | null {
|
|
294
|
+
return Graphics.textureToCanvas(texture, force);
|
|
216
295
|
}
|
|
217
296
|
|
|
218
297
|
declare class OffscreenCanvas { };
|
|
@@ -222,33 +301,4 @@ function isImageBitmap(image) {
|
|
|
222
301
|
(typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement) ||
|
|
223
302
|
(typeof OffscreenCanvas !== 'undefined' && image instanceof OffscreenCanvas) ||
|
|
224
303
|
(typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
export function textureToCanvas(texture: THREE.Texture, force : boolean = false): HTMLCanvasElement | null {
|
|
229
|
-
|
|
230
|
-
if(!texture) return null;
|
|
231
|
-
|
|
232
|
-
if (force === true || texture["isCompressedTexture"] === true) {
|
|
233
|
-
texture = copyTexture(texture);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const image = texture.image;
|
|
237
|
-
|
|
238
|
-
if (isImageBitmap(image)) {
|
|
239
|
-
|
|
240
|
-
const canvas = document.createElement('canvas');
|
|
241
|
-
canvas.width = image.width;
|
|
242
|
-
canvas.height = image.height;
|
|
243
|
-
|
|
244
|
-
const context = canvas.getContext('2d');
|
|
245
|
-
if (!context) {
|
|
246
|
-
console.error("Failed getting canvas 2d context");
|
|
247
|
-
return null;
|
|
248
|
-
}
|
|
249
|
-
context.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
|
|
250
|
-
return canvas;
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
return null;
|
|
254
304
|
}
|
|
@@ -27,6 +27,7 @@ export class Time {
|
|
|
27
27
|
this.deltaTime = this.clock.getDelta();
|
|
28
28
|
// clamp delta time because if tab is not active clock.getDelta can get pretty big
|
|
29
29
|
this.deltaTime = Math.min(.1, this.deltaTime);
|
|
30
|
+
if(this.deltaTime <= 0) this.deltaTime = 0.000000000001;
|
|
30
31
|
this.frame += 1;
|
|
31
32
|
this.time += this.deltaTime;
|
|
32
33
|
|
|
@@ -157,7 +157,14 @@ export type Vec2 = {
|
|
|
157
157
|
export type Vec3 = {
|
|
158
158
|
x: number,
|
|
159
159
|
y: number,
|
|
160
|
-
z: number
|
|
160
|
+
z: number,
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export type Vec4 = {
|
|
164
|
+
x: number,
|
|
165
|
+
y: number,
|
|
166
|
+
z: number,
|
|
167
|
+
w: number,
|
|
161
168
|
}
|
|
162
169
|
|
|
163
170
|
const contactsVectorBuffer = new CircularBuffer(() => new Vector3(), 20);
|
|
@@ -57,6 +57,16 @@ enum CullMode {
|
|
|
57
57
|
Front = 1,
|
|
58
58
|
Back = 2,
|
|
59
59
|
}
|
|
60
|
+
enum ZTestMode {
|
|
61
|
+
Never = 1,
|
|
62
|
+
Less = 2,
|
|
63
|
+
Equal = 3,
|
|
64
|
+
LEqual = 4,
|
|
65
|
+
Greater = 5,
|
|
66
|
+
NotEqual = 6,
|
|
67
|
+
GEqual = 7,
|
|
68
|
+
Always = 8,
|
|
69
|
+
}
|
|
60
70
|
|
|
61
71
|
export class CustomShader extends RawShaderMaterial {
|
|
62
72
|
|
|
@@ -446,6 +456,7 @@ export class NEEDLE_techniques_webgl implements GLTFLoaderPlugin {
|
|
|
446
456
|
// "USE_SHADOWMAP" : true
|
|
447
457
|
// },
|
|
448
458
|
});
|
|
459
|
+
|
|
449
460
|
const culling = uniforms["_Cull"]?.value;
|
|
450
461
|
switch (culling) {
|
|
451
462
|
case CullMode.Off:
|
|
@@ -462,6 +473,38 @@ export class NEEDLE_techniques_webgl implements GLTFLoaderPlugin {
|
|
|
462
473
|
break;
|
|
463
474
|
}
|
|
464
475
|
|
|
476
|
+
const zTest = uniforms["_ZTest"]?.value as ZTestMode;
|
|
477
|
+
switch (zTest) {
|
|
478
|
+
case ZTestMode.Equal:
|
|
479
|
+
material.depthTest = true;
|
|
480
|
+
material.depthFunc = THREE.EqualDepth;
|
|
481
|
+
break;
|
|
482
|
+
case ZTestMode.NotEqual:
|
|
483
|
+
material.depthTest = true;
|
|
484
|
+
material.depthFunc = THREE.NotEqualDepth;
|
|
485
|
+
break;
|
|
486
|
+
case ZTestMode.Less:
|
|
487
|
+
material.depthTest = true;
|
|
488
|
+
material.depthFunc = THREE.LessDepth;
|
|
489
|
+
break;
|
|
490
|
+
case ZTestMode.LEqual:
|
|
491
|
+
material.depthTest = true;
|
|
492
|
+
material.depthFunc = THREE.LessEqualDepth;
|
|
493
|
+
break;
|
|
494
|
+
case ZTestMode.Greater:
|
|
495
|
+
material.depthTest = true;
|
|
496
|
+
material.depthFunc = THREE.GreaterDepth;
|
|
497
|
+
break;
|
|
498
|
+
case ZTestMode.GEqual:
|
|
499
|
+
material.depthTest = true;
|
|
500
|
+
material.depthFunc = THREE.GreaterEqualDepth;
|
|
501
|
+
break;
|
|
502
|
+
case ZTestMode.Always:
|
|
503
|
+
material.depthTest = false;
|
|
504
|
+
material.depthFunc = THREE.AlwaysDepth;
|
|
505
|
+
break;
|
|
506
|
+
}
|
|
507
|
+
|
|
465
508
|
material.transparent = isTransparent;
|
|
466
509
|
if (isTransparent)
|
|
467
510
|
material.depthWrite = false;
|
|
@@ -490,7 +533,6 @@ export class NEEDLE_techniques_webgl implements GLTFLoaderPlugin {
|
|
|
490
533
|
if (debug)
|
|
491
534
|
console.log(material.uuid, uniforms);
|
|
492
535
|
|
|
493
|
-
|
|
494
536
|
createUniformProperties(material);
|
|
495
537
|
|
|
496
538
|
resolve(material);
|
|
@@ -6,6 +6,9 @@ import { serializeable } from "../engine/engine_serialization_decorator";
|
|
|
6
6
|
import { InstancingUtil } from "../engine/engine_instancing";
|
|
7
7
|
import { Mathf } from "../engine/engine_math";
|
|
8
8
|
import { Vec2 } from "../engine/engine_types";
|
|
9
|
+
import { getParam } from "../engine/engine_utils";
|
|
10
|
+
|
|
11
|
+
const debug = getParam("debuganimation");
|
|
9
12
|
|
|
10
13
|
export declare class PlayOptions {
|
|
11
14
|
fadeDuration?: number;
|
|
@@ -33,16 +36,19 @@ export class Animation extends Behaviour {
|
|
|
33
36
|
return this.animations?.length ? this.animations[0] : null;
|
|
34
37
|
}
|
|
35
38
|
set clip(val: AnimationClip | null) {
|
|
36
|
-
if (!this.
|
|
39
|
+
if (!this.__didAwake) {
|
|
40
|
+
if(debug) console.log("Assign clip during serialization", val);
|
|
37
41
|
this._tempAnimationClipBeforeGameObjectExisted = val;
|
|
38
42
|
return;
|
|
39
43
|
}
|
|
40
44
|
if (!val) return;
|
|
45
|
+
if(debug) console.log("Assign clip", val, Boolean(this.gameObject));
|
|
41
46
|
if (!this.gameObject.animations) this.gameObject.animations = [];
|
|
42
47
|
this.gameObject.animations.push(val);
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
set animations(animations: THREE.AnimationClip[]) {
|
|
51
|
+
if(debug) console.log("assign animations", animations);
|
|
46
52
|
this.gameObject.animations = animations;
|
|
47
53
|
}
|
|
48
54
|
|
|
@@ -32,12 +32,12 @@ export class AnimationCurve {
|
|
|
32
32
|
if (!this.keys || this.keys.length == 0) return 0;
|
|
33
33
|
// if the first keyframe time is already greater than the time we want to evaluate
|
|
34
34
|
// then we dont need to iterate
|
|
35
|
-
if (this.keys[0].time
|
|
35
|
+
if (this.keys[0].time >= time) {
|
|
36
36
|
return this.keys[0].value;
|
|
37
37
|
}
|
|
38
38
|
for (let i = 0; i < this.keys.length; i++) {
|
|
39
39
|
const kf = this.keys[i];
|
|
40
|
-
if (kf.time
|
|
40
|
+
if (kf.time <= time) {
|
|
41
41
|
const hasNextKeyframe = i+1 < this.keys.length;
|
|
42
42
|
if (hasNextKeyframe) {
|
|
43
43
|
const nextKf = this.keys[i+1];
|
|
@@ -7,6 +7,7 @@ import * as THREE from "three";
|
|
|
7
7
|
import { TypeStore } from "../engine/engine_typestore";
|
|
8
8
|
import { assign } from "../engine/engine_serialization_core";
|
|
9
9
|
import { Mathf } from "../engine/engine_math";
|
|
10
|
+
import { isAnimationAction } from "../engine/engine_three_utils";
|
|
10
11
|
|
|
11
12
|
const debug = getParam("debuganimatorcontroller");
|
|
12
13
|
const debugRootMotion = getParam("debugrootmotion");
|
|
@@ -122,7 +123,10 @@ export class AnimatorController {
|
|
|
122
123
|
// dont clone three Objects
|
|
123
124
|
if (_value.type === "Object3D" || _value.isObject3D === true) return false;
|
|
124
125
|
// dont clone AnimationAction
|
|
125
|
-
if (_value
|
|
126
|
+
if (isAnimationAction(_value)) { //.constructor.name === "AnimationAction") {
|
|
127
|
+
console.log(_value);
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
126
130
|
// dont clone AnimationClip
|
|
127
131
|
if (_value["tracks"] !== undefined) return false;
|
|
128
132
|
return true;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Behaviour } from "./Component";
|
|
2
2
|
import * as THREE from "three";
|
|
3
3
|
import { getParam } from "../engine/engine_utils";
|
|
4
|
-
import { CreateWireCube } from "../engine/engine_gizmos";
|
|
4
|
+
import { CreateWireCube, Gizmos } from "../engine/engine_gizmos";
|
|
5
5
|
import { getWorldPosition, getWorldScale } from "../engine/engine_three_utils";
|
|
6
6
|
|
|
7
7
|
const gizmos = getParam("gizmos");
|
|
8
|
+
const debug = getParam("debugboxhelper");
|
|
8
9
|
|
|
9
10
|
export class BoxHelperComponent extends Behaviour {
|
|
10
11
|
|
|
@@ -14,7 +15,7 @@ export class BoxHelperComponent extends Behaviour {
|
|
|
14
15
|
private static _position: THREE.Vector3 = new THREE.Vector3();
|
|
15
16
|
private static _size: THREE.Vector3 = new THREE.Vector3(.01, .01, .01);
|
|
16
17
|
|
|
17
|
-
public isInBox(obj: THREE.Object3D, scaleFactor
|
|
18
|
+
public isInBox(obj: THREE.Object3D, scaleFactor?: number): boolean | undefined {
|
|
18
19
|
if (!obj) return undefined;
|
|
19
20
|
|
|
20
21
|
// if (!obj.geometry.boundingBox) obj.geometry.computeBoundingBox();
|
|
@@ -24,15 +25,13 @@ export class BoxHelperComponent extends Behaviour {
|
|
|
24
25
|
this.box = new THREE.Box3();
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
|
|
27
29
|
if (obj.type === "Mesh") {
|
|
28
30
|
BoxHelperComponent.testBox.setFromObject(obj);
|
|
29
31
|
}
|
|
30
32
|
else if (obj.type === "Group") {
|
|
33
|
+
BoxHelperComponent.testBox.makeEmpty();
|
|
31
34
|
if (obj.children.length > 0) {
|
|
32
|
-
BoxHelperComponent.testBox.setFromCenterAndSize(
|
|
33
|
-
BoxHelperComponent._position.set(0, 0, 0),
|
|
34
|
-
BoxHelperComponent._size.set(0, 0, 0)
|
|
35
|
-
);
|
|
36
35
|
for (let i = 0; i < obj.children.length; i++) {
|
|
37
36
|
const ch = obj.children[i];
|
|
38
37
|
if (ch.type === "Mesh") {
|
|
@@ -44,19 +43,17 @@ export class BoxHelperComponent extends Behaviour {
|
|
|
44
43
|
else {
|
|
45
44
|
const wp = getWorldPosition(obj, BoxHelperComponent._position);
|
|
46
45
|
const size = getWorldScale(obj, BoxHelperComponent._size);
|
|
47
|
-
if(scaleFactor !== undefined) size.multiplyScalar(scaleFactor);
|
|
46
|
+
if (scaleFactor !== undefined) size.multiplyScalar(scaleFactor);
|
|
48
47
|
BoxHelperComponent.testBox.setFromCenterAndSize(wp, size);
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
// console.log("Obj box:", obj.name, obj.uuid, BoxHelperComponent.testBox.getCenter(new THREE.Vector3()), BoxHelperComponent.testBox.getSize(new THREE.Vector3()),
|
|
52
|
-
// "\nTest box:", this.box.getCenter(new THREE.Vector3()), this.box.getSize(new THREE.Vector3()), this.context.time.frameCount);
|
|
53
|
-
// this.tp.copy(obj.geometry.boundingBox);
|
|
54
|
-
// // this.tp.setFromCenterAndSize(obj.position, obj.scale);
|
|
55
|
-
// this.tp.applyMatrix4(obj.matrixWorld);
|
|
56
|
-
// console.log(this.tp);
|
|
57
|
-
// console.log(this.box?.min, this.box?.max, this.tp.min, this.tp.max);
|
|
58
50
|
this.updateBox();
|
|
59
|
-
|
|
51
|
+
const intersects = this.box?.intersectsBox(BoxHelperComponent.testBox);
|
|
52
|
+
if (intersects) {
|
|
53
|
+
if (debug)
|
|
54
|
+
Gizmos.DrawBox3(BoxHelperComponent.testBox, 0xff0000, 5);
|
|
55
|
+
}
|
|
56
|
+
return intersects;
|
|
60
57
|
}
|
|
61
58
|
|
|
62
59
|
public intersects(box: THREE.Box3): boolean {
|
|
@@ -80,6 +80,19 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
80
80
|
@serializeable()
|
|
81
81
|
public ARBackgroundAlpha: number = 0;
|
|
82
82
|
|
|
83
|
+
@serializeable()
|
|
84
|
+
public set cullingMask(val: number) {
|
|
85
|
+
this._cullingMask = val;
|
|
86
|
+
if (this._cam) {
|
|
87
|
+
this._cam.layers.mask = val;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
public get cullingMask(): number {
|
|
91
|
+
if (this._cam) return this._cam.layers.mask;
|
|
92
|
+
return this._cullingMask;
|
|
93
|
+
}
|
|
94
|
+
private _cullingMask: number = 0xffffffff;
|
|
95
|
+
|
|
83
96
|
private _nearClipPlane: number = 0.1;
|
|
84
97
|
private _farClipPlane: number = 1000;
|
|
85
98
|
|
|
@@ -95,7 +108,7 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
95
108
|
}
|
|
96
109
|
else this._backgroundColor.copy(val);
|
|
97
110
|
// set background color to solid if provided color doesnt have any alpha channel
|
|
98
|
-
if(val.alpha === undefined) this._backgroundColor.alpha = 1;
|
|
111
|
+
if (val.alpha === undefined) this._backgroundColor.alpha = 1;
|
|
99
112
|
this.applyClearFlagsIfIsActiveCamera();
|
|
100
113
|
}
|
|
101
114
|
|
|
@@ -113,10 +126,6 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
113
126
|
}
|
|
114
127
|
|
|
115
128
|
|
|
116
|
-
// constructor(){
|
|
117
|
-
// super();
|
|
118
|
-
// console.log(this);
|
|
119
|
-
// }
|
|
120
129
|
|
|
121
130
|
awake() {
|
|
122
131
|
if (!this.sourceId) {
|
|
@@ -146,6 +155,7 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
146
155
|
let cam: THREE.PerspectiveCamera | THREE.OrthographicCamera | null = null;
|
|
147
156
|
if (cameraAlreadyCreated) {
|
|
148
157
|
cam = this.gameObject as any;
|
|
158
|
+
cam?.layers.enableAll();
|
|
149
159
|
}
|
|
150
160
|
else
|
|
151
161
|
cam = this.gameObject.children[0] as THREE.PerspectiveCamera | THREE.OrthographicCamera | null;
|
|
@@ -167,11 +177,8 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
167
177
|
}
|
|
168
178
|
this._cam = cam;
|
|
169
179
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (this.layer === 0) {
|
|
173
|
-
this._cam.layers.enableAll();
|
|
174
|
-
}
|
|
180
|
+
this._cam.layers.mask = this._cullingMask;
|
|
181
|
+
|
|
175
182
|
if (this.tag == "MainCamera") {
|
|
176
183
|
this.context.setCurrentCamera(this);
|
|
177
184
|
}
|