Exemplo n.º 1
0
        public static void SaveQuadTreeHeader(string dataName, MTQuadTreeHeader header, int matCount)
        {
            string path = string.Format("{0}/MightyTerrainMesh/Resources/{1}.bytes",
                                        Application.dataPath, dataName);

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            FileStream stream = File.Open(path, FileMode.Create);

            byte[] uBuff = BitConverter.GetBytes(header.QuadTreeDepth);
            stream.Write(uBuff, 0, sizeof(int));
            WriteVector3(stream, header.BoundMin);
            WriteVector3(stream, header.BoundMax);
            //lod count
            uBuff = BitConverter.GetBytes(header.LOD);
            stream.Write(uBuff, 0, sizeof(int));
            //material count
            uBuff = BitConverter.GetBytes(matCount);
            stream.Write(uBuff, 0, sizeof(int));
            //blocks
            uBuff = BitConverter.GetBytes(header.Meshes.Count);
            stream.Write(uBuff, 0, sizeof(int));
            foreach (var v in header.Meshes.Values)
            {
                uBuff = BitConverter.GetBytes(v.MeshID);
                stream.Write(uBuff, 0, sizeof(int));
                WriteVector3(stream, v.Center);
            }
            stream.Close();
        }
Exemplo n.º 2
0
        public static MTQuadTreeHeader LoadQuadTreeHeader(string dataName)
        {
            MTQuadTreeHeader header = new MTQuadTreeHeader(dataName);
            string           path   = string.Format("{0}/{1}/{1}.bytes", s_DataPath, dataName);
            FileStream       stream = File.Open(path, FileMode.Open);

            byte[] nBuff = new byte[sizeof(int)];
            stream.Read(nBuff, 0, sizeof(int));
            header.QuadTreeDepth = BitConverter.ToInt32(nBuff, 0);
            header.BoundMin      = ReadVector3(stream);
            header.BoundMax      = ReadVector3(stream);
            //lod count
            stream.Read(nBuff, 0, sizeof(int));
            header.LOD = BitConverter.ToInt32(nBuff, 0);
            //material count
            stream.Read(nBuff, 0, sizeof(int));
            int matCount = BitConverter.ToInt32(nBuff, 0);

            header.RuntimeMats = new Material[matCount];
            //blocks
            stream.Read(nBuff, 0, sizeof(int));
            int len = BitConverter.ToInt32(nBuff, 0);

            for (int i = 0; i < len; ++i)
            {
                stream.Read(nBuff, 0, sizeof(int));
                int     meshid = BitConverter.ToInt32(nBuff, 0);
                Vector3 c      = ReadVector3(stream);
                header.Meshes.Add(meshid, new MTMeshHeader(meshid, c));
            }
            stream.Close();
            //init material
            for (int i = 0; i < header.RuntimeMats.Length; ++i)
            {
                string mathPath = string.Format("{0}_{1}", header.DataName, i);
                string resPath  = PathHelper.ABSPath2AssetsPath(string.Format("{0}/{1}/{2}.mat", s_DataPath, header.DataName, mathPath));
                //TODO 修改资源加载方式 需要兼顾预览模式和实际运行
                header.RuntimeMats[i] = UnityEditor.AssetDatabase.LoadAssetAtPath <Material>(resPath);//Resources.Load<Material>(mathPath);
            }
            return(header);
        }
Exemplo n.º 3
0
        public static MTQuadTreeHeader LoadQuadTreeHeader(string dataName)
        {
            MTQuadTreeHeader header = new MTQuadTreeHeader(dataName);
            string           path   = string.Format("{0}/MightyTerrainMesh/Resources/{1}.bytes",
                                                    Application.dataPath, dataName);
            FileStream stream = File.Open(path, FileMode.Open);

            byte[] nBuff = new byte[sizeof(int)];
            stream.Read(nBuff, 0, sizeof(int));
            header.QuadTreeDepth = BitConverter.ToInt32(nBuff, 0);
            header.BoundMin      = ReadVector3(stream);
            header.BoundMax      = ReadVector3(stream);
            //lod count
            stream.Read(nBuff, 0, sizeof(int));
            header.LOD = BitConverter.ToInt32(nBuff, 0);
            //material count
            stream.Read(nBuff, 0, sizeof(int));
            int matCount = BitConverter.ToInt32(nBuff, 0);

            header.RuntimeMats = new Material[matCount];
            //blocks
            stream.Read(nBuff, 0, sizeof(int));
            int len = BitConverter.ToInt32(nBuff, 0);

            for (int i = 0; i < len; ++i)
            {
                stream.Read(nBuff, 0, sizeof(int));
                int     meshid = BitConverter.ToInt32(nBuff, 0);
                Vector3 c      = ReadVector3(stream);
                header.Meshes.Add(meshid, new MTMeshHeader(meshid, c));
            }
            stream.Close();
            //init material
            for (int i = 0; i < header.RuntimeMats.Length; ++i)
            {
                string mathPath = string.Format("{0}_{1}", header.DataName, i);
                header.RuntimeMats[i] = Resources.Load <Material>(mathPath);
            }
            return(header);
        }