sparcoon 0.0.1 → 0.0.3
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/dist/elements/FXEmitter.d.ts +2 -1
- package/dist/elements/FXEmitter.js +3 -9
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/instancedParticle/FXInstancedParticle.Internal.d.ts +2 -2
- package/dist/instancedParticle/FXInstancedParticle.Internal.js +6 -6
- package/dist/instancedParticle/FXInstancedParticle.d.ts +2 -1
- package/dist/instancedParticle/FXInstancedParticle.js +2 -4
- package/dist/instancedParticle/shared.d.ts +0 -2
- package/dist/renderingModules/FXRenderingAnimatedTexture.d.ts +5 -0
- package/dist/renderingModules/FXRenderingAnimatedTexture.js +14 -0
- package/dist/renderingModules/FXRenderingTexture.d.ts +1 -1
- package/dist/renderingModules/FXRenderingTexture.js +2 -2
- package/dist/shaders/FXRenderingAnimatedTexture.glsl.js +3 -0
- package/dist/spawnModules/FXSpawnRandomVelocity.d.ts +5 -14
- package/dist/spawnModules/FXSpawnRandomVelocity.js +42 -27
- package/package.json +1 -1
- package/dist/miscellaneous/FXTransparencyMode.d.ts +0 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Object3D } from "three";
|
|
1
|
+
import { Object3D, type Blending } from "three";
|
|
2
2
|
import type { FXBehaviorModule } from "../behaviorModules/FXBehaviorModule";
|
|
3
3
|
import type { FXRenderingModule } from "../renderingModules/FXRenderingModule";
|
|
4
4
|
import type { FXSpawnModule } from "../spawnModules/FXSpawnModule";
|
|
@@ -7,6 +7,7 @@ export interface FXEmitterOptions {
|
|
|
7
7
|
expectedCapacity: number;
|
|
8
8
|
capacityStep: number;
|
|
9
9
|
automaticallyDestroyModules: boolean;
|
|
10
|
+
blending: Blending;
|
|
10
11
|
}
|
|
11
12
|
export declare class FXEmitter extends Object3D {
|
|
12
13
|
private readonly spawnSequence;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Object3D, Vector2 } from 'three';
|
|
1
|
+
import { Object3D, Vector2, NormalBlending } from 'three';
|
|
2
2
|
import { FXInstancedParticle } from '../instancedParticle/FXInstancedParticle.js';
|
|
3
3
|
import { collectProperties, collectUniforms } from '../instancedParticle/FXInstancedParticle.Internal.js';
|
|
4
4
|
import { resolveGLSLTypeInfo } from '../instancedParticle/shared.js';
|
|
@@ -72,13 +72,6 @@ class FXEmitter extends Object3D {
|
|
|
72
72
|
};
|
|
73
73
|
const collectedProperties = {
|
|
74
74
|
builtin: resolveGLSLTypeInfo("Matrix4"),
|
|
75
|
-
// 0, 1 positionX, positionY
|
|
76
|
-
// 2, 3 velocityX, velocityY
|
|
77
|
-
// 4, 5 scaleX, scaleY
|
|
78
|
-
// 6, 7 rotation, torque
|
|
79
|
-
// 8, 9 lifetime, age
|
|
80
|
-
// 10, 11, 12 randomX, randomY, randomZ
|
|
81
|
-
// 13, 14, 16 reservedX, reservedY, reservedZ
|
|
82
75
|
};
|
|
83
76
|
collectProperties(collectedProperties, _private_spawnSequence, "UIEmitter.constructor.spawnSequence:");
|
|
84
77
|
collectProperties(collectedProperties, _private_behaviorSequence, "UIEmitter.constructor.behaviorSequence");
|
|
@@ -87,7 +80,7 @@ class FXEmitter extends Object3D {
|
|
|
87
80
|
origin: { value: new Vector2(), glslTypeInfo: resolveGLSLTypeInfo("Vector2") },
|
|
88
81
|
};
|
|
89
82
|
collectUniforms(collectedUniforms, _private_renderingSequence, "UIEmitter.constructor.renderingSequence");
|
|
90
|
-
this._private_mesh = new FXInstancedParticle(this._private_renderingSequence.map((module) => module.source), collectedUniforms, collectedProperties, options.expectedCapacity ?? EMITTER_DEFAULT_EXPECTED_CAPACITY, options.capacityStep ?? EMITTER_DEFAULT_CAPACITY_STEP);
|
|
83
|
+
this._private_mesh = new FXInstancedParticle(this._private_renderingSequence.map((module) => module.source), collectedUniforms, collectedProperties, options.expectedCapacity ?? EMITTER_DEFAULT_EXPECTED_CAPACITY, options.capacityStep ?? EMITTER_DEFAULT_CAPACITY_STEP, options.blending ?? NormalBlending);
|
|
91
84
|
this.automaticallyDestroyModules =
|
|
92
85
|
options.automaticallyDestroyModules ?? EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES;
|
|
93
86
|
this.add(this._private_mesh);
|
|
@@ -109,6 +102,7 @@ class FXEmitter extends Object3D {
|
|
|
109
102
|
module.destroy?.();
|
|
110
103
|
}
|
|
111
104
|
}
|
|
105
|
+
this.removeFromParent();
|
|
112
106
|
}
|
|
113
107
|
burst(count) {
|
|
114
108
|
const instanceBegin = this._private_mesh.instanceCount;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,10 +5,12 @@ export { FXBehaviorTorqueDamping } from "./behaviorModules/FXBehaviorTorqueDampi
|
|
|
5
5
|
export { FXBehaviorTorqueNoise } from "./behaviorModules/FXBehaviorTorqueNoise";
|
|
6
6
|
export { FXBehaviorVelocityDamping } from "./behaviorModules/FXBehaviorVelocityDamping";
|
|
7
7
|
export { FXBehaviorVelocityNoise } from "./behaviorModules/FXBehaviorVelocityNoise";
|
|
8
|
+
export { FXColor } from "./color/FXColor";
|
|
8
9
|
export { FXEmitter } from "./elements/FXEmitter";
|
|
10
|
+
export { FXRenderingAnimatedTexture } from "./renderingModules/FXRenderingAnimatedTexture";
|
|
9
11
|
export { FXRenderingColorOverLife } from "./renderingModules/FXRenderingColorOverLife";
|
|
10
12
|
export { FXRenderingColorOverVelocity } from "./renderingModules/FXRenderingColorOverVelocity";
|
|
11
|
-
export {
|
|
13
|
+
export { FXRenderingTexture } from "./renderingModules/FXRenderingTexture";
|
|
12
14
|
export { FXSpawnBox } from "./spawnModules/FXSpawnBox";
|
|
13
15
|
export { FXSpawnOffset } from "./spawnModules/FXSpawnOffset";
|
|
14
16
|
export { FXSpawnRandomLifetime } from "./spawnModules/FXSpawnRandomLifetime";
|
package/dist/index.js
CHANGED
|
@@ -5,10 +5,12 @@ export { FXBehaviorTorqueDamping } from './behaviorModules/FXBehaviorTorqueDampi
|
|
|
5
5
|
export { FXBehaviorTorqueNoise } from './behaviorModules/FXBehaviorTorqueNoise.js';
|
|
6
6
|
export { FXBehaviorVelocityDamping } from './behaviorModules/FXBehaviorVelocityDamping.js';
|
|
7
7
|
export { FXBehaviorVelocityNoise } from './behaviorModules/FXBehaviorVelocityNoise.js';
|
|
8
|
+
export { FXColor } from './color/FXColor.js';
|
|
8
9
|
export { FXEmitter } from './elements/FXEmitter.js';
|
|
10
|
+
export { FXRenderingAnimatedTexture } from './renderingModules/FXRenderingAnimatedTexture.js';
|
|
9
11
|
export { FXRenderingColorOverLife } from './renderingModules/FXRenderingColorOverLife.js';
|
|
10
12
|
export { FXRenderingColorOverVelocity } from './renderingModules/FXRenderingColorOverVelocity.js';
|
|
11
|
-
export {
|
|
13
|
+
export { FXRenderingTexture } from './renderingModules/FXRenderingTexture.js';
|
|
12
14
|
export { FXSpawnBox } from './spawnModules/FXSpawnBox.js';
|
|
13
15
|
export { FXSpawnOffset } from './spawnModules/FXSpawnOffset.js';
|
|
14
16
|
export { FXSpawnRandomLifetime } from './spawnModules/FXSpawnRandomLifetime.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InstancedBufferGeometry, ShaderMaterial } from "three";
|
|
1
|
+
import { InstancedBufferGeometry, ShaderMaterial, type Blending } from "three";
|
|
2
2
|
import type { GLProperty, GLTypeInfo } from "./shared";
|
|
3
3
|
import { type FXProperty, type FXPropertyName } from "./shared";
|
|
4
4
|
export declare const INSTANCED_PARTICLE_GEOMETRY: InstancedBufferGeometry;
|
|
@@ -10,4 +10,4 @@ export declare function collectUniforms(keeper: Record<string, GLProperty>, modu
|
|
|
10
10
|
}[], debugContext: string): void;
|
|
11
11
|
export declare function buildParticleVertexShader(uniformDeclarations: string[], attributeDeclarations: string[], varyingDeclarations: string[], vertexAssignments: string[]): string;
|
|
12
12
|
export declare function buildParticleFragmentShader(uniformDeclarations: string[], varyingDeclarations: string[], sources: string[]): string;
|
|
13
|
-
export declare function buildParticleMaterial(sources: string[], uniformProperties: Record<string, GLProperty>, varyingProperties: Record<string, GLTypeInfo
|
|
13
|
+
export declare function buildParticleMaterial(sources: string[], uniformProperties: Record<string, GLProperty>, varyingProperties: Record<string, GLTypeInfo>, blending: Blending): ShaderMaterial;
|
|
@@ -87,6 +87,7 @@ function buildParticleVertexShader(uniformDeclarations, attributeDeclarations, v
|
|
|
87
87
|
p_uv = uv;
|
|
88
88
|
|
|
89
89
|
vec2 transformedPosition = position.xy;
|
|
90
|
+
|
|
90
91
|
transformedPosition.x *= PARTICLE_SCALE_X;
|
|
91
92
|
transformedPosition.y *= PARTICLE_SCALE_Y;
|
|
92
93
|
|
|
@@ -104,11 +105,9 @@ function buildParticleVertexShader(uniformDeclarations, attributeDeclarations, v
|
|
|
104
105
|
PARTICLE_POSITION_Z
|
|
105
106
|
);
|
|
106
107
|
|
|
107
|
-
vec4
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
gl_Position = projectionMatrix * mvCenter;
|
|
108
|
+
vec4 modelViewCenter = modelViewMatrix * vec4(center, 1.0);
|
|
109
|
+
modelViewCenter.xy += transformedPosition;
|
|
110
|
+
gl_Position = projectionMatrix * modelViewCenter;
|
|
112
111
|
}
|
|
113
112
|
`;
|
|
114
113
|
}
|
|
@@ -186,7 +185,7 @@ function buildParticleFragmentShader(uniformDeclarations, varyingDeclarations, s
|
|
|
186
185
|
}
|
|
187
186
|
`;
|
|
188
187
|
}
|
|
189
|
-
function buildParticleMaterial(sources, uniformProperties, varyingProperties) {
|
|
188
|
+
function buildParticleMaterial(sources, uniformProperties, varyingProperties, blending) {
|
|
190
189
|
const uniforms = {};
|
|
191
190
|
const uniformDeclarations = [];
|
|
192
191
|
const attributeDeclarations = [];
|
|
@@ -210,6 +209,7 @@ function buildParticleMaterial(sources, uniformProperties, varyingProperties) {
|
|
|
210
209
|
transparent: true,
|
|
211
210
|
depthWrite: false,
|
|
212
211
|
depthTest: true,
|
|
212
|
+
blending,
|
|
213
213
|
});
|
|
214
214
|
}
|
|
215
215
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Blending } from "three";
|
|
1
2
|
import { InstancedBufferAttribute, Mesh } from "three";
|
|
2
3
|
import { type GLProperty, type GLTypeInfo } from "./shared";
|
|
3
4
|
export declare class FXInstancedParticle extends Mesh {
|
|
@@ -6,7 +7,7 @@ export declare class FXInstancedParticle extends Mesh {
|
|
|
6
7
|
private readonly instancedGeometry;
|
|
7
8
|
private readonly shaderMaterial;
|
|
8
9
|
private capacity;
|
|
9
|
-
constructor(sources: string[], uniforms: Record<string, GLProperty>, varyings: Record<string, GLTypeInfo>, expectedCapacity: number, capacityStep: number);
|
|
10
|
+
constructor(sources: string[], uniforms: Record<string, GLProperty>, varyings: Record<string, GLTypeInfo>, expectedCapacity: number, capacityStep: number, blending: Blending);
|
|
10
11
|
get instanceCount(): number;
|
|
11
12
|
createInstances(count: number): void;
|
|
12
13
|
setOrigin(x: number, y: number): void;
|
|
@@ -4,15 +4,13 @@ import { INSTANCED_PARTICLE_GEOMETRY, buildParticleMaterial } from './FXInstance
|
|
|
4
4
|
import { resolvePropertyUniform } from './shared.js';
|
|
5
5
|
|
|
6
6
|
class FXInstancedParticle extends Mesh {
|
|
7
|
-
constructor(sources, uniforms, varyings, expectedCapacity, _private_capacityStep) {
|
|
7
|
+
constructor(sources, uniforms, varyings, expectedCapacity, _private_capacityStep, blending) {
|
|
8
8
|
const instancedGeometry = INSTANCED_PARTICLE_GEOMETRY.clone();
|
|
9
|
-
const shaderMaterial = buildParticleMaterial(sources, uniforms, varyings);
|
|
9
|
+
const shaderMaterial = buildParticleMaterial(sources, uniforms, varyings, blending);
|
|
10
10
|
super(instancedGeometry, shaderMaterial);
|
|
11
11
|
this._private_capacityStep = _private_capacityStep;
|
|
12
12
|
this.propertyBuffers = {};
|
|
13
13
|
this.frustumCulled = false;
|
|
14
|
-
this.matrixAutoUpdate = false;
|
|
15
|
-
this.matrixWorldAutoUpdate = false;
|
|
16
14
|
this._private_instancedGeometry = instancedGeometry;
|
|
17
15
|
this._private_instancedGeometry.instanceCount = 0;
|
|
18
16
|
this._private_shaderMaterial = shaderMaterial;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { IUniform, ShaderMaterial } from "three";
|
|
2
2
|
import { Matrix3, Matrix4, Texture, Vector2, Vector3, Vector4 } from "three";
|
|
3
3
|
import { FXColor } from "../color/FXColor";
|
|
4
|
-
import type { FXTransparencyMode } from "../miscellaneous/FXTransparencyMode";
|
|
5
4
|
export type FXProperty = Texture | FXColor | Vector2 | Vector3 | Vector4 | Matrix3 | Matrix4 | number;
|
|
6
5
|
export type FXPropertyName = "Texture" | "UIColor" | "Vector2" | "Vector3" | "Vector4" | "Matrix3" | "Matrix4" | "number";
|
|
7
6
|
export type FXPropertyConstructor = typeof Texture | typeof FXColor | typeof Vector2 | typeof Vector3 | typeof Vector4 | typeof Matrix3 | typeof Matrix4 | NumberConstructor;
|
|
@@ -21,7 +20,6 @@ export interface PlaneData {
|
|
|
21
20
|
properties: Record<string, GLProperty>;
|
|
22
21
|
transform: Matrix4;
|
|
23
22
|
visibility: boolean;
|
|
24
|
-
transparency: FXTransparencyMode;
|
|
25
23
|
}
|
|
26
24
|
export declare function resolveGLSLTypeInfo(value: FXProperty | FXPropertyName | FXPropertyConstructor): GLTypeInfo;
|
|
27
25
|
export declare function resolvePropertyUniform(name: string, material: ShaderMaterial): IUniform<FXProperty>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Vector2 } from 'three';
|
|
2
|
+
import source from '../shaders/FXRenderingAnimatedTexture.glsl.js';
|
|
3
|
+
import { FXRenderingModule } from './FXRenderingModule.js';
|
|
4
|
+
|
|
5
|
+
class FXRenderingAnimatedTexture extends FXRenderingModule {
|
|
6
|
+
constructor(texture, horizontalCount, verticalCount) {
|
|
7
|
+
super();
|
|
8
|
+
/** @internal */
|
|
9
|
+
this.source = source;
|
|
10
|
+
this.requiredUniforms = { texture, count: new Vector2(horizontalCount, verticalCount) };
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { FXRenderingAnimatedTexture };
|
|
@@ -5,7 +5,7 @@ import { FXRenderingModule } from "./FXRenderingModule";
|
|
|
5
5
|
*
|
|
6
6
|
* Samples the texture using particle UV coordinates.
|
|
7
7
|
*/
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class FXRenderingTexture extends FXRenderingModule {
|
|
9
9
|
private readonly texture;
|
|
10
10
|
/**
|
|
11
11
|
* @param config - Texture configuration
|
|
@@ -7,7 +7,7 @@ import { FXRenderingModule } from './FXRenderingModule.js';
|
|
|
7
7
|
*
|
|
8
8
|
* Samples the texture using particle UV coordinates.
|
|
9
9
|
*/
|
|
10
|
-
class
|
|
10
|
+
class FXRenderingTexture extends FXRenderingModule {
|
|
11
11
|
/**
|
|
12
12
|
* @param config - Texture configuration
|
|
13
13
|
*/
|
|
@@ -23,4 +23,4 @@ class FXTextureRenderingModule extends FXRenderingModule {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export {
|
|
26
|
+
export { FXRenderingTexture };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var source = "vec4 draw(){float totalFrames=p_count.x*p_count.y;float frame=floor(PARTICLE_AGE/PARTICLE_LIFETIME*totalFrames);frame=clamp(frame,0.0,totalFrames-1.0);float col=mod(frame,p_count.x);float row=floor(frame/p_count.x);vec2 frameSize=vec2(1.0/p_count.x,1.0/p_count.y);vec2 uv=(p_uv+vec2(col,(p_count.y-1.0-row)))*frameSize;return srgbTexture2D(p_texture,uv);}";
|
|
2
|
+
|
|
3
|
+
export { source as default };
|
|
@@ -1,26 +1,17 @@
|
|
|
1
|
+
import { Vector3 } from "three";
|
|
1
2
|
import { type FXRange, type FXRangeConfig } from "../miscellaneous/miscellaneous";
|
|
2
3
|
import { FXSpawnModule } from "./FXSpawnModule";
|
|
3
|
-
/**
|
|
4
|
-
* Assigns random velocity to particles.
|
|
5
|
-
*
|
|
6
|
-
* Direction and magnitude are chosen independently from their respective ranges.
|
|
7
|
-
*/
|
|
8
4
|
export declare class FXSpawnRandomVelocity extends FXSpawnModule<{
|
|
9
5
|
builtin: "Matrix4";
|
|
10
6
|
}> {
|
|
11
7
|
private angleInternal;
|
|
12
8
|
private magnitudeInternal;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* @param magnitude - Speed range in units/second. Accepts number, tuple, or range object
|
|
16
|
-
*/
|
|
17
|
-
constructor(angle?: FXRangeConfig, magnitude?: FXRangeConfig);
|
|
18
|
-
/** Direction range in radians */
|
|
9
|
+
private readonly directionInternal;
|
|
10
|
+
constructor(direction?: Vector3, angle?: FXRangeConfig, magnitude?: FXRangeConfig);
|
|
19
11
|
get angle(): FXRange;
|
|
20
|
-
/** Speed range in units/second */
|
|
21
12
|
get magnitude(): FXRange;
|
|
22
|
-
|
|
13
|
+
get direction(): Vector3;
|
|
23
14
|
set angle(value: FXRangeConfig);
|
|
24
|
-
/** Speed range in units/second */
|
|
25
15
|
set magnitude(value: FXRangeConfig);
|
|
16
|
+
set direction(value: Vector3);
|
|
26
17
|
}
|
|
@@ -1,48 +1,45 @@
|
|
|
1
|
-
import { MathUtils } from 'three';
|
|
1
|
+
import { Vector3, MathUtils } from 'three';
|
|
2
2
|
import { assertValidNumber } from '../miscellaneous/asserts.js';
|
|
3
|
-
import { resolveFXRangeConfig, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y } from '../miscellaneous/miscellaneous.js';
|
|
3
|
+
import { resolveFXRangeConfig, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, BUILTIN_OFFSET_VELOCITY_Z } from '../miscellaneous/miscellaneous.js';
|
|
4
4
|
import { FXSpawnModule } from './FXSpawnModule.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* Direction and magnitude are chosen independently from their respective ranges.
|
|
10
|
-
*/
|
|
6
|
+
const TEMP_TANGENT = new Vector3();
|
|
7
|
+
const TEMP_BITANGENT = new Vector3();
|
|
8
|
+
const TEMP_VELOCITY = new Vector3();
|
|
11
9
|
class FXSpawnRandomVelocity extends FXSpawnModule {
|
|
12
|
-
|
|
13
|
-
* @param angle - Direction range in radians. Accepts number, tuple, or range object
|
|
14
|
-
* @param magnitude - Speed range in units/second. Accepts number, tuple, or range object
|
|
15
|
-
*/
|
|
16
|
-
constructor(angle = { min: -Math.PI, max: Math.PI }, magnitude = { min: -50, max: 50 }) {
|
|
10
|
+
constructor(direction = new Vector3(0, 1, 0), angle = { min: 0, max: Math.PI }, magnitude = { min: -50, max: 50 }) {
|
|
17
11
|
super();
|
|
18
12
|
/** @internal */
|
|
19
13
|
this.requiredProperties = { builtin: "Matrix4" };
|
|
14
|
+
this._private_directionInternal = direction.clone().normalize();
|
|
20
15
|
this._private_angleInternal = resolveFXRangeConfig(angle);
|
|
21
16
|
this._private_magnitudeInternal = resolveFXRangeConfig(magnitude);
|
|
22
|
-
assertValidNumber(this._private_angleInternal.min, "
|
|
23
|
-
assertValidNumber(this._private_angleInternal.max, "
|
|
24
|
-
assertValidNumber(this._private_magnitudeInternal.min, "
|
|
25
|
-
assertValidNumber(this._private_magnitudeInternal.max, "
|
|
17
|
+
assertValidNumber(this._private_angleInternal.min, "FXSpawnRandomVelocity.constructor.angle.min");
|
|
18
|
+
assertValidNumber(this._private_angleInternal.max, "FXSpawnRandomVelocity.constructor.angle.max");
|
|
19
|
+
assertValidNumber(this._private_magnitudeInternal.min, "FXSpawnRandomVelocity.constructor.magnitude.min");
|
|
20
|
+
assertValidNumber(this._private_magnitudeInternal.max, "FXSpawnRandomVelocity.constructor.magnitude.max");
|
|
26
21
|
}
|
|
27
|
-
/** Direction range in radians */
|
|
28
22
|
get angle() {
|
|
29
23
|
return this._private_angleInternal;
|
|
30
24
|
}
|
|
31
|
-
/** Speed range in units/second */
|
|
32
25
|
get magnitude() {
|
|
33
26
|
return this._private_magnitudeInternal;
|
|
34
27
|
}
|
|
35
|
-
|
|
28
|
+
get direction() {
|
|
29
|
+
return this._private_directionInternal;
|
|
30
|
+
}
|
|
36
31
|
set angle(value) {
|
|
37
32
|
this._private_angleInternal = resolveFXRangeConfig(value);
|
|
38
|
-
assertValidNumber(this._private_angleInternal.min, "
|
|
39
|
-
assertValidNumber(this._private_angleInternal.max, "
|
|
33
|
+
assertValidNumber(this._private_angleInternal.min, "FXSpawnRandomVelocity.angle.min");
|
|
34
|
+
assertValidNumber(this._private_angleInternal.max, "FXSpawnRandomVelocity.angle.max");
|
|
40
35
|
}
|
|
41
|
-
/** Speed range in units/second */
|
|
42
36
|
set magnitude(value) {
|
|
43
37
|
this._private_magnitudeInternal = resolveFXRangeConfig(value);
|
|
44
|
-
assertValidNumber(this._private_magnitudeInternal.min, "
|
|
45
|
-
assertValidNumber(this._private_magnitudeInternal.max, "
|
|
38
|
+
assertValidNumber(this._private_magnitudeInternal.min, "FXSpawnRandomVelocity.magnitude.min");
|
|
39
|
+
assertValidNumber(this._private_magnitudeInternal.max, "FXSpawnRandomVelocity.magnitude.max");
|
|
40
|
+
}
|
|
41
|
+
set direction(value) {
|
|
42
|
+
this._private_directionInternal.copy(value).normalize();
|
|
46
43
|
}
|
|
47
44
|
/** @internal */
|
|
48
45
|
spawn(properties, instanceBegin, instanceEnd) {
|
|
@@ -50,12 +47,30 @@ class FXSpawnRandomVelocity extends FXSpawnModule {
|
|
|
50
47
|
const { array, itemSize } = builtin;
|
|
51
48
|
const { min: angleMin, max: angleMax } = this._private_angleInternal;
|
|
52
49
|
const { min: magnitudeMin, max: magnitudeMax } = this._private_magnitudeInternal;
|
|
50
|
+
const dir = this._private_directionInternal;
|
|
51
|
+
if (Math.abs(dir.y) < 0.999) {
|
|
52
|
+
TEMP_TANGENT.set(0, 1, 0).cross(dir).normalize();
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
TEMP_TANGENT.set(1, 0, 0).cross(dir).normalize();
|
|
56
|
+
}
|
|
57
|
+
TEMP_BITANGENT.crossVectors(dir, TEMP_TANGENT);
|
|
58
|
+
const cosMin = Math.cos(angleMax);
|
|
59
|
+
const cosMax = Math.cos(angleMin);
|
|
53
60
|
for (let i = instanceBegin; i < instanceEnd; i++) {
|
|
54
61
|
const itemOffset = i * itemSize;
|
|
55
|
-
const
|
|
62
|
+
const cosTheta = MathUtils.lerp(cosMin, cosMax, Math.random());
|
|
63
|
+
const sinTheta = Math.sqrt(1 - cosTheta * cosTheta);
|
|
64
|
+
const phi = Math.random() * Math.PI * 2;
|
|
56
65
|
const magnitude = MathUtils.randFloat(magnitudeMin, magnitudeMax);
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
TEMP_VELOCITY.copy(dir)
|
|
67
|
+
.multiplyScalar(cosTheta)
|
|
68
|
+
.addScaledVector(TEMP_TANGENT, Math.cos(phi) * sinTheta)
|
|
69
|
+
.addScaledVector(TEMP_BITANGENT, Math.sin(phi) * sinTheta)
|
|
70
|
+
.multiplyScalar(magnitude);
|
|
71
|
+
array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] = TEMP_VELOCITY.x;
|
|
72
|
+
array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] = TEMP_VELOCITY.y;
|
|
73
|
+
array[itemOffset + BUILTIN_OFFSET_VELOCITY_Z] = TEMP_VELOCITY.z;
|
|
59
74
|
}
|
|
60
75
|
builtin.needsUpdate = true;
|
|
61
76
|
}
|
package/package.json
CHANGED