Skip to content

Commit 2d62698

Browse files
committed
Renaming as AR non-core library
1 parent da9b631 commit 2d62698

File tree

9 files changed

+100
-76
lines changed

9 files changed

+100
-76
lines changed

core/src/processing/core/PConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public interface PConstants {
5252
static final String STEREO = "processing.vr.PGraphicsVRStereo";
5353
static final String MONO = "processing.vr.PGraphicsVRMono";
5454
static final String VR = STEREO;
55-
static final String AR = "processing.ar.PGraphicsAR";
55+
static final String AR = "processing.ar.ARGraphics";
5656
static final String ARCORE = AR;
5757

5858
// The PDF and DXF renderers are not available for Android.

debug/apps/arscene/src/main/java/arscene/Sketch.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,53 @@
77

88
public class Sketch extends PApplet {
99
float angle;
10-
Anchor selAnchor;
11-
ArrayList<Anchor> regAnchors;
12-
ArrayList<Anchor> delAnchors;
10+
ARAnchor touchAnchor;
11+
ArrayList<ARAnchor> trackAnchors;
1312

14-
Tracker tracker;
13+
ARTracker tracker;
1514

1615
public void settings() {
1716
fullScreen(AR);
1817
}
1918

2019
public void setup() {
21-
tracker = new Tracker(this);
20+
tracker = new ARTracker(this);
2221
tracker.start();
23-
regAnchors = new ArrayList<Anchor>();
24-
delAnchors = new ArrayList<Anchor>();
22+
trackAnchors = new ArrayList<ARAnchor>();
2523
}
2624

2725
public void draw() {
2826
// The AR Core session, frame and camera can be accessed through Processing's surface object
2927
// to obtain the full information about the AR scene:
30-
// PSurfaceAR surface = (PSurfaceAR) getSurface();
28+
// ARSurface surface = (ARSurface) getSurface();
3129
// surface.camera.getPose();
3230
// surface.frame.getLightEstimate();
3331

3432
lights();
3533

3634
if (mousePressed) {
3735
// Create new anchor at the current touch point
38-
if (selAnchor != null) selAnchor.dispose();
39-
Trackable hit = tracker.get(mouseX, mouseY);
40-
if (hit != null) selAnchor = new Anchor(hit);
41-
else selAnchor = null;
36+
if (touchAnchor != null) touchAnchor.dispose();
37+
ARTrackable hit = tracker.get(mouseX, mouseY);
38+
if (hit != null) touchAnchor = new ARAnchor(hit);
39+
else touchAnchor = null;
4240
}
4341

4442
// Draw objects attached to each anchor
45-
for (Anchor anchor : regAnchors) {
43+
for (ARAnchor anchor : trackAnchors) {
4644
if (anchor.isTracking()) drawBox(anchor, 255, 255, 255);
4745

4846
// It is very important to dispose anchors once they are no longer tracked.
4947
if (anchor.isStopped()) anchor.dispose();
5048
}
51-
if (selAnchor != null) drawBox(selAnchor, 255, 0, 0);
49+
if (touchAnchor != null) drawBox(touchAnchor, 255, 0, 0);
5250

5351
// Conveniency function in the tracker object to remove disposed anchors from a list
54-
tracker.clearAnchors(regAnchors);
52+
tracker.clearAnchors(trackAnchors);
5553

5654
// Draw trackable planes
5755
for (int i = 0; i < tracker.count(); i++) {
58-
Trackable trackable = tracker.get(i);
56+
ARTrackable trackable = tracker.get(i);
5957
if (!trackable.isTracking()) continue;
6058

6159
pushMatrix();
@@ -79,16 +77,16 @@ public void draw() {
7977
angle += 0.1;
8078
}
8179

82-
public void drawBox(Anchor anchor, int r, int g, int b) {
80+
public void drawBox(ARAnchor anchor, int r, int g, int b) {
8381
anchor.attach();
8482
fill(r, g, b);
8583
rotateY(angle);
8684
box(0.15f);
8785
anchor.detach();
8886
}
8987

90-
public void trackableEvent(Trackable t) {
91-
if (regAnchors.size() < 10) {
88+
public void trackableEvent(ARTrackable t) {
89+
if (trackAnchors.size() < 10) {
9290
float x0 = 0, y0 = 0;
9391
if (t.isWallPlane()) {
9492
// The new trackable is a wall, so adding the anchor 0.3 meters to its side
@@ -100,7 +98,7 @@ public void trackableEvent(Trackable t) {
10098
// The new trackable is a floor plane, so adding the anchor 0.3 meters below it
10199
y0 = -0.3f;
102100
}
103-
regAnchors.add(new Anchor(t, x0, y0, 0));
101+
trackAnchors.add(new ARAnchor(t, x0, y0, 0));
104102
}
105103
}
106104
}

mode/libraries/ar/src/processing/ar/Anchor.java renamed to mode/libraries/ar/src/processing/ar/ARAnchor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@
2424

2525
import processing.core.PMatrix3D;
2626

27-
public class Anchor {
28-
protected PGraphicsAR g;
27+
public class ARAnchor {
28+
protected ARGraphics g;
2929
private boolean disposed = false;
3030

3131
private int id;
3232
private PMatrix3D m;
3333

34-
public Anchor(Trackable trackable, float x, float y, float z) {
34+
public ARAnchor(ARTrackable trackable, float x, float y, float z) {
3535
this.g = trackable.g;
3636

3737
int idx = g.trackableIndex(Integer.parseInt(trackable.id()));
3838
id = g.createAnchor(idx, x, y, z);
3939
}
4040

41-
public Anchor(Trackable trackable) {
41+
public ARAnchor(ARTrackable trackable) {
4242
this.g = trackable.g;
4343
id = g.createAnchor(trackable.hit);
4444
trackable.hit = null;
@@ -70,15 +70,15 @@ public void detach() {
7070
}
7171

7272
public boolean isTracking() {
73-
return g.anchorStatus(id) == PGraphicsAR.TRACKING;
73+
return g.anchorStatus(id) == ARGraphics.TRACKING;
7474
}
7575

7676
public boolean isPaused() {
77-
return g.anchorStatus(id) == PGraphicsAR.PAUSED;
77+
return g.anchorStatus(id) == ARGraphics.PAUSED;
7878
}
7979

8080
public boolean isStopped() {
81-
return g.anchorStatus(id) == PGraphicsAR.STOPPED;
81+
return g.anchorStatus(id) == ARGraphics.STOPPED;
8282
}
8383

8484
public boolean isDisposed() {

mode/libraries/ar/src/processing/ar/PGraphicsAR.java renamed to mode/libraries/ar/src/processing/ar/ARGraphics.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import processing.opengl.PGraphicsOpenGL;
4848
import processing.opengl.PShader;
4949

50-
public class PGraphicsAR extends PGraphics3D {
50+
public class ARGraphics extends PGraphics3D {
5151
static protected final int UNKNOWN = -1;
5252

5353
static protected final int PLANE_FLOOR = 0;
@@ -60,7 +60,7 @@ public class PGraphicsAR extends PGraphics3D {
6060
static protected final int STOPPED = 2;
6161

6262
// Convenience reference to the AR surface. It is the same object one gets from PApplet.getSurface().
63-
protected PSurfaceAR surfar;
63+
protected ARSurface surfar;
6464

6565
protected BackgroundRenderer backgroundRenderer;
6666

@@ -69,7 +69,7 @@ public class PGraphicsAR extends PGraphics3D {
6969
protected float[] anchorMatrix = new float[16];
7070
protected float[] colorCorrection = new float[4];
7171

72-
protected ArrayList<Tracker> trackers = new ArrayList<Tracker>();
72+
protected ArrayList<ARTracker> trackers = new ArrayList<ARTracker>();
7373
protected ArrayList<Plane> trackPlanes = new ArrayList<Plane>();
7474
protected HashMap<Plane, float[]> trackMatrices = new HashMap<Plane, float[]>();
7575
protected HashMap<Plane, Integer> trackIds = new HashMap<Plane, Integer>();
@@ -98,18 +98,18 @@ public class PGraphicsAR extends PGraphics3D {
9898
protected PShader arLightShader;
9999
protected PShader arTexlightShader;
100100

101-
public PGraphicsAR() {
101+
public ARGraphics() {
102102
}
103103

104104

105-
static processing.ar.Trackable[] getTrackables() {
105+
static ARTrackable[] getTrackables() {
106106
return null;
107107
}
108108

109109
@Override
110110
public PSurface createSurface(AppComponent appComponent, SurfaceHolder surfaceHolder, boolean reset) {
111111
if (reset) pgl.resetFBOLayer();
112-
surfar = new PSurfaceAR(this, appComponent, surfaceHolder);
112+
surfar = new ARSurface(this, appComponent, surfaceHolder);
113113
return surfar;
114114
}
115115

@@ -199,12 +199,12 @@ protected void updateView() {
199199
}
200200

201201

202-
public void addTracker(Tracker tracker) {
202+
public void addTracker(ARTracker tracker) {
203203
trackers.add(tracker);
204204
}
205205

206206

207-
public void removeTracker(Tracker tracker) {
207+
public void removeTracker(ARTracker tracker) {
208208
trackers.remove(tracker);
209209
}
210210

@@ -303,6 +303,17 @@ public float[] getTrackablePolygon(int i, float[] points) {
303303
}
304304

305305

306+
public float getTrackableExtentX(int i) {
307+
Plane plane = trackPlanes.get(i);
308+
return plane.getExtentX();
309+
}
310+
311+
312+
public float getTrackableExtentZ(int i) {
313+
Plane plane = trackPlanes.get(i);
314+
return plane.getExtentZ();
315+
}
316+
306317
public PMatrix3D getTrackableMatrix(int i) {
307318
return getTrackableMatrix(i, null);
308319
}
@@ -454,7 +465,7 @@ protected void updateTrackables() {
454465
trackMatrices.remove(plane);
455466
int pid = trackIds.remove(plane);
456467
trackIdx.remove(pid);
457-
for (Tracker t: trackers) t.remove(pid);
468+
for (ARTracker t: trackers) t.remove(pid);
458469
}
459470
}
460471

@@ -464,7 +475,7 @@ protected void updateTrackables() {
464475
int pid = trackIds.get(plane);
465476
trackIdx.put(pid, i);
466477
if (newPlanes.contains(plane)) {
467-
for (Tracker t: trackers) t.create(i);
478+
for (ARTracker t: trackers) t.create(i);
468479
}
469480
}
470481
}

mode/libraries/ar/src/processing/ar/PSurfaceAR.java renamed to mode/libraries/ar/src/processing/ar/ARSurface.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
import java.io.File;
5050
import java.io.InputStream;
5151

52-
public class PSurfaceAR extends PSurfaceGLES {
52+
public class ARSurface extends PSurfaceGLES {
5353
private static String T_ALERT_MESSAGE = "ALERT";
5454
private static String C_NOT_SUPPORTED = "ARCore SDK required to run this app type";
5555
private static String T_PROMPT_MESSAGE = "PROMPT";
@@ -66,18 +66,18 @@ public class PSurfaceAR extends PSurfaceGLES {
6666

6767
protected GLSurfaceView surfaceView;
6868
protected AndroidARRenderer renderer;
69-
protected PGraphicsAR par;
69+
protected ARGraphics par;
7070

7171
protected RotationHandler displayRotationHelper;
7272

73-
public PSurfaceAR(PGraphics graphics, AppComponent appComponent, SurfaceHolder surfaceHolder) {
73+
public ARSurface(PGraphics graphics, AppComponent appComponent, SurfaceHolder surfaceHolder) {
7474
super(graphics, appComponent, surfaceHolder);
7575
this.sketch = graphics.parent;
7676
this.graphics = graphics;
7777
this.component = appComponent;
7878
this.pgl = (PGLES) ((PGraphicsOpenGL) graphics).pgl;
7979

80-
par = (PGraphicsAR) graphics;
80+
par = (ARGraphics) graphics;
8181

8282
displayRotationHelper = new RotationHandler(activity);
8383
surfaceView = new SurfaceViewAR(activity);

mode/libraries/ar/src/processing/ar/Trackable.java renamed to mode/libraries/ar/src/processing/ar/ARTrackable.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626

2727
import com.google.ar.core.HitResult;
2828

29-
public class Trackable {
30-
protected PGraphicsAR g;
29+
public class ARTrackable {
30+
protected ARGraphics g;
3131
protected HitResult hit;
3232

3333
private int id;
3434
private PMatrix3D m;
3535
private float[] points;
3636

37-
public Trackable(PGraphicsAR g, int id) {
37+
public ARTrackable(ARGraphics g, int id) {
3838
this.g = g;
3939
this.id = id;
4040
}
@@ -59,6 +59,24 @@ public float[] getPolygon() {
5959
return points;
6060
}
6161

62+
63+
public float lengthX() {
64+
int idx = g.trackableIndex(id);
65+
return g.getTrackableExtentX(idx);
66+
}
67+
68+
69+
public float lengthY() {
70+
return 0;
71+
}
72+
73+
74+
public float lengthZ() {
75+
int idx = g.trackableIndex(id);
76+
return g.getTrackableExtentZ(idx);
77+
}
78+
79+
6280
public boolean isSelected(int mx, int my) {
6381
int idx = g.trackableIndex(id);
6482
return g.trackableSelected(idx, mx, my);
@@ -71,17 +89,17 @@ public boolean isNew() {
7189

7290
public boolean isTracking() {
7391
int idx = g.trackableIndex(id);
74-
return g.trackableStatus(idx) == PGraphicsAR.TRACKING;
92+
return g.trackableStatus(idx) == ARGraphics.TRACKING;
7593
}
7694

7795
public boolean isPaused() {
7896
int idx = g.trackableIndex(id);
79-
return g.trackableStatus(idx) == PGraphicsAR.PAUSED;
97+
return g.trackableStatus(idx) == ARGraphics.PAUSED;
8098
}
8199

82100
public boolean isStopped() {
83101
int idx = g.trackableIndex(id);
84-
return g.trackableStatus(idx) == PGraphicsAR.STOPPED;
102+
return g.trackableStatus(idx) == ARGraphics.STOPPED;
85103
}
86104

87105
public boolean isPlane() {
@@ -94,16 +112,16 @@ public boolean isPointCloud() {
94112

95113
public boolean isFloorPlane() {
96114
int idx = g.trackableIndex(id);
97-
return g.trackableType(idx) == PGraphicsAR.PLANE_FLOOR;
115+
return g.trackableType(idx) == ARGraphics.PLANE_FLOOR;
98116
}
99117

100118
public boolean isCeilingPlane() {
101119
int idx = g.trackableIndex(id);
102-
return g.trackableType(idx) == PGraphicsAR.PLANE_CEILING;
120+
return g.trackableType(idx) == ARGraphics.PLANE_CEILING;
103121
}
104122

105123
public boolean isWallPlane() {
106124
int idx = g.trackableIndex(id);
107-
return g.trackableType(idx) == PGraphicsAR.PLANE_WALL;
125+
return g.trackableType(idx) == ARGraphics.PLANE_WALL;
108126
}
109127
}

0 commit comments

Comments
 (0)