Generic, empty 3D node in the scene graph. The transforms set on a node (position, rotation, scale), apply to all children. See the Scenes guide for more information. Animatable.

Example use:
<ViroNode
    position={[2.0, 5.0, -2.0]}
    rotation={[0, 45, 45]}
    scale={[2.0, 2.0, 2.0]}
/>

Props

animation

TypeDescription
ViroAnimationPropsA collection of parameters that determine if this component should animate. For more information on animated components please see our Animation Guide.

dragPlane

TypeDescription
ViroDragPlaneWhen a drag type of "FixedToPlane" is given, dragging is limited to a user defined plane. The dragging behavior is then configured by this property (specified by a point on the plane and its normal vector). You can also limit the maximum distance the dragged object is allowed to travel away from the camera/controller (useful for situations where the user can drag an object towards infinity).

dragType

TypeDescription
"FixedDistance" | "FixedToWorld" | "FixedDistanceOrigin" | "FixedToPlane"Determines the behavior of drag if onDrag is specified. The default value is "FixedDistance".

FixedDistance: Dragging is limited to a fixed radius around the user, dragged from the point at which the user has grabbed the geometry containing this draggable node

FixedDistanceOrigin: Dragging is limited to a fixed radius around the user, dragged from the point of this node's position in world space.

FixedToWorld: Dragging is based on intersection with real world objects. Available only in AR

FixedToPlane: Dragging is limited to a fixed plane around the user. The configuration of this plane is defined by the dragPlane property.

highAccuracyEvents

TypeDescription
booleanTrue if events should use the geometry of the object to determine if the user is interacting with this object. If false, the object's axis-aligned bounding box will be used instead. Enabling this is more accurate but takes more processing power, so it is set to false by default.

ignoreEventHandling

TypeDescription
booleanWhen set to true, this control will ignore events and not prevent controls behind it from receiving event callbacks.

The default value is false.

onClick

TypeDescription
Called when an object has been clicked.

The position parameter represents the position in world coordinates on the box where the click occurred.

For the mapping of sources to controller inputs, see the Events section.
<ViroNode onClick={(position, source) => console.log('Click', position, source)}/>

onClickState

TypeDescription
Called for each click state an object goes through as it is clicked. Supported click states and their values are the following:

Click Down (1): Triggered when the user has performed a click down action while hovering on this control.

Click Up (2): Triggered when the user has performed a click up action while hovering on this control.

Clicked (3): Triggered when the user has performed both a click down and click up action on this control sequentially, thereby having "Clicked" the object.

For the mapping of sources to controller inputs, see the Events section.
<ViroNode 
  height={2}
  length={2}
  width={2}
  onClickState={(stateValue, position, source) => {
    console.log('ClickState', stateValue, position, source)
    if(stateValue == 1) {        
      // Click Down    
    } else if(stateValue == 2) {        
      // Click Up    
    } else if(stateValue == 3) {         
      // Clicked    
    }
  }}
/>

onCollision

TypeDescription
(viroTag, collidedPoint, collidedNormal) => voidCalled when this component's physics body collides with another component's physics body. Also invoked by ViroScene/ViroARScene's findCollisions... functions.

viroTag: the given viroTag (string) of the collided component

collidedPoint: an array of numbers representing the position, in world coordinates, of the point of collision

collidedNormal: an array representing the normal of the collision in world coordinates.
<ViroNode 
  height={2}
  length={2}
  width={2}
  onCollision={(viroTag, collidedPoint, collidedNormal) => 
    console.log('Collision', viroTag, collidedPoint, collidedNormal)
  }
/>

onDrag

TypeDescription
(dragToPos, source) => voidCalled when the view is currently being dragged. The dragToPos parameter provides the current 3D location of the dragged object. For the mapping of sources to controller inputs, see the Events section.

Unsupported VR Platforms: Cardboard iOS
<ViroNode 
  height={2}
  length={2}
  width={2}
  onDrag={(dragToPos, source) => {    
  	console.log('Drag', dragToPos, source);
    // dragtoPos[0]: x position    
    // dragtoPos[1]: y position    
    // dragtoPos[2]: z position
  }}
/>

onFuse

TypeDescription
Function | { callback: Function, timeToFuse?: number }onFuse takes one of two types - either a callback, or a dictionary with a callback and duration. It is called after the user hovers onto and remains hovered on the control for a certain duration of time, as indicated in timeToFuse that represents the duration of time in milliseconds. While hovering, the reticle will display a count down animation while fusing towards timeToFuse. For the mapping of sources to controller inputs, see the Events section.

Note that timeToFuse defaults to 2000ms.
<ViroNode 
  height={2}
  length={2}
  width={2}
  onFuse={{
    callback: (source) => {
      console.log('Fuse', source);
    	// User has hovered over object for timeToFuse milliseconds
    },
    timeToFuse: 3000,
  }}
/>

onHover

TypeDescription
(isHovering, position, source) => voidCalled when the user hovers on or off the control. For the mapping of sources to controller inputs, see the Events section.
<ViroNode 
  height={2}
  length={2}
  width={2}
  onHover={
  (isHovering, position, source) => {    
    if(isHovering) {        
      // user is hovering over the box    
    } else {        
      // user is no longer hovering over the box    
    }
  }}
/>

onPinch

🚧

onPinch

This event is only available in AR.

TypeDescription
Called when the user performs a pinch gesture on the control. When the pinch starts, the scale factor is set to 1 is relative to the points of the two touch points.

pinchState can be the following values:
Pinch Start (1): Triggered when the user has started a pinch gesture.

Pinch Move (2): Triggered when the user has adjusted the pinch, moving both fingers.

Pinch End (3): When the user has finishes the pinch gesture and released both touch points.
<ViroNode 
  height={2}
  length={2}
  width={2}
  onPinch={(pinchState, scaleFactor, source) => {
    if(pinchState == 3) {
    	// update scale of obj by multiplying by scaleFactor when pinch ends.
      return;       
    }     
    //set scale using native props to reflect pinch.  
  }} 
/>

onRotate

🚧

This event is only available in AR

TypeDescription
(rotateState, rotationFactor, source) => voidCalled when the user performs a rotation touch gesture on the control. Rotation factor is returned in degrees. When setting rotation, the rotation should be relative to it's current rotation, not set to the absolute value of the given rotationFactor. rotationFactor can be the following values:

Rotation Start (1): Triggered when the user has started a rotation gesture.

Rotation Move (2): Triggered when the user has adjusted the rotation, moving both fingers.

Rotation End (3): When the user has finishes the rotation gesture and released both touch points.
<ViroNode 
  height={2}
  length={2}
  width={2}
  onRotate={(rotateState, rotationFactor, source) => {
    if (rotateState == 3) {
      //set to current rotation - rotationFactor.
      return;      
    }     
    //update rotation using setNativeProps    
  }}
/>

onScroll

TypeDescription
(scrollPos, source) => voidCalled when the user performs a scroll action, while hovering on the control.

For the mapping of sources to controller inputs, see the Events section. Unsupported VR Platforms: Cardboard (Android and iOS).
<ViroNode 
  height={2}
  length={2}
  width={2}
  onScroll={(scrollPos, source) => {    
    // scrollPos[0]: x scroll position from 0.0 to 1.0.     
    // scrollPos[1]: y scroll position from 0.0 to 1.0.}
  }
/>

onSwipe

TypeDescription
(state, source) => voidCalled when the user performs a swipe gesture on the physical controller, while hovering on this control.

For the mapping of sources to controller inputs, see the Events section.

Unsupported VR Platforms: Cardboard (Android and iOS)
<ViroNode 
  height={2}
  length={2}
  width={2}
  onSwipe={(state, source) => {    
    if(state == 1) {        
      // Swiped up    
    } else if(state == 2) {        
      // Swiped down    
    } else if(state == 3) {        
      // Swiped left    
    } else if(state == 4) {        
      // Swiped right    
    }
  }
/>

onTouch

TypeDescription
(state, touchPos, source) => voidCalled when the user performs a touch action, while hovering on the control. Provides the touch state type, and the x/y coordinate at which this touch event has occurred.

Touch Down (1): Triggered when the user makes physical contact with the touch pad on the controller.

Touch Down Move (2): Called when the user moves around the touch pad immediately after having performed a Touch Down action.

Touch Up (3): Triggered after the user is no longer in physical contact with the touch pad after a Touch Down action.

For the mapping of sources to controller inputs, see the Events section.

Unsupported VR Platforms: Cardboard (Android and iOS).
<ViroNode 
  height={2}
  length={2}
  width={2}
  onTouch={(state, touchPos, source) => {   
    var touchX = touchPos[0];   
    var touchY = touchPos[1];    
   
    if(state == 1) {        
      // Touch Down    
    } else if(state == 2) {        
      // Touch Down Move    
    } else if(state == 3) {         
      // Touch Up    
    }
  }
/>

onTransformUpdate

TypeDescription
FunctionA function that is invoked when the component moves and provides an array of numbers representing the component's position in world coordinates.

opacity

TypeDescription
numberA number from 0 to 1 that specifies the opacity of the container. A value of 1 translates into a fully opaque node while 0 represents full transparency.

position

TypeDescription
[number, number, number]Cartesian position in 3D space, stored as [x, y, z].

physicsBody

TypeDescription
Physics BodyCreates and binds a physics body that is configured with the provided collection of physics properties associated with this control.For more information on physics components, please see the Physics.

renderingOrder

TypeDescription
numberThis determines the order in which this Node is rendered relative to other Nodes. Nodes with greater rendering orders are rendered last. The default rendering order is zero. For example, setting a Node's rendering order to -1 will cause the Node to be rendered before all Nodes with rendering orders greater than or equal to 0.

rotation

TypeDescription
[number, number, number]The rotation of the box around it's local axis specified as Euler angles [x, y, z]. Units for each angle are specified in degrees.

rotationPivot

TypeDescription
[number, number, number]Cartesian position in [x,y,z] about which rotation is applied relative to the component's position.

scale

TypeDescription
[number, number, number]The scale of the component in 3D space, specified as [x,y,z]. A scale of 1 represents the current size of the box. A scale value of < 1 will make the component proportionally smaller while a value >1 will make the component proportionally bigger along the specified axis.

scalePivot

TypeDescription
[number, number, number]Cartesian position in [x,y,z] from which scale is applied relative to the component's position.

transformBehaviors

TypeDescription
string[]An array of transform constraints that affect the transform of the object. For example, putting the value "billboard" will ensure the box is facing the user as the user rotates their head on any axis. This is useful for icons or text where you'd like the box to always face the user at a particular rotation. Allowed values(values are case sensitive):

"billboard": Billboard object on x,y,z axis "billboardX": Billboard object on the x axis
"billboardY": Billboard object on the y axis
"billboardZ": Billboard object on the z axis

viroTag

TypeDescription
stringA tag given to other components when their physics body collides with this component's physics body. Refer to physics for more information.

visible

TypeDescription
booleanFalse if the container should be hidden. By default the container is visible and this value is true.

width

TypeDescription
The width of the image in 3D space. Default value is 1.

Methods

async getBoundingBoxAsync()

Async function that returns the component's bounding box in world coordinates. Returns a Promise that will be completed with the following object:

{
  "boundingBox": {
    "minX": number,
    "maxX": number,
    "minY": number,
    "maxY": number,
    "minZ": number, 
    "maxZ": number
  }
}

async getTransformAsync()

Async function that returns the component's transform (position, scale and rotation).

Returns a transform object that contains "position", "scale" and "rotation" keys which point to number arrays

applyImpulse(force: number[], position: number[])

A function used with physics to apply an impulse (instantaneous) force to an object with a physics body.

ParameterDescription
forcean array of magnitudes to be applied as force (N) to the object in the positive x, y and z directions
positiona position relative to the object from which to apply the given force

applyTorqueImpulse(torque: number[], position: number[])

A function used with physics to apply an impulse (instantaneous) torque to an object with a physics body.

ParameterDescription
torquean array of magnitudes to be applied as a torque (N * m) to the object in the positive x, y and z directions at the given position
positiona position relative to the object from which to apply the given torque

setVelocity(velocity: number[])

A function used with physics to set the velocity of an object with a physics body.

ParameterDescription
velocityan array of numbers corresponding to x, y, and z velocity

setNativeProps(nativeProps)

A wrapper function around the native component's setNativeProps which allow users to set values on the native component without changing state/setting props and re-rendering. Refer to the React Native documentation on Direct Manipulation for more information.

ParameterDescription
nativePropsan object where the keys are the properties to set and the values are the values to set
componentRef.setNativeProps({ position: [0, 0, -1] });