Esempio n. 1
0
    /// <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");
        }
    }
Esempio n. 2
0
    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;
    }
Esempio n. 3
0
 private static extern void _getMeshObj(ref MeshObjPlugin mesh);
Esempio n. 4
0
    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;
    }
Esempio n. 5
0
    /// <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");
        }
    }
Esempio n. 6
0
 private static extern void _getMeshObj(ref MeshObjPlugin mesh);