7 vector m_vLastTracePos;
8 vector m_vLastTraceNormal;
10 bool m_bConnectToPrevious;
15 m_vLastAxlePos = vector.Zero;
16 m_vLastTracePos = vector.Zero;
17 m_vLastTraceNormal = vector.Zero;
19 m_bConnectToPrevious =
false;
22 void Finalize(
float dist)
28 m_Decal.FinalizeTrackDecal(
false, 0);
29 m_bConnectToPrevious =
true;
33 m_Decal.FinalizeTrackDecal(
true, dist);
34 m_bConnectToPrevious =
false;
49 [
Attribute(
"", UIWidgets.ResourceNamePicker,
desc:
"Material for track decal",
params:
"emat")]
50 private ResourceName m_TrackMaterial;
52 [
Attribute(
"0.5", UIWidgets.EditBox,
"Minimal lateral slip of wheel" )]
53 float m_fMinimalLateralSlip;
55 [
Attribute(
"0.5", UIWidgets.EditBox,
"Minimal longitudinal slip of wheel" )]
56 float m_fMinimalLongitudinalSlip;
58 VehicleWheeledSimulation m_VehicleWheeledSimulation;
59 VehicleWheeledSimulation_SA m_VehicleWheeledSimulation_SA;
61 ref array<ref TrackDecalInfo> m_TrackDecalsInfo;
62 int m_iWheelCount = 0;
65 override void OnPostInit(IEntity owner)
68 if (System.IsConsoleApp())
74 SetEventMask(owner, EntityEvent.INIT);
78 override void EOnInit(IEntity owner)
87 m_VehicleWheeledSimulation = VehicleWheeledSimulation.Cast(generic_entity.FindComponent(VehicleWheeledSimulation));
88 m_iWheelCount = m_VehicleWheeledSimulation.WheelCount();
93 m_VehicleWheeledSimulation_SA = VehicleWheeledSimulation_SA.Cast(generic_entity.FindComponent(VehicleWheeledSimulation_SA));
94 m_iWheelCount = m_VehicleWheeledSimulation_SA.WheelCount();
100 m_TrackDecalsInfo =
new array<ref TrackDecalInfo>();
101 m_TrackDecalsInfo.Resize(m_iWheelCount);
103 for(
int i = 0; i < m_iWheelCount; i++)
108 SetEventMask(owner, EntityEvent.FRAME);
112 override void EOnFrame(IEntity owner,
float timeSlice)
114 for(
int i = 0; i < m_iWheelCount; i++)
116 UpdateTrack(owner, i);
120 void UpdateTrack(IEntity owner,
int wheelIdx)
124 float lateralSlip = 0;
125 float latitudeSlip = 0;
127 bool shouldAddTrackDecal = 0;
131 lateralSlip = m_VehicleWheeledSimulation.WheelGetLateralSlip(wheelIdx);
132 latitudeSlip = m_VehicleWheeledSimulation.WheelGetLongitudinalSlip(wheelIdx);
134 shouldAddTrackDecal = m_VehicleWheeledSimulation.WheelHasContact(wheelIdx) && (lateralSlip >= m_fMinimalLateralSlip || latitudeSlip >= m_fMinimalLongitudinalSlip);
138 lateralSlip = m_VehicleWheeledSimulation_SA.WheelGetLateralSlip(wheelIdx);
139 latitudeSlip = m_VehicleWheeledSimulation_SA.WheelGetLongitudinalSlip(wheelIdx);
141 shouldAddTrackDecal = m_VehicleWheeledSimulation_SA.WheelHasContact(wheelIdx) && (lateralSlip >= m_fMinimalLateralSlip || latitudeSlip >= m_fMinimalLongitudinalSlip);
144 if(!shouldAddTrackDecal)
146 if(trackInfo.m_Decal)
149 trackInfo.Finalize(0.25);
156 IEntity contactEntity;
160 position = m_VehicleWheeledSimulation.WheelGetContactPosition(wheelIdx);
161 normal = m_VehicleWheeledSimulation.WheelGetContactNormal(wheelIdx);
162 contactEntity = m_VehicleWheeledSimulation.WheelGetContactEntity(wheelIdx);
166 position = m_VehicleWheeledSimulation_SA.WheelGetContactPosition(wheelIdx);
167 normal = m_VehicleWheeledSimulation_SA.WheelGetContactNormal(wheelIdx);
168 contactEntity = m_VehicleWheeledSimulation_SA.WheelGetContactEntity(wheelIdx);
171 if(!trackInfo.m_Decal)
173 if(trackInfo.m_bConnectToPrevious)
175 trackInfo.m_Decal =
GetOwner().GetWorld().CreateTrackDecal(contactEntity, trackInfo.m_vLastTracePos, trackInfo.m_vLastTraceNormal, 0.25, 120.0, m_TrackMaterial,
null, 1.0);
176 trackInfo.m_bConnectToPrevious =
false;
181 trackInfo.m_Decal =
GetOwner().GetWorld().CreateTrackDecal(contactEntity,
position, normal, 0.25, 120.0, m_TrackMaterial,
null, 0.0);
185 else if(vector.DistanceSq(trackInfo.m_vLastAxlePos,
position) > 0.01)
187 trackInfo.m_vLastAxlePos =
position;
189 int validationEnum = trackInfo.m_Decal.CanAddToTrackDecal(contactEntity, m_TrackMaterial,
position);
191 switch(validationEnum)
194 Print(
"Track error");
198 trackInfo.m_fLength += vector.Distance(
position, trackInfo.m_vLastTracePos);
200 if(!trackInfo.m_Decal.AddPointToTrackDecal(
position, normal, 1.0))
202 trackInfo.Finalize(0.0);
203 Print(
"Finalized point");
209 TrackDecal oldDecal = trackInfo.m_Decal;
210 oldDecal.FinalizeTrackDecal(
false, 0);
212 trackInfo.m_Decal =
GetOwner().GetWorld().CreateTrackDecal(contactEntity,
position, normal, 0.25, 120.0, m_TrackMaterial, oldDecal, 1.0);
213 trackInfo.m_bConnectToPrevious =
false;
219 trackInfo.Finalize(0.1);
220 trackInfo.m_fLength = 0.0;
221 trackInfo.m_Decal =
GetOwner().GetWorld().CreateTrackDecal(contactEntity,
position, normal, 0.25, 120.0, m_TrackMaterial,
null, 0.0);
222 trackInfo.m_bConnectToPrevious =
false;
229 trackInfo.m_vLastTracePos =
position;
230 trackInfo.m_vLastTraceNormal = normal;