new Model()
Model.fromGltfAsync. Do not call the constructor directly.
SuperMap3D supports glTF assets with the following extensions:
Note: for models with compressed textures using the KHR_texture_basisu extension, we recommend power of 2 textures in both dimensions 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).
- See:
Members
-
readonly activeAnimationsModelAnimationCollection
-
The currently playing glTF animations.
-
activeAnimationsModelAnimationCollection
-
The currently playing glTF animations.
-
readonly allowPickingBoolean
-
When
true, each glTF mesh and primitive is pickable withScene#pick. Whenfalse, GPU memory is saved.- Default Value: true
readonly asynchronousBoolean
Determines if model WebGL resource creation will be spread out over several frames or block until completion once all glTF files are loaded.
- Default Value: true
backFaceCullingboolean
Whether to cull back-facing geometry. When true, back face culling is
determined by the material's doubleSided property; when false, back face
culling is disabled. Back faces are not culled if Model#color
is translucent or Model#silhouetteSize is greater than 0.0.
- Default Value: true
readonly basePathString
The base path that paths in the glTF JSON are relative to. The base
path is the same path as the path containing the .gltf file
minus the .gltf file, when binary, image, and shader files are
in the same directory as the .gltf. When this is '',
the app's base path is used.
- Default Value: ''
readonly boundingSphereBoundingSphere
Gets the model's bounding sphere in world space. This does not take into account
glTF animations, skins, or morph targets. It also does not account for
Model#minimumPixelSize.
readonly boundingSphereBoundingSphere
The model's bounding sphere in its local coordinate system. This does not take into
account glTF animations and skins nor does it take into account Model#minimumPixelSize.
- Default Value: undefined
Example
// Center in WGS84 coordinates
var center = SuperMap3D.Matrix4.multiplyByPoint(model.modelMatrix, model.boundingSphere.center, new SuperMap3D.Cartesian3());
clampAnimationsboolean
Determines if the model's animations should hold a pose over frames where no keyframes are specified.
- Default Value: true
clampAnimationsBoolean
Determines if the model's animations should hold a pose over frames where no keyframes are specified.
readonly classificationTypeClassificationType
Gets the model's classification type. This determines whether terrain, 3D Tiles, or both will be classified by this model.
Additionally, there are a few requirements/limitations:
- 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.
The 3D Tiles or terrain receiving the classification must be opaque.
- Default Value: undefined
clippingPlanesClippingPlaneCollection
The ClippingPlaneCollection used to selectively disable rendering the model.
clippingPlanesClippingPlaneCollection
The ClippingPlaneCollection used to selectively disable rendering the model.
colorColor
The color to blend with the model's rendered color.
- Default Value: undefined
colorColor
A color that blends with the model's rendered color.
- Default Value: Color.WHITE
colorBlendAmountnumber
Value used to determine the color strength when the colorBlendMode is MIX. 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.
- Default Value: 0.5
colorBlendAmountNumber
Value used to determine the color strength when the colorBlendMode is MIX.
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.
- Default Value: 0.5
colorBlendModeCesium3DTileColorBlendMode ColorBlendMode
Defines how the color blends with the model.
- Default Value: ColorBlendMode.HIGHLIGHT
colorBlendModeColorBlendMode
Defines how the color blends with the model.
- Default Value: ColorBlendMode.HIGHLIGHT
readonly creditCredit
Gets the credit that will be displayed for the model.
customShaderCustomShader
The model's custom shader, if it exists. Using custom shaders with a Cesium3DTileStyle
may lead to undefined behavior.
debugShowBoundingVolumeboolean
This property is for debugging only; it is not for production use nor is it optimized.
Draws the bounding sphere for each draw command in the model.
- Default Value: false
debugShowBoundingVolumeBoolean
This property is for debugging only; it is not for production use nor is it optimized.
Draws the bounding sphere for each draw command in the model. A glTF primitive corresponds to one draw command. A glTF mesh has an array of primitives, often of length one.
- Default Value: false
debugWireframeboolean
This property is for debugging only; it is not for production use nor is it optimized.
Draws the model in wireframe.
- Default Value: false
debugWireframeBoolean
This property is for debugging only; it is not for production use nor is it optimized.
Draws the model in wireframe.
- Default Value: false
distanceDisplayConditionDistanceDisplayCondition
Gets or sets the distance display condition, which specifies at what distance from the camera this model will be displayed.
- Default Value: undefined
distanceDisplayConditionDistanceDisplayCondition
Gets or sets the condition specifying at what distance from the camera that this model will be displayed.
- Default Value: undefined
readonly errorEventEvent
Gets an event that is raised when the model encounters an asynchronous rendering error. By subscribing
to the event, you will be notified of the error and can potentially recover from it. Event listeners
are passed an instance of ModelError.
featureIdLabelstring
Label of the feature ID set to use for picking and styling.
For EXT_mesh_features, this is the feature ID's label property, or "featureId_N" (where N is the index in the featureIds array) when not specified. EXT_feature_metadata did not have a label field, so such feature ID sets are always labeled "featureId_N" where N is the index in the list of all feature Ids, where feature ID attributes are listed before feature ID textures.
If featureIdLabel is set to an integer N, it is converted to the string "featureId_N" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.
readonly gltfObject
The object for the glTF JSON, including properties with default values omitted from the JSON provided to this model.
- Default Value: undefined
heightReferenceHeightReference
The height reference of the model, which determines how the model is drawn relative to terrain.
- Default Value: {HeightReference.NONE}
heightReferenceHeightReference
Returns the height reference of the model
- Default Value: HeightReference.NONE
idobject
A user-defined object that is returned when the model is picked.
- Default Value: undefined
idObject
User-defined object returned when the model is picked.
- Default Value: undefined
imageBasedLightingImageBasedLighting
The properties for managing image-based lighting on this model.
imageBasedLightingFactorCartesian2
SuperMap3D adds lighting from the earth, sky, atmosphere, and star skybox. This cartesian is used to scale the final diffuse and specular lighting contribution from those sources to the final color. A value of 0.0 will disable those light sources.
- Default Value: Cartesian2(1.0, 1.0)
readonly incrementallyLoadTexturesBoolean
Determine if textures may continue to stream in after the model is loaded.
- Default Value: true
instanceFeatureIdLabelstring
Label of the instance feature ID set used for picking and styling.
If instanceFeatureIdLabel is set to an integer N, it is converted to the string "instanceFeatureId_N" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.
lightColorCartesian3
The light color when shading the model. When undefined the scene's light color is used instead.
Disabling additional light sources by setting
model.imageBasedLighting.imageBasedLightingFactor = new Cartesian2(0.0, 0.0)
will make the model much darker. Here, increasing the intensity of the light source will make the model brighter.
- Default Value: undefined
lightColorCartesian3
The color and intensity of the sunlight used to shade the model.
For example, disabling additional light sources by setting model.imageBasedLightingFactor = new SuperMap3D.Cartesian2(0.0, 0.0) will make the
model much darker. Here, increasing the intensity of the light source will make the model brighter.
- Default Value: undefined
luminanceAtZenithNumber
The sun's luminance at the zenith in kilo candela per meter squared to use for this model's procedural environment map.
This is used when Model#specularEnvironmentMaps and Model#sphericalHarmonicCoefficients are not defined.
- Default Value: 0.5
maximumScalenumber
The maximum scale size for a model. This can be used to give
an upper limit to the Model#minimumPixelSize, ensuring that the model
is never an unreasonable scale.
maximumScaleNumber
The maximum scale size for a model. This can be used to give
an upper limit to the Model#minimumPixelSize, ensuring that the model
is never an unreasonable scale.
minimumPixelSizenumber
The approximate minimum pixel size of the model regardless of zoom.
This can be used to ensure that a model is visible even when the viewer
zooms out. When 0.0, no minimum size is enforced.
- Default Value: 0.0
minimumPixelSizeNumber
The approximate minimum pixel size of the model regardless of zoom.
This can be used to ensure that a model is visible even when the viewer
zooms out. When 0.0, no minimum size is enforced.
- Default Value: 0.0
modelMatrixMatrix4
The 4x4 transformation matrix that transforms the model from model to world coordinates.
When this is the identity matrix, the model is drawn in world coordinates, i.e., Earth's Cartesian WGS84 coordinates.
Local reference frames can be used by providing a different transformation matrix, like that returned
by Transforms.eastNorthUpToFixedFrame.
- Default Value:
Matrix4.IDENTITYExample
const origin = SuperMap3D.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0);
m.modelMatrix = SuperMap3D.Transforms.eastNorthUpToFixedFrame(origin);
modelMatrixMatrix4
The 4x4 transformation matrix that transforms the model from model to world coordinates.
When this is the identity matrix, the model is drawn in world coordinates, i.e., Earth's WGS84 coordinates.
Local reference frames can be used by providing a different transformation matrix, like that returned
by Transforms.eastNorthUpToFixedFrame.
- Default Value:
Matrix4.IDENTITYExample
var origin = SuperMap3D.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0);
m.modelMatrix = SuperMap3D.Transforms.eastNorthUpToFixedFrame(origin);
outlineColorColor
The color to use when rendering outlines.
- Default Value: Color.BLACK
readonly pendingTextureLoadsNumber
Return the number of pending texture loads.
pointCloudShadingPointCloudShading
Point cloud shading settings for controlling point cloud attenuation
and lighting. For 3D Tiles, this is inherited from the
Cesium3DTileset.
readonly readyboolean
When true, this model is ready to render, i.e., the external binary, image,
and shader files were downloaded and the WebGL resources were created.
- Default Value: false
readonly readyBoolean
When true, this model is ready to render, i.e., the external binary, image,
and shader files were downloaded and the WebGL resources were created. This is set to
true right before Model#readyPromise is resolved.
- Default Value: false
readonly readyEventEvent
Gets an event that is raised when the model is 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.
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.
Gets the promise that will be resolved when this model is ready to render, i.e., when the external binary, image, and shader files were downloaded and the WebGL resources were created.
This promise is resolved at the end of the frame before the first frame the model is rendered in.
- See:
Example
// Play all animations at half-speed when the model is ready to render
Promise.resolve(model.readyPromise).then(function(model) {
model.activeAnimations.addAll({
multiplier : 0.5
});
}).catch(function(error){
window.alert(error);
});
scalenumber
A uniform scale applied to this model before the Model#modelMatrix.
Values greater than 1.0 increase the size of the model; values
less than 1.0 decrease.
- Default Value: 1.0
scaleNumber
A uniform scale applied to this model before the Model#modelMatrix.
Values greater than 1.0 increase the size of the model; values
less than 1.0 decrease.
- Default Value: 1.0
shadowsShadowMode
Determines whether the model casts or receives shadows from light sources.
- Default Value: ShadowMode.ENABLED
shadowsShadowMode
Determines whether the model casts or receives shadows from each light source.
- Default Value: ShadowMode.ENABLED
showboolean
Whether or not to render the model.
- Default Value: true
showBoolean
Determines if the model primitive will be shown.
- Default Value: true
showCreditsOnScreenboolean
Gets or sets whether the credits of the model will be displayed on the screen.
- Default Value: false
showOutlineboolean
Whether to display the outline for models using the
extension. When true, outlines are displayed. When false, outlines are not displayed.
- Default Value: true
silhouetteColorColor
The silhouette color.
- Default Value: Color.RED
silhouetteColorColor
The silhouette color.
- Default Value: Color.RED
silhouetteSizenumber
The size of the silhouette in pixels.
- Default Value: 0.0
silhouetteSizeNumber
The size of the silhouette in pixels.
- Default Value: 0.0
specularEnvironmentMapsString
A URL to a KTX file that contains a cube map of the specular lighting and the convoluted specular mipmaps.
sphericalHarmonicCoefficientsArray.<Cartesian3>
The third order spherical harmonic coefficients used for the diffuse color of image-based lighting. When undefined, a diffuse irradiance
computed from the atmosphere color is used.
There are nine Cartesian3 coefficients.
The order of the coefficients is: L00, L1-1, L10, L11, L2-2, L2-1, L20, L21, L22
These values can be obtained by preprocessing the environment map using the cmgen tool of
Google's Filament project. This will also generate a KTX file that can be
supplied to to apply to this model.
- Default Value:
SplitDirection.NONEstyleCesium3DTileStyle
The style to apply to the features in the model. Cannot be applied if a CustomShader is also applied.
readonly texturesReadyEventEvent
Gets an event that, if 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 fromGltf(options){Model}
-
Creates a model from a glTF asset. When the model is ready to render, i.e., when the external binary, image, and shader files are downloaded and the WebGL resources are created, the
Model#readyPromiseis resolved.The model can be a traditional glTF asset with a .gltf extension or a Binary glTF using the .glb extension.
SuperMap3D supports glTF assets with the following extensions:
SUPERMAP3D_RTC_MODELVIEW parameter semantic that says the node is in WGS84 coordinates translated relative to a local origin.
Name Type Description optionsObject Object with the following properties:
Name Type Default Description urlResource | String The url to the .gltf file.
basePathResource | String 可选 The base path that paths in the glTF JSON are relative to.
showBoolean true 可选 Determines if the model primitive will be shown.
modelMatrixMatrix4 Matrix4.IDENTITY 可选 The 4x4 transformation matrix that transforms the model from model to world coordinates.
scaleNumber 1.0 可选 A uniform scale applied to this model.
minimumPixelSizeNumber 0.0 可选 The approximate minimum pixel size of the model regardless of zoom.
maximumScaleNumber 可选 The maximum scale for the model.
idObject 可选 A user-defined object to return when the model is picked with
Scene#pick.allowPickingBoolean true 可选 When
true, each glTF mesh and primitive is pickable withScene#pick.incrementallyLoadTexturesBoolean true 可选 Determine if textures may continue to stream in after the model is loaded.
asynchronousBoolean true 可选 Determines if model WebGL resource creation will be spread out over several frames or block until completion once all glTF files are loaded.
clampAnimationsBoolean true 可选 Determines if the model's animations should hold a pose over frames where no keyframes are specified.
shadowsShadowMode ShadowMode.ENABLED 可选 Determines whether the model casts or receives shadows from each light source.
debugShowBoundingVolumeBoolean false 可选 For debugging only. Draws the bounding sphere for each
DrawCommandin the model.debugWireframeBoolean false 可选 For debugging only. Draws the model in wireframe.
heightReferenceHeightReference 可选 Determines how the model is drawn relative to terrain.
sceneScene 可选 Must be passed in for models that use the height reference property.
distanceDisplayConditionDistanceDisplayCondition 可选 The condition specifying at what distance from the camera that this model will be displayed.
colorColor Color.WHITE 可选 A color that blends with the model's rendered color.
colorBlendModeColorBlendMode ColorBlendMode.HIGHLIGHT 可选 Defines how the color blends with the model.
colorBlendAmountNumber 0.5 可选 Value used to determine the color strength when the
colorBlendModeisMIX. 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.silhouetteColorColor Color.RED 可选 The silhouette color. If more than 256 models have silhouettes enabled, there is a small chance that overlapping models will have minor artifacts.
silhouetteSizeNumber 0.0 可选 The size of the silhouette in pixels.
clippingPlanesClippingPlaneCollection 可选 The
ClippingPlaneCollectionused to selectively disable rendering the model.dequantizeInShaderBoolean true 可选 Determines if a Draco encoded model is dequantized on the GPU. This decreases total memory usage for encoded models.
Returns:
Type Description Model The newly created model. Examples
// Example 1. Create a model from a glTF asset var model = scene.primitives.add(SuperMap3D.Model.fromGltf({ url : './duck/duck.gltf' }));// Example 2. Create model and provide all properties and events var origin = SuperMap3D.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0); var modelMatrix = SuperMap3D.Transforms.eastNorthUpToFixedFrame(origin); var model = scene.primitives.add(SuperMap3D.Model.fromGltf({ url : './duck/duck.gltf', show : true, // default modelMatrix : modelMatrix, scale : 2.0, // double size minimumPixelSize : 128, // never smaller than 128 pixels maximumScale: 20000, // never larger than 20000 * model size (overrides minimumPixelSize) allowPicking : false, // not pickable debugShowBoundingVolume : false, // default debugWireframe : false })); model.readyPromise.then(function(model) { // Play all animations when the model is ready to render model.activeAnimations.addAll(); }); -
static fromGltfAsync(options){Promise.<Model>}
-
Asynchronously creates a model from a glTF asset. This function returns a promise that resolves when the model is ready to render, i.e., when the external binary, image, and shader files are downloaded and the WebGL resources are created.
The model can be a traditional glTF asset with a .gltf extension or a Binary glTF using the .glb extension.
Name Type Description optionsobject Object with the following properties:
Name Type Default Description urlstring | Resource The url to the .gltf or .glb file.
basePathstring | Resource '' 可选 The base path that paths in the glTF JSON are relative to.
showboolean true 可选 Whether or not to render the model.
modelMatrixMatrix4 Matrix4.IDENTITY 可选 The 4x4 transformation matrix that transforms the model from model to world coordinates.
scalenumber 1.0 可选 A uniform scale applied to this model.
minimumPixelSizenumber 0.0 可选 The approximate minimum pixel size of the model regardless of zoom.
maximumScalenumber 可选 The maximum scale size of a model. An upper limit for minimumPixelSize.
idobject 可选 A user-defined object to return when the model is picked with
Scene#pick.allowPickingboolean true 可选 When
true, each primitive is pickable withScene#pick.incrementallyLoadTexturesboolean true 可选 Determine if textures may continue to stream in after the model is loaded.
asynchronousboolean true 可选 Determines if model WebGL resource creation will be spread out over several frames or block until completion once all glTF files are loaded.
clampAnimationsboolean true 可选 Determines if the model's animations should hold a pose over frames where no keyframes are specified.
shadowsShadowMode ShadowMode.ENABLED 可选 Determines whether the model casts or receives shadows from light sources.
releaseGltfJsonboolean false 可选 When true, the glTF JSON is released once the glTF is loaded. This is is especially useful for cases like 3D Tiles, where each .gltf model is unique and caching the glTF JSON is not effective.
debugShowBoundingVolumeboolean false 可选 For debugging only. Draws the bounding sphere for each draw command in the model.
enableDebugWireframeboolean false 可选 For debugging only. This must be set to true for debugWireframe to work in WebGL1. This cannot be set after the model has loaded.
debugWireframeboolean false 可选 For debugging only. Draws the model in wireframe. Will only work for WebGL1 if enableDebugWireframe is set to true.
cullboolean true 可选 Whether or not to cull the model using frustum/horizon culling. If the model is part of a 3D Tiles tileset, this property will always be false, since the 3D Tiles culling system is used.
opaquePassboolean Pass.OPAQUE 可选 The pass to use in the
DrawCommandfor the opaque portions of the model.upAxisAxis Axis.Y 可选 The up-axis of the glTF model.
forwardAxisAxis Axis.Z 可选 The forward-axis of the glTF model.
customShaderCustomShader 可选 A custom shader. This will add user-defined GLSL code to the vertex and fragment shaders. Using custom shaders with a
Cesium3DTileStylemay lead to undefined behavior.contentCesium3DTileContent 可选 The tile content this model belongs to. This property will be undefined if model is not loaded as part of a tileset.
heightReferenceHeightReference HeightReference.NONE 可选 Determines how the model is drawn relative to terrain.
sceneScene 可选 Must be passed in for models that use the height reference property.
distanceDisplayConditionDistanceDisplayCondition 可选 The condition specifying at what distance from the camera that this model will be displayed.
colorColor 可选 A color that blends with the model's rendered color.
colorBlendModeColorBlendMode ColorBlendMode.HIGHLIGHT 可选 Defines how the color blends with the model.
colorBlendAmountnumber 0.5 可选 Value used to determine the color strength when the
colorBlendModeisMIX. 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.silhouetteColorColor Color.RED 可选 The silhouette color. If more than 256 models have silhouettes enabled, there is a small chance that overlapping models will have minor artifacts.
silhouetteSizenumber 0.0 可选 The size of the silhouette in pixels.
enableShowOutlineboolean true 可选 Whether to enable outlines for models using the CESIUM_primitive_outline extension. This can be set false to avoid post-processing geometry at load time. When false, the showOutlines and outlineColor options are ignored.
showOutlineboolean true 可选 Whether to display the outline for models using the CESIUM_primitive_outline extension. When true, outlines are displayed. When false, outlines are not displayed.
outlineColorColor Color.BLACK 可选 The color to use when rendering outlines.
clippingPlanesClippingPlaneCollection 可选 The
ClippingPlaneCollectionused to selectively disable rendering the model.lightColorCartesian3 可选 The light color when shading the model. When
undefinedthe scene's light color is used instead.imageBasedLightingImageBasedLighting 可选 The properties for managing image-based lighting on this model.
backFaceCullingboolean true 可选 Whether to cull back-facing geometry. When true, back face culling is determined by the material's doubleSided property; when false, back face culling is disabled. Back faces are not culled if the model's color is translucent.
creditCredit | string 可选 A credit for the data source, which is displayed on the canvas.
showCreditsOnScreenboolean false 可选 Whether to display the credits of this model on screen.
splitDirectionSplitDirection SplitDirection.NONE 可选 The
SplitDirectionsplit to apply to this model.projectTo2Dboolean false 可选 Whether to accurately project the model's positions in 2D. If this is true, the model will be projected accurately to 2D, but it will use more memory to do so. If this is false, the model will use less memory and will still render in 2D / CV mode, but its positions may be inaccurate. This disables minimumPixelSize and prevents future modification to the model matrix. This also cannot be set after the model has loaded.
enablePickboolean false 可选 Whether to allow with CPU picking with
pickwhen not using WebGL 2 or above. If using WebGL 2 or above, this option will be ignored. If using WebGL 1 and this is true, thepickoperation will work correctly, but it will use more memory to do so. If running with WebGL 1 and this is false, the model will use less memory, butpickwill always returnundefined. This cannot be set after the model has loaded.featureIdLabelstring | number "featureId_0" 可选 Label of the feature ID set to use for picking and styling. For EXT_mesh_features, this is the feature ID's label property, or "featureId_N" (where N is the index in the featureIds array) when not specified. EXT_feature_metadata did not have a label field, so such feature ID sets are always labeled "featureId_N" where N is the index in the list of all feature Ids, where feature ID attributes are listed before feature ID textures. If featureIdLabel is an integer N, it is converted to the string "featureId_N" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.
instanceFeatureIdLabelstring | number "instanceFeatureId_0" 可选 Label of the instance feature ID set used for picking and styling. If instanceFeatureIdLabel is set to an integer N, it is converted to the string "instanceFeatureId_N" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.
pointCloudShadingobject 可选 Options for constructing a
PointCloudShadingobject to control point attenuation and lighting.classificationTypeClassificationType 可选 Determines whether terrain, 3D Tiles or both will be classified by this model. This cannot be set after the model has loaded.
gltfCallbackModel.GltfCallback 可选 A function that is called with the loaded gltf object once loaded.
Throws:
-
-
The model failed to load.
- Type
- RuntimeError
-
-
-
Unsupported glTF version.
- Type
- RuntimeError
-
-
-
Unsupported glTF Extension
- Type
- RuntimeError
-
Returns:
Type Description Promise.<Model> A promise that resolves to the created model when it is ready to render. Examples
// Load a model and add it to the scene try { const model = await SuperMap3D.Model.fromGltfAsync({ url: "./duck/duck.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 = SuperMap3D.Cartesian3.fromDegrees( -123.0744619, 44.0503706, 5000.0 ); const headingPositionRoll = new SuperMap3D.HeadingPitchRoll(); const fixedFrameTransform = SuperMap3D.Transforms.localFrameToFixedFrameGenerator( "north", "west" ); try { const model = await SuperMap3D.Model.fromGltfAsync({ url: "./duck/duck.glb", modelMatrix: SuperMap3D.Transforms.headingPitchRollToFixedFrame( position, headingPositionRoll, SuperMap3D.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 SuperMap3D.Model.fromGltfAsync({ url: "./duck/duck.glb", gltfCallback: gltf => { animations = gltf.animations } }); viewer.scene.primitives.add(model); model.readyEvent.addEventListener(() => { model.activeAnimations.add({ index: animations.length - 1, loop: SuperMap3D.ModelAnimationLoop.REPEAT, multiplier: 0.5, }); }); } catch (error) { console.log(`Failed to load model. ${error}`); } -
-
static silhouetteSupported(scene){Boolean}
-
Determines if silhouettes are supported.
Name Type Description sceneScene The scene.
Returns:
Type Description Boolean trueif silhouettes are supported; otherwise, returnsfalse -
applyArticulations()
-
Applies any modified articulation stages to the matrix of each node that participates in any articulation. Note that this will overwrite any node transformations on participating nodes.
Throws:
-
The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.
- Type
- DeveloperError
-
-
destroy()
-
Destroys the WebGL resources held by this object. Destroying an object allows for deterministic release of WebGL resources, instead of relying on the garbage collector to destroy this object.
Once an object is destroyed, it should not be used; calling any function other thanisDestroyedwill result in aDeveloperErrorexception. Therefore, assign the return value (undefined) to the object as done in the example.- See:
Throws:
-
This object was destroyed, i.e., destroy() was called.
- Type
- DeveloperError
Example
model = model && model.destroy(); -
destroy()
-
Destroys the WebGL resources held by this object. Destroying an object allows for deterministic release of WebGL resources, instead of relying on the garbage collector to destroy this object.
Once an object is destroyed, it should not be used; calling any function other thanisDestroyedwill result in aDeveloperErrorexception. Therefore, assign the return value (undefined) to the object as done in the example.- See:
Throws:
-
This object was destroyed, i.e., destroy() was called.
- Type
- DeveloperError
Example
model = model && model.destroy(); -
getMaterial(name){ModelMaterial}
-
Returns the glTF material with the given
nameproperty.Name Type Description nameString The glTF name of the material.
Throws:
-
The model is not loaded. Use Model.readyPromise or wait for Model.ready to be true.
- Type
- DeveloperError
Returns:
Type Description ModelMaterial The material or undefinedif no material withnameexists. -
-
getMesh(name){ModelMesh}
-
Returns the glTF mesh with the given
nameproperty.Name Type Description nameString The glTF name of the mesh.
Throws:
-
The model is not loaded. Use Model.readyPromise or wait for Model.ready to be true.
- Type
- DeveloperError
Returns:
Type Description ModelMesh The mesh or undefinedif no mesh withnameexists. -
-
getNode(name){ModelNode}
-
Returns the node with the given
namein the glTF. This is used to modify a node's transform for user-defined animation.Name Type Description namestring The name of the node in the glTF.
Throws:
-
The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.
- Type
- DeveloperError
Returns:
Type Description ModelNode The node, or undefinedif no node with thenameexists.Example
// Apply non-uniform scale to node "Hand" const node = model.getNode("Hand"); node.matrix = SuperMap3D.Matrix4.fromScale(new SuperMap3D.Cartesian3(5.0, 1.0, 1.0), node.matrix); -
-
getNode(name){ModelNode}
-
Returns the glTF node with the given
nameproperty. This is used to modify a node's transform for animation outside of glTF animations.Name Type Description nameString The glTF name of the node.
Throws:
-
The model is not loaded. Use Model.readyPromise or wait for Model.ready to be true.
- Type
- DeveloperError
Returns:
Type Description ModelNode The node or undefinedif no node withnameexists.Example
// Apply non-uniform scale to node LOD3sp var node = model.getNode('LOD3sp'); node.matrix = SuperMap3D.Matrix4.fromScale(new SuperMap3D.Cartesian3(5.0, 1.0, 1.0), node.matrix); -
-
isDestroyed(){boolean}
-
Returns true if this object was destroyed; otherwise, false.
If this object was destroyed, it should not be used; calling any function other thanisDestroyedwill result in aDeveloperErrorexception.- See:
Returns:
Type Description boolean trueif this object was destroyed; otherwise,false. -
isDestroyed(){Boolean}
-
Returns true if this object was destroyed; otherwise, false.
If this object was destroyed, it should not be used; calling any function other thanisDestroyedwill result in aDeveloperErrorexception.- See:
Returns:
Type Description Boolean trueif this object was destroyed; otherwise,false. -
makeStyleDirty()
-
Marks the model's
Model#styleas dirty, which forces all features to re-evaluate the style in the next frame the model is visible. -
setArticulationStage(articulationStageKey, value)
-
Sets the current value of an articulation stage. After setting one or multiple stage values, call Model.applyArticulations() to cause the node matrices to be recalculated.
Name Type Description articulationStageKeystring The name of the articulation, a space, and the name of the stage.
valuenumber The numeric value of this stage of the articulation.
Throws:
-
The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.
- Type
- DeveloperError
Example
// Sets the value of the stage named "MoveX" belonging to the articulation named "SampleArticulation" model.setArticulationStage("SampleArticulation MoveX", 50.0); -
-
update()
-
Called when
ViewerorWidgetrender the scene to get the draw commands needed to render this primitive.Do not call this function directly. This is documented just to list the exceptions that may be propagated when the scene is rendered:
Throws:
-
Failed to load external reference.
- Type
- RuntimeError
-
-
update()
-
Called when
ViewerorWidgetrender the scene to get the draw commands needed to render this primitive.Do not call this function directly. This is documented just to list the exceptions that may be propagated when the scene is rendered:
Throws:
-
Failed to load external reference.
- Type
- RuntimeError
-
Type Definitions
-
GltfCallback(gltf)
-
Interface for the function that is called with the loaded gltf object once loaded.
Name Type Description gltfobject The gltf object