Model.fromGltfAsync
. 不要直接调用构造函数。
Cesium 通过以下扩展支持 glTF :
- AGI_articulations
- CESIUM_primitive_outline
- CESIUM_RTC
- EXT_instance_features
- EXT_mesh_features
- EXT_mesh_gpu_instancing
- EXT_meshopt_compression
- EXT_structural_metadata
- EXT_texture_webp
- KHR_draco_mesh_compression
- KHR_techniques_webgl
- KHR_materials_common
- KHR_materials_pbrSpecularGlossiness
- KHR_materials_unlit
- KHR_mesh_quantization
- KHR_texture_basisu
- KHR_texture_transform
- WEB3D_quantized_attributes
- NGA_gpm_local (experimental)
注意:对于使用 KHR_texture_basisu 扩展的压缩纹理的模型,我们建议在两个维度上都具有 2 次纹理的幂 以获得最大的兼容性。这是因为某些采样器需要 2 个纹理 (在 WebGL 中使用纹理) 和 KHR_texture_basisu 需要 4 个维度的倍数 (KHR_texture_basisu其他要求)。
Demo:
See:
Members
readonly activeAnimations : ModelAnimationCollection
Model#color
是半透明的或 Model#silhouetteSize
大于 0.0。
-
Default Value:
true
readonly boundingSphere : BoundingSphere
Model#minimumPixelSize
.
-
Default Value:
true
readonly classificationType : ClassificationType
此外,还有一些要求/限制:
- glTF 不能包含变形目标、皮肤或动画。
- glTF 不能包含
EXT_mesh_gpu_instancing
扩展。 - 只有带有 TRIANGLES 的网格才能用于对其他资产进行分类。
- 网格必须防水。
- POSITION 属性是必需的。
- 如果要素 ID 和索引缓冲区都存在,则具有相同要素 ID 的所有索引必须占据索引缓冲区的连续部分。
- 如果存在要素 ID 而没有索引缓冲区,则具有相同要素 ID 的所有位置必须占据位置缓冲区的连续部分。
接受分类的 3D 瓦片或地形必须是不透明的。
-
Default Value:
undefined
Experimental
此功能使用的是 3D Tiles 规范的一部分,该规范不是最终版本,并且可能会在没有 Cesium 标准弃用策略的情况下进行更改。
clippingPlanes : ClippingPlaneCollection
ClippingPlaneCollection
。
clippingPolygons : ClippingPolygonCollection
ClippingPolygonCollection
。
-
Default Value:
undefined
colorBlendMode
为 MIX
时颜色强度的值。值为 0.0 时,将产生模型的渲染颜色,而值为 1.0 时,将产生纯色,介于两者之间的任何值都会导致两者混合。
-
Default Value:
0.5
-
Default Value:
ColorBlendMode.HIGHLIGHT
readonly credit : Credit
customShader : CustomShader
Cesium3DTileStyle
一起使用
可能会导致未定义的行为。
Experimental
此功能使用的是 3D Tiles 规范的一部分,该规范不是最终版本,并且可能会在没有 Cesium 标准弃用策略的情况下进行更改。
为模型中的每个绘制命令绘制边界球体。
-
Default Value:
false
以线框形式绘制模型。
-
Default Value:
false
distanceDisplayCondition : DistanceDisplayCondition
-
Default Value:
undefined
true
,则当 Scene.verticalExaggeration
设置为非 1.0
的值时,模型将沿椭球法线放大。
-
Default Value:
true
Example:
// Exaggerate terrain by a factor of 2, but prevent model exaggeration
scene.verticalExaggeration = 2.0;
model.enableVerticalExaggeration = false;
readonly environmentMapManager : DynamicEnvironmentMapManager
Example:
// 将用于模型环境贴图的地面颜色更改为森林绿色
const environmentMapManager = model.environmentMapManager;
environmentMapManager.groundColor = Cesium.Color.fromCssColorString("#203b34");
readonly errorEvent : Event
ModelError
的实例。
对于EXT_mesh_features,这是要素 ID 的 label 属性,或者 “featureId_N”(其中 N 是 featureIds 数组中的索引),否则 指定。EXT_feature_metadata没有 label 字段,因此 要素 ID 集始终标记为“featureId_N”,其中 N 是 所有特征 ID 的列表,其中特征 ID 属性列在前面 特征 ID 纹理。
如果 featureIdLabel 设置为整数 N,则将其转换为 字符串 “featureId_N” 自动。如果每个基元和 存在每个实例的功能 ID,实例功能 ID 采用 优先权。
Experimental
此功能使用的是 3D Tiles 规范的一部分,该规范不是最终版本,并且可能会在没有 Cesium 标准弃用策略的情况下进行更改。
heightReference : HeightReference
-
Default Value:
{HeightReference.NONE}
-
Default Value:
undefined
See:
imageBasedLighting : ImageBasedLighting
如果 instanceFeatureIdLabel 设置为整数 N,则将其转换为 字符串 “instanceFeatureId_N” 自动。 如果每个基元和每个实例的特征 ID 都存在,则 实例功能 ID 优先。
Experimental
此功能使用的是 3D Tiles 规范的一部分,该规范不是最终版本,并且可能会在没有 Cesium 标准弃用策略的情况下进行更改。
lightColor : Cartesian3
undefined
the scene's light color is used instead.
通过设置
model.imageBasedLighting.imageBasedLightingFactor = 新笛卡尔2(0.0, 0.0)
将使模型更暗。在这里,增加光源的强度将使模型更亮。
-
Default Value:
undefined
Model#minimumPixelSize
的上限,确保模型
从来都不是一个不合理的比例。
0.0
时,不强制使用最小大小。
-
Default Value:
0.0
modelMatrix : Matrix4
Transforms.eastNorthUpToFixedFrame
提供。
-
Default Value:
Matrix4.IDENTITY
Example:
const origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0);
m.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
outlineColor : Color
-
Default Value:
Color.BLACK
pointCloudShading : PointCloudShading
Cesium3DTileset
.
true
,则此模型已准备好渲染,即外部二进制文件 image、
下载了着色器文件并创建了 WebGL 资源。
-
Default Value:
false
readonly readyEvent : Event
Model
的实例。
如果 Model.incrementallyLoadTextures
为 true,则在所有纹理加载并准备好渲染之前,将引发此事件。订阅 Model.texturesReadyEvent
以在纹理准备就绪时收到通知。
-
Default Value:
1.0
-
Default Value:
ShadowMode.ENABLED
-
Default Value:
true
-
Default Value:
false
-
Default Value:
true
silhouetteColor : Color
-
Default Value:
Color.RED
-
Default Value:
0.0
splitDirection : SplitDirection
SplitDirection
。
-
Default Value:
SplitDirection.NONE
CustomShader
,则无法应用。
readonly texturesReadyEvent : Event
Model.incrementallyLoadTextures
为 true,则在加载模型纹理并准备好进行渲染时(即当外部资源
已下载,并且 WebGL 资源已创建。事件侦听器
的实例将传递 Model
的实例。
Methods
static Cesium.Model.fromGltfAsync(options) → Promise.<Model>
从 glTF 资产异步创建模型。此函数返回一个 promise,该 promise 在模型准备好渲染时进行解析,即当外部二进制文件 image 和 并下载着色器文件并创建 WebGL 资源。
模型可以是扩展名为 .gltf 的传统 glTF 资产,也可以是扩展名为 .glb 的二进制 glTF。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Object 具有以下属性:
|
Returns:
Throws:
-
RuntimeError : The model failed to load.
-
RuntimeError : Unsupported glTF version.
-
RuntimeError : Unsupported glTF Extension
Examples:
// Load a model and add it to the scene
try {
const model = await Cesium.Model.fromGltfAsync({
url: "../../SampleData/models/CesiumMan/Cesium_Man.glb"
});
viewer.scene.primitives.add(model);
} catch (error) {
console.log(`Failed to load model. ${error}`);
}
// Position a model with modelMatrix and display it with a minimum size of 128 pixels
const position = Cesium.Cartesian3.fromDegrees(
-123.0744619,
44.0503706,
5000.0
);
const headingPositionRoll = new Cesium.HeadingPitchRoll();
const fixedFrameTransform = Cesium.Transforms.localFrameToFixedFrameGenerator(
"north",
"west"
);
try {
const model = await Cesium.Model.fromGltfAsync({
url: "../../SampleData/models/CesiumAir/Cesium_Air.glb",
modelMatrix: Cesium.Transforms.headingPitchRollToFixedFrame(
position,
headingPositionRoll,
Cesium.Ellipsoid.WGS84,
fixedFrameTransform
),
minimumPixelSize: 128,
});
viewer.scene.primitives.add(model);
} catch (error) {
console.log(`Failed to load model. ${error}`);
}
// Load a model and play the last animation at half speed
let animations;
try {
const model = await Cesium.Model.fromGltfAsync({
url: "../../SampleData/models/CesiumMan/Cesium_Man.glb",
gltfCallback: gltf => {
animations = gltf.animations
}
});
viewer.scene.primitives.add(model);
model.readyEvent.addEventListener(() => {
model.activeAnimations.add({
index: animations.length - 1,
loop: Cesium.ModelAnimationLoop.REPEAT,
multiplier: 0.5,
});
});
} catch (error) {
console.log(`Failed to load model. ${error}`);
}
Throws:
-
DeveloperError : The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.
一旦对象被销毁,就不应该使用它;调用
isDestroyed
将导致 DeveloperError
异常。 因此
将返回值 (undefined
) 分配给对象,如示例中所示。
Throws:
-
DeveloperError : 这个物体被摧毁了,destroy().
Example:
model = model && model.destroy();
See:
Name | Type | Description |
---|---|---|
extensionName |
string | 扩展的名称 |
Returns:
Throws:
-
DeveloperError : 模型未加载。使用 Model.readyEvent 或等待 Model.ready 为 true。
Experimental
此功能不是最终的,在没有 Cesium 的标准弃用政策的情况下可能会发生变化。
getNode(name) → ModelNode
名称
的节点。这用于
修改用户定义的动画的节点变换。
Name | Type | Description |
---|---|---|
name |
string | glTF 中节点的名称。 |
Returns:
该名称
的节点,则为 undefined
。
Throws:
-
DeveloperError : 模型未加载。 使用 Model.readyEvent 或等待 Model.ready 为 true。
Example:
// Apply non-uniform scale to node "Hand"
const node = model.getNode("Hand");
node.matrix = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(5.0, 1.0, 1.0), node.matrix);
Returns:
true
,则为 false
。
See:
Model#style
标记为 dirty,这将强制执行所有特征
在下一帧中重新评估样式,模型可见。
Name | Type | Description |
---|---|---|
articulationStageKey |
string | 关节的名称、空格和舞台的名称。 |
value |
number | 此发音阶段的数值。 |
Throws:
-
DeveloperError : The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.
Example:
// Sets the value of the stage named "MoveX" belonging to the articulation named "SampleArticulation"
model.setArticulationStage("SampleArticulation MoveX", 50.0);
See:
Throws:
-
RuntimeError : Failed to load external reference.
Type Definitions
Name | Type | Description |
---|---|---|
gltf |
object | gltf 对象 |