@needle-tools/engine 4.3.0-alpha.4 → 4.3.0-alpha.6
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 +10 -0
- package/dist/needle-engine.bundle.js +5050 -5003
- package/dist/needle-engine.bundle.light.js +4922 -4875
- package/dist/needle-engine.bundle.light.min.js +107 -107
- package/dist/needle-engine.bundle.light.umd.cjs +115 -115
- package/dist/needle-engine.bundle.min.js +107 -107
- package/dist/needle-engine.bundle.umd.cjs +115 -115
- package/dist/needle-engine.d.ts +9 -9
- package/lib/engine/engine_addressables.js +10 -2
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_math.d.ts +22 -2
- package/lib/engine/engine_math.js +23 -3
- package/lib/engine/engine_math.js.map +1 -1
- package/lib/engine/engine_three_utils.d.ts +8 -2
- package/lib/engine/engine_three_utils.js +17 -10
- package/lib/engine/engine_three_utils.js.map +1 -1
- package/lib/engine/engine_utils_screenshot.js +17 -2
- package/lib/engine/engine_utils_screenshot.js.map +1 -1
- package/lib/engine-components/AudioSource.js +10 -3
- package/lib/engine-components/AudioSource.js.map +1 -1
- package/lib/engine-components/RigidBody.d.ts +3 -1
- package/lib/engine-components/RigidBody.js +6 -5
- package/lib/engine-components/RigidBody.js.map +1 -1
- package/lib/engine-components/SpriteRenderer.d.ts +2 -0
- package/lib/engine-components/SpriteRenderer.js +16 -6
- package/lib/engine-components/SpriteRenderer.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.d.ts +2 -0
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js +42 -5
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js.map +1 -1
- package/lib/engine-components/postprocessing/PostProcessingEffect.d.ts +4 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.js +9 -1
- package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.js +6 -6
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
- package/lib/engine-components/postprocessing/Volume.js +6 -6
- package/lib/engine-components/postprocessing/Volume.js.map +1 -1
- package/lib/engine-components/postprocessing/VolumeProfile.d.ts +2 -1
- package/lib/engine-components/postprocessing/VolumeProfile.js +8 -2
- package/lib/engine-components/postprocessing/VolumeProfile.js.map +1 -1
- package/package.json +2 -2
- package/src/engine/engine_addressables.ts +12 -2
- package/src/engine/engine_math.ts +25 -7
- package/src/engine/engine_three_utils.ts +22 -14
- package/src/engine/engine_utils_screenshot.ts +17 -3
- package/src/engine-components/AudioSource.ts +17 -8
- package/src/engine-components/RigidBody.ts +6 -4
- package/src/engine-components/SpriteRenderer.ts +22 -6
- package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.ts +56 -9
- package/src/engine-components/postprocessing/PostProcessingEffect.ts +7 -1
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +6 -6
- package/src/engine-components/postprocessing/Volume.ts +5 -7
- package/src/engine-components/postprocessing/VolumeProfile.ts +10 -2
|
@@ -61,6 +61,8 @@ export class Volume extends Behaviour {
|
|
|
61
61
|
if (!(entry instanceof PostProcessingEffect)) {
|
|
62
62
|
entry = new EffectWrapper(entry);
|
|
63
63
|
}
|
|
64
|
+
if (entry.gameObject === undefined)
|
|
65
|
+
this.gameObject.addComponent(entry);
|
|
64
66
|
if (this._effects.includes(entry))
|
|
65
67
|
return effect;
|
|
66
68
|
this._effects.push(entry);
|
|
@@ -113,7 +115,7 @@ export class Volume extends Behaviour {
|
|
|
113
115
|
});
|
|
114
116
|
}
|
|
115
117
|
// ensure the profile is initialized
|
|
116
|
-
this.sharedProfile?.
|
|
118
|
+
this.sharedProfile?.__init(this);
|
|
117
119
|
}
|
|
118
120
|
onEnable() {
|
|
119
121
|
this._isDirty = true;
|
|
@@ -168,7 +170,7 @@ export class Volume extends Behaviour {
|
|
|
168
170
|
_isDirty = false;
|
|
169
171
|
apply() {
|
|
170
172
|
if (debug)
|
|
171
|
-
console.log(
|
|
173
|
+
console.log(`Apply PostProcessing "${this.name}"`);
|
|
172
174
|
if (isDevEnvironment()) {
|
|
173
175
|
if (this._lastApplyTime !== undefined && Date.now() - this._lastApplyTime < 100) {
|
|
174
176
|
this._rapidApplyCount++;
|
|
@@ -184,17 +186,15 @@ export class Volume extends Behaviour {
|
|
|
184
186
|
if (this.sharedProfile?.components) {
|
|
185
187
|
const comps = this.sharedProfile.components;
|
|
186
188
|
for (const effect of comps) {
|
|
187
|
-
if (effect.active && !this._activeEffects.includes(effect))
|
|
189
|
+
if (effect.active && effect.enabled && !this._activeEffects.includes(effect))
|
|
188
190
|
this._activeEffects.push(effect);
|
|
189
191
|
}
|
|
190
192
|
}
|
|
191
193
|
// add effects registered via code
|
|
192
194
|
for (const effect of this._effects) {
|
|
193
|
-
if (effect.active && !this._activeEffects.includes(effect))
|
|
195
|
+
if (effect.active && effect.enabled && !this._activeEffects.includes(effect))
|
|
194
196
|
this._activeEffects.push(effect);
|
|
195
197
|
}
|
|
196
|
-
if (debug)
|
|
197
|
-
console.log("Apply PostProcessing", this._activeEffects);
|
|
198
198
|
if (this._activeEffects.length > 0) {
|
|
199
199
|
if (!this._postprocessing)
|
|
200
200
|
this._postprocessing = new PostProcessingHandler(this.context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Volume.js","sourceRoot":"","sources":["../../../src/engine-components/postprocessing/Volume.ts"],"names":[],"mappings":";;;;;;AAEA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEnF,OAAO,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AA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CAAC,WAAW,CAAC;QAC9B,UAAU,CAAC,GAAG,EAAE;YACZ,IAAI,EAAE,KAAK,IAAI,CAAC,WAAW;gBAAE,OAAO;YACpC,IAAI,CAAC,SAAS,EAAE,CAAC;YACjB,IAAI,CAAC,QAAQ,EAAE,CAAC;QACpB,CAAC,EAAE,GAAG,CAAC,CAAC;IACZ,CAAC;CAEJ;AA5QG;IADC,aAAa,CAAC,aAAa,CAAC;6CACC;AA8QlC,6CAA6C;AAC7C,MAAM,sBAAsB,GAA0B,IAAI,GAAG,EAAoB,CAAC;AAGlF,4BAA4B,CAAC,MAAM,CAAC,CAAC;AAErC,OAAO,EAAE,MAAM,IAAI,qBAAqB,EAAE,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Component } from "../Component.js";
|
|
1
2
|
import { PostProcessingEffect } from "./PostProcessingEffect.js";
|
|
2
3
|
export declare function registerCustomEffectType(name: string, effect: typeof PostProcessingEffect): void;
|
|
3
4
|
/** @internal */
|
|
@@ -8,7 +9,7 @@ export declare class VolumeProfile {
|
|
|
8
9
|
* call init on all components
|
|
9
10
|
* @hidden
|
|
10
11
|
**/
|
|
11
|
-
|
|
12
|
+
__init(owner: Component): void;
|
|
12
13
|
addEffect(effect: PostProcessingEffect): void;
|
|
13
14
|
removeEffect(effect: PostProcessingEffect): void;
|
|
14
15
|
}
|
|
@@ -37,8 +37,14 @@ export class VolumeProfile {
|
|
|
37
37
|
* call init on all components
|
|
38
38
|
* @hidden
|
|
39
39
|
**/
|
|
40
|
-
|
|
41
|
-
this.components?.forEach(c =>
|
|
40
|
+
__init(owner) {
|
|
41
|
+
this.components?.forEach(c => {
|
|
42
|
+
// Make sure all components are added to the gameobject (this is not the case when e.g. effects are serialized from Unity)
|
|
43
|
+
if (c.gameObject === undefined) {
|
|
44
|
+
owner.gameObject.addComponent(c);
|
|
45
|
+
}
|
|
46
|
+
c.init();
|
|
47
|
+
});
|
|
42
48
|
}
|
|
43
49
|
addEffect(effect) {
|
|
44
50
|
this.components.push(effect);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VolumeProfile.js","sourceRoot":"","sources":["../../../src/engine-components/postprocessing/VolumeProfile.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"VolumeProfile.js","sourceRoot":"","sources":["../../../src/engine-components/postprocessing/VolumeProfile.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAExD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAGjE,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;AAEpC,MAAM,aAAa,GAAoD,EAAE,CAAC;AAC1E,MAAM,UAAU,wBAAwB,CAAC,IAAY,EAAE,MAAmC;IACtF,aAAa,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACjC,CAAC;AAED,qBAAqB;AACrB,SAAS,oBAAoB,CAAC,IAAwB;IAClD,IAAI,IAAI,CAAC,MAAM,IAAI,aAAa;QAC5B,OAAO,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtC,0CAA0C;IAC1C,uDAAuD;IACvD,yBAAyB;IACzB,qCAAqC;IACrC,mDAAmD;IACnD,0CAA0C;IAC1C,2DAA2D;IAC3D,iDAAiD;IACjD,IAAI;IACJ,IAAI,KAAK,IAAI,IAAI,CAAC,MAAM;QACpB,OAAO,CAAC,IAAI,CAAC,6BAA6B,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAClE,OAAO,oBAAoB,CAAC;AAChC,CAAC;AAED,gBAAgB;AAChB,MAAM,OAAO,aAAa;IAEtB,kCAAkC;IAElC,UAAU,GAA2B,EAAE,CAAC;IAExC;;;QAGI;IACJ,MAAM,CAAC,KAAgB;QACnB,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE;YACzB,0HAA0H;YAC1H,IAAI,CAAC,CAAC,UAAU,KAAK,SAAS,EAAE;gBAC5B,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;aACpC;YACD,CAAC,CAAC,IAAI,EAAE,CAAA;QACZ,CAAC,CAAC,CAAC;IACP,CAAC;IAED,SAAS,CAAC,MAA4B;QAClC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IACD,YAAY,CAAC,MAA4B;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,GAAG,IAAI,CAAC;YAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACjD,CAAC;CACJ;AAvBG;IADC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;iDAC5B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/engine",
|
|
3
|
-
"version": "4.3.0-alpha.
|
|
3
|
+
"version": "4.3.0-alpha.6",
|
|
4
4
|
"description": "Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in",
|
|
5
5
|
"main": "dist/needle-engine.min.js",
|
|
6
6
|
"exports": {
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
],
|
|
87
87
|
"dependencies": {
|
|
88
88
|
"@dimforge/rapier3d-compat": "^0.14.0",
|
|
89
|
-
"@needle-tools/gltf-progressive": "^2.1.
|
|
89
|
+
"@needle-tools/gltf-progressive": "^2.1.2",
|
|
90
90
|
"@webxr-input-profiles/motion-controllers": "^1.0.0",
|
|
91
91
|
"flatbuffers": "2.0.4",
|
|
92
92
|
"md5": "^2.3.0",
|
|
@@ -548,10 +548,20 @@ export class ImageReference {
|
|
|
548
548
|
|
|
549
549
|
private loader: TextureLoader | null = null;
|
|
550
550
|
createTexture(): Promise<Texture | null> {
|
|
551
|
-
if (!this.url)
|
|
551
|
+
if (!this.url) {
|
|
552
|
+
console.error("Can not load texture without url");
|
|
553
|
+
return failedTexturePromise;
|
|
554
|
+
}
|
|
555
|
+
|
|
552
556
|
if (!this.loader) this.loader = new TextureLoader();
|
|
553
557
|
this.loader.setCrossOrigin("anonymous");
|
|
554
|
-
return this.loader.loadAsync(this.url)
|
|
558
|
+
return this.loader.loadAsync(this.url).then(res => {
|
|
559
|
+
if (res && !res.name?.length) {
|
|
560
|
+
// default name if no name is defined
|
|
561
|
+
res.name = this.url.split("/").pop() ?? this.url;
|
|
562
|
+
}
|
|
563
|
+
return res;
|
|
564
|
+
})
|
|
555
565
|
// return this.getBitmap().then((bitmap) => {
|
|
556
566
|
// if (bitmap) {
|
|
557
567
|
// const texture = new Texture(bitmap);
|
|
@@ -43,16 +43,30 @@ class MathHelper {
|
|
|
43
43
|
return this.clamp(value, 0, 1);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Linear interpolate
|
|
48
|
+
*/
|
|
46
49
|
lerp(value1: number, value2: number, t: number) {
|
|
47
50
|
t = t < 0 ? 0 : t;
|
|
48
51
|
t = t > 1 ? 1 : t;
|
|
49
52
|
return value1 + (value2 - value1) * t;
|
|
50
53
|
}
|
|
51
54
|
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
52
58
|
inverseLerp(value1: number, value2: number, t: number) {
|
|
53
59
|
return (t - value1) / (value2 - value1);
|
|
54
60
|
}
|
|
55
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Remaps a value from one range to another.
|
|
64
|
+
* @param value The value to remap.
|
|
65
|
+
* @param min1 The minimum value of the current range.
|
|
66
|
+
* @param max1 The maximum value of the current range.
|
|
67
|
+
* @param min2 The minimum value of the target range.
|
|
68
|
+
* @param max2 The maximum value of the target range.
|
|
69
|
+
*/
|
|
56
70
|
remap(value: number, min1: number, max1: number, min2: number, max2: number) {
|
|
57
71
|
return min2 + (max2 - min2) * (value - min1) / (max1 - min1);
|
|
58
72
|
}
|
|
@@ -64,20 +78,24 @@ class MathHelper {
|
|
|
64
78
|
return value1;
|
|
65
79
|
}
|
|
66
80
|
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
readonly Rad2Deg = 180 / Math.PI;
|
|
84
|
+
readonly Deg2Rad = Math.PI / 180;
|
|
85
|
+
readonly Epsilon = 0.00001;
|
|
86
|
+
/**
|
|
87
|
+
* Converts radians to degrees
|
|
88
|
+
*/
|
|
67
89
|
toDegrees(radians: number) {
|
|
68
90
|
return radians * 180 / Math.PI;
|
|
69
91
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Converts degrees to radians
|
|
94
|
+
*/
|
|
73
95
|
toRadians(degrees: number) {
|
|
74
96
|
return degrees * Math.PI / 180;
|
|
75
97
|
}
|
|
76
98
|
|
|
77
|
-
readonly Deg2Rad = Math.PI / 180;
|
|
78
|
-
|
|
79
|
-
readonly Epsilon = 0.00001;
|
|
80
|
-
|
|
81
99
|
tan(radians: number) {
|
|
82
100
|
return Math.tan(radians);
|
|
83
101
|
}
|
|
@@ -398,7 +398,7 @@ export class Graphics {
|
|
|
398
398
|
gl_FragColor = texture2D( map, uv);
|
|
399
399
|
// gl_FragColor = vec4(uv.xy, 0, 1);
|
|
400
400
|
}`;
|
|
401
|
-
private static
|
|
401
|
+
private static blitMaterial: ShaderMaterial | undefined = undefined;
|
|
402
402
|
|
|
403
403
|
/**
|
|
404
404
|
* Create a blit material for copying textures
|
|
@@ -419,27 +419,28 @@ export class Graphics {
|
|
|
419
419
|
* @returns the newly created, copied texture
|
|
420
420
|
*/
|
|
421
421
|
static copyTexture(texture: Texture, blitMaterial?: ShaderMaterial): Texture {
|
|
422
|
-
const material = blitMaterial ?? this.blipMaterial!;
|
|
423
|
-
|
|
424
|
-
material.uniforms.map.value = texture;
|
|
425
|
-
material.needsUpdate = true;
|
|
426
|
-
material.uniformsNeedUpdate = true;
|
|
427
|
-
|
|
428
422
|
// ensure that a blit material exists
|
|
429
|
-
if (!this.
|
|
430
|
-
this.
|
|
423
|
+
if (!this.blitMaterial) {
|
|
424
|
+
this.blitMaterial = new ShaderMaterial({
|
|
431
425
|
uniforms: { map: new Uniform(null) },
|
|
432
426
|
vertexShader: this.vertex,
|
|
433
427
|
fragmentShader: this.fragment
|
|
434
428
|
});
|
|
435
429
|
}
|
|
436
430
|
|
|
431
|
+
const material = blitMaterial || this.blitMaterial;
|
|
432
|
+
|
|
433
|
+
material.uniforms.map.value = texture;
|
|
434
|
+
material.needsUpdate = true;
|
|
435
|
+
material.uniformsNeedUpdate = true;
|
|
436
|
+
|
|
437
|
+
|
|
437
438
|
// ensure that the blit material has the correct vertex shader
|
|
438
439
|
const origVertexShader = material.vertexShader;
|
|
439
440
|
material.vertexShader = this.vertex;
|
|
440
441
|
|
|
441
442
|
if (!this.mesh)
|
|
442
|
-
this.mesh = new Mesh(this.planeGeometry, this.
|
|
443
|
+
this.mesh = new Mesh(this.planeGeometry, this.blitMaterial);
|
|
443
444
|
const mesh = this.mesh;
|
|
444
445
|
mesh.material = material;
|
|
445
446
|
mesh.frustumCulled = false;
|
|
@@ -474,15 +475,22 @@ export class Graphics {
|
|
|
474
475
|
// return new Texture(this.renderer.domElement);
|
|
475
476
|
// }
|
|
476
477
|
|
|
477
|
-
|
|
478
|
-
|
|
478
|
+
/**
|
|
479
|
+
* Copy a texture to a HTMLCanvasElement
|
|
480
|
+
* @param texture the texture convert
|
|
481
|
+
* @param force if true the texture will be copied to a new texture before converting
|
|
482
|
+
* @returns the HTMLCanvasElement with the texture or null if the texture could not be copied
|
|
483
|
+
*/
|
|
484
|
+
static textureToCanvas(texture: Texture, force: boolean = false): HTMLCanvasElement | null {
|
|
485
|
+
if (!texture) {
|
|
486
|
+
return null;
|
|
487
|
+
}
|
|
479
488
|
|
|
480
489
|
if (force === true || texture["isCompressedTexture"] === true) {
|
|
481
490
|
texture = copyTexture(texture);
|
|
482
491
|
}
|
|
483
492
|
const image = texture.image;
|
|
484
493
|
if (isImageBitmap(image)) {
|
|
485
|
-
|
|
486
494
|
const canvas = document.createElement('canvas');
|
|
487
495
|
canvas.width = image.width;
|
|
488
496
|
canvas.height = image.height;
|
|
@@ -494,8 +502,8 @@ export class Graphics {
|
|
|
494
502
|
}
|
|
495
503
|
context.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
|
|
496
504
|
return canvas;
|
|
497
|
-
|
|
498
505
|
}
|
|
506
|
+
|
|
499
507
|
return null;
|
|
500
508
|
}
|
|
501
509
|
}
|
|
@@ -10,6 +10,7 @@ import { onAfterRender } from "./engine_lifecycle_api.js";
|
|
|
10
10
|
import { registerFrameEventCallback } from "./engine_lifecycle_functions_internal.js";
|
|
11
11
|
import { Context, FrameEvent } from "./engine_setup.js";
|
|
12
12
|
import { ICamera } from "./engine_types.js";
|
|
13
|
+
import { DeviceUtilities } from "./engine_utils.js";
|
|
13
14
|
import { updateTextureFromXRFrame } from "./engine_utils_screenshot.xr.js";
|
|
14
15
|
import { RGBAColor } from "./js-extensions/index.js";
|
|
15
16
|
import { setCustomVisibility } from "./js-extensions/Layers.js";
|
|
@@ -395,8 +396,22 @@ export function screenshot2(opts: ScreenshotOptionsDataUrl | ScreenshotOptionsTe
|
|
|
395
396
|
|
|
396
397
|
if ("download_filename" in opts && opts.download_filename) {
|
|
397
398
|
let download_name = opts.download_filename;
|
|
398
|
-
|
|
399
|
-
|
|
399
|
+
// On mobile we don't want to see the dialogue for every screenshot
|
|
400
|
+
if (DeviceUtilities.isMobileDevice() && typeof window !== "undefined") {
|
|
401
|
+
const key = download_name + "_screenshots";
|
|
402
|
+
const parts = download_name.split(".");
|
|
403
|
+
const ext = parts.pop()?.toLowerCase();
|
|
404
|
+
let count = 0;
|
|
405
|
+
if (localStorage.getItem(key)) {
|
|
406
|
+
count = parseInt(sessionStorage.getItem(key) || "0");
|
|
407
|
+
}
|
|
408
|
+
if (count > 0) {
|
|
409
|
+
// const timestamp = new Date().toLocaleString();
|
|
410
|
+
download_name = `${parts.join()}-${count}.${ext}`;
|
|
411
|
+
}
|
|
412
|
+
count += 1;
|
|
413
|
+
sessionStorage.setItem(key, count.toString());
|
|
414
|
+
}
|
|
400
415
|
saveImage(dataUrl, download_name);
|
|
401
416
|
}
|
|
402
417
|
return dataUrl;
|
|
@@ -424,7 +439,6 @@ export function screenshot2(opts: ScreenshotOptionsDataUrl | ScreenshotOptionsTe
|
|
|
424
439
|
|
|
425
440
|
|
|
426
441
|
|
|
427
|
-
|
|
428
442
|
// trim to transparent pixels
|
|
429
443
|
function trimCanvas(originalCanvas: HTMLCanvasElement): HTMLCanvasElement | null {
|
|
430
444
|
if (!("document" in globalThis)) return null;
|
|
@@ -3,6 +3,7 @@ import { PositionalAudioHelper } from 'three/examples/jsm/helpers/PositionalAudi
|
|
|
3
3
|
|
|
4
4
|
import { isDevEnvironment } from "../engine/debug/index.js";
|
|
5
5
|
import { Application, ApplicationEvents } from "../engine/engine_application.js";
|
|
6
|
+
import { findObjectOfType } from "../engine/engine_components.js";
|
|
6
7
|
import { Mathf } from "../engine/engine_math.js";
|
|
7
8
|
import { serializable } from "../engine/engine_serialization_decorator.js";
|
|
8
9
|
import { DeviceUtilities, getParam } from "../engine/engine_utils.js";
|
|
@@ -21,13 +22,13 @@ export enum AudioRolloffMode {
|
|
|
21
22
|
* exponentially with distance.
|
|
22
23
|
*/
|
|
23
24
|
Logarithmic = 0,
|
|
24
|
-
|
|
25
|
+
|
|
25
26
|
/**
|
|
26
27
|
* Linear rolloff provides a straightforward volume reduction that decreases at a constant
|
|
27
28
|
* rate with distance.
|
|
28
29
|
*/
|
|
29
30
|
Linear = 1,
|
|
30
|
-
|
|
31
|
+
|
|
31
32
|
/**
|
|
32
33
|
* Custom rolloff allows for defining specialized distance-based attenuation curves.
|
|
33
34
|
* Note: Custom rolloff is not fully implemented in this version.
|
|
@@ -123,7 +124,7 @@ export class AudioSource extends Behaviour {
|
|
|
123
124
|
get duration() {
|
|
124
125
|
return this.sound?.buffer?.duration;
|
|
125
126
|
}
|
|
126
|
-
|
|
127
|
+
|
|
127
128
|
/**
|
|
128
129
|
* The current playback position as a normalized value between 0 and 1.
|
|
129
130
|
* Can be set to seek to a specific position in the audio.
|
|
@@ -172,7 +173,7 @@ export class AudioSource extends Behaviour {
|
|
|
172
173
|
this._loop = val;
|
|
173
174
|
if (this.sound) this.sound.setLoop(val);
|
|
174
175
|
}
|
|
175
|
-
|
|
176
|
+
|
|
176
177
|
/**
|
|
177
178
|
* Controls how the audio is positioned in space.
|
|
178
179
|
* Values range from 0 (2D, non-positional) to 1 (fully 3D positioned).
|
|
@@ -187,7 +188,7 @@ export class AudioSource extends Behaviour {
|
|
|
187
188
|
this._spatialBlend = val;
|
|
188
189
|
this._needUpdateSpatialDistanceSettings = true;
|
|
189
190
|
}
|
|
190
|
-
|
|
191
|
+
|
|
191
192
|
/**
|
|
192
193
|
* The minimum distance from the audio source at which the volume starts to attenuate.
|
|
193
194
|
* Within this radius, the audio plays at full volume regardless of distance.
|
|
@@ -201,7 +202,7 @@ export class AudioSource extends Behaviour {
|
|
|
201
202
|
this._minDistance = val;
|
|
202
203
|
this._needUpdateSpatialDistanceSettings = true;
|
|
203
204
|
}
|
|
204
|
-
|
|
205
|
+
|
|
205
206
|
/**
|
|
206
207
|
* The maximum distance from the audio source beyond which the volume no longer decreases.
|
|
207
208
|
* This defines the outer limit of the attenuation curve.
|
|
@@ -278,8 +279,13 @@ export class AudioSource extends Behaviour {
|
|
|
278
279
|
*/
|
|
279
280
|
public get Sound(): PositionalAudio | null {
|
|
280
281
|
if (!this.sound && AudioSource.userInteractionRegistered) {
|
|
281
|
-
|
|
282
|
-
|
|
282
|
+
// Get or create an audiolistener in the scene
|
|
283
|
+
let listener = this.gameObject.getComponent(AudioListener) // AudioListener on AudioSource?
|
|
284
|
+
?? this.context.mainCamera.getComponent(AudioListener) // AudioListener on current main camera?
|
|
285
|
+
?? findObjectOfType(AudioListener, this.context, false); // Active AudioListener in scene?
|
|
286
|
+
|
|
287
|
+
if (!listener && this.context.mainCamera) listener = this.context.mainCamera.addComponent(AudioListener);
|
|
288
|
+
|
|
283
289
|
if (listener?.listener) {
|
|
284
290
|
this.sound = new PositionalAudio(listener.listener);
|
|
285
291
|
this.gameObject?.add(this.sound);
|
|
@@ -426,6 +432,9 @@ export class AudioSource extends Behaviour {
|
|
|
426
432
|
if (sound.isPlaying)
|
|
427
433
|
sound.stop();
|
|
428
434
|
|
|
435
|
+
// const panner = sound.panner;
|
|
436
|
+
// panner.coneOuterGain = 1;
|
|
437
|
+
// sound.setDirectionalCone(360, 360, 1);
|
|
429
438
|
// const src = sound.context.createBufferSource();
|
|
430
439
|
// src.buffer = sound.buffer;
|
|
431
440
|
// src.connect(sound.panner);
|
|
@@ -498,7 +498,9 @@ export class Rigidbody extends Behaviour implements IRigidbody {
|
|
|
498
498
|
else this.setAngularVelocity(x);
|
|
499
499
|
}
|
|
500
500
|
|
|
501
|
-
/**
|
|
501
|
+
/**
|
|
502
|
+
* Returns the rigidbody velocity smoothed over ~ 10 frames
|
|
503
|
+
*/
|
|
502
504
|
public get smoothedVelocity(): Vector3 {
|
|
503
505
|
this._smoothedVelocityGetter.copy(this._smoothedVelocity);
|
|
504
506
|
return this._smoothedVelocityGetter.multiplyScalar(1 / this.context.time.deltaTime);
|
|
@@ -512,9 +514,9 @@ export class Rigidbody extends Behaviour implements IRigidbody {
|
|
|
512
514
|
|
|
513
515
|
|
|
514
516
|
private captureVelocity() {
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
const vel =
|
|
517
|
+
const matrixWorld = this.gameObject.matrixWorld;
|
|
518
|
+
Rigidbody.tempPosition.setFromMatrixPosition(matrixWorld);
|
|
519
|
+
const vel = Rigidbody.tempPosition.sub(this._lastPosition);
|
|
518
520
|
this._lastPosition.copy(Rigidbody.tempPosition);
|
|
519
521
|
this._smoothedVelocity.lerp(vel, this.context.time.deltaTime / .1);
|
|
520
522
|
}
|
|
@@ -155,7 +155,11 @@ const $spriteTexOwner = Symbol("spriteOwner");
|
|
|
155
155
|
export class SpriteSheet {
|
|
156
156
|
|
|
157
157
|
@serializable(Sprite)
|
|
158
|
-
sprites
|
|
158
|
+
sprites: Sprite[];
|
|
159
|
+
|
|
160
|
+
constructor() {
|
|
161
|
+
this.sprites = [];
|
|
162
|
+
}
|
|
159
163
|
}
|
|
160
164
|
|
|
161
165
|
export class SpriteData {
|
|
@@ -171,6 +175,13 @@ export class SpriteData {
|
|
|
171
175
|
// hence the spriteSheet field is undefined by default
|
|
172
176
|
constructor() { }
|
|
173
177
|
|
|
178
|
+
clone() {
|
|
179
|
+
const i = new SpriteData();
|
|
180
|
+
i.index = this.index;
|
|
181
|
+
i.spriteSheet = this.spriteSheet;
|
|
182
|
+
return i;
|
|
183
|
+
}
|
|
184
|
+
|
|
174
185
|
/**
|
|
175
186
|
* Set the sprite to be rendered in the currently assigned sprite sheet at the currently active index {@link index}
|
|
176
187
|
*/
|
|
@@ -320,7 +331,6 @@ export class SpriteRenderer extends Behaviour {
|
|
|
320
331
|
if (typeof value === "number") {
|
|
321
332
|
const index = Math.floor(value);
|
|
322
333
|
this.spriteIndex = index;
|
|
323
|
-
return;
|
|
324
334
|
}
|
|
325
335
|
else if (value instanceof Sprite) {
|
|
326
336
|
if (!this._spriteSheet) {
|
|
@@ -328,8 +338,8 @@ export class SpriteRenderer extends Behaviour {
|
|
|
328
338
|
}
|
|
329
339
|
if (this._spriteSheet.sprite != value) {
|
|
330
340
|
this._spriteSheet.sprite = value;
|
|
331
|
-
this.updateSprite();
|
|
332
341
|
}
|
|
342
|
+
this.updateSprite();
|
|
333
343
|
}
|
|
334
344
|
else if (value != this._spriteSheet) {
|
|
335
345
|
this._spriteSheet = value;
|
|
@@ -342,7 +352,6 @@ export class SpriteRenderer extends Behaviour {
|
|
|
342
352
|
*/
|
|
343
353
|
set spriteIndex(value: number) {
|
|
344
354
|
if (!this._spriteSheet) return;
|
|
345
|
-
if (value === this.spriteIndex) return;
|
|
346
355
|
this._spriteSheet.index = value;
|
|
347
356
|
this.updateSprite();
|
|
348
357
|
}
|
|
@@ -359,13 +368,19 @@ export class SpriteRenderer extends Behaviour {
|
|
|
359
368
|
private _spriteSheet?: SpriteData;
|
|
360
369
|
private _currentSprite?: Mesh;
|
|
361
370
|
|
|
371
|
+
|
|
362
372
|
/** @internal */
|
|
363
373
|
awake(): void {
|
|
364
374
|
this._currentSprite = undefined;
|
|
375
|
+
|
|
365
376
|
if (!this._spriteSheet) {
|
|
366
|
-
this._spriteSheet =
|
|
367
|
-
this._spriteSheet.spriteSheet = new SpriteSheet();
|
|
377
|
+
this._spriteSheet = SpriteData.create();
|
|
368
378
|
}
|
|
379
|
+
else {
|
|
380
|
+
// Ensure each SpriteRenderer has a unique spritesheet instance for cases where sprite renderer are cloned at runtime and then different sprites are assigned to each instance
|
|
381
|
+
this._spriteSheet = this._spriteSheet.clone();
|
|
382
|
+
}
|
|
383
|
+
|
|
369
384
|
if (debug) {
|
|
370
385
|
console.log("Awake", this.name, this, this.sprite);
|
|
371
386
|
}
|
|
@@ -408,6 +423,7 @@ export class SpriteRenderer extends Behaviour {
|
|
|
408
423
|
}
|
|
409
424
|
mat.transparent = true;
|
|
410
425
|
mat.toneMapped = this.toneMapped;
|
|
426
|
+
mat.depthWrite = false;
|
|
411
427
|
|
|
412
428
|
if (sprite.texture && !mat.wireframe) {
|
|
413
429
|
let tex = sprite.texture;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { N8AOPostPass } from "n8ao";
|
|
2
|
-
import { Color, PerspectiveCamera } from "three";
|
|
2
|
+
import { Color, DepthFormat, DepthStencilFormat, DepthTexture, PerspectiveCamera, UnsignedInt248Type, UnsignedIntType, WebGLRenderTarget } from "three";
|
|
3
3
|
|
|
4
4
|
import { MODULES } from "../../../engine/engine_modules.js";
|
|
5
5
|
import { serializable } from "../../../engine/engine_serialization.js";
|
|
6
6
|
import { validate } from "../../../engine/engine_util_decorator.js";
|
|
7
|
+
import { getParam } from "../../../engine/engine_utils.js";
|
|
7
8
|
import { type EffectProviderResult, PostProcessingEffect } from "../PostProcessingEffect.js";
|
|
8
9
|
import { VolumeParameter } from "../VolumeParameter.js";
|
|
9
10
|
import { registerCustomEffectType } from "../VolumeProfile.js";
|
|
10
11
|
|
|
12
|
+
const debugN8AO = getParam("debugN8AO");
|
|
13
|
+
|
|
11
14
|
// https://github.com/N8python/n8ao
|
|
12
15
|
|
|
13
16
|
/**See (N8AO documentation)[https://github.com/N8python/n8ao] */
|
|
@@ -30,6 +33,10 @@ export class ScreenSpaceAmbientOcclusionN8 extends PostProcessingEffect {
|
|
|
30
33
|
return "ScreenSpaceAmbientOcclusionN8";
|
|
31
34
|
}
|
|
32
35
|
|
|
36
|
+
get pass(): N8AOPostPass {
|
|
37
|
+
return this._ssao;
|
|
38
|
+
}
|
|
39
|
+
|
|
33
40
|
@validate()
|
|
34
41
|
@serializable()
|
|
35
42
|
gammaCorrection: boolean = true;
|
|
@@ -109,19 +116,51 @@ export class ScreenSpaceAmbientOcclusionN8 extends PostProcessingEffect {
|
|
|
109
116
|
|
|
110
117
|
const cam = this.context.mainCamera! as PerspectiveCamera;
|
|
111
118
|
|
|
119
|
+
const width = this.context.domWidth;
|
|
120
|
+
const height = this.context.domHeight;
|
|
121
|
+
|
|
112
122
|
const ssao = this._ssao = new MODULES.POSTPROCESSING_AO.MODULE.N8AOPostPass(
|
|
113
123
|
this.context.scene,
|
|
114
124
|
cam,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
125
|
+
width, height
|
|
126
|
+
) as N8AOPostPass;
|
|
127
|
+
|
|
118
128
|
const mode = ScreenSpaceAmbientOcclusionN8QualityMode[this.quality];
|
|
119
129
|
ssao.setQualityMode(mode);
|
|
120
130
|
|
|
121
|
-
ssao.configuration.
|
|
131
|
+
ssao.configuration.transparencyAware = false;
|
|
132
|
+
// ssao.needsSwap = false;
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
const renderTarget = new WebGLRenderTarget(width, height);
|
|
136
|
+
ssao.configuration.beautyRenderTarget = renderTarget;
|
|
137
|
+
ssao.configuration.autoRenderBeauty = false;
|
|
138
|
+
// // If you just want a depth buffer
|
|
139
|
+
// renderTarget.depthTexture = new DepthTexture(width, height, UnsignedIntType);
|
|
140
|
+
// renderTarget.depthTexture.format = DepthFormat;
|
|
141
|
+
// // If you want a depth buffer and a stencil buffer
|
|
142
|
+
// renderTarget.depthTexture = new DepthTexture(width, height, UnsignedInt248Type);
|
|
143
|
+
// renderTarget.depthTexture.format = DepthStencilFormat;
|
|
122
144
|
|
|
145
|
+
|
|
146
|
+
ssao.configuration.gammaCorrection = this.gammaCorrection;
|
|
123
147
|
ssao.configuration.screenSpaceRadius = this.screenspaceRadius;
|
|
124
148
|
|
|
149
|
+
|
|
150
|
+
if (debugN8AO) {
|
|
151
|
+
// ssao.debug = debugN8AO;
|
|
152
|
+
ssao.enableDebugMode();
|
|
153
|
+
console.log(ssao);
|
|
154
|
+
setInterval(() => {
|
|
155
|
+
console.log("SSAO", ssao.lastTime);
|
|
156
|
+
}, 1000);
|
|
157
|
+
setInterval(() => {
|
|
158
|
+
// ssao.enabled = !ssao.enabled;
|
|
159
|
+
console.log("SSAO", ssao.enabled, { ssao, autoRenderBeauty: ssao.configuration.autoRenderBeauty });
|
|
160
|
+
}, 4000)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
125
164
|
this.intensity.onValueChanged = newValue => {
|
|
126
165
|
ssao.configuration.intensity = newValue;
|
|
127
166
|
}
|
|
@@ -135,10 +174,18 @@ export class ScreenSpaceAmbientOcclusionN8 extends PostProcessingEffect {
|
|
|
135
174
|
if (!ssao.color) ssao.color = new Color();
|
|
136
175
|
ssao.configuration.color.copy(newValue);
|
|
137
176
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
// const normalPass = new MODULES.POSTPROCESSING.MODULE.NormalPass(this.context.scene, cam);
|
|
180
|
+
// const depthDownsamplingPass = new MODULES.POSTPROCESSING.MODULE.DepthDownsamplingPass({
|
|
181
|
+
// normalBuffer: normalPass.texture,
|
|
182
|
+
// resolutionScale: .1
|
|
183
|
+
// });
|
|
184
|
+
// const arr = new Array();
|
|
185
|
+
// arr.push(normalPass);
|
|
186
|
+
// arr.push(depthDownsamplingPass);
|
|
187
|
+
// arr.push(ssao);
|
|
188
|
+
return ssao;
|
|
142
189
|
}
|
|
143
190
|
|
|
144
191
|
}
|