Motorola E680 Technical Manual - Page 35

Interrogating and interacting with objects - manual

Page 35 highlights

9 JSR 184 } The finally block makes sure that the target is released and the Graphics3D can be reused. The bindTarget call must be outside the try block, as it can throw exceptions that will cause releaseTarget to be called when a target has not been bound, and releaseTarget throwing an exception. Interrogating and interacting with objects The World object is a container that sits at the top of the hierarchy of objects that form the scene graph. You can find particular objects within the scene very simply by calling find() with an ID. find() returns a reference to the object which has been assigned that ID in the authoring tool (or manually assigned from code). This is important because it largely makes the application logic independent of the detailed structure of the scene. final int PERSON_OBJECT_ID = 339929883; Node personNode = (Node)theWorld.find(PERSON_OBJECT_ID); If you need to find many objects, or you don't have a fixed ID, then you can follow the hierarchy explicitly using the Object3D.getReferences() or Group.getChild() methods. static void traverseDescendants(Object3D obj) { int numReferences = obj.getReferences(null); if (numReferences > 0) { Object3D[] objArray = new Object3D[numReferences]; obj.getReferences(objArray); for (int i = 0; i < numReferences; i++) traverseDescendants(objArray[i]); } } Once you have an object, most of the properties on it can be modified using the M3G API. For example, you can change the position, size, orientation, color, brightness, or whatever other attribute of the object is important. You can also create and delete objects and insert them into the world, or link parts of other M3G files into the scene graph. 35

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107

9
JSR 184
35
}
The finally block makes sure that the target is released and the Graphics3D can be
reused.
The bindTarget call must be outside the try block, as it can throw exceptions that
will cause releaseTarget to be called when a target has not been bound, and
releaseTarget throwing an exception.
Interrogating and interacting with objects
The World object is a container that sits at the top of the hierarchy of objects that form the
scene graph. You can find particular objects within the scene very simply by calling find()
with an ID. find() returns a reference to the object which has been assigned that ID in the
authoring tool (or manually assigned from code). This is important because it largely
makes the application logic independent of the detailed structure of the scene.
final int PERSON_OBJECT_ID = 339929883;
Node personNode = (Node)theWorld.find(PERSON_OBJECT_ID);
If you need to find many objects, or you don’t have a fixed ID, then you can follow the
hierarchy explicitly using the Object3D.getReferences() or Group.getChild() methods.
static void traverseDescendants(Object3D obj)
{
int numReferences = obj.getReferences(null);
if (numReferences > 0)
{
Object3D[] objArray = new Object3D[numReferences];
obj.getReferences(objArray);
for (int i = 0; i < numReferences; i++)
traverseDescendants(objArray[i]);
}
}
Once you have an object, most of the properties on it can be modified using the M3G API.
For example, you can change the position, size, orientation, color, brightness, or whatever
other attribute of the object is important. You can also create and delete objects and insert
them into the world, or link parts of other M3G files into the scene graph.