void OutputWholeScene()
    {
        MaterialExporter             matEx    = GetComponent <MaterialExporter>();
        MeshExporter                 meshEx   = GetComponent <MeshExporter>();
        TextureExporter              texEx    = GetComponent <TextureExporter>();
        Dictionary <Material, bool>  matDict  = new Dictionary <Material, bool>();
        Dictionary <Mesh, bool>      meshDict = new Dictionary <Mesh, bool>();
        Dictionary <Texture2D, bool> texDict  = new Dictionary <Texture2D, bool>();

        GetSceneData(
            SceneManager.GetActiveScene(),
            meshDict, matDict, texDict);
        void * jsonObjPtr = UnsafeUtility.Malloc((long)MJsonUtility.JsonObjectSize(), 16, Unity.Collections.Allocator.Temp);
        string jsonPath   = folder + "AssetDatabase.json";

        fixed(char *c = jsonPath)
        {
            MJsonUtility.CreateJsonObject(c, (ulong)jsonPath.Length, jsonObjPtr);
        }

        List <Mesh>   meshes    = new List <Mesh>(meshDict.Count);
        List <string> meshNames = new List <string>(meshDict.Count);

        foreach (var i in meshDict)
        {
            string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(i.Key));
            string name = folder + i.Key.name + ".vmesh";
            meshes.Add(i.Key);
            meshNames.Add(name);
            MJsonUtility.UpdateKeyValue(jsonObjPtr, guid.Ptr(), (ulong)guid.Length, name.Ptr(), (ulong)name.Length);
        }
        foreach (var i in matDict)
        {
            string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(i.Key));
            string name = folder + i.Key.name + ".mat";
            MJsonUtility.UpdateKeyValue(jsonObjPtr, guid.Ptr(), (ulong)guid.Length, name.Ptr(), (ulong)name.Length);
            matEx.testMat = i.Key;
            matEx.PrintToFile(name);
        }

        foreach (var i in texDict)
        {
            string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(i.Key));
            string name = folder + i.Key.name + ".vtex";
            MJsonUtility.UpdateKeyValue(jsonObjPtr, guid.Ptr(), (ulong)guid.Length, name.Ptr(), (ulong)name.Length);
            texEx.texture     = i.Key;
            texEx.path        = name;
            texEx.useMipMap   = true;
            texEx.tex2DFormat = TextureData.LoadFormat.LoadFormat_BC7;
            texEx.Print();
        }
        meshEx.ExportAllMeshes(meshes, meshNames);
        MJsonUtility.OutputJsonObject(jsonPath.Ptr(), (ulong)jsonPath.Length, jsonObjPtr);
        MJsonUtility.DisposeJsonObject(jsonObjPtr);
    }
    void OutputTerrainData()
    {
        if (splatSize * splatSize != splatMaps.Length)
        {
            Debug.LogError("Splat Size Not Equal To Splat Map!");
            return;
        }
        TextureExporter export = GetComponent <TextureExporter>();

        for (int i = 0; i < texturePackes.Length; ++i)
        {
            export.texture     = texturePackes[i].albedoTex;
            export.tex2DFormat = TextureData.LoadFormat.LoadFormat_BC7;
            export.path        = texturePackes[i].albedoTex.name + "_Albedo" + i.ToString() + ".vtex";
            export.useMipMap   = true;
            export.Print();
            export.texture     = texturePackes[i].normalTex;
            export.tex2DFormat = TextureData.LoadFormat.LoadFormat_BC7;
            export.path        = texturePackes[i].normalTex.name + "_Normal" + i.ToString() + ".vtex";
            export.useMipMap   = true;
            export.Print();
        }
        for (int i = 0; i < splatMaps.Length; ++i)
        {
            //export.texture = splatMaps[i];
            export.tex2DFormat = TextureData.LoadFormat.LoadFormat_BC7;
            //export.path = splatMaps[i].name + "_Splat" + i.ToString() + ".vtex";
            export.useMipMap = true;
            export.texture   = splatMaps[i].splat0;
            export.path      = splatMaps[i].splat0.name + "_Splat" + i.ToString() + ".vtex";
            export.Print();
            export.texture = splatMaps[i].indexMap;
            export.path    = splatMaps[i].indexMap.name + "_Index" + i.ToString() + ".vtex";
            export.Print();
        }

        List <string> splatJsons = new List <string>();

        for (int y = 0, count = 0; y < splatSize; ++y)
        {
            for (int x = 0; x < splatSize; ++x)
            {
                splatJsons.Add(
                    MJsonUtility.GetKeyValue(x.ToString() + ',' + y.ToString(),
                                             MJsonUtility.MakeJsonObject(
                                                 MJsonUtility.GetKeyValue("splat", splatMaps[count].splat0.name + "_Splat" + count.ToString() + ".vtex", false),
                                                 MJsonUtility.GetKeyValue("index", splatMaps[count].indexMap.name + "_Index" + count.ToString() + ".vtex", false)
                                                 ), true)
                    );
                count++;
            }
        }
        string        splatJson   = MJsonUtility.MakeJsonObject(splatJsons);
        List <string> albedoJsons = new List <string>();

        for (int i = 0; i < texturePackes.Length; ++i)
        {
            albedoJsons.Add(
                MJsonUtility.GetKeyValue(i.ToString(),
                                         MJsonUtility.MakeJsonObject(
                                             MJsonUtility.GetKeyValue("albedo", texturePackes[i].albedoTex.name + "_Albedo" + i.ToString() + ".vtex", false),
                                             MJsonUtility.GetKeyValue("normal", texturePackes[i].normalTex.name + "_Normal" + i.ToString() + ".vtex", false)), true)
                );
        }
        string albedoJson = MJsonUtility.MakeJsonObject(albedoJsons);
        string result     = MJsonUtility.MakeJsonObject(
            MJsonUtility.GetKeyValue("splat", splatJson, true),
            MJsonUtility.GetKeyValue("texture", albedoJson, true)
            );

        using (StreamWriter fsm = new StreamWriter(infoFile, false, System.Text.Encoding.ASCII))
        {
            fsm.Write(result);
        }
    }
Example #3
0
 void RunTest()
 {
     Debug.Log(MJsonUtility.JsonObjectSize());
 }