usePrimitiveScope
Scope PrimitiveCollection mutations so created primitives are removed automatically when the component unmounts.
WARNING
This is a low-level helper used by usePrimitive. Prefer usePrimitive unless you need custom collection management.
Usage
ts
import { Primitive, PrimitiveCollection } from 'cesium';
import { usePrimitiveScope } from 'vesium';
const { add, remove } = usePrimitiveScope({
collection: 'ground',
});
const primitive = add(new Primitive({
geometryInstances: [],
}));
// Async creation is also supported.
add(Promise.resolve(new Primitive({
geometryInstances: [],
})));Notes
- The target collection defaults to
useViewer().value.scene.primitives. - Pass
collection: 'ground'to useviewer.value.scene.groundPrimitives. addaccepts promises and adds the resolved primitive to the collection.
Type Definitions
typescript
import type { GroundPrimitive, Primitive, PrimitiveCollection } from 'cesium';
import type { MaybeRefOrGetter } from 'vue';
export interface UsePrimitiveScopeOptions {
/**
* The collection of Primitive to be added,
* 'ground' alias `useViewer().value.scene.groundPrimitives`
* @default useViewer().value.scene.primitives
*/
collection?: MaybeRefOrGetter<PrimitiveCollection | 'ground' | undefined>;
/**
* Whether to destroy the primitive when removed from the collection.
* When true, the primitive's GPU resources will be released.
* @default true
*/
destroyOnRemove?: boolean;
}
/**
* Make `add` and `remove` operations of `PrimitiveCollection` scoped,
* automatically remove `Primitive` instance when component is unmounted.
*/
export declare function usePrimitiveScope(options?: UsePrimitiveScopeOptions): {
scope: Readonly<import("vue").ShallowReactive<Set<Primitive | GroundPrimitive>>>;
add: <R extends Primitive | GroundPrimitive | Promise<Primitive | GroundPrimitive>>(instance: R, ...args: any[]) => R extends Promise<infer U> ? Promise<U> : Primitive | GroundPrimitive;
remove: (instance: Primitive | GroundPrimitive) => any;
removeWhere: (predicate: import("..").EffcetRemovePredicate<Primitive | GroundPrimitive>) => void;
removeScope: () => void;
};
//# sourceMappingURL=index.d.ts.map