Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
keiya01 committed Oct 3, 2023
1 parent e8356f1 commit 46312da
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/Model/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ export const otherProps = ["onReady", "onError", "url"] as const;
const Model = createCesiumComponent<CesiumModel, ModelProps>({
name: "Model",
async create(context, { scene, url, colorBlendMode, ...props }) {
const state = {
readyEventListener: (model: CesiumModel) => {
props.onReady?.(model)
}
}

if (!context.scene || !context.primitiveCollection || !url) return;
const maybePromiseURL = url;

Expand All @@ -104,37 +98,34 @@ const Model = createCesiumComponent<CesiumModel, ModelProps>({
resultURL = maybePromiseURL as typeof resultURL;
}


let element;


try {
element = await CesiumModel.fromGltfAsync({
...props,
url: resultURL,
colorBlendMode: colorBlendMode as ColorBlendMode,
scene: scene || context.scene,
});
element.readyEvent.addEventListener(state.readyEventListener)
} catch (e) {
props.onError?.(e);
return;
}

context.primitiveCollection.add(element);
return [element, state];
return element;
},
destroy(element, context, _, state) {
if (state.readyEventListener) {
element.readyEvent.removeEventListener(state.readyEventListener)
}
destroy(element, context, _) {
if (context.primitiveCollection && !context.primitiveCollection.isDestroyed()) {
context.primitiveCollection.remove(element);
}
if (!element.isDestroyed()) {
element.destroy();
}
},
cesiumEventProps: {
onReady: "readyEvent",
},
cesiumProps,
cesiumReadonlyProps,
otherProps,
Expand Down

0 comments on commit 46312da

Please sign in to comment.