10 using System.Runtime.InteropServices;
14 [RequireComponent(typeof(MeshRenderer))]
17 public float FeatureSize = 1.0f;
19 private Renderer meshRenderer;
21 public Camera arCamera;
22 private MeshFilter meshFilter = null;
24 void OnApplicationPause(
bool pause)
28 Destroy(this.meshFilter);
32 private void Generate(Vector3[] vertex)
35 if (this.meshFilter == null)
37 this.meshFilter = gameObject.AddComponent<MeshFilter>();
38 meshFilter.mesh =
new Mesh();
39 meshFilter.mesh.name =
"Procedural Grid";
40 meshRenderer = GetComponent<Renderer>();
41 meshRenderer.material.SetFloat(
"_Type", 1.0f);
42 meshRenderer.material.SetFloat(
"_FeatureSize", FeatureSize);
45 Matrix4x4 projectionMatrix = arCamera.projectionMatrix;
47 if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer)
49 Matrix4x4 orientationMatrix = Matrix4x4.Scale(
new Vector3(1.0f, 1.0f, 1.0f));
50 projectionMatrix = projectionMatrix * orientationMatrix;
54 Matrix4x4 orientationMatrix = Matrix4x4.Scale(
new Vector3(1.0f, -1.0f, 1.0f));
55 projectionMatrix = projectionMatrix * orientationMatrix;
58 meshRenderer.material.SetMatrix(
"projectionMatrix", projectionMatrix);
60 Vector3[] vertices =
new Vector3[vertex.Length << 2];
62 for (
int i = 0; i < vertex.Length; i++)
64 vertices[0 + (i << 2)] = vertex[i];
65 vertices[1 + (i << 2)] = vertex[i];
66 vertices[2 + (i << 2)] = vertex[i];
67 vertices[3 + (i << 2)] = vertex[i];
70 meshFilter.mesh.vertices = vertices;
72 int[] triangles =
new int[vertex.Length * 6];
74 for (
int i = 0; i < vertex.Length; i++)
76 triangles[0 + (i * 6)] = 0 + (i << 2);
77 triangles[1 + (i * 6)] = 1 + (i << 2);
78 triangles[2 + (i * 6)] = 2 + (i << 2);
79 triangles[3 + (i * 6)] = 3 + (i << 2);
80 triangles[4 + (i * 6)] = 2 + (i << 2);
81 triangles[5 + (i * 6)] = 1 + (i << 2);
84 meshFilter.mesh.triangles = triangles;
86 Vector2[] uv =
new Vector2[vertex.Length << 2];
88 for (
int i = 0; i < vertex.Length; i++)
90 uv[0 + (i << 2)] =
new Vector2(0, 0);
91 uv[1 + (i << 2)] =
new Vector2(1, 0);
92 uv[2 + (i << 2)] =
new Vector2(0, 1);
93 uv[3 + (i << 2)] =
new Vector2(1, 1);
96 meshFilter.mesh.uv = uv;
99 private Vector3[] convertFloatToVertex3(
float[] vertex,
int count)
106 Vector3[] tempVertex =
new Vector3[count];
108 for (
int i = 0; i < count; i++)
110 tempVertex[i] =
new Vector3(vertex[0 + (i * 3)], vertex[1 + (i * 3)], vertex[2 + (i * 3)]);
118 GetComponent<Renderer>().material.renderQueue = 1600;
119 transform.localScale = arCamera.transform.localScale;
120 transform.localRotation = arCamera.transform.localRotation;
121 transform.localPosition = arCamera.transform.localPosition;
123 if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D9 ||
124 SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11 ||
125 SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D12 ||
126 SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLCore)
128 transform.localScale =
new Vector3(1.0f, -1.0f, 1.0f);
132 private void Update()
134 if (this.meshFilter != null)
136 meshFilter.mesh.Clear();
142 if (featureCount == 0)
147 if (featureCount > 0)
150 Vector3[] vertexVector3Array = convertFloatToVertex3(featureBuffer, featureCount);
152 Generate(vertexVector3Array);
float [] GetFeatureBuffer()
Get projected feature buffer for SLAM (Always returns same address so vertex count must be considered...
int GetFeatureCount()
Get projected feature count in SLAM (float * 3 = 1 feature)
Contains surface's data generated from slam tracking
GuideInfo GetGuideInfo()
Get guide information of the found surface on SLAM after the FindSurface method has been called ...
static TrackerManager GetInstance()
Get TrackerManager instance
Control AR Engine (Singletone)