Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SnapAndOrientToTerrainPlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
3 name: "Snap and Orient Entities to Terrain",
4 shortcut: "Ctrl+PageDown",
5 wbModules: { "WorldEditor" },
6 category: SCR_PluginCategory.WORLDEDITOR_MASS_PROCESSING,
7 awesomeFontCode: 0xF2D1)]
8class SCR_SnapAndOrientToTerrainPlugin : WorkbenchPlugin
9{
10 //------------------------------------------------------------------------------------------------
11 override void Run()
12 {
13 WorldEditor worldEditor = Workbench.GetModule(WorldEditor);
14 if (!worldEditor)
15 return;
16
17 WorldEditorAPI worldEditorAPI = worldEditor.GetApi();
18 if (!worldEditorAPI)
19 return;
20
21 BaseWorld world = worldEditorAPI.GetWorld();
22 if (!world)
23 return;
24
25 worldEditorAPI.BeginEntityAction();
26
27 IEntity parent;
28 vector transform[4], parentTransform[4];
29 vector angles, pos;
31 for (int i, count = worldEditorAPI.GetSelectedEntitiesCount(); i < count; i++)
32 {
33 IEntitySource entitySource = worldEditorAPI.GetSelectedEntity(i);
34 IEntity entity = worldEditorAPI.SourceToEntity(entitySource);
35 entity.GetWorldTransform(transform);
36 if (SCR_TerrainHelper.SnapAndOrientToTerrain(transform, world))
37 {
38 parent = worldEditorAPI.SourceToEntity(worldEditorAPI.EntityToSource(entity).GetParent());
39 if (parent)
40 {
41 parent.GetWorldTransform(parentTransform);
42 Math3D.MatrixInvMultiply4(parentTransform, transform, transform);
43 }
44
45 angles = Math3D.MatrixToAngles(transform);
46 worldEditorAPI.SetVariableValue(entitySource, null, "angles", string.Format("%1 %2 %3", angles[1], angles[0], angles[2]));
47
48 pos = transform[3];
49 //--- Y height relative to ground, use 0 instead of ASL height
50 entitySource.Get("Flags", flags);
51 if (flags & EntityFlags.RELATIVE_Y)
52 pos[1] = 0;
53
54 worldEditorAPI.SetVariableValue(entitySource, null, "coords", string.Format("%1 %2 %3", pos[0], pos[1], pos[2]));
55 }
56 }
57
58 worldEditorAPI.EndEntityAction();
59 }
60}
61#endif // WORKBENCH
SCR_EAIThreatSectorFlags flags
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
ref array< string > angles
override void Run()
proto external void GetWorldTransform(out vector mat[])
See IEntity::GetTransform.
static bool SnapAndOrientToTerrain(out vector transform[4], BaseWorld world=null, bool noUnderwater=false, TraceParam trace=null)
EntityFlags
Various entity flags.
Definition EntityFlags.c:14