-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from darwin-education/groundprimitive
Add GroundPrimitive and GroundPrimitiveCollection
- Loading branch information
Showing
5 changed files
with
184 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import Cesium from "cesium"; | ||
|
||
import createCesiumComponent from "./core/CesiumComponent"; | ||
import EventManager, { EventProps } from "./core/EventManager"; | ||
|
||
/* | ||
@summary | ||
`GroundPrimitive` is a ground primitive in the `PrimitiveCollection`. | ||
Primitive is a low layer API for geographical visualization. | ||
[Entity](/components/entity) is more recommended unless performance issues. | ||
*/ | ||
|
||
/* | ||
@scope | ||
Inside [Viewer](/components/Viewer), [CesiumWidget](/components/CesiumWidget), or [GroundPrimitiveCollection](/components/GroundPrimitiveCollection) component. | ||
If this component is inside GroundPrimitiveCollection component, a ground primitive object will be attached to the ground primitive collection of the scene. | ||
Otherwise, a primitive object will be attached to the PrimitiveCollection of the Viewer or CesiumWidget. | ||
*/ | ||
|
||
export interface GroundPrimitiveCesiumProps { | ||
appearance?: Cesium.Appearance; | ||
debugShowBoundingVolume?: boolean; | ||
debugShowShadowVolume?: boolean; | ||
classificationType?: any; // Cesium.ClassificationType | ||
depthFailAppearance?: Cesium.Appearance; | ||
show?: boolean; | ||
} | ||
|
||
export interface GroundPrimitiveCesiumReadonlyProps { | ||
allowPicking?: boolean; | ||
asynchronous?: boolean; | ||
compressVertices?: boolean; | ||
geometryInstances?: Cesium.GeometryInstance[] | Cesium.GeometryInstance; | ||
interleave?: boolean; | ||
releaseGeometryInstances?: boolean; | ||
vertexCacheOptimize?: boolean; | ||
} | ||
|
||
export interface GroundPrimitiveProps | ||
extends GroundPrimitiveCesiumProps, | ||
GroundPrimitiveCesiumReadonlyProps, | ||
EventProps<any> { | ||
// Cesium.GroundPrimitive | ||
// Calls when [Primitive#readyPromise](https://cesiumjs.org/Cesium/Build/Documentation/GroundPrimitive.html#readyPromise) is fullfilled | ||
onReady?: (primitive: any /* Cesium.GroundPrimitive */) => void; | ||
} | ||
|
||
export interface GroundPrimitiveContext { | ||
primitiveCollection?: Cesium.PrimitiveCollection; | ||
__RESIUM_EVENT_MANAGER?: EventManager; | ||
} | ||
|
||
const cesiumProps: (keyof GroundPrimitiveCesiumProps)[] = [ | ||
"appearance", | ||
"classificationType", | ||
"debugShowBoundingVolume", | ||
"debugShowShadowVolume", | ||
"depthFailAppearance", | ||
"show", | ||
]; | ||
|
||
const cesiumReadonlyProps: (keyof GroundPrimitiveCesiumReadonlyProps)[] = [ | ||
"allowPicking", | ||
"asynchronous", | ||
"compressVertices", | ||
"geometryInstances", | ||
"interleave", | ||
"releaseGeometryInstances", | ||
"vertexCacheOptimize", | ||
]; | ||
|
||
const GroundPrimitive = createCesiumComponent< | ||
any /* Cesium.GroundPrimitive */, | ||
GroundPrimitiveProps, | ||
GroundPrimitiveContext | ||
>({ | ||
name: "GroundPrimitive", | ||
create(cprops, props) { | ||
const primitive = new (Cesium as any).GroundPrimitive(cprops); | ||
if (props.onReady) { | ||
primitive.readyPromise.then(props.onReady); | ||
} | ||
return primitive; | ||
}, | ||
mount(element, context, props) { | ||
if (context.__RESIUM_EVENT_MANAGER) { | ||
context.__RESIUM_EVENT_MANAGER.setEvents(element, props); | ||
} | ||
if (context.primitiveCollection) { | ||
context.primitiveCollection.add(element); | ||
} | ||
}, | ||
update(element, props, prevProps, context) { | ||
if (context.__RESIUM_EVENT_MANAGER) { | ||
context.__RESIUM_EVENT_MANAGER.setEvents(element, props); | ||
} | ||
}, | ||
unmount(element, context) { | ||
if (context.__RESIUM_EVENT_MANAGER) { | ||
context.__RESIUM_EVENT_MANAGER.clearEvents(element); | ||
} | ||
if (context.primitiveCollection && !context.primitiveCollection.isDestroyed()) { | ||
context.primitiveCollection.remove(element); | ||
} | ||
if (!element.isDestroyed()) { | ||
element.destroy(); | ||
} | ||
}, | ||
cesiumProps, | ||
cesiumReadonlyProps, | ||
}); | ||
|
||
export default GroundPrimitive; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Cesium from "cesium"; | ||
|
||
import createCesiumComponent from "./core/CesiumComponent"; | ||
|
||
// @cesiumElement PrimitiveCollection | ||
|
||
/* | ||
@summary | ||
`GroundPrimitiveCollection` is the collection of ground primitives of the scene. | ||
All properties are applied to single ground primitives collection of the scene. | ||
It can have some GroundPrimitive components as children. | ||
*/ | ||
|
||
/* | ||
@scope | ||
Inside [Viewer](/components/Viewer) or [CesiumWidget](/components/CesiumWidget) components. | ||
*/ | ||
|
||
export interface GroundPrimitiveCollectionCesiumProps { | ||
show?: boolean; | ||
} | ||
|
||
export interface GroundPrimitiveCollectionProps extends GroundPrimitiveCollectionCesiumProps { | ||
children?: React.ReactNode; | ||
} | ||
|
||
export interface GroundPrimitiveCollectionContext { | ||
scene: Cesium.Scene; | ||
} | ||
|
||
const cesiumProps: (keyof GroundPrimitiveCollectionCesiumProps)[] = ["show"]; | ||
|
||
const GroundPrimitiveCollection = createCesiumComponent< | ||
Cesium.PrimitiveCollection, | ||
GroundPrimitiveCollectionProps, | ||
GroundPrimitiveCollectionContext | ||
>({ | ||
name: "GroundPrimitiveCollection", | ||
create(cprops, props, context) { | ||
return context.scene.groundPrimitives; | ||
}, | ||
provide(element) { | ||
return { | ||
primitiveCollection: element, | ||
}; | ||
}, | ||
cesiumProps, | ||
setCesiumPropsAfterCreate: true, | ||
}); | ||
|
||
export default GroundPrimitiveCollection; |