AR三维管线
数据制作
AR三维管线的数据制作流程,同制作三维管线的数据相同。
功能实现
(1)必备类库
进行AR管线功能开发必需的类库为com.supermap.data.jar、com.supermap.mapping.jar、com.supermap.realspace.jar、com.supermap.ar.jar、sceneform-sm-11.1.0.aar,必需的so库为libimb.so。
(2)功能开发
这里介绍开发AR管线应用的关键步骤。
添加控件
在activity_main.xml添加用于显示三维场景的SceneControl控件。参考代码如下:
<com.supermap.realspace.SceneControl
android:id = "@+id/SceneControl"
android:layout_width="match_parent"
android:layout_height = "match_parent">
</com.supermap.realspace.SceneControl>
加载管线数据
sceneControl = findViewById(R.id.sceneControl);
arControl = new ARControl(this, sceneControl);
sceneControl.sceneControlInitedComplete(success -> {
arControl.setARState(true);
arControl.setAugmentedImageTrackState(true);
Workspace workspace = new Workspace();
WorkspaceConnectionInfo info = new WorkspaceConnectionInfo();
info.setServer(SCENE_PATH);
info.setType(WorkspaceType.SXWU);
sceneControl.getScene().setWorkspace(workspace);
if (workspace.open(info)) {
boolean mOpen = sceneControl.getScene().open(workspace.getScenes().get(0));
layer3Ds = sceneControl.getScene().getLayers();
layerCount = layer3Ds.getCount();
}
arControl.setSceneTransLation(0, 0, -5);// 调整整个场景的位置
arControl.setARPlaneState(false); // 隐藏平面提示
Point3D point3D = new Point3D(1, 12, 6.5);
// 设置cross裁剪 把地下部分隐藏
if (layerCount > 0) {
for (int j = 0; j < layerCount; j++) {
layer3Ds.get(j).setCustomClipCross(point3D, new Point2D(25, 15), 180, 0, 0, 0);
layer3Ds.get(j).setClipLineColor(new Color(255, 0, 0, 255));
}
}
});
sceneControl.setOnTouchListener(this);//设置监听回调
管线属性查询
if (layerCount > 0) {
for (int i = 0; i < layerCount; i++) {
Layer3D layer = layer3Ds.get(i);
if (layer != null && layer.getName() != null) {
FieldInfos fieldInfos = layer.getFieldInfos();
Feature3D feature = null;
Layer3DOSGBFile layer3d = null;
if (layer.getType() == Layer3DType.OSGBFILE) {
layer3d = (Layer3DOSGBFile) layer;
} else if (layer.getType() == Layer3DType.VECTORFILE) {
feature = selection.toFeature3D();
}
int count = fieldInfos.getCount();
if (count > 0) {
Object[] str = layer3d.getAllFieldValueOfLastSelectedObject();
if (str != null) {
for (int j = 0; j < count; j++) {
String name = fieldInfos.get(j).getName();
String strValue;
Object value;
if (feature == null) {
value = str[j];
} else {
value = feature.getFieldValue(name);
}
if (value.equals("NULL")) {
strValue = "";
} else {
strValue = value.toString();
}
}
}
}
}
}
}