Example #1
0
        public void Modify(string path)
        {
            if (replaceGuidPairDictionary == null ||
                path == null ||
                !Path.GetExtension(path).Equals(".fbx", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            var modelImporter = ModelImporter.GetAtPath(path);
            var map           = modelImporter.GetExternalObjectMap();

            foreach (var pair in map)
            {
                if (pair.Value is Material)
                {
                    var mat     = pair.Value as Material;
                    var matPath = AssetDatabase.GetAssetPath(mat.GetInstanceID());
                    var matGuid = AssetDatabase.AssetPathToGUID(matPath);
                    if (replaceGuidPairDictionary.ContainsKey(matGuid))
                    {
                        var newMatPath = AssetDatabase.GUIDToAssetPath(replaceGuidPairDictionary[matGuid]);
                        var newMat     = AssetDatabase.LoadAssetAtPath <Material>(newMatPath);
                        modelImporter.RemoveRemap(pair.Key);
                        modelImporter.AddRemap(pair.Key, newMat);
                    }
                }
            }
            AssetDatabase.WriteImportSettingsIfDirty(path);
        }
Example #2
0
    void AdjustNoAniModel(string rootPath)
    {
        Debug.Log("AdjustNoAniModel " + rootPath);
        #if UNITY_EDITOR
        var        allModel = Path.Combine(Application.dataPath, rootPath);
        var        resDir   = new DirectoryInfo(allModel);
        FileInfo[] fileInfo = resDir.GetFiles("*.fbx", SearchOption.TopDirectoryOnly);
        AssetDatabase.StartAssetEditing();
        foreach (FileInfo file in fileInfo)
        {
            Debug.Log("file is " + file.Name + " " + file.Name);

            //var ass = Path.Combine("Assets/" + modelStr.stringValue, file.Name);
            var ass    = file.FullName.Replace(Application.dataPath, "Assets");
            var import = ModelImporter.GetAtPath(ass) as ModelImporter;
            Debug.Log("import is " + import);
            import.globalScale     = 1;
            import.importAnimation = false;
            import.animationType   = ModelImporterAnimationType.None;

            Debug.Log("import change state " + import);
            AssetDatabase.WriteImportSettingsIfDirty(ass);
        }
        AssetDatabase.StopAssetEditing();
        AssetDatabase.Refresh();
        #endif
    }
Example #3
0
        /// <summary>
        /// Sets the correct settings for the models to be imported
        /// </summary>
        /// <param name="directory">The directory in which to look for models</param>
        private static void FixModelMaterialReferences(string directory)
        {
            if (!Directory.Exists(directory))
            {
                Debug.LogError("ZoneImporter: Cannot fix model material references at path: " + directory);
                return;
            }

            string[] meshFiles = Directory.GetFiles(directory, "*.obj", SearchOption.AllDirectories);

            for (int i = 0; i < meshFiles.Length; ++i)
            {
                meshFiles[i] = Path.GetFileName(meshFiles[i]);
            }

            foreach (var meshPath in meshFiles)
            {
                string        assetPath = directory + meshPath;
                ModelImporter importer  = (ModelImporter)ModelImporter.GetAtPath(assetPath);

                importer.addCollider      = true; //  we will replace the collision mesh where relevant
                importer.importNormals    = ModelImporterNormals.Calculate;
                importer.importMaterials  = true;
                importer.materialLocation = ModelImporterMaterialLocation.External;
                importer.materialSearch   = ModelImporterMaterialSearch.RecursiveUp;
                importer.SaveAndReimport();
            }
        }
Example #4
0
    void OnGUI()
    {
        EditorGUILayout.BeginVertical();

        m_compressType = (AnimationCompressType)EditorGUILayout.EnumPopup(m_compressType);

        if (m_compressType != AnimationCompressType.NONE)
        {
            m_rotationErrorThreshold = EditorGUILayout.FloatField("Rotation Error: ", m_rotationErrorThreshold);
            m_positionErrorThreshold = EditorGUILayout.FloatField("Position Error: ", m_positionErrorThreshold);
            m_scaleErrorThreshold    = EditorGUILayout.FloatField("Scale Error: ", m_scaleErrorThreshold);
        }

        if (GUILayout.Button("Apply"))
        {
            string[] allAssetPaths = AssetDatabase.GetAllAssetPaths();
            for (int i = 0; i < allAssetPaths.Length; ++i)
            {
                ModelImporter importer = ModelImporter.GetAtPath(allAssetPaths[i]) as ModelImporter;
                if (importer != null)
                {
                    FormatModel(importer, m_compressType, m_rotationErrorThreshold, m_positionErrorThreshold, m_scaleErrorThreshold);
                }
            }
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            Debug.Log(m_compressType);
            Debug.Log(m_rotationErrorThreshold);
            Debug.Log(m_positionErrorThreshold);
            Debug.Log(m_scaleErrorThreshold);
        }
        EditorGUILayout.EndHorizontal();
    }
Example #5
0
        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);
        }
Example #6
0
    public override void OnInspectorGUI()
    {
        if (GUILayout.Button("Set Import"))
        {
            Debug.Log(Application.dataPath);

            var        allModel = Path.Combine(Application.dataPath, "levelsets/mine");
            var        resDir   = new DirectoryInfo(allModel);
            FileInfo[] fileInfo = resDir.GetFiles("*.fbx", SearchOption.AllDirectories);
            AssetDatabase.StartAssetEditing();
            foreach (FileInfo file in fileInfo)
            {
                Debug.Log("file is " + file.Name + " " + file.Name);

                var ass    = Path.Combine("Assets/levelsets/mine", file.Name);
                var import = ModelImporter.GetAtPath(ass) as ModelImporter;
                Debug.Log("import is " + import);
                import.globalScale     = 1;
                import.importAnimation = false;
                import.animationType   = ModelImporterAnimationType.None;

                Debug.Log("import change state " + import);
                AssetDatabase.WriteImportSettingsIfDirty(ass);
            }
            AssetDatabase.StopAssetEditing();
            AssetDatabase.Refresh();
        }
    }
        private static SerializedObject GetSerializedObject(AssetAuditor.AssetType assetType)
        {
            SerializedObject so = null;

            switch (assetType)
            {
            case AssetAuditor.AssetType.Texture:
                so = new SerializedObject(TextureImporter.GetAtPath(AssetAuditorPreferences.ProxyTexturePath));
                break;

            case AssetAuditor.AssetType.Model:
                so = new SerializedObject(ModelImporter.GetAtPath(AssetAuditorPreferences.ProxyModelPath));
                break;

            case AssetAuditor.AssetType.Audio:
                so = new SerializedObject(AudioImporter.GetAtPath(AssetAuditorPreferences.ProxyAudioPath));
                break;

            case AssetAuditor.AssetType.Folder:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(so);
        }
Example #8
0
    static private void ChangeFBXToAnimAndCompess(List <FileInfo> filesInfos)
    {
        int           iAniClipNum = 0;
        AnimationClip kAC = null;
        string        strFileName, strExtention, strFbxAssetPath;
        int           progress = 0;
        float         total    = filesInfos.Count;

        foreach (FileInfo fileInfo in filesInfos)
        {
            progress++;
            string parentDir = fileInfo.Directory.FullName;
            parentDir = parentDir.Substring(parentDir.IndexOf("Assets"));

            strFileName     = fileInfo.Name;
            strExtention    = fileInfo.Extension;
            strFbxAssetPath = fileInfo.FullName;

            strFbxAssetPath = strFbxAssetPath.Substring(strFbxAssetPath.IndexOf("Assets"));

            ModelImporter kMI = ModelImporter.GetAtPath(strFbxAssetPath) as ModelImporter;
            if (kMI == null)
            {
                Debug.LogError("null:" + strFbxAssetPath);
                continue;
            }
            //kMI.animationType = ModelImporterAnimationType.Legacy;

            //过滤
            if (fileInfo.Name.IndexOf("_skin", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                continue;
            }

            string targetDir = parentDir + "/" + "Animations";
            FileTools.CreateDirectory(targetDir);

            UnityEngine.Object[] arrObj = AssetDatabase.LoadAllAssetRepresentationsAtPath(strFbxAssetPath);
            foreach (UnityEngine.Object obj in arrObj)
            {
                kAC = obj as AnimationClip;
                if (kAC != null)
                {
                    string strClipAssetPath = targetDir + "/" + kAC.name + ".anim";
                    CreateAniClipAsset(kAC, strClipAssetPath);
                    iAniClipNum++;
                    EditorUtility.DisplayProgressBar("导出动画并压缩", strFbxAssetPath, progress / total);
                }
            }
        }
        EditorUtility.ClearProgressBar();
        if (iAniClipNum > 0)
        {
            //string strContext = String.Format("导出完成,共导出{0}个动画文件", iAniClipNum);
            //EditorUtility.DisplayDialog("导出动画文件", strContext, "确定");
        }
    }
Example #9
0
    public static void setModelProp(string modelName, bool isReadable, ModelImporterNormals modelNormals, ModelImporterTangents modelTangents)
    {
        string matPath = PStr.b().a("Assets/").a(CLPathCfg.self.basePath).a("/")
                         .a("upgradeRes4Dev").a("/other/model/").a(modelName.Replace(".", "/")).a(".FBX").e();

        ModelImporter mi = ModelImporter.GetAtPath(matPath) as ModelImporter;

        setModelProp(mi, isReadable, modelNormals, modelTangents);
        doCleanModelMaterials(matPath);
    }
    public static bool UpdateModel(string assetPath, ResourceParams param, bool onlySetting)
    {
        ModelImporter modelImporter = ModelImporter.GetAtPath(assetPath) as ModelImporter;

        if (modelImporter == null)
        {
            Debug.LogErrorFormat("no model importer at {0}", assetPath);
            return(false);
        }
        return(UpdateModel(param, modelImporter, onlySetting));
    }
Example #11
0
    // 修改模型设置
    void setModelSetup(string path)
    {
        ModelImporter importer = (ModelImporter)ModelImporter.GetAtPath(path);

        if (importer)
        {
            importer.globalScale = scaleFactor;
            importer.SaveAndReimport();
            Debug.Log("Scale Factor 设置成功: " + Path.GetFileName(path));
        }
    }
Example #12
0
        void ShowAnimatorModel()
        {
            _fbxModel = (GameObject)CreateObjectField("model", _fbxModel, typeof(GameObject));

            string path = AssetDatabase.GetAssetPath(_fbxModel);

            ModelImporter modelIm = (ModelImporter)ModelImporter.GetAtPath(path);

            //		AnimationClip newClip = AssetDatabase.LoadAssetAtPath(path, typeof(AnimationClip)) as AnimationClip;

            EditorGUILayout.BeginHorizontal();
            CreateLabel("name");
            CreateLabel("start");
            CreateLabel("end");
            CreateLabel("isLooping");
            EditorGUILayout.EndHorizontal();

            if (modelIm == null)
            {
                return;
            }
            ModelImporterClipAnimation[] animations = modelIm.clipAnimations;
            for (int pos = 0; pos < animations.Length; pos++)
            {
                EditorGUILayout.BeginHorizontal();
                animations[pos].name       = CreateStringField(animations[pos].name);
                animations[pos].firstFrame = CreateFloatField(animations[pos].firstFrame);
                animations[pos].lastFrame  = CreateFloatField(animations[pos].lastFrame);
                animations[pos].loop       = CreateCheckBox(animations[pos].loop);
                //			animations[pos].
                CreateLabel(animations[pos].loop.ToString());
                EditorGUILayout.EndHorizontal();
            }
            if (CreateSpaceButton("Insert"))
            {
                ModelImporterClipAnimation[] newAnim = new ModelImporterClipAnimation[animations.Length + 1];
                animations.CopyTo(newAnim, 0);
                animations = newAnim;
                animations[animations.Length - 1] = animations[0];
            }
            if (CreateSpaceButton("Sub"))
            {
                ModelImporterClipAnimation[] newAnim = new ModelImporterClipAnimation[animations.Length - 1];
                System.Array.Copy(animations, newAnim, newAnim.Length);
                animations = newAnim;
            }
            if (GUI.changed)
            {
                modelIm.clipAnimations = animations;

                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
        }
Example #13
0
        void ImportMesh(string path)
        {
            AssetDatabase.ImportAsset(path);
            ModelImporter importer = ModelImporter.GetAtPath(path) as ModelImporter;

            // importer.globalScale = 1;
            importer.importMaterials = false;
            importer.importAnimation = false;
            importer.importNormals   = ModelImporterNormals.Import;
            importer.importTangents  = ModelImporterTangents.Import;
            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
        }
Example #14
0
 public void OnBlendShap(bool flag, bool[] state)
 {
     for (int i = 0; i < m_resourceModelData.m_BlendShape.Count; i++)
     {
         if (state[i])
         {
             ModelImporter modelImporter = ModelImporter.GetAtPath(m_resourceModelData.m_BlendShape[i]) as ModelImporter;
             modelImporter.importBlendShapes = flag;
             modelImporter.SaveAndReimport();
         }
     }
 }
Example #15
0
 public void OnLightmapUV(bool flag, bool[] state)
 {
     for (int i = 0; i < m_resourceModelData.m_allNoLightmapUV.Count; i++)
     {
         if (state[i])
         {
             ModelImporter modelImporter = ModelImporter.GetAtPath(m_resourceModelData.m_allNoLightmapUV[i]) as ModelImporter;
             modelImporter.generateSecondaryUV = flag;
             modelImporter.SaveAndReimport();
         }
     }
 }
        public static void UnoptimizeGameObjects(string assetPath)
        {
            ModelImporter modelImporter = (ModelImporter)ModelImporter.GetAtPath(assetPath);

            if (modelImporter == null)
            {
                return;
            }
            modelImporter.optimizeGameObjects        = false;
            modelImporter.extraExposedTransformPaths = new string[0];
            modelImporter.SaveAndReimport();
        }
Example #17
0
 public void OnRW(bool flag, bool[] state)
 {
     for (int i = 0; i < m_resourceModelData.m_allOnWrite.Count; i++)
     {
         if (state[i])
         {
             ModelImporter modelImporter = ModelImporter.GetAtPath(m_resourceModelData.m_allOnWrite[i]) as ModelImporter;
             modelImporter.isReadable = flag;
             modelImporter.SaveAndReimport();
         }
     }
 }
        /// <summary>
        /// Coroutine that saves the specified global mesh asset into the asset bundle.
        /// </summary>
        /// <returns></returns>
        private IEnumerator SaveGlobalMeshAsAssetCoroutine()
        {
            // Set the destination paths to a temporary asset folder.
            string bundledAssetName  = GetBundledAssetName(globalMeshAssetName);
            string assetPathAbsolute = GetAssetPathAbsolute(bundledAssetName);
            string assetPathRelative = GetAssetPathRelative(bundledAssetName);

            // Check if the asset has already been processed.
            if (!dataHandler.IsAssetAlreadyProcessed(assetPathRelative))
            {
                // If the mesh to store is already an asset, move it to the asset bundle path.
                string dstExtension = Path.GetExtension(_globalMeshPathAbsolute);
                if (dstExtension == ".asset")
                {
                    // Copy the asset to the destination path.
                    GeneralToolkit.Replace(PathType.File, _globalMeshPathAbsolute, assetPathAbsolute);
                    // Refresh the asset database.
                    AssetDatabase.Refresh();
                }
                // Otherwise, the mesh first has to be converted into an asset.
                else
                {
                    // Copy the mesh to the resources folder.
                    string dstName     = "COLIBRITempResource";
                    string dstFullPath = Path.Combine(COLIBRIVRSettings.settingsResourcesAbsolutePath, dstName + dstExtension);
                    GeneralToolkit.Replace(PathType.File, _globalMeshPathAbsolute, dstFullPath);
                    // Refresh the asset database.
                    AssetDatabase.Refresh();
                    yield return(null);

                    // Make the mesh readable so that colliders can be added.
                    ModelImporter modelImporter = ModelImporter.GetAtPath(GeneralToolkit.ToRelativePath(dstFullPath)) as ModelImporter;
                    modelImporter.isReadable = true;
                    modelImporter.SaveAndReimport();
                    // Load the mesh from resources.
                    Mesh loadedMesh = Resources.Load <Mesh>(dstName);
                    // Copy the mesh by instantiating it.
                    globalMesh = (Mesh)Instantiate(loadedMesh);
                    // Recalculate the mesh's normals and bounds.
                    globalMesh.RecalculateNormals();
                    globalMesh.RecalculateBounds();
                    // Create an asset from the copied mesh.
                    AssetDatabase.CreateAsset(globalMesh, assetPathRelative);
                    AssetDatabase.Refresh();
                    // Delete the mesh that was copied into the resources folder.
                    GeneralToolkit.Delete(dstFullPath);
                }
            }
            Mesh meshAsset = AssetDatabase.LoadAssetAtPath <Mesh>(assetPathRelative);

            globalMesh = (Mesh)Instantiate(meshAsset);
        }
        public static void OptimizeGameObjects(string assetPath, string[] extraExposedTransformNames)
        {
            ModelImporter modelImporter = (ModelImporter)ModelImporter.GetAtPath(assetPath);

            if (modelImporter == null)
            {
                Debug.LogError("ModelOptimize::OptimizeGameObjects->modelImporter is null.assetPath = " + assetPath);
                return;
            }

            if (modelImporter.animationType != ModelImporterAnimationType.Human && modelImporter.animationType != ModelImporterAnimationType.Generic)
            {
                Debug.LogError("ModelOptimize::OptimizeGameObjects->animationType is not Human or Generic. animtionType = " + modelImporter.animationType);
                return;
            }

            SerializedObject   serializedObject = new SerializedObject(modelImporter);
            SerializedProperty copyAvatar       = serializedObject.FindProperty("m_CopyAvatar");

            if (copyAvatar == null || copyAvatar.boolValue)
            {
                Debug.LogError("ModelOptimize::OptimizeGameObjects-> Avatar Definition should be set as \"Create From This Model\"");
                return;
            }

            modelImporter.optimizeGameObjects = true;
            if (extraExposedTransformNames == null || extraExposedTransformNames.Length == 0)
            {
                modelImporter.extraExposedTransformPaths = new string[0];
                modelImporter.SaveAndReimport();
                return;
            }

            List <string> paths = new List <string>();

            string[] transformPaths = modelImporter.transformPaths;
            foreach (var path in transformPaths)
            {
                foreach (var name in extraExposedTransformNames)
                {
                    if (path.ToLower().Contains(name.ToLower()))
                    {
                        paths.Add(path);
                    }
                }
            }

            modelImporter.extraExposedTransformPaths = paths.ToArray();
            modelImporter.SaveAndReimport();

            AssetDatabase.ImportAsset(assetPath);
        }
    // 修改模型设置
    void setModelSetup(string path)
    {
        ModelImporter importer = ModelImporter.GetAtPath(path) as ModelImporter;

        if (importer)
        {
            importer.animationType      = ModelImporterAnimationType.Generic;
            importer.avatarSetup        = ModelImporterAvatarSetup.CreateFromThisModel;
            importer.globalScale        = 100;
            importer.materialImportMode = ModelImporterMaterialImportMode.None;
            importer.SaveAndReimport();
            // Debug.Log("-- 修改模型设置: " + importer.name);
        }
    }
Example #21
0
    void Optimize()
    {
        ModelImporter importer = (ModelImporter)ModelImporter.GetAtPath(AssetDatabase.GetAssetPath(exposedTransforms [0].GetComponent <SkinnedMeshRenderer> ().sharedMesh.GetInstanceID()));

        if (importer != null)
        {
            Debug.Log("found one! " + importer.assetPath);
        }

        importer.extraExposedTransformPaths =
            (from t in exposedTransforms
             select t.name).ToArray();
        importer.optimizeGameObjects = true;
        EditorUtility.SetDirty(importer);
        AssetDatabase.SaveAssets();
    }
    void Export()
    {
        string sceneName = System.IO.Path.GetFileNameWithoutExtension(EditorApplication.currentScene);

        foreach (var mesh in generatedObject.transform.GetComponentsInChildren <MeshFilter>())
        {
            string exportPath = "Assets/" + sceneName + "/" + name + "/" + mesh.name + ".obj";
            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(exportPath));
            ObjExporter.MeshToFile(mesh, exportPath);

            AssetDatabase.ImportAsset(exportPath);

            var importer = (ModelImporter)ModelImporter.GetAtPath(exportPath);

            importer.animationType = ModelImporterAnimationType.None;
        }
    }
        public void AddModelObj(string modelPath)
        {
            ModelImporter modelImporter = ModelImporter.GetAtPath(modelPath) as ModelImporter;

            if (modelImporter.isReadable)
            {
                m_allOnWrite.Add(modelPath);
            }
            if (!modelImporter.generateSecondaryUV)
            {
                m_allNoLightmapUV.Add(modelPath);
            }
            if (modelImporter.importBlendShapes)
            {
                m_BlendShape.Add(modelPath);
            }
        }
        public static void CreateModel()
        {
            GameObject o = Selection.activeGameObject;

            if (!o)
            {
                return;
            }
            ModelImporter importer = ModelImporter.GetAtPath(AssetDatabase.GetAssetPath(o)) as ModelImporter;

            if (!importer)
            {
                EditorUtility.DisplayDialog("Error!", "Model Import Failed!", "OK");
                return;
            }
            //AvatarBuilder.BuildHumanAvatar
        }
Example #25
0
        public static void ReImportFBX()
        {
            DirectoryInfo di       = new DirectoryInfo("Assets/Res/Model/");
            int           total    = di.GetFiles("*.FBX", SearchOption.AllDirectories).Length;
            int           progress = 0;

            foreach (FileInfo fi in di.GetFiles("*.FBX", SearchOption.AllDirectories))
            {
                progress++;
                string modelPath = fi.FullName.Substring(fi.FullName.IndexOf(@"Assets"));
                //Debugger.Log(modelPath);
                ModelImporter modelImporter = ModelImporter.GetAtPath(modelPath) as ModelImporter;
                modelImporter.SaveAndReimport();
                EditorUtility.DisplayProgressBar("导入模型", "当前进度", progress / (float)total);
            }
            EditorUtility.ClearProgressBar();
        }
Example #26
0
    private static void RemapFBXMaterial(string fbx_guid)
    {
        var fbx_path = AssetDatabase.GUIDToAssetPath(fbx_guid);
        var fbx      = AssetDatabase.LoadAssetAtPath <GameObject>(fbx_path);

        if (fbx == null)
        {
            return;
        }

        var importer = ModelImporter.GetAtPath(fbx_path) as ModelImporter;

        if (importer == null)
        {
            return;
        }
    }
Example #27
0
    private void processModelTangent(FileInfo file)
    {
        string        fbxPath       = file.FullName.Substring(file.FullName.IndexOf("Assets"));
        ModelImporter modelImporter = (ModelImporter)ModelImporter.GetAtPath(fbxPath);

        if (is_set_tangent)
        {
            if (modelImporter.tangentImportMode != modelTangentOption)
            {
                modelImporter.tangentImportMode = modelTangentOption;
                AssetDatabase.ImportAsset(fbxPath);
            }
        }
        if (modelImporter.tangentImportMode == modelTangentOption)
        {
            ModelTangentMsg.Add("<tr>" + "<td>" + file.FullName + "</td>" + "<td>" + modelTangentOption + "</td>" + "</tr>");
        }
    }
Example #28
0
 public static void FormateFbx()
 {
     Debug.LogWarning("开始");
     Object[] selectedAsset = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
     for (int i = 0; i < selectedAsset.Length; i++)
     {
         ModelImporter importer = (ModelImporter)ModelImporter.GetAtPath(AssetDatabase.GetAssetPath(selectedAsset[i]));
         if (importer != null)
         {
             ResImprotPost.FormateFbx(ref importer);
             importer.importNormals   = ModelImporterNormals.None;
             importer.importMaterials = true;
             AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(importer));
         }
     }
     AssetDatabase.SaveAssets();
     Debug.LogWarning("结束");
 }
Example #29
0
        public static MeshData GetMeshData(JanusRoom room, Mesh mesh)
        {
            MeshData data = new MeshData();

            Vector3[] vertices  = mesh.vertices;
            Vector3[] normals   = mesh.normals;
            int[]     triangles = mesh.triangles;

            data.Vertices  = vertices;
            data.Normals   = normals;
            data.Triangles = triangles;
            data.Name      = mesh.name;

            if (vertices == null || vertices.Length == 0)
            {
                Debug.LogWarning("Mesh is empty " + mesh.name, mesh);
                return(null);
            }

            // check if we have all the data
            int maximum = triangles.Max();

            if (normals.Length < maximum)
            {
                Debug.LogWarning("Mesh has not enough normals - " + mesh.name, mesh);
                return(null);
            }

            string meshPath = AssetDatabase.GetAssetPath(mesh);

            if (!string.IsNullOrEmpty(meshPath))
            {
                ModelImporter importer = (ModelImporter)ModelImporter.GetAtPath(meshPath);
                if (importer != null)
                {
                    data.Scale = importer.globalScale;
                }
            }

            data.UV = GetMeshUVs(room, mesh);
            return(data);
        }
Example #30
0
    public static void doCleanModelMaterials(string matPath)
    {
        checkModleSetting(matPath);
        ModelImporter mi = ModelImporter.GetAtPath(matPath) as ModelImporter;

        if (mi != null)
        {
            cleanModleMaterials(mi);
            AssetDatabase.ImportAsset(matPath);
        }

        GameObject go = ECLEditorUtl.getObjectByPath(matPath) as GameObject;

        if (go != null)
        {
            MeshRenderer mf = go.GetComponentInChildren <MeshRenderer> ();
            if (mf != null)
            {
                mf.sharedMaterial = null;
                Material[] mats = mf.sharedMaterials;
                for (int i = 0; i < mats.Length; i++)
                {
                    mats [i] = null;
                }
                mf.sharedMaterials = mats;
            }
            SkinnedMeshRenderer smr = go.GetComponentInChildren <SkinnedMeshRenderer> ();
            if (smr != null)
            {
                smr.sharedMaterial = null;
                Material[] mats = smr.sharedMaterials;
                for (int i = 0; i < mats.Length; i++)
                {
                    mats [i] = null;
                }
                smr.sharedMaterials = mats;
            }
            EditorUtility.SetDirty(go);
            AssetDatabase.WriteImportSettingsIfDirty(matPath);
            AssetDatabase.Refresh();
        }
    }