/// <summary> /// this is called after the mesh ready notification from the ObjectLoader /// class where the mesh is assigned to the gameObject's meshfilter /// component attached to the GameObject. /// </summary> /// <param name="mesh">Mesh.</param> public static void getMeshObj(ref Mesh mesh) { if (Application.platform == RuntimePlatform.IPhonePlayer) { MeshObjPlugin meshObjPlugin = new MeshObjPlugin(); // this calls the plugin for the latest mesh once we're done // scanning the scene for a mesh. _getMeshObj(ref meshObjPlugin); // this is the rather slow method call which can take a second or two // to marshal copy form the plugin to the unity scene convertMeshObj(ref meshObjPlugin, ref mesh); } else { Debug.Log("not supported"); } }
static void convertMeshObj(ref MeshObjPlugin meshObjPlugin, ref Mesh mesh) { int numVertices = meshObjPlugin.numberOfMeshVertices; int numFaces = meshObjPlugin.numberOfMeshFaces; if (numVertices == 0 || numFaces == 0) { mesh = null; Debug.Log("Mesh doesn't contain any vertices or faces!"); return; } float[] tmpVertices = new float[numVertices * 3]; float[] tmpNormals = new float[numVertices * 3]; short[] tmpTriangles = new short[numFaces * 3]; Marshal.Copy(meshObjPlugin.vertices, tmpVertices, 0, numVertices * 3); Marshal.Copy(meshObjPlugin.normals, tmpNormals, 0, numVertices * 3); Marshal.Copy(meshObjPlugin.triangles, tmpTriangles, 0, numFaces * 3); Vector3[] vertices = null; Vector3[] normals = null; int[] triangles = null; convertVertices(ref tmpVertices, ref vertices, new Vector3(meshObjPlugin.meshOffsetX, meshObjPlugin.meshOffsetY, meshObjPlugin.meshOffsetZ)); convertNormals(ref tmpNormals, ref normals); convertFaces(ref tmpTriangles, ref triangles); mesh.vertices = vertices; mesh.normals = normals; mesh.triangles = triangles; }
private static extern void _getMeshObj(ref MeshObjPlugin mesh);
static void convertMeshObj(ref MeshObjPlugin meshObjPlugin, ref Mesh mesh) { int numVertices = meshObjPlugin.numberOfMeshVertices; int numFaces = meshObjPlugin.numberOfMeshFaces; if(numVertices == 0 || numFaces == 0) { mesh = null; Debug.Log("Mesh doesn't contain any vertices or faces!"); return; } float[] tmpVertices = new float[numVertices * 3]; float[] tmpNormals = new float[numVertices * 3]; short[] tmpTriangles = new short[numFaces * 3]; Marshal.Copy(meshObjPlugin.vertices, tmpVertices, 0, numVertices * 3); Marshal.Copy(meshObjPlugin.normals, tmpNormals, 0, numVertices * 3); Marshal.Copy(meshObjPlugin.triangles, tmpTriangles, 0, numFaces * 3); Vector3[] vertices = null; Vector3[] normals = null; int[] triangles = null; convertVertices(ref tmpVertices, ref vertices, new Vector3(meshObjPlugin.meshOffsetX, meshObjPlugin.meshOffsetY, meshObjPlugin.meshOffsetZ)); convertNormals(ref tmpNormals, ref normals); convertFaces(ref tmpTriangles, ref triangles); mesh.vertices = vertices; mesh.normals = normals; mesh.triangles = triangles; }
/// <summary> /// this is called after the mesh ready notification from the ObjectLoader /// class where the mesh is assigned to the gameObject's meshfilter /// component attached to the GameObject. /// </summary> /// <param name="mesh">Mesh.</param> public static void getMeshObj(ref Mesh mesh) { if(Application.platform == RuntimePlatform.IPhonePlayer) { MeshObjPlugin meshObjPlugin = new MeshObjPlugin(); // this calls the plugin for the latest mesh once we're done // scanning the scene for a mesh. _getMeshObj(ref meshObjPlugin); // this is the rather slow method call which can take a second or two // to marshal copy form the plugin to the unity scene convertMeshObj(ref meshObjPlugin, ref mesh); } else { Debug.Log("not supported"); } }