Exemple #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());
                }
            }
        }
Exemple #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());
                }
            }
        }
Exemple #3
0
        public void GenerateAsync(bool listCommand = true)
        {
            clusterBuffer = new NativeArray <Cluster>(property.clusterCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            pointsBuffer  = new NativeArray <Point>(property.clusterCount * PipelineBaseBuffer.CLUSTERCLIPCOUNT, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            Cluster *      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 + ".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);
                }
            }
            LoadingCommandQueue commandQueue = LoadingThread.commandQueue;

            if (listCommand)
            {
                lock (commandQueue)
                {
                    commandQueue.Queue(GenerateRun());
                }
            }
        }
Exemple #4
0
        //TODO
        public void LoadTextures()
        {
            PropertyValue[] values = property.properties;
            if (property.texPaths.Length > 3)
            {
                Debug.LogError("Scene: " + property.name + "'s texture type count is larger than 3! That is illegal!");
                return;
            }
            for (int i = 0; i < values.Length; ++i)
            {
                ref PropertyValue value = ref values[i];
                int *indexPtr           = (int *)UnsafeUtility.AddressOf(ref value.textureIndex);
                for (int a = 0; a < property.texPaths.Length; ++a)
                {
                    string         texName = property.texPaths[a].instancingIDs[i];
                    MStringBuilder sb      = new MStringBuilder(texName.Length + 50);
                    allStrings[0] = "Assets/BinaryData/Textures/";
                    allStrings[1] = texName;
                    allStrings[2] = ".txt";
                    sb.Combine(allStrings);
                    string texType = property.texPaths[a].texName;
                    bool   alreadyContained;
                    indexPtr[a] = SceneController.commonData.GetIndex(texName, out alreadyContained);
                    if (indexPtr[a] >= 0)
                    {
                        if (alreadyContained)
                        {
                            allTextureDatas.Add(new TextureInfos
                            {
                                array   = new NativeArray <Color32>(),
                                index   = indexPtr[a],
                                texGUID = texName,
                                texType = texType
                            });
                        }
                        using (BinaryReader reader = new BinaryReader(File.Open(sb.str, FileMode.Open)))
                        {
                            byte[] bytes = reader.ReadBytes((int)reader.BaseStream.Length);
                            int    res   = SceneController.resolution;
                            NativeArray <Color32> allColors = new NativeArray <Color32>(res * res, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                            fixed(byte *source = bytes)
                            {
                                UnsafeUtility.MemCpy(allColors.GetUnsafePtr(), source, Mathf.Min(allColors.Length * sizeof(Color32), bytes.Length));
                            }

                            allTextureDatas.Add(new TextureInfos
                            {
                                array   = allColors,
                                index   = indexPtr[a],
                                texGUID = texName,
                                texType = texType
                            });
                        }
                    }
                }
            }
Exemple #5
0
        public void GenerateAsync(bool listCommand = true)
        {
            allStrings[0] = ClusterMatResources.infosPath;
            allStrings[1] = name;
            allStrings[2] = ".mpipe";
            sb.Combine(allStrings);
            loader.fsm = new FileStream(sb.str, FileMode.Open, FileAccess.Read);
            loader.LoadAll();
            materialIndexBuffer = resources.vmManager.SetMaterials(loader.allProperties.Length);
            for (int i = 0; i < loader.cluster.Length; ++i)
            {
                loader.cluster[i].index = propertyCount;
            }
            materialProperties = new NativeArray <VirtualMaterial.MaterialProperties>(loader.allProperties.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            VirtualMaterial.MaterialProperties *propertiesPtr = materialProperties.Ptr();
            //Update Material
            for (int i = 0; i < materialProperties.Length; ++i)
            {
                ref var currProp = ref propertiesPtr[i];
                currProp = loader.allProperties[i];
                if (currProp._MainTex >= 0)
                {
                    currProp._MainTex = resources.rgbaPool.GetTex(loader.albedoGUIDs[currProp._MainTex]);
                }
                if (currProp._SecondaryMainTex >= 0)
                {
                    currProp._SecondaryMainTex = resources.rgbaPool.GetTex(loader.secondAlbedoGUIDs[currProp._SecondaryMainTex]);
                }
                if (currProp._BumpMap >= 0)
                {
                    currProp._BumpMap = resources.rgbaPool.GetTex(loader.normalGUIDs[currProp._BumpMap], true);
                }
                if (currProp._SecondaryBumpMap >= 0)
                {
                    currProp._SecondaryBumpMap = resources.rgbaPool.GetTex(loader.secondNormalGUIDs[currProp._SecondaryBumpMap], true);
                }

                if (currProp._SpecularMap >= 0)
                {
                    currProp._SpecularMap = resources.rgbaPool.GetTex(loader.smoGUIDs[currProp._SpecularMap]);
                }
                if (currProp._SecondarySpecularMap >= 0)
                {
                    currProp._SecondarySpecularMap = resources.rgbaPool.GetTex(loader.secondSpecGUIDs[currProp._SecondarySpecularMap]);
                }
                if (currProp._EmissionMap >= 0)
                {
                    currProp._EmissionMap = resources.emissionPool.GetTex(loader.emissionGUIDs[currProp._EmissionMap]);
                }
                if (currProp._HeightMap >= 0)
                {
                    currProp._HeightMap = resources.heightPool.GetTex(loader.heightGUIDs[currProp._HeightMap]);
                }
            }
Exemple #6
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        if (foldOut = EditorGUILayout.Foldout(foldOut, "Layer Culling Distance: "))
        {
            for (int i = 0; i < 32; ++i)
            {
                string layerName = LayerMask.LayerToName(i);

                if (!string.IsNullOrEmpty(layerName))
                {
                    msb.Combine("   ", layerName);
                    msb.Add(": ");
                    target.layerCullDistance[i] = EditorGUILayout.FloatField(msb.str, target.layerCullDistance[i]);
                }
            }
        }
    }
        public void GenerateAsync()
        {
            var resources = ClusterMatResources.current;

            allStrings[0] = ClusterMatResources.infosPath;
            allStrings[1] = fileName;
            allStrings[2] = ".mpipe";
            sb.Combine(allStrings);
            loader.fsm = new FileStream(sb.str, FileMode.Open, FileAccess.Read);
            if (!loader.LoadAll(resources.maximumClusterCount - SceneController.baseBuffer.prepareClusterCount))
            {
                if (!waiting)
                {
                    loading = false;
                }
                state = State.Unloaded;
                int required = SceneController.baseBuffer.prepareClusterCount + loader.clusterCount;
                int actual   = resources.maximumClusterCount;
                Debug.LogError("No Enough Model Space! Required: " + required + " Actual: " + actual);
                loader.Dispose();
                return;
            }
            materialIndexBuffer = resources.vmManager.SetMaterials(loader.allProperties.Length);
            for (int i = 0; i < loader.cluster.Length; ++i)
            {
                loader.cluster[i].index = propertyCount;
            }
            materialProperties = new NativeArray <VirtualMaterial.MaterialProperties>(loader.allProperties.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            VirtualMaterial.MaterialProperties *propertiesPtr = materialProperties.Ptr();
            textureLoadingFlags.Clear();
            //Update Material
            for (int i = 0; i < materialProperties.Length; ++i)
            {
                ref var currProp = ref propertiesPtr[i];
                currProp = loader.allProperties[i];
                if (currProp._MainTex >= 0)
                {
                    currProp._MainTex = resources.rgbaPool.GetTex(loader.albedoGUIDs[currProp._MainTex], ref textureLoadingFlags);
                }
                if (currProp._SecondaryMainTex >= 0)
                {
                    currProp._SecondaryMainTex = resources.rgbaPool.GetTex(loader.secondAlbedoGUIDs[currProp._SecondaryMainTex], ref textureLoadingFlags);
                }
                if (currProp._BumpMap >= 0)
                {
                    currProp._BumpMap = resources.rgbaPool.GetTex(loader.normalGUIDs[currProp._BumpMap], ref textureLoadingFlags, true);
                }
                if (currProp._SecondaryBumpMap >= 0)
                {
                    currProp._SecondaryBumpMap = resources.rgbaPool.GetTex(loader.secondNormalGUIDs[currProp._SecondaryBumpMap], ref textureLoadingFlags, true);
                }

                if (currProp._SpecularMap >= 0)
                {
                    currProp._SpecularMap = resources.rgbaPool.GetTex(loader.smoGUIDs[currProp._SpecularMap], ref textureLoadingFlags);
                }
                if (currProp._SecondarySpecularMap >= 0)
                {
                    currProp._SecondarySpecularMap = resources.rgbaPool.GetTex(loader.secondSpecGUIDs[currProp._SecondarySpecularMap], ref textureLoadingFlags);
                }
                if (currProp._EmissionMap >= 0)
                {
                    currProp._EmissionMap = resources.emissionPool.GetTex(loader.emissionGUIDs[currProp._EmissionMap], ref textureLoadingFlags);
                }
                if (currProp._HeightMap >= 0)
                {
                    currProp._HeightMap = resources.heightPool.GetTex(loader.heightGUIDs[currProp._HeightMap], ref textureLoadingFlags);
                }
            }
Exemple #8
0
        //TODO
        public void LoadTextures()
        {
            PropertyValue[] values = property.properties;
            if (property.texPaths.Length > 5)
            {
                Debug.LogError("Scene: " + property.name + "'s texture type count is larger than 5! That is illegal!");
                return;
            }
            MStringBuilder sb = new MStringBuilder(150);

            allStrings[0] = "Assets/BinaryData/Lightmaps/";
            allStrings[2] = ".mpipe";
            for (int i = 0; i < property.lightmapGUIDs.Length; ++i)
            {
                LightmapPaths lightmapGUID = property.lightmapGUIDs[i];
                allStrings[1] = lightmapGUID.name;
                sb.Combine(allStrings);
                bool alreadyContained;
                int  index = SceneController.commonData.GetLightmapIndex(lightmapGUID.name, out alreadyContained);
                if (index >= 0)
                {
                    if (alreadyContained)
                    {
                        allLightmapDatas.Add(new LightmapInfos
                        {
                            index   = index,
                            texGUID = lightmapGUID.name,
                            size    = 0
                        });
                    }
                    else
                    {
                        using (FileStream reader = new FileStream(sb.str, FileMode.Open, FileAccess.Read))
                        {
                            NativeArray <Color32> color;
                            int    length = (int)reader.Length;
                            byte[] bytes  = GetByteArray(length);
                            reader.Read(bytes, 0, length);
                            color = new NativeArray <Color32>(length / sizeof(Color32), Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                            fixed(byte *source = bytes)
                            {
                                UnsafeUtility.MemCpy(color.GetUnsafePtr(), source, Mathf.Min(color.Length * sizeof(Color32), length));
                            }

                            allLightmapDatas.Add(new LightmapInfos
                            {
                                array   = color,
                                index   = index,
                                texGUID = lightmapGUID.name,
                                size    = lightmapGUID.size
                            });
                        }
                    }
                }
            }
            for (int i = 0; i < values.Length; ++i)
            {
                ref PropertyValue value = ref values[i];
                int *indexPtr           = (int *)UnsafeUtility.AddressOf(ref value.textureIndex);
                for (int a = 0; a < property.texPaths.Length; ++a)
                {
                    string texName = property.texPaths[a].instancingIDs[i];
                    allStrings[0] = "Assets/BinaryData/Textures/";
                    allStrings[1] = texName;
                    allStrings[2] = ".mpipe";
                    sb.Combine(allStrings);
                    string texType = property.texPaths[a].texName;
                    bool   alreadyContained;
                    indexPtr[a] = SceneController.commonData.GetIndex(texName, out alreadyContained);
                    if (indexPtr[a] >= 0)
                    {
                        if (alreadyContained)
                        {
                            allTextureDatas.Add(new TextureInfos
                            {
                                array   = new NativeArray <Color32>(),
                                index   = indexPtr[a],
                                texGUID = texName,
                                texType = texType
                            });
                        }
                        else
                        {
                            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);
                                int res = SceneController.resolution;
                                NativeArray <Color32> allColors = new NativeArray <Color32>(res * res, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                                fixed(byte *source = bytes)
                                {
                                    UnsafeUtility.MemCpy(allColors.GetUnsafePtr(), source, Mathf.Min(allColors.Length * sizeof(Color32), length));
                                }

                                allTextureDatas.Add(new TextureInfos
                                {
                                    array   = allColors,
                                    index   = indexPtr[a],
                                    texGUID = texName,
                                    texType = texType
                                });
                            }
                        }
                    }
                }
            }