Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
Crossroad.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameLib/Generic", description:"Crossroad", dynamicBox: true)]
2class CrossroadEntityClass: GenericEntityClass
3{
4}
5
7{
8 [Attribute(defvalue: "0", uiwidget: UIWidgets.CheckBox, desc: "If enabled, adjust terrain height map to entity", category: "Terrain")]
9 private bool AdjustHeightMap;
10
11 [Attribute(defvalue: "0", desc: "Priority of terrain heightmap adjust", category: "Terrain")]
12 private int AdjustHeightMapPriority;
13
14 [Attribute(defvalue: "2", uiwidget: UIWidgets.EditBox, desc: "Distance between edge and start of fall-off", category: "Terrain")]
15 private float FalloffStartWidth;
16
17 [Attribute(defvalue: "20", uiwidget: UIWidgets.EditBox, desc: "Width of the fall-off", category: "Terrain")]
18 private float FalloffWidth;
19
20 protected void CrossroadEntity(IEntitySource src, IEntity parent)
21 {
23 }
24
25 //-----------------------------------------------------------------------
26 protected void ~CrossroadEntity()
27 {
28 #ifdef WORKBENCH
30 if (api)
31 {
32 api.RemoveTerrainFlatterEntity(this);
33 }
34 #endif
35 }
36
37 override protected void EOnInit(IEntity owner)
38 {
39 Init();
40 }
41
42#ifdef WORKBENCH
43 ref array<vector> m_Bones = new array<vector>;
44
45 void Init()
46 {
47 vector mat[4];
48 auto boneNames = new array<string>;
49 Animation anim = GetAnimation();
50 anim.GetBoneNames(boneNames);
51 foreach(string bone: boneNames)
52 {
53 int idx = anim.GetBoneIndex(bone);
54 anim.GetBoneMatrix(idx, mat);
55 m_Bones.Insert(mat[3]);
56 }
57
58 UpdateTerrain();
59 }
60
61 void UpdateTerrain()
62 {
63 WorldEditorAPI api = _WB_GetEditorAPI();
64 if (!api) return;
65
66 if (AdjustHeightMap)
67 {
68 vector mins;
69 vector maxs;
70 GetWorldBounds(mins, maxs);
71
72 api.AddTerrainFlatterEntity(this, mins, maxs, AdjustHeightMapPriority, FalloffStartWidth, FalloffWidth);
73 }
74 else
75 {
76 api.RemoveTerrainFlatterEntity(this);
77 }
78 }
79
80 override bool _WB_CanAnchorSnap(IEntitySource thisSrc, int thisAnchor, IEntitySource otherSrc, int otherAnchor, bool isReceiver)
81 {
82 if (isReceiver && otherSrc.GetClassName() == "SplineShapeEntity")
83 {
84 BaseContainerList points = otherSrc.GetObjectArray("Points");
85 if (otherAnchor == 0 || otherAnchor == points.Count() - 1)
86 return true;
87 }
88
89 return false;
90 }
91
92 vector GetTangent(ShapeEntity shape, int pIdx)
93 {
94 array<vector> points = new array<vector>();
95 shape.GetPointsPositions(points);
96
97 int nPoints = points.Count();
98 if (nPoints < 2)
99 return vector.Zero;
100
101
102 if (pIdx == 0)
103 {
104 vector res = (points[1] - points[0]);
105 res.Normalize();
106 return res;
107 }
108
109 if (pIdx >= nPoints - 1)
110 {
111 vector res = (points[nPoints - 1] - points[nPoints - 2]);
112 res.Normalize();
113 return res;
114 }
115
116 return vector.Zero;
117 }
118
119 override void _WB_OnAnchorSnapped(IEntitySource thisSrc, int thisAnchor, IEntitySource otherSrc, int otherAnchor, bool isReceiver)
120 {
121 if (isReceiver && otherSrc.GetClassName() == "SplineShapeEntity")
122 {
123 BaseContainerList points = otherSrc.GetObjectArray("Points");
124 WorldEditorAPI api = _WB_GetEditorAPI();
125 ShapeEntity shape = ShapeEntity.Cast(api.SourceToEntity(otherSrc));
126 int boneIdx = thisAnchor + 1;
127 vector mat[4];
128
129 if (points && points.Count() > otherAnchor && shape)
130 {
131 // get crossroad point tangent
132
134
135 // apply bone transform
136 vector crossroadTangent = (m_Bones[boneIdx] - m_Bones[0]).Normalized().Multiply3(mat);
137
138 // get spline point tangent
139 shape.GetWorldTransform(mat);
140 vector splineTangent = GetTangent(shape, otherAnchor).Multiply3(mat);
141
142 float len = Math.Max(0.2, 1.0 - Math.AbsFloat(vector.Dot(-splineTangent, crossroadTangent)));
143 vector finalSplineTangent = crossroadTangent.InvMultiply3(mat) * len * 300;
144
145 api.BeginEntityAction("Snap to crossroad");
146 // adjust spline control point
147 BaseContainer point = points[otherAnchor];
148 BaseContainerList pointData = point.GetObjectArray("Data");
149 if (pointData.Count() == 0)
150 {
151 api.CreateObjectArrayVariableMember(point, null, "Data", "SplinePointData", 0);
152 }
153
154 array<ref ContainerIdPathEntry> containerPath = {ContainerIdPathEntry("Points", otherAnchor), ContainerIdPathEntry("Data", 0)};
155 if (otherAnchor == 0)
156 {
157 api.SetVariableValue(otherSrc, containerPath, "OutTangent", finalSplineTangent.ToString(false));
158 }
159 else
160 {
161 api.SetVariableValue(otherSrc, containerPath, "InTangent", (-finalSplineTangent).ToString(false));
162 }
163
164 //adjust bone
165
166 api.EndEntityAction();
167 }
168 }
169 }
170
171 override bool _WB_OnKeyChanged(BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
172 {
173 UpdateTerrain();
174 return false;
175 }
176
177 override int _WB_GetAnchorCount(IEntitySource src)
178 {
179 int cnt = m_Bones.Count();
180 if (cnt > 2)
181 return m_Bones.Count() - 1;
182 return 0;
183 }
184
185 override void _WB_GetAnchor(inout vector position, IEntitySource src, int index)
186 {
187 position = m_Bones[index + 1];
188 }
189#else
190 void Init()
191 {
192 }
193#endif
194}
override void Init()
void ContainerIdPathEntry(string propertyName, int index=-1)
Definition worldEditor.c:30
void CrossroadEntity(IEntitySource src, IEntity parent)
Definition Crossroad.c:20
void ~CrossroadEntity()
Definition Crossroad.c:26
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
vector position
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
enum EVehicleType IEntity
event int _WB_GetAnchorCount(IEntitySource src)
Returns how many anchor points does this entity have at this time.
event bool _WB_CanAnchorSnap(IEntitySource thisSrc, int thisAnchor, IEntitySource otherSrc, int otherAnchor, bool isReceiver)
proto external WorldEditorAPI _WB_GetEditorAPI()
This returns world editor API, which is safe to use from editor events bellow.
event bool _WB_OnKeyChanged(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 ...
event void _WB_GetAnchor(inout vector position, IEntitySource src, int index)
Fills position of anchor at index index to anchorPosition.
event void _WB_OnAnchorSnapped(IEntitySource thisSrc, int thisAnchor, IEntitySource otherSrc, int otherAnchor, bool isReceiver)
proto external EntityEvent SetEventMask(EntityEvent e)
void EOnInit(IEntity owner)
proto external void GetWorldTransform(out vector mat[])
See IEntity::GetTransform.
proto external Animation GetAnimation()
proto external void GetWorldBounds(out vector mins, out vector maxs)
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.