1、先找一个3D模型,注意格式
- 3D Max (
.3ds
) - Collada (
.dae
) - Filmbox (
.fbx
) - GL Transmission Format (
.gltf
,.glb
) - Wavefront (
.obj
)
我使用的是glb格式,没有的话用电脑自带的画图工具里面的3D画图随便生成一个。
2、找到模型后放入手机文件夹中,比如
String path3D = Environment.getExternalStorageDirectory().getAbsolutePath() + "/xxx/xxx.glb";
3、创建图层
GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
4、设置一个摆放模型的坐标
Point pierPoint1 = new Point(x, y, z, SpatialReferences.getWgs84());
x和y是横纵坐标,z是高度,如果需要z生效需要再设置一个参数,不设置就是贴在地图上
graphicsOverlay.getSceneProperties().setSurfacePlacement(LayerSceneProperties.SurfacePlacement.ABSOLUTE);
5、通过文件地址拿到模型
ModelSceneSymbol sceneSymbol = new ModelSceneSymbol(path3D, scale);
scale:模型大小。小模型设置数字大一些,大模型设置小一些,反正随便设置。
6、图形Graphic
Graphic graphic = new Graphic(pierPoint, sceneSymbol);
7、把图形添加进入图层中
graphicsOverlay.getGraphics().add(graphic)
8、使用
sceneview.getGraphicsOverlays().add(graphicsOverlay);
到这里就可以看到模型显示在地图中了。
官方文档:加载3D模型