11 static string particle_attribute_descriptions =
"Select particle effect for driving on this surface type.";
45 [
Attribute(
"",
UIWidgets.Coords,
"Orientation of the effect relative to the vehicle" )]
46 vector m_vLocalOrientation;
51 [
Attribute(
"",
UIWidgets.EditBox,
"Minimal speed (km/h) which triggers the dust effect and its interpolation from 0%" )]
52 float m_fDustStartSpeed;
54 [
Attribute(
"",
UIWidgets.EditBox,
"Speed (km/h) which tops the effect's interpolation at 100% values" )]
55 float m_fDustTopSpeed;
60 int m_iCurrentSurfaceID;
61 int m_iSurfaceSignalID = -1;
65 float m_fCurrentUpdateDelay;
66 const float TICK_TIME_DELAY_MAX = 2;
67 const float TICK_DELAY_RANGE_START = 15;
68 const float TICK_DELAY_RANGE_END = 100;
72 super.OnPostInit(owner);
84 override void EOnInit(
IEntity owner)
89 if (surface_particles.Count() == 0)
90 RegisterSurfaceTypes();
109 m_Effect.SetTransform(mat);
117 void RegisterSurfaceTypes()
120 surface_particles.Insert(0, m_Default);
121 surface_particles.Insert(31, m_Grass);
122 surface_particles.Insert(21, m_Dirt);
123 surface_particles.Insert(25, m_Gravel);
124 surface_particles.Insert(51, m_Wood);
125 surface_particles.Insert(11, m_Asphalt);
126 surface_particles.Insert(41, m_Snow);
127 surface_particles.Insert(28, m_Sand);
128 surface_particles.Insert(61, m_Metal);
129 surface_particles.Insert(12, m_Concrete);
130 surface_particles.Insert(23, m_Soil);
131 surface_particles.Insert(15, m_Stone);
132 surface_particles.Insert(27, m_Stone);
133 surface_particles.Insert(72, m_Rubber);
134 surface_particles.Insert(91, m_Flesh);
135 surface_particles.Insert(71, m_Glass);
136 surface_particles.Insert(73, m_Plastic);
139 override void EOnFrame(
IEntity owner,
float timeSlice)
141 m_fCurrentUpdateDelay += timeSlice;
144 vector camera_transform[4];
145 GetGame().GetWorld().GetCurrentCamera(camera_transform);
146 vector camera_world_pos = camera_transform[3];
148 float distance = relative_pos.Length();
151 if (
distance > TICK_DELAY_RANGE_START)
153 m_fUpdateDelay = TICK_TIME_DELAY_MAX * (
Math.Clamp( (
distance - TICK_DELAY_RANGE_START) / TICK_DELAY_RANGE_END , 0, 1) );
161 if (m_fCurrentUpdateDelay > m_fUpdateDelay)
163 m_fCurrentUpdateDelay = 0;
169 void UpdateEffect(
IEntity owner)
173 if (physics && m_SignalManagerComp)
175 float speed = physics.GetVelocity().Length();
178 if (speed >= m_fDustStartSpeed && m_fDustStartSpeed > 0 && m_fDustTopSpeed >= m_fDustStartSpeed)
180 int previousSurfaceID = m_iCurrentSurfaceID;
183 if (m_iSurfaceSignalID < 0)
184 m_iSurfaceSignalID = m_SignalManagerComp.AddOrFindSignal(
"surface");
186 m_iCurrentSurfaceID = m_SignalManagerComp.GetSignalValue(m_iSurfaceSignalID);
188 if (!surface_particles)
189 RegisterSurfaceTypes();
194 m_iCurrentSurfaceID = m_iCurrentSurfaceID/100;
195 if (m_iCurrentSurfaceID >= 0 && surface_particles.Contains(m_iCurrentSurfaceID))
196 surface_type = surface_particles.Get(m_iCurrentSurfaceID);
200 if (m_Effect && previousSurfaceID == m_iCurrentSurfaceID)
203 m_Effect.UpdateVehicleDustEffect(speed, m_fDustStartSpeed, m_fDustTopSpeed);
208 m_Effect.StopEmission();
210 if (surface_type.Length() > 0)
214 Math3D.AnglesToMatrix(m_vLocalOrientation, spawnParams.Transform);
215 spawnParams.Transform[3] = m_vLocalOffset;
216 spawnParams.Parent = owner;
217 spawnParams.UseFrameEvent =
true;
220 m_Effect.UpdateVehicleDustEffect(speed, m_fDustStartSpeed*3.6, m_fDustTopSpeed);
227 m_Effect.StopEmission();
void ParticleEffectEntity(IEntitySource src, IEntity parent)