diff --git a/app/pages/PageEnigma/comps/ControlsTopButtons/ControlsTopButtons.tsx b/app/pages/PageEnigma/comps/ControlsTopButtons/ControlsTopButtons.tsx index 73196bc6c5..1aaf710623 100644 --- a/app/pages/PageEnigma/comps/ControlsTopButtons/ControlsTopButtons.tsx +++ b/app/pages/PageEnigma/comps/ControlsTopButtons/ControlsTopButtons.tsx @@ -10,6 +10,7 @@ export const ControlsTopButtons = () => { const handleButtonSave = () => { console.log(`SceneName is ${sceneName}`); // editorEngine?.save(); + }; const handleButtonCameraView = () => { diff --git a/app/pages/PageEnigma/js/api_manager.ts b/app/pages/PageEnigma/js/api_manager.ts index ec240ae0ff..8167bcd0e4 100644 --- a/app/pages/PageEnigma/js/api_manager.ts +++ b/app/pages/PageEnigma/js/api_manager.ts @@ -22,20 +22,21 @@ class APIManager { async saveSceneState( scene: THREE.Scene, timeline: TimelineCurrentReactState, - media_file_token: string | null = null, + scene_name: string, + scene_media_file_token: string | null = null, ): Promise { - // create new scene. + // create new scene + let file = await this.gltfExport(scene); let response = await this.uploadGLB(file); let success = response["success"]; if (success) { - let media_file_token = response["media_file_token"]; - - console.log(`media file token: ${media_file_token}`) - - const result = await this._saveSceneAndTimelineToJSONSpec(media_file_token, timeline); - return result - } + let media_file_token = response["media_file_token"]; + console.log(`media file token: ${media_file_token}`) + const result = await this._saveSceneAndTimelineToJSONSpec(media_file_token,scene_name, timeline); + return result + } + throw Error("Saving the Scene Resulted in an Error Success False"); } @@ -47,16 +48,18 @@ class APIManager { // media_file_token (optional; the file to replace if present) async _saveSceneAndTimelineToJSONSpec( media_file_token: string, + scene_file_name: string, timeline: TimelineCurrentReactState, ): Promise { const url = `${this.baseUrl}/v1/media_files/write/scene_file`; let uuid = uuidv4(); // turn json into a blob - const file_test = {"glb_media_file_id":media_file_token,"entities":[], "timeline":""} + const file_test = {"glb_media_file_id":media_file_token,"name":scene_file_name,"entities":[], "timeline":""} + const json = JSON.stringify(file_test); const blob = new Blob([json], {type: 'application/json'}); - const fileName = `${uuid}.json`; + const fileName = `${uuid}-${scene_file_name}.json`; const formData = new FormData(); @@ -176,11 +179,17 @@ class APIManager { media_file_subtype (optional; mixamo, mocap_net, scene_import, animation_only) media_file_class (audio, image, video, animation, character, prop, scene, unknown) **/ - async uploadGLB(file: File): Promise { + async uploadGLB(file: File, scene_media_file_token:string | null): Promise { const url = `${this.baseUrl}/v1/media_files/write/engine_asset`; let uuid = uuidv4(); const formData = new FormData(); formData.append("uuid_idempotency_token", uuid); + + // update existing scene otherwise create new scene and use it's media_file_id + if (scene_media_file_token != null) { + formData.append("media_file_token", scene_media_file_token); + } + formData.append("file", file); formData.append("source", "file"); formData.append("media_file_subtype", "scene_import"); diff --git a/app/pages/PageEnigma/js/editor.js b/app/pages/PageEnigma/js/editor.js index c918f68052..8cc07f9c87 100644 --- a/app/pages/PageEnigma/js/editor.js +++ b/app/pages/PageEnigma/js/editor.js @@ -169,6 +169,18 @@ class Editor { this.timeline.scene = this.activeScene; this._test_demo() + + + // saving state of the scene + this.scene_file_token = null + } + + + async saveScene(name) { + // check if I already have the scene token. + console.log("Saving..."); + const result = await this.api_manager.saveSceneState(this.activeScene.scene,this.scene_file_token); + console.log("Saved!"); } // uploading some objects for testing to get their media ids from my account. @@ -281,7 +293,7 @@ class Editor { ); // then it creates clip ui to load the playable clips // then refreshes the timeline. - + // create the clip with the same id for a reference to the media this.timeline.addPlayableClip( new ClipUI(