Skip to content

Commit

Permalink
feat(editor): fix import event, load glb: if cancel, should return to…
Browse files Browse the repository at this point in the history
… page
  • Loading branch information
yyc-git committed Oct 27, 2023
1 parent 5d92c6a commit 745d186
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion contributes/meta3d-action-import-event/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meta3d-action-import-event",
"version": "0.18.0",
"version": "0.18.1",
"publisher": "0xf63e1991A343814EdE505D7cfC368615EAe75307",
"displayName": "meta3d-action-import-event",
"repoLink": "",
Expand Down
8 changes: 5 additions & 3 deletions contributes/meta3d-action-import-event/src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export let getContribute: getContributeMeta3D<actionContribute<clickUIData, stat
return new Promise<meta3dState>((resolve, reject) => {
let eventSourcingService = api.getExtensionService<eventSourcingService>(meta3dState, "meta3d-event-sourcing-protocol")

importFile((file:any, result:any) => {
importFile((file: any, result: any) => {
if (!file.name.includes(".arraybuffer")) {
reject(new Error("文件后缀名应该是.arraybuffer"))
}
Expand All @@ -74,11 +74,13 @@ export let getContribute: getContributeMeta3D<actionContribute<clickUIData, stat
name: eventName,
inputData: [result as ArrayBuffer]
}))
}, (event:Event, file:any) => {
}, (event: Event, file: any) => {
reject(new Error(`读取${file.name}错误`))
}, (loaded:number, total:number) => {
}, (loaded: number, total: number) => {
// TODO show progress message
console.log(`loading ${loaded / total} %`)
}, () => {
resolve(meta3dState)
})
})
},
Expand Down
2 changes: 1 addition & 1 deletion contributes/meta3d-action-load-glb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meta3d-action-load-glb",
"version": "0.18.1",
"version": "0.18.2",
"publisher": "0xf63e1991A343814EdE505D7cfC368615EAe75307",
"repoLink": "",
"protocol": {
Expand Down
2 changes: 2 additions & 0 deletions contributes/meta3d-action-load-glb/src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export let getContribute: getContributeMeta3D<actionContribute<loadGlbUIData, st
}, (loaded: number, total: number) => {
// TODO show progress message
console.log(`loading ${loaded / total} %`)
}, () => {
resolve(meta3dState)
})
})
},
Expand Down
2 changes: 1 addition & 1 deletion doc/0.19.0.org
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ set event



* TODO fix: import event, load glb: if not import, should return to page instead of empty
* DONE fix: import event, load glb: if not import, should return to page instead of empty



Expand Down
10 changes: 9 additions & 1 deletion utils/meta3d-file-ts-utils/src/ImportFileUtils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
export let importFile = (onloadFunc:any, onerrorFunc:any, onprogressFunc:any) => {
export let importFile = (onloadFunc: any, onerrorFunc: any, onprogressFunc: any, oncancelFunc: any) => {
let input = document.createElement('input')
input.setAttribute('type', "file")
input.style.visibility = 'hidden'

input.onchange = (event) => {
if ((event.target as any).files.length == 0) {
oncancelFunc()
}

let file = (event.target as any).files[0]

let reader = new FileReader()
Expand All @@ -23,6 +27,10 @@ export let importFile = (onloadFunc:any, onerrorFunc:any, onprogressFunc:any) =>
reader.readAsArrayBuffer(file)
}

input.oncancel = (event) => {
oncancelFunc()
}

document.body.appendChild(input)
input.click()
document.body.removeChild(input)
Expand Down

0 comments on commit 745d186

Please sign in to comment.