void SaveClusterData(NativeList <Cluster> cluster, NativeList <Point> points, NativeList <int> triangleMats)
        {
            int length = cluster.Length * sizeof(Cluster) + points.Length * sizeof(Point) + triangleMats.Length * sizeof(int);

            byte[] bytes = SceneStreaming.GetByteArray(length);
            fixed(byte *b = bytes)
            {
                UnsafeUtility.MemCpy(b, cluster.unsafePtr, cluster.Length * sizeof(Cluster));
                UnsafeUtility.MemCpy(b + cluster.Length * sizeof(Cluster), points.unsafePtr, points.Length * sizeof(Point));
                UnsafeUtility.MemCpy(b + cluster.Length * sizeof(Cluster) + points.Length * sizeof(Point), triangleMats.unsafePtr, triangleMats.Length * sizeof(int));
            }

            fsm.Write(bytes, 0, length);
        }
        void LoadClusterData(out NativeList <Cluster> cluster, out NativeList <Point> points, out NativeList <int> triangleMats)
        {
            cluster      = new NativeList <Cluster>(clusterCount, clusterCount, Allocator.Persistent);
            points       = new NativeList <Point>(clusterCount * PipelineBaseBuffer.CLUSTERCLIPCOUNT, clusterCount * PipelineBaseBuffer.CLUSTERCLIPCOUNT, Allocator.Persistent);
            triangleMats = new NativeList <int>(clusterCount * PipelineBaseBuffer.CLUSTERTRIANGLECOUNT, clusterCount * PipelineBaseBuffer.CLUSTERTRIANGLECOUNT, Allocator.Persistent);
            int length = cluster.Length * sizeof(Cluster) + points.Length * sizeof(Point) + triangleMats.Length * sizeof(int);

            byte[] bytes = SceneStreaming.GetByteArray(length);
            fsm.Read(bytes, 0, length);
            fixed(byte *b = bytes)
            {
                UnsafeUtility.MemCpy(cluster.unsafePtr, b, cluster.Length * sizeof(Cluster));
                UnsafeUtility.MemCpy(points.unsafePtr, b + cluster.Length * sizeof(Cluster), points.Length * sizeof(Point));
                UnsafeUtility.MemCpy(triangleMats.unsafePtr, b + cluster.Length * sizeof(Cluster) + points.Length * sizeof(Point), triangleMats.Length * sizeof(int));
            }
        }
Esempio n. 3
0
        public static void GetCluster(NativeList <Point> pointsFromMesh, NativeList <int> materialsFromMesh, Bounds bd, out NativeList <Cluster> boxes, out NativeList <Point> points, out NativeList <int> outMats, int voxelCount)
        {
            NativeList <Triangle> trs = GenerateTriangle(pointsFromMesh, materialsFromMesh);

            Voxel[,,] voxels = GetVoxelData(trs, voxelCount, bd);
            GetClusterFromVoxel(voxels, out boxes, out points, out outMats, pointsFromMesh.Length, voxelCount);
        }
Esempio n. 4
0
        private static NativeList <Triangle> GenerateTriangle(NativeList <Point> points, NativeList <int> materialID)
        {
            NativeList <Triangle> retValue = new NativeList <Triangle>(points.Length / 3, Allocator.Temp);

            for (int i = 0; i < points.Length; i += 3)
            {
                Triangle tri = new Triangle
                {
                    a          = points[i],
                    b          = points[i + 1],
                    c          = points[i + 2],
                    materialID = materialID[i / 3],
                    last       = null,
                    next       = null
                };
                retValue.Add(tri);
            }
            return(retValue);
        }
Esempio n. 5
0
        public CombinedModel ProcessCluster(MeshRenderer[] allRenderers, ref SceneStreamLoader loader, Dictionary <MeshRenderer, bool> lowLODLevels)
        {
            List <MeshFilter> allFilters = new List <MeshFilter>(allRenderers.Length);
            int sumVertexLength          = 0;

            for (int i = 0; i < allRenderers.Length; ++i)
            {
                if (!lowLODLevels.ContainsKey(allRenderers[i]))
                {
                    MeshFilter filter = allRenderers[i].GetComponent <MeshFilter>();
                    allFilters.Add(filter);
                    sumVertexLength += (int)(filter.sharedMesh.vertexCount * 1.2f);
                }
            }
            NativeList <Point> points            = new NativeList <Point>(sumVertexLength, Allocator.Temp);
            NativeList <int>   triangleMaterials = new NativeList <int>(sumVertexLength / 3, Allocator.Temp);
            var matToIndexDict = VirtualMaterial.GetMaterialsData(allRenderers, ref loader);

            for (int i = 0; i < allFilters.Count; ++i)
            {
                Mesh mesh = allFilters[i].sharedMesh;
                GetPoints(points, triangleMaterials, mesh, allFilters[i].transform, allRenderers[i].sharedMaterials, matToIndexDict);
            }
            float3 less = points[0].vertex;
            float3 more = points[0].vertex;

            for (int i = 1; i < points.Length; ++i)
            {
                float3 current = points[i].vertex;
                if (less.x > current.x)
                {
                    less.x = current.x;
                }
                if (more.x < current.x)
                {
                    more.x = current.x;
                }
                if (less.y > current.y)
                {
                    less.y = current.y;
                }
                if (more.y < current.y)
                {
                    more.y = current.y;
                }
                if (less.z > current.z)
                {
                    less.z = current.z;
                }
                if (more.z < current.z)
                {
                    more.z = current.z;
                }
            }

            float3        center = (less + more) / 2;
            float3        extent = more - center;
            Bounds        b      = new Bounds(center, extent * 2);
            CombinedModel md;

            md.bound       = b;
            md.allPoints   = points;
            md.allMatIndex = triangleMaterials;
            return(md);
        }