Scene

public class Scene

The Sceneform Scene maintains the scene graph, a hierarchical organization of a scene’s content. A scene can have zero or more child nodes and each node can have zero or more child nodes.

The Scene also provides hit testing, a way to detect which node is touched by a MotionEvent or Ray.

Nested Classes

interface Scene.OnPeekTouchListener Interface definition for a callback to be invoked when a touch event is dispatched to a scene. 
interface Scene.OnTouchListener Interface definition for a callback to be invoked when a touch event is dispatched to a scene. 
interface Scene.OnUpdateListener Interface definition for a callback to be invoked once per frame immediately before the scene is updated. 

Public Constructors

Scene(SceneView view)
Create a scene with the given context.

Public Methods

void
addOnPeekTouchListener(Scene.OnPeekTouchListener onPeekTouchListener)
Adds a listener that will be called before the Scene.OnTouchListener is invoked.
void
addOnUpdateListener(Scene.OnUpdateListener onUpdateListener)
Adds a listener that will be called once per frame immediately before the Scene is updated.
Camera
getCamera()
Get the camera that is used to render the scene.
Node
getSunlight()
Get the default sunlight node.
SceneView
getView()
Returns the SceneView used to create the scene.
HitTestResult
hitTest(MotionEvent motionEvent)
Tests to see if a motion event is touching any nodes within the scene, based on a ray hit test whose origin is the screen position of the motion event, and outputs a HitTestResult containing the node closest to the screen.
HitTestResult
hitTest(Ray ray)
Tests to see if a ray is hitting any nodes within the scene and outputs a HitTestResult containing the node closest to the ray origin that intersects with the ray.
ArrayList<HitTestResult>
hitTestAll(Ray ray)
Tests to see if a ray is hitting any nodes within the scene and returns a list of HitTestResults containing all of the nodes that were hit, sorted by distance.
ArrayList<HitTestResult>
hitTestAll(MotionEvent motionEvent)
Tests to see if a motion event is touching any nodes within the scene and returns a list of HitTestResults containing all of the nodes that were hit, sorted by distance.
void
onAddChild(Node child)
void
Node
overlapTest(Node node)
Tests to see if the given node's collision shape overlaps the collision shape of any other nodes in the scene using getCollisionShape().
ArrayList<Node>
overlapTestAll(Node node)
Tests to see if a node is overlapping any other nodes within the scene using getCollisionShape().
void
removeOnPeekTouchListener(Scene.OnPeekTouchListener onPeekTouchListener)
Removes a listener that will be called before the Scene.OnTouchListener is invoked.
void
removeOnUpdateListener(Scene.OnUpdateListener onUpdateListener)
Removes a listener that will be called once per frame immediately before the Scene is updated.
void
setOnPeekTouchListener(Scene.OnPeekTouchListener onPeekTouchListener)
This method is deprecated. Will be removed in release 1.6. Please use addOnPeekTouchListener(OnPeekTouchListener) and removeOnPeekTouchListener(OnPeekTouchListener) instead.
void
setOnTouchListener(Scene.OnTouchListener onTouchListener)
Register a callback to be invoked when the scene is touched.
void
setOnUpdateListener(Scene.OnUpdateListener onUpdateListener)
This method is deprecated. Will be removed in release 1.6. Please use addOnUpdateListener(OnUpdateListener) and removeOnUpdateListener(OnUpdateListener) instead.

Inherited Methods

Public Constructors

public Scene (SceneView view)

Create a scene with the given context.

Parameters
view

Public Methods

public void addOnPeekTouchListener (Scene.OnPeekTouchListener onPeekTouchListener)

Adds a listener that will be called before the Scene.OnTouchListener is invoked. This is invoked even if the gesture was consumed, making it possible to observe all motion events dispatched to the scene. This is called even if the touch is not over a node, in which case getNode() will be null. The listeners will be called in the order in which they were added.

Parameters
onPeekTouchListener the peek touch listener to add

public void addOnUpdateListener (Scene.OnUpdateListener onUpdateListener)

Adds a listener that will be called once per frame immediately before the Scene is updated. The listeners will be called in the order in which they were added.

Parameters
onUpdateListener the update listener to add

public Camera getCamera ()

Get the camera that is used to render the scene. The camera is a type of node.

Returns
  • the camera used to render the scene

public Node getSunlight ()

Get the default sunlight node.

Returns
  • the sunlight node used to light the scene

public SceneView getView ()

Returns the SceneView used to create the scene.

public HitTestResult hitTest (MotionEvent motionEvent)

Tests to see if a motion event is touching any nodes within the scene, based on a ray hit test whose origin is the screen position of the motion event, and outputs a HitTestResult containing the node closest to the screen.

Parameters
motionEvent the motion event to use for the test
Returns
  • the result includes the first node that was hit by the motion event (may be null), and information about where the motion event hit the node in world-space

public HitTestResult hitTest (Ray ray)

Tests to see if a ray is hitting any nodes within the scene and outputs a HitTestResult containing the node closest to the ray origin that intersects with the ray.

Parameters
ray the ray to use for the test
Returns
  • the result includes the first node that was hit by the ray (may be null), and information about where the ray hit the node in world-space

public ArrayList<HitTestResult> hitTestAll (Ray ray)

Tests to see if a ray is hitting any nodes within the scene and returns a list of HitTestResults containing all of the nodes that were hit, sorted by distance.

Parameters
ray The ray to use for the test.
Returns
  • Populated with a HitTestResult for each node that was hit sorted by distance. Empty if no nodes were hit.

public ArrayList<HitTestResult> hitTestAll (MotionEvent motionEvent)

Tests to see if a motion event is touching any nodes within the scene and returns a list of HitTestResults containing all of the nodes that were hit, sorted by distance.

Parameters
motionEvent The motion event to use for the test.
Returns
  • Populated with a HitTestResult for each node that was hit sorted by distance. Empty if no nodes were hit.

public void onAddChild (Node child)

Parameters
child

public void onRemoveChild (Node child)

Parameters
child

public Node overlapTest (Node node)

Tests to see if the given node's collision shape overlaps the collision shape of any other nodes in the scene using getCollisionShape(). The node used for testing does not need to be active.

Parameters
node The node to use for the test.
Returns
  • A node that is overlapping the test node. If no node is overlapping the test node, then this is null. If multiple nodes are overlapping the test node, then this could be any of them.

public ArrayList<Node> overlapTestAll (Node node)

Tests to see if a node is overlapping any other nodes within the scene using getCollisionShape(). The node used for testing does not need to be active.

Parameters
node The node to use for the test.
Returns
  • A list of all nodes that are overlapping the test node. If no node is overlapping the test node, then the list is empty.

public void removeOnPeekTouchListener (Scene.OnPeekTouchListener onPeekTouchListener)

Removes a listener that will be called before the Scene.OnTouchListener is invoked. This is invoked even if the gesture was consumed, making it possible to observe all motion events dispatched to the scene. This is called even if the touch is not over a node, in which case getNode() will be null.

Parameters
onPeekTouchListener the peek touch listener to remove

public void removeOnUpdateListener (Scene.OnUpdateListener onUpdateListener)

Removes a listener that will be called once per frame immediately before the Scene is updated.

Parameters
onUpdateListener the update listener to remove

public void setOnPeekTouchListener (Scene.OnPeekTouchListener onPeekTouchListener)

This method was deprecated in API level .
Will be removed in release 1.6. Please use addOnPeekTouchListener(OnPeekTouchListener) and removeOnPeekTouchListener(OnPeekTouchListener) instead.

Register a callback to be invoked before the Scene.OnTouchListener is invoked. This is invoked even if the gesture was consumed, making it possible to ovserve all motion events dispatched to the scene. This is called even if the touch is not over a node, in which case getNode() will be null.

Parameters
onPeekTouchListener the peek touch listener to attach

public void setOnTouchListener (Scene.OnTouchListener onTouchListener)

Register a callback to be invoked when the scene is touched. The callback will be invoked after the touch event is dispatched to the nodes in the scene if no node consumed the event. This is called even if the touch is not over a node, in which case getNode() will be null.

Parameters
onTouchListener the touch listener to attach

public void setOnUpdateListener (Scene.OnUpdateListener onUpdateListener)

This method was deprecated in API level .
Will be removed in release 1.6. Please use addOnUpdateListener(OnUpdateListener) and removeOnUpdateListener(OnUpdateListener) instead.

Register a callback to be invoked once per frame immediately before the Scene is updated.

Parameters
onUpdateListener the update listener to attach

Send feedback about...