Identifying objects?

  • Pete

    Pete - 2014-03-18


    I was wondering how to recognize if two things on the scene are live duplicates (fore example to avoid calculationg pfusical properties of an object several times over) and I found out that the toString() method seems to display the unique ID of any object. So I wrote a little script that prints out:


    The first two are "Cube 1" and "Cube 1.2" and they do have the sme ID.

    My questions are:
    1) Is that a good way of recognizing liveduplicates or is there something in AoI built for that?
    2) Where do those codes come from? Java has a lottery machine? (Not that it really would matter, but just asking.)



  • Luke S

    Luke S - 2014-03-18

    Okay: Two questions. Second first, as it provides some background to the answer to your real question.

    Those Strings are created by the java runtime. They are based on the


    This is not a good method to determine live duplicates for the following reasons:

    • By definition, during a single JVM run, hashcode() must return the same code for all objects that are equals(), That is, all cubes that are 1x1x1 will return the same code, regardless of whether they are live duplicates or not.
    • There is no guarantee that objects with different dimensions will have different codes.
    • There is also no guarantee that the code will be the same on different JVM runs.

    There does not currently seem to be a built-in way to determine whether two objects are live duplicates. My approach to the problem would be as follows: (java-ish pseudo-code)

    /Given that you have an ObjectInfo & Object3d reference to the item
    that you want to find duplicates of, call it myObjectInfo

    for(ObjectInfo object:scene.objects)
    /The first part of this line makes sure that we don't compare our existing
    reference to itself. That would always return true, probably not what you want.
    if ((object != myObjectInfo) && (object.object == myObjectInfo.object))
    addToListOfDuplicates(object); //Implement this as you see fit :)

    If there is a better way to do this, perhaps Peter can comment?

    Last edit: Luke S 2014-03-18
  • Peter Eastman

    Peter Eastman - 2014-03-19

    Two objects are live duplicates if both ObjectInfos refer to the same Object3D. So just check

    if (object1.object == object2.object)


  • Pete

    Pete - 2014-03-19

    Thanks. Seems to make sense. :)


Log in to post a comment.