Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EditablePreviewEntity.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Preview", color: "0 0 0 0")]
3 {
4 };
9 {
10  protected SCR_EditableEntityComponent m_EditableEntity;
11  protected ref array<IEntity> m_aExcludeArray; //--- Entities excluded when tracing terrain. Must be here, trace does not hold own reference.
12 
22  static SCR_BasePreviewEntity SpawnPreviewFromEditableOwner(IEntity entity, ResourceName previewPrefab, BaseWorld world = null, EntitySpawnParams spawnParams = null, ResourceName material = ResourceName.Empty, EPreviewEntityFlag flags = 0)
23  {
24  SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.GetEditableEntity(entity);
25  if (editableEntity)
26  return SpawnPreviewFromEditableEntity(editableEntity, previewPrefab, world, spawnParams, material, flags);
27  else
28  return null;
29  }
39  static SCR_BasePreviewEntity SpawnPreviewFromEditableEntity(SCR_EditableEntityComponent entity, ResourceName previewPrefab, BaseWorld world = null, EntitySpawnParams spawnParams = null, ResourceName material = ResourceName.Empty, EPreviewEntityFlag flags = 0)
40  {
41  if (!entity)
42  {
43  Print("No entity defined", LogLevel.WARNING);
44  return null;
45  }
46  array<ref SCR_BasePreviewEntry> entries = GetPreviewEntriesFromEditableEntity(entity, spawnParams, flags);
47  return SpawnPreview(entries, previewPrefab, world, spawnParams, material, flags);
48  }
58  static SCR_BasePreviewEntity SpawnPreviewFromEditableEntities(notnull set<SCR_EditableEntityComponent> entities, ResourceName previewPrefab, BaseWorld world = null, EntitySpawnParams spawnParams = null, ResourceName material = ResourceName.Empty, EPreviewEntityFlag flags = 0)
59  {
60  if (!entities || entities.IsEmpty())
61  {
62  Print("No editable entities defined", LogLevel.WARNING);
63  return null;
64  }
65 
66  EntitySpawnParams spawnParamsLocal = spawnParams;
67  if (!spawnParamsLocal)
68  spawnParamsLocal = new EntitySpawnParams();
69 
70  TraceParam trace;
71  array<IEntity> excludeArray = {};
72  if (SCR_Enum.HasFlag(flags, EPreviewEntityFlag.GEOMETRY))
73  trace = new TraceParam();
74 
75  array<ref SCR_BasePreviewEntry> entries = {};
76  set<SCR_EditableEntityComponent> entitiesCopy = new set<SCR_EditableEntityComponent>;
77  entitiesCopy.Copy(entities);
78  int index;
79  while (!entitiesCopy.IsEmpty())
80  {
81  SCR_EditableEntityComponent entity = entitiesCopy[index];
82  SCR_EditableEntityComponent entityParent = entity.GetParentEntity();
83  if (entityParent && entitiesCopy.Find(entityParent) != -1)
84  {
85  //--- Parent is edited, but not registered yet; skip
86  index++;
87  continue;
88  }
89  else
90  {
91  GetPreviewEntries(entity, entries, spawnParamsLocal.Transform, -1, flags, trace);
92  entitiesCopy.Remove(index);
93  index = 0;
94  }
95  }
96  return SpawnPreview(entries, previewPrefab, world, spawnParamsLocal, material, flags);
97  }
98 
106  static array<ref SCR_BasePreviewEntry> GetPreviewEntriesFromEditableEntity(SCR_EditableEntityComponent entity, out EntitySpawnParams spawnParams = null, EPreviewEntityFlag flags = 0)
107  {
108  if (!spawnParams)
109  spawnParams = new EntitySpawnParams();
110 
111  TraceParam trace;
112  if (SCR_Enum.HasFlag(flags, EPreviewEntityFlag.GEOMETRY))
113  trace = new TraceParam();
114 
115  array<ref SCR_BasePreviewEntry> entries = {};
116  GetPreviewEntries(entity, entries, spawnParams.Transform, -1, flags, trace);
117  return entries;
118  }
119 
126  static void GetPreviewEntries(SCR_EditableEntityComponent entity, out notnull array<ref SCR_BasePreviewEntry> outEntries, out vector rootTransform[4], int parentID = -1, EPreviewEntityFlag flags = 0, TraceParam trace = null)
127  {
128  IEntity owner = entity.GetOwner();
129  vector transform[4];
130  if (parentID == -1)
131  {
132  entity.GetTransform(transform);
133  SaveRootTransform(transform, rootTransform);
134  }
135  else
136  {
137  //--- Skip entities flagged by IGNORE_LAYERS when their patrent is edited as well (e.g., don't move waypoints when moving a group)
138  if (entity.HasEntityFlag(EEditableEntityFlag.IGNORE_LAYERS))
139  return;
140 
141  //--- Skip the entity if...
142  if (
143  //--- ... it has an object (e.g., not a composition folder)...
144  owner.GetVObject()
145  &&
146  (
147  //--- ... but the object does not have a mesh (e.g., particle effect)...
148  (!owner.GetVObject().ToMeshObject())
149  ||
150  //--- ... or the object is not visible or is not intended for play mode
151  (!(owner.GetFlags() & EntityFlags.VISIBLE) || (owner.GetFlags() & EntityFlags.EDITOR_ONLY))
152  )
153  )
154  return;
155 
156  entity.GetLocalTransform(transform);
157  }
158 
159  SCR_BasePreviewEntry entry = new SCR_BasePreviewEntry(true);
160  entry.m_iParentID = parentID;
161  parentID = outEntries.Insert(entry);
162 
163  entry.m_Entity = owner;
164  entry.SaveTransform(transform);
165  entry.SetScale(GetLocalScale(entry.m_Entity));
166  entry.m_iPivotID = GetPivotName(entry.m_Entity);
167 
168  if (GetMesh(entry.m_Entity, flags, entry, outEntries))
169  return;
170 
171  entry.m_Flags |= EPreviewEntityFlag.EDITABLE;
172 
173  if (entity.HasEntityFlag(EEditableEntityFlag.HORIZONTAL))
174  entry.m_Flags |= EPreviewEntityFlag.HORIZONTAL;
175 
176  if (entity.HasEntityFlag(EEditableEntityFlag.ORIENT_CHILDREN))
177  entry.m_Flags |= EPreviewEntityFlag.ORIENT_CHILDREN;
178 
179  if (!SCR_Enum.HasFlag(flags, EPreviewEntityFlag.IGNORE_TERRAIN))
180  {
181  bool isUnderwater = SCR_Enum.HasFlag(flags, EPreviewEntityFlag.UNDERWATER);
182  SaveTerrainTransform(entry.m_Entity, entry, isUnderwater, trace);
183  }
184  else
185  {
186  //--- Don't calculate terrain under entity, but use default values. Without it, entities with modified pitch or bank would have them reset.
187  entry.m_vAnglesTerrain = Vector(0, entry.m_vAngles[1], entry.m_vAngles[2]);
188  entry.m_vHeightTerrain = entry.m_vPosition[1];
189  }
190 
191  if (entry.m_Shape != EPreviewEntityShape.PREFAB)
192  {
193  //--- Scan children
194  set<IEntity> childOwners = new set<IEntity>();
195 
196  //--- In editor hierarchy (ignore when children are shown individually, e.g., soldiers in a group, to prevent duplicate previews)
197  if (!entity.HasEntityFlag(EEditableEntityFlag.INDIVIDUAL_CHILDREN) || SCR_Enum.HasFlag(flags, EPreviewEntityFlag.IGNORE_TERRAIN))
198  {
199  set<SCR_EditableEntityComponent> children = entity.GetChildrenRef();
200  if (children)
201  {
202  for (int i = 0, count = children.Count(); i < count; i++)
203  {
204  GetPreviewEntries(children[i], outEntries, rootTransform, parentID, flags);
205  childOwners.Insert(children[i].GetOwner());
206  }
207  }
208  }
209 
210  //--- In engine hierarchy
211  if (!SCR_Enum.HasFlag(flags, EPreviewEntityFlag.ONLY_EDITABLE))
212  {
213  IEntity child = entry.m_Entity.GetChildren();
214  while (child)
215  {
216  if (!childOwners.Contains(child)) //--- Check for duplicates with editor hierarchy
217  GetPreviewEntries(child, outEntries, rootTransform, parentID, flags);
218 
219  child = child.GetSibling();
220  }
221  }
222  }
223  }
224 
229  SCR_EditableEntityComponent GetEditableEntity()
230  {
231  return m_EditableEntity;
232  }
237  array<IEntity> GetExcludeArray()
238  {
239  return m_aExcludeArray;
240  }
241 
242  protected override void EOnPreviewInit(SCR_BasePreviewEntry entry, SCR_BasePreviewEntity root)
243  {
244  super.EOnPreviewInit(entry, root);
245  m_EditableEntity = SCR_EditableEntityComponent.GetEditableEntity(entry.m_Entity);
246 
247  if (entry.m_iParentID == -1 || (SCR_Enum.HasFlag(m_Flags, EPreviewEntityFlag.REGISTER_EDITABLE)))
248  {
249  //--- Let the preview copy appearance of source's editable entity
250  SCR_EditablePreviewComponent previewEditableEntity = SCR_EditablePreviewComponent.Cast(FindComponent(SCR_EditablePreviewComponent));
251  if (previewEditableEntity)
252  {
253  if (m_EditableEntity)
254  previewEditableEntity.InitFromEntity(m_EditableEntity);
255  else
256  previewEditableEntity.InitFromSource(SCR_BaseContainerTools.FindComponentSource(entry.m_EntitySource, SCR_EditableEntityComponent));
257  }
258  }
259  }
260  override protected void EOnRootPreviewInit(array<ref SCR_BasePreviewEntry> entries)
261  {
262  m_aExcludeArray = {};
263  foreach (SCR_BasePreviewEntry entry: entries)
264  {
265  m_aExcludeArray.Insert(entry.m_Entity);
266  }
267  }
268 };
EEditableEntityFlag
EEditableEntityFlag
Unique flags of the entity.
Definition: EEditableEntityFlag.c:5
SCR_Enum
Definition: SCR_Enum.c:1
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_BasePreviewEntry
Definition: SCR_BasePreviewEntry.c:2
SCR_EditablePreviewEntity
Definition: SCR_EditablePreviewEntity.c:8
EPreviewEntityShape
EPreviewEntityShape
Definition: EPreviewEntityMesh.c:1
SCR_BasePreviewEntity
Definition: SCR_BasePreviewEntity.c:9
SCR_GenericPreviewEntity
Definition: SCR_GenericPreviewEntity.c:8
SCR_EditablePreviewEntityClass
Definition: SCR_EditablePreviewEntity.c:2
EPreviewEntityFlag
EPreviewEntityFlag
Definition: EPreviewEntityFlag.c:1
SpawnPreview
void SpawnPreview()
Create a preview if it does not exist.
Definition: SCR_CampaignBuildingLayoutComponent.c:244
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
SCR_BaseContainerTools
Definition: SCR_BaseContainerTools.c:3
SCR_GenericPreviewEntityClass
Definition: SCR_GenericPreviewEntity.c:2
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180