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 );
 	}
Пример #2
0
        /// <summary>
        /// Optimizes the mesh array to the maximum level of compression safetly allowed within the precision parameter.
        /// </summary>
        /// <param name="meshes">Meshes.</param>
        /// <param name="maxCompressionLevel">Max compression level.</param>
        /// <param name="precision">How much tolerance for fault in the vert positions is allowed. Defaults to 1/10th of a pixel.</param>
        public static void OptimizeMeshes(Mesh[] meshes, ModelImporterMeshCompression maxCompressionLevel = ModelImporterMeshCompression.High, float precision = 0.001f, bool logBreakdown = false)
        {
            if (meshes != null && meshes.Length > 0)
            {
                StartEditing();
                var compressionLevels = GetCompressionLevels(maxCompressionLevel);

                var breakdown = new Dictionary <ModelImporterMeshCompression, int>();
                foreach (var level in compressionLevels)
                {
                    breakdown.Add(level, 0);
                }

                for (int i = 0; i < meshes.Length; i++)
                {
                    var mesh  = meshes[i];
                    var level = Optimize(mesh, compressionLevels, precision);
                    breakdown[level]++;
                    float  progress      = (float)i / (float)meshes.Length;
                    string progressLabel = i + " of " + meshes.Length + " completed";
                    EditorUtility.DisplayProgressBar("Compressing Meshes", progressLabel, progress);
                }

                if (logBreakdown)
                {
                    LogMeshBreakdown(breakdown);
                }
                EditorUtility.ClearProgressBar();
                StopEditing();
            }
        }
Пример #3
0
            public ModelFolderRule(ProjectImportSettings.ModelFolderRule rule)
            {
                maxVertices = rule.maxVertices;
                shouldBatch = rule.shouldBatch;

                m_MeshCompression   = rule.m_MeshCompression;
                m_IsReadable        = rule.m_IsReadable;
                optimizeMeshForGPU  = rule.optimizeMeshForGPU;
                m_ImportBlendShapes = rule.m_ImportBlendShapes;
                m_AddColliders      = rule.m_AddColliders;
                keepQuads           = rule.keepQuads;
                weldVertices        = rule.weldVertices;
                m_ImportVisibility  = rule.m_ImportVisibility;
                m_ImportCameras     = rule.m_ImportCameras;
                m_ImportLights      = rule.m_ImportLights;
                swapUVChannels      = rule.swapUVChannels;
                generateSecondaryUV = rule.generateSecondaryUV;
                normalImportMode    = rule.normalImportMode;
                tangentImportMode   = rule.tangentImportMode;

                m_AnimationType            = rule.m_AnimationType;
                m_LegacyGenerateAnimations = rule.m_LegacyGenerateAnimations;

                importAnimation        = rule.importAnimation;
                m_AnimationCompression = rule.m_AnimationCompression;
                m_OptimizeGameObjects  = rule.m_OptimizeGameObjects;

                importMaterials = rule.importMaterials;

                maxBones       = rule.maxBones;
                maxBoneWeights = rule.maxBoneWeights;
            }
Пример #4
0
        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;
        }
Пример #5
0
        private void AnalyzerModel()
        {
            GameObject asset = AssetDatabase.LoadMainAssetAtPath(path) as GameObject;

            this.name              = asset.name;
            this.scale             = mi.globalScale;
            this.meshCompression   = mi.meshCompression;
            this.isRW              = mi.isReadable;
            this.isAddCollider     = mi.addCollider;
            this.swapUVChannels    = mi.swapUVChannels;
            this.normalImportMode  = mi.normalImportMode;
            this.tangentImportMode = mi.tangentImportMode;
            this.isBakeIK          = mi.bakeIK;
            this.animCompression   = mi.animationCompression;

            if (!mi.importAnimation || mi.animationType == ModelImporterAnimationType.None)
            {
                this.animationClipCount = 0;
            }
            else
            {
                this.animationClipCount = mi.clipAnimations.Length;
            }

            CollectMeshInfo(asset);

            CheckValid();
        }
Пример #6
0
        public void SetModelDefault()
        {
            bool flag = false;

            if (this.mi.meshCompression != ModelImporterMeshCompression.Medium)
            {
                this.mi.meshCompression = ModelImporterMeshCompression.Medium;
                flag = true;
            }
            if (this.mi.animationCompression != ModelImporterAnimationCompression.KeyframeReductionAndCompression)
            {
                this.mi.animationCompression = ModelImporterAnimationCompression.KeyframeReductionAndCompression;
                flag = true;
            }
            if (this.mi.isReadable != false)
            {
                mi.isReadable = false;
                flag          = true;
            }
            if (flag)
            {
                AssetDatabase.ImportAsset(path);
                AnalyzerModel();
            }
        }
 	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 );
 	}
Пример #8
0
 public MeshData(string path, ModelImporterTangentSpaceMode normaltype, ModelImporterMeshCompression meshcompress, bool optmesh, bool readable)
 {
     MeshPath         = path;
     NormalImportMode = normaltype;
     OptimizeMesh     = optmesh;
     IsReadable       = readable;
     MeshCompression  = meshcompress;
 }
Пример #9
0
 public void SetMeshCompress()
 {
     if (this.mi.meshCompression != ModelImporterMeshCompression.Medium)
     {
         this.mi.meshCompression = ModelImporterMeshCompression.Medium;
         AssetDatabase.ImportAsset(path);
         AnalyzerModel();
     }
 }
Пример #10
0
 /// <summary>
 /// Optimizes the mesh to the maximum level of compression safetly allowed within the precision parameter.
 /// </summary>
 /// <param name="mesh">Mesh.</param>
 /// <param name="maxCompressionLevel">Max compression level.</param>
 /// <param name="precision">How much tolerance for fault in the vert positions is allowed. Defaults to 1/10th of a pixel.</param>
 public static void OptimizeMesh(Mesh mesh, ModelImporterMeshCompression maxCompressionLevel, float precision)
 {
     if (mesh != null)
     {
         StartEditing();
         var compressionLevels = GetCompressionLevels(maxCompressionLevel);
         var level             = Optimize(mesh, compressionLevels, precision);
         Debug.Log("Set compression level to: " + level);
         StopEditing();
     }
 }
 public void ApplyDefaults()
 {
     readWriteEnabled       = false;
     optimiseMesh           = true;
     ImportBlendShapes      = false;
     normalImportMode       = ModelImporterNormals.Import;
     animationType          = ModelImporterAnimationType.None;
     meshCompression        = ModelImporterMeshCompression.Off;
     importMaterials        = true;
     importTangents         = ModelImporterTangents.None;
     changeReadableSettings = false;
 }
Пример #12
0
    private static bool SetMeshCompression(ModelImporter mi, ModelImporterMeshCompression compression)
    {
        bool rt = false;

        if (mi.meshCompression != compression)
        {
            rt = true;
            mi.meshCompression = compression;
            Debug.Log("SetMeshCompression succ:" + mi.assetPath + " " + compression);
        }
        return(rt);
    }
 public MeshImportSettings()
 {
     globalScale              = 1.0f;
     addCollider              = false;
     normalSmoothingAngle     = 60.0f;
     splitTangentsAcrossSeams = true;
     swapUVChannels           = false;
     generateSecondaryUV      = false;
     optimizeMesh             = false;
     normalImportMode         = ModelImporterTangentSpaceMode.Import;
     tangentImportMode        = ModelImporterTangentSpaceMode.Calculate;
     meshCompression          = ModelImporterMeshCompression.Off;
 }
Пример #14
0
 private void DisplayBaseSettings()
 {
     GUILayout.Label("Base Settings", EditorStyles.miniBoldLabel);
     globalScale         = EditorGUILayout.FloatField("Scale Factor", globalScale);
     useFileScale        = EditorGUILayout.Toggle("Use File Scale", useFileScale);
     meshCompressionType = (ModelImporterMeshCompression)EditorGUILayout.EnumPopup("Mesh Compression", meshCompressionType);
     readWriteEnabled    = EditorGUILayout.Toggle("Read/Write Enabled", readWriteEnabled);
     optimizeMesh        = EditorGUILayout.Toggle("Optimze Mesh", optimizeMesh);
     importBlendshapes   = EditorGUILayout.Toggle("Import BlendShapes", importBlendshapes);
     generateColliders   = EditorGUILayout.Toggle("Generate Colliders", generateColliders);
     //TODO find where this goes
     //keepQuads = EditorGUILayout.Toggle("Keep Quads", keepQuads);
     swapUVs     = EditorGUILayout.Toggle("Swap UVs", swapUVs);
     lightmapUVs = EditorGUILayout.Toggle("Generate Lightmap UVs", lightmapUVs);
 }
Пример #15
0
        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;
        }
Пример #16
0
        private static ModelImporterMeshCompression[] GetCompressionLevels(ModelImporterMeshCompression maxCompressionLevel)
        {
            var compressionLevels     = System.Enum.GetValues(typeof(ModelImporterMeshCompression));
            var compressionLevelsList = new List <ModelImporterMeshCompression>();

            // Only trying to compress to the max specified by the user
            foreach (var compressionLevel in compressionLevels)
            {
                var level = (ModelImporterMeshCompression)compressionLevel;
                compressionLevelsList.Add(level);
                if (level == maxCompressionLevel)
                {
                    break;
                }
            }

            compressionLevelsList.Reverse();
            return(compressionLevelsList.ToArray());
        }
    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;
    }
Пример #18
0
        public static Mesh CopyMeshTo(Mesh sourceMesh, string targetPath, ModelImporterMeshCompression compression = ModelImporterMeshCompression.Off)
        {
            Mesh targetMesh = AssetDatabase.LoadAssetAtPath <Mesh>(targetPath);

            if (targetMesh != null)
            {
                AssetDatabase.DeleteAsset(targetPath);
            }

            targetMesh = UnityObject.Instantiate <Mesh>(sourceMesh);
            if (compression != ModelImporterMeshCompression.Off)
            {
                UnityEditor.MeshUtility.SetMeshCompression(targetMesh, compression);
            }
            UnityEditor.MeshUtility.Optimize(targetMesh);

            AssetDatabase.CreateAsset(targetMesh, targetPath);
            AssetDatabase.ImportAsset(targetPath);

            return(targetMesh);
        }
Пример #19
0
        public override void CopyData(ImportData data)
        {
            ModelImportData tData = data as ModelImportData;

            if (tData == null)
            {
                return;
            }

            base.CopyData(data);
            ReadWriteEnable = tData.ReadWriteEnable;
            OptimizeMesh    = tData.OptimizeMesh;
            ImportMaterials = tData.ImportMaterials;
            ImportAnimation = tData.ImportAnimation;
            ImportUV2       = tData.ImportUV2;
            ImportUV3       = tData.ImportUV3;
            ImportUV4       = tData.ImportUV4;
            ImportNormal    = tData.ImportNormal;
            ImportTangent   = tData.ImportTangent;
            MeshCompression = tData.MeshCompression;
        }
Пример #20
0
        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();
        }
Пример #21
0
        /// <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);
            }
        }
Пример #22
0
        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();
        }
Пример #23
0
        public void SetModelDefault()
        {
            bool flag = false;
            if (this.mi.meshCompression != ModelImporterMeshCompression.Medium)
            {
                this.mi.meshCompression = ModelImporterMeshCompression.Medium;
                flag = true;

            }
            if (this.mi.animationCompression != ModelImporterAnimationCompression.KeyframeReductionAndCompression)
            {
                this.mi.animationCompression = ModelImporterAnimationCompression.KeyframeReductionAndCompression;
                flag = true;
            }
            if (this.mi.isReadable != false)
            {
                mi.isReadable = false;
                flag = true;
            }
            if (flag)
            {
                AssetDatabase.ImportAsset(path);
                AnalyzerModel();
            }
        }
Пример #24
0
 public void SetMeshCompress()
 {
     if (this.mi.meshCompression != ModelImporterMeshCompression.Medium)
     {
         this.mi.meshCompression = ModelImporterMeshCompression.Medium;
         AssetDatabase.ImportAsset(path);
         AnalyzerModel();
     }
 }
Пример #25
0
        private void AnalyzerModel()
        {
            GameObject asset = AssetDatabase.LoadMainAssetAtPath(path) as GameObject;
            this.name = asset.name;
            this.scale = mi.globalScale;
            this.meshCompression = mi.meshCompression;
            this.isRW = mi.isReadable;
            this.isAddCollider = mi.addCollider;
            this.swapUVChannels = mi.swapUVChannels;
            this.normalImportMode = mi.normalImportMode;
            this.tangentImportMode = mi.tangentImportMode;
            this.isBakeIK = mi.bakeIK;
            this.animCompression = mi.animationCompression;

            if (!mi.importAnimation || mi.animationType == ModelImporterAnimationType.None)
            {
                this.animationClipCount = 0;
            }
            else
            {
                this.animationClipCount = mi.clipAnimations.Length;
            }

            CollectMeshInfo(asset);

            CheckValid();
        }
Пример #26
0
 public static extern void SetMeshCompression(Mesh mesh, ModelImporterMeshCompression compression);
Пример #27
0
        private void DrawModelGUI()
        {
            EditorGUILayout.LabelField("Scene", EditorStyles.boldLabel);
            EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 2), QuickEditorColors.DarkGrayX11);
            GUILayout.Space(3);

            scaleFactor       = EditorGUILayout.FloatField("Scale Factor", scaleFactor);
            importBlendShapes = EditorGUILayout.Toggle(AssetImportStyles.Model.ImportBlendShapes, importBlendShapes);

            GUILayout.Space(3);
            EditorGUILayout.LabelField("Meshes", EditorStyles.boldLabel);
            EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 2), QuickEditorColors.DarkGrayX11);
            GUILayout.Space(3);

            meshCompression    = (ModelImporterMeshCompression)EditorGUILayout.EnumPopup(AssetImportStyles.Model.MeshCompressionLabel, meshCompression);
            isReadable         = EditorGUILayout.Toggle(AssetImportStyles.Model.IsReadable, isReadable);
            optimizeMeshForGPU = EditorGUILayout.Toggle(AssetImportStyles.Model.OptimizeMeshForGPU, optimizeMeshForGPU);

            generateColliders = EditorGUILayout.Toggle(AssetImportStyles.Model.GenerateColliders, generateColliders);
            GUILayout.Space(5);
            EditorGUILayout.LabelField("Geometry", EditorStyles.boldLabel);
            EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 2), QuickEditorColors.DarkGrayX11);
            GUILayout.Space(3);
            using (new EditorGUI.DisabledScope(true))
            {
                keepQuads = EditorGUILayout.Toggle(AssetImportStyles.Model.KeepQuads, keepQuads);
            }
            weldVertices = EditorGUILayout.Toggle(AssetImportStyles.Model.WeldVertices, weldVertices);

            GUILayout.Label(AssetImportStyles.Model.TangentSpace, EditorStyles.boldLabel, new GUILayoutOption[0]);

            EditorGUI.BeginChangeCheck();
            normalImportMode = (ModelImporterNormals)EditorGUILayout.EnumPopup(AssetImportStyles.Model.TangentSpaceNormalLabel, normalImportMode);
            if (EditorGUI.EndChangeCheck())
            {
                if (normalImportMode == ModelImporterNormals.None)
                {
                    tangentImportMode = ModelImporterTangents.None;
                }
                //                else if (rule.normalImportMode == ModelImporterNormals.Import)
                //                {
                //                    rule.tangentImportMode = ModelImporterTangents.Import;
                //                }
                else
                {
                    tangentImportMode = ModelImporterTangents.CalculateMikk;
                }
            }

            using (new EditorGUI.DisabledScope(normalImportMode != ModelImporterNormals.Calculate))
            {
                normalSmoothAngle = EditorGUILayout.Slider(AssetImportStyles.Model.SmoothingAngle, normalSmoothAngle, 0f, 180f);
            }
            GUIContent[]            displayedOptions = AssetImportStyles.Model.TangentSpaceModeOptLabelsAll;
            ModelImporterTangents[] array            = AssetImportStyles.Model.TangentSpaceModeOptEnumsAll;
            if (normalImportMode == ModelImporterNormals.Calculate)
            {
                displayedOptions = AssetImportStyles.Model.TangentSpaceModeOptLabelsCalculate;
                array            = AssetImportStyles.Model.TangentSpaceModeOptEnumsCalculate;
            }
            else if (normalImportMode == ModelImporterNormals.None)
            {
                displayedOptions = AssetImportStyles.Model.TangentSpaceModeOptLabelsNone;
                array            = AssetImportStyles.Model.TangentSpaceModeOptEnumsNone;
            }
            using (new EditorGUI.DisabledScope(normalImportMode == ModelImporterNormals.None))
            {
                int num = Array.IndexOf(array, tangentImportMode);
                EditorGUI.BeginChangeCheck();
                num = EditorGUILayout.Popup(AssetImportStyles.Model.TangentSpaceTangentLabel, num, displayedOptions, new GUILayoutOption[0]);
                if (EditorGUI.EndChangeCheck())
                {
                    tangentImportMode = array[num];
                }
            }

            swapUVChannels      = EditorGUILayout.Toggle(AssetImportStyles.Model.SwapUVChannels, swapUVChannels);
            generateSecondaryUV = EditorGUILayout.Toggle(AssetImportStyles.Model.GenerateSecondaryUV, generateSecondaryUV);
            if (generateSecondaryUV)
            {
                //EditorGUI.indentLevel++;
                //this.m_SecondaryUVAdvancedOptions = EditorGUILayout.Foldout(this.m_SecondaryUVAdvancedOptions,
                //    styles.GenerateSecondaryUVAdvanced, EditorStyles.foldout);
                //if (this.m_SecondaryUVAdvancedOptions)
                //{
                //    assetRule.secondaryUVHardAngle = EditorGUILayout.Slider(styles.secondaryUVHardAngle,
                //        assetRule.secondaryUVHardAngle, 0f, 180f, new GUILayoutOption[0]);
                //    assetRule.secondaryUVPackMargin = EditorGUILayout.Slider(styles.secondaryUVPackMargin,
                //        assetRule.secondaryUVPackMargin, 0f, 180f, new GUILayoutOption[0]);
                //    assetRule.secondaryUVAngleDistortion = EditorGUILayout.Slider(styles.secondaryUVAngleDistortion,
                //        assetRule.secondaryUVAngleDistortion, 0f, 180f, new GUILayoutOption[0]);
                //    assetRule.secondaryUVAreaDistortion = EditorGUILayout.Slider(styles.secondaryUVAreaDistortion,
                //        assetRule.secondaryUVAreaDistortion, 0f, 180f, new GUILayoutOption[0]);
                //}
                //EditorGUI.indentLevel--;
            }
        }
Пример #28
0
        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);
        }
 extern public static void SetMeshCompression(Mesh mesh, ModelImporterMeshCompression compression);
 	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();
 	}
Пример #31
0
        void LoadFilterOption()
        {
            try
            {
                FileStream fileStream = new FileStream(savePath + saveFileName, FileMode.Open);
                if (fileStream == null)
                {
                    return;
                }

                using (fileStream)
                {
                    byte[] _Loadfloat = new byte[4];
                    for (int i = 0; i < _Loadfloat.Length; ++i)
                    {
                        _Loadfloat[i] = (byte)fileStream.ReadByte();
                    }
                    baseScaleFactor = BitConverter.ToSingle(_Loadfloat, 0);

                    baseMeshCompression   = (ModelImporterMeshCompression)fileStream.ReadByte();
                    baseReadWriteEnabled  = (BOOL)fileStream.ReadByte();
                    baseOptimizeMesh      = (BOOL)fileStream.ReadByte();
                    baseImportBlendShapes = (BOOL)fileStream.ReadByte();
                    baseGenerateColliders = (BOOL)fileStream.ReadByte();
                    //baseKeepQuads = (BOOL)fileStream.ReadByte();
                    baseSwapUVs             = (BOOL)fileStream.ReadByte();
                    baseGenerateLightmapUVs = (BOOL)fileStream.ReadByte();
                    baseTangents            = (TANGENTS)fileStream.ReadByte();
                    baseImportMaterials     = (BOOL)fileStream.ReadByte();
                    baseMaterialName        = (MATERIAL_NAMING)fileStream.ReadByte();
                    baseMaterialSearch      = (MATERIAL_SEARCH)fileStream.ReadByte();
                    baseUVCount             = (byte)fileStream.ReadByte();
                    baseVertexColorSet      = (BOOL)fileStream.ReadByte();
                    baseNormalsOption       = (NORMALS)fileStream.ReadByte();
                    baseSmoothingAngle      = (Byte)fileStream.ReadByte();
                    baseIndexFormat         = (ModelImporterIndexFormat)fileStream.ReadByte();
                    baseImportAnimation     = (BOOL)fileStream.ReadByte();


                    //if (fileStream.Position < fileStream.Length)
                    //    baseMeshCompression = (ModelImporterMeshCompression)fileStream.ReadByte();
                    //if (fileStream.Position < fileStream.Length)
                    //    baseReadWriteEnabled = (BOOL)fileStream.ReadByte();
                    //if (fileStream.Position < fileStream.Length)
                    //    baseOptimizeMesh = (BOOL)fileStream.ReadByte();
                    //if (fileStream.Position < fileStream.Length)
                    //    baseImportBlendShapes = (BOOL)fileStream.ReadByte();
                    //if (fileStream.Position < fileStream.Length)
                    //    baseGenerateColliders = (BOOL)fileStream.ReadByte();
                    ////if (fileStream.Position < fileStream.Length)
                    //    //baseKeepQuads = (BOOL)fileStream.ReadByte();
                    //if (fileStream.Position < fileStream.Length)
                    //    baseSwapUVs = (BOOL)fileStream.ReadByte();
                    //if (fileStream.Position < fileStream.Length)
                    //    baseGenerateLightmapUVs = (BOOL)fileStream.ReadByte();
                    //if (fileStream.Position < fileStream.Length)
                    //    baseTangents = (TANGENTS)fileStream.ReadByte();
                    //if (fileStream.Position < fileStream.Length)
                    //    baseImportMaterials = (BOOL)fileStream.ReadByte();
                    //if (fileStream.Position < fileStream.Length)
                    //    baseMaterialName = (MATERIAL_NAMING)fileStream.ReadByte();
                    //if (fileStream.Position < fileStream.Length)
                    //    baseMaterialSearch = (MATERIAL_SEARCH)fileStream.ReadByte();
                    //if (fileStream.Position < fileStream.Length)
                    //    baseUVCount = (byte)fileStream.ReadByte();
                    //if (fileStream.Position < fileStream.Length)
                    //    baseVertexColorSet = (BOOL)fileStream.ReadByte();
                }

                fileStream.Close();
            }
            catch { }
        }
	public MeshImportSettings()
	{
		globalScale = 1.0f;
		addCollider = false;
		normalSmoothingAngle = 60.0f;
		splitTangentsAcrossSeams = true;
		swapUVChannels = false;
		generateSecondaryUV = false;
		optimizeMesh = false;
		normalImportMode = ModelImporterTangentSpaceMode.Import;
		tangentImportMode = ModelImporterTangentSpaceMode.Calculate;
		meshCompression = ModelImporterMeshCompression.Off;
	}
Пример #33
0
        void DrawFilters()
        {
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.BeginVertical("box", GUILayout.Width(300));
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckScaleFactor))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("1. Scale Factor is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckScaleFactor);
                        }
                        GUI.backgroundColor = Color.white;

                        baseScaleFactor = EditorGUILayout.FloatField(baseScaleFactor, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();


                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckOptimizeMesh))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("4. Optimize Mesh is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckOptimizeMesh);
                        }
                        GUI.backgroundColor = Color.white;

                        baseOptimizeMesh = (BOOL)EditorGUILayout.EnumPopup(baseOptimizeMesh, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckSwapUVs))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("7. Swap UVs is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckSwapUVs);
                        }
                        GUI.backgroundColor = Color.white;

                        baseSwapUVs = (BOOL)EditorGUILayout.EnumPopup(baseSwapUVs, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckTangents))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("10. Tangents is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckTangents);
                        }
                        GUI.backgroundColor = Color.white;

                        baseTangents = (TANGENTS)EditorGUILayout.EnumPopup(baseTangents, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckUVCount))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("13. UV-Count is more than", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckUVCount);
                        }
                        GUI.backgroundColor = Color.white;

                        baseUVCount = (byte)EditorGUILayout.IntField((int)baseUVCount, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();

                    //Index Format
                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckIndexFormat))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("16. Index Format is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckIndexFormat);
                        }
                        GUI.backgroundColor = Color.white;

                        baseIndexFormat = (ModelImporterIndexFormat)EditorGUILayout.EnumPopup(baseIndexFormat, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical("box", GUILayout.Width(300));
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckMeshCompression))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("2. Mesh Compression is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckMeshCompression);
                        }
                        GUI.backgroundColor = Color.white;

                        baseMeshCompression = (ModelImporterMeshCompression)EditorGUILayout.EnumPopup(baseMeshCompression, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckImportBlendShapes))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("5. Import BlendShapes is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckImportBlendShapes);
                        }
                        GUI.backgroundColor = Color.white;

                        baseImportBlendShapes = (BOOL)EditorGUILayout.EnumPopup(baseImportBlendShapes, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();


                    //EditorGUILayout.BeginHorizontal();
                    //{
                    //    if (GetCheckType(CheckTypes, CheckType.CheckKeepQuads)) GUI.backgroundColor = Color.green;
                    //    if (GUILayout.Button("Keep Quads is not ", GUILayout.Width(200)))
                    //        SetCheckType(CheckType.CheckKeepQuads);
                    //    GUI.backgroundColor = Color.white;

                    //    baseKeepQuads = (BOOL)EditorGUILayout.EnumPopup(baseKeepQuads, GUILayout.Width(100));
                    //}
                    //EditorGUILayout.EndHorizontal();


                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckGenerateLightmapUVs))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("8. Generate Lightmap UVs is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckGenerateLightmapUVs);
                        }
                        GUI.backgroundColor = Color.white;

                        baseGenerateLightmapUVs = (BOOL)EditorGUILayout.EnumPopup(baseGenerateLightmapUVs, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckMaterialNaming))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("11. Material Naming is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckMaterialNaming);
                        }
                        GUI.backgroundColor = Color.white;

                        baseMaterialName = (MATERIAL_NAMING)EditorGUILayout.EnumPopup(baseMaterialName, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckVertexColor))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("14. VertexColor Setting is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckVertexColor);
                        }
                        GUI.backgroundColor = Color.white;

                        baseVertexColorSet = (BOOL)EditorGUILayout.EnumPopup(baseVertexColorSet, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();

                    //Import Animation
                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckImportAnimation))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("17. Import Animation is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckImportAnimation);
                        }
                        GUI.backgroundColor = Color.white;

                        baseImportAnimation = (BOOL)EditorGUILayout.EnumPopup(baseImportAnimation, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical("box", GUILayout.Width(300));
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckReadWriteEnabled))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("3. Read/Write Enabled is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckReadWriteEnabled);
                        }
                        GUI.backgroundColor = Color.white;

                        baseReadWriteEnabled = (BOOL)EditorGUILayout.EnumPopup(baseReadWriteEnabled, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckGenerateColliders))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("6. Generate Colliders is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckGenerateColliders);
                        }
                        GUI.backgroundColor = Color.white;

                        baseGenerateColliders = (BOOL)EditorGUILayout.EnumPopup(baseGenerateColliders, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckImportMaterials))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("9. Import Materials is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckImportMaterials);
                        }
                        GUI.backgroundColor = Color.white;

                        baseImportMaterials = (BOOL)EditorGUILayout.EnumPopup(baseImportMaterials, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();



                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckMaterialSearch))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("12. MaterialSearch is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckMaterialSearch);
                        }
                        GUI.backgroundColor = Color.white;

                        baseMaterialSearch = (MATERIAL_SEARCH)EditorGUILayout.EnumPopup(baseMaterialSearch, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();


                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GetCheckType(CheckTypes, CheckType.CheckNormalsOption))
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("15. Normars Option is not ", GUILayout.Width(200)))
                        {
                            SetCheckType(CheckType.CheckNormalsOption);
                        }
                        GUI.backgroundColor = Color.white;

                        baseNormalsOption = (NORMALS)EditorGUILayout.EnumPopup(baseNormalsOption, GUILayout.Width(100));
                    }
                    EditorGUILayout.EndHorizontal();

                    if (baseNormalsOption == NORMALS.Calculate)
                    {
                        EditorGUILayout.BeginHorizontal();
                        //GUI.enabled = baseNormalsOption == NORMALS.Calculate ? true : false;
                        baseSmoothingAngle = (Byte)EditorGUILayout.IntSlider(baseSmoothingAngle, 0, 180, GUILayout.Width(300));
                        //GUI.enabled = true;
                        EditorGUILayout.EndHorizontal();
                    }
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndHorizontal();
        }
Пример #34
0
    void OnGUI()
    {
        Undo.RecordObject(this, "lb");

        scrollPos = EditorGUILayout.BeginScrollView(scrollPos,
                                                    false,
                                                    false,
                                                    GUILayout.Width(Screen.width),
                                                    GUILayout.Height(Screen.height));

        EditorGUILayout.Space(); EditorGUILayout.Space();
        EditorGUILayout.Space(); EditorGUILayout.Space();

        importerType = (ModelImporterType)EditorGUILayout.EnumPopup("Importer Mode", importerType, GUILayout.Width(343));

        if (GUILayout.Button("Batch Import"))
        {
            if (importerType == ModelImporterType.CustomModels)
            {
                if (targets.Length > 0)
                {
                    foreach (GameObject s in targets)
                    {
                        ModelImporter tImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(s)) as ModelImporter;

                        tImporter.meshCompression     = meshCompression;
                        tImporter.isReadable          = readWriteEnabled;
                        tImporter.optimizeMesh        = optimizeMesh;
                        tImporter.importBlendShapes   = importBlendShape;
                        tImporter.generateSecondaryUV = generateLightmapUV;
                        tImporter.addCollider         = generateColliders;

                        if (advancedMode)
                        {
                            tImporter.importAnimation = importAnimation;

                            tImporter.globalScale     = modelScale;
                            tImporter.keepQuads       = keepQuads;
                            tImporter.weldVertices    = weldVertices;
                            tImporter.swapUVChannels  = swapUV;
                            tImporter.importMaterials = ImportMaterials;
                        }

                        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(s), ImportAssetOptions.ForceUpdate);
                    }
                }
            }

            if (importerType == ModelImporterType.AllModels)
            {
                var files = Directory.GetFiles("Assets", "*.*", SearchOption.AllDirectories)
                            .Where(s => s.EndsWith(".fbx") || s.EndsWith(".obj") || s.EndsWith(".ma") || s.EndsWith(".max") || s.EndsWith(".dae") ||
                                   s.EndsWith(".blend") || s.EndsWith(".dxf") || s.EndsWith(".3ds") || s.EndsWith(".skp") ||
                                   s.EndsWith(".c4d") || s.EndsWith(".lxo ") || s.EndsWith(".jas"));

                foreach (string s in files)
                {
                    ModelImporter tImporter = AssetImporter.GetAtPath(s) as ModelImporter;

                    tImporter.meshCompression     = meshCompression;
                    tImporter.isReadable          = readWriteEnabled;
                    tImporter.optimizeMesh        = optimizeMesh;
                    tImporter.importBlendShapes   = importBlendShape;
                    tImporter.generateSecondaryUV = generateLightmapUV;
                    tImporter.addCollider         = generateColliders;

                    if (advancedMode)
                    {
                        tImporter.importAnimation = importAnimation;

                        tImporter.globalScale     = modelScale;
                        tImporter.keepQuads       = keepQuads;
                        tImporter.weldVertices    = weldVertices;
                        tImporter.swapUVChannels  = swapUV;
                        tImporter.importMaterials = ImportMaterials;
                    }

                    AssetDatabase.ImportAsset(s, ImportAssetOptions.ForceUpdate);
                }
            }

            if (importerType == ModelImporterType.CustomPath)
            {
                if (CustomPath.Length > 0)
                {
                    foreach (string f in CustomPath)
                    {
                        var files = Directory.GetFiles(f, "*.*", SearchOption.AllDirectories)
                                    .Where(s => s.EndsWith(".fbx") || s.EndsWith(".obj") || s.EndsWith(".ma") || s.EndsWith(".max") || s.EndsWith(".dae") ||
                                           s.EndsWith(".blend") || s.EndsWith(".dxf") || s.EndsWith(".3ds") || s.EndsWith(".skp") ||
                                           s.EndsWith(".c4d") || s.EndsWith(".lxo ") || s.EndsWith(".jas"));

                        foreach (string ss in files)
                        {
                            ModelImporter tImporter = AssetImporter.GetAtPath(ss) as ModelImporter;
                            tImporter.meshCompression     = meshCompression;
                            tImporter.isReadable          = readWriteEnabled;
                            tImporter.optimizeMesh        = optimizeMesh;
                            tImporter.importBlendShapes   = importBlendShape;
                            tImporter.generateSecondaryUV = generateLightmapUV;
                            tImporter.addCollider         = generateColliders;

                            if (advancedMode)
                            {
                                tImporter.importAnimation = importAnimation;
                                tImporter.globalScale     = modelScale;
                                tImporter.keepQuads       = keepQuads;
                                tImporter.weldVertices    = weldVertices;
                                tImporter.swapUVChannels  = swapUV;
                                tImporter.importMaterials = ImportMaterials;
                            }

                            AssetDatabase.ImportAsset(ss, ImportAssetOptions.ForceUpdate);
                        }
                    }
                }
            }
        }

        EditorGUILayout.Space(); EditorGUILayout.Space();

        if (importerType == ModelImporterType.CustomModels)
        {
            ScriptableObject   target          = this;
            SerializedObject   so              = new SerializedObject(target);
            SerializedProperty stringsProperty = so.FindProperty("targets");
            EditorGUILayout.PropertyField(stringsProperty, true); // True means show children
            so.ApplyModifiedProperties();                         // Remember to apply modified properties
        }

        if (importerType == ModelImporterType.CustomPath)
        {
            ScriptableObject   target          = this;
            SerializedObject   so              = new SerializedObject(target);
            SerializedProperty stringsProperty = so.FindProperty("CustomPath");
            EditorGUILayout.PropertyField(stringsProperty, true); // True means show children
            so.ApplyModifiedProperties();                         // Remember to apply modified properties
        }

        EditorGUILayout.Space(); EditorGUILayout.Space();
        meshCompression    = (ModelImporterMeshCompression)EditorGUILayout.EnumPopup("Compression Mode", meshCompression, GUILayout.Width(343));
        readWriteEnabled   = EditorGUILayout.Toggle("Read / Write Enabled", readWriteEnabled, GUILayout.Width(343));
        optimizeMesh       = EditorGUILayout.Toggle("Optimize Mesh", optimizeMesh, GUILayout.Width(343));
        importBlendShape   = EditorGUILayout.Toggle("Import Blend Shape", importBlendShape, GUILayout.Width(343));
        generateColliders  = EditorGUILayout.Toggle("Generate Colliders", generateColliders, GUILayout.Width(343));
        generateLightmapUV = EditorGUILayout.Toggle("Generate Lightmap UV", generateLightmapUV, GUILayout.Width(343));

        advancedMode = EditorGUILayout.Toggle("Show Advanced Options", advancedMode);
        EditorGUILayout.Space();
        EditorGUILayout.Space();

        if (advancedMode)
        {
            modelScale      = EditorGUILayout.FloatField("Model Scale", modelScale, GUILayout.Width(343));
            importAnimation = EditorGUILayout.Toggle("Import Animation", importAnimation, GUILayout.Width(343));

            keepQuads       = EditorGUILayout.Toggle("Keep Quads", keepQuads, GUILayout.Width(343));
            weldVertices    = EditorGUILayout.Toggle("Weld Vertices", weldVertices, GUILayout.Width(343));
            swapUV          = EditorGUILayout.Toggle("Swap UV", swapUV, GUILayout.Width(343));
            ImportMaterials = EditorGUILayout.Toggle("Import Materials", ImportMaterials, GUILayout.Width(343));
        }
        EditorGUILayout.Space();
        EditorGUILayout.Space();

        EditorGUILayout.EndScrollView();
    }
        private void OnGUI()
        {
            if (m_MessageNotification != null)
            {
                DrawMessage();
            }

            m_ScrollPos = EditorGUILayout.BeginScrollView(m_ScrollPos);

            GUILayout.Space(10f);

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            {
                EditorGUILayout.BeginHorizontal();
                {
                    GUILayout.Label("Sub mesh count", GUILayout.ExpandWidth(false));
                    var count = EditorGUILayout.IntSlider(m_SubMeshCount, k_MinSubMeshCount, k_MaxSubMeshCount);
                    if (count != m_SubMeshCount)
                    {
                        m_SubMeshCount = count;
                        TrimSourcePathFromSubMeshCount();
                    }
                }
                EditorGUILayout.EndHorizontal();

                GUILayout.Space(10f);

                for (int subMeshIndex = 0; subMeshIndex < m_SubMeshCount; ++subMeshIndex)
                {
                    if (subMeshIndex != 0)
                    {
                        GUILayout.Space(5f);
                    }
                    EditorGUILayout.BeginHorizontal();
                    {
                        GUILayout.Label($"SubMesh #{subMeshIndex + 1} CSV", GUILayout.ExpandWidth(false));
                        GUILayout.Space(10f);
                        if (string.IsNullOrEmpty(m_SourcePath[subMeshIndex]))
                        {
                            GUILayout.FlexibleSpace();
                            GUILayout.Label("not select source csv file. Or you can drop csv file to here.", GUILayout.ExpandWidth(false), GUILayout.MinWidth(0f));
                            GUILayout.FlexibleSpace();
                        }
                        else
                        {
                            GUILayout.Label(m_SourcePath[subMeshIndex], GUILayout.ExpandWidth(false), GUILayout.MinWidth(0f));
                        }
                        GUILayout.Space(10f);

                        GUILayout.FlexibleSpace();

                        if (GUILayout.Button("Select File...", GUILayout.ExpandWidth(false)))
                        {
                            string fileSelected = EditorUtility.OpenFilePanelWithFilters("Select source csv file", string.IsNullOrEmpty(m_SourcePath[subMeshIndex]) ? Application.dataPath : m_SourcePath[subMeshIndex], new string[] { "csv files", "csv", "All files", "*" });
                            if (!string.IsNullOrEmpty(fileSelected))
                            {
                                DoChangeSourceCSV(subMeshIndex, fileSelected);
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    HandleDragAndDropGUI(GUILayoutUtility.GetLastRect(), subMeshIndex);
                }
            }
            EditorGUILayout.EndVertical();

            if (!string.IsNullOrEmpty(m_ErrorMessage))
            {
                EditorGUILayout.HelpBox(m_ErrorMessage, MessageType.Error);
            }

            GUILayout.Space(10f);

            EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.MinHeight(50f));
            {
                GUILayout.FlexibleSpace();
                EditorGUILayout.BeginHorizontal();
                {
                    GUILayout.Label("Destination Mesh", GUILayout.ExpandWidth(false));
                    GUILayout.Space(10f);
                    m_DestPath = GUILayout.TextField(m_DestPath);
                    GUILayout.Space(10f);

                    if (GUILayout.Button("Select Path...", GUILayout.ExpandWidth(false)))
                    {
                        string fileSelected = EditorUtility.SaveFilePanelInProject("Select destination mesh file", "New Mesh", "asset", "file to save");
                        if (!string.IsNullOrEmpty(fileSelected))
                        {
                            DoChangeDestMesh(fileSelected);
                        }
                        GUIUtility.ExitGUI();
                    }
                }
                EditorGUILayout.EndHorizontal();
                GUILayout.FlexibleSpace();
            }
            EditorGUILayout.EndVertical();

            GUILayout.Space(10f);

            EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.MinHeight(50f));
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Vertex Attribute Mapping (Determined by the CSV of the first submesh)");
                GUILayout.FlexibleSpace();
                if (m_VertexAttrList.Count > 0)
                {
                    DoPresetsDropDown();
                }
                EditorGUILayout.EndHorizontal();

                if (m_VertexAttrList.Count <= 0)
                {
                    GUILayout.Label("Waiting set CSV File...");
                }
                else
                {
                    for (int i = 0; i < m_VertexAttrList.Count; ++i)
                    {
                        bool changed = false;
                        var  data    = m_VertexAttrList[i];
                        EditorGUILayout.BeginHorizontal();
                        var newIgnore = EditorGUILayout.ToggleLeft($"{data.CSVName} ({data.CompCount})", !data.Ignore, GUILayout.ExpandWidth(false));
                        if (newIgnore == data.Ignore)
                        {
                            data.Ignore = !newIgnore;
                            changed     = true;
                        }
                        EditorGUI.BeginDisabledGroup(data.Ignore);
                        var newAttr = (UnityEngine.Rendering.VertexAttribute)EditorGUILayout.EnumPopup(string.Empty, data.Attr, GUILayout.ExpandWidth(false));
                        EditorGUI.EndDisabledGroup();
                        if (newAttr != data.Attr)
                        {
                            data.Attr = newAttr;
                            changed   = true;
                        }
                        EditorGUILayout.EndHorizontal();
                        if (changed)
                        {
                            m_VertexAttrList[i] = data;
                        }
                    }
                }
            }
            EditorGUILayout.EndVertical();


            GUILayout.Space(10f);

            m_FlipVertexWindingOrder    = EditorGUILayout.ToggleLeft(new GUIContent("Flip Vertex Winding Order", "vertices of triangles in counter-clockwise order (or in clockwise order in DirectX)"), m_FlipVertexWindingOrder, GUILayout.ExpandWidth(false));
            m_AutoCalcNormalIfNotExist  = EditorGUILayout.ToggleLeft(new GUIContent("Auto calculate normal if not exist", "Source of mesh normals. If a mesh has no normals, they will be calculated instead."), m_AutoCalcNormalIfNotExist, GUILayout.ExpandWidth(false));
            m_AutoCalcTangentIfNotExist = EditorGUILayout.ToggleLeft(new GUIContent("Auto calculate tangent if not exist", "Source of mesh tangents. If a mesh has no tangents, they will be calculated instead."), m_AutoCalcTangentIfNotExist, GUILayout.ExpandWidth(false));
            m_OptimizesRendering        = EditorGUILayout.ToggleLeft(new GUIContent("Optimize Mesh", "Reorder vertices and/or polygons for better GPU performance."), m_OptimizesRendering, GUILayout.ExpandWidth(false));
            m_ReadWriteEnable           = EditorGUILayout.ToggleLeft(new GUIContent("Read/Write Enabled", "Allow vertices and indices to be accessed from script."), m_ReadWriteEnable, GUILayout.ExpandWidth(false));
            m_MeshCompression           = (ModelImporterMeshCompression)EditorGUILayout.EnumPopup(new GUIContent("Mesh Compression", "Higher compression ratio means lower mesh precision. If enabled, the mesh bounds and a lower bit depth per component are used to compress the mesh data."), m_MeshCompression, GUILayout.ExpandWidth(false));


            EditorGUILayout.EndScrollView();

            GUILayout.FlexibleSpace();

            EditorGUI.BeginDisabledGroup(!IsAllSourcePathReady() || string.IsNullOrEmpty(m_DestPath));
            {
                if (GUILayout.Button("Generate Mesh", GUILayout.MinHeight(50f)))
                {
                    DoGenerateMesh();
                }
            }
            EditorGUI.EndDisabledGroup();
        }