-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOcclusionManager.cs
More file actions
378 lines (339 loc) · 16.5 KB
/
OcclusionManager.cs
File metadata and controls
378 lines (339 loc) · 16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OcclusionManager : MonoBehaviour
{
// Awake is called at start
void Awake()
{
// hom3r.quickLinks.scriptsObject.GetComponent<OcclusionCommandReceiver>().occlusionManager = this.GetComponent<OcclusionManager>();
}
//////////////////////////////
// REMOVE //
//////////////////////////////
public bool IsRemovedGO(GameObject go)
{
return hom3r.quickLinks.scriptsObject.GetComponent<RemoveManager>().IsRemovedGameObject(go);
}
public bool IsRemovedArea(string areaID)
{
return hom3r.quickLinks.scriptsObject.GetComponent<RemoveManager>().IsRemovedArea(areaID);
}
public void RemoveArea(string areaId, THom3rCommandOrigin _origin)
{
if (hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().IsArea(areaId))
{
//TO DO check if the area is alreday removed
GameObject objToRemove = hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().GetAreaGameObject_ByAreaID(areaId);
this.RemoveGameObject(objToRemove, areaId, _origin);
}
else if (hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().IsLeaf(areaId))
{
//1. Perform the remove algorithm
ExecuteRemoveLeaf(areaId, _origin);
//2. Update mode
hom3r.state.currentIsolateMode = THom3rIsolationMode.WITH_REMOVEDNODES;
}
}
/// <summary>Remove a game object from the scene</summary>
/// <param name="objToRemove">Pointer to the object to be hide</param>
public void RemoveGameObject(GameObject objToRemove, string areaID = null, THom3rCommandOrigin _origin = THom3rCommandOrigin.ui)
{
//1. Confirm OFF the area/special node if it's confirmed
hom3r.coreLink.Do(new CSelectionCommand(TSelectionCommands.ConfirmationOff, objToRemove), Constants.undoNotAllowed);
//2. Perform the remove algorithm
if (areaID == null) { areaID = objToRemove.GetComponent<ObjectStateManager>().areaID; }
ExecuteRemove(areaID, _origin);
//3. Update mode
hom3r.state.currentIsolateMode = THom3rIsolationMode.WITH_REMOVEDNODES;
//4. Re-focus
//this.GetComponent<Isolate_Script>().ReFocusIsolatedGO();
}
/// <summary>Change an object to remove state</summary>
/// <param name="goToRemove"></param>
private void ExecuteRemove(string areaID, THom3rCommandOrigin _origin)
{
//Get the areaID of the area selected
//string areaID = goToRemove.GetComponent<ObjectStateManager>().areaID;
if (areaID != null)
{
//Filled _areaList to be selected in a different way, depending of the selection mode
if (hom3r.state.currentSelectionMode == THom3rSelectionMode.AREA)
{
string leafID = this.GetComponent<ModelManager>().GetNodeLeafID_ByAreaID(areaID);
if (leafID != null)
{
// Desconfirm and remove
List<GameObject> areasOfaLeaf = this.GetComponent<ModelManager>().GetAreaGameObjectList_ByLeafID(leafID);
foreach (GameObject go in areasOfaLeaf)
{
//Desconfirm the area if it's confirmed
hom3r.coreLink.Do(new CSelectionCommand(TSelectionCommands.ConfirmationOff, go), Constants.undoNotAllowed);
//Change the state of the object to hide (this method will be in charge of changing the object material)
float duration = hom3r.quickLinks.scriptsObject.GetComponent<ConfigurationManager>().GetDurationRemoveAnimation();
go.GetComponent<ObjectStateManager>().Do(new CObjectVisualStateCommand(TObjectVisualStateCommands.Remove_On, duration));
}
// Send list of areas to WebApp only if the action starts in the UserInterface
if (_origin == THom3rCommandOrigin.ui)
{
List<string> areaIDList = this.GetComponent<ModelManager>().GetAreaList_ByLeafID(leafID);
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.RemovedPart_Activate, areaIDList));
}
}
else { Debug.LogError("areaID not found"); }
}
else if (hom3r.state.currentSelectionMode == THom3rSelectionMode.SPECIAL_NODE)
{
//Select all the areas with the same special ancestor.
string _specialNodeID = this.GetComponent<ModelManager>().GetSpecialAncestorID_ByAreaID(areaID);
List<GameObject> _areaList = this.GetComponent<ModelManager>().GetAreaGameObjectList_BySpecialAncestorID(_specialNodeID);
foreach (var item in _areaList)
{
float duration = hom3r.quickLinks.scriptsObject.GetComponent<ConfigurationManager>().GetDurationRemoveAnimation();
item.GetComponent<ObjectStateManager>().Do(new CObjectVisualStateCommand(TObjectVisualStateCommands.Remove_On, duration));
}
// Send list of areas to WebApp
List<string> areaIDList = this.GetComponent<ModelManager>().GetAreaIDList_BySpecialAncestorID(_specialNodeID);
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.RemovedPart_Activate, areaIDList));
}
}
}
private void ExecuteRemoveLeaf(string leafID, THom3rCommandOrigin _origin)
{
if (leafID != null)
{
// Desconfirm and remove
List<GameObject> areasOfaLeaf = this.GetComponent<ModelManager>().GetAreaGameObjectList_ByLeafID(leafID);
List<string> areaIDList = new List<string>();
foreach (GameObject go in areasOfaLeaf)
{
if (!IsRemovedGO(go))
{
//Desconfirm the area if it's confirmed
hom3r.coreLink.Do(new CSelectionCommand(TSelectionCommands.ConfirmationOff, go), Constants.undoNotAllowed);
//Change the state of the object to hide (this method will be in charge of changing the object material)
float duration = hom3r.quickLinks.scriptsObject.GetComponent<ConfigurationManager>().GetDurationRemoveAnimation();
go.GetComponent<ObjectStateManager>().Do(new CObjectVisualStateCommand(TObjectVisualStateCommands.Remove_On, duration));
areaIDList.Add(go.GetComponent<ObjectStateManager>().areaID); // Save areaID to be sent to the app
}
}
// Send list of areas to WebApp only if the action starts in the UserInterface
if ((_origin == THom3rCommandOrigin.ui) & (areaIDList.Count != 0))
{
//List<string> areaIDList = this.GetComponent<ModelManager>().GetAreaList_ByLeafID(leafID);
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.RemovedPart_Activate, areaIDList));
}
}
else {
Debug.LogError("areaID not found");
}
}
public void ShowRemovedArea(string areaID, THom3rCommandOrigin _origin)
{
GameObject objToShow = hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().GetAreaGameObject_ByAreaID(areaID);
this.ShowRemovedGameObject(objToShow, _origin);
}
public void ShowRemovedGameObject(GameObject obj, THom3rCommandOrigin _origin = THom3rCommandOrigin.ui)
{
List<string> areaIdList = new List<string>();
if (hom3r.quickLinks.scriptsObject.GetComponent<RemoveManager>().IsRemovedGameObject(obj)) {
if (obj.GetComponent<ObjectStateManager>() != null)
{
float duration = hom3r.quickLinks.scriptsObject.GetComponent<ConfigurationManager>().GetDurationRemoveAnimation();
obj.GetComponent<ObjectStateManager>().Do(new CObjectVisualStateCommand(TObjectVisualStateCommands.Remove_Off, duration));
areaIdList.Add(obj.GetComponent<ObjectStateManager>().areaID);
}
if ((areaIdList.Count != 0) && (_origin == THom3rCommandOrigin.ui))
{
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.RemovedPart_Deactivated, areaIdList));
}
}
}
public void StartStopRemoveMode()
{
if (hom3r.state.currentMode == THom3rMode.remove) { this.StopRemoveMode(); }
else { this.StartRemoveMode(); }
}
private void StartRemoveMode()
{
hom3r.state.currentMode = THom3rMode.remove;
if (hom3r.state.currentIsolateMode == THom3rIsolationMode.idle)
{
hom3r.state.currentIsolateMode = THom3rIsolationMode.WITH_REMOVEDNODES;
}
}
private void StopRemoveMode()
{
if (hom3r.state.currentMode == THom3rMode.remove)
{
hom3r.state.currentMode = THom3rMode.idle;
}
}
//////////////////////////////
// TRANSPARENCY //
//////////////////////////////
public void StartSmartTransparency(THom3rCommandOrigin _origin)
{
this.GetComponent<TransparencyManager>().SmartTransparencyStart(); // Start transparency
// Indicate to others
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.Occlusion_SmartTransparency_Enabled, _origin));
}
public void StopSmartTransparency(THom3rCommandOrigin _origin, bool _instanlly = false )
{
//Execute stop tranparency algorithms
this.GetComponent<TransparencyManager>().SmartTransparencyStop();
//Reset objects materials
hom3r.quickLinks.scriptsObject.GetComponent<TransparencyManager>().AllGameObjectTransparencyOff(_instanlly);
//hom3r.quickLinks.scriptsObject.GetComponent<HiddenManager>().RevealAllHiddenGameObjects();
//Execute stop tranparency algorithms
//hom3r.state.smartTransparencyModeActive = false;
//ExecuteSmartTransparency(false);
// Indicate to others
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.Occlusion_SmartTransparency_Disabled, _origin));
}
/// <summary>Execute SmartTransaprency</summary>
/// <param name="status">true=start, false = stop</param>
//private void ExecuteSmartTransparency(bool status)
//{
// if (status)
// {
// //Start Smart Transparency
// this.GetComponent<TransparencyManager>().SmartTransparencyStart();
// }
// else
// {
// //Stop Smart Transparency
// this.GetComponent<TransparencyManager>().SmartTransparencyStop();
// }
//}
//////////////////////////////
// EXPLOSION //
//////////////////////////////
public void StartGlobalExplosion()
{
if (!hom3r.quickLinks._3DModelRoot.GetComponent<ExplosionManager>().IsEmpty())
{
ExecuteExplosion(true, "global");
//hom3r.coreLink.Do(new UICoreCommand(TUICommands.DisableExplodelayoutButton), Constants.undoNotAllowed); //Disable LayoutExplosion
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.Occlusion_ExplosionGlobalON));
hom3r.state.currentExplosionMode = THom3rExplosionMode.EXPLODE;
}
}
public void RevertGlobalExplosion()
{
ExecuteExplosion(false, "global");
//hom3r.coreLink.Do(new UICoreCommand(TUICommands.EnableExplodelayoutButton), Constants.undoNotAllowed); //Enable LayoutExplosion
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.Occlusion_ExplosionGlobalOFF));
hom3r.state.currentExplosionMode = THom3rExplosionMode.IMPLODE;
}
public void StartLocalExplosionMode()
{
if (!hom3r.quickLinks._3DModelRoot.GetComponent<ExplosionManager>().IsEmpty())
{
hom3r.state.currentMode = THom3rMode.local_explosion;
}
}
public void StopLocalExplosionMode()
{
hom3r.state.currentMode = THom3rMode.idle;
if (hom3r.quickLinks._3DModelRoot.GetComponent<ExplosionManager>().IsAnyObjectExploded())
{
hom3r.state.currentExplosionMode = THom3rExplosionMode.EXPLODE;
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.Occlusion_ExplosionChangedMode));
}
else
{
hom3r.state.currentExplosionMode = THom3rExplosionMode.IMPLODE;
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.Occlusion_ExplosionChangedMode));
}
}
/// <summary>Execute Explosion</summary>
/// <param name="status">true=start, false=stop</param>
/// <param name="type">Type of explosion, allow "global" or "focussed".</param>
private void ExecuteExplosion(bool status, string type)
{
if (status)
{
if (type == "global")
{
//Start Explosion
hom3r.quickLinks._3DModelRoot.GetComponent<ExplosionManager>().Implode();
hom3r.quickLinks._3DModelRoot.GetComponent<ExplosionManager>().Explode(1.0f);
}
else if (type == "focussed")
{
//Start Explosion
hom3r.quickLinks._3DModelRoot.GetComponent<ExplosionManager>().ExplodeConfirmedAll();
}
}
else
{
//Stop Explosion
hom3r.quickLinks._3DModelRoot.GetComponent<ExplosionManager>().Implode();
}
}
//////////////////////////////
// ISOLATE //
//////////////////////////////
public void StartIsolate()
{
if (hom3r.quickLinks.scriptsObject.GetComponent<SelectionManager>().GetNumberOfConfirmedGameObjects() > 0)
{
//Stop transparency mode if is activated
if (hom3r.state.smartTransparencyModeActive)
{
hom3r.coreLink.Do(new COcclusionCommand(TOcclusionCommands.DisableSmartTransparency), Constants.undoNotAllowed);
}
//1. Update Core mode
hom3r.state.currentIsolateMode = THom3rIsolationMode.ISOLATE;
//2. Execute algorithms
hom3r.quickLinks.scriptsObject.GetComponent<IsolateManager>().StartIsolateMode();
}
else
{
//TODO: Show messege in UI
//m.GetComponent<Core>().Do(new UICoreCommand(TUICommands.ShowAlertText, "No product was selected: there is nothing to focus"), Constants.undoNotAllowed);
}
}
public void ShowAll()
{
//Exit transparency mode if is activate
if (hom3r.state.smartTransparencyModeActive)
{
hom3r.coreLink.Do(new COcclusionCommand(TOcclusionCommands.DisableSmartTransparency), Constants.undoNotAllowed);
}
if (hom3r.state.currentIsolateMode == THom3rIsolationMode.ISOLATE)
{
//1. Update Core mode
hom3r.state.currentIsolateMode = THom3rIsolationMode.idle;
//2. Execute algorithms
hom3r.quickLinks.scriptsObject.GetComponent<IsolateManager>().StopIsolateMode();
//3. Update buttons
if (hom3r.state.currentMode == THom3rMode.capturing_surface_point)
{
// hom3r.quickLinks.uiObject.GetComponent<UIManager>().UpdateDisableButtons_SinglePointMode(true);
}
}
else if (hom3r.state.currentIsolateMode == THom3rIsolationMode.WITH_REMOVEDNODES)
{
//1. Update Core mode
hom3r.state.currentIsolateMode = THom3rIsolationMode.idle;
//2. Execute algorithms
hom3r.quickLinks.scriptsObject.GetComponent<RemoveManager>().RevealAllRemovedGameObjects();
}
}
public void UpdateOcclusionMode()
{
// Do nothing for now
}
public void ResetOcclusionProcess()
{
hom3r.quickLinks._3DModelRoot.GetComponent<ExplosionManager>().Clear(); // Clear Explosion
hom3r.quickLinks.scriptsObject.GetComponent<TransparencyManager>().AllGameObjectTransparencyOff();
hom3r.quickLinks.scriptsObject.GetComponent<HiddenManager>().RevealAllHiddenGameObjects();
//Execute stop tranparency algorithms
this.GetComponent<TransparencyManager>().SmartTransparencyStop();
// Update Isolate state
hom3r.state.currentIsolateMode = THom3rIsolationMode.idle;
}
}