1. Preface
NVisionXR engine is the world's first cross-platform multi-compatible native AR application development engine, making AR application development more efficient.
For more details, please refer to the NVisionXR series tutorial summary " [Native AR development must-see] NVisionXR engine tutorial summary (continuously updated...) " This series of tutorials introduces how to use the NVisionXR engine to develop native Android projects, using Android Studio 3.0.1 . 2. SDK directory
|---- assets //The resource library file that nvisionxr needs to use |---- nvisionxr
|---- nvisionxrDeps //The dependency library file of the nvisionxr library
3. Use the NVisionXR library in the project
31 Put the nvisionxr folder in the project root directory, and put nvisionxrDep in the project root directory 3.2 Add in project settings.gradle
include ':nvisionxr' include ':nvisionxrDeps:common'
include ':nvisionxrDeps:ijkplayer' include ':nvisionxrDeps:ijkplayer:java'
include ':nvisionxrDeps:ijkplayer:armv7a'
3.3 Add in build.gradle in the project app directory
compile project(':nvisionxr')
compile project(':nvisionxrDeps:common')
compile project(':nvisionxrDeps:ijkplayer:java')
compile project(':nvisionxrDeps:ijkplayer:armv7a')
compile 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-7'
4. Put the assets folder into the main directory of the project 5. Add NVSurfaceView 5.1 to define the layout
In the project's custom View layout xml, add NVSurfaceView.
Here, you can add NVSurfaceView just like you add SurfaceView. A simplest example is as follows:
In the onCreate method of the Activity that displays the nvisionXR content First, get the NVSurfaceView object,
NVSurfaceView needs to call its lifecycle methods such as onCreate, onResume, onPause, onDestroy
6. Add Vuforia function
The Vuforia function is a plug-in function of the NVisionXR engine, which needs to be added through the addPlugin method of NVAppDirector.
Welcome to contact:
For more details, please refer to the NVisionXR series tutorial summary " [Native AR development must-see] NVisionXR engine tutorial summary (continuously updated...) " This series of tutorials introduces how to use the NVisionXR engine to develop native Android projects, using Android Studio 3.0.1 . 2. SDK directory
|---- assets //The resource library file that nvisionxr needs to use |---- nvisionxr
|---- nvisionxrDeps //The dependency library file of the nvisionxr library
3. Use the NVisionXR library in the project
31 Put the nvisionxr folder in the project root directory, and put nvisionxrDep in the project root directory 3.2 Add in project settings.gradle
include ':nvisionxr' include ':nvisionxrDeps:common'
include ':nvisionxrDeps:ijkplayer' include ':nvisionxrDeps:ijkplayer:java'
include ':nvisionxrDeps:ijkplayer:armv7a'
3.3 Add in build.gradle in the project app directory
compile project(':nvisionxr')
compile project(':nvisionxrDeps:common')
compile project(':nvisionxrDeps:ijkplayer:java')
compile project(':nvisionxrDeps:ijkplayer:armv7a')
compile 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-7'
4. Put the assets folder into the main directory of the project 5. Add NVSurfaceView 5.1 to define the layout
In the project's custom View layout xml, add NVSurfaceView.
Here, you can add NVSurfaceView just like you add SurfaceView. A simplest example is as follows:
<com.nvisionxr.NVSurfaceViewandroid:layout_width="match_parent" android:layout_height="match_parent" />5.2 Initialize NVSurfaceView
In the onCreate method of the Activity that displays the nvisionXR content First, get the NVSurfaceView object,
surfaceView = findViewById(R.id.nvsurface_view);
Then,
//create render SurfacemSurfaceView.onCreate(); //Set resource loading management mSurfaceView.setAssetManager(this.getAssets());5.3 Add NVScenePlay First, we need to create an NVScenePlay class like FirstScenePlay.
public class FirstScenePlay extends NVScenePlay {public FirstScenePlay(String name) { super(name);} @Overridepublic void onCreate() { super.onCreate();} }Then, we need to register this NVScenePlay with the implementation class NVAppDirector. Or in the onCreate method of the Activity:
FirstScenePlay scenePlay = new FirstScenePlay("first_sceneplay"); NVAppDirector.getInstance().addScenePlay("MAIN_SCENEPLAY", scenePlay);MAIN_SCENEPLAY represents that we register FirstScenePlay as the initial startup ScenePlay. Notice:
NVSurfaceView needs to call its lifecycle methods such as onCreate, onResume, onPause, onDestroy
6. Add Vuforia function
The Vuforia function is a plug-in function of the NVisionXR engine, which needs to be added through the addPlugin method of NVAppDirector.
NVAppDirector.getInstance().addPlugin(NVAppDirector.PluginType.AR_INPUT, "ar_input_plugin");Then, create an instance of VuforiaWrapper and initialize it:
vuforiaWrapper = new VuforiaWrapper(this);vuforiaWrapper.init(“String key”);Since Vuforia needs to render its own camera screen, it needs to monitor its Surface life cycle, that is, call the following statement:
mSurfaceView.addSurfaceCallback(vuforiaWrapper);Finally, in the life cycle method of Activity, complete the life cycle method of VuforiaWrapper.
@Overrideprotected void onResume() { super.onResume(); if(mSurfaceView != null) { mSurfaceView.onResume(); } if(vuforiaWrapper != null) { vuforiaWrapper.onResume(); } }@Overrideprotected void onPause() { super.onPause(); if(mSurfaceView != null) { mSurfaceView.onPause(); } if(vuforiaWrapper != null) { vuforiaWrapper.onPause(); } }@Override protected void onDestroy() { super.onDestroy(); if(mSurfaceView != null) { mSurfaceView.onDestroy(); } if(vuforiaWrapper != null) { vuforiaWrapper.shutdown(); }}In addition, we also need to add the permission of Camera.
Note that the permission application needs to be done before adding the plugin:
// request for access if(!NVCameraPermissionHelper.hasCameraPermission(this)){ NVCameraPermissionHelper.requestCameraPermission(this); return; } NVAppDirector.getInstance().addPlugin(NVAppDirector.PluginType.AR_INPUT, "ar_input_plugin"); if(!NVCameraPermissionHelper.hasCameraPermission(this)){ NVCameraPermissionHelper.requestCameraPermission(this); return; } NVAppDirector.getInstance().addPlugin(NVAppDirector.PluginType.AR_INPUT, "ar_input_plugin");After running, the camera will be turned on.
Welcome to contact:
- Contact: +86 18801341080
- Email: [email protected]
- Website: http://www.nvisionxr.com/
- QQ group: 416802300
![](http://www.arvrschool.com/attachment/1803/thread/111_3513_09335ee5037d7ec.png)