void OnDisable() { //Debug.Log("Inspector OnDisable workingObj: " + workingObj + " isPLaying " + Application.isPlaying); if (hasChanges && EditorUtility.DisplayDialog("Unapplied import settings", "Unapplied import settings for '" + assetPath + "'", "Apply", "Revert")) { _applyProgramChanges(); } if (prog != null) { // First destroy the processors KrablMesh.Processor[] procs = prog.processors; for (int i = 0; i < procs.Length; ++i) { DestroyImmediate(procs[i]); } DestroyImmediate(prog); prog = null; } if (progGUI != null) { DestroyImmediate(progGUI); progGUI = null; } }
override public void Calculate(ref KrablMesh.MeshEdges mesh, KMProcessorProgram parentProgram = null) { base.Calculate(ref mesh); if (materials == MaterialOption.Merge) { mesh.numMaterials = 1; int numFaces = mesh.faceCount(); for (int i = 0; i < numFaces; ++i) { mesh.faces[i].material = 0; } } if (vertexColors == Option.Remove) { mesh.hasVertexColors = false; } if (uv1Option == Option.Remove) { mesh.hasUV1 = false; } if (uv2Option == Option.Remove) { mesh.hasUV2 = false; } /*if (skin == Option.Remove) { * mesh.hasBoneWeights = false; * mesh.bindposes = null; * }*/ }
void _initializeProgram() { storedProg = null; prog = null; progGUI = null; // Look for a program stored in the asset. storedProg = KMImportSettings.ProgramForMesh(assetGUID, meshPath); if (storedProg != null) { // Create a copy of the program to work with. prog = ScriptableObject.CreateInstance <KMProcessorProgram>(); EditorUtility.CopySerialized(storedProg, prog); int numProcessors = prog.processors.Length; for (int i = 0; i < numProcessors; ++i) { KrablMesh.Processor proc = prog.processors[i]; KrablMesh.Processor clone = ScriptableObject.CreateInstance(proc.GetType()) as KrablMesh.Processor; EditorUtility.CopySerialized(proc, clone); clone.hideFlags = HideFlags.DontSave; prog.processors[i] = clone; } prog.hideFlags = HideFlags.DontSave; progGUI = (KMProcessorProgramGUI)Editor.CreateEditor(prog); if (progGUI != null) { progGUI.usedByMeshImporter = true; } } }
public static void AddProgram(KMProcessorProgram prog) { _assureInstance(); if (prog == null) { return; } HideFlags hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector; prog.hideFlags = hideFlags; AssetDatabase.AddObjectToAsset(prog, _instance); // storing to the file. // Store all the processors to the asset file as well. for (int i = 0; i < prog.processors.Length; ++i) { prog.processors[i].hideFlags = hideFlags; AssetDatabase.AddObjectToAsset(prog.processors[i], _instance); } ArrayUtility.Add <KMProcessorProgram>(ref _instance.programs, prog); // this import sometimes takes very long (7 sec)... not sure why but it's a reason not to do it. // AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(_instance)); // Needed? It does lead to the subassets showing up in case they are not hidden. // Save assets leads to the same problem // AssetDatabase.SaveAssets(); }
override public void Calculate(ref KrablMesh.MeshEdges mesh, KMProcessorProgram parentProgram = null) { base.Calculate(ref mesh); SubdivideQ sub = new SubdivideQ(); SubdivideQParameters par = new SubdivideQParameters(); sub.progressDelegate = delegate(string text, float val) { ReportProgress(text, val); }; par.trisToQuads = trisToQuads; par.trisToQuadsMaxAngle = trisToQuadsMaxEdgeAngle; par.iterations = iterations; par.recalculateNormals = (normalMode == NormalMode.Recalculate); if (platformID != null) { for (int i = 0; i < iterationsOverridePlatform.Length; ++i) { if (platformID.Equals(iterationsOverridePlatform[i])) { par.iterations = iterationsOverride[i]; break; } } } sub.Execute(ref mesh, par); }
// Called from progGUI public void DeleteProgram() { if (prog == null) { return; } bool del = true; if (prog.processors.Length > 0) { del = EditorUtility.DisplayDialog("Delete Import Program", "Do you want to permanently delete this mesh import program?", "Delete", "Cancel"); } if (del) { if (storedProg != null) { EditorUtility.DisplayProgressBar(KMImportProcessor.ProgressTitle(prog), "Unity3D reimports model file", 0.0f); KMImportSettings.RemoveProgram(storedProg); // Trigger model reimport AssetDatabase.ImportAsset(assetPath); EditorUtility.ClearProgressBar(); } prog = null; progGUI = null; storedProg = null; } }
override public void Calculate(ref KrablMesh.MeshEdges mesh, KMProcessorProgram parentProgram = null) { base.Calculate(ref mesh); bool recalcNormals = false; KrablMesh.CreaseDetect.ClearAllCreases(mesh); if (creasesFromNormals) { KrablMesh.CreaseDetect.MarkCreasesFromFaceNormals(mesh, 1.0f); // if (creaseStrength < 1.0f) recalcNormals = true; } else { recalcNormals = true; } if (creasesFromEdgeAngles) { KrablMesh.CreaseDetect.MarkCreasesFromEdgeAngles(mesh, minEdgeAngle, 1.0f); recalcNormals = true; } if (creasesFromMaterialSeams) { KrablMesh.CreaseDetect.MarkCreasesFromMaterialSeams(mesh, 1.0f); recalcNormals = true; } if (recalcNormals) { mesh.CalculateFaceVertexNormalsFromEdgeCreases(); } }
void AddProgram() { // Create an empty program in memory prog = KMImportSettings.CreateProgram(assetGUID, meshPath, mesh); // Now create the GUI progGUI = (KMProcessorProgramGUI)Editor.CreateEditor(prog); if (progGUI != null) { progGUI.usedByMeshImporter = true; } hasChanges = true; }
void OnEnable() { // Debug.Log("Inspector OnEnable workingObj " + workingObj); storedProg = null; prog = null; hasChanges = false; progGUI = null; searchedForProgram = false; meshPath = null; mesh = null; // Don't fetch the prog here, as this will break the intial library buildup as it creates the settings before they are imported .. when creating previews }
public void OnEnable() { if (target != null) { prog = (KMProcessorProgram)target; processorsProp = serializedObject.FindProperty("processors"); unityOptimizeMeshProp = serializedObject.FindProperty("unityOptimizeMesh"); inputToleranceProp = serializedObject.FindProperty("inputTolerance"); bypassProp = serializedObject.FindProperty("bypass"); // targetPathProp = serializedObject.FindProperty("targetPath"); } processorEditors.Clear(); largeButtonStyle = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).GetStyle("LargeButton"); }
public static KMProcessorProgram ProgramForMesh(string assetGUID, string meshPath) { _assureInstance(); KMProcessorProgram[] programs = _instance.programs; for (int i = 0; i < programs.Length; ++i) { KMProcessorProgram prog = programs[i]; if (prog != null && prog.inAssetGUID.Equals(assetGUID) && prog.inMeshPath.Equals(meshPath)) { return(prog); } } return(null); }
void _revertProgramChanges() { if (prog != null) { KrablMesh.Processor[] procs = prog.processors; for (int i = 0; i < procs.Length; ++i) { DestroyImmediate(procs[i]); } DestroyImmediate(prog); prog = null; } // Get a new clone of the original prog _initializeProgram(); hasChanges = false; }
public static KMProcessorProgram CreateProgram(string assetGUID, string meshPath, UnityEngine.Mesh mesh) { KMProcessorProgram prog = ScriptableObject.CreateInstance <KMProcessorProgram>(); string assetPath = AssetDatabase.GUIDToAssetPath(assetGUID); prog.inMeshPath = meshPath; prog.inContainerName = System.IO.Path.GetFileNameWithoutExtension(assetPath); prog.inAssetGUID = assetGUID; prog.inMeshDescription = KMProcessorProgram.MeshDescription(mesh); // number of verts/tris etc. prog.name = "KMProcessorProgram"; if (prog.descriptiveName() != null) { prog.name += "[" + prog.descriptiveName() + "]"; } return(prog); }
public static void RemoveProgram(KMProcessorProgram prog) { _assureInstance(); if (prog == null) { return; } // Remove from the array ArrayUtility.Remove <KMProcessorProgram>(ref _instance.programs, prog); // Destroy all the store processors for (int i = 0; i < prog.processors.Length; ++i) { DestroyImmediate(prog.processors[i], true); } // Destroy the program DestroyImmediate(prog, true); // AssetDatabase.SaveAssets(); // Needed? sometimes it is crazy slow }
override public void Calculate(ref KrablMesh.MeshEdges mesh, KMProcessorProgram parentProgram = null) { base.Calculate(ref mesh); KrablMesh.Simplify sim = new KrablMesh.Simplify(); KrablMesh.SimplifyParameters par = new KrablMesh.SimplifyParameters(); sim.progressDelegate = delegate(string text, float val) { ReportProgress(text, val); }; // par.maximumError = maximumError; par.targetFaceCount = targetTriangleCount; if (platformID != null) { for (int i = 0; i < ttcOverridePlatform.Length; ++i) { if (platformID.Equals(ttcOverridePlatform[i])) { par.targetFaceCount = ttcOverrideTargetTriangleCount[i]; break; } } } par.recalculateVertexPositions = allowVertexReposition; par.preventNonManifoldEdges = preventNonManifoldEdges; par.borderWeight = borders; par.creaseWeight = creases; par.uvSeamWeight = uvSeams; par.uv2SeamWeight = uv2Seams; par.materialSeamWeight = materialSeams; // par.minTriangleShape = minTriangleShape; par.boneWeightProtection = boneWeightProtection; par.vertexColorProtection = vertexColorProtection; // par.vertexNormalProtection = vertexNormalProtection; sim.Execute(ref mesh, par); }
public static void SettingsReimported() { _assureInstance(); float tm = 0.0f; if (KMImportSettings.DoDebug()) { tm = Time.realtimeSinceStartup; Debug.Log("Mesh Processor Settings were reimported."); } Dictionary <string, int> revisionDB = KMImportProcessor.GetModelImportRevisionDictionary(); KMProcessorProgram[] programs = _instance.programs; for (int i = 0; i < programs.Length; ++i) { KMProcessorProgram prog = programs[i]; if (prog != null) { int modelImportRevision = 0; // this is the revision number of the import on the running machine // prog.importRevision is the revision stored inside the importer asset // They need to be the same in order for the mesh to have the correct state. revisionDB.TryGetValue(prog.inAssetGUID, out modelImportRevision); //Debug.Log("P: " + path + " Rev New: " + rev); // If the importsettings changed on a different machine, // we need to reimport the changed assets if (modelImportRevision != prog.importRevision) { string path = AssetDatabase.GUIDToAssetPath(prog.inAssetGUID); if (path != null && path != "") { AssetDatabase.ImportAsset(path); } } } } if (KMImportSettings.DoDebug()) { Debug.Log("Settings reimported took " + (Time.realtimeSinceStartup - tm) * 1000.0f + " ms."); } }
bool _processMesh(GameObject container, Mesh umesh) { #if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 if (umesh.blendShapeCount > 0) { Debug.Log("Krabl Mesh Processors can not yet process meshes with blendshapes."); return(false); } #endif string assetGUID = AssetDatabase.AssetPathToGUID(assetPath); //Debug.Log("Container guid: " + assetGUID); string meshPath = KrablMesh.UnityEditorUtils.MeshPathInAsset(umesh, container); //Debug.Log("Meshpath: " + meshPath); KMProcessorProgram program = KMImportSettings.ProgramForMesh(assetGUID, meshPath); if (program == null) { return(false); } if (program.bypass) { return(true); } // Debug.Log("KMImportProcessor Process " + container.name + "/" + umesh.name + " PRG: " + ((program == null) ? "NULL" : program.ToString()), umesh); KrablMesh.Processor[] processors = program.processors; if (true) //program.importTriggeredByInspector == true) { // Set up progress indicators { program.importTriggeredByInspector = false; float numEnabled = 0.0f; for (int i = 0; i < processors.Length; ++i) { if (processors[i].enabled) { numEnabled += 1.0f; } } float progStep = (numEnabled > 0.0f) ? 1.0f / numEnabled : 1.0f; float progOffset = 0.0f; string title = ProgressTitle(program); for (int i = 0; i < processors.Length; ++i) { if (processors[i].enabled == true) { float offset = progOffset; processors[i].progressDelegate = delegate(string text, float val) { EditorUtility.DisplayProgressBar(title, text, val * progStep + offset); }; progOffset += progStep; } } } Mesh processedMesh = program.Process(umesh, EditorUserBuildSettings.selectedBuildTargetGroup.ToString()); processedMesh.name = umesh.name; if (program.unityOptimizeMesh) { ; } EditorUtility.ClearProgressBar(); // Store Revision to program program.importRevision = importRevision; EditorUtility.SetDirty(program); //AssetDatabase.SaveAssets(); if (program.targetPath.Equals("replace")) { umesh.Clear(); EditorUtility.CopySerialized(processedMesh, umesh); } else { _outputToAsset(processedMesh, program.targetPath); } GameObject.DestroyImmediate(processedMesh); return(true); }
static public string ProgressTitle(KMProcessorProgram prog) { return("Mesh Processors: " + prog.descriptiveName()); }
virtual public void Calculate(ref KrablMesh.MeshEdges mesh, KMProcessorProgram parentProgram = null) { ReportProgress("", 0.0f); }
public void OnDisable() { processorEditors.Clear(); prog = null; }
override public void OnInspectorGUI() { DrawDefaultInspector(); GUI.enabled = true; if (meshPath == null) { mesh = (UnityEngine.Mesh)target; assetPath = AssetDatabase.GetAssetPath(target); assetGUID = AssetDatabase.AssetPathToGUID(assetPath); GameObject asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)) as GameObject; meshPath = KrablMesh.UnityEditorUtils.MeshPathInAsset(mesh, asset); } if (prog == null && searchedForProgram == false) { _initializeProgram(); searchedForProgram = true; } // Mesh information on top. // Mesh path string path = ""; if (assetPath != null && assetPath != "") { path += assetPath.Replace("Assets/", "") + " - "; } GUILayout.BeginHorizontal(); GUILayout.Label("Mesh Path: ", GUILayout.Width(80.0f)); GUILayout.Label(path + meshPath); GUILayout.EndHorizontal(); // Mesh description string desc; if (prog != null) { desc = prog.inMeshDescription; if (desc == null || desc == "") { desc = "n/a"; } } else { desc = KMProcessorProgram.MeshDescription(mesh); } GUILayout.BeginHorizontal(); GUILayout.Label("Description: ", GUILayout.Width(80.0f)); GUILayout.Label(desc); GUILayout.EndHorizontal(); GUI.enabled = true; if (prog != null && progGUI != null) { // The program object draws all the processors etc. progGUI.DrawImporterGUI(this); } // prog and progGUI might have disappeared from delete, so check again if (prog != null && progGUI != null) { // Draw the part below the processors with Apply and Revert if (progGUI.modifiedDuringLastUpdate) { hasChanges = true; } GUI.enabled = hasChanges; EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Revert", GUILayout.ExpandWidth(false))) { _revertProgramChanges(); return; } if (GUILayout.Button("Apply", GUILayout.ExpandWidth(false))) { GUI.FocusControl(""); // make sure text editor field get committed _applyProgramChanges(); } EditorGUILayout.EndHorizontal(); GUI.enabled = true; } else { // Draw the Add mesh import program section. EditorGUILayout.Separator(); bool canUseProgram = (assetPath != null && assetPath != ""); #if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 if (mesh.blendShapeCount > 0) { canUseProgram = false; } #endif if (canUseProgram) { GUIStyle largeButtonStyle = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).GetStyle("LargeButton"); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Add Mesh Import Program", largeButtonStyle)) { AddProgram(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } else { bool specialError = false; #if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 if (mesh.blendShapeCount > 0) { EditorGUILayout.HelpBox( "Meshes with blendshapes can not yet be processed by Krabl Mesh Processors.\n\n" + "Support will be added as soon as Unity exposes blendshape access in the API.", MessageType.Info); specialError = true; } #endif if (specialError == false) { EditorGUILayout.HelpBox( "Only meshes inside the project folder can have mesh import programs.\n\n" + "Built-In meshes and scene meshes are never imported by Unity.", MessageType.Info); } } } }