MaxstARSDK  3.5.0
SurfaceMesh.cs
1 /*==============================================================================
2 Copyright 2017 Maxst, Inc. All Rights Reserved.
3 ==============================================================================*/
4 
5 using UnityEngine;
6 using System;
7 using System.Collections.Generic;
8 using System.Linq;
9 using System.Text;
10 using System.Runtime.InteropServices;
11 
12 namespace maxstAR
13 {
17  public class SurfaceMesh
18  {
19  private const int MAX_VERTICES = 1000;
20  private const int MAX_INDICES = 20000;
21 
22  private float progress = 0.0f;
23  private int vertexCount = 0;
24  private int indexCount = 0;
25  private static float[] vertexBuffer = null;
26  private static short[] indexBuffer = null;
27 
28  internal SurfaceMesh()
29  {
30 
31  }
32 
33  internal void UpdateSurfaceMesh()
34  {
35  if (Application.platform == RuntimePlatform.IPhonePlayer)
36  {
37  ulong SurfaceMesh_cPtr = NativeStaticAPI.TrackerManager_getSurfaceMesh();
38  if (SurfaceMesh_cPtr != 0)
39  {
40  progress = NativeStaticAPI.SurfaceMesh_getInitializingProgress(SurfaceMesh_cPtr);
41  vertexCount = NativeStaticAPI.SurfaceMesh_getVertexCount(SurfaceMesh_cPtr);
42  indexCount = NativeStaticAPI.SurfaceMesh_getIndexCount(SurfaceMesh_cPtr);
43 
44  if (vertexBuffer == null)
45  {
46  vertexBuffer = new float[MAX_VERTICES * 3];
47  }
48 
49  if (indexBuffer == null)
50  {
51  indexBuffer = new short[MAX_INDICES];
52  }
53 
54  NativeStaticAPI.SurfaceMesh_getVertexBuffer(SurfaceMesh_cPtr, vertexBuffer, vertexCount * 3);
55  NativeStaticAPI.SurfaceMesh_getIndexBuffer(SurfaceMesh_cPtr, indexBuffer, indexCount);
56  }
57  }
58  else
59  {
60  ulong SurfaceMesh_cPtr = NativeSharedAPI.TrackerManager_getSurfaceMesh();
61  if (SurfaceMesh_cPtr != 0)
62  {
63  progress = NativeSharedAPI.SurfaceMesh_getInitializingProgress(SurfaceMesh_cPtr);
64  vertexCount = NativeSharedAPI.SurfaceMesh_getVertexCount(SurfaceMesh_cPtr);
65  indexCount = NativeSharedAPI.SurfaceMesh_getIndexCount(SurfaceMesh_cPtr);
66 
67  if (vertexBuffer == null)
68  {
69  vertexBuffer = new float[MAX_VERTICES * 3];
70  }
71 
72  if (indexBuffer == null)
73  {
74  indexBuffer = new short[MAX_INDICES];
75  }
76 
77  NativeSharedAPI.SurfaceMesh_getVertexBuffer(SurfaceMesh_cPtr, vertexBuffer, vertexCount * 3);
78  NativeSharedAPI.SurfaceMesh_getIndexBuffer(SurfaceMesh_cPtr, indexBuffer, indexCount);
79  }
80  }
81  }
82 
87  public float GetInitializingProgress()
88  {
89  return progress;
90  }
91 
95  public int GetVertexCount()
96  {
97  return vertexCount;
98  }
99 
103  public int GetIndexCount()
104  {
105  return indexCount;
106  }
107 
112  public float[] GetVertexBuffer()
113  {
114  return vertexBuffer;
115  }
116 
121  public short[] GetIndexBuffer()
122  {
123  return indexBuffer;
124  }
125  }
126 }
float [] GetVertexBuffer()
surface mesh vertex buffer (Always returns same address so vertex count must be considered) ...
Definition: SurfaceMesh.cs:112
float GetInitializingProgress()
Get a percentage of progress during an initialization step of SLAM
Definition: SurfaceMesh.cs:87
short [] GetIndexBuffer()
surface mesh index buffer (Always returns same address so index count must be considered ) ...
Definition: SurfaceMesh.cs:121
Contains surface's mesh data generated from slam tracking
Definition: SurfaceMesh.cs:17