This sample shows how to import 3D models into a SceneLayer and persist those changes into the SceneLayer and its associated FeatureLayer. Importing a model consists of a few steps
- Uploading a model file (for example a glb or fbx file) and converting it to a Mesh
- Placing the mesh in the view
- Persisting the model into the SceneLayer and its associated feature layer
The sample also directs you to the necessary resources to learn how to set up and configure a SceneLayer that supports this workflow.
Placing the model
You can create a mesh from a file using the scene
method. To make the model visible, we must also place the mesh geometry into a graphic on the view. In this sample we manage this graphic with a SketchViewModel. This makes the model immediately editable and allows you to control the placement of the model. We get the mesh into the SketchViewModel using the sketch
method.
const mesh = await sceneLayer.convertMesh([file]);
sketchVM.place(mesh, {
graphicProperties: {
layer: sketchLayer,
}
});
Persisting the changes
After the model is placed you can persist the changes using the scene
method.
When updating or deleting features, each item must have a valid object
or global
corresponding to the feature being changed.
await sceneLayer.applyEdits({
addFeatures: graphics
});
await sceneLayer.applyEdits({
updateFeatures: graphics
});
await sceneLayer.applyEdits({
deleteFeatures: ids
});
Note that update
does not add features that are not already present in the SceneLayer, for those features you must use add
.
Publish SceneLayer and rebuild cache
Follow these steps to publish a scene layer with GLB format enabled.
Edits to scene layers are applied directly from their associated feature service and support a limited number of edits until you need to rebuild the cache.
This concept allows access to individual features with their geometry with Scene
, while benefiting from optimized display through scene layer caching.