Cesium添加模型并设置各种属性

一、所需文件

css样式文件:

Cesium-1.88\Apps\Sandcastle\templates\bucket.css

js文件:

Cesium-1.88\Build\Cesium\Cesium.js

Cesium-1.88\Apps\Sandcastle\Sandcastle-header.js

 二、HTML body

 三、JavaScript

创建观查器

  var viewer = new Cesium.Viewer('cesiumContainer', {})

 设置一个模型属性

  var entity = viewer.entities.add({
        name: '飞机',
        position: Cesium.Cartesian3.fromDegrees(113.03, 23.42, 200),
        model: {
          uri: '../resource/mode/Cesium_Air.glb',
          minimumPixelSize: 1, //最小的模型像素
          maximumScale: 50, //最大的模型像素
          runAnimations: true, //是否显示动画
          clampAnimations: true, //是否保持最后一针的动画
          color: Cesium.Color.RED, //颜色
          color: Cesium.Color.fromAlpha(Cesium.Color.RED, parseFloat(1.0)), //包含透明度的颜色
          colorBlendMode: Cesium.ColorBlendMode['MIX'], //常用的有三个HIGHLIGHT,REPLACE,MIX
          colorBlendAmount: 0, //颜色遮罩:0-1,这个属性必须是MIX混合属性才能生效
        },
      })

 将相机设置到模型位置

viewer.trackedEntity = entity

 四、模型属性配置目录(百度翻译)

viewer.entities.add 的实体构造函数的初始化选项原文

ame Type Description
id String A unique identifier for this object. If none is provided, a GUID is generated.
name String A human readable name to display to users. It does not have to be unique.
availability TimeIntervalCollection The availability, if any, associated with this object.
show Boolean A boolean value indicating if the entity and its children are displayed.
description Property | string A string Property specifying an HTML description for this entity.
position PositionProperty | Cartesian3 A Property specifying the entity position.
orientation Property A Property specifying the entity orientation.
viewFrom Property A suggested initial offset for viewing this object.
parent Entity A parent entity to associate with this entity.
billboard BillboardGraphics | BillboardGraphics.ConstructorOptions A billboard to associate with this entity.
box BoxGraphics | BoxGraphics.ConstructorOptions A box to associate with this entity.
corridor CorridorGraphics | CorridorGraphics.ConstructorOptions A corridor to associate with this entity.
cylinder CylinderGraphics | CylinderGraphics.ConstructorOptions A cylinder to associate with this entity.
ellipse EllipseGraphics | EllipseGraphics.ConstructorOptions A ellipse to associate with this entity.
ellipsoid EllipsoidGraphics | EllipsoidGraphics.ConstructorOptions A ellipsoid to associate with this entity.
label LabelGraphics | LabelGraphics.ConstructorOptions A options.label to associate with this entity.
model ModelGraphics | ModelGraphics.ConstructorOptions A model to associate with this entity.
tileset Cesium3DTilesetGraphics | Cesium3DTilesetGraphics.ConstructorOptions A 3D Tiles tileset to associate with this entity.
path PathGraphics | PathGraphics.ConstructorOptions A path to associate with this entity.
plane PlaneGraphics | PlaneGraphics.ConstructorOptions A plane to associate with this entity.
point PointGraphics | PointGraphics.ConstructorOptions A point to associate with this entity.
polygon PolygonGraphics | PolygonGraphics.ConstructorOptions A polygon to associate with this entity.
polyline PolylineGraphics | PolylineGraphics.ConstructorOptions A polyline to associate with this entity.
properties PropertyBag | Object. Arbitrary properties to associate with this entity.
polylineVolume PolylineVolumeGraphics | PolylineVolumeGraphics.ConstructorOptions A polylineVolume to associate with this entity.
rectangle RectangleGraphics | RectangleGraphics.ConstructorOptions A rectangle to associate with this entity.
wall WallGraphics | WallGraphics.ConstructorOptions A wall to associate with this entity.

viewer.entities.add 的实体构造函数的初始化选项翻译

名字 类型 描述
id 字符串 此对象的唯一标识符。如果未提供任何内容,则生成 GUID。
name 字符串 要向用户显示的人类可读名称。它不必是唯一的。
availability 时间间隔收集 与此对象关联的可用性(如果有)。
show 布尔 一个布尔值,指示是否显示实体及其子实体。
description 物业|字符串 一个字符串 属性,用于指定此实体的 HTML 说明。
position 位置属性|笛卡尔3 指定实体位置的属性。
orientation 财产 指定实体方向的属性。
viewFrom 财产 用于查看此对象的建议初始偏移量。
parent 实体 要与此实体关联的父实体。
billboard 广告牌图形| BillboardGraphics.ConstructorOptions 与此实体关联的广告牌。
box 盒装图形| BoxGraphics.ConstructorOptions 要与此实体关联的框。
corridor 走廊图形|走廊图形.构造器选项 要与此实体关联的通道。
cylinder 柱面图形| CylinderGraphics.ConstructorOptions 要与此实体关联的柱面。
ellipse 椭圆图形|椭圆图形.构造函数选项 要与此实体关联的椭圆。
ellipsoid 椭圆体图形|椭圆体图形.构造函数选项 要与此实体关联的椭球体。
label 标签图形| LabelGraphics.ConstructorOptions 要与此实体关联的选项标签。
model 模型图形|模型图形.构造函数选项 要与此实体关联的模型。
tileset 3DTilesetGraphics | Cesium3DTilesetGraphics.ConstructorOptions 要与此实体关联的 3D 切片集。
path 路径图形| PathGraphics.ConstructorOptions 与此实体关联的路径。
plane 平面图形|平面图形.构造函数选项 要与此实体关联的平面。
point 点图形|点图形.构造函数选项 要与此实体关联的点。
polygon 多边形图形|多边形图形.构造函数选项 要与此实体关联的面。
polyline 折线图形|折线图形.构造函数选项 要与此实体关联的折线。
properties 物业袋|Object. 要与此实体关联的任意属性。
polylineVolume 折线卷积| PolylineVolumeGraphics.ConstructorOptions 要与此实体关联的折线卷。
rectangle 矩形图形|矩形图形.构造函数选项 要与此实体关联的矩形。
wall 墙面图形| WallGraphics.ConstructorOptions 要与此实体关联的墙。

 模型图形构造函数的初始化选项原文

Name Type Description
show Property | boolean A boolean Property specifying the visibility of the model.
uri Property | string | Resource A string or Resource Property specifying the URI of the glTF asset.
scale Property | number A numeric Property specifying a uniform linear scale.
minimumPixelSize Property | number A numeric Property specifying the approximate minimum pixel size of the model regardless of zoom.
maximumScale Property | number The maximum scale size of a model. An upper limit for minimumPixelSize.
incrementallyLoadTextures Property | boolean Determine if textures may continue to stream in after the model is loaded.
runAnimations Property | boolean A boolean Property specifying if glTF animations specified in the model should be started.
clampAnimations Property | boolean A boolean Property specifying if glTF animations should hold the last pose for time durations with no keyframes.
shadows Property | ShadowMode An enum Property specifying whether the model casts or receives shadows from light sources.
heightReference Property | HeightReference A Property specifying what the height is relative to.
silhouetteColor Property | Color A Property specifying the Color of the silhouette.
silhouetteSize Property | number A numeric Property specifying the size of the silhouette in pixels.
color Property | Color A Property specifying the Color that blends with the model's rendered color.
colorBlendMode Property | ColorBlendMode An enum Property specifying how the color blends with the model.
colorBlendAmount Property | number A numeric Property specifying the color strength when the is . A value of 0.0 results in the model's rendered color while a value of 1.0 results in a solid color, with any value in-between resulting in a mix of the two.colorBlendModeMIX
imageBasedLightingFactor Property | Cartesian2 A property specifying the contribution from diffuse and specular image-based lighting.
lightColor Property | Color A property specifying the light color when shading the model. When the scene's light color is used instead.undefined
distanceDisplayCondition Property | DistanceDisplayCondition A Property specifying at what distance from the camera that this model will be displayed.
nodeTransformations PropertyBag | Object. An object, where keys are names of nodes, and values are TranslationRotationScale Properties describing the transformation to apply to that node. The transformation is applied after the node's existing transformation as specified in the glTF, and does not replace the node's existing transformation.
articulations PropertyBag | Object. An object, where keys are composed of an articulation name, a single space, and a stage name, and the values are numeric properties.
clippingPlanes Property | ClippingPlaneCollection A property specifying the ClippingPlaneCollection used to selectively disable rendering the model.

 模型图形构造函数的初始化选项翻译

名字 类型 描述
show 物业|布尔 一个布尔属性,用于指定模型的可见性。
uri 物业|字符串|资源 指定 glTF 资产的 URI 的字符串或资源属性。
scale 物业|数 指定统一线性刻度的数值属性。
minimumPixelSize 物业|数 一个数值属性,指定模型的近似最小像素大小,而不考虑缩放。
maximumScale 物业|数 模型的最大比例大小。最小像素大小的上限。
incrementallyLoadTextures 物业|布尔 确定纹理在加载模型后是否可以继续流入。
runAnimations 物业|布尔 一个布尔属性,指定是否应启动模型中指定的 glTF 动画。
clampAnimations 物业|布尔 一个布尔属性,用于指定 glTF 动画是否应在没有关键帧的时间段内保持最后一个姿势。
shadows 物业|阴影模式 一个枚举属性,指定模型是从光源投射还是接收阴影。
heightReference 物业|高度引用 指定高度相对于的属性。
silhouetteColor 物业|颜色 指定侧面影像颜色的属性。
silhouetteSize 物业|数 一个数值属性,指定剪影的大小(以像素为单位)。
color 物业|颜色 指定与模型的渲染颜色混合的颜色的属性。
colorBlendMode 物业|颜色混合模式 指定颜色如何与模型混合的枚举属性。
colorBlendAmount 物业|数 一个数字属性,指定在 为 时的颜色强度。值 0.0 将生成模型的渲染颜色,而值 1.0 将生成纯色,介于两者之间的任何值都会导致两者的混合。colorBlendModeMIX
imageBasedLightingFactor 物业|笛卡尔2 指定基于漫反射和镜面反射图像的照明的贡献的属性。
lightColor 物业|颜色 指定对模型进行着色时的浅色的属性。当使用场景的光色时。undefined
distanceDisplayCondition 物业|距离显示条件 一个属性,指定将在距摄像机的距离处显示此模型。
nodeTransformations 物业袋|Object. 一个对象,其中键是节点的名称,值是描述要应用于该节点的转换的TranslationRotationScale属性。该转换在 glTF 中指定的节点的现有转换之后应用,并且不会替换节点的现有转换。
articulations 物业袋|对象<字符串,数字> 一个对象,其中键由发音名称、单个空格和阶段名称组成,值是数值属性。
clippingPlanes 物业|剪贴平面集合 指定用于有选择地禁用模型呈现的"裁剪平面集合"的属性。

你可能感兴趣的:(Cesium,前端,javascript)