3 [
Attribute(
desc:
"List of poin infos defining the convex boundry area")]
4 private ref array<ref SCR_BoundsPosition> m_aBounds;
13 static bool s_bSupressChangedPropertyWarnings;
14 const string PROPERTY_OFFSET =
"Offset";
15 const string PROPERTY_BOUNDS =
"m_aBounds";
16 const string PROPERTY_HEIGHT =
"m_fHeight";
24 array<vector> positions = {};
30 if (positions.Count() < 3)
34 int color =
Color.RED;
43 shapeMgr.AddBounds(positions,
m_fHeight, mat[1], color, additionalFlags: flag);
49 if (s_bSupressChangedPropertyWarnings)
55 if (key != PROPERTY_OFFSET && key != PROPERTY_BOUNDS && key != PROPERTY_HEIGHT)
58 Print(
"SCR_ConvexPolygonDamageAreaShape -> NOTICE! After you are finished adjusting the bounds, use World Editor -> Plugins -> Optimize Damage Area Shapes",
LogLevel.WARNING);
63 override bool OptimizeShape(notnull IEntitySource ownerSource, inout notnull WorldEditorAPI api, notnull array<ref ContainerIdPathEntry> shapePath, out vector offset)
69 if (numberOfPoints < 1)
73 float low =
float.MAX;
96 if (offset == vector.Zero ||
97 (
float.AlmostEqual(offset[0], 0) &&
float.AlmostEqual(offset[1], 0) &&
float.AlmostEqual(offset[2], 0)))
101 offset /= numberOfPoints * 2;
103 array<ref ContainerIdPathEntry> finalPath = {};
110 SCR_ConvexPolygonDamageAreaShape.s_bSupressChangedPropertyWarnings =
true;
113 api.SetVariableValue(ownerSource, finalPath, PROPERTY_HEIGHT,
m_fHeight.ToString());
116 int lastElementId = finalPath.Count() - 1;
119 finalPath[lastElementId].Index = entryId;
121 vector newPos = oldPos - offset;
122 api.SetVariableValue(ownerSource, finalPath, PROPERTY_OFFSET, newPos.ToString(
false));
125 SCR_ConvexPolygonDamageAreaShape.s_bSupressChangedPropertyWarnings =
false;
130 override void Diag_DrawArea(
int color)
136 SCR_DamageAreaComponent dmgAreaComp = SCR_DamageAreaComponent.Cast(owner.
FindComponent(SCR_DamageAreaComponent));
137 SCR_DebugShapeManager shapeMgr = dmgAreaComp.GetDebugShapeMgr();
150 float maxDistanceSq, currentDistSq;
161 currentDistSq = pos.LengthSq();
162 if (currentDistSq > maxDistanceSq)
163 maxDistanceSq = currentDistSq;
166 currentDistSq = upperCorner.LengthSq();
167 if (currentDistSq > maxDistanceSq)
168 maxDistanceSq = currentDistSq;
188 worldPos = character.AimingPosition();
194 worldPos = phys.GetCenterOfMass();
213 const float halfHeight =
m_fHeight * 0.5;
214 if (positionCopy[1] > halfHeight || positionCopy[1] < -halfHeight)
219 vector previousCorner, nextCorner, previousPlaneDir, nextPlaneDir, previousNormal, nextNormal, directionToPoint;
220 float previousDot, nextDot;
237 previousPlaneDir = previousCorner - corner;
238 nextPlaneDir = nextCorner - corner;
239 previousNormal =
SCR_Math3D.Cross(upOffset, previousPlaneDir,
true);
240 nextNormal =
SCR_Math3D.Cross(upOffset, nextPlaneDir,
true);
241 directionToPoint = positionCopy - corner;
242 previousDot =
vector.Dot(previousNormal, directionToPoint);
243 nextDot =
vector.Dot(nextNormal, directionToPoint);
246 if (previousDot * nextDot > 0)
override bool _WB_OnKeyChanged(IEntity owner, BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
Any property value has been changed. You can use editor API here and do some additional edit actions ...
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.