Cesium JS API
AppearanceArcGisMapServerImageryProviderArcGISTiledElevationTerrainProviderArcTypeAssociativeArrayAxisAxisAlignedBoundingBoxbarycentricCoordinatesBillboardBillboardCollectionBillboardGraphicsBillboardVisualizerbinarySearchbinarySearchComparatorBingMapsGeocoderServiceBingMapsImageryProviderBingMapsStyleBlendEquationBlendFunctionBlendingStateBlendOptionBoundingRectangleBoundingSphereBoxEmitterBoxGeometryBoxGeometryUpdaterBoxGraphicsBoxOutlineGeometrybuildModuleUrlCallbackPropertyCameraCameraEventAggregatorCameraEventTypeCartesian2Cartesian3Cartesian4CartographicCartographicGeocoderServiceCatmullRomSplineCesium3DTileCesium3DTileColorBlendModeCesium3DTileContentCesium3DTileFeatureCesium3DTilePointFeatureCesium3DTilesetCesium3DTilesetGraphicsCesium3DTilesetVisualizerCesium3DTileStyleCesium3DTilesVoxelProviderCesiumTerrainProviderCesiumWidgetCheckerboardMaterialPropertyCircleEmitterCircleGeometryCircleOutlineGeometryClassificationPrimitiveClassificationTypeClippingPlaneClippingPlaneCollectionClockClockRangeClockStepcloneCloudCollectionCloudTypeColorColorBlendModeColorGeometryInstanceAttributeColorMaterialPropertycombineComponentDatatypeCompositeEntityCollectionCompositeMaterialPropertyCompositePositionPropertyCompositePropertyCompressedTextureBufferConditionsExpressionConeEmitterConstantPositionPropertyConstantPropertyConstantSplineContextOptionsCoplanarPolygonGeometryCoplanarPolygonOutlineGeometryCornerTypeCorridorGeometryCorridorGeometryUpdaterCorridorGraphicsCorridorOutlineGeometrycreateElevationBandMaterialcreateElevationBandMaterialBandcreateElevationBandMaterialEntrycreateGuidcreateOsmBuildingscreateTangentSpaceDebugPrimitivecreateWorldImagerycreateWorldTerrainCreditCreditDisplayCubicRealPolynomialCullFaceCullingVolumeCumulusCloudCustomDataSourceCustomHeightmapTerrainProviderCustomShaderCustomShaderModeCustomShaderTranslucencyModeCylinderGeometryCylinderGeometryUpdaterCylinderGraphicsCylinderOutlineGeometryCzmlDataSourceDataSourceDataSourceClockDataSourceCollectionDataSourceDisplayDebugAppearanceDebugCameraPrimitiveDebugModelMatrixPrimitiveDefaultProxydefaultValuedefinedDepthFunctiondestroyObjectDeveloperErrorDirectionalLightDirectionUpDiscardEmptyTileImagePolicyDiscardMissingTileImagePolicyDistanceDisplayConditionDistanceDisplayConditionGeometryInstanceAttributeEasingFunctionEllipseGeometryEllipseGeometryUpdaterEllipseGraphicsEllipseOutlineGeometryEllipsoidEllipsoidGeodesicEllipsoidGeometryEllipsoidGeometryUpdaterEllipsoidGraphicsEllipsoidOutlineGeometryEllipsoidRhumbLineEllipsoidSurfaceAppearanceEllipsoidTangentPlaneEllipsoidTerrainProviderEntityEntityClusterEntityCollectionEntityViewEventEventHelperexcludesReverseAxisexportKmlexportKmlModelCallbackexportKmlResultKmlexportKmlResultKmzExpressionExtrapolationTypeFeatureDetectionFogformatErrorFrameRateMonitorFrustumGeometryFrustumOutlineGeometryFullscreenGeocoderServiceGeocodeTypeGeographicProjectionGeographicTilingSchemeGeoJsonDataSourceGeometryGeometryAttributeGeometryAttributesGeometryFactoryGeometryInstanceGeometryInstanceAttributeGeometryPipelineGeometryUpdaterGeometryVisualizergetAbsoluteUrigetBaseUrigetExtensionFromUriGetFeatureInfoFormatgetFilenameFromUrigetImagePixelsgetTimestampGlobeGlobeTranslucencyGoogleEarthEnterpriseImageryProviderGoogleEarthEnterpriseMapsProviderGoogleEarthEnterpriseMetadataGoogleEarthEnterpriseTerrainDataGoogleEarthEnterpriseTerrainProviderGpxDataSourceGregorianDateGridImageryProviderGridMaterialPropertyGroundGeometryUpdaterGroundPolylineGeometryGroundPolylinePrimitiveGroundPrimitiveHeadingPitchRangeHeadingPitchRollHeadingPitchRollValuesHeightmapEncodingHeightmapTerrainDataHeightReferenceHermitePolynomialApproximationHermiteSplineHilbertOrderHorizontalOriginI3SDataProviderI3SFeatureI3SFieldI3SGeometryI3SLayerI3SNodeImageBasedLightingImageMaterialPropertyImageryLayerImageryLayerCollectionImageryLayerFeatureInfoImageryProviderImageryTypesincludesReverseAxisIndexDatatypeIntersectIntersections2DIntersectionTestsIntervalIonIonGeocoderServiceIonImageryProviderIonResourceIonWorldImageryStyleisLeapYearIso8601JulianDateKeyboardEventModifierKmlCameraKmlDataSourceKmlFeatureDataKmlLookAtKmlTourKmlTourFlyToKmlTourWaitLabelLabelCollectionLabelGraphicsLabelStyleLabelVisualizerLagrangePolynomialApproximationLeapSecondLightLightingModelLinearApproximationLinearSplineMapboxImageryProviderMapboxStyleImageryProviderMapMode2DMapProjectionMaterialMaterialAppearanceMaterialSupportMaterialPropertyMathMatrix2Matrix3Matrix4mergeSortmergeSortComparatorMetadataClassMetadataClassPropertyMetadataComponentTypeMetadataEnumMetadataEnumValueMetadataSchemaMetadataTypeModelModelAnimationModelAnimationCollectionModelAnimationLoopModelFeatureModelGraphicsModelNodeModelVisualizerMoonMorphWeightSplineNearFarScalarNeverTileDiscardPolicyNodeTransformationPropertyobjectToQueryOccluderOpenCageGeocoderServiceOpenStreetMapImageryProviderOrientedBoundingBoxOrthographicFrustumOrthographicOffCenterFrustumPackableForInterpolationParticleParticleBurstParticleEmitterParticleSystemPathGraphicsPathVisualizerPeliasGeocoderServicePerInstanceColorAppearancePerspectiveFrustumPerspectiveOffCenterFrustumPinBuilderPixelDatatypePixelFormatPlanePlaneGeometryPlaneGeometryUpdaterPlaneGraphicsPlaneOutlineGeometryPointCloudShadingPointGraphicspointInsideTrianglePointPrimitivePointPrimitiveCollectionPointVisualizerPolygonGeometryPolygonGeometryUpdaterPolygonGraphicsPolygonHierarchyPolygonOutlineGeometryPolylinePolylineArrowMaterialPropertyPolylineCollectionPolylineColorAppearancePolylineDashMaterialPropertyPolylineGeometryPolylineGeometryUpdaterPolylineGlowMaterialPropertyPolylineGraphicsPolylineMaterialAppearancePolylineOutlineMaterialPropertyPolylineVisualizerPolylineVolumeGeometryPolylineVolumeGeometryUpdaterPolylineVolumeGraphicsPolylineVolumeOutlineGeometryPositionPropertyPositionPropertyArrayPostProcessStagePostProcessStageCollectionPostProcessStageCompositePostProcessStageLibraryPostProcessStageSampleModePrimitivePrimitiveCollectionPrimitiveTypePropertyPropertyArrayPropertyBagProxyQuadraticRealPolynomialQuantizedMeshTerrainDataQuarticRealPolynomialQuaternionQuaternionSplinequeryToObjectQueueRayreadyPromiseRectangleRectangleGeometryRectangleGeometryUpdaterRectangleGraphicsRectangleOutlineGeometryReferenceFrameReferencePropertyremoveExtensionRequestRequestErrorEventRequestSchedulerRequestStateRequestTypeResourceRuntimeErrorSampledPositionPropertySampledPropertysampleTerrainsampleTerrainMostDetailedSceneSceneModeSceneTransformsScreenSpaceCameraControllerScreenSpaceEventHandlerScreenSpaceEventTypeshaderDefinesshaderMaximumIntersectionsLengthshaderUniformsShadowMapShadowModeShowGeometryInstanceAttributeSimon1994PlanetaryPositionsSimplePolylineGeometrySingleTileImageryProviderSkyAtmosphereSkyBoxSphereEmitterSphereGeometrySphereOutlineGeometrySphericalSplineSplitDirectionStencilFunctionStencilOperationSteppedSplineStripeMaterialPropertyStripeOrientationStyleExpressionsubdivideArraySunSunLightTaskProcessorTerrainDataTerrainProviderTextureMagnificationFilterTextureMinificationFilterTextureUniformTileAvailabilityTileCoordinatesImageryProviderTileDiscardPolicyTileMapServiceImageryProviderTileProviderErrorTilingSchemeTimeDynamicImageryTimeDynamicPointCloudTimeIntervalTimeIntervalCollectionTimeIntervalCollectionPositionPropertyTimeIntervalCollectionPropertyTimeStandardTransformsTranslationRotationScaleTridiagonalSystemSolverTrustedServersUniformSpecifierUniformTypeUrlTemplateImageryProviderVaryingTypeVelocityOrientationPropertyVelocityVectorPropertyVertexFormatVerticalOriginVideoSynchronizerViewportQuadVisibilityVisualizerVoxelPrimitiveVoxelProviderVoxelShapeTypeVRTheWorldTerrainProviderWallGeometryWallGeometryUpdaterWallGraphicsWallOutlineGeometryWebGLConstantsWebGLOptionsWebMapServiceImageryProviderWebMapTileServiceImageryProviderWebMercatorProjectionWebMercatorTilingSchemeWindingOrderwriteTextToCanvasAnimationAnimationViewModelBaseLayerPickerBaseLayerPickerViewModelCesium3DTilesInspectorCesium3DTilesInspectorViewModelCesiumInspectorCesiumInspectorViewModelClockViewModelCommandcreateCommandFullscreenButtonFullscreenButtonViewModelGeocoderGeocoderViewModelHomeButtonHomeButtonViewModelInfoBoxInfoBoxViewModelNavigationHelpButtonNavigationHelpButtonViewModelPerformanceWatchdogPerformanceWatchdogViewModelProjectionPickerProjectionPickerViewModelProviderViewModelSceneModePickerSceneModePickerViewModelSelectionIndicatorSelectionIndicatorViewModelSvgPathBindingHandlerTimelineToggleButtonViewModelViewerviewerCesium3DTilesInspectorMixinviewerCesiumInspectorMixinviewerDragDropMixinviewerPerformanceWatchdogMixinviewerVoxelInspectorMixinVoxelInspectorVoxelInspectorViewModelVRButtonVRButtonViewModel

VoxelPrimitive

VoxelPrimitiveCesiumJS 中一种基于体素(Voxel)渲染技术的渲染器,可以用于绘制体素化的三维模型,支持多种材质和光照效果。本文档将会介绍 VoxelPrimitive 的基本用法、构造参数和常见问题。

基本用法

使用 VoxelPrimitive 渲染三维模型需要先加载模型数据,并构造 VoxelPrimitive 对象。以下是一个简单的示例,展示了如何使用 VoxelPrimitive 渲染一个简单的方块模型。

// 加载模型数据
var positions = [
    [0, 0, 0],
    [1, 0, 0],
    [1, 0, 1],
    [0, 0, 1],
    [0, 1, 0],
    [1, 1, 0],
    [1, 1, 1],
    [0, 1, 1]
];
var indices = [
    0, 1, 2, 0, 2, 3,
    0, 3, 4, 3, 7, 4,
    3, 2, 7, 2, 6, 7,
    1, 6, 2, 1, 5, 6,
    0, 4, 1, 1, 4, 5,
    4, 7, 5, 5, 7, 6
];

// 构造 VoxelPrimitive 对象
var primitive = new Cesium.VoxelPrimitive({
    positions: positions,
    indices: indices,
    material: Cesium.Material.fromType('DiffuseMap')
});

// 添加到场景中
viewer.scene.primitives.add(primitive);

在上面的示例中,我们先定义了一个简单的模型,包含八个顶点和三十六个索引。然后使用 VoxelPrimitive 构造函数创建了一个 VoxelPrimitive 对象,并指定了模型的顶点坐标、索引以及材质。最后将 VoxelPrimitive 对象添加到场景中即可完成渲染。

构造参数

VoxelPrimitive 构造函数的参数如下表所示:

参数 类型 默认值 描述
positions Array.<Number[]> 必需 模型顶点坐标数组,每个顶点的坐标为 [x, y, z] 格式。
indices Array.<Number> 必需 模型索引数组,包含一系列描述模型三角形面的索引。
dimensions Cesium.Cartesian3 new Cesium.Cartesian3(1, 1, 1) 模型的尺寸,用于确定体素大小。
show Boolean true 是否显示。
modelMatrix Cesium.Matrix4 Cesium.Matrix4.IDENTITY 模型矩阵,用于指定模型的位姿。
material Cesium.Material Cesium.Material.Default 渲染材质。
sliceMaterial Cesium.Material undefined 分片渲染材质,用于在矢量图形上显示分割面。
silhouetteMaterial Cesium.Material undefined 轮廓渲染材质,用于在矢量图形上显示轮廓线。
debugShowBoundingVolume Boolean false 是否显示包围盒。
debugShowNormals Boolean false 是否显示法向量。

常见问题

如何设置体素大小?

可以通过 dimensions 参数指定模型的尺寸,用于确定体素大小。例如:

var primitive = new Cesium.VoxelPrimitive({
    // ...
    dimensions: new Cesium.Cartesian3(2, 2, 3)
});

上述代码中,我们将模型的尺寸设置为 (2, 2, 3),表示模型的宽度为 2,高度为 2,深度为 3,根据该尺寸确定体素的大小。

如何设置材质?

可以通过 material 参数指定渲染材质,该参数可以接收一个 Cesium.Material 对象。例如:

var primitive = new Cesium.VoxelPrimitive({
    // ...
    material: Cesium.Material.fromType('DiffuseMap', {
        image: 'path/to/texture.png'
    })
});

上述代码中,我们使用了 DiffuseMap 材质,并指定了纹理图像。

如何添加分割面渲染效果?

可以通过 sliceMaterial 参数指定分割面渲染材质,该参数可以接收一个 Cesium.Material 对象。例如:

var sliceMaterial = Cesium.Material.fromType('Slice');
sliceMaterial.uniforms.plane.normal = new Cesium.Cartesian3(0, 0, -1);
sliceMaterial.uniforms.plane.distance = 0;
var primitive = new Cesium.VoxelPrimitive({
    // ...
    sliceMaterial: sliceMaterial
});

上述代码中,我们创建了一个 Slice 材质,并设置了分割面的位置和法向量,然后将该材质赋值给了 sliceMaterial 参数,从而让 VoxelPrimitive 对象在视图中显示分割面效果。

如何添加轮廓渲染效果?

可以通过 silhouetteMaterial 参数指定轮廓渲染材质,该参数可以接收一个 Cesium.Material 对象。例如:

var silhouetteMaterial = Cesium.Material.fromType('Silhouette');
silhouetteMaterial.uniforms.color = new Cesium.Color(1, 0, 0, 1);
silhouetteMaterial.uniforms.length = 20;
var primitive = new Cesium.VoxelPrimitive({
    // ...
    silhouetteMaterial: silhouetteMaterial
});

上述代码中,我们创建了一个 Silhouette 材质,并设置了轮廓线的颜色和长度,然后将该材质赋值给了 silhouetteMaterial 参数,从而让 VoxelPrimitive 对象在视图中显示轮廓线效果。

如何优化性能?

VoxelPrimitive 渲染器对于大规模的三维模型可能需要较长的渲染时间,因此需要对性能进行优化。以下是一些常见的优化策略:

  • 减少模型的三角面数量。
  • 缩小体素大小。
  • 对于每次渲染只需要显示部分模型的情况,可以使用 show 参数设置模型的显示状态。
  • 对于需要动态更新的模型,可以使用 VoxelProvider 实现动态加载和卸载模型数据。

参考链接