/// <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) { AttributeLayoutContainer detectedMeshAttributes; 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 (PolyShaderUtil.GetMeshAttributes(mat, out detectedMeshAttributes)) { m_MeshAttributesContainers.Add(detectedMeshAttributes); indexes.Add(i); supports = true; } } if (supports) { m_MeshAttributesContainer = m_MeshAttributesContainers.First(); foreach (int i in indexes) { ArrayUtility.Add <string>(ref m_AvailableMaterialsAsString, materials[i].name); } } return(supports); }
/// <summary> /// Find a path to the Polybrush metadata for a shader. /// </summary> /// <param name="shader">Shader associated with the metadata</param> /// <returns>The path found, null if not found.</returns> internal static string FindPolybrushMetaDataForShader(Shader shader) { if (shader == null) { return(null); } string path = AssetDatabase.GetAssetPath(shader); if (string.IsNullOrEmpty(path)) { return(null); } string filename = Path.GetFileNameWithoutExtension(path); string directory = Path.GetDirectoryName(path); string[] paths = new string[] { string.Format("{0}/{1}.{2}", directory, PolyShaderUtil.GetMetaDataPath(shader), SHADER_ATTRIB_FILE_EXTENSION), string.Format("{0}/{1}.{2}", directory, filename, SHADER_ATTRIB_FILE_EXTENSION) }; // @todo verify that the json is actually valid foreach (string str in paths) { if (File.Exists(str)) { // remove `..` from path since `AssetDatabase.LoadAssetAtPath` doesn't like 'em string full = Path.GetFullPath(str).Replace("\\", "/"); string resolved = full.Replace(Application.dataPath, "Assets"); return(resolved); } } return(null); }
/// <summary> /// Searches only by looking for a compatibly named file in the same directory. /// </summary> /// <param name="shader">Shader associated with the metadata</param> /// <param name="attributes">result if any metadata found</param> /// <returns></returns> internal static bool FindMeshAttributesForShader(Shader shader, out AttributeLayoutContainer attributes) { attributes = null; string path = AssetDatabase.GetAssetPath(shader); string filename = Path.GetFileNameWithoutExtension(path); string directory = Path.GetDirectoryName(path); string[] paths = new string[] { string.Format("{0}/{1}.{2}", directory, filename, SHADER_ATTRIB_FILE_EXTENSION), string.Format("{0}/{1}.{2}", directory, PolyShaderUtil.GetMetaDataPath(shader), SHADER_ATTRIB_FILE_EXTENSION) }; foreach (string str in paths) { if (TryReadAttributeLayoutsFromJsonFile(str, out attributes)) { return(true); } } return(false); }
// Called when the mouse begins hovering an editable object. internal override void OnBrushEnter(EditableObject target, BrushSettings settings) { base.OnBrushEnter(target, settings); if (target.graphicsMesh == null) { return; } EditableObjectData data; if (!m_EditableObjectsData.TryGetValue(target, out data)) { data = new EditableObjectData(); m_EditableObjectsData.Add(target, data); } RebuildCaches(target, settings); data.TriangleLookup = PolyMeshUtility.GetAdjacentTriangles(target.editMesh); MeshRenderer mr = target.gameObjectAttached.GetComponent <MeshRenderer>(); if (mr != null && mr.sharedMaterials != null) { data.LikelySupportsVertexColors = mr.sharedMaterials.Any(x => x != null && x.shader != null && PolyShaderUtil.SupportsVertexColors(x.shader)); } else { data.LikelySupportsVertexColors = false; } }