@@ -62,16 +62,21 @@ public class PGraphicsAR extends PGraphics3D {
6262
6363 protected ArrayList <Plane > trackPlanes = new ArrayList <Plane >();
6464 protected HashMap <Plane , float []> trackMatrices = new HashMap <Plane , float []>();
65+ protected HashMap <Plane , Integer > trackIds = new HashMap <Plane , Integer >();
6566
6667 protected ArrayList <Plane > newPlanes = new ArrayList <Plane >();
6768 protected ArrayList <Plane > updatedPlanes = new ArrayList <Plane >();
6869 protected ArrayList <Anchor > delAnchors = new ArrayList <Anchor >();
6970
7071 protected ArrayList <Anchor > anchors = new ArrayList <Anchor >();
72+ protected HashMap <Anchor , Integer > anchorIds = new HashMap <Anchor , Integer >();
7173
7274 protected float [] pointIn = new float [3 ];
7375 protected float [] pointOut = new float [3 ];
7476
77+ protected int lastTrackableId = 0 ;
78+ protected int lastAnchorId = 0 ;
79+
7580
7681 public PGraphicsAR () {
7782 }
@@ -178,7 +183,7 @@ public int trackableCount() {
178183
179184 @ Override
180185 public int trackableId (int i ) {
181- return trackPlanes .get (i ). hashCode ( );
186+ return trackIds . get ( trackPlanes .get (i ));
182187 }
183188
184189
@@ -280,7 +285,7 @@ public int anchorCount() {
280285
281286 @ Override
282287 public int anchorId (int i ) {
283- return anchors .get (i ). hashCode ( );
288+ return anchorIds . get ( anchors .get (i ));
284289 }
285290
286291
@@ -309,7 +314,8 @@ public int createAnchor(int i, float x, float y, float z) {
309314 Pose anchorPose = Pose .makeTranslation (pointOut );
310315 Anchor anchor = plane .createAnchor (anchorPose );
311316 anchors .add (anchor );
312- return anchors .size () - 1 ;
317+ anchorIds .put (anchor , ++lastAnchorId );
318+ return lastAnchorId ;
313319 }
314320
315321
@@ -322,11 +328,12 @@ public int createAnchor(int mx, int my) {
322328 if (trackPlanes .contains (plane ) && plane .isPoseInPolygon (hit .getHitPose ())) {
323329 Anchor anchor = hit .createAnchor ();
324330 anchors .add (anchor );
325- return anchors .size () - 1 ;
331+ anchorIds .put (anchor , ++lastAnchorId );
332+ return lastAnchorId ;
326333 }
327334 }
328335 }
329- return - 1 ;
336+ return 0 ;
330337 }
331338
332339
@@ -401,6 +408,7 @@ protected void updateTrackables() {
401408 mat = new float [16 ];
402409 trackMatrices .put (plane , mat );
403410 trackPlanes .add (plane );
411+ trackIds .put (plane , ++lastTrackableId );
404412 newPlanes .add (plane );
405413 System .out .println ("-------------> ADDED TRACKING PLANE " + plane .hashCode ());
406414 }
@@ -415,6 +423,7 @@ protected void updateTrackables() {
415423 if (plane .getTrackingState () == TrackingState .STOPPED || plane .getSubsumedBy () != null ) {
416424 trackPlanes .remove (i );
417425 trackMatrices .remove (plane );
426+ trackIds .remove (plane );
418427 System .out .println ("-------------> REMOVED TRACKING PLANE " + plane .hashCode ());
419428 }
420429 }
@@ -427,6 +436,7 @@ protected void cleanup() {
427436
428437 for (Anchor anchor : delAnchors ) {
429438 anchor .detach ();
439+ anchorIds .remove (anchor );
430440 anchors .remove (anchor );
431441 System .out .println ("-------------> REMOVED ANCHOR PLANE " + anchor .hashCode ());
432442 }
0 commit comments