Model.fromGltfAsync. Do not call the constructor directly.
NT 0 支持 glTF 资产,扩展如下:
- AGI_articulations
- CESIUM_primitive_outline
- CESIUM_RTC
- EXT_instance_features
- EXT_mesh_features
- EXT_mesh_gpu_instancing
- EXT_mesh_primitive_restart
- 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 扩展的压缩纹理的模型,我们推荐两个维度的纹理功率 for maximum compatibility. This is because some samplers require power of 2 textures (Using textures in WebGL) and KHR_texture_basisu requires multiple of 4 dimensions (KHR_texture_basisu additional requirements).
Demo:
See:
Members
readonly activeAnimations : ModelAnimationCollection
Model#color
is translucent or Model#silhouetteSize is greater than 0.0.
-
Default Value:
true
readonly boundingSphere : BoundingSphere
Model#minimumPixelSize.
-
Default Value:
true
readonly classificationType : ClassificationType
此外,还有一些要求/限制:
- The glTF cannot contain morph targets, skins, or animations.
- The glTF cannot contain the
EXT_mesh_gpu_instancingextension. - Only meshes with TRIANGLES can be used to classify other assets.
- The meshes must be watertight.
- The POSITION attribute is required.
- If feature IDs and an index buffer are both present, all indices with the same feature id must occupy contiguous sections of the index buffer.
- If feature IDs are present without an index buffer, all positions with the same feature id must occupy contiguous sections of the position buffer.
接受分类的3D梯或地形必须不透明.
-
Default Value:
undefined
Experimental
This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
clippingPlanes : ClippingPlaneCollection
ClippingPlaneCollection used to selectively disable rendering the model.
clippingPolygons : ClippingPolygonCollection
ClippingPolygonCollection used to selectively disable rendering the model.
color : Color
-
Default Value:
undefined
-
Default Value:
0.5
colorBlendMode : Cesium3DTileColorBlendMode|ColorBlendMode
-
Default Value:
ColorBlendMode.HIGHLIGHT
readonly credit : Credit
customShader : CustomShader
Cesium3DTileStyle
可能导致未定义的行为.
Experimental
This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
绘制模型中每个绘图命令的边框.
-
Default Value:
false
在线框中绘制模型.
-
Default Value:
false
distanceDisplayCondition : DistanceDisplayCondition
-
Default Value:
undefined
true, the model is exaggerated along the ellipsoid normal when Scene.verticalExaggeration is set to a value other than 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:
// Change the ground color used for a model's environment map to a forest green
const environmentMapManager = model.environmentMapManager;
environmentMapManager.groundColor = Cesium.Color.fromCssColorString("#203b34");
readonly errorEvent : Event
ModelError.
对于EXT mesh features,这是特性ID的标签属性,或 “ featureId N”(其中N是特性Ids阵列中的索引) 当不是时 页:1 EXT feature metadata 没有标签字段, 因此 特性 ID 集总是标注“ featureId N ” ,其中 N 是索引 全部特性ID的列表,其中特性 ID 属性在前面列出 特性标识纹理.
如果特性IdLabel设定为整数 N,则转换为 字符串“ featureId N” 自动。 如果两者兼有 存在 per-instance 特征 ID , 实例 特征 ID 使用 priority.
Experimental
This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
heightReference : HeightReference
-
Default Value:
{HeightReference.NONE}
-
Default Value:
undefined
See:
imageBasedLighting : ImageBasedLighting
如果实例FeatureIdLabel设定为整数 N,则转换为 字符串“ InstanceFeatureId N” 自动. 如果有每个原始特征的识别码和普通特征的识别码,则 实例特征标识优先.
Experimental
This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
lightColor : Cartesian3
通过设置使额外光源失效
model.imageBasedLighting.imageBasedLightingFactor = new Cartesian2(0.0, 0.0)
这会让模型变得更加黑暗。 在这里,增加光源的强度将使模型更亮.
-
Default Value:
undefined
Model#minimumPixelSize, ensuring that the model
绝不是一个不合理的尺度.
-
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.
-
Default Value:
false
readonly readyEvent : Event
Model.
If Model.incrementallyLoadTextures is true, this event will be raised before all textures are loaded and ready for rendering. Subscribe to Model.texturesReadyEvent to be notified when the textures are ready.
Model#modelMatrix.
大于 NT 0 1.0 NT 1 的值增加模型大小; 值
小于 NT 0 1.0 NT 1 减少.
-
Default Value:
1.0
shadows : ShadowMode
-
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
style : Cesium3DTileStyle
CustomShader is also applied.
readonly texturesReadyEvent : Event
Model.incrementallyLoadTextures is true, is raised when the model textures are loaded and ready for rendering, i.e. when the external resources
have been downloaded and the WebGL resources are created. Event listeners
are passed an instance of the Model.
Methods
static Cesium.Model.fromGltfAsync(options) → Promise.<Model>
从 glTF 资产中同步创建模型 。 此函数返回一个承诺, 当模型准备好渲染时解析, NT % 0 . 当外部二进制, 图像, 和阴影文件被下载,并创建 WebGL 资源.
该模型可以是一个传统的glTF资产,具有.gltf扩展或使用.glb扩展的二进制glTF.
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
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.
Once an object is destroyed, it should not be used; calling any function other than
isDestroyed will result in a DeveloperError exception. Therefore,
assign the return value (undefined) to the object as done in the example.
Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
Example:
model = model && model.destroy();
See:
| Name | Type | Description |
|---|---|---|
extensionName |
string | 扩展名 |
Returns:
Throws:
-
DeveloperError : The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.
Experimental
This feature is not final and is subject to change without Cesium's standard deprecation policy.
getNode(name) → ModelNode
name in the glTF. This is used to
修改用于用户定义的动画的节点转换.
| Name | Type | Description |
|---|---|---|
name |
string | GlTF 中的节点名称 . |
Returns:
未定义 ,如果与 2 名称 存在节点.
Throws:
-
DeveloperError : The model is not loaded. Use Model.readyEvent or wait for Model.ready to be 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);
If this object was destroyed, it should not be used; calling any function other than
isDestroyed will result in a DeveloperError exception.
Returns:
true if this object was destroyed; otherwise, false.
See:
| 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:
Viewer or CesiumWidget render the scene to
获得使这个原始化所需的绘图命令.
不要直接调用此函数 。 记录下来的只是 列出场景拍摄时可能宣传的例外情况:
Throws:
-
RuntimeError : Failed to load external reference.