예제 #1
0
    private void Awake()
    {
        FilePath = pathSettings.RootPath + FilePath;
        if (File.Exists(FilePath))
        {
            objImporter = gameObject.GetComponent <ObjectImporter>();
            if (objImporter == null)
            {
                objImporter = gameObject.AddComponent <ObjectImporter>();
            }

            objImporter.ImportingStart += () => { Handheld.StartActivityIndicator(); };
            objImporter.ImportedModel  += (baseModel, name) =>
            {
                var model  = baseModel.transform.GetChild(0);
                var center = model.GetComponent <MeshFilter>().mesh.bounds.center;
                model.transform.position = -center;
                loadingText.enabled      = false;
                Handheld.StopActivityIndicator();
            };
            objImporter.ImportError += (err) => { Utils.ShowAndroidToastMessage(err); };
        }
        else
        {
            Utils.ShowAndroidToastMessage("path: '" + FilePath + "' not exist");
        }
    }
예제 #2
0
    public IEnumerator getObj()
    {
        yield return(www);

        Mesh           holderMesh = new Mesh();
        ObjectImporter newMesh    = new ObjectImporter();

        holderMesh = newMesh.ImportFile(www.text);

        foreach (Transform trans in this.gameObject.transform)
        {
            GameObject.Destroy(trans.gameObject);
        }

        GameObject child = Instantiate(newObj);

        child.transform.parent = this.gameObject.transform;

        MeshRenderer renderer = child.AddComponent <MeshRenderer>();
        MeshFilter   filter   = child.AddComponent <MeshFilter>();

        child.GetComponent <Renderer>().sharedMaterial = CustomMaterial;

        filter.mesh = holderMesh;

        CenterObject(child);
    }
예제 #3
0
 public void LoadObject()
 {
     firstLoad   = true;
     objImporter = loadedObject.AddComponent <ObjectImporter>();
     importOptions.buildColliders = true;
     objImporter.ImportModelAsync("loadedObject", filePath, loadedObject.transform, importOptions);
 }
예제 #4
0
            private void Awake()
            {
#if (UNITY_ANDROID || UNITY_IPHONE)
                filePath = Application.persistentDataPath + "/" + filePath;
#endif
                objImporter = gameObject.AddComponent <ObjectImporter>();
            }
예제 #5
0
        public static void ImportObjectsWithMegaList(Window window = null)
        {
            try
            {
                GenerationsLib.Core.FolderSelectDialog ofd = new GenerationsLib.Core.FolderSelectDialog();
                ofd.Title = "Select a clean Data Folder";
                if (ofd.ShowDialog() == true)
                {
                    string gameConfigPath = System.IO.Path.Combine(ofd.FileName, "Game", "GameConfig.bin");
                    if (File.Exists(gameConfigPath))
                    {
                        GameConfig SourceConfig   = new GameConfig(gameConfigPath);
                        var        objectImporter = new ObjectImporter(ofd.FileName, SourceConfig, Methods.Solution.CurrentSolution.CurrentScene.Entities.SceneObjects, Methods.Solution.CurrentSolution.StageConfig, Editor);
                        if (window != null)
                        {
                            objectImporter.Owner = window;
                        }
                        objectImporter.ShowDialog();

                        if (objectImporter.DialogResult != true)
                        {
                            return; // nothing to do
                        }
                        // user clicked Import, get to it!
                        Methods.Internal.UserInterface.UpdateControls();
                        Editor.EntitiesToolbar?.RefreshSpawningObjects(Methods.Solution.CurrentSolution.CurrentScene.Entities.SceneObjects);
                        Methods.Internal.UserInterface.SplineControls.UpdateSplineSpawnObjectsList(Methods.Solution.CurrentSolution.CurrentScene.Entities.SceneObjects);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Unable to import Objects. " + ex.Message);
            }
        }
예제 #6
0
        public static void ImportObjectsFromScene(Window window = null)
        {
            try
            {
                RSDKv5.Scene sourceScene = GetSceneForObjectImporting(window);
                if (sourceScene == null)
                {
                    return;
                }
                var objectImporter = new ObjectImporter(sourceScene.Objects, Methods.Solution.CurrentSolution.CurrentScene.Entities.SceneObjects, Methods.Solution.CurrentSolution.StageConfig, Editor);
                if (window != null)
                {
                    objectImporter.Owner = window;
                }
                objectImporter.ShowDialog();

                if (objectImporter.DialogResult != true)
                {
                    return; // nothing to do
                }
                // user clicked Import, get to it!
                Methods.Internal.UserInterface.UpdateControls();
                Editor.EntitiesToolbar?.RefreshSpawningObjects(Methods.Solution.CurrentSolution.CurrentScene.Entities.SceneObjects);
                Methods.Internal.UserInterface.SplineControls.UpdateSplineSpawnObjectsList(Methods.Solution.CurrentSolution.CurrentScene.Entities.SceneObjects);
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Unable to import Objects. " + ex.Message);
            }
        }
예제 #7
0
파일: ImportObj.cs 프로젝트: LHuss/capstone
    public void ImportObjFromFile(string fp)
    {
        Camera        cam           = Camera.main;
        ImportOptions importOptions = new ImportOptions();

        importOptions.modelScaling = 1f;
        GameObject gameObject = new GameObject();

        gameObject.AddComponent <ObjectImporter>();
        ObjectImporter objImporter = gameObject.GetComponent <ObjectImporter>();

        Debug.Log(fp);
        Debug.Log(filePath);
        if (filePath == "")
        {
            filePath = fp;
        }
        Debug.Log(filePath);
        objImporter.ImportModelAsync("My Object", filePath, null, importOptions);
        MeshController.Instance.DestroyModel();
        objImporter.ImportedModel += (GameObject importedObject, string path) =>
        {
            //manipulate the asynchronously imported object
            AttachComponents(importedObject);
            PositionObject(importedObject);
        };
    }
예제 #8
0
 private void Awake()
 {
     objLoader = GetComponent <ObjectImporter>();
     if (objLoader == null)
     {
         objLoader = gameObject.AddComponent <ObjectImporter>();
     }
 }
예제 #9
0
 private void Awake()
 {
     filePath    = pathSettings.RootPath + filePath;
     objImporter = gameObject.GetComponent <ObjectImporter>();
     if (objImporter == null)
     {
         objImporter = gameObject.AddComponent <ObjectImporter>();
     }
 }
예제 #10
0
    public override void OnInspectorGUI()
    {
        import = (ObjectImporter)target;
        base.DrawDefaultInspector();

        if (GUILayout.Button("Add a brick", GUILayout.ExpandWidth(true)))
        {
            import.setupObjects();
            import.getObjects();
        }
    }
예제 #11
0
            private void Awake()
            {
                modelID   = PlayerPrefs.GetString("modelID");
                modelLink = PlayerPrefs.GetString("modelLink" + modelID);
                //modelLoad = PlayerPrefs.GetInt("modelLoad");

#if (UNITY_ANDROID || UNITY_IPHONE)
                filePath = modelLink;
#endif
                objImporter = gameObject.AddComponent <ObjectImporter>();
            }
예제 #12
0
    IEnumerator ImportObjFromUrl(string url)
    {
        ObjectImporter objectLoadedImporter = this;
        ImportOptions  options = new ImportOptions();

        options.reuseLoaded   = true;
        options.inheritLayer  = false;
        options.modelScaling  = modelScaling;
        options.localPosition = Vector3.zero;
        Debug.Log("start import model async");
        objectLoadedImporter.ImportModelAsync("model", url, interactionModelParent.transform, options);
        yield return(null);
    }
예제 #13
0
    private void OnValidate()
    {
        if (!isAwakened)
        {
            return;
        }
        if (objImporter == null)
        {
            objImporter = gameObject.AddComponent <ObjectImporter>();
        }
        if (exportButton == null)
        {
            exportButton = GameObject.Find("ExportButton").GetComponent <Button>();
        }
        if (importButton == null)
        {
            importButton = GameObject.Find("ImportButton").GetComponent <Button>();
        }
        if (unitsDropdown == null)
        {
            unitsDropdown = GameObject.Find("UnitsDropdown").GetComponent <Dropdown>();
        }
        if (scaleInputField == null)
        {
            scaleInputField = GameObject.Find("ScaleInputField").GetComponent <InputField>();
        }
        if (rttToggle == null)
        {
            rttToggle = GameObject.Find("ToggleRTT").GetComponent <Toggle>();
        }
        if (zupToggle == null)
        {
            zupToggle = GameObject.Find("ToggleZup").GetComponent <Toggle>();
        }
        if (importInputField == null)
        {
            importInputField = GameObject.Find("ImportInputField").GetComponent <InputField>();
        }
        if (exportInputField == null)
        {
            exportInputField = GameObject.Find("ExportInputField").GetComponent <InputField>();
        }
        if (exportNameOverrideInputField == null)
        {
            exportNameOverrideInputField = GameObject.Find("ExportNameOverrideInputField").GetComponent <InputField>();
        }

        SyncUnitValues();
    }
예제 #14
0
            public async void ImportFromNetworkWebGL(string objURL, string objName, string diffuseTexURL, string bumpTexURL, string specularTexURL, string opacityTexURL, string materialURL, ReferencedNumeric <float> downloadProgress, Action <GameObject> OnSuccess, Action <Exception> OnError, OBJImportOptions importOptions = null)
            {
                if (String.IsNullOrWhiteSpace(objURL))
                {
                    OnError(new InvalidOperationException("Cannot download from empty URL. Please provide a direct URL to the obj file"));
                    return;
                }

                if (String.IsNullOrWhiteSpace(diffuseTexURL))
                {
                    Debug.LogWarning("Cannot download from empty URL. Please provide a direct URL to the accompanying texture file.");
                }

                if (String.IsNullOrWhiteSpace(materialURL))
                {
                    Debug.LogWarning("Cannot download from empty URL. Please provide a direct URL to the accompanying material file.");
                }

                if (downloadProgress == null)
                {
                    OnError(new ArgumentNullException("downloadProgress", "You must pass a reference to the Download Progress object."));
                    return;
                }

                GameObject objectToPopulate = new GameObject();

                objectToPopulate.AddComponent <ObjectImporter>();
                ObjectImporter objImporter = objectToPopulate.GetComponent <ObjectImporter>();


                if (importOptions == null)
                {
                    importOptions = new OBJImportOptions();
                }



                objImporter.ImportModelFromNetworkWebGL(objURL, objName, diffuseTexURL, bumpTexURL, specularTexURL, opacityTexURL, materialURL, downloadProgress, importOptions, (GameObject imported) =>
                {
                    Destroy(objImporter);
                    OnSuccess(imported);
                },
                                                        (exception) =>
                {
                    DestroyImmediate(objectToPopulate);
                    OnError(exception);
                });
            }
예제 #15
0
    private void ImportPlane()
    {
        string filePath = "Assets/Resources/plane/plane.obj";

#if (UNITY_ANDROID || UNITY_IPHONE)
        filePath = Application.persistentDataPath + "/" + filePath;
#endif

        if (!File.Exists(filePath))
        {
            Debug.LogError("Please set FilePath in ObjFromFile.cs to a valid path.");
            return;
        }

        ImportOptions  importOptions = new ImportOptions();
        ObjectImporter objImporter   = gameObject.AddComponent <ObjectImporter> ();
        objImporter.ImportModelAsync("Plane", filePath, null, importOptions);
        objImporter.ImportedModel += this.OnPlaneImported;
    }
예제 #16
0
        public void ImportObject()
        {
            if (_modelViewerOpen)
            {
                return;
            }

            MDL0Node       external = null;
            OpenFileDialog o        = new OpenFileDialog();

            o.Filter = "MDL0 Raw Model (*.mdl0)|*.mdl0";
            o.Title  = "Please select a model to import an object from.";
            if (o.ShowDialog() == DialogResult.OK)
            {
                if ((external = (MDL0Node)NodeFactory.FromFile(null, o.FileName)) != null)
                {
                    ObjectImporter i = new ObjectImporter();
                    i.ShowDialog((MDL0Node)_resource, external);
                }
            }
        }
예제 #17
0
    public void Setup(string name, string filePath, Vector3 rotation, Vector3 position, ref GameObject target, int objectsNumber = 1)
    {
        this.target        = target;
        this.filePath      = filePath;
        this.rotation      = rotation;
        this.name          = name;
        this.position      = position;
        this.objectsNumber = objectsNumber;

        #if (UNITY_ANDROID || UNITY_IPHONE)
        this.filePath = Application.persistentDataPath + "/" + this.filePath;
        #endif

        if (!File.Exists(this.filePath))
        {
            Debug.LogError("Please set FilePath in ObjFromFile.cs to a valid path.");
            return;
        }

        ImportOptions  importOptions = new ImportOptions();
        ObjectImporter objImporter   = gameObject.AddComponent <ObjectImporter> ();
        objImporter.ImportModelAsync(this.name, this.filePath, null, importOptions);
        objImporter.ImportedModel += this.OnModelImported;
    }
예제 #18
0
            private void Awake()
            {
#if (UNITY_ANDROID || UNITY_IPHONE)
                filePath = Application.persistentDataPath + "/" + filePath;
#endif
                objImporter = gameObject.AddComponent <ObjectImporter>();

                if (loadmodel_type == 0)                   //load model from the local path
                {
                    string current_exe_path = System.Environment.CurrentDirectory;
                    Debug.Log("cur = " + current_exe_path);
                    filePath = current_exe_path + "/output/body.obj";

                    if (File.Exists(filePath))
                    {
                        Debug.Log("model exist!");
                    }
                    else
                    {
                        Debug.Log("model not exist!");
                        filePath = "output/body.obj";
                    }
                }
            }
예제 #19
0
 public void TestImport()
 {
     ObjectImporter import = new ObjectImporter();
     //import.objectImport(FileBrowser.FullFilePath);
 }
예제 #20
0
        private void objectProc()
        {
            this.Cursor=Cursors.WaitCursor ;
            this.Enabled=false;
            Application.DoEvents();

            ObjectImporter objImporter=null;
            try
            {
                objImporter=new ObjectImporter( m_fileName,true,"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Application.StartupPath+@"\SharpBase.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False;",true);
                objImporter.loadSession();
                objImporter.updateObjects();
                this.objObj=new ObjectData( objImporter.getObjectData);

            }
            catch(Exception ex)
            {
                this.Cursor=Cursors.Arrow;
                Application.DoEvents() ;
                MessageBox.Show("Session could not be loaded.\n"+ex.Message,"Error!",MessageBoxButtons.OK,MessageBoxIcon.Error);
                this.Title ="Error!";
                try
                {
                    SharpClientForm.scInstance.sharpClientMDITab.TabPages.Remove(this);
                }
                catch{}
            }
            finally
            {
                if(this.Cursor==Cursors.WaitCursor)
                {
                    this.Cursor=Cursors.Arrow;
                    this.Enabled=true;
                    PruneReportTree(false);
                    ReportsNavigation.ExpandAll();
                    Application.DoEvents();

                }
                if(objImporter!=null)
                {
                    this.Title =objImporter.profileeName+":"+ objImporter.profileeSessionName;
                    m_Session=objImporter.profileeSessionName;
                    objImporter.Dispose();
                    objImporter=null;
                }

            }
        }
예제 #21
0
 protected virtual void Awake()
 {
     objectImporter = GetComponent <ObjectImporter>();
 }
예제 #22
0
    void Awake()
    {
        isImporting         = false;
        importedModelsCache = new Dictionary <string, GameObject>();

        objImporter = gameObject.AddComponent <ObjectImporter>();

        // Gets called when the model has been imported
        objImporter.ImportedModel += (importedGameObject, path) => {
            GameObject g;
            try {
                g = importedGameObject.GetComponentInChildren <MeshRenderer>().gameObject;
            } catch (NullReferenceException) {
                g = importedGameObject;
            }

            // Set initial locations and meta data
            Transform t = g.transform;
            t.parent        = spawnLocation.transform;
            t.localPosition = Vector3.zero;
            t.localRotation = Quaternion.identity;
            t.name          = string.Format("({0}) {1}", article.Id.ToString(), article.Name);

            // Scale the object
            float scaleFactor = (float)article.ScaleFactor;
            t.localScale = new Vector3(scaleFactor, scaleFactor, scaleFactor);

            // Remove all other Collider components first, just in case any are loaded
            foreach (Collider c in g.GetComponentsInChildren <Collider>())
            {
                DestroyImmediate(c, true);
            }

            // Add a generic BoxCollider (MeshColliders would be more accurate, but they're really expensive on complex models with lots of faces)
            g.AddComponent <BoxCollider>();

            // Add a Rigidbody, but don't enable gravity yet
            Rigidbody r = g.AddComponent <Rigidbody>();
            r.useGravity  = false;
            r.isKinematic = !r.useGravity;

            // Draw particles
            loadingAnimation.SetActive(false);
            spawnLocation.SetActive(true);

            // Cache the spawned object
            spawnedObject = g;
            GameObject cachedModel = Instantiate(g, transform);
            cachedModel.SetActive(false);
            cachedModel.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);
            importedModelsCache[articleModelPath] = cachedModel;

            // Destroy the container, if unequal
            if (importedGameObject != g)
            {
                Destroy(importedGameObject);
            }

            isImporting = false;
        };
    }
예제 #23
0
            public async Task ImportFromLocalFileSystem(string objPath, string texturesFolderPath, string materialsFolderPath, Action <GameObject> Callback, OBJImportOptions importOptions = null)
            {
                if (Application.platform == RuntimePlatform.WebGLPlayer)
                {
                    Debug.LogWarning("The function cannot run on WebGL player. As web apps cannot read from or write to local file system.");
                    return;
                }

                if (!String.IsNullOrWhiteSpace(objPath))
                {
                    objPath = Path.GetFullPath(objPath);
                    if (objPath[objPath.Length - 1] == '\\')
                    {
                        objPath = objPath.Remove(objPath.Length - 1);
                    }
                    else if (objPath[objPath.Length - 1] == '/')
                    {
                        objPath = objPath.Remove(objPath.Length - 1);
                    }
                }

                if (!String.IsNullOrWhiteSpace(texturesFolderPath))
                {
                    texturesFolderPath = Path.GetFullPath(texturesFolderPath);
                    if (texturesFolderPath[texturesFolderPath.Length - 1] == '\\')
                    {
                        texturesFolderPath = texturesFolderPath.Remove(texturesFolderPath.Length - 1);
                    }
                    else if (texturesFolderPath[texturesFolderPath.Length - 1] == '/')
                    {
                        texturesFolderPath = texturesFolderPath.Remove(texturesFolderPath.Length - 1);
                    }
                }

                if (!String.IsNullOrWhiteSpace(materialsFolderPath))
                {
                    materialsFolderPath = Path.GetFullPath(materialsFolderPath);
                    if (materialsFolderPath[materialsFolderPath.Length - 1] == '\\')
                    {
                        materialsFolderPath = materialsFolderPath.Remove(materialsFolderPath.Length - 1);
                    }
                    else if (materialsFolderPath[materialsFolderPath.Length - 1] == '/')
                    {
                        materialsFolderPath = materialsFolderPath.Remove(materialsFolderPath.Length - 1);
                    }
                }


                if (!System.IO.File.Exists(objPath))
                {
                    throw new FileNotFoundException("The path provided doesn't point to a file. The path might be invalid or the file is non-existant.");
                }

                if (!string.IsNullOrWhiteSpace(texturesFolderPath) && !System.IO.Directory.Exists(texturesFolderPath))
                {
                    Debug.LogWarning("The directory pointed to by the given path for textures is non-existant.");
                }

                if (!string.IsNullOrWhiteSpace(materialsFolderPath) && !System.IO.Directory.Exists(materialsFolderPath))
                {
                    Debug.LogWarning("The directory pointed to by the given path for materials is non-existant.");
                }


                string fileNameWithExt = System.IO.Path.GetFileName(objPath);
                string dirPath         = System.IO.Path.GetDirectoryName(objPath);
                string objName         = fileNameWithExt.Split('.')[0];

#pragma warning disable
                bool didFail = false;

                GameObject objectToPopulate = new GameObject();
                objectToPopulate.AddComponent <ObjectImporter>();
                ObjectImporter objImporter = objectToPopulate.GetComponent <ObjectImporter>();

                if (dirPath.Contains("/") && !dirPath.EndsWith("/"))
                {
                    dirPath += "/";
                }
                else if (!dirPath.EndsWith("\\"))
                {
                    dirPath += "\\";
                }

                var split = fileNameWithExt.Split('.');


                if (split[1].ToLower() != "obj")
                {
                    DestroyImmediate(objectToPopulate);
                    throw new System.InvalidOperationException("The path provided must point to a wavefront obj file.");
                }


                if (importOptions == null)
                {
                    importOptions = new OBJImportOptions();
                }


                try
                {
                    GameObject toReturn = await objImporter.ImportModelAsync(objName, objPath, null, importOptions, texturesFolderPath, materialsFolderPath);

                    Destroy(objImporter);
                    Callback(toReturn);
                }

                catch (Exception ex)
                {
                    DestroyImmediate(objectToPopulate);
                    throw ex;
                }
            }