Cesium JS API
AppearanceArcGisMapServerImageryProviderArcGISTiledElevationTerrainProviderArcTypeAssociativeArrayAxisAxisAlignedBoundingBoxbarycentricCoordinatesBillboardBillboardCollectionBillboardGraphicsBillboardVisualizerbinarySearchbinarySearchComparatorBingMapsGeocoderServiceBingMapsImageryProviderBingMapsStyleBlendEquationBlendFunctionBlendingStateBlendOptionBoundingRectangleBoundingSphereBoxEmitterBoxGeometryBoxGeometryUpdaterBoxGraphicsBoxOutlineGeometrybuildModuleUrlCallbackPropertyCameraCameraEventAggregatorCameraEventTypeCartesian2Cartesian3Cartesian4CartographicCartographicGeocoderServiceCatmullRomSplineCesium3DTileCesium3DTileColorBlendModeCesium3DTileContentCesium3DTileFeatureCesium3DTilePointFeatureCesium3DTilesetCesium3DTilesetGraphicsCesium3DTilesetVisualizerCesium3DTileStyleCesium3DTilesVoxelProviderCesiumTerrainProviderCesiumWidgetCheckerboardMaterialPropertyCircleEmitterCircleGeometryCircleOutlineGeometryClassificationPrimitiveClassificationTypeClippingPlaneClippingPlaneCollectionClockClockRangeClockStepcloneCloudCollectionCloudTypeColorColorBlendModeColorGeometryInstanceAttributeColorMaterialPropertycombineComponentDatatypeCompositeEntityCollectionCompositeMaterialPropertyCompositePositionPropertyCompositePropertyCompressedTextureBufferConditionsExpressionConeEmitterConstantPositionPropertyConstantPropertyConstantSplineContextOptionsCoplanarPolygonGeometryCoplanarPolygonOutlineGeometryCornerTypeCorridorGeometryCorridorGeometryUpdaterCorridorGraphicsCorridorOutlineGeometrycreateElevationBandMaterialcreateElevationBandMaterialBandcreateElevationBandMaterialEntrycreateGuidcreateOsmBuildingscreateTangentSpaceDebugPrimitivecreateWorldImagerycreateWorldTerrainCreditCreditDisplayCubicRealPolynomialCullFaceCullingVolumeCumulusCloudCustomDataSourceCustomHeightmapTerrainProviderCustomShaderCustomShaderModeCustomShaderTranslucencyModeCylinderGeometryCylinderGeometryUpdaterCylinderGraphicsCylinderOutlineGeometryCzmlDataSourceDataSourceDataSourceClockDataSourceCollectionDataSourceDisplayDebugAppearanceDebugCameraPrimitiveDebugModelMatrixPrimitiveDefaultProxydefaultValuedefinedDepthFunctiondestroyObjectDeveloperErrorDirectionalLightDirectionUpDiscardEmptyTileImagePolicyDiscardMissingTileImagePolicyDistanceDisplayConditionDistanceDisplayConditionGeometryInstanceAttributeEasingFunctionEllipseGeometryEllipseGeometryUpdaterEllipseGraphicsEllipseOutlineGeometryEllipsoidEllipsoidGeodesicEllipsoidGeometryEllipsoidGeometryUpdaterEllipsoidGraphicsEllipsoidOutlineGeometryEllipsoidRhumbLineEllipsoidSurfaceAppearanceEllipsoidTangentPlaneEllipsoidTerrainProviderEntityEntityClusterEntityCollectionEntityViewEventEventHelperexcludesReverseAxisexportKmlexportKmlModelCallbackexportKmlResultKmlexportKmlResultKmzExpressionExtrapolationTypeFeatureDetectionFogformatErrorFrameRateMonitorFrustumGeometryFrustumOutlineGeometryFullscreenGeocoderServiceGeocodeTypeGeographicProjectionGeographicTilingSchemeGeoJsonDataSourceGeometryGeometryAttributeGeometryAttributesGeometryFactoryGeometryInstanceGeometryInstanceAttributeGeometryPipelineGeometryUpdaterGeometryVisualizergetAbsoluteUrigetBaseUrigetExtensionFromUriGetFeatureInfoFormatgetFilenameFromUrigetImagePixelsgetTimestampGlobeGlobeTranslucencyGoogleEarthEnterpriseImageryProviderGoogleEarthEnterpriseMapsProviderGoogleEarthEnterpriseMetadataGoogleEarthEnterpriseTerrainDataGoogleEarthEnterpriseTerrainProviderGpxDataSourceGregorianDateGridImageryProviderGridMaterialPropertyGroundGeometryUpdaterGroundPolylineGeometryGroundPolylinePrimitiveGroundPrimitiveHeadingPitchRangeHeadingPitchRollHeadingPitchRollValuesHeightmapEncodingHeightmapTerrainDataHeightReferenceHermitePolynomialApproximationHermiteSplineHilbertOrderHorizontalOriginI3SDataProviderI3SFeatureI3SFieldI3SGeometryI3SLayerI3SNodeImageBasedLightingImageMaterialPropertyImageryLayerImageryLayerCollectionImageryLayerFeatureInfoImageryProviderImageryTypesincludesReverseAxisIndexDatatypeIntersectIntersections2DIntersectionTestsIntervalIonIonGeocoderServiceIonImageryProviderIonResourceIonWorldImageryStyleisLeapYearIso8601JulianDateKeyboardEventModifierKmlCameraKmlDataSourceKmlFeatureDataKmlLookAtKmlTourKmlTourFlyToKmlTourWaitLabelLabelCollectionLabelGraphicsLabelStyleLabelVisualizerLagrangePolynomialApproximationLeapSecondLightLightingModelLinearApproximationLinearSplineMapboxImageryProviderMapboxStyleImageryProviderMapMode2DMapProjectionMaterialMaterialAppearanceMaterialSupportMaterialPropertyMathMatrix2Matrix3Matrix4mergeSortmergeSortComparatorMetadataClassMetadataClassPropertyMetadataComponentTypeMetadataEnumMetadataEnumValueMetadataSchemaMetadataTypeModelModelAnimationModelAnimationCollectionModelAnimationLoopModelFeatureModelGraphicsModelNodeModelVisualizerMoonMorphWeightSplineNearFarScalarNeverTileDiscardPolicyNodeTransformationPropertyobjectToQueryOccluderOpenCageGeocoderServiceOpenStreetMapImageryProviderOrientedBoundingBoxOrthographicFrustumOrthographicOffCenterFrustumPackableForInterpolationParticleParticleBurstParticleEmitterParticleSystemPathGraphicsPathVisualizerPeliasGeocoderServicePerInstanceColorAppearancePerspectiveFrustumPerspectiveOffCenterFrustumPinBuilderPixelDatatypePixelFormatPlanePlaneGeometryPlaneGeometryUpdaterPlaneGraphicsPlaneOutlineGeometryPointCloudShadingPointGraphicspointInsideTrianglePointPrimitivePointPrimitiveCollectionPointVisualizerPolygonGeometryPolygonGeometryUpdaterPolygonGraphicsPolygonHierarchyPolygonOutlineGeometryPolylinePolylineArrowMaterialPropertyPolylineCollectionPolylineColorAppearancePolylineDashMaterialPropertyPolylineGeometryPolylineGeometryUpdaterPolylineGlowMaterialPropertyPolylineGraphicsPolylineMaterialAppearancePolylineOutlineMaterialPropertyPolylineVisualizerPolylineVolumeGeometryPolylineVolumeGeometryUpdaterPolylineVolumeGraphicsPolylineVolumeOutlineGeometryPositionPropertyPositionPropertyArrayPostProcessStagePostProcessStageCollectionPostProcessStageCompositePostProcessStageLibraryPostProcessStageSampleModePrimitivePrimitiveCollectionPrimitiveTypePropertyPropertyArrayPropertyBagProxyQuadraticRealPolynomialQuantizedMeshTerrainDataQuarticRealPolynomialQuaternionQuaternionSplinequeryToObjectQueueRayreadyPromiseRectangleRectangleGeometryRectangleGeometryUpdaterRectangleGraphicsRectangleOutlineGeometryReferenceFrameReferencePropertyremoveExtensionRequestRequestErrorEventRequestSchedulerRequestStateRequestTypeResourceRuntimeErrorSampledPositionPropertySampledPropertysampleTerrainsampleTerrainMostDetailedSceneSceneModeSceneTransformsScreenSpaceCameraControllerScreenSpaceEventHandlerScreenSpaceEventTypeshaderDefinesshaderMaximumIntersectionsLengthshaderUniformsShadowMapShadowModeShowGeometryInstanceAttributeSimon1994PlanetaryPositionsSimplePolylineGeometrySingleTileImageryProviderSkyAtmosphereSkyBoxSphereEmitterSphereGeometrySphereOutlineGeometrySphericalSplineSplitDirectionStencilFunctionStencilOperationSteppedSplineStripeMaterialPropertyStripeOrientationStyleExpressionsubdivideArraySunSunLightTaskProcessorTerrainDataTerrainProviderTextureMagnificationFilterTextureMinificationFilterTextureUniformTileAvailabilityTileCoordinatesImageryProviderTileDiscardPolicyTileMapServiceImageryProviderTileProviderErrorTilingSchemeTimeDynamicImageryTimeDynamicPointCloudTimeIntervalTimeIntervalCollectionTimeIntervalCollectionPositionPropertyTimeIntervalCollectionPropertyTimeStandardTransformsTranslationRotationScaleTridiagonalSystemSolverTrustedServersUniformSpecifierUniformTypeUrlTemplateImageryProviderVaryingTypeVelocityOrientationPropertyVelocityVectorPropertyVertexFormatVerticalOriginVideoSynchronizerViewportQuadVisibilityVisualizerVoxelPrimitiveVoxelProviderVoxelShapeTypeVRTheWorldTerrainProviderWallGeometryWallGeometryUpdaterWallGraphicsWallOutlineGeometryWebGLConstantsWebGLOptionsWebMapServiceImageryProviderWebMapTileServiceImageryProviderWebMercatorProjectionWebMercatorTilingSchemeWindingOrderwriteTextToCanvasAnimationAnimationViewModelBaseLayerPickerBaseLayerPickerViewModelCesium3DTilesInspectorCesium3DTilesInspectorViewModelCesiumInspectorCesiumInspectorViewModelClockViewModelCommandcreateCommandFullscreenButtonFullscreenButtonViewModelGeocoderGeocoderViewModelHomeButtonHomeButtonViewModelInfoBoxInfoBoxViewModelNavigationHelpButtonNavigationHelpButtonViewModelPerformanceWatchdogPerformanceWatchdogViewModelProjectionPickerProjectionPickerViewModelProviderViewModelSceneModePickerSceneModePickerViewModelSelectionIndicatorSelectionIndicatorViewModelSvgPathBindingHandlerTimelineToggleButtonViewModelViewerviewerCesium3DTilesInspectorMixinviewerCesiumInspectorMixinviewerDragDropMixinviewerPerformanceWatchdogMixinviewerVoxelInspectorMixinVoxelInspectorVoxelInspectorViewModelVRButtonVRButtonViewModel

ParticleEmitter

ParticleEmitterCesiumJS 中的一个实体类,它可以在三维场景中生成一个粒子发射器,模拟各种不同的效果,比如火花、火焰、烟雾等等。本文档将详细介绍 ParticleEmitter 类的属性和用法。

实例化

ParticleEmitter 类的实例可以通过以下代码进行创建:

const emitter = new Cesium.ParticleEmitter(scene);

其中,sceneCesium.Scene 类的实例,代表一个在 CesiumJS 中的三维场景。

属性

emitter.active

类型: Boolean

表述:表示当前粒子发射器是否处于激活状态,激活状态下将会不断发射新的粒子。

emitter.life

类型: Number

默认值: Number.POSITIVE_INFINITY

表述:表示每个粒子的生命周期,单位为秒。一个粒子的生命周期是指从被发射开始,到它消失为止的时间间隔,如果设置为 Number.POSITIVE_INFINITY,则表示粒子不会消失。

emitter.particleLife

类型: Number

默认值: 2.0

表述:表示被发射的每个粒子的初始寿命,单位为秒。这个属性的值应该小于 emitter.life,否则粒子将不会有足够的时间在场景中存在。

emitter.rate

类型: Number

默认值: 5.0

表述:表示每秒发射粒子的数量。

emitter.radius

类型: Number

默认值: 1.0

表述:表示从粒子发射器源点开始,粒子的发射半径。当这个属性值越大时,粒子在场景中分布得越开。

emitter.radiusSpread

类型: Number

默认值: 1.0

表述:表示从粒子发射器源点开始,粒子发射半径的扩展范围。例如当 radius 值为 10.0radiusSpread 值为 2.0 时,粒子发射半径的范围将在 8.012.0 之间。

emitter.speed

类型: Number

默认值: 0.0

表述:表示被发射的每个粒子的初始速度,单位为米/秒。

emitter.speedSpread

类型: Number

默认值: 1.0

表述:表示被发射的每个粒子的初始速度的扩展范围。例如当 speed 值为 5.0speedSpread 值为 2.0 时,粒子的初始化速度将在 3.07.0 之间。

emitter.emitterModelMatrix

类型: Cesium.Matrix4

默认值: Cesium.Matrix4.IDENTITY

表述:表示粒子发射器在场景中的变换矩阵,通过该属性可以对粒子发射器进行平移、旋转、缩放等变换操作。

emitter.emitterBursts

类型: Array

默认值: []

表述:表示所有粒子发射器喷发事件的数组,每个元素为对象类型。喷发事件有一次性大量发射粒子的效果,可以用于模拟爆炸或者烟花效果等。

emitter.emitterBursts[].time

类型: Number

默认值: 0.0

表述:表示触发粒子喷发事件的延迟时间,单位为秒。

emitter.emitterBursts[].minimum

类型: Number

默认值: 10

表述:表示粒子喷发事件触发后,最少发射的粒子数量。

emitter.emitterBursts[].maximum

类型: Number

默认值: 30

表述:表示粒子喷发事件触发后,最多发射的粒子数量。

emitter.emitterBursts[].particleLife

类型: Number

默认值: emitter.particleLife

表述:表示通过当前喷发事件喷发出来的每个粒子的寿命,单位为秒。

emitter.emitterBursts[].speed

类型: Number

默认值: emitter.speed

表述:表示通过当前喷发事件喷发出来的每个粒子的初始速度,单位为米/秒。

emitter.image

类型: Object

默认值: null

表述:表示用来创建粒子材质的 Image 类型对象。

emitter.pixelOffset

类型: Cesium.Cartesian2

默认值: Cesium.Cartesian2.ZERO

表述:表示每个粒子的像素偏移量,用于控制粒子在屏幕上的位置。

emitter.size

类型: Number

默认值: 1.0

表述:表示每个粒子在场景中的尺寸,单位为米。

emitter.sizeSpread

类型: Number

默认值: 1.0

表述:表示每个粒子尺寸的扩展范围,例如当 size 值为 5.0sizeSpread 值为 2.0 时,粒子的尺寸将在 3.07.0 之间。

emitter.lifeTime

类型: Number

默认值: 0.0

表述:表示粒子发射器已经存在的时间,单位为秒。

emitter.billboard

类型: Cesium.Billboard

表述:表示粒子实体使用的 Billboard 对象,可用于修改其它属性,如 color、rotation、scale 等。

方法

emitter.update(time)

表述:更新粒子发射器状态,内部根据时间 time 进行粒子发射、粒子更新和删除等操作。例如,可以通过下面的代码实时更新粒子发射器状态:

const clock = new Cesium.Clock();

viewer.clock.onTick.addEventListener(function(clock) {
  emitter.update(clock.currentTime);
});

例子

以下是一个简单的粒子发射器例子:

const viewer = new Cesium.Viewer("cesiumContainer");

const scene = viewer.scene;
const emitter = new Cesium.ParticleEmitter(scene);

emitter.image = new Image();
emitter.image.src = "particle.png";

emitter.emitterModelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
  Cesium.Cartesian3.ZERO
);

emitter.emitterBursts = [
  {
    time: 0.0,
    minimum: 10,
    maximum: 30,
    particleLife: 2.0,
    speed: 10.0,
  },
];

viewer.scene.primitives.add(emitter);

在这个例子中,我们创建了一个 ParticleEmitter 实例,使用了一个 particle.png 的图片作为粒子材质。我们还在 emitterModelMatrix 属性中设置了一个空间变换矩阵,这个变换矩阵用于将粒子发射器移动到场景中的某个位置。

最后,我们使用 emitterBursts 属性定义了一个触发粒子喷发事件,并且在事件中发射了一些粒子。

总结

ParticleEmitter 类是 CesiumJS 中实现粒子效果的核心类之一,它可以模拟各种不同的场景,包括烟花、火焰、雨滴等等。在本文档中,我们详细介绍了 ParticleEmitter 类的属性和方法,希望可以为读者带来帮助。