22
22
23
23
package processing .ar ;
24
24
25
- import android .Manifest ;
26
25
import android .app .Activity ;
27
26
import android .app .ActivityManager ;
28
27
import android .app .AlertDialog ;
31
30
import android .content .DialogInterface ;
32
31
import android .content .Intent ;
33
32
import android .content .pm .ConfigurationInfo ;
34
- import android .content .pm .PackageManager ;
35
33
import android .content .res .AssetManager ;
36
34
import android .opengl .GLES20 ;
37
35
import android .opengl .GLSurfaceView ;
42
40
43
41
import processing .android .AppComponent ;
44
42
import processing .ar .render .*;
45
- import processing .core .PApplet ;
46
43
import processing .core .PGraphics ;
47
44
import processing .opengl .PGLES ;
48
45
import processing .opengl .PGraphicsOpenGL ;
58
55
import java .util .concurrent .ArrayBlockingQueue ;
59
56
60
57
public class PSurfaceAR extends PSurfaceGLES {
61
-
62
- private GLSurfaceView surfaceView ;
63
- protected AndroidARRenderer renderer ;
64
- protected PGraphicsAR par ;
65
-
66
- public static float [] anchorMatrix = new float [16 ];
67
- public static float [] quaternionMatrix = new float [16 ];
68
- public static ArrayBlockingQueue <MotionEvent > queuedTaps = new ArrayBlockingQueue <>(16 );
69
- public static ArrayList <Anchor > anchors = new ArrayList <>();
70
-
71
- public static float [] projmtx ;
72
- public static float [] viewmtx ;
73
-
74
- public static float lightIntensity ;
75
-
76
- public static Session session ;
77
- public static Pose mainPose ;
78
- public static RotationHandler displayRotationHelper ;
79
-
80
- public static String PLANE_TEXTURE = "grid.png" ;
81
- public static String OBJ_NAME = null ;
82
- public static String OBJ_TEX = null ;
83
- public static boolean PLACED = false ;
84
-
85
- public static PBackground backgroundRenderer = new PBackground ();
86
- public static PPlane planeRenderer = new PPlane ();
87
- public static PPointCloud pointCloud = new PPointCloud ();
88
- public static PObject virtualObject = new PObject ();
89
-
90
58
private static String T_ALERT_MESSAGE = "ALERT" ;
91
59
private static String C_NOT_SUPPORTED = "ARCore SDK required to run this app type" ;
92
60
private static String T_PROMPT_MESSAGE = "PROMPT" ;
@@ -95,11 +63,29 @@ public class PSurfaceAR extends PSurfaceGLES {
95
63
private static String C_EXCEPT_UPDATE_SDK = "Please update ARCore" ;
96
64
private static String C_EXCEPT_UPDATE_APP = "Please update this app" ;
97
65
private static String C_DEVICE = "This device does not support AR" ;
98
- private static final int CAMERA_PERMISSION_CODE = 0 ;
99
- private static final String CAMERA_PERMISSION = Manifest .permission .CAMERA ;
100
66
101
- ProgressDialog progressdialog = new ProgressDialog (activity );
67
+ protected GLSurfaceView surfaceView ;
68
+ protected AndroidARRenderer renderer ;
69
+ protected PGraphicsAR par ;
70
+
71
+ protected static float [] anchorMatrix = new float [16 ];
72
+ protected static ArrayBlockingQueue <MotionEvent > queuedTaps = new ArrayBlockingQueue <>(16 );
73
+ protected static ArrayList <Anchor > anchors = new ArrayList <>();
102
74
75
+ protected float [] projmtx ;
76
+ protected float [] viewmtx ;
77
+
78
+ protected float lightIntensity ;
79
+
80
+ protected Session session ;
81
+ protected Pose mainPose ;
82
+ protected RotationHandler displayRotationHelper ;
83
+
84
+ protected PBackground backgroundRenderer = new PBackground ();
85
+ protected PPlane planeRenderer = new PPlane ();
86
+ protected PPointCloud pointCloud = new PPointCloud ();
87
+
88
+ protected ProgressDialog progressdialog = new ProgressDialog (activity );
103
89
104
90
public PSurfaceAR (PGraphics graphics , AppComponent appComponent , SurfaceHolder surfaceHolder ) {
105
91
super (graphics , appComponent , surfaceHolder );
@@ -186,8 +172,6 @@ public void dispose() {
186
172
public class SurfaceViewAR extends GLSurfaceView {
187
173
public SurfaceViewAR (Context context ) {
188
174
super (context );
189
- // sketch.setup();
190
- // sketch.draw();
191
175
192
176
final ActivityManager activityManager = (ActivityManager ) context .getSystemService (Context .ACTIVITY_SERVICE );
193
177
final ConfigurationInfo configurationInfo = activityManager .getDeviceConfigurationInfo ();
@@ -244,16 +228,8 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
244
228
pgl .getGL (null );
245
229
GLES20 .glClearColor (0.1f , 0.1f , 0.1f , 1.0f );
246
230
backgroundRenderer .createOnGlThread (activity );
247
- if (OBJ_NAME != null && OBJ_TEX != null ) {
248
- try {
249
- virtualObject .createOnGlThread (activity , OBJ_NAME , OBJ_TEX );
250
- virtualObject .setMaterialProperties (0.0f , 3.5f , 1.0f , 6.0f );
251
- } catch (IOException e ) {
252
- PGraphics .showWarning ("Failed to read obj file" );
253
- }
254
- }
255
231
try {
256
- planeRenderer .createOnGlThread (activity , PLANE_TEXTURE );
232
+ planeRenderer .createOnGlThread (activity );
257
233
} catch (IOException e ) {
258
234
PGraphics .showWarning ("Failed to read plane texture" );
259
235
}
@@ -274,12 +250,7 @@ public void onSurfaceChanged(GL10 gl, int width, int height) {
274
250
275
251
@ Override
276
252
public void onDrawFrame (GL10 gl ) {
277
- GLES20 .glClear (GLES20 .GL_COLOR_BUFFER_BIT | GLES20 .GL_DEPTH_BUFFER_BIT );
278
-
279
- if (session == null ) {
280
- return ;
281
- }
282
- performRendering ();
253
+ if (session == null ) return ;
283
254
284
255
if (progressdialog != null ) {
285
256
for (Plane plane : session .getAllTrackables (Plane .class )) {
@@ -296,7 +267,9 @@ public void onDrawFrame(GL10 gl) {
296
267
}
297
268
}
298
269
299
- public static void performRendering () {
270
+ public void performRendering () {
271
+ if (session == null ) return ;
272
+
300
273
displayRotationHelper .updateSessionIfNeeded (session );
301
274
302
275
try {
@@ -348,11 +321,6 @@ public static void performRendering() {
348
321
continue ;
349
322
}
350
323
anchor .getPose ().toMatrix (anchorMatrix , 0 );
351
-
352
- if ((OBJ_NAME != null && OBJ_TEX != null ) && PLACED ) {
353
- virtualObject .updateModelMatrix (anchorMatrix , scaleFactor );
354
- virtualObject .draw (viewmtx , projmtx , lightIntensity );
355
- }
356
324
}
357
325
} catch (Throwable t ) {
358
326
PGraphics .showWarning ("Exception on the OpenGL thread" );
0 commit comments