Skip to content

Commit

Permalink
fix(editor): fix "load glb->cancel" error
Browse files Browse the repository at this point in the history
solution
fix meta3d-action-add-asset -> loadGlb
  • Loading branch information
yyc-git committed Feb 28, 2024
1 parent 0ca14cd commit 41033a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 11 additions & 7 deletions contributes/meta3d-action-add-asset/src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ let _loadImages = (meta3dState: meta3dState, api: api) => {
})
}

let _loadGlb = (meta3dState: meta3dState, api: api): Promise<[nullable<glbName>, nullable<glbData>]> => {
let _loadGlb = (api: api): Promise<[boolean, nullable<glbName>, nullable<glbData>]> => {
return new Promise((resolve, reject) => {
importFile((file: any, result: any) => {
if (!file.name.includes(".glb")) {
reject(new Error("文件后缀名应该是.glb"))
}

resolve([api.nullable.return(file.name.slice(0, -4)), api.nullable.return(result as ArrayBuffer)])
resolve([true, api.nullable.return(file.name.slice(0, -4)), api.nullable.return(result as ArrayBuffer)])
}, (event: Event, file: any) => {
reject(new Error(`读取${file.name}错误`))
}, (loaded: number, total: number) => {
// TODO show progress message
console.log(`loading ${loaded / total} %`)
}, () => {
resolve(meta3dState)
resolve([false, api.nullable.getEmpty(), api.nullable.getEmpty()])
})
})
}
Expand Down Expand Up @@ -152,15 +152,19 @@ export let getContribute: getContributeMeta3D<actionContribute<uiData, state>> =

let selectedIndex = uiData

let promise: Promise<[nullable<glbName>, nullable<glbData>]>
let promise: Promise<[boolean, nullable<glbName>, nullable<glbData>]>
if (_getAssetType(selectedIndex) == assetType.Glb) {
promise = _loadGlb(meta3dState, api)
promise = _loadGlb(api)
}
else {
promise = Promise.resolve([api.nullable.getEmpty(), api.nullable.getEmpty()])
promise = Promise.resolve([true, api.nullable.getEmpty(), api.nullable.getEmpty()])
}

return promise.then(([glbName, glbData]) => {
return promise.then(([isSuccess, glbName, glbData]) => {
if (!isSuccess) {
return meta3dState
}

return eventSourcingService.addEvent<inputData>(meta3dState, {
name: eventName,
inputData: [
Expand Down
4 changes: 3 additions & 1 deletion doc/1.3.1.org
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if action not implement restore, not;
not restore ui control state


* TODO fix(editor): load glb->cancel error
* DONE fix(editor): load glb->cancel error

* TODO fix(editor): shouldn't export when run

Expand All @@ -58,6 +58,8 @@ not restore ui control state
TODO need update
ui

add-asset


TODO update production code

Expand Down

0 comments on commit 41033a2

Please sign in to comment.