private void reset() { // Meshes mGlobalScale = 1.0f; mMeshCompression = ModelImporterMeshCompression.Off; mOptimizeMesh = false; mAddCollider = false; mSwapUVChannels = false; mGenerateSecondaryUV = false; // Normals & Tangents mNormalImportMode = ModelImporterTangentSpaceMode.Import; mTangentImportMode = ModelImporterTangentSpaceMode.Calculate; mNormalSmoothingAngle = 60.0f; mSplitTangentsAcrossSeams = false; // Materials mImportMaterials = true; mMaterialName = ModelImporterMaterialName.BasedOnTextureName; mMaterialSearch = ModelImporterMaterialSearch.RecursiveUp; // remember current preset selection mCurrentPresetName = mDefaultPresetName; EditorPrefs.SetString( "ModelImportManager.CurrentPreset", mCurrentPresetName ); }
public static bool ExportGameObjToFBX(GameObject gameObj, string newPath, bool copyMaterials = false, bool copyTextures = false) { // Check to see if the extension is right if (newPath.Remove(0, newPath.LastIndexOf('.')) != ".fbx") { Debug.LogError("The end of the path wasn't \".fbx\""); return(false); } if (copyMaterials) { CopyComplexMaterialsToPath(gameObj, newPath, copyTextures); } Renderer[] meshRenderers = gameObj.GetComponentsInChildren <Renderer>(); #if UNITY_EDITOR AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); #endif string buildMesh = MeshToString(gameObj, newPath, copyMaterials, copyTextures); //if(System.IO.File.Exists(newPath)) // System.IO.File.Delete(newPath); //System.IO.File.WriteAllText(newPath, buildMesh); #if UNITY_EDITOR // Import the model properly so it looks for the material instead of by the texture name // TODO: By calling refresh, it imports the model with the wrong materials, but we can't find the model to import without // refreshing the database. A chicken and the egg issue AssetDatabase.Refresh(); string stringLocalPath = newPath.Remove(0, newPath.LastIndexOf("/Assets") + 1); ModelImporter modelImporter = ModelImporter.GetAtPath(stringLocalPath) as ModelImporter; if (modelImporter != null) { ModelImporterMaterialName modelImportOld = modelImporter.materialName; modelImporter.materialName = ModelImporterMaterialName.BasedOnMaterialName; #if UNITY_5_1 modelImporter.normalImportMode = ModelImporterTangentSpaceMode.Import; #else modelImporter.importNormals = ModelImporterNormals.Import; #endif if (copyMaterials == false) { modelImporter.materialSearch = ModelImporterMaterialSearch.Everywhere; } AssetDatabase.ImportAsset(stringLocalPath, ImportAssetOptions.ForceUpdate); } else { Debug.Log("Model Importer is null and can't import"); } AssetDatabase.Refresh(); #endif return(true); }
private void loadPreset( string presetName ) { string prefix = "ModelImportManager." + presetName; // Meshes mGlobalScale = EditorPrefs.GetFloat( prefix + ".GlobalScale", 1.0f ); mMeshCompression = (ModelImporterMeshCompression)System.Enum.Parse( typeof(ModelImporterMeshCompression), EditorPrefs.GetString( prefix + ".MeshCompression", "Off" ) ); mOptimizeMesh = EditorPrefs.GetBool( prefix + ".OptimizeMesh", false ); mAddCollider = EditorPrefs.GetBool( prefix + ".AddCollider", false ); mSwapUVChannels = EditorPrefs.GetBool( prefix + ".SwapUVChannels", false ); mGenerateSecondaryUV = EditorPrefs.GetBool( prefix + ".GenerateSecondaryUV", false ); // Normals & Tangents mNormalImportMode = (ModelImporterTangentSpaceMode)System.Enum.Parse( typeof(ModelImporterTangentSpaceMode), EditorPrefs.GetString( prefix + ".NormalImportMode", "Import" ) ); mTangentImportMode = (ModelImporterTangentSpaceMode)System.Enum.Parse( typeof(ModelImporterTangentSpaceMode), EditorPrefs.GetString( prefix + ".TangentImportMode", "Calculate" ) ); mNormalSmoothingAngle = EditorPrefs.GetFloat( prefix + ".NormalSmoothingAngle", 60.0f ); mSplitTangentsAcrossSeams = EditorPrefs.GetBool( prefix + ".SplitTangentsAcrossSeams", false ); // Materials mImportMaterials = EditorPrefs.GetBool( prefix + ".ImportMaterials", false ); mMaterialName = (ModelImporterMaterialName)System.Enum.Parse( typeof(ModelImporterMaterialName), EditorPrefs.GetString( prefix + ".MaterialName", "BasedOnTextureName" ) ); mMaterialSearch = (ModelImporterMaterialSearch)System.Enum.Parse( typeof(ModelImporterMaterialSearch), EditorPrefs.GetString( prefix + ".MaterialSearch", "RecursiveUp" ) ); // remember current preset selection mCurrentPresetName = presetName; EditorPrefs.SetString( "ModelImportManager.CurrentPreset", mCurrentPresetName ); }
private void DisplayMaterialSettings() { GUILayout.Label("Material Settings", EditorStyles.miniBoldLabel); importMaterials = EditorGUILayout.Toggle("Import Materials", importMaterials); materialNameMode = (ModelImporterMaterialName)EditorGUILayout.EnumPopup("Material Naming", materialNameMode); materialSearch = (ModelImporterMaterialSearch)EditorGUILayout.EnumPopup("Material Search", materialSearch); }
public override void ApplyDefaults() { this.RuleName = "New Model Rule"; SuffixFilter = ".FBX"; meshCompression = ModelImporterMeshCompression.Off; isReadable = false; importBlendShapes = false; optimizeMeshForGPU = true; generateColliders = false; keepQuads = false; weldVertices = true; swapUVChannels = false; generateSecondaryUV = false; normalImportMode = ModelImporterNormals.None; tangentImportMode = ModelImporterTangents.CalculateMikk; importMaterials = true; materialName = ModelImporterMaterialName.BasedOnTextureName; materialSearch = ModelImporterMaterialSearch.Everywhere; animationType = ModelImporterAnimationType.None; importAnimation = false; animCompression = ModelImporterAnimationCompression.Off; }
private void InitModel() { m_globalScale = 1f; m_meshCompression = ModelImporterMeshCompression.Off; m_isReadable = true; m_optimizeMesh = true; m_importBlendShapes = true; m_addCollider = false; m_swapUVChannels = false; m_importNormals = ModelImporterNormals.Import; m_importTangents = ModelImporterTangents.CalculateMikk; m_importMaterials = true; m_materialName = ModelImporterMaterialName.BasedOnTextureName; m_materialSearch = ModelImporterMaterialSearch.RecursiveUp; }
private void DrawMaterialsGUI() { importMaterials = EditorGUILayout.Toggle(AssetImportStyles.Model.ImportMaterials, importMaterials); string tip; if (importMaterials) { materialName = (ModelImporterMaterialName)EditorGUILayout.Popup(AssetImportStyles.Model.MaterialName, (int)materialName, AssetImportStyles.Model.MaterialNameOptMain); materialSearch = (ModelImporterMaterialSearch)EditorGUILayout.Popup(AssetImportStyles.Model.MaterialSearch, (int)materialSearch, AssetImportStyles.Model.MaterialSearchOpt); tip = string.Concat(AssetImportStyles.Model.MaterialHelpStart.text.Replace("%MAT%", AssetImportStyles.Model.MaterialNameHelp[(int)materialName].text), "\n", AssetImportStyles.Model.MaterialSearchHelp[(int)materialSearch].text, "\n", AssetImportStyles.Model.MaterialHelpEnd.text); } else { tip = AssetImportStyles.Model.MaterialHelpDefault.text; } GUILayout.Label(new GUIContent(tip), EditorStyles.helpBox, new GUILayoutOption[0]); }
public void ApplyDefaults() { m_MeshCompression = ModelImporterMeshCompression.Off; m_IsReadable = false; m_ImportBlendShapes = false; m_AddColliders = false; keepQuads = false; m_weldVertices = true; swapUVChannels = false; generateSecondaryUV = false; normalImportMode = ModelImporterNormals.None; tangentImportMode = ModelImporterTangents.None; m_ImportMaterials = true; m_MaterialName = ModelImporterMaterialName.BasedOnMaterialName; m_MaterialSearch = ModelImporterMaterialSearch.Everywhere; AnimationType = ModelImporterAnimationType.None; ImportAnimation = false; }
private void DrawModel() { EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Meshes", EditorStyles.boldLabel); GUI.color = Color.grey; EditorGUILayout.LabelField("File Scale"); GUI.color = Color.white; m_globalScale = EditorGUILayout.FloatField("Scale Factor", m_globalScale); m_meshCompression = (ModelImporterMeshCompression)EditorGUILayout.EnumPopup("Mesh Compression", m_meshCompression); m_isReadable = EditorGUILayout.Toggle("Read/Write Enabled", m_isReadable); m_optimizeMesh = EditorGUILayout.Toggle("Optimize Mesh", m_optimizeMesh); m_importBlendShapes = EditorGUILayout.Toggle("Import BlendShapes", m_importBlendShapes); m_addCollider = EditorGUILayout.Toggle("Generate Colliders", m_addCollider); GUI.color = Color.grey; EditorGUILayout.LabelField("Keep Quads"); GUI.color = Color.white; m_swapUVChannels = EditorGUILayout.Toggle("Swap UVs", m_swapUVChannels); GUI.color = Color.grey; EditorGUILayout.LabelField("Generate Lightmap UVs"); GUI.color = Color.white; EditorGUILayout.LabelField("Normals & Tangents", EditorStyles.boldLabel); m_importNormals = (ModelImporterNormals)EditorGUILayout.EnumPopup("Normals", m_importNormals); GUI.color = Color.grey; EditorGUILayout.LabelField("Smoothing Angle"); GUI.color = Color.white; m_importTangents = (ModelImporterTangents)EditorGUILayout.EnumPopup("Tangents", m_importTangents); EditorGUILayout.LabelField("Materials", EditorStyles.boldLabel); m_importMaterials = EditorGUILayout.Toggle("Import Materials", m_importMaterials); if (m_importMaterials == true) { m_materialName = (ModelImporterMaterialName)EditorGUILayout.EnumPopup("Material Naming", m_materialName); m_materialSearch = (ModelImporterMaterialSearch)EditorGUILayout.EnumPopup("Material Search", m_materialSearch); } EditorGUILayout.EndVertical(); }
private void drawSettingDialog() { GUILayout.BeginVertical( GUILayout.MinWidth( 300 ), GUILayout.MaxWidth( 1000 ), GUILayout.ExpandWidth( true ) ); GUILayout.Label( "Meshes", EditorStyles.boldLabel ); // Global scale factor for importing. mGlobalScale = EditorGUILayout.FloatField( "Scale Factor", mGlobalScale ); // Mesh compression setting. mMeshCompression = (ModelImporterMeshCompression)EditorGUILayout.EnumPopup( "Mesh Compression", mMeshCompression ); // Vertex optimization setting mOptimizeMesh = EditorGUILayout.Toggle( "Optimize Mesh", mOptimizeMesh ); // Add mesh colliders to imported meshes. mAddCollider = EditorGUILayout.Toggle( "Generate Colliders", mAddCollider ); // Swap primary and secondary UV channels when importing. mSwapUVChannels = EditorGUILayout.Toggle( "Swap UVs", mSwapUVChannels ); // Generate secondary UV set for lightmapping. mGenerateSecondaryUV = EditorGUILayout.Toggle( "Generate Lightmap UVs", mGenerateSecondaryUV ); EditorGUILayout.Space(); GUILayout.Label( "Normals & Tangents", EditorStyles.boldLabel ); // Normals import mode. mNormalImportMode = (ModelImporterTangentSpaceMode)EditorGUILayout.EnumPopup( "Normals", mNormalImportMode ); // Tangents import mode. mTangentImportMode = (ModelImporterTangentSpaceMode)EditorGUILayout.EnumPopup( "Tangents", mTangentImportMode ); EditorGUI.BeginDisabledGroup( mNormalImportMode != ModelImporterTangentSpaceMode.Calculate ); // Smoothing angle for calculating normals. mNormalSmoothingAngle = (int)EditorGUILayout.IntSlider( "Smoothing Angle", (int)mNormalSmoothingAngle, 0, 180 ); EditorGUI.EndDisabledGroup(); // Should tangents be split across UV seams. mSplitTangentsAcrossSeams = EditorGUILayout.Toggle( "Split Tangents", mSplitTangentsAcrossSeams ); EditorGUILayout.Space(); GUILayout.Label( "Materials", EditorStyles.boldLabel ); // Import materials from file. mImportMaterials = EditorGUILayout.Toggle( "Import Materials", mImportMaterials ); EditorGUI.BeginDisabledGroup( !mImportMaterials ); // Material naming setting. mMaterialName = (ModelImporterMaterialName)EditorGUILayout.EnumPopup( "Material Naming", mMaterialName ); // Existing material search setting. mMaterialSearch = (ModelImporterMaterialSearch)EditorGUILayout.EnumPopup( "Material Search", mMaterialSearch ); EditorGUI.EndDisabledGroup(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); if( mCurrentPresetName != mDefaultPresetName ) { if( GUILayout.Button( "Save" ) ) savePreset( mCurrentPresetName ); if( GUILayout.Button( "Delete" ) ) deletePreset( mCurrentPresetName ); } else { if( GUILayout.Button( "Save As", GUILayout.Width( 200 ) ) && ( mNewPresetName.Length > 0 ) && ( mNewPresetName != mDefaultPresetName ) ) { savePreset( mNewPresetName ); loadPreset( mNewPresetName ); } // only characters allowed mNewPresetName = Regex.Replace( GUILayout.TextField( mNewPresetName ), @"[^\w]", string.Empty ); } EditorGUILayout.EndHorizontal(); GUILayout.EndVertical(); }
public extern bool SearchAndRemapMaterials(ModelImporterMaterialName nameOption, ModelImporterMaterialSearch searchOption);
public override void DrawInnerGUI() { DrawFilterGUI(); EditorGUILayout.LabelField("Meshes", EditorStyles.boldLabel); EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 2), QuickEditorColors.DarkGrayX11); GUILayout.Space(3); ScaleFactor = EditorGUILayout.FloatField("Scale Factor", ScaleFactor); MeshCompression = (ModelImporterMeshCompression)EditorGUILayout.EnumPopup("Mesh Compression", MeshCompression); ReadWriteEnabled = EditorGUILayout.Toggle("Read/Write Enabled", ReadWriteEnabled); OptimizeMesh = EditorGUILayout.Toggle("Optimize Mesh", OptimizeMesh); ImportBlendShapes = EditorGUILayout.Toggle("Import BlendShapes", ImportBlendShapes); GenerateColliders = EditorGUILayout.Toggle("Generate Colliders", GenerateColliders); KeepQuads = EditorGUILayout.Toggle("Keep Quads", KeepQuads); WeldVertices = EditorGUILayout.Toggle("Weld Vertices", WeldVertices); ImportVisibility = EditorGUILayout.Toggle("Import Visibility", ImportVisibility); ImportCameras = EditorGUILayout.Toggle("Import Cameras", ImportCameras); ImportLights = EditorGUILayout.Toggle("Import Lights", ImportLights); SwapUVs = EditorGUILayout.Toggle("Swap UVs", SwapUVs); GenerateLightmapUV = EditorGUILayout.Toggle("Generate Lightmap UVs", GenerateLightmapUV); if (GenerateLightmapUV) { EditorGUI.indentLevel++; LightmapHardAngle = EditorGUILayout.IntSlider("Hard Angle", LightmapHardAngle, 0, 180); LightmapPadding = EditorGUILayout.IntSlider("Pack Margin", LightmapPadding, 1, 64); LightmapAngleError = EditorGUILayout.IntSlider("Angle Error", LightmapAngleError, 1, 75); LightmapAreaError = EditorGUILayout.IntSlider("Area Error", LightmapAreaError, 1, 75); EditorGUI.indentLevel--; } GUILayout.Space(6); EditorGUILayout.LabelField("Normals & Tangent", EditorStyles.boldLabel); EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 2), QuickEditorColors.DarkGrayX11); GUILayout.Space(3); ImportNormals = (ModelImporterNormals)EditorGUILayout.EnumPopup("Normals", ImportNormals); EditorGUI.BeginDisabledGroup(ImportNormals == ModelImporterNormals.Calculate ? false : true); //NormalCalculationMode = (ModelImporterNormalCalculationMode)EditorGUILayout.EnumPopup("Normals Mode", NormalCalculationMode); SmoothingAngle = EditorGUILayout.IntSlider("Smoothing Angle", SmoothingAngle, 0, 180); EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(ImportNormals == ModelImporterNormals.None ? true : false); TangentMode = (ModelImporterTangents)EditorGUILayout.EnumPopup("Tangents", TangentMode); EditorGUI.EndDisabledGroup(); GUILayout.Space(6); EditorGUILayout.LabelField("Materials", EditorStyles.boldLabel); EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 2), QuickEditorColors.DarkGrayX11); GUILayout.Space(3); ImportMats = EditorGUILayout.Toggle("Import Materials", ImportMats); if (ImportMats) { MaterialNaming = (ModelImporterMaterialName)EditorGUILayout.EnumPopup("Material Naming", MaterialNaming); MaterialSearch = (ModelImporterMaterialSearch)EditorGUILayout.EnumPopup("Material Search", MaterialSearch); } GUILayout.Space(6); EditorGUILayout.LabelField("Animation", EditorStyles.boldLabel); EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 2), QuickEditorColors.DarkGrayX11); GUILayout.Space(3); ImportAnim = EditorGUILayout.Toggle("Import Animation", ImportAnim); ForceNoRig = EditorGUILayout.Toggle("Force no rig", ForceNoRig); GUILayout.Space(8); }
/// <inherit/> public override void OnGUI() { // meshes EditorGUILayout.LabelField("Meshes", EditorStyles.boldLabel); scaleFactor = EditorGUILayout.FloatField("Scale Factor", scaleFactor); meshCompression = (ModelImporterMeshCompression)EditorGUILayout.EnumPopup("Mesh Compression", meshCompression); readWriteEnabled = EditorGUILayout.Toggle("Read/Write Enabled", readWriteEnabled); optimizeMesh = EditorGUILayout.Toggle("Optimize Mesh", optimizeMesh); importBlendShapes = EditorGUILayout.Toggle("Import BlendShapes", importBlendShapes); generateColliders = EditorGUILayout.Toggle("Generate Colliders", generateColliders); swapUVs = EditorGUILayout.Toggle("Swap UVs", swapUVs); generateLightmapUV = EditorGUILayout.Toggle("Generate Lightmap UVs", generateLightmapUV); // normals and tangents EditorGUILayout.LabelField("Normals & Tangents", EditorStyles.boldLabel); normals = (ModelImporterTangentSpaceMode)EditorGUILayout.EnumPopup("Normals", normals); tangents = (ModelImporterTangentSpaceMode)EditorGUILayout.EnumPopup("Tangents", tangents); GUI.enabled = normals == ModelImporterTangentSpaceMode.Calculate; smoothingAngle = EditorGUILayout.Slider("Smoothing Angle", smoothingAngle, SmoothingAngleMin, SmoothingAngleMax); GUI.enabled = true; GUI.enabled = tangents == ModelImporterTangentSpaceMode.None; splitTangents = EditorGUILayout.Toggle("Split Tangents", splitTangents); GUI.enabled = true; // materials EditorGUILayout.LabelField("Materials", EditorStyles.boldLabel); importMaterials = EditorGUILayout.Toggle("Import Materials", importMaterials); if (importMaterials) { materialNaming = (ModelImporterMaterialName)EditorGUILayout.EnumPopup("Material Naming", materialNaming); materialSearch = (ModelImporterMaterialSearch)EditorGUILayout.EnumPopup("Material Search", materialSearch); } }
void OnDrawOptionUI() { EditorGUILayout.LabelField("Meshes", EditorStyles.boldLabel); _scaleFactor = EditorGUILayout.FloatField("Scale Factor", _scaleFactor); _bUseFileScale = EditorGUILayout.Toggle("Use File Scale", _bUseFileScale); GUI.enabled = _bUseFileScale; _fileScale = EditorGUILayout.FloatField(" File Scale", _fileScale); GUI.enabled = true; _eMeshCompression = (ModelImporterMeshCompression)EditorGUILayout.EnumPopup("Mesh Compression", _eMeshCompression); _ReadWriteEnable = EditorGUILayout.Toggle("Read/Write Enabled", _ReadWriteEnable); _OptimizeMesh = EditorGUILayout.Toggle("Optimize Mesh", _OptimizeMesh); _ImportBlendShapes = EditorGUILayout.Toggle("Import BlendShapes", _ImportBlendShapes); _GenerateColliders = EditorGUILayout.Toggle("Generate Colliders", _GenerateColliders); _KeepQuads = EditorGUILayout.Toggle("Keep Quads", _KeepQuads); _bWeldVertices = EditorGUILayout.Toggle("Weld Vertices", _bWeldVertices); _bImportVisibility = EditorGUILayout.Toggle("Import Visibility", _bImportVisibility); _bImportCameras = EditorGUILayout.Toggle("Import Cameras", _bImportCameras); _bImportLights = EditorGUILayout.Toggle("Import Lights", _bImportLights); _SwapUVs = EditorGUILayout.Toggle("Swap UVs", _SwapUVs); _GenerateLightmapUVs = EditorGUILayout.Toggle("Generate Lightmap UVs", _GenerateLightmapUVs); if (_GenerateLightmapUVs) { _uiFolderAdvanced = EditorGUILayout.Foldout(_uiFolderAdvanced, "Advanced"); if (_uiFolderAdvanced) { _HardAngle = EditorGUILayout.IntSlider(" Hard Angle", _HardAngle, 0, 180); _PackMargin = EditorGUILayout.IntSlider(" Pack Margin", _PackMargin, 0, 180); _AngleError = EditorGUILayout.IntSlider(" Angle Error", _AngleError, 0, 180); _AreaError = EditorGUILayout.IntSlider(" Area Error", _AreaError, 0, 180); } } EditorGUILayout.LabelField("Normals & Tangents", EditorStyles.boldLabel); _eImporterNormals = (ModelImporterNormals)EditorGUILayout.EnumPopup("Normals", _eImporterNormals); GUI.enabled = _eImporterNormals == ModelImporterNormals.Calculate; _SmoothAngle = EditorGUILayout.IntSlider("Smooth Angles", _SmoothAngle, 0, 180); GUI.enabled = _eImporterNormals != ModelImporterNormals.None; _eImporterTangents = (ModelImporterTangents)EditorGUILayout.EnumPopup("Tangents", _eImporterTangents); GUI.enabled = true; EditorGUILayout.LabelField("Materials", EditorStyles.boldLabel); _ImportMaterials = EditorGUILayout.Toggle("ImportMaterials", _ImportMaterials); if (_ImportMaterials) { _eImporterMaterialName = (ModelImporterMaterialName)EditorGUILayout.Popup("Material Naming", (int)_eImporterMaterialName, _strMaterialNaming); _eImporterMaterialSearch = (ModelImporterMaterialSearch)EditorGUILayout.EnumPopup("Material Search", _eImporterMaterialSearch); } GUILayout.BeginHorizontal(); if (GUILayout.Button("Find")) { FindModelImport(); } if (GUILayout.Button("Apply")) { ApplyModelImport(); } GUILayout.EndHorizontal(); }