Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SpherePointGeneratorPreviewComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Utilities", description: "Displays points generated by the SCR_SpherePointGenerator")]
5
6class SCR_SpherePointGeneratorPreviewComponent : ScriptComponent
7{
8 [Attribute(desc: "Radii of spheres to generate", defvalue: "{}", category: "Sphere", params: "0.001 inf")]
9 ref array<float> m_aSphereRadii;
10
11 [Attribute(desc: "Size of generated points", defvalue: "1", category: "Sphere", params: "0.001 inf")]
12 float m_fPointSize;
13
14 [Attribute(desc: "Maximum generated points", defvalue: "1000", category: "Sphere", params: "0 100000")]
15 int m_iMaxPoints;
16
17 [Attribute(desc: "Spacing between generated points. ", defvalue: "5", category: "Spacing Based", params: "0.001 inf")]
18 float m_fSpacing;
19
20 [Attribute(desc: "Amount of Points to generate in each sphere. Overrides Spacing Based settings.", defvalue: "{}", category: "Amount Based", params: "0 100000")]
21 ref array<int> m_aPointAmounts;
22
23 [Attribute(desc: "Base color", defvalue: "", category: "Labelling")]
25
26 [Attribute(desc: "Hue-shift By Point In Sphere", defvalue: "1", category: "Labelling")]
28
29 [Attribute(desc: "Hue-shift By Sphere", defvalue: "1", category: "Labelling")]
31
32 [Attribute(desc: "Show index", defvalue: "1", category: "Labelling")]
34
35 protected string m_sInstanceId;
36
37 protected static const int PREVIEW_POINT_BUDGET = 100000;
38 protected static ref set<string> s_KeyUpdateSet;
39
40 //------------------------------------------------------------------------------------------------
42 override protected void OnPostInit(IEntity owner)
43 {
45 }
46
47 //------------------------------------------------------------------------------------------------
50 protected void DrawPreview()
51 {
52 string tag = string.Format("SCR_SpherePointGeneratorPreview_%1", GetInstanceId());
53 SCR_DebugShapeHelperComponent.RemoveTag(tag);
54 if (!IsActive())
55 return;
56
57 int sphereAmount = m_aSphereRadii.Count();
58 if (sphereAmount < 1)
59 return;
60
61 if (!m_BaseColor)
62 m_BaseColor = Color.FromInt(SCR_DebugShapeHelperComponent.MakeTransparent(Color.VIOLET));
63 if (m_fSpacing < 0.01)
64 m_fSpacing = 0.01;
65
66 World world = GetOwner().GetWorld();
68 SCR_ColorAHSV colorHSVA = SCR_ColorAHSV.FromColor(m_BaseColor);
69 int colorInt = m_BaseColor.PackToInt();
70 float pointShiftOffset = 0;
71 float pointShiftModifier = 0.833; // Prevents full hue rotation to avoid confusion.
73 pointShiftModifier /= sphereAmount;
74
75 int remainingPointBudget = Math.Min(m_iMaxPoints, PREVIEW_POINT_BUDGET);
76 for (int sphereI = 1; sphereI <= sphereAmount; ++sphereI)
77 {
78 int pointsAmount;
79 float radius = m_aSphereRadii[sphereI - 1];
80 if (radius <= 0)
81 continue;
82
83 if (m_aPointAmounts.Count() >= sphereI)
84 pointsAmount = m_aPointAmounts[sphereI - 1];
85 else
86 pointsAmount = SCR_SpherePointGenerator.EstimatePointsFromSpacingOnUnitSphere(m_fSpacing / radius);
87
88 if (pointsAmount < 0)
89 continue; // Allow other sheres with defiend points to be renderd.
90
91 pointsAmount = Math.Min(pointsAmount, remainingPointBudget);
92 remainingPointBudget -= pointsAmount;
93 if (pointsAmount < 1)
94 break; // No more points in budget.
95
97 pointShiftOffset = (sphereI - 1) / sphereAmount;
98 for (int pointI = 0; pointI < pointsAmount; ++pointI)
99 {
100 int shiftedColor = colorInt;
102 shiftedColor = colorHSVA.WithHueShift(pointShiftOffset + pointShiftModifier * (pointI / pointsAmount)).ToColor().PackToInt();
103 vector point = position + radius * SCR_SpherePointGenerator.GetPointOnUnitSphereFromEquator(pointsAmount, pointI);
104 SCR_DebugShapeHelperComponent.AddSphere(point, m_fPointSize, shiftedColor, tag: tag);
105 if (world && m_bShowIndex)
106 SCR_DebugShapeHelperComponent.AddText(world, point, pointI.ToString(), tag: tag);
107 }
108 }
109 }
110
111 //------------------------------------------------------------------------------------------------
115 protected string GetInstanceId()
116 {
118 return m_sInstanceId;
120 return m_sInstanceId;
121 }
122
123 //------------------------------------------------------------------------------------------------
125 override void _WB_OnInit(IEntity owner, inout vector mat[4], IEntitySource src)
126 {
127 DrawPreview();
128 super._WB_OnInit(owner, mat, src);
129 }
130
131 //------------------------------------------------------------------------------------------------
133 override bool _WB_OnKeyChanged(IEntity owner, BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
134 {
135 if (key == "coords")
136 {
137 DrawPreview();
138 return true;
139 }
140
141 if (GetKeyUpdateSet().Contains(key))
142 return false;
143
144 return true;
145 }
146
147 //------------------------------------------------------------------------------------------------
150 override void OnDelete(IEntity owner)
151 {
152 SCR_DebugShapeHelperComponent.RemoveTag("SCR_SpherePointGeneratorPreview_" + GetInstanceId());
153 }
154
155 //------------------------------------------------------------------------------------------------
157 protected static set<string> GetKeyUpdateSet()
158 {
159 if (!s_KeyUpdateSet)
160 {
161 s_KeyUpdateSet = new set<string>();
162 s_KeyUpdateSet.Insert("Enabled");
163 s_KeyUpdateSet.Insert("m_aSphereRadii");
164 s_KeyUpdateSet.Insert("m_fPointSize");
165 s_KeyUpdateSet.Insert("m_iMaxPoints");
166 s_KeyUpdateSet.Insert("m_fSpacing");
167 s_KeyUpdateSet.Insert("m_aPointAmounts");
168 s_KeyUpdateSet.Insert("m_BaseColor");
169 s_KeyUpdateSet.Insert("m_bHueShiftByIndex");
170 s_KeyUpdateSet.Insert("m_bHueShiftBySphere");
171 s_KeyUpdateSet.Insert("m_bShowIndex");
172 }
173 return s_KeyUpdateSet;
174 }
175}
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
vector position
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Color.c:13
proto external bool IsActive()
event void _WB_OnInit(IEntity owner, inout vector mat[4], IEntitySource src)
Called always after entity creation. It's purpose is to prepare entity for editing....
event 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 external vector GetOrigin()
proto external BaseWorld GetWorld()
proto external string GetName()
Definition Math.c:13
static bool IsEmptyOrWhiteSpace(string input)
proto external GenericEntity GetOwner()
Get owner entity.
Definition World.c:16
SCR_FieldOfViewSettings Attribute
proto bool Contains(T value)