This sample shows how to upload 3D models into a 3D object layer, and edit them using the SceneLayer class. 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 3D object layer through a SceneLayer instance
The sample also directs you to the necessary resources to learn how to set up 3D object layers that support 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 layer, for those features you must use add
.
Sample workflow
The workflow the sample demonstrates can be broken up into a few steps:
- File loading: The sample implements loading of user files either through a file picker or by dragging and dropping them into a designated area.
- Model uploading: The
upload
function takes a SceneLayer and a File instance, converts the file into a mesh, positions it at the mouse cursor's location using theModel place
method of the SketchViewModel (SVM), and adds it as a Graphic to the GraphicsLayer. - Mesh selection and hiding: When the SVM is updated and a Graphic is selected (the event state is
start
), the sample attempts to hide the model with the sameobject
from the 3D object layer. Two scenarios are possible here:Id - If a new model has been added, it will not yet have an
object
(it will receive it upon being saved to the layer). As a result, no hiding will occur.Id - If an existing model has been retrieved from the 3D object layer (see "Retrieving stored models" below), it will have an
object
and will be hidden from the layer.Id
- If a new model has been added, it will not yet have an
- Adding, updating, and deleting features: Deselecting a Graphic (which can happen after manipulating it) triggers another SVM update with the event state
complete
. At this point, the sample again checks for the presence of theobject
:Id - If it is absent (newly added model)
apply
is used to add the model to the layer. This method assigns anEdits object
to the feature and as an attribute to the Graphic. The model is then hidden from the 3D object layer.Id - If it is present,
apply
is used to update the model's attributes in the database. The updated model is then again displayed from the 3D object layer but the sample hides it as an identical Graphic still exists in the GraphicsLayer, and it is better suited for further manipulation. Pressing the delete key with the Graphic selected, deletes it from the GraphicsLayer, and triggers the SVM (the event state isEdits delete
) to delete the selected model from the 3d object layer usingapply
.Edits
- If it is absent (newly added model)
Retrieving stored models: When a scene is loaded, and a user clicks on a feature already stored in the 3D object layer, the view's hit
method is used to find the feature's object
. It then queries the 3D object layer, retrieves the corresponding Graphic, adds it to the GraphicsLayer, and updates it through the SketchViewModel, which brings us back to step 3.2.
Learn more about 3D object layers
A 3D object layer is a unit consisting of a 3D object scene layer with a 3D object feature layer. The scene layer facilitates efficient display and loading, while the associated feature layer stores the data for editing and querying. This 3D functionality is integrated within the SceneLayer class, allowing you to use Scene
to retrieve results directly from the associated feature layer.