Skip to content

Commit

Permalink
refactor(components): ♻️ improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyaoji committed Sep 16, 2023
1 parent 02bb9dc commit 4acd03f
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 5 deletions.
84 changes: 82 additions & 2 deletions packages/components/primitives/tileset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
VcCartesian2,
VcComponentInternalInstance,
VcComponentPublicInstance,
VcImageBasedLighting,
VcPickEvent,
VcPosition,
VcReadyObject
Expand All @@ -26,7 +27,9 @@ import {
debugWireframe,
debugShowBoundingVolume,
customShader,
enableMouseEvent
enableMouseEvent,
imageBasedLighting,
outlineColor
} from '@vue-cesium/utils/cesium-props'
import { kebabCase } from '@vue-cesium/utils/util'
import { primitiveEmits } from '@vue-cesium/utils/emits'
Expand All @@ -45,11 +48,28 @@ export const tilesetPrimitiveProps = {
url: [String, Object] as PropType<string | Promise<string> | Promise<Cesium.Resource> | Cesium.Resource>,
...show,
...modelMatrix,
modelUpAxis: {
type: Number,
// default: 1 // Cesium.Axis.Y
},
modelForwardAxis: {
type: Number,
// default: 0 // Cesium.Axis.X
},
...shadows,
...maximumScreenSpaceError,
// Deprecated
maximumMemoryUsage: {
type: Number,
default: 512
// default: 512
},
cacheBytes: {
type: Number,
default: 536870912
},
maximumCacheOverflowBytes: {
type: Number,
default: 536870912
},
cullWithChildrenBounds: {
type: Boolean,
Expand Down Expand Up @@ -145,11 +165,17 @@ export const tilesetPrimitiveProps = {
...luminanceAtZenith,
...sphericalHarmonicCoefficients,
...specularEnvironmentMaps,
...imageBasedLighting,
...backFaceCulling,
enableShowOutline: {
type: Boolean,
default: true
},
showOutline: {
type: Boolean,
default: true
},
...outlineColor,
vectorClassificationOnly: {
type: Boolean,
default: false
Expand All @@ -166,6 +192,20 @@ export const tilesetPrimitiveProps = {
type: Number,
default: 0
},
featureIdLabel: {
type: [String, Number]
},
instanceFeatureIdLabel: {
type: [String, Number]
},
splitDirection: {
type: Number as PropType<Cesium.SplitDirection>,
default: 0 //Cesium.SplitDirection.NONE
},
projectTo2D: {
type: Boolean,
default: false
},
showCreditsOnScreen: {
type: Boolean,
default: false
Expand Down Expand Up @@ -294,6 +334,14 @@ export type VcPrimitiveTilesetProps = {
* A 4x4 transformation matrix that transforms the tileset's root tile.
*/
modelMatrix?: Cesium.Matrix4
/**
* Which axis is considered up when loading models for tile contents.
*/
modelUpAxis?: number | Cesium.Axis.Y
/**
* Which axis is considered forward when loading models for tile contents.
*/
modelForwardAxis?: number | Cesium.Axis.X
/**
* Determines whether the tileset casts or receives shadows from light sources.
*/
Expand All @@ -308,6 +356,14 @@ export type VcPrimitiveTilesetProps = {
* Default value: 512
*/
maximumMemoryUsage?: number
/**
* The size (in bytes) to which the tile cache will be trimmed, if the cache contains tiles not needed for the current view.
*/
cacheBytes?: number
/**
* The maximum additional memory (in bytes) to allow for cache headroom, if more than Cesium3DTileset#cacheBytes are needed for the current view.
*/
maximumCacheOverflowBytes?: number
/**
* Optimization option. Whether to cull tiles using the union of their children bounding volumes.
* Default value: true
Expand Down Expand Up @@ -458,11 +514,19 @@ export type VcPrimitiveTilesetProps = {
* A URL to a KTX2 file that contains a cube map of the specular lighting and the convoluted specular mipmaps.
*/
specularEnvironmentMaps?: string
/**
* The properties for managing image-based lighting for this tileset.
*/
imageBasedLighting?: VcImageBasedLighting
/**
* Whether to cull back-facing geometry. When true, back face culling is determined by the glTF material's doubleSided property; when false, back face culling is disabled.
* Default value: true
*/
backFaceCulling?: boolean
/**
* Whether to enable outlines for models using the CESIUM_primitive_outline extension. This can be set to false to avoid the additional processing of geometry at load time. When false, the showOutlines and outlineColor options are ignored.
*/
enableShowOutline?: boolean
/**
* Whether to display the outline for models using the CESIUM_primitive_outline extension. When true, outlines are displayed. When false, outlines are not displayed.
* Default value: true
Expand All @@ -488,6 +552,22 @@ export type VcPrimitiveTilesetProps = {
* Default value: 0
*/
instanceFeatureIdIndex?: number
/**
* Label of the feature ID set to use for picking and styling. For EXT_mesh_features, this is the feature ID's label property, or "featureId_N" (where N is the index in the featureIds array) when not specified. EXT_feature_metadata did not have a label field, so such feature ID sets are always labeled "featureId_N" where N is the index in the list of all feature Ids, where feature ID attributes are listed before feature ID textures. If featureIdLabel is an integer N, it is converted to the string "featureId_N" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.
*/
featureIdLabel?: number | string
/**
* Label of the instance feature ID set used for picking and styling. If instanceFeatureIdLabel is set to an integer N, it is converted to the string "instanceFeatureId_N" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.
*/
instanceFeatureIdLabel?: number | string
/**
* The SplitDirection split to apply to this tileset.
*/
splitDirection?: number | Cesium.SplitDirection
/**
* Whether to accurately project the tileset to 2D. If this is true, the tileset will be projected accurately to 2D, but it will use more memory to do so. If this is false, the tileset will use less memory and will still render in 2D / CV mode, but its projected positions may be inaccurate. This cannot be set after the tileset has loaded.
*/
projectTo2D?: boolean
/**
* Whether to display the credits of this tileset on screen.
* Default value: false
Expand Down
31 changes: 30 additions & 1 deletion packages/utils/cesium-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import type {
VcHeadingPitchRoll,
VcHeadingPitchRange,
VcPlane,
CesiumPlane
CesiumPlane,
VcImageBasedLighting
} from './types'
import { compare, CompareOperator } from 'compare-versions'
import { hasOwn, isFunction, isArray, isString, isPlainObject, isEmptyObj, getObjClassName, isUndefined } from './util'
Expand Down Expand Up @@ -1094,3 +1095,31 @@ export function heightToLevel(altitude: number) {
export function compareCesiumVersion(a, b, operator: CompareOperator = '>=') {
return compare(a, b, operator)
}

export function makeImageBasedLighting(options: VcImageBasedLighting) {
const { ImageBasedLighting, defined } = Cesium

if (options instanceof Cesium.ImageBasedLighting) {
return options
}

const imageBasedLighting = new ImageBasedLighting()

if (imageBasedLighting.imageBasedLightingFactor) {
imageBasedLighting.imageBasedLightingFactor = makeCartesian2(options.imageBasedLightingFactor) as Cesium.Cartesian2
}

if (imageBasedLighting.sphericalHarmonicCoefficients) {
imageBasedLighting.sphericalHarmonicCoefficients = makeCartesian3Array(options.sphericalHarmonicCoefficients) as Cesium.Cartesian3[]
}

if (imageBasedLighting.luminanceAtZenith) {
imageBasedLighting.luminanceAtZenith = Number(options.luminanceAtZenith)
}

if (defined(imageBasedLighting.specularEnvironmentMaps)) {
imageBasedLighting.specularEnvironmentMaps = options.specularEnvironmentMaps
}

return imageBasedLighting
}
16 changes: 14 additions & 2 deletions packages/utils/cesium-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
makeTranslationRotationScale,
makeQuaternion,
makeOptions,
makeAppearance
makeAppearance,
makeImageBasedLighting
} from './cesium-helpers'
import type { PropType } from 'vue'
import type {
Expand All @@ -35,7 +36,8 @@ import type {
VcPolygonHierarchy,
VcMaterial,
VcBoundingRectangle,
VcPlane
VcPlane,
VcImageBasedLighting
} from './types'

// 下面属性作为实体加载时 可以传 Function
Expand Down Expand Up @@ -1634,6 +1636,15 @@ const specularEnvironmentMaps = {
specularEnvironmentMaps: String
}

const imageBasedLighting = {
imageBasedLighting: {
type: Object as PropType<VcImageBasedLighting>,
watcherOptions: {
cesiumObjectBuilder: makeImageBasedLighting
}
}
}

/**
* @const {Boolean} backFaceCulling mixin
*/
Expand Down Expand Up @@ -1742,6 +1753,7 @@ export {
colors,
enableMouseEvent,
backFaceCulling,
imageBasedLighting,
specularEnvironmentMaps,
sphericalHarmonicCoefficients,
luminanceAtZenith,
Expand Down
21 changes: 21 additions & 0 deletions packages/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,27 @@ export type VcPrimitiveClusterOptions = {
clusterPoints?: boolean
}

export type VcImageBasedLightingOpts = {
/**
* Scales diffuse and specular image-based lighting from the earth, sky, atmosphere and star skybox.
*/
imageBasedLightingFactor?: VcCartesian2
/**
* The sun's luminance at the zenith in kilo candela per meter squared to use for this model's procedural environment map.
*/
luminanceAtZenith?: number
/**
* The third order spherical harmonic coefficients used for the diffuse color of image-based lighting.
*/
sphericalHarmonicCoefficients?: CesiumCartesian3Array
/**
* A URL to a KTX2 file that contains a cube map of the specular lighting and the convoluted specular mipmaps.
*/
specularEnvironmentMaps?: string
}

export type VcImageBasedLighting = VcImageBasedLightingOpts | Cesium.ImageBasedLighting

export {
AnyObject,
VcCamera,
Expand Down

0 comments on commit 4acd03f

Please sign in to comment.