private void CloseConfiguration(bool saveOnDisk) { if (saveOnDisk) { Material mat = m_CacheMaterials[currentMeshACIndex]; Shader shader = mat.shader; ShaderMetaDataUtility.SaveShaderMetaData(shader, m_LoadedAttributes); foreach (GameObject go in Selection.gameObjects) { m_LikelySupportsTextureBlending = CheckForTextureBlendSupport(go); if (m_LikelySupportsTextureBlending) { break; } } if (m_CacheTarget != null) { RebuildCaches(m_CacheTarget.editMesh); } } m_LoadedAttributes = null; m_CurrentPanelView = PanelView.Paint; }
private void OpenConfiguration() { m_CurrentPanelView = PanelView.Configuration; if (m_MainCacheMaterials == null || m_CurrentMeshACIndex < 0 || m_CurrentMeshACIndex >= m_MainCacheMaterials.Count) { return; } Material mat = m_MainCacheMaterials[m_CurrentMeshACIndex]; Shader shader = mat.shader; if (ShaderMetaDataUtility.IsValidShader(shader)) { #pragma warning disable 0618 // Data conversion between Polybrush Beta and Polybrush 1.0. string path = ShaderMetaDataUtility.FindPolybrushMetaDataForShader(shader); if (!string.IsNullOrEmpty(path)) { ShaderMetaDataUtility.ConvertMetaDataToNewFormat(shader); } #pragma warning restore 0618 m_LoadedAttributes = ShaderMetaDataUtility.LoadShaderMetaData(shader); } }
static void CreateShaderMetaData() { string path = ""; foreach (Shader shader in Selection.objects) { AttributeLayout[] attributes = new AttributeLayout[] { new AttributeLayout(MeshChannel.Color, ComponentIndex.R, Vector2.up, 0, "_Texture1"), new AttributeLayout(MeshChannel.Color, ComponentIndex.G, Vector2.up, 0, "_Texture2"), new AttributeLayout(MeshChannel.Color, ComponentIndex.B, Vector2.up, 0, "_Texture3"), new AttributeLayout(MeshChannel.Color, ComponentIndex.A, Vector2.up, 0, "_Texture4"), }; #pragma warning disable 0618 path = ShaderMetaDataUtility.SaveMeshAttributesData(shader, attributes, true); #pragma warning restore 0618 } AssetDatabase.Refresh(); TextAsset asset = AssetDatabase.LoadAssetAtPath <TextAsset>(path); if (asset != null) { EditorGUIUtility.PingObject(asset); } }
static void UpdateShaderMetaToNewFormat() { foreach (Shader s in Selection.objects) { ShaderMetaDataUtility.ConvertMetaDataToNewFormat(s); } }
public override void OnInspectorGUI() { TextAsset asset = target as TextAsset; if (asset == null || !asset.name.EndsWith(".pbs")) { // sfor whatever reason this doesn't work // DrawDefaultInspector(); DrawTextAssetInspector(); return; } if (editor == null) { #pragma warning disable 0618 ShaderMetaDataUtility.TryReadAttributeLayoutsFromJson(asset.text, out container); #pragma warning disable 0618 editor = Editor.CreateEditor(container); } GUI.enabled = true; EditorGUI.BeginChangeCheck(); editor.OnInspectorGUI(); if (EditorGUI.EndChangeCheck()) { modified = true; } GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.enabled = modified; if (GUILayout.Button("Revert")) { ReloadJson(); } if (GUILayout.Button("Apply")) { ShaderMetaDataUtility.SaveMeshAttributesData(container, true); ReloadJson(); } GUILayout.EndHorizontal(); GUI.enabled = false; }
/// <summary> /// Test a gameObject and it's mesh renderers for compatible shaders, and if one is found /// load it's attribute data into meshAttributes. /// </summary> /// <param name="go">The GameObject being checked for texture blend support</param> /// <returns></returns> internal bool CheckForTextureBlendSupport(GameObject go) { bool supports = false; var materials = Util.GetMaterials(go); m_MeshAttributesContainers.Clear(); Material mat; List <int> indexes = new List <int>(); for (int i = 0; i < materials.Count; i++) { mat = materials[i]; if (ShaderMetaDataUtility.IsValidShader(mat.shader)) { AttributeLayoutContainer detectedMeshAttributes = ShaderMetaDataUtility.LoadShaderMetaData(mat.shader); { if (detectedMeshAttributes != null) { m_MeshAttributesContainers.Add(detectedMeshAttributes); indexes.Add(i); m_MainCacheMaterials.Add(mat); supports = true; } } } } if (supports) { m_MeshAttributesContainer = m_MeshAttributesContainers.First(); foreach (int i in indexes) { ArrayUtility.Add <string>(ref m_AvailableMaterialsAsString, materials[i].name); } } if (meshAttributes == null) { supports = false; } return(supports); }
/// <summary> /// Store the shader's attributes in the new format. /// Erase the .pbs.json on success. /// </summary> internal static void ConvertMetaDataToNewFormat(Shader shader) { if (shader == null) { throw new NullReferenceException("shader"); } string path = ShaderMetaDataUtility.FindPolybrushMetaDataForShader(shader); // If not null, it means we have data stored with the old format. // Proceed to conversion. if (path != null) { AttributeLayoutContainer attributesContainer = ScriptableObject.CreateInstance <AttributeLayoutContainer>(); ShaderMetaDataUtility.TryReadAttributeLayoutsFromJsonFile(path, out attributesContainer); if (attributesContainer != null) { ShaderMetaDataUtility.SaveShaderMetaData(shader, attributesContainer); FileUtil.DeleteFileOrDirectory(path); FileUtil.DeleteFileOrDirectory(path + ".meta"); AssetDatabase.Refresh(); } } }
/// <summary> /// Loads AttributeLayout data from a shader. Checks for both legacy (define Z_TEXTURE_CHANNELS) and /// .pbs.json metadata. /// </summary> /// <param name="material"></param> /// <param name="attribContainer"></param> /// <returns></returns> internal static bool GetMeshAttributes(Material material, out AttributeLayoutContainer attribContainer) { attribContainer = null; if (material == null) { return(false); } // first search for json, then fall back on legacy if (ShaderMetaDataUtility.FindMeshAttributesForShader(material.shader, out attribContainer)) { Dictionary <string, int> shaderProperties = new Dictionary <string, int>(); for (int i = 0; i < ShaderUtil.GetPropertyCount(material.shader); i++) { shaderProperties.Add(ShaderUtil.GetPropertyName(material.shader, i), i); } foreach (AttributeLayout a in attribContainer.attributes) { int index = -1; if (shaderProperties.TryGetValue(a.propertyTarget, out index)) { if (ShaderUtil.GetPropertyType(material.shader, index) == ShaderUtil.ShaderPropertyType.TexEnv) { a.previewTexture = (Texture2D)material.GetTexture(a.propertyTarget); } } } return(true); } return(false); }