Esempio n. 1
0
        public void GenerateAsync(bool listCommand = true)
        {
            clusterBuffer = new NativeArray <CullBox>(property.clusterCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            pointsBuffer  = new NativeArray <Point>(property.clusterCount * PipelineBaseBuffer.CLUSTERCLIPCOUNT, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            indicesBuffer = new NativeArray <int>(property.clusterCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            NativeList <ulong> pointerContainer = SceneController.pointerContainer;

            pointerContainer.AddCapacityTo(pointerContainer.Length + indicesBuffer.Length);
            CullBox *      clusterData  = clusterBuffer.Ptr();
            Point *        verticesData = pointsBuffer.Ptr();
            const string   infosPath    = "Assets/BinaryData/MapInfos/";
            const string   pointsPath   = "Assets/BinaryData/MapPoints/";
            MStringBuilder sb           = new MStringBuilder(pointsPath.Length + property.name.Length + ".txt".Length);

            allStrings[0] = infosPath;
            allStrings[1] = property.name;
            allStrings[2] = ".txt";
            sb.Combine(allStrings);
            using (BinaryReader reader = new BinaryReader(File.Open(sb.str, FileMode.Open)))
            {
                byte[] bytes = reader.ReadBytes((int)reader.BaseStream.Length);
                fixed(byte *b = bytes)
                {
                    UnsafeUtility.MemCpy(clusterData, b, bytes.Length);
                }
            }
            allStrings[0] = pointsPath;
            sb.Combine(allStrings);
            using (BinaryReader reader = new BinaryReader(File.Open(sb.str, FileMode.Open)))
            {
                byte[] bytes = reader.ReadBytes((int)reader.BaseStream.Length);
                fixed(byte *b = bytes)
                {
                    UnsafeUtility.MemCpy(verticesData, b, bytes.Length);
                }
            }
            int *indicesPtr = indicesBuffer.Ptr();
            LoadingCommandQueue commandQueue = SceneController.commandQueue;

            for (int i = 0; i < indicesBuffer.Length; ++i)
            {
                indicesPtr[i] = pointerContainer.Length;
                pointerContainer.Add((ulong)(indicesPtr + i));
            }
            LoadTextures();
            propertiesPool = SceneController.commonData.GetPropertyIndex(property.properties.Length);
            uint *poolPtr = propertiesPool.Ptr();

            for (int i = 0; i < pointsBuffer.Length; ++i)
            {
                verticesData[i].objIndex = poolPtr[verticesData[i].objIndex];
            }
            if (listCommand)
            {
                lock (commandQueue)
                {
                    commandQueue.Queue(GenerateRun());
                }
            }
        }
Esempio n. 2
0
        public void GenerateAsync(bool listCommand = true)
        {
            clusterBuffer = new NativeArray <CullBox>(property.clusterCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            pointsBuffer  = new NativeArray <float3>(property.clusterCount * PipelineBaseBuffer.CLUSTERCLIPCOUNT, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            indicesBuffer = new NativeArray <int>(property.clusterCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            NativeList <ulong> pointerContainer = SceneController.pointerContainer;

            pointerContainer.AddCapacityTo(pointerContainer.Length + indicesBuffer.Length);
            CullBox *      clusterData  = clusterBuffer.Ptr();
            float3 *       verticesData = pointsBuffer.Ptr();
            const string   infosPath    = "Assets/BinaryData/MapInfos/";
            const string   pointsPath   = "Assets/BinaryData/MapPoints/";
            MStringBuilder sb           = new MStringBuilder(pointsPath.Length + property.name.Length + ".mpipe".Length);

            allStrings[0] = infosPath;
            allStrings[1] = property.name;
            allStrings[2] = ".mpipe";
            sb.Combine(allStrings);
            // FileStream fileStream = new FileStream(sb.str, FileMode.Open, FileAccess.Read);
            using (FileStream reader = new FileStream(sb.str, FileMode.Open, FileAccess.Read))
            {
                int    length = (int)reader.Length;
                byte[] bytes  = GetByteArray(length);
                reader.Read(bytes, 0, length);
                fixed(byte *b = bytes)
                {
                    UnsafeUtility.MemCpy(clusterData, b, length);
                }
            }
            allStrings[0] = pointsPath;
            sb.Combine(allStrings);
            using (FileStream reader = new FileStream(sb.str, FileMode.Open, FileAccess.Read))
            {
                int    length = (int)reader.Length;
                byte[] bytes  = GetByteArray(length);
                reader.Read(bytes, 0, length);
                fixed(byte *b = bytes)
                {
                    UnsafeUtility.MemCpy(verticesData, b, length);
                }
            }
            int *indicesPtr = indicesBuffer.Ptr();
            LoadingCommandQueue commandQueue = LoadingThread.commandQueue;

            for (int i = 0; i < indicesBuffer.Length; ++i)
            {
                indicesPtr[i] = pointerContainer.Length;
                pointerContainer.Add((ulong)(indicesPtr + i));
            }

            if (listCommand)
            {
                lock (commandQueue)
                {
                    commandQueue.Queue(GenerateRun());
                }
            }
        }