Ejemplo n.º 1
0
        public static void CreateMeshesFromCaronte(CaronteSharp.MeshComplex[] arrCaronteMesh, out UnityEngine.Mesh[] arrMesh, out Tuple2 <int, int>[] arrSubmeshRange, out int[] meshComplexIndex)
        {
            int numMeshes = arrCaronteMesh.Length;

            List <Mesh> listMesh = new List <Mesh>();
            List <Tuple2 <int, int> > listSubmeshRange = new List <Tuple2 <int, int> >();
            List <int> listMeshComplexIndex            = new List <int>();

            for (int i = 0; i < numMeshes; i++)
            {
                CaronteSharp.MeshComplex caronteMesh = arrCaronteMesh[i];

                Mesh[] arrAuxMesh;
                Tuple2 <int, int>[] arrAuxSubmeshRange;

                CRGeometryUtils.CreateMeshesFromComplex(caronteMesh, out arrAuxMesh, out arrAuxSubmeshRange);
                listMesh.AddRange(arrAuxMesh);
                listSubmeshRange.AddRange(arrAuxSubmeshRange);

                for (int j = 0; j < arrAuxMesh.Length; j++)
                {
                    listMeshComplexIndex.Add(i);
                }
            }

            arrMesh          = listMesh.ToArray();
            arrSubmeshRange  = listSubmeshRange.ToArray();
            meshComplexIndex = listMeshComplexIndex.ToArray();
        }
Ejemplo n.º 2
0
        private static void CreateMeshCollapsedUnity(string name, MeshComplex mesh_COLLAPSED_car, ArrayIndex mesh_COLLAPSED_info, GameObject boundsObject,
                                                     List <Material> listMaterial, out GameObject[] arrGameObject, out Mesh[] arrMesh)
        {
            UnityEngine.Mesh[]  arrMesh_COLLAPSED_un;
            Tuple2 <int, int>[] arrSubmeshRange;

            CRGeometryUtils.CreateMeshesFromComplex(mesh_COLLAPSED_car, out arrMesh_COLLAPSED_un, out arrSubmeshRange);

            int nMeshUnity = arrMesh_COLLAPSED_un.Length;

            List <GameObject> listGameObject = new List <GameObject>();
            List <Mesh>       listMesh       = new List <Mesh>();

            for (int i = 0; i < nMeshUnity; i++)
            {
                Mesh mesh_COLLAPSED_un = arrMesh_COLLAPSED_un[i];
                mesh_COLLAPSED_un.name = name + "_" + i;
                listMesh.Add(mesh_COLLAPSED_un);

                GameObject go = Object.Instantiate(boundsObject);
                go.name = name + "_" + i;
                go.AddMesh(mesh_COLLAPSED_un);
                listGameObject.Add(go);

                Tuple2 <int, int> submeshRange = arrSubmeshRange[i];

                List <Material> collapsedMaterials = new List <Material>();
                uint[]          arrMaterialIdx     = mesh_COLLAPSED_info.arrIdx_;

                for (int j = submeshRange.First; j <= submeshRange.Second; j++)
                {
                    uint materialIdx = arrMaterialIdx[j];
                    if (materialIdx != uint.MaxValue)
                    {
                        Material mat = listMaterial[(int)materialIdx];
                        collapsedMaterials.Add(mat);
                    }
                    else
                    {
                        collapsedMaterials.Add(null);
                    }
                }

                Renderer renderer = go.GetComponent <Renderer>();
                renderer.sharedMaterials = collapsedMaterials.ToArray();
            }

            arrGameObject = listGameObject.ToArray();
            arrMesh       = listMesh.ToArray();
        }