public IEnumerator ImportModel()
    {
        PiXYZImportSettings settings = target as PiXYZImportSettings;

        GameObject gameObject = settings.gameObject;    //Find the gameobject the script is attached to

        Vector3 eulerAngles = new Vector3() + gameObject.transform.rotation.eulerAngles;
        Vector3 scale       = new Vector3() + gameObject.transform.lossyScale;

        if (gameObject.transform.childCount > 0)
        {
            foreach (Transform child in gameObject.transform)
            {
                DestroyImmediate(child.gameObject);
            }
        }

        UnityEngine.Object prefab;
        prefab = PrefabUtility.CreateEmptyPrefab("Assets/3DModels/" + settings.settings.prefabName + ".prefab");

        loader = new PiXYZ4UnityLoader();

        loader.setSourceCoordinatesSystem(settings.settings.isRightHanded, settings.settings.isZUp, settings.settings.scaleFactor);
        double mapUV3dSize = settings.settings.mapUV ? settings.settings.mapUV3dSize : -1;

        loader.configure(settings.settings.orient, mapUV3dSize, settings.settings.treeProcess, settings.settings.useLods ? settings.settings.lodsMode : LODsMode.NONE, settings.settings.lodSettings, !settings.settings.splitTo16BytesIndex, settings.settings.useMergeFinalAssemblies);

        CoroutineNode coco = coroutineScheduler.StartCoroutine(loader.loadFileRuntime(gameObject, settings.settings.originalFilename, true, prefab));

        yield return(coco);

        PiXYZUtils.clearProgressBar();
        if (loader.getErrorMessage().Length > 0)
        {
            Debug.LogError("PiXYZAssetImporter: loader.loadfile failed");
        }
        else
        {
            Debug.Log("Success");
        }

#if UNITY_EDITOR
        foreach (UnityEngine.Object obj in loader.loadedObject)
        {
            AssetDatabase.AddObjectToAsset(obj, prefab);
        }
#endif

        gameObject.transform.Rotate(-gameObject.transform.rotation.eulerAngles);
        gameObject.transform.Rotate(eulerAngles);
        gameObject.transform.localScale = scale;
        PrefabUtility.ReplacePrefab(gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab);
        loader = null;
    }
Ejemplo n.º 2
0
 public void OnCancelClicked()
 {
     if (coroutineScheduler != null)
     {
         coroutineScheduler.StopAllCoroutines();
     }
     if (loader != null)
     {
         PiXYZUtils.clearProgressBar();
     }
     this.Close();
 }
Ejemplo n.º 3
0
 public void OnImportFinished()
 {
     PiXYZUtils.clearProgressBar();
     //Display success PopUp
     if (loader.getErrorMessage().Length > 0)
     {
         EditorUtility.DisplayDialog("PiXYZImporter", "File import failed.\n\nReasons : " + loader.getErrorMessage(), "ok");
     }
     else
     {
         EditorUtility.DisplayDialog("PiXYZImporter", "File successfully imported in Scene.\nPrefab created in Assets/3DModels.", "ok");
     }
     loader    = null;
     frameSkip = 0;
     //window.Close();
     DestroyImmediate(this);
     importing       = false;
     isFileNameValid = false;
 }