Example #1
0
 private void Awake()
 {
     if (progressSlider != null)
     {
         progressSlider.maxValue = 100f;
         progressSlider.gameObject.SetActive(false);
     }
     if (progressImage != null)
     {
         progressImage.gameObject.SetActive(false);
     }
     if (progressText != null)
     {
         progressText.gameObject.SetActive(false);
     }
     objImporter = GetComponent <ObjectImporter>();
 }
Example #2
0
 private void Awake()
 {
     multiobject = gameObject.GetComponent <MultiObjectImporter>();
     if (progressSlider != null)
     {
         progressSlider.maxValue = 100f;
         progressSlider.gameObject.SetActive(false);
     }
     if (progressImage != null)
     {
         progressImage.gameObject.SetActive(false);
     }
     if (progressText != null)
     {
         progressText.gameObject.SetActive(false);
     }
     objImporter = GetComponent <ObjectImporter>();
     // TODO: check and warn
 }
Example #3
0
        private void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();
            defaultImportPath = EditorGUILayout.TextField("Default import path:", defaultImportPath);
            if (GUILayout.Button("...", GUILayout.Width(24), GUILayout.Height(15)))
            {
                defaultImportPath = EditorUtility.OpenFolderPanel("Select a folder", defaultImportPath, "");
                defaultImportPath = defaultImportPath.Replace('\\', '/');
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            lastPath = EditorGUILayout.TextField("OBJ file path:", lastPath);
            if (!string.IsNullOrEmpty(lastPath))
            {
                if (GUILayout.Button("^", GUILayout.Width(24), GUILayout.Height(15)))
                {
                    FileInfo fileInfo = new FileInfo(lastPath);
                    defaultImportPath = fileInfo.Directory.FullName;
                    defaultImportPath = defaultImportPath.Replace('\\', '/');
                }
            }
            if (GUILayout.Button("...", GUILayout.Width(24), GUILayout.Height(15)))
            {
                string[] filters      = { "OBJ files", "obj", "All files", "*" };
                string   absolutePath = EditorUtility.OpenFilePanelWithFilters("Laod OBJ model", defaultImportPath, filters);
                if (!string.IsNullOrEmpty(absolutePath))
                {
                    FileInfo fileInfo = new FileInfo(absolutePath);
                    Debug.Log(fileInfo.Directory.FullName);
                    //EditorPrefs.SetString("OBJ Import path", fileInfo.Directory.FullName);
                    lastPath = absolutePath;
                }
            }
            EditorGUILayout.EndHorizontal();

            scale                = EditorGUILayout.FloatField("Scale:", scale);
            convertUpAxis        = EditorGUILayout.Toggle("Convert vertical axis", convertUpAxis);
            convertToDoubleSided = EditorGUILayout.Toggle("Convert to double-sided (duplicate&flip polygons)", convertToDoubleSided);
            litDiffuseMap        = EditorGUILayout.Toggle("Lit diffuse map", litDiffuseMap);
            buildColliders       = EditorGUILayout.Toggle("Generate mesh colliders", buildColliders);
            if (buildColliders)
            {
                colliderConvex = EditorGUILayout.Toggle("Convex mesh colliders", colliderConvex);
                if (colliderConvex)
                {
                    EditorGUILayout.HelpBox(
                        "Building convex meshes may not work for meshes with too many smooth surface regions.\n" +
                        "If you get errors find each involved object and fix its mesh collider (e.g. remove it or uncheck \"Convex\").",
                        MessageType.Warning);
                    colliderTrigger   = EditorGUILayout.Toggle("Mesh colliders as trigger", colliderTrigger);
                    colliderInflate   = EditorGUILayout.Toggle("Mesh colliders inflated", colliderInflate);
                    colliderSkinWidth = EditorGUILayout.FloatField("Mesh colliders inflation amount", colliderSkinWidth);
                }
            }
#if UNITY_2017_3_OR_NEWER
            use32bitIndices = EditorGUILayout.Toggle("Use 32 bit indices", use32bitIndices);
#endif

            importAssets = EditorGUILayout.Toggle("Import assets", importAssets);
            if (importAssets)
            {
                importAssetPath = EditorGUILayout.TextField("OBJ asset path:", importAssetPath);
                importAssetPath = importAssetPath.Replace('\\', '/');
            }
            EditorGUILayout.Separator();
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Reset settings", GUILayout.Width(100), GUILayout.Height(24)))
            {
                ResetSettings();
            }
            if (GUILayout.Button("Save settings", GUILayout.Width(100), GUILayout.Height(24)))
            {
                SaveSettings();
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Import", GUILayout.Width(80), GUILayout.Height(24)))
            {
                lastPath = lastPath.Replace('\\', '/');
                string absolute_path = lastPath;
                if (!string.IsNullOrEmpty(absolute_path))
                {
                    objObject                   = new GameObject();
                    objObject.name              = "OBJ Loader";
                    objImporter                 = objObject.AddComponent <ObjectImporter>();
                    objImporter.importAssets    = importAssets;
                    objImporter.importAssetPath = importAssetPath;

                    //string absolute_path = @"E:\DEV\PROTO\DATA\Models\teleportbeam.obj";
                    //absolute_path = absolute_path.Replace('\\', '/');
                    GameObject parentObject = Selection.activeObject as GameObject;
                    if (parentObject && !parentObject.activeInHierarchy)
                    {
                        parentObject = null;
                    }
                    ImportOptions opt = new ImportOptions();
                    opt.zUp                  = convertUpAxis;
                    opt.litDiffuse           = litDiffuseMap;
                    opt.convertToDoubleSided = convertToDoubleSided;
                    opt.modelScaling         = scale;
                    opt.buildColliders       = buildColliders;
                    opt.colliderTrigger      = colliderTrigger;
                    opt.colliderConvex       = colliderConvex;
                    opt.colliderInflate      = colliderInflate;
                    opt.colliderSkinWidth    = colliderSkinWidth;
                    objImporter.ImportFile(absolute_path, parentObject ? parentObject.transform : null, opt);
                    //ObjLoader loader = new ObjLoader();
                    //loader.zUpToYUp = false;
                    //loader.scaling = Vector3.one * 10f;
                    //Debug.Log("Loading OBJ: " + absolute_path);
                    //loader.Load("obj_import_test", absolute_path, go);
                    loading = true;
                }
            }
            if (GUILayout.Button("Cancel", GUILayout.Width(80), GUILayout.Height(24)))
            {
                EditorUtility.ClearProgressBar();
                if (loading)
                {
                    if (objObject)
                    {
                        DestroyImmediate(objObject);
                    }
                    loading = false;
                }
                Close();
            }
            EditorGUILayout.EndHorizontal();
        }
Example #4
0
        private void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();
            defaultImportPath = EditorGUILayout.TextField("Default import path:", defaultImportPath);
            if (GUILayout.Button("...", GUILayout.Width(24), GUILayout.Height(15)))
            {
                defaultImportPath = EditorUtility.OpenFolderPanel("Select a folder", defaultImportPath, "");
                defaultImportPath = defaultImportPath.Replace('\\', '/');
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            lastPath = EditorGUILayout.TextField("OBJ file path:", lastPath);
            if (!string.IsNullOrEmpty(lastPath))
            {
                if (GUILayout.Button("^", GUILayout.Width(24), GUILayout.Height(15)))
                {
                    FileInfo fileInfo = new FileInfo(lastPath);
                    defaultImportPath = fileInfo.Directory.FullName;
                    defaultImportPath = defaultImportPath.Replace('\\', '/');
                }
            }
            if (GUILayout.Button("...", GUILayout.Width(24), GUILayout.Height(15)))
            {
                string[] filters      = { "OBJ files", "obj", "All files", "*" };
                string   absolutePath = EditorUtility.OpenFilePanelWithFilters("Laod OBJ model", defaultImportPath, filters);
                if (!string.IsNullOrEmpty(absolutePath))
                {
                    FileInfo fileInfo = new FileInfo(absolutePath);
                    Debug.Log(fileInfo.Directory.FullName);
                    //EditorPrefs.SetString("OBJ Import path", fileInfo.Directory.FullName);
                    lastPath = absolutePath;
                }
            }
            EditorGUILayout.EndHorizontal();

            scale                = EditorGUILayout.FloatField("Scale:", scale);
            convertUpAxis        = EditorGUILayout.Toggle("Convert vertical axis", convertUpAxis);
            convertToDoubleSided = EditorGUILayout.Toggle("Convert to double-sided (duplicate&flip polygons)", convertToDoubleSided);
            litDiffuseMap        = EditorGUILayout.Toggle("Lit diffuse map", litDiffuseMap);
            importAssets         = EditorGUILayout.Toggle("Import assets", importAssets);
            if (importAssets)
            {
                importAssetPath = EditorGUILayout.TextField("OBJ asset path:", importAssetPath);
                importAssetPath = importAssetPath.Replace('\\', '/');
            }
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Reset settings", GUILayout.Width(100), GUILayout.Height(24)))
            {
                ResetSettings();
            }
            if (GUILayout.Button("Save settings", GUILayout.Width(100), GUILayout.Height(24)))
            {
                SaveSettings();
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Import", GUILayout.Width(80), GUILayout.Height(24)))
            {
                lastPath = lastPath.Replace('\\', '/');
                string absolute_path = lastPath;
                if (!string.IsNullOrEmpty(absolute_path))
                {
                    objObject                   = new GameObject();
                    objObject.name              = "OBJ Loader";
                    objImporter                 = objObject.AddComponent <ObjectImporter>();
                    objImporter.importAssets    = importAssets;
                    objImporter.importAssetPath = importAssetPath;

                    //string absolute_path = @"E:\DEV\PROTO\DATA\Models\teleportbeam.obj";
                    //absolute_path = absolute_path.Replace('\\', '/');
                    GameObject parentObject = Selection.activeObject as GameObject;
                    if (parentObject && !parentObject.activeInHierarchy)
                    {
                        parentObject = null;
                    }
                    ImportOptions opt = new ImportOptions();
                    opt.zUp                  = convertUpAxis;
                    opt.litDiffuse           = litDiffuseMap;
                    opt.convertToDoubleSided = convertToDoubleSided;
                    opt.modelScaling         = scale;
                    objImporter.ImportFile(absolute_path, parentObject ? parentObject.transform : null, opt);
                    //ObjLoader loader = new ObjLoader();
                    //loader.zUpToYUp = false;
                    //loader.scaling = Vector3.one * 10f;
                    //Debug.Log("Loading OBJ: " + absolute_path);
                    //loader.Load("obj_import_test", absolute_path, go);
                    loading = true;
                }
            }
            if (GUILayout.Button("Cancel", GUILayout.Width(80), GUILayout.Height(24)))
            {
                EditorUtility.ClearProgressBar();
                if (loading)
                {
                    if (objObject)
                    {
                        DestroyImmediate(objObject);
                    }
                    loading = false;
                }
                Close();
            }
            EditorGUILayout.EndHorizontal();
        }