babylon.quarks 0.17.4 → 0.17.7

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.
Files changed (78) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/LICENSE +21 -21
  3. package/README.md +169 -33
  4. package/dist/babylon.quarks.cjs +1 -1
  5. package/dist/babylon.quarks.cjs.map +1 -1
  6. package/dist/babylon.quarks.esm.js +1 -1
  7. package/dist/babylon.quarks.esm.js.map +1 -1
  8. package/dist/babylon.quarks.umd.min.js +2 -0
  9. package/dist/babylon.quarks.umd.min.js.map +1 -0
  10. package/dist/types/index.d.ts +2829 -19
  11. package/package.json +62 -60
  12. package/src/BatchedParticleRenderer.ts +3 -3
  13. package/src/BatchedRenderer.ts +228 -227
  14. package/src/MeshSurfaceEmitter.ts +137 -137
  15. package/src/ParticleEmitter.ts +86 -86
  16. package/src/ParticleSystem.ts +1322 -1285
  17. package/src/QuarksLoader.ts +529 -510
  18. package/src/QuarksPrefab.ts +307 -307
  19. package/src/QuarksUtil.ts +66 -66
  20. package/src/SpriteBatch.ts +403 -404
  21. package/src/TrailBatch.ts +420 -419
  22. package/src/VFXBatch.ts +108 -108
  23. package/src/geometryUtil.ts +15 -15
  24. package/src/index.ts +59 -52
  25. package/src/materials/ParticleMaterials.ts +23 -23
  26. package/src/materials/index.ts +1 -1
  27. package/src/shaders/chunks/index.ts +1 -1
  28. package/src/shaders/chunks/register-shader-chunks.ts +32 -32
  29. package/src/shaders/chunks/soft_fragment.glsl.ts +13 -13
  30. package/src/shaders/chunks/soft_pars_fragment.glsl.ts +20 -20
  31. package/src/shaders/chunks/soft_pars_vertex.glsl.ts +6 -6
  32. package/src/shaders/chunks/soft_vertex.glsl.ts +6 -6
  33. package/src/shaders/chunks/tile_fragment.glsl.ts +9 -9
  34. package/src/shaders/chunks/tile_pars_fragment.glsl.ts +9 -9
  35. package/src/shaders/chunks/tile_pars_vertex.glsl.ts +28 -28
  36. package/src/shaders/chunks/tile_vertex.glsl.ts +18 -18
  37. package/src/shaders/index.ts +9 -9
  38. package/src/shaders/local_particle_physics_vert.glsl.ts +79 -79
  39. package/src/shaders/local_particle_vert.glsl.ts +50 -50
  40. package/src/shaders/particle_frag.glsl.ts +61 -61
  41. package/src/shaders/particle_physics_frag.glsl.ts +67 -67
  42. package/src/shaders/particle_vert.glsl.ts +85 -85
  43. package/src/shaders/stretched_bb_particle_vert.glsl.ts +76 -74
  44. package/src/shaders/trail_frag.glsl.ts +21 -21
  45. package/src/shaders/trail_vert.glsl.ts +58 -58
  46. package/dist/types/BatchedParticleRenderer.d.ts +0 -2
  47. package/dist/types/BatchedRenderer.d.ts +0 -59
  48. package/dist/types/MeshSurfaceEmitter.d.ts +0 -19
  49. package/dist/types/ParticleEmitter.d.ts +0 -16
  50. package/dist/types/ParticleSystem.d.ts +0 -234
  51. package/dist/types/QuarksLoader.d.ts +0 -28
  52. package/dist/types/QuarksPrefab.d.ts +0 -48
  53. package/dist/types/QuarksUtil.d.ts +0 -14
  54. package/dist/types/SpriteBatch.d.ts +0 -33
  55. package/dist/types/TrailBatch.d.ts +0 -28
  56. package/dist/types/VFXBatch.d.ts +0 -51
  57. package/dist/types/geometryUtil.d.ts +0 -2
  58. package/dist/types/materials/ParticleMaterials.d.ts +0 -12
  59. package/dist/types/materials/index.d.ts +0 -1
  60. package/dist/types/shaders/chunks/index.d.ts +0 -1
  61. package/dist/types/shaders/chunks/register-shader-chunks.d.ts +0 -3
  62. package/dist/types/shaders/chunks/soft_fragment.glsl.d.ts +0 -2
  63. package/dist/types/shaders/chunks/soft_pars_fragment.glsl.d.ts +0 -2
  64. package/dist/types/shaders/chunks/soft_pars_vertex.glsl.d.ts +0 -2
  65. package/dist/types/shaders/chunks/soft_vertex.glsl.d.ts +0 -2
  66. package/dist/types/shaders/chunks/tile_fragment.glsl.d.ts +0 -2
  67. package/dist/types/shaders/chunks/tile_pars_fragment.glsl.d.ts +0 -2
  68. package/dist/types/shaders/chunks/tile_pars_vertex.glsl.d.ts +0 -2
  69. package/dist/types/shaders/chunks/tile_vertex.glsl.d.ts +0 -2
  70. package/dist/types/shaders/index.d.ts +0 -9
  71. package/dist/types/shaders/local_particle_physics_vert.glsl.d.ts +0 -2
  72. package/dist/types/shaders/local_particle_vert.glsl.d.ts +0 -2
  73. package/dist/types/shaders/particle_frag.glsl.d.ts +0 -2
  74. package/dist/types/shaders/particle_physics_frag.glsl.d.ts +0 -2
  75. package/dist/types/shaders/particle_vert.glsl.d.ts +0 -2
  76. package/dist/types/shaders/stretched_bb_particle_vert.glsl.d.ts +0 -2
  77. package/dist/types/shaders/trail_frag.glsl.d.ts +0 -2
  78. package/dist/types/shaders/trail_vert.glsl.d.ts +0 -2
@@ -1,137 +1,137 @@
1
- import {Mesh} from '@babylonjs/core/Meshes/mesh';
2
- import {VertexBuffer} from '@babylonjs/core/Buffers/buffer';
3
- import {
4
- Particle,
5
- EmitterShape,
6
- ShapeJSON,
7
- IParticleSystem,
8
- Vector3,
9
- Plugin,
10
- } from 'quarks.core';
11
-
12
- export class MeshSurfaceEmitter implements EmitterShape {
13
- type = 'mesh_surface';
14
-
15
- private _triangleIndexToArea: number[] = [];
16
- private _mesh?: Mesh;
17
- private _positions?: Float32Array;
18
- private _indices?: Uint32Array | Int32Array;
19
- private _meshReferenceId?: string;
20
-
21
- get mesh() {
22
- return this._mesh;
23
- }
24
-
25
- set mesh(mesh: Mesh | undefined) {
26
- this._mesh = mesh;
27
- if (!mesh) return;
28
-
29
- const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
30
- const indices = mesh.getIndices();
31
- if (!positions || !indices) return;
32
-
33
- this._positions = new Float32Array(positions);
34
- this._indices = new Int32Array(indices);
35
-
36
- this._triangleIndexToArea.length = 0;
37
- let area = 0;
38
- const triCount = indices.length / 3;
39
- this._triangleIndexToArea.push(0);
40
-
41
- const a = new Vector3();
42
- const b = new Vector3();
43
- const c = new Vector3();
44
-
45
- for (let i = 0; i < triCount; i++) {
46
- const i0 = indices[i * 3];
47
- const i1 = indices[i * 3 + 1];
48
- const i2 = indices[i * 3 + 2];
49
-
50
- a.set(positions[i0 * 3], positions[i0 * 3 + 1], positions[i0 * 3 + 2]);
51
- b.set(positions[i1 * 3], positions[i1 * 3 + 1], positions[i1 * 3 + 2]);
52
- c.set(positions[i2 * 3], positions[i2 * 3 + 1], positions[i2 * 3 + 2]);
53
-
54
- b.sub(a);
55
- c.sub(a);
56
- const cross = new Vector3();
57
- cross.crossVectors(b, c);
58
- area += cross.length() * 0.5;
59
- this._triangleIndexToArea.push(area);
60
- }
61
- }
62
-
63
- constructor(mesh?: Mesh, meshReferenceId?: string) {
64
- this._meshReferenceId = meshReferenceId;
65
- if (mesh) this.mesh = mesh;
66
- }
67
-
68
- initialize(p: Particle) {
69
- if (!this._positions || !this._indices) {
70
- p.position.set(0, 0, 0);
71
- p.velocity.set(0, 0, 1).multiplyScalar(p.startSpeed);
72
- return;
73
- }
74
-
75
- const triCount = this._triangleIndexToArea.length - 1;
76
- let left = 0, right = triCount;
77
- const target = Math.random() * this._triangleIndexToArea[triCount];
78
-
79
- while (left + 1 < right) {
80
- const mid = Math.floor((left + right) / 2);
81
- if (target < this._triangleIndexToArea[mid]) {
82
- right = mid;
83
- } else {
84
- left = mid;
85
- }
86
- }
87
-
88
- let u1 = Math.random();
89
- let u2 = Math.random();
90
- if (u1 + u2 > 1) {
91
- u1 = 1 - u1;
92
- u2 = 1 - u2;
93
- }
94
-
95
- const idx0 = this._indices[left * 3];
96
- const idx1 = this._indices[left * 3 + 1];
97
- const idx2 = this._indices[left * 3 + 2];
98
-
99
- const ax = this._positions[idx0 * 3], ay = this._positions[idx0 * 3 + 1], az = this._positions[idx0 * 3 + 2];
100
- const bx = this._positions[idx1 * 3] - ax, by = this._positions[idx1 * 3 + 1] - ay, bz = this._positions[idx1 * 3 + 2] - az;
101
- const cx = this._positions[idx2 * 3] - ax, cy = this._positions[idx2 * 3 + 1] - ay, cz = this._positions[idx2 * 3 + 2] - az;
102
-
103
- p.position.set(ax + bx * u1 + cx * u2, ay + by * u1 + cy * u2, az + bz * u1 + cz * u2);
104
-
105
- const nx = by * cz - bz * cy;
106
- const ny = bz * cx - bx * cz;
107
- const nz = bx * cy - by * cx;
108
- const len = Math.sqrt(nx * nx + ny * ny + nz * nz) || 1;
109
- p.velocity.set(nx / len, ny / len, nz / len).multiplyScalar(p.startSpeed);
110
- }
111
-
112
- toJSON(): ShapeJSON {
113
- return {type: 'mesh_surface', mesh: this._mesh ? (this._mesh as any).uniqueId?.toString() : this._meshReferenceId ?? ''};
114
- }
115
-
116
- static fromJSON(json: any): MeshSurfaceEmitter {
117
- return new MeshSurfaceEmitter(undefined, json?.mesh);
118
- }
119
-
120
- clone(): EmitterShape {
121
- return new MeshSurfaceEmitter(this._mesh, this._meshReferenceId);
122
- }
123
-
124
- update(_system: IParticleSystem, _delta: number): void {}
125
- }
126
-
127
- export const MeshSurfaceEmitterPlugin: Plugin = {
128
- id: 'babylon.quarks',
129
- initialize: () => {},
130
- emitterShapes: [{
131
- type: 'mesh_surface',
132
- params: [['mesh', ['mesh']]],
133
- constructor: MeshSurfaceEmitter,
134
- loadJSON: (json: any) => MeshSurfaceEmitter.fromJSON(json),
135
- }],
136
- behaviors: [],
137
- };
1
+ import {Mesh} from '@babylonjs/core/Meshes/mesh';
2
+ import {VertexBuffer} from '@babylonjs/core/Buffers/buffer';
3
+ import {
4
+ Particle,
5
+ EmitterShape,
6
+ ShapeJSON,
7
+ IParticleSystem,
8
+ Vector3,
9
+ Plugin,
10
+ } from 'quarks.core';
11
+
12
+ export class MeshSurfaceEmitter implements EmitterShape {
13
+ type = 'mesh_surface';
14
+
15
+ private _triangleIndexToArea: number[] = [];
16
+ private _mesh?: Mesh;
17
+ private _positions?: Float32Array;
18
+ private _indices?: Uint32Array | Int32Array;
19
+ private _meshReferenceId?: string;
20
+
21
+ get mesh() {
22
+ return this._mesh;
23
+ }
24
+
25
+ set mesh(mesh: Mesh | undefined) {
26
+ this._mesh = mesh;
27
+ if (!mesh) return;
28
+
29
+ const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
30
+ const indices = mesh.getIndices();
31
+ if (!positions || !indices) return;
32
+
33
+ this._positions = new Float32Array(positions);
34
+ this._indices = new Int32Array(indices);
35
+
36
+ this._triangleIndexToArea.length = 0;
37
+ let area = 0;
38
+ const triCount = indices.length / 3;
39
+ this._triangleIndexToArea.push(0);
40
+
41
+ const a = new Vector3();
42
+ const b = new Vector3();
43
+ const c = new Vector3();
44
+
45
+ for (let i = 0; i < triCount; i++) {
46
+ const i0 = indices[i * 3];
47
+ const i1 = indices[i * 3 + 1];
48
+ const i2 = indices[i * 3 + 2];
49
+
50
+ a.set(positions[i0 * 3], positions[i0 * 3 + 1], positions[i0 * 3 + 2]);
51
+ b.set(positions[i1 * 3], positions[i1 * 3 + 1], positions[i1 * 3 + 2]);
52
+ c.set(positions[i2 * 3], positions[i2 * 3 + 1], positions[i2 * 3 + 2]);
53
+
54
+ b.sub(a);
55
+ c.sub(a);
56
+ const cross = new Vector3();
57
+ cross.crossVectors(b, c);
58
+ area += cross.length() * 0.5;
59
+ this._triangleIndexToArea.push(area);
60
+ }
61
+ }
62
+
63
+ constructor(mesh?: Mesh, meshReferenceId?: string) {
64
+ this._meshReferenceId = meshReferenceId;
65
+ if (mesh) this.mesh = mesh;
66
+ }
67
+
68
+ initialize(p: Particle) {
69
+ if (!this._positions || !this._indices) {
70
+ p.position.set(0, 0, 0);
71
+ p.velocity.set(0, 0, 1).multiplyScalar(p.startSpeed);
72
+ return;
73
+ }
74
+
75
+ const triCount = this._triangleIndexToArea.length - 1;
76
+ let left = 0, right = triCount;
77
+ const target = Math.random() * this._triangleIndexToArea[triCount];
78
+
79
+ while (left + 1 < right) {
80
+ const mid = Math.floor((left + right) / 2);
81
+ if (target < this._triangleIndexToArea[mid]) {
82
+ right = mid;
83
+ } else {
84
+ left = mid;
85
+ }
86
+ }
87
+
88
+ let u1 = Math.random();
89
+ let u2 = Math.random();
90
+ if (u1 + u2 > 1) {
91
+ u1 = 1 - u1;
92
+ u2 = 1 - u2;
93
+ }
94
+
95
+ const idx0 = this._indices[left * 3];
96
+ const idx1 = this._indices[left * 3 + 1];
97
+ const idx2 = this._indices[left * 3 + 2];
98
+
99
+ const ax = this._positions[idx0 * 3], ay = this._positions[idx0 * 3 + 1], az = this._positions[idx0 * 3 + 2];
100
+ const bx = this._positions[idx1 * 3] - ax, by = this._positions[idx1 * 3 + 1] - ay, bz = this._positions[idx1 * 3 + 2] - az;
101
+ const cx = this._positions[idx2 * 3] - ax, cy = this._positions[idx2 * 3 + 1] - ay, cz = this._positions[idx2 * 3 + 2] - az;
102
+
103
+ p.position.set(ax + bx * u1 + cx * u2, ay + by * u1 + cy * u2, az + bz * u1 + cz * u2);
104
+
105
+ const nx = by * cz - bz * cy;
106
+ const ny = bz * cx - bx * cz;
107
+ const nz = bx * cy - by * cx;
108
+ const len = Math.sqrt(nx * nx + ny * ny + nz * nz) || 1;
109
+ p.velocity.set(nx / len, ny / len, nz / len).multiplyScalar(p.startSpeed);
110
+ }
111
+
112
+ toJSON(): ShapeJSON {
113
+ return {type: 'mesh_surface', mesh: this._mesh ? (this._mesh as any).uniqueId?.toString() : this._meshReferenceId ?? ''};
114
+ }
115
+
116
+ static fromJSON(json: any): MeshSurfaceEmitter {
117
+ return new MeshSurfaceEmitter(undefined, json?.mesh);
118
+ }
119
+
120
+ clone(): EmitterShape {
121
+ return new MeshSurfaceEmitter(this._mesh, this._meshReferenceId);
122
+ }
123
+
124
+ update(_system: IParticleSystem, _delta: number): void {}
125
+ }
126
+
127
+ export const MeshSurfaceEmitterPlugin: Plugin = {
128
+ id: 'babylon.quarks',
129
+ initialize: () => {},
130
+ emitterShapes: [{
131
+ type: 'mesh_surface',
132
+ params: [['mesh', ['mesh']]],
133
+ constructor: MeshSurfaceEmitter,
134
+ loadJSON: (json: any) => MeshSurfaceEmitter.fromJSON(json),
135
+ }],
136
+ behaviors: [],
137
+ };
@@ -1,86 +1,86 @@
1
- import {TransformNode} from '@babylonjs/core/Meshes/transformNode';
2
- import {Scene} from '@babylonjs/core/scene';
3
- import {Matrix4, IParticleSystem, SerializationOptions} from 'quarks.core';
4
-
5
- export class ParticleEmitter extends TransformNode {
6
- system: IParticleSystem;
7
- private _matrixWorld: Matrix4 = new Matrix4();
8
-
9
- get matrixWorld(): Matrix4 {
10
- const m = this.getWorldMatrix();
11
- const e = this._matrixWorld.elements;
12
- e[0] = m.m[0]; e[1] = m.m[1]; e[2] = m.m[2]; e[3] = m.m[3];
13
- e[4] = m.m[4]; e[5] = m.m[5]; e[6] = m.m[6]; e[7] = m.m[7];
14
- e[8] = m.m[8]; e[9] = m.m[9]; e[10] = m.m[10]; e[11] = m.m[11];
15
- e[12] = m.m[12]; e[13] = m.m[13]; e[14] = m.m[14]; e[15] = m.m[15];
16
- return this._matrixWorld;
17
- }
18
-
19
- get visible(): boolean {
20
- return this.isEnabled();
21
- }
22
-
23
- set visible(value: boolean) {
24
- this.setEnabled(value);
25
- }
26
-
27
- get uuid(): string {
28
- return this.uniqueId.toString();
29
- }
30
-
31
- constructor(system: IParticleSystem, scene?: Scene) {
32
- super('particleEmitter', scene || undefined);
33
- this.system = system;
34
- }
35
-
36
- dispose(): void {
37
- super.dispose();
38
- }
39
-
40
- extractFromCache(cache: any): any[] {
41
- const values: any[] = [];
42
- for (const key in cache) {
43
- const data = cache[key];
44
- if (data && typeof data === 'object') {
45
- delete data.metadata;
46
- }
47
- values.push(data);
48
- }
49
- return values;
50
- }
51
-
52
- clone(name?: string): ParticleEmitter {
53
- const clonedSystem = this.system.clone();
54
- const clonedEmitter = clonedSystem.emitter as ParticleEmitter;
55
- clonedEmitter.name = name ?? this.name;
56
- clonedEmitter.position.copyFrom(this.position);
57
- clonedEmitter.rotation.copyFrom(this.rotation);
58
- clonedEmitter.scaling.copyFrom(this.scaling);
59
- if (this.rotationQuaternion) {
60
- clonedEmitter.rotationQuaternion = this.rotationQuaternion.clone();
61
- }
62
- clonedEmitter.setEnabled(this.isEnabled());
63
- return clonedEmitter;
64
- }
65
-
66
- toJSON(meta?: any, options: SerializationOptions = {}): any {
67
- return {
68
- uuid: (this as any)._quarksUUID ?? this.uniqueId.toString(),
69
- type: 'ParticleEmitter',
70
- name: this.name,
71
- position: [this.position.x, this.position.y, this.position.z],
72
- rotation: [this.rotation.x, this.rotation.y, this.rotation.z],
73
- quaternion: this.rotationQuaternion
74
- ? [
75
- this.rotationQuaternion.x,
76
- this.rotationQuaternion.y,
77
- this.rotationQuaternion.z,
78
- this.rotationQuaternion.w,
79
- ]
80
- : undefined,
81
- scale: [this.scaling.x, this.scaling.y, this.scaling.z],
82
- visible: this.isEnabled(),
83
- ps: this.system.toJSON(meta, options),
84
- };
85
- }
86
- }
1
+ import {TransformNode} from '@babylonjs/core/Meshes/transformNode';
2
+ import {Scene} from '@babylonjs/core/scene';
3
+ import {Matrix4, IParticleSystem, SerializationOptions} from 'quarks.core';
4
+
5
+ export class ParticleEmitter extends TransformNode {
6
+ system: IParticleSystem;
7
+ private _matrixWorld: Matrix4 = new Matrix4();
8
+
9
+ get matrixWorld(): Matrix4 {
10
+ const m = this.getWorldMatrix();
11
+ const e = this._matrixWorld.elements;
12
+ e[0] = m.m[0]; e[1] = m.m[1]; e[2] = m.m[2]; e[3] = m.m[3];
13
+ e[4] = m.m[4]; e[5] = m.m[5]; e[6] = m.m[6]; e[7] = m.m[7];
14
+ e[8] = m.m[8]; e[9] = m.m[9]; e[10] = m.m[10]; e[11] = m.m[11];
15
+ e[12] = m.m[12]; e[13] = m.m[13]; e[14] = m.m[14]; e[15] = m.m[15];
16
+ return this._matrixWorld;
17
+ }
18
+
19
+ get visible(): boolean {
20
+ return this.isEnabled();
21
+ }
22
+
23
+ set visible(value: boolean) {
24
+ this.setEnabled(value);
25
+ }
26
+
27
+ get uuid(): string {
28
+ return this.uniqueId.toString();
29
+ }
30
+
31
+ constructor(system: IParticleSystem, scene?: Scene) {
32
+ super('particleEmitter', scene || undefined);
33
+ this.system = system;
34
+ }
35
+
36
+ dispose(): void {
37
+ super.dispose();
38
+ }
39
+
40
+ extractFromCache(cache: any): any[] {
41
+ const values: any[] = [];
42
+ for (const key in cache) {
43
+ const data = cache[key];
44
+ if (data && typeof data === 'object') {
45
+ delete data.metadata;
46
+ }
47
+ values.push(data);
48
+ }
49
+ return values;
50
+ }
51
+
52
+ clone(name?: string): ParticleEmitter {
53
+ const clonedSystem = this.system.clone();
54
+ const clonedEmitter = clonedSystem.emitter as ParticleEmitter;
55
+ clonedEmitter.name = name ?? this.name;
56
+ clonedEmitter.position.copyFrom(this.position);
57
+ clonedEmitter.rotation.copyFrom(this.rotation);
58
+ clonedEmitter.scaling.copyFrom(this.scaling);
59
+ if (this.rotationQuaternion) {
60
+ clonedEmitter.rotationQuaternion = this.rotationQuaternion.clone();
61
+ }
62
+ clonedEmitter.setEnabled(this.isEnabled());
63
+ return clonedEmitter;
64
+ }
65
+
66
+ toJSON(meta?: any, options: SerializationOptions = {}): any {
67
+ return {
68
+ uuid: (this as any)._quarksUUID ?? this.uniqueId.toString(),
69
+ type: 'ParticleEmitter',
70
+ name: this.name,
71
+ position: [this.position.x, this.position.y, this.position.z],
72
+ rotation: [this.rotation.x, this.rotation.y, this.rotation.z],
73
+ quaternion: this.rotationQuaternion
74
+ ? [
75
+ this.rotationQuaternion.x,
76
+ this.rotationQuaternion.y,
77
+ this.rotationQuaternion.z,
78
+ this.rotationQuaternion.w,
79
+ ]
80
+ : undefined,
81
+ scale: [this.scaling.x, this.scaling.y, this.scaling.z],
82
+ visible: this.isEnabled(),
83
+ ps: this.system.toJSON(meta, options),
84
+ };
85
+ }
86
+ }