From 46312da20f1b1c3a7ab6ab3912944ec659dfa15a Mon Sep 17 00:00:00 2001 From: keiya01 Date: Tue, 3 Oct 2023 11:47:47 +0900 Subject: [PATCH] fix --- src/Model/Model.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/Model/Model.ts b/src/Model/Model.ts index 6e281893a..28437044f 100644 --- a/src/Model/Model.ts +++ b/src/Model/Model.ts @@ -84,12 +84,6 @@ export const otherProps = ["onReady", "onError", "url"] as const; const Model = createCesiumComponent({ 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; @@ -104,10 +98,8 @@ const Model = createCesiumComponent({ resultURL = maybePromiseURL as typeof resultURL; } - let element; - try { element = await CesiumModel.fromGltfAsync({ ...props, @@ -115,19 +107,15 @@ const Model = createCesiumComponent({ 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); } @@ -135,6 +123,9 @@ const Model = createCesiumComponent({ element.destroy(); } }, + cesiumEventProps: { + onReady: "readyEvent", + }, cesiumProps, cesiumReadonlyProps, otherProps,