コード例 #1
0
    public static void SyncAll()
    {
        MicroSplatTerrain.SyncAll();
#if __MICROSPLAT_MESHTERRAIN__
        MicroSplatMeshTerrain.SyncAll();
#endif
#if __MICROSPLAT_MESH__
        MicroSplatMesh.SyncAll();
        MicroSplatVertexMesh.SyncAll();
#endif
#if __MICROSPLAT_POLARIS__
        MicroSplatPolarisMesh.SyncAll();
#endif
    }
コード例 #2
0
        public static void Setup(GStylizedTerrain t)
        {
            if (t.TerrainData == null)
            {
                return;
            }

            t.TerrainData.Shading.ShadingSystem = GShadingSystem.MicroSplat;
            GMicroSplatIntegrationSettings settings = GMicroSplatIntegrationSettings.Instance;
            MicroSplatPolarisMesh          pm       = t.gameObject.GetComponent <MicroSplatPolarisMesh>();

            if (pm != null)
            {
                GUtilities.DestroyObject(pm);
            }

            MeshRenderer[]      renderers    = t.GetOrCreateChunkRoot().GetComponentsInChildren <MeshRenderer>();
            List <MeshRenderer> rendererList = new List <MeshRenderer>();

            rendererList.AddRange(renderers);

            MicroSplatPolarisMeshEditor.PolarisData data = new MicroSplatPolarisMeshEditor.PolarisData();
            data.basePath           = settings.DataDirectory;
            data.name               = settings.ShaderNamePrefix;
            data.additionalKeywords = new string[0];
            data.rootObject         = t.gameObject;
            data.renderers          = rendererList;
            MicroSplatPolarisMeshEditor.Setup(data);

            pm = t.gameObject.GetComponent <MicroSplatPolarisMesh>();
            t.TerrainData.Shading.CustomMaterial = pm.templateMaterial;

            string             materialPath = AssetDatabase.GetAssetPath(pm.templateMaterial);
            string             directory    = Path.GetDirectoryName(materialPath);
            string             configPath   = string.Format("{0}/MicroSplatConfig.asset", directory);
            TextureArrayConfig config       = AssetDatabase.LoadAssetAtPath <TextureArrayConfig>(configPath);

            t.TerrainData.Shading.MicroSplatTextureArrayConfig = config;

            currentTAConfig = config;
        }
コード例 #3
0
        private static void InjectTerrainGUI(GStylizedTerrain terrain, int order)
        {
            if (order != 3)
            {
                return;
            }
            string label = "MicroSplat Integration";
            string id    = "terrain-gui-microsplat-integration";

            GEditorCommon.Foldout(label, false, id, () =>
            {
                bool useMS = terrain.TerrainData.Shading.ShadingSystem == GShadingSystem.MicroSplat;
                useMS      = EditorGUILayout.Toggle("Enable", useMS);
                terrain.TerrainData.Shading.ShadingSystem =
                    useMS ?
                    GShadingSystem.MicroSplat :
                    GShadingSystem.Polaris;

                GEditorCommon.Separator();
                EditorGUILayout.LabelField("Setup", EditorStyles.boldLabel);

                GMicroSplatIntegrationSettings settings = GMicroSplatIntegrationSettings.Instance;
                string dir = settings.DataDirectory;
                GEditorCommon.BrowseFolderMiniButton("Data Directory", ref dir);
                settings.DataDirectory    = dir;
                settings.ShaderNamePrefix = EditorGUILayout.TextField("Shader Name Prefix", settings.ShaderNamePrefix);
                if (GUILayout.Button("Setup"))
                {
                    MicroSplatPolarisMesh pm = terrain.gameObject.GetComponent <MicroSplatPolarisMesh>();
                    if (pm != null)
                    {
                        GUtilities.DestroyObject(pm);
                    }

                    MeshRenderer[] renderers         = terrain.Internal_ChunkRoot.GetComponentsInChildren <MeshRenderer>();
                    List <MeshRenderer> rendererList = new List <MeshRenderer>();
                    rendererList.AddRange(renderers);

                    MicroSplatPolarisMeshEditor.PolarisData data = new MicroSplatPolarisMeshEditor.PolarisData();
                    data.basePath           = settings.DataDirectory;
                    data.name               = string.Format("{0}_{1}", settings.ShaderNamePrefix, terrain.TerrainData.Id);
                    data.additionalKeywords = new string[0];
                    data.rootObject         = terrain.gameObject;
                    data.renderers          = rendererList;
                    MicroSplatPolarisMeshEditor.Setup(data);
                    terrain.PushControlTexturesToMicroSplat();

                    if (terrain.TerrainData.Shading.Splats == null ||
                        terrain.TerrainData.Shading.Splats.Prototypes.Count == 0)
                    {
                        return;
                    }

                    pm = terrain.gameObject.GetComponent <MicroSplatPolarisMesh>();
                    if (pm == null)
                    {
                        return;
                    }

                    string materialPath       = AssetDatabase.GetAssetPath(pm.templateMaterial);
                    string directory          = Path.GetDirectoryName(materialPath);
                    string configPath         = string.Format("{0}/MicroSplatConfig.asset", directory);
                    TextureArrayConfig config = AssetDatabase.LoadAssetAtPath <TextureArrayConfig>(configPath);
                    if (config != null)
                    {
                        terrain.TerrainData.Shading.MicroSplatTextureArrayConfig = config;

                        GSplatPrototypeGroup splats       = terrain.TerrainData.Shading.Splats;
                        List <GSplatPrototype> prototypes = splats.Prototypes;
                        for (int i = 0; i < prototypes.Count; ++i)
                        {
                            TextureArrayConfig.TextureEntry entry = new TextureArrayConfig.TextureEntry();
                            entry.diffuse           = prototypes[i].Texture;
                            entry.normal            = prototypes[i].NormalMap;
                            entry.aoChannel         = TextureArrayConfig.TextureChannel.G;
                            entry.heightChannel     = TextureArrayConfig.TextureChannel.G;
                            entry.smoothnessChannel = TextureArrayConfig.TextureChannel.G;
                            entry.alphaChannel      = TextureArrayConfig.TextureChannel.G;
                            config.sourceTextures.Add(entry);
                        }

                        TextureArrayConfigEditor.CompileConfig(config);
                        terrain.PullMaterialAndSplatMapsFromMicroSplat();
                    }
                }
            });
        }