Beispiel #1
0
        public static CruncherIO RetrieveMesh(int meshId, bool recalculateNormals, bool retrieveOriginalIndexes = false)
        {
            if (!CruncherPluginManager.PluginQueryMeshSizes(meshId, CruncherPluginManager.cruncherPluginManager.arrayLengths))
            {
                Debug.LogError(CruncherPluginManager.errorOperationFailed);
                return(null);
            }
            int num = CruncherPluginManager.cruncherPluginManager.arrayLengths[0];

            CruncherPluginManager.cruncherPluginManager.cruncherData.vertices  = new Vector3[num];
            CruncherPluginManager.cruncherPluginManager.cruncherData.triangles = new int[CruncherPluginManager.cruncherPluginManager.arrayLengths[1]];
            if (CruncherPluginManager.cruncherPluginManager.arrayLengths[2] == num)
            {
                CruncherPluginManager.cruncherPluginManager.cruncherData.normals = new Vector3[num];
            }
            else
            {
                Debug.Log("PluginQueryMeshSizes says normal array length is " + CruncherPluginManager.cruncherPluginManager.arrayLengths[2]);
            }
            if (CruncherPluginManager.cruncherPluginManager.arrayLengths[3] == num)
            {
                CruncherPluginManager.cruncherPluginManager.cruncherData.uv0s = new Vector2[num];
            }
            if (CruncherPluginManager.cruncherPluginManager.arrayLengths[4] == num)
            {
                CruncherPluginManager.cruncherPluginManager.cruncherData.uv1s = new Vector2[num];
            }
            int num2 = 0;

            for (int i = 0; i < CruncherPluginManager.cruncherPluginManager.arrayLengths[6]; i++)
            {
                num2 += CruncherPluginManager.cruncherPluginManager.arrayLengths[7 + i];
            }
            CruncherPluginManager.cruncherPluginManager.cruncherData.subMeshTriangles = new int[num2];
            CruncherPluginManager.UserData userData = CruncherPluginManager.cruncherPluginManager.userData;
            if (retrieveOriginalIndexes || userData.colors != null || userData.boneWeights != null || userData.tangents != null)
            {
                CruncherPluginManager.cruncherPluginManager.cruncherData.originalIndexes = new int[num];
            }
            if (!CruncherPluginManager.PluginRetrieveMesh(meshId, CruncherPluginManager.cruncherPluginManager.cruncherData, CruncherPluginManager.cruncherPluginManager.arrayLengths, recalculateNormals))
            {
                Debug.LogError(CruncherPluginManager.errorOperationFailed);
                CruncherPluginManager.cruncherPluginManager.cruncherData = default(CruncherPluginManager.CruncherData);
                return(null);
            }
            CruncherIO cruncherIO = new CruncherIO();

            cruncherIO.vertices         = CruncherPluginManager.cruncherPluginManager.cruncherData.vertices;
            cruncherIO.triangles        = CruncherPluginManager.cruncherPluginManager.cruncherData.triangles;
            cruncherIO.normals          = CruncherPluginManager.cruncherPluginManager.cruncherData.normals;
            cruncherIO.uv0s             = CruncherPluginManager.cruncherPluginManager.cruncherData.uv0s;
            cruncherIO.uv1s             = CruncherPluginManager.cruncherPluginManager.cruncherData.uv1s;
            cruncherIO.subMeshTriangles = new int[CruncherPluginManager.cruncherPluginManager.arrayLengths[6]][];
            int num3 = 0;

            for (int j = 0; j < cruncherIO.subMeshTriangles.Length; j++)
            {
                cruncherIO.subMeshTriangles[j] = new int[CruncherPluginManager.cruncherPluginManager.arrayLengths[7 + j]];
                Array.Copy(CruncherPluginManager.cruncherPluginManager.cruncherData.subMeshTriangles, num3, cruncherIO.subMeshTriangles[j], 0, cruncherIO.subMeshTriangles[j].Length);
                num3 += cruncherIO.subMeshTriangles[j].Length;
            }
            cruncherIO.bindPoses       = userData.bindPoses;
            cruncherIO.originalIndexes = CruncherPluginManager.cruncherPluginManager.cruncherData.originalIndexes;
            if (cruncherIO.originalIndexes != null && cruncherIO.originalIndexes.Length == cruncherIO.vertices.Length && (userData.colors != null || userData.boneWeights != null || userData.tangents != null))
            {
                if (userData.colors != null && userData.colors.Length > 0)
                {
                    cruncherIO.colors = new Color[num];
                }
                if (userData.boneWeights != null && userData.boneWeights.Length > 0)
                {
                    cruncherIO.boneWeights = new BoneWeight[num];
                }
                if (userData.tangents != null && userData.tangents.Length > 0)
                {
                    cruncherIO.tangents = new Vector4[num];
                }
                for (int k = 0; k < num; k++)
                {
                    if (userData.colors != null && userData.colors.Length > 0)
                    {
                        cruncherIO.colors[k] = userData.colors[cruncherIO.originalIndexes[k]];
                    }
                    if (userData.boneWeights != null && userData.boneWeights.Length > 0)
                    {
                        cruncherIO.boneWeights[k] = userData.boneWeights[cruncherIO.originalIndexes[k]];
                    }
                    if (userData.tangents != null && userData.tangents.Length > 0)
                    {
                        cruncherIO.tangents[k] = userData.tangents[cruncherIO.originalIndexes[k]];
                    }
                }
            }
            if (!retrieveOriginalIndexes)
            {
                cruncherIO.originalIndexes = null;
            }
            CruncherPluginManager.cruncherPluginManager.cruncherData = default(CruncherPluginManager.CruncherData);
            return(cruncherIO);
        }
Beispiel #2
0
        public static int AddMesh(CruncherIO cruncherIO, CruncherMeshConfiguration cruncherMeshConfiguration)
        {
            if (CruncherPluginManager.cruncherPluginManager == null && !CruncherPluginManager.Startup(""))
            {
                return(-1);
            }
            if (cruncherIO == null || cruncherIO.vertices == null || cruncherIO.triangles == null)
            {
                Debug.LogError("Invalid CruncherIO object, aborting AddMesh.");
                return(-1);
            }
            CruncherPluginManager.cruncherPluginManager.cruncherData.vertices  = cruncherIO.vertices;
            CruncherPluginManager.cruncherPluginManager.cruncherData.triangles = cruncherIO.triangles;
            CruncherPluginManager.cruncherPluginManager.cruncherData.normals   = cruncherIO.normals;
            CruncherPluginManager.cruncherPluginManager.cruncherData.uv0s      = cruncherIO.uv0s;
            CruncherPluginManager.cruncherPluginManager.cruncherData.uv1s      = cruncherIO.uv1s;
            int num = cruncherIO.subMeshTriangles.Length;

            CruncherPluginManager.cruncherPluginManager.arrayLengths    = new int[7 + num];
            CruncherPluginManager.cruncherPluginManager.arrayLengths[6] = num;
            CruncherPluginManager.cruncherPluginManager.arrayLengths[0] = CruncherPluginManager.cruncherPluginManager.cruncherData.vertices.Length;
            CruncherPluginManager.cruncherPluginManager.arrayLengths[1] = CruncherPluginManager.cruncherPluginManager.cruncherData.triangles.Length;
            if (CruncherPluginManager.cruncherPluginManager.cruncherData.normals != null)
            {
                CruncherPluginManager.cruncherPluginManager.arrayLengths[2] = CruncherPluginManager.cruncherPluginManager.cruncherData.normals.Length;
            }
            if (CruncherPluginManager.cruncherPluginManager.cruncherData.uv0s != null)
            {
                CruncherPluginManager.cruncherPluginManager.arrayLengths[3] = CruncherPluginManager.cruncherPluginManager.cruncherData.uv0s.Length;
            }
            if (CruncherPluginManager.cruncherPluginManager.cruncherData.uv1s != null)
            {
                CruncherPluginManager.cruncherPluginManager.arrayLengths[4] = CruncherPluginManager.cruncherPluginManager.cruncherData.uv1s.Length;
            }
            CruncherPluginManager.cruncherPluginManager.cruncherData.lockedVertices = cruncherIO.lockedVertices;
            if (CruncherPluginManager.cruncherPluginManager.cruncherData.lockedVertices != null)
            {
                CruncherPluginManager.cruncherPluginManager.arrayLengths[5] = CruncherPluginManager.cruncherPluginManager.cruncherData.lockedVertices.Length;
            }
            int num2 = 0;

            for (int i = 0; i < num; i++)
            {
                num2 += cruncherIO.subMeshTriangles[i].Length;
            }
            CruncherPluginManager.cruncherPluginManager.cruncherData.subMeshTriangles = new int[num2];
            int num3 = 0;

            for (int j = 0; j < num; j++)
            {
                CruncherPluginManager.cruncherPluginManager.arrayLengths[7 + j] = cruncherIO.subMeshTriangles[j].Length;
                Array.Copy(cruncherIO.subMeshTriangles[j], 0, CruncherPluginManager.cruncherPluginManager.cruncherData.subMeshTriangles, num3, cruncherIO.subMeshTriangles[j].Length);
                num3 += cruncherIO.subMeshTriangles[j].Length;
            }
            if (cruncherMeshConfiguration != null)
            {
                CruncherPluginManager.cruncherPluginManager.meshConfiguration.joinVertices          = cruncherMeshConfiguration.joinVertices;
                CruncherPluginManager.cruncherPluginManager.meshConfiguration.joinVerticesThreshold = cruncherMeshConfiguration.joinVerticesThreshold;
                CruncherPluginManager.cruncherPluginManager.meshConfiguration.joinNormals           = cruncherMeshConfiguration.joinNormals;
                CruncherPluginManager.cruncherPluginManager.meshConfiguration.joinNormalsThreshold  = cruncherMeshConfiguration.joinNormalsThreshold;
                CruncherPluginManager.cruncherPluginManager.meshConfiguration.joinUvs                   = cruncherMeshConfiguration.joinUvs;
                CruncherPluginManager.cruncherPluginManager.meshConfiguration.joinUvsThreshold          = cruncherMeshConfiguration.joinUvsThreshold;
                CruncherPluginManager.cruncherPluginManager.meshConfiguration.removeTJunctions          = cruncherMeshConfiguration.removeTJunctions;
                CruncherPluginManager.cruncherPluginManager.meshConfiguration.removeTJunctionsThreshold = cruncherMeshConfiguration.removeTJunctionsThreshold;
                CruncherPluginManager.cruncherPluginManager.meshConfiguration.recalculateNormals        = cruncherMeshConfiguration.recalculateNormals;
            }
            else
            {
                Debug.Log("cruncherMeshConfiguration == null, you must pass in a valid CruncherMeshConfiguration in order to process meshes.");
            }
            int num4 = CruncherPluginManager.PluginAddMesh(CruncherPluginManager.cruncherPluginManager.cruncherData, CruncherPluginManager.cruncherPluginManager.arrayLengths, ref CruncherPluginManager.cruncherPluginManager.meshConfiguration);

            CruncherPluginManager.cruncherPluginManager.cruncherData = default(CruncherPluginManager.CruncherData);
            if (num4 < 0)
            {
                Debug.LogError(CruncherPluginManager.errorOperationFailed);
                return(-1);
            }
            CruncherPluginManager.UserData userData = new CruncherPluginManager.UserData();
            if (cruncherIO.colors != null && cruncherIO.colors.Length > 0)
            {
                userData.colors = new Color[cruncherIO.colors.Length];
                Array.Copy(cruncherIO.colors, userData.colors, cruncherIO.colors.Length);
            }
            if (cruncherIO.boneWeights != null && cruncherIO.boneWeights.Length > 0)
            {
                userData.boneWeights = new BoneWeight[cruncherIO.boneWeights.Length];
                Array.Copy(cruncherIO.boneWeights, userData.boneWeights, cruncherIO.boneWeights.Length);
            }
            if (cruncherIO.tangents != null && cruncherIO.tangents.Length > 0)
            {
                userData.tangents = new Vector4[cruncherIO.tangents.Length];
                Array.Copy(cruncherIO.tangents, userData.tangents, cruncherIO.tangents.Length);
            }
            userData.originalVertices = new Vector3[cruncherIO.vertices.Length];
            Array.Copy(cruncherIO.vertices, userData.originalVertices, cruncherIO.vertices.Length);
            userData.bindPoses = cruncherIO.bindPoses;
            CruncherPluginManager.cruncherPluginManager.userData = userData;
            return(num4);
        }