-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointOnSurfaceManager.cs
115 lines (93 loc) · 4.29 KB
/
PointOnSurfaceManager.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//public enum THom3rPointCaptureMode { iddle, capturing, editing };
public class PointOnSurfaceManager : MonoBehaviour
{
//TPointOnSurfaceManagerState currentPointCaptureMode;
string specificAreaId;
GameObject specificAreaGO;
void Awake()
{
//currentPointCaptureMode = TPointOnSurfaceManagerState.iddle;
specificAreaGO = null;
}
/// <summary>
/// Start point capture
/// </summary>
public void StartPointCapture()
{
hom3r.state.selectionBlocked = true;
hom3r.state.currentMode = THom3rMode.capturing_surface_point;
hom3r.state.currentPointCaptureMode = THom3rPointCaptureMode.capturing;
//hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.PointOnSurface_PointCaptureBegin));
this.SendMessageToUI("Please, select a point into the object surface..");
}
public void StartPointCapture(string _areaId)
{
specificAreaId = _areaId;
specificAreaGO = hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().GetAreaGameObject_ByAreaID(specificAreaId);
if (specificAreaGO == null)
{
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.PointOnSurface_PointCaptureError));
Debug.Log("AREA NOT VALID");
} else
{
this.StartPointCapture();
}
}
public bool GetPointCapturingActivated() { return hom3r.state.currentPointCaptureMode == THom3rPointCaptureMode.capturing; }
/// <summary>
/// Capture a point into the surface of an area
/// </summary>
/// <param name="clickPosition"></param>
/// <param name="rayCastedArea"></param>
public void CapturePointOnSurface(Vector3 mousePosition, GameObject rayCastedArea)
{
if (rayCastedArea == null) { return; }
if (hom3r.state.currentPointCaptureMode != THom3rPointCaptureMode.capturing) { return; }
if ((specificAreaGO == null) || (specificAreaGO != rayCastedArea)) { return; }
int productRootLayer = 1 << LayerMask.NameToLayer(hom3r.state.productRootLayer);
Vector3 clickPosition = Raycast(mousePosition, Camera.main, productRootLayer);
Vector3 pointLocal = rayCastedArea.transform.InverseTransformPoint(clickPosition);
string areaId = rayCastedArea.GetComponent<ObjectStateManager>().areaID;
//Emit event
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.PointOnSurface_PointCaptureSuccess, pointLocal, areaId));
hom3r.state.selectionBlocked = false;
hom3r.state.currentMode = THom3rMode.idle;
hom3r.state.currentPointCaptureMode = THom3rPointCaptureMode.iddle;
//hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.PointOnSurface_PointCaptureEnd));
}
public void DrawPointOnSurface(Vector3 pointLocalPosition, string areaID) {
GameObject areaObj = hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().GetAreaGameObject_ByAreaID(areaID);
//Draw point on surface
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
//sphere.transform.parent = areaObj.transform;
sphere.transform.position = areaObj.transform.TransformPoint(pointLocalPosition);
}
/// <summary>Method that use Ray Casting technique</summary>
private Vector3 Raycast(Vector3 mouseCurrentPosition, Camera _camera, int _layer)
{
// Convert mouse position from screen space to three-dimensional space
// Build ray, directed from mouse position to “camera forward” way
Ray ray = _camera.ScreenPointToRay(mouseCurrentPosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity, _layer))
{
return hit.point; // Now, let’s determine intersected GameObject
}
else
{
return Vector3.zero;
}
}
void SendMessageToUI(string _message)
{
SendMessageToUI(_message, 0.0f);
}
void SendMessageToUI(string _message, float _time)
{
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.ModelManagement_ShowMessage, _message, _time));
Debug.Log(_message);
}
}