Ejemplo n.º 1
0
            public static void Postfix(ref MeshDescriptionCollection __instance)
            {
                System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();

                string myResourcesPath = Path.Combine(Utils.GetGamePath(), "Mods", MyModFolder, "Resources");
                string myBundlePath    = Path.Combine(myResourcesPath, MyUnityBundle);

                MeshDescription newBlockTexMD = new MeshDescription(__instance.meshes[0]);

                newBlockTexMD.Name            = MyTextureArrayMeshName;
                newBlockTexMD.ShaderName      = __instance.meshes[0].ShaderName;
                newBlockTexMD.SecondaryShader = __instance.meshes[0].SecondaryShader;
                newBlockTexMD.bTextureArray   = true;
                newBlockTexMD.MetaData        = new TextAsset(File.ReadAllText(Path.Combine(myResourcesPath, MyUVMappingXml)));

                AssetBundleManager.Instance.LoadAssetBundle(myBundlePath, false);

                newBlockTexMD.TexDiffuse  = AssetBundleManager.Instance.Get <Texture2DArray>(myBundlePath, MyTextureArrayDiffuse);
                newBlockTexMD.TexNormal   = AssetBundleManager.Instance.Get <Texture2DArray>(myBundlePath, MyTextureArrayNormal);
                newBlockTexMD.TexSpecular = AssetBundleManager.Instance.Get <Texture2DArray>(myBundlePath, MyTextureArraySpecular);

                Array.Resize(ref __instance.meshes, 11);
                __instance.meshes[10]       = newBlockTexMD;
                MeshDescription.MESH_LENGTH = 11;

                sw.Stop();
                Log.Out("Load new texture arrays complete.  Elapsed time: {0}", sw.Elapsed);
            }
Ejemplo n.º 2
0
            public static bool Prefix(ref MeshDescription __instance, MeshDescriptionCollection _meshDescriptionCollection, int _index, int _quality, bool _isReload = false)
            {
                if (_index > MeshDescription.MESH_OPAQUE2)
                {
                    Log.Out("_index > MESH_OPAQUE2(9) so let's not load/reload.  Skipping LoadTextureArraysForQuality for index {0}", _index);
                    return(false);
                }

                return(true);
            }
Ejemplo n.º 3
0
            static bool Prefix(ref bool __result, ref TextureAtlasTerrain __instance, int _idx, ref MeshDescriptionCollection _tac, bool _bLoadTextures)
            {
                System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();

                string myResourcesPath = Path.Combine(Utils.GetGamePath(), "Mods", MyModFolder, "Resources");
                string myBundlePath    = Path.Combine(myResourcesPath, MyUnityBundle);

                AssetBundleManager.Instance.LoadAssetBundle(myBundlePath, false);

                if (TextureAtlasBlocks_LoadTextureAtlas(ref __instance, _idx, _tac, _bLoadTextures))
                {
                    __instance.diffuse  = new Texture2D[__instance.uvMapping.Length];
                    __instance.normal   = new Texture2D[__instance.uvMapping.Length];
                    __instance.specular = new Texture2D[__instance.uvMapping.Length];

                    if (_bLoadTextures)
                    {
                        for (int i = 0; i < __instance.uvMapping.Length; i++)
                        {
                            if (__instance.uvMapping[i].textureName != null)
                            {
                                string text          = Utils.RemoveFileExtension(__instance.uvMapping[i].textureName);
                                string fileExtension = Utils.GetFileExtension(__instance.uvMapping[i].textureName);

                                __instance.diffuse[i] = AssetBundleManager.Instance.Get <Texture2D>("TerrainTextures", __instance.uvMapping[i].textureName);
                                if (__instance.diffuse[i] == null)
                                {
                                    __instance.diffuse[i] = AssetBundleManager.Instance.Get <Texture2D>(myBundlePath, __instance.uvMapping[i].textureName);
                                    if (__instance.diffuse[i] == null)
                                    {
                                        throw new Exception("TextureAtlasTerrain: couldn't load diffuse texture '" + __instance.uvMapping[i].textureName + "'");
                                    }
                                }

                                __instance.normal[i] = AssetBundleManager.Instance.Get <Texture2D>("TerrainTextures", text + "_n" + fileExtension);
                                if (__instance.normal[i] == null)
                                {
                                    __instance.normal[i] = AssetBundleManager.Instance.Get <Texture2D>(myBundlePath, text + "_n" + fileExtension);
                                    if (__instance.normal[i] == null)
                                    {
                                        throw new Exception(string.Concat(new string[] { "TextureAtlasTerrain: couldn't load normal texture '", text, "_n", fileExtension, "'" }));
                                    }
                                }

                                __instance.specular[i] = AssetBundleManager.Instance.Get <Texture2D>("TerrainTextures", text + "_s" + fileExtension);
                                if (__instance.specular[i] == null)
                                {
                                    __instance.specular[i] = AssetBundleManager.Instance.Get <Texture2D>(myBundlePath, text + "_s" + fileExtension);
                                }
                            }
                        }
                    }
                }

                sw.Stop();
                Log.Out("Load new terrain textures complete.  Elapsed time: {0}", sw.Elapsed);

                __result = true;

                return(false);
            }
Ejemplo n.º 4
0
            static bool TextureAtlas_LoadTextureAtlas(ref TextureAtlasTerrain __instance, int _idx, MeshDescriptionCollection _tac, bool _bLoadTextures)
            {
                if (_bLoadTextures)
                {
                    __instance.diffuseTexture    = _tac.meshes[_idx].TexDiffuse;
                    __instance.normalTexture     = _tac.meshes[_idx].TexNormal;
                    __instance.specularTexture   = _tac.meshes[_idx].TexSpecular;
                    __instance.emissionTexture   = _tac.meshes[_idx].TexEmission;
                    __instance.heightTexture     = _tac.meshes[_idx].TexHeight;
                    __instance.occlusionTexture  = _tac.meshes[_idx].TexOcclusion;
                    __instance.maskTexture       = _tac.meshes[_idx].TexMask;
                    __instance.maskNormalTexture = _tac.meshes[_idx].TexMaskNormal;
                }

                return(true);
            }
Ejemplo n.º 5
0
            static bool TextureAtlasBlocks_LoadTextureAtlas(ref TextureAtlasTerrain __instance, int _idx, MeshDescriptionCollection _tac, bool _bLoadTextures)
            {
                try
                {
                    XmlNodeList childNodes = new XmlFile(_tac.meshes[_idx].MetaData).XmlDoc.DocumentElement.ChildNodes;
                    int         highestId  = 0;

                    foreach (XmlNode xmlNode in childNodes)
                    {
                        if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name.Equals("uv"))
                        {
                            XmlElement xmlElement = (XmlElement)xmlNode;
                            highestId = Math.Max(highestId, int.Parse(xmlElement.GetAttribute("id")));
                        }
                    }

                    string      myResourcesPath = Path.Combine(Utils.GetGamePath(), "Mods", MyModFolder, "Resources");
                    string      myBundlePath    = Path.Combine(myResourcesPath, MyUnityBundle);
                    string      xmlfile         = Path.Combine(myResourcesPath, MyUVMappingXml);
                    XmlNodeList modChildNodes   = new XmlFile(File.ReadAllBytes(xmlfile)).XmlDoc.DocumentElement.ChildNodes;

                    foreach (XmlNode xmlNode in modChildNodes)
                    {
                        if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name.Equals("uv"))
                        {
                            XmlElement xmlElement = (XmlElement)xmlNode;
                            highestId = Math.Max(highestId, int.Parse(xmlElement.GetAttribute("id")));
                        }
                    }

                    __instance.uvMapping = new UVRectTiling[highestId + 1];

                    foreach (XmlNode xmlNode in childNodes)
                    {
                        if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name.Equals("uv"))
                        {
                            XmlElement   xmlElement2  = (XmlElement)xmlNode;
                            int          id           = int.Parse(xmlElement2.GetAttribute("id"));
                            UVRectTiling uvrectTiling = default(UVRectTiling);
                            uvrectTiling.FromXML(xmlElement2);
                            if (MatchUVMappings)
                            {
                                uvrectTiling.blockH = UVBlockSize;
                                uvrectTiling.blockW = UVBlockSize;
                            }
                            __instance.uvMapping[id] = uvrectTiling;
                        }
                    }

                    foreach (XmlNode xmlNode in modChildNodes)
                    {
                        if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name.Equals("uv"))
                        {
                            XmlElement   xmlElement2  = (XmlElement)xmlNode;
                            int          id           = int.Parse(xmlElement2.GetAttribute("id"));
                            UVRectTiling uvrectTiling = default(UVRectTiling);
                            uvrectTiling.FromXML(xmlElement2);
                            if (MatchUVMappings)
                            {
                                uvrectTiling.blockH = UVBlockSize;
                                uvrectTiling.blockW = UVBlockSize;
                            }
                            __instance.uvMapping[id] = uvrectTiling;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(string.Concat(new object[] { "Parsing file xml file for texture atlas ", _tac.name, " (", _idx, "): ", ex.Message, ")" }));
                    Log.Exception(ex);
                    Log.Error("Loading of textures aborted due to errors!");
                    return(false);
                }

                TextureAtlas_LoadTextureAtlas(ref __instance, _idx, _tac, _bLoadTextures);
                return(true);
            }