/// <summary> /// Create a prefab from the imported hierarchy of game objects. /// This is the final output of an Editor glTF import. /// </summary> protected IEnumerator <GameObject> CreatePrefabEnum() { string basename = "scene.prefab"; if (!String.IsNullOrEmpty(_imported.Scene.name)) { basename = String.Format("{0}.prefab", GLTFUtils.cleanName(_imported.Scene.name)); } string dir = UnityPathUtil.GetProjectPath(_importPath); string path = Path.Combine(dir, basename); GameObject prefab = PrefabUtility.SaveAsPrefabAsset(_imported.Scene, path); // Make the prefab visible. // // Note: The model hierarchy is kept hidden during the glTF import // so that the user never sees the partially reconstructed // model. prefab.SetActive(true); // Note: base.Clear() removes imported game objects from // the scene and from memory, but does not remove imported // asset files from disk. base.Clear(); yield return(prefab); }
// File serialization public Mesh saveMesh(Mesh mesh, string objectName = "Scene") { string baseName = GLTFUtils.cleanName(objectName + ".asset"); string fullPath = Path.Combine(_importMeshesDirectory, baseName); string meshProjectPath = GLTFUtils.getPathProjectFromAbsolute(fullPath); serializeAsset(mesh, meshProjectPath, fullPath, true); return(AssetDatabase.LoadAssetAtPath(meshProjectPath, typeof(Mesh)) as Mesh); }
public Texture2D saveTexture(Texture2D texture, int index = -1, string imageName = "") { string basename = GLTFUtils.cleanName(texture.name + (index >= 0 ? "_" + index.ToString() : "") + ".png"); // Extension will be overridden string fullPath = Path.Combine(_importTexturesDirectory, basename); // Write texture string newAssetPath = GLTFTextureUtils.writeTextureOnDisk(texture, fullPath, true); // Reload as asset string projectPath = GLTFUtils.getPathProjectFromAbsolute(newAssetPath); Texture2D tex = (Texture2D)AssetDatabase.LoadAssetAtPath(projectPath, typeof(Texture2D)); _parsedImages.Add(tex); return(tex); }
public void displayModelPage(SketchfabModel model, SketchfabBrowser browser) { _window = browser; if (_currentModel == null || model.uid != _currentModel.uid) { _currentModel = model; _prefabName = GLTFUtils.cleanName(_currentModel.name).Replace(" ", "_"); _importDirectory = Application.dataPath + "/Import/" + _prefabName.Replace(" ", "_"); } else { _currentModel = model; } _ui = SketchfabPlugin.getUI(); show = true; }
/// <summary> /// Create a prefab from the imported hierarchy of game objects. /// This is the final output of an Editor glTF import. /// </summary> protected IEnumerator <GameObject> CreatePrefabEnum() { string basename = "scene.prefab"; if (!String.IsNullOrEmpty(_imported.Scene.name)) { basename = String.Format("{0}.prefab", GLTFUtils.cleanName(_imported.Scene.name)); } string dir = UnityPathUtil.GetProjectPath(_importPath); string path = Path.Combine(dir, basename); GameObject prefab = PrefabUtility.SaveAsPrefabAsset(_imported.Scene, path); // Note: base.Clear() removes imported game objects from // the scene and from memory, but does not remove imported // asset files from disk. base.Clear(); yield return(prefab); }
private GameObject createGameObject(string name) { name = GLTFUtils.cleanName(name); return(_assetManager.createGameObject(name)); }
public string getPrefabName(string sceneObjectName) { return(GLTFUtils.cleanName(sceneObjectName.Length > 0 ? sceneObjectName : "GlTF")); }
public string generateName(string name, int index) { return(GLTFUtils.cleanName(name + "_" + index).Replace(":", "_")); }