zhangmenghe / calvr-for-android Goto Github PK
View Code? Open in Web Editor NEWAR Kit for Android using CalVR
AR Kit for Android using CalVR
Refer to this commit to see how how to include arcore lib in ndk project.
Then we can use native arcore functions in native codes.
create
/destroy
. The latter owned by ARCore. e.g. ARAnchor. Use acquire
/release
. Acquire could be a long-lived or acquire each frame is transient large data.ArPose
model matrix in metersComController
multinode communication and synchronizationTracking
system.Navigation
System: originally used for move camera. But camera need to follow real cameraScreen
CollaborativeManager
and ThreadedLoader
(ignore yet)InteractionManager
System. Really close related to tracking and navigation. Necessary?OpenCV provides pre-built SDK for varies Android platform, however, those APKs and staticLibs are compiled by GNU which is not compatibale for us.
To build from scratch :
cppFlags
in gradle files with -std=c++17
while arguments -DANDROID_STL=c++_static
throw()
and register
. use #define register
to ignore them set(OpenCV_DIR "${EXT_PROJ_DIR}/opencv-3.4.3/build/${ANDROID_ABI}/sdk/native/jni")
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV libraries: ${OpenCV_LIBS}")
target_link_libraries(cvrUtil ${OpenCV_LIBS})
Make the ARCore samples as well as our project work on S9 :
See environment details listed in README file.
Render AR plane:
effectively detect horizontal surfaces but limited depth perception. How they detect vertical plane?
Render point cloud and anchors:
Render objects with lighting estimation :
use of light estimate: color correction to fragment shader ArLightEstimate_getColorCorrection
+ Retrieves the pixel intensity in gamma space of the current view ArLightEstimate_getPixelIntensity
Learn to use Android Studio : Build a simple pure Java Android App. Includes 2 activities and simple interactions.
Get to know NDK/JNI : Build simple NDK project
Use OpenGL ES : Build NDK project with OpenGL ES lib #3
Get to know ARCore : #4
All together: MyGLES project
Refer to the sample ARCore project to put all parts together:
Is ARCore open source?
No.
Does Emulator work?
Yes and yes for ARCore as well!(there will be a virtual scene)
What role it plays in a rendering process?
It is not the controller. We can easily access the camera, trackable planes, points ... to get to known the environment via ARCore APIs. Now we create an activity with surface ->surface.setRenderer(GLSurfaceView.Renderer )
-> do actual rendering in native codes using OpenGLES renderer, which could be encapsulated by CalVR.
What's next
Create AR/VR/3D app on web easily.
Specificlly useful for rare data.E.g. red left turn traffic light
For GL 2.0 and 2.1, you could make use of built in uniforms such as
gl_ProjectionMatrix
andgl_ModelViewProjectionMatrix
and many others.
It is strongly recommended that you get rid of these and use your own uniforms.
In core contexts version 3.1 or greater, most of the built-in uniforms were removed.
We do not update scene camera, instead, manully set those uniforms using createXXUniform
from AndroidHelper
osgUtil::IntersectVisitor
Deprecated - use IntersectionVisitor instead.
Our work on building CalVR on Android based on Weichen's Note. Here is a brief summary of the steps to build CalVR and abstract of what I've achieved.
#ifndef __ANDROID__
in most cases.CMakeLists
can be gained from my repo. You can switch REBUILD
variable to choose whether rebuild or use the static libs.CalVRAsset
. On creating the Activity, those resource will be copied to runtime.getenv()
. On Android, we need to get the runtime file location. We created our own Environment processor to manully set environmental variables and override getenv
methodCalVR.cpp
and create my own calvrController
and use calvr viewer
, scene
, menu
and config
tools. For board menu, use a fix position for now to get it displayed on screen first.osgText::font
to load .ttf
fonts from resource. Therefore, I first build freetype on android. As a drawable, under osg framework, succeed rendering some strings. However, osg still can not get .ttf
reader.OSG Font fail to get ttf reader even if Freetype libs successful linked(since ttf text can be rendered in a gl drawable way)
We may need to figure out what components of CalVR are not required for Android.
Started to integrate Karen's project. The submenu entrance is here
*.cpp
under cpp
and CMakeLists.txt
under External Build FilesCMakeLists.txt
.so
(shared opbject library), Gradle then packages it into APK static {
System.loadLibrary("native-lib");
}
cmake_minimum_required(VERSION 3.4.1)
add_library(yourOwnLibName
SHARED
src/main/cpp/cppFileName.cpp)
${ANDROID_NDK}
to include local NDK lib add_library(importedLibName
SHARED
IMPORTED)
set_target_properties(importedLibName
PROPERTIES IMPORTED_LOCATION
${ANDROID_ABI}/importedLibName.so)
include_directories(path-to-include-folder)
log
) and store its path as a variable(e.g. named log-lib
)
find_library(log-lib
log)
your lib
to NDK libs
)
target_link_libraries(yourOwnLibName
${log-lib}
${ndklib2}
${ndklib3})
public class libClass{
// load shared lib
static{
System.loadLibrary("yourCppSharedLibName");
}
public static native void init(int width, int height);
public static native void step();
}
linkerCppJava.cpp
contain function getCppLinker()
which will be called by java class javaClass.java
under the path projectName/src/com/example/myProj/javaClass.java
. Then the cpp code should be
JNIEXPORT jstring JNICALL
Java_com_example_myProj_javaClass_getCppLinker(JNIEnv * env, jobject)
JNIEnv *
point to VM and jobject
points to this. The name is Java_PATHofJAVA_functionName
public static native void JNI_FUNC_CALL(JAVACLASS instance);
JNI_METHOD(void, JNI_FUNC_CALL)(JNIEnv*env, jclass, jobject jobj){
/////Some way to cast jobject to the class used in native codes
AAssetManager * cpp_asset_manager = AAssetManager_fromJava(env, asset_manager);
cpp_actual_func(cpp_asset_manager);
}
void cpp_acutal_func(AAssetManager * manager);
AAssetManager
provides interface to obtain the corresponding native AAssetManager
object. A more common method is
jclass localClass = env->FindClass(InterestedClass);
dest_Type globalClass =reinterpret_cast<dest_Type>(src_Type);
// for example
myNativeClass * native_cls;
jlong addr = reinterpret_cast<intptr_t>(native_cls);
// for example 2
jlong addr;
myNativeClass * native_cls= reinterpret_cast<myNativeClass *>(addr);
Reference:
Signature
Calling Java Methods
jclass helper_class = env->FindClass( "com/samsung/arcalvr/MainActivity" );
if(helper_class){
helper_class = static_cast<jclass>(env->NewGlobalRef(helper_class));
jmethodID button_move_method = env->GetMethodID(helper_class, funcName, "()V");
jobject object = GetMainActivityObj();
env->CallVoidMethod(object,button_move_method);
}
/*
* Lambda func in cpp
* [ capture clause ] (parameters) -> return-type{definition of method}
*/
static struct JNIData{
jclass helper_class;
jmethodID test_method;
jmethodID button_move_method;
}jniIds = [env]()->JNIData{
constexpr char kHelperClassName[] = "com/samsung/arcalvr/JniInterface";
constexpr char kTestFunctionName[] = "testCallBack";
constexpr char kButtonMoveFunction[]="popButtons";
constexpr char kSignature[] = "()V";
jclass helper_class = env->FindClass( kHelperClassName );
if(helper_class){
helper_class = static_cast<jclass>(env->NewGlobalRef(helper_class));
jmethodID test_method = env->GetStaticMethodID(
helper_class, kTestFunctionName, kSignature);
jmethodID button_move_method = env->GetMethodID(
helper_class, kButtonMoveFunction, kSignature);
return {helper_class, test_method, button_move_method};
}
LOGE("===CAN'T FIND HELPER CLASS");
return {};
}();
if(!jniIds.helper_class)
return;
jmethodID constructor = env->GetMethodID(jniIds.helper_class, "<init>", "()V");
env->CallStaticVoidMethod(jniIds.helper_class, jniIds.test_method);
jobject object = env->NewObject(jniIds.helper_class, constructor);
env->CallVoidMethod(object,jniIds.button_move_method);
glBegin/glEnd
,etc).IBO
buffer both length and contents each frame)glDrawable
class as the parent class to all kinds of drawable using gl commends directly.void Initialization(AAssetManager * manager,std::stack<utils::glState>* stateStack)
void drawImplementation(osg::RenderInfo&) const;
For dynamic draw, you may also need to write a updateOnFrame
function to update buffer data.glPushAttrib
and glPopAttrib
(GLES removed those functions).backgroundNode->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
backgroundNode->getOrCreateStateSet()->setRenderBinDetails(1,"RenderBin");
sceneGroup->getOrCreateStateSet()->setRenderBinDetails(2,"RenderBin");
sceneGroup->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::ON);
root->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
In manifest file
<uses-feature android:glEsVersion = "0x00020000" android:required="true"/>
Also, when setup context
surfaceView.setEGLContextClientVersion(2)
to use OpenGL ES 2.0. To use 3.x+ check for the avaliablity of 3.x API at run time and then use those features if supported
<supports-gl-texture android:name = COMPRESSION_METHOD/>
to support Texture Compression
2 fundational classes in Andriod framework that let you create and manipulate graphics with the OpenGL ES API:
GLSurfaceView
SurfaceView
, could be fit into setContentView()
in activity.GLSurfaceView.Renderer
GLSurfaceView
. Implement it and attach to GLSurfaceView
by GLSurfaceView.setRenderer()
onSurfaceCreated()
setting OpenGL env params and initializationonDrawFrame()
call on each redrawonSurfaceChanged()
call on view geometry change(size/ orientation)A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.