1 Star 4 Fork 1

Ikkyu / AR管线巡检开发示例

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

AR管线巡检示例

写在前面的话

本文档是基于超图移动端SDK的AR模块开发的示例,仅供参考,SDK在持续迭代中,相关描述可能有变化。

完整开发流程,参考如下链接: AR管线巡检开发示例

这是一个使用AR查看墙内管线的基础示例程序。

涉及的关键词:SuperMap iMobile for Android、深度遮挡、ARCore、AREngine

示例数据

示例数据位于ar_occlusion\sampledata\PipeData.zip中

示例介绍

这是一个使用AR查看墙内管线的基础示例程序。

涉及的关键词:SuperMap iMobile for Android、深度遮挡、ARCore、AREngine

数据准备

数据格式

本示例所使用到的管线模型格式为:gltf2.0gltf2.0介绍

示例数据

示例数据位于ar_occlusion\sampledata\PipeData.zip中

数据制作

  1. 使用blender制作模型(或在blender中导入模型)

为了防止在模型批量导出的过程中出现错误,请参考下图的场景集合的层级结构。

由于示例程序中采用OBB有向包围盒( 它是包含该对象且相对于坐标轴方向任意的最小的长方体 )的方式用于射线检测。为了在示例程序中能够准确点击模型,请通过将模型拆分成单个实体对象的方式,确保模型的冗余空间尽可能地小。

模型导入

  1. 批量导出模型

在菜单栏->"Scripting"中新建脚本,内容如下:

# exports each selected object into its own file
import bpy
import os

# export to blend file location
basedir = r"E:\3d\top_pipe\\"

if not basedir:
    raise Exception("Blend file is not saved")

view_layer = bpy.context.view_layer

obj_active = view_layer.objects.active
selection = bpy.context.selected_objects

bpy.ops.object.select_all(action='DESELECT')

for obj in selection:

    obj.select_set(True)

    # some exporters only use the active object
    view_layer.objects.active = obj

    name = bpy.path.clean_name(obj.name)
    fn = os.path.join(basedir, name)

    #bpy.ops.export_scene.fbx(filepath=fn + ".fbx", use_selection=True)
    bpy.ops.export_scene.gltf(filepath=fn, export_format="GLB", export_lights=False, use_selection=True)

    obj.select_set(False)

    print("written:", fn)

view_layer.objects.active = obj_active

for obj in selection:
    obj.select_set(True)

print("All save completed!")
  1. 选中场景集合中所有模型,执行脚本,导出模型。

批量导出脚本

  1. 查看模型文件夹。

模型组

  1. 至此,数据准备阶段已完成。

在后续构建的AR场景中,通过点击交互就可以查询出模型的名称。(Mesh2、Mesh3、Line......)。

若是需要通过点击交互,查询模型的其他属性信息(诸如规格、连接类型这些信息)。可通过创建一张属性表,建立模型名称与属性字段的一一对应的关系。通过查询模型名称,进而去查询对应的属性值。

属性查询

运行流程

开发环境

  • IDE:Android Studio 2021
  • Android Gradle Plugin Version:4.1.2
  • Gradle Version:6.5

注意事项:

Gradle 7.0版本后,请参考Android官方对于Gradle版本与Gradle插件的配套关系,把Gradle插件版本也升级到7.0及以上。

iMobile SDK

使用SuperMap移动GIS的iMobile for Android 的SDK 下载链接

示例程序涉及SDK中的以下so 和 jar

  • libimb2d_1100.so
  • com.supermap.data_v1100.jar
  • com.supermap.ar_v1100.jar
  • scenefrom-sm-11.0.1.aar

在工程中导入iMboile的AR模块

产品包

模块的build.gradle配置如下

plugins {
    id 'com.android.application'
}

android {
    compileSdk 28

    defaultConfig {
        applicationId "com.supermap.samplecode.occlusiondemo"
        minSdk 24
        targetSdk 28
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        ndk{
        	//注意使用的产品包是32位还是64位
            abiFilters 'armeabi-v7a'
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

    //SuperMap Data模块
    implementation files('libs/com.supermap.data_v1100.jar')
    //SuperMap AR模块
    implementation files('libs/com.supermap.ar_v1100.jar')

    //渲染框架
    implementation files('libs/sceneform-sm-11.0.1.aar')
    //第三方工具类
    implementation files('libs/eqtool-1.3.0.jar')
}

运行示例

  1. 许可设置

    此示例程序使用的是离线使用许可。

    在src/main/assets/目录下,默认存放一个试用许可"SuperMapiMobileTrial.slm"。在程序初次启动时,会拷贝至手机对应文件夹(../PipeData/license)下。

    若许可过期或不可用,请先申请许可,然后拷贝至手机对应文件夹(../PipeData/license)下,或在assets目录进行替换。

    注意:

    许可过期或不可用,会出现如下报错信息:

错误信息

若许可可用,仍出现上述异常信息,请从以下方面进行自查。

  • 使用的so与jar不是同一个产品包的产物
  • 申请的许可与对应产品包的版本不一致
  • 手机未开启存储读写权限
  1. 导入工程

方式一 打开工程

导入工程

指定对应文件夹

导入工程

方式二 在现有工程的settings.gradle中添加配置,实现模块导入

include ':ar_occlusion'
project(':ar_occlusion').projectDir=new File('D:\\OcclusionDemo')
  1. 导入模型数据

将模型数据拷贝至手机目录/SuperMap/PipeData。

具体路径配置,参考PathConfig.java

public static final String SD_CARD = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();

/**
* 数据文件夹根路径
* MI 9 Transparent Edition\内部存储设备\SuperMap\PipeData
*/
public static final String PIPE_DATA_PATH = SD_CARD + "/SuperMap/PipeData";

/**
* 屋顶通风管道模型组文件夹路径
*/
public static String TOP_PIPE_DATA = PIPE_DATA_PATH + "/Model/top_pipe";

/**
* 地下管线模型组
*/
public static String UNDERGROUND_PIPE_DATA = PIPE_DATA_PATH + "/Model/underground_pipe";

/**
* 垂直墙面内的管线数据
*/
public static String VERTICAL_PIPE_DATA = PIPE_DATA_PATH + "/Model/pipe_v";
  1. 运行示例

运行示例程序

run

程序运行成功后,会在手机SuperMap/PipeData生成以下内容

  • ImgData
  • license
  • Log
  • app.cfg

run

app.cfg(default.cfg)、ImgData(包含一张名为“mark.png”的图片)可在工程的assets目录下找到

run

  1. 示例程序使用流程
  • 打印“mark.png”,将其布置在场景中

  • 启动程序,进入主界面

使用流程

  • 点击 “定位”,扫描“mark.png”,加载场景

使用流程

  • 点击 "视口模式",行走浏览

    可通过手势调节开挖参数,具体操作见程序演示

  • 点击"卷帘模式",行走浏览

    可通过手势调节显示范围,具体操作见程序演示

代码定位

场景加载

实现通过扫码的方式加载场景。

见MarkerConfig,涉及Marker的初始位置、图片资源路径的相关信息。

见ScanLayout,涉及布局设置和图片识别相关的接口(ImageScanner)调用。

/**
* 开启图片扫描功能
* @param arEffectView AR视图
* @param callback 扫描结果回调
*/
public void startImageScan(AREffectView arEffectView,ScanCallback callback){
    //...
}

/**
* 结束图片扫描
* @param arEffectView AR视图
*/
private void stopScan(AREffectView arEffectView) {
        //...
}

见DataManager,涉及数据的加载.

/**
* 添加管线场景
* @param parent 父节点
* @param dataPath 数据路径
* @param enabled 启用点击交互
* @param type 数据类型
*/
public void addPipeScene(AREffectElement parent,String dataPath,boolean enabled,Type type){
	//...
}

/**
* 添加管线场景
* @param parent 父节点
* @param dataPath 数据路径
* @param enabled 启用点击交互
*/
public void addPipeScene(AREffectElement parent,String dataPath,boolean enabled) {
	//...
}

视口模式

实现在视口模式下,对墙内管线模型进行开挖显示。

见ViewportFuncLayout,涉及布局设置。

见ExcavatorManager,涉及开挖参数的计算、坑洞对象渲染和屏幕显示范围构成的点集的更新。

private EffectView.OnUpdateListener onUpdateListener = new OnUpdateListener() {
    @Override
    public void onUpdate() {
        //开挖参数计算->坑洞对象渲染->更新屏幕显示范围构成的点集
    }

卷帘模式

实现类似卷帘的效果。

实现原理上,比视口模式更简单。直接根据分割线计算出屏幕显示范围构成的点集即可。

见RollingFuncLayout,涉及布局设置。

屏幕范围裁剪

见ScreenPointManager,统一管理屏幕显示范围构成的点集,当点集更新时,触发update回调。在回调事件里执行屏幕范围裁剪。

//在PipeActivity中
ScreenPointManager.getInstance().setOnUpdatePointListener(new ScreenPointManager.OnUpdatePointListener() {
    @Override
    public void update(List<ArrayList<int[]>> screenPoint,List<ArrayList<int[]>> bottomScreenPoint) {
    	//...裁剪屏幕显示范围
    }
});

开挖参数调节

在视口模式中,涉及通过手势去修改开挖参数。

在最初的版本中,是通过SeekBar的方式去修改开挖参数。

参数修改

参数修改

当前版本修改为通过手势去修改开挖参数。

参数修改

见CustomGesture,涉及单指、双指手势的定义。 见DigGestureManager,涉及开挖参数修改的手势管理。

见DynamicView,在布局上位于最顶部,用于接收MotionEvent,分发onTouch事件。

@Override
public boolean onTouch(View v, MotionEvent event) {
	//...
}

程序演示

注: 以下内容非最终成果,仅是迭代过程中的录屏。且对应模型数据需要结合对应场景,才可正确地显示。

v1.0

示例程序的录屏

<iframe src="https://file.eqgis.cn/img/gitee/ar_occlusion/readme/TestRec01.mp4" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" height=600 width=800> </iframe>

补充说明

实现方式

对每一帧显示的AR内容进行裁剪的方式来实现只显示坑洞范围内的AR内容。

在EffectView#OnUpdateListener的onUpdate事件中,重复执行以下步骤。

  • 构建开挖参数ExcavationParameter
  • Excavator#generateHitPoint 生成碰撞点
  • Excavator#calculate 根据开挖参数进行计算
  • PitObject#updateMesh 更新坑洞对象的网格
  • OcclusionHelper#setUniquePointList 设置屏幕裁剪的范围
  • OcclusionHelper#refresh 刷新

简单示例

//遮挡设置
occlusionHelper = arView.getOcclusionHelper();
occlusionHelper.init(0.36f)
    .setRenderMode(OcclusionHelper.RenderMode.NORMAL);
  
List  roomBounds = Arrays.asList(
    new Point3D(-1, -1, -2),
    new Point3D(-1, 6, -2),
    new Point3D(6, 6, -2),
    new Point3D(6, -1, -2),
    new Point3D(-1, -1, -2)
);

//采用ARGeoPrism,构建“检测墙”
ARGeoPrism geoVerticalRegion = new ARGeoPrism();
geoVerticalRegion.setParentNode(arView);
//仅用作射线检测,渲染状态设置为false
geoVerticalRegion.setRenderable(false);
geoVerticalRegion.addPart(roomBounds,6.0f);

//创建开挖工具,在这之前,需确认AREffectView开启了遮挡设置
//Excavator所有子类使用方法一致
excavatorWall = new WallExcavator(geoVerticalRegion);
//坑洞纹理
Bitmap bitmap=null;
Bitmap bitmap2=null;
try {
    InputStream is = getApplicationContext().getAssets()
        .open("brown_mud_dry2.png");
    bitmap= BitmapFactory.decodeStream(is);
    InputStream is2 = getApplicationContext().getAssets()
        .open("wall_texture.png");
    bitmap2= BitmapFactory.decodeStream(is2);
    is.close();
    is2.close();
} catch (IOException e) {
}

//创建坑洞渲染对象
pitWall = new PitObject(excavatorWall)
    .setTexture(bitmap,bitmap2);
  

//在每一帧刷新时调用(通常使用EffectView.addOnUpdateListener(EffectView.OnUpdateListener)添加帧监听事件)
arView.addOnUpdateListener(()->{
    //开挖计算墙面碰撞点 arView为AREffectView、screenPointX/Y为对应的屏幕坐标
    //以屏幕中心计算碰撞点
    Point3D hitPoint = excavatorWall
                .generateHitPoint(arView, screenPointX, screenPointY);
    if (hitPoint!=null){
        //desc-执行开挖的顶点计算(开挖参数)
        excavatorWall.calculate(ExcavationParameter.builder()
                                .setRadius(radius)
                                .setOffset(offset)
                                .setInnerMargin(0)
                                .setCenterPoint(hitPoint)
                                .build());
    }
    //渲染坑洞结果
    pitWall.updateMesh();
                                  
    if (occlusionHelper.isEnabled()){
        //desc-执行画面裁剪
        ArrayList  screenPoint = null;
        if (excavatorWall !=null){
            //计算屏幕坐标
            screenPoint = excavatorWall.getScreenPoint(null);
            if (screenPoint!=null){
                //根据屏幕坐标刷新裁剪范围
                occlusionHelper.setUniquePointList(screenPoint).refresh();
            }
        }
    }
})
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

这是一个使用AR查看墙内管线的基础示例程序。 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tanyunxiu/AR-pipe.git
git@gitee.com:tanyunxiu/AR-pipe.git
tanyunxiu
AR-pipe
AR管线巡检开发示例
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891