API Docs for:
Show:

RD.SceneNode Class

Defined in: ../src/rendeer.js:86

SceneNode class to hold an scene item

Constructor

RD.SceneNode

()

Methods

addChild

(
  • node
)

Attach node to its children list

Parameters:

clear

()

Remove all childs

configure

(
  • o
)

Configure this SceneNode to a state from an object (used with serialize)

Parameters:

  • o Object

    object with the state of a SceneNode

findNode

(
  • id
)
SceneNode

Searchs the node and returns the first child node with the matching id, it is a recursive search so it is slow

Parameters:

  • id String

    the id of the node

Returns:

SceneNode:

result node otherwise null

fromMatrix

(
  • m
  • [is_global=false]
)

updates position, rotation and scale from the matrix

Parameters:

  • m Mat4

    the matrix

  • [is_global=false] Bool optional

    if the matrix is in global or local space

getAllChildren

(
  • result
)
Array

Recursively retrieves all children nodes (this doesnt include itself)

Parameters:

  • result Array

    [Optional] you can specify an array where all the children will be pushed

Returns:

Array:

all the children nodes

getDistanceTo

(
  • position
)
Number

Returns the distance between the center of the node and the position in global coordinates

Parameters:

  • position Vec3

    the point

Returns:

Number:

result

getGlobalMatrix

() Mat4

Get transform global matrix (concatenating parents) (its a reference)

Returns:

Mat4:

matrix44

getGlobalPoint

(
  • v
  • [result=vec3]
)
Vec3

Returns a point multiplied by the global matrix

Parameters:

  • v Vec3

    the point

  • [result=vec3] Vec3 optional

    where to store the output

Returns:

Vec3:

result

getGlobalPosition

(
  • [result=optional]
  • [fast=optional]
)
Vec3

Returns the node position in global coordinates

Parameters:

  • [result=optional] Vec3 optional

    where to store the output

  • [fast=optional] Boolean optional

    uses the current global amtrix without recomputing it, is faster but if the current matrix hasnt been updated the result will be wrong

Returns:

Vec3:

result

getGlobalRotation

(
  • [result=quat]
)
Quat

Get global rotation (concatenating parent rotations)

Parameters:

  • [result=quat] Quat optional

    quaternion to store the result

Returns:

Quat:

resulting rotation in quaternion format

getGlobalVector

(
  • v
  • [result=vec3]
)
Vec3

Returns a point rotated by the global matrix

Parameters:

  • v Vec3

    the point

  • [result=vec3] Vec3 optional

    where to store the output

Returns:

Vec3:

result

getLocalMatrix

() Mat4

Get transform local matrix

Returns:

Mat4:

matrix44

getLocalPoint

(
  • v
  • [result=vec3]
)
Vec3

Returns a point multiplied by the local matrix

Parameters:

  • v Vec3

    the point

  • [result=vec3] Vec3 optional

    where to store the output

Returns:

Vec3:

result

getLocalVector

(
  • v
  • [result=vec3]
)
Vec3

Returns a point rotated by the local rotation

Parameters:

  • v Vec3

    the point

  • [result=vec3] Vec3 optional

    where to store the output

Returns:

Vec3:

result

getVisibleChildren

(
  • [result=[]]
)
Array

Recursively retrieves all children nodes taking into account visibility (flags.visible)

Parameters:

  • [result=[]] Array optional

    you can specify an array where all the children will be pushed

Returns:

Array:

all the children nodes

propagate

(
  • method
  • params
)

calls a function in child nodes

Parameters:

  • method String

    name

  • params Array

    array containing the params

removeChild

(
  • node
)

Remove a node from its children list

Parameters:

  • node SceneNode

resetTransform

()

clears position, rotation and scale

rotate

(
  • angle_in_rad
  • axis
  • in_local
)

Rotate object (supports local or global but doesnt takes into account parent)

Parameters:

  • angle_in_rad Number
  • axis Vec3
  • in_local Boolean

    specify if the axis is in local space or global space

scale

(
  • v
)

Scale object

Parameters:

  • v Vec3

serialize

() Object

Returns an object that represents the current state of this object an its children

Returns:

Object:

object

setChildIndex

(
  • child
  • index
)

Change the order inside the children, useful when rendering without Depth Test

Parameters:

setMesh

(
  • mesh_name
)

sets the name of the mesh to be used to render the object

Parameters:

  • mesh_name String | Mesh

    also it accepts a mesh itself

setPivot

(
  • pivot
)

Set the pivot point, 0,0,0 by default (WARNING: use flags.pivot = true to enable the use of the pivot)

Parameters:

  • pivot Vec3

    local coordinate of the pivot point

setTexture

(
  • channel
  • texture
)

Sets the name of the mesh to be used to render the object

Parameters:

  • channel String

    which channel to use (the texture will be uploaded to the shader with the name "u_" + channel + "_texture"

  • texture String

    texture name (textures are retrieved from the renderer.textures

translate

(
  • delta
)

Translate object in local space

Parameters:

  • delta Vec3

updateGlobalMatrix

(
  • [fast=false]
  • [update_childs=false]
)

recomputes _global_matrix according to position, rotation and scaling

Parameters:

  • [fast=false] Boolean optional

    skips recomputation of parent, use it only if you are sure its already updated

  • [update_childs=false] Boolean optional

    update global matrix in childs too

updateLocalMatrix

()

recomputes _local_matrix according to position, rotation and scaling

updateMatrices

(
  • [fast=false]
)

recompute local and global matrix

Parameters:

  • [fast=false] Bool optional

    uses the global matrix as it is in the parent node instead of crawling all the ierarchy

Properties

color

Vec4

The color in RGBA format

Default: [1,1,1,1]

id

String

A unique identifier, useful to retrieve nodes by name

opacity

Number

This number is the 4� component of color but can be accessed directly

parentNode

SceneNode

The parent node where this node is attached

position

Vec3

The position relative to its parent in vec3 format

rotation

Quat

The orientation relative to its parent in quaternion format

scaling

Vec3

The scaling relative to its parent in vec3 format (default is [1,1,1])

scene

Scene

The scene where this node is attached

shader

String

the name of the shader in the shaders manager

texture

String

name of texture to use in the color channel (the same as SetTexture("color", name ))

uniforms

Vec3

The position relative to its parent