SceneLayer upload 3D models and applyEdits

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

  1. Uploading a model file (for example a glb or fbx file) and converting it to a Mesh
  2. Placing the mesh in the view
  3. 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.

Information
This sample uses a client side definition expression to filter out other users additions. The data get's periodically cleaned.

Placing the model

You can create a mesh from a file using the sceneLayer.convertMesh 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 sketchVM.place method.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
  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 sceneLayer.applyEdits method. When updating or deleting features, each item must have a valid objectId or globalId corresponding to the feature being changed.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
  await sceneLayer.applyEdits({
    addFeatures: graphics
  });

  await sceneLayer.applyEdits({
    updateFeatures: graphics
  });

  await sceneLayer.applyEdits({
    deleteFeatures: ids
  });

Note that updateFeatures does not add features that are not already present in the SceneLayer, for those features you must use addFeatures.

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 SceneLayer.queryFeatures(), while benefiting from optimized display through scene layer caching.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.