Author Topic: [Tips] Android, augmented reality 3D with JPCT + Camera.  (Read 98440 times)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: [Tips] Android, augmented reality 3D with JPCT + Camera.
« Reply #45 on: December 01, 2011, 01:52:41 pm »
The AAConfigChooser doesn't specify an alpha value for the config, which means that it defaults to 0. I can change this and give you an updated version to try later.

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: [Tips] Android, augmented reality 3D with JPCT + Camera.
« Reply #46 on: December 01, 2011, 03:10:16 pm »
Awesome, thanks Egon. Let me know and I'll test.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: [Tips] Android, augmented reality 3D with JPCT + Camera.
« Reply #47 on: December 01, 2011, 04:54:40 pm »
Please try this jar: http://www.jpct.de/download/beta/jpct_ae.jar. It has an additional constructor that takes a boolean to enable/disable alpha. I haven't tested it, i'm just setting the configuration and hoping for the best...

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: [Tips] Android, augmented reality 3D with JPCT + Camera.
« Reply #48 on: December 01, 2011, 05:49:00 pm »
Brilliant - thats done it!

The final setup within the SurfaceView is...
Code: [Select]
setEGLContextClientVersion(2);
setEGLConfigChooser(new AAConfigChooser(this, true));
getHolder().setFormat(PixelFormat.TRANSLUCENT);
//setEGLConfigChooser(8, 8, 8, 8, 16, 8);//Tablet compatible (RETEST)

// Setup the renderer
String inC = Globals.App_Prefs.getString("BackgroundColour", "0,0,0,0");
RGBColor background = Utilities.decodeColour(inC);
mRenderer = new JpctRenderer(background);
setRenderer(mRenderer);

All I have to do now is align the objects to the world without billboarding!

Cheers.

[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: [Tips] Android, augmented reality 3D with JPCT + Camera.
« Reply #49 on: January 11, 2012, 09:23:56 pm »

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: [Tips] Android, augmented reality 3D with JPCT + Camera.
« Reply #50 on: February 17, 2012, 02:13:11 pm »
Egon,
Unfortunately some test users (including myself) are getting an IndexOutOfBounds exception within the AAConfigChooser() now.
This code
Code: [Select]
    setEGLContextClientVersion(2);
    if (Main.isTablet()) {
    setEGLConfigChooser(8, 8, 8, 8, 16, 8);
    } else {
    setEGLConfigChooser(new AAConfigChooser(this, true));
    }
getHolder().setFormat(PixelFormat.TRANSLUCENT);

has been working fine for months, but now running it on lesser devices to my Galaxy SII results in the following stack trace on start-up:
Code: [Select]
FATAL EXCEPTION: GLThread 9
 java.lang.ArrayIndexOutOfBoundsException
  at com.threed.jpct.util.AAConfigChooser.chooseConfig(AAConfigChooser.java:131)
  at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:918)
  at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1248)
  at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)

I must add that I have had to download a more recent beta of jPCT-AE as my dev environment died and I had to re-acquire several libraries - I don't know if this would make a difference...

Any thoughts/ tips would be great.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: [Tips] Android, augmented reality 3D with JPCT + Camera.
« Reply #51 on: February 17, 2012, 03:29:07 pm »
Seems like a flaw...when no matching config was found, it should choose the first one....but it chooses the -1th one instead, which fails. This version should fix this: http://jpct.de/download/beta/jpct_ae.jar. However, i've no idea what this first config actually will be and if it fits...

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: [Tips] Android, augmented reality 3D with JPCT + Camera.
« Reply #52 on: February 17, 2012, 06:53:53 pm »
Thanks Egon, that's done the trick.

As an aside, you wouldn't have a good bit of code for working out the actual available memory for the running application?  (Just wonder if you do anything already in jPCT in terms of memory checking)

Thanks again,

Mike

Offline GLeonio

  • byte
  • *
  • Posts: 1
    • View Profile
Re: [Tips] Android, augmented reality 3D with JPCT + Camera.
« Reply #53 on: March 12, 2013, 07:28:05 pm »
Thanks for the helpful tips! I compiled a list of some top resources I found around this topic of 3D Android augmented reality. I included this post. Check it out. I hope it can be useful to other developers here.  :) http://www.verious.com/board/Giancarlo-Leonio/3d-android-augmented-reality/

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: [Tips] Android, augmented reality 3D with JPCT + Camera.
« Reply #54 on: December 17, 2013, 03:23:18 pm »
First we need to set up an XML layout.
Our minimum requirement is a glSurfaceView that's where we will draw 3D(JPCT engine),
and a SurfaceView to draw the camera preview.

Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<android.opengl.GLSurfaceView android:id="@+id/glsurfaceview"
android:layout_width="fill_parent" android:layout_height="fill_parent" />

<SurfaceView android:id="@+id/surface_camera"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_centerInParent="true" android:keepScreenOn="true" />
</FrameLayout>


I'm experimenting with this idea, very useful post:)

what I dont get is, in this layout camera view should be on top of GL view, not the other way around. but it's not ??? furthermore if I switch the order, GL view disappears  ::)

what am I missing?

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: [Tips] Android, augmented reality 3D with JPCT + Camera.
« Reply #55 on: December 17, 2013, 05:36:09 pm »
Unfortunately I can't answer your question directly (as to why), but I struggled for sometime getting a stable implementation whereby the AR data was always on top of the camera, especially whilst toggling the camera preview on and off.
I always implemented this in code, not using a layout as follows;

In the main activity onCreate method, in this order;

Create the CameraPreview.
Create the SurfaceView (with renderer)

In the CameraPreview constructor;
Code: [Select]
    RelativeLayout tmpLayout = new RelativeLayout( appContext );
    tmpLayout.addView(this, 0,
    new LayoutParams(
    LayoutParams.FILL_PARENT,
    LayoutParams.FILL_PARENT)
    );
    activity.setContentView(tmpLayout);

In the SurfaceView constructor;
Code: [Select]
        setEGLContextClientVersion(2);

setEGLConfigChooser(new AAConfigChooser(this, true));

getHolder().setFormat(PixelFormat.TRANSLUCENT);

// Setup the renderer
mRenderer = new JpctRenderer( mainARView.orientationListener.tabletMode );
Activity activity = (Activity)mainARView.appContext;

// Add this view to the main activity
        setZOrderMediaOverlay(true);
    activity.addContentView(this, new LayoutParams(
    LayoutParams.FILL_PARENT,
    LayoutParams.FILL_PARENT));

If you want a UI on-top of both, do this in the main activity after creating the SurfaceView;
Code: [Select]
uiScreen = new UserInterfaceView(this);
addContentView(uiScreen, fillLayout);

In onResume;
Code: [Select]
camScreen.start();
augScreen.setVisibility(View.VISIBLE);
augScreen.onResume();

In onPause;
Code: [Select]
augScreen.setVisibility(View.INVISIBLE);
augScreen.onPause();
camScreen.stop();

Hope this helps.

M
« Last Edit: December 18, 2013, 01:43:06 pm by AugTech »

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: [Tips] Android, augmented reality 3D with JPCT + Camera.
« Reply #56 on: December 18, 2013, 01:15:46 pm »
thanks:) I guess making layout either from xml or code ends up with same thing.

I believe the right way of doing this is, somehow making camera render to GLSurfaceView. anyone did this?

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: [Tips] Android, augmented reality 3D with JPCT + Camera.
« Reply #57 on: December 18, 2013, 01:21:08 pm »
You can do this using the Vuforia SDK - That provides the image recognition and camera rendering via one 'renderFrame()' call which goes in the onDrawFrame method along with Jpct.
There's a pretty good article on the Wiki which I followed (mostly) to do just that.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: [Tips] Android, augmented reality 3D with JPCT + Camera.
« Reply #58 on: December 18, 2013, 01:33:40 pm »
yes, I saw that wiki page. actually rendering both into the same surface idea came from there.

but I cannot use it. is it open source? rendering code may help

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: [Tips] Android, augmented reality 3D with JPCT + Camera.
« Reply #59 on: December 18, 2013, 01:40:50 pm »
The QCAR/ Vuforia is not OpenSource, but it is free to use in private and commercial apps; https://developer.vuforia.com/legal/license/2-8

Which bit can't you use (commercial reasons or technical?)

Code: [Select]

frameBuffer.clear(background);

/* Call our native QCAR function to render the video
 * background and scan images for recognition */
renderFrame();

// Render the AR data to the jPCT scene
theWorld.renderScene(frameBuffer);
theWorld.draw(frameBuffer);

// Display our content...
frameBuffer.display();