@@ -17,6 +17,7 @@ import { _CreateLocalPositionData } from "./emitters.functions";
1717export class ConeShapeBlock extends NodeParticleBlock implements IShapeBlock {
1818 /**
1919 * Gets or sets a boolean indicating if the system should emit only from the spawn point
20+ * DirectionRandomizer will be used for the particles initial direction unless both direction1 and direction2 are connected.
2021 */
2122 @editableInPropertyPage ( "Emit from spawn point only" , PropertyTypeForEdition . Boolean , "ADVANCED" , { embedded : true , notifiers : { rebuild : true } } )
2223 public emitFromSpawnPointOnly = false ;
@@ -34,6 +35,8 @@ export class ConeShapeBlock extends NodeParticleBlock implements IShapeBlock {
3435 this . registerInput ( "radiusRange" , NodeParticleBlockConnectionPointTypes . Float , true , 1 ) ;
3536 this . registerInput ( "heightRange" , NodeParticleBlockConnectionPointTypes . Float , true , 1 ) ;
3637 this . registerInput ( "directionRandomizer" , NodeParticleBlockConnectionPointTypes . Float , true , 0 ) ;
38+ this . registerInput ( "direction1" , NodeParticleBlockConnectionPointTypes . Vector3 , true ) ;
39+ this . registerInput ( "direction2" , NodeParticleBlockConnectionPointTypes . Vector3 , true ) ;
3740 this . registerOutput ( "output" , NodeParticleBlockConnectionPointTypes . Particle ) ;
3841 }
3942
@@ -87,6 +90,20 @@ export class ConeShapeBlock extends NodeParticleBlock implements IShapeBlock {
8790 return this . _inputs [ 5 ] ;
8891 }
8992
93+ /**
94+ * Gets the direction1 input component
95+ */
96+ public get direction1 ( ) : NodeParticleConnectionPoint {
97+ return this . _inputs [ 6 ] ;
98+ }
99+
100+ /**
101+ * Gets the direction2 input component
102+ */
103+ public get direction2 ( ) : NodeParticleConnectionPoint {
104+ return this . _inputs [ 7 ] ;
105+ }
106+
90107 /**
91108 * Gets the output component
92109 */
@@ -105,21 +122,37 @@ export class ConeShapeBlock extends NodeParticleBlock implements IShapeBlock {
105122 state . particleContext = particle ;
106123 state . systemContext = system ;
107124
108- const directionRandomizer = this . directionRandomizer . getConnectedValue ( state ) as number ;
109-
110- const direction = particle . position . subtract ( state . emitterPosition ! ) . normalize ( ) ;
111- const randX = RandomRange ( 0 , directionRandomizer ) ;
112- const randY = RandomRange ( 0 , directionRandomizer ) ;
113- const randZ = RandomRange ( 0 , directionRandomizer ) ;
114- direction . x += randX ;
115- direction . y += randY ;
116- direction . z += randZ ;
117- direction . normalize ( ) ;
118-
119- if ( system . isLocal ) {
120- particle . direction . copyFromFloats ( direction . x , direction . y , direction . z ) ;
125+ // We always use directionRandomizer unless both directions are connected
126+ if ( this . direction1 . isConnected === false || this . direction2 . isConnected === false ) {
127+ const directionRandomizer = this . directionRandomizer . getConnectedValue ( state ) as number ;
128+
129+ const direction = particle . position . subtract ( state . emitterPosition ! ) . normalize ( ) ;
130+ const randX = RandomRange ( 0 , directionRandomizer ) ;
131+ const randY = RandomRange ( 0 , directionRandomizer ) ;
132+ const randZ = RandomRange ( 0 , directionRandomizer ) ;
133+ direction . x += randX ;
134+ direction . y += randY ;
135+ direction . z += randZ ;
136+ direction . normalize ( ) ;
137+
138+ if ( system . isLocal ) {
139+ particle . direction . copyFromFloats ( direction . x , direction . y , direction . z ) ;
140+ } else {
141+ Vector3 . TransformNormalFromFloatsToRef ( direction . x , direction . y , direction . z , state . emitterWorldMatrix ! , particle . direction ) ;
142+ }
121143 } else {
122- Vector3 . TransformNormalFromFloatsToRef ( direction . x , direction . y , direction . z , state . emitterWorldMatrix ! , particle . direction ) ;
144+ const direction1 = this . direction1 . getConnectedValue ( state ) as Vector3 ;
145+ const direction2 = this . direction2 . getConnectedValue ( state ) as Vector3 ;
146+
147+ const randX = RandomRange ( direction1 . x , direction2 . x ) ;
148+ const randY = RandomRange ( direction1 . y , direction2 . y ) ;
149+ const randZ = RandomRange ( direction1 . z , direction2 . z ) ;
150+
151+ if ( system . isLocal ) {
152+ particle . direction . copyFromFloats ( randX , randY , randZ ) ;
153+ } else {
154+ Vector3 . TransformNormalFromFloatsToRef ( randX , randY , randZ , state . emitterWorldMatrix ! , particle . direction ) ;
155+ }
123156 }
124157
125158 particle . _initialDirection = particle . direction . clone ( ) ;
0 commit comments