Sub Scene

A Sub Scene is used to control an imported FBX asset. Check the Manual page for more information.

Function Description
animationSpeed(anim)

This method takes a Keyframe Animation Model object and returns the animation’s speed. It will return 0 if the animation isn’t currently active.

animationTimeElapsed(anim)

This method takes a Keyframe Animation Model object and returns the time elapsed as an active animation. The time elapsed is a value from 0-1, 1 being the completion of the animation. This method will return -1 if the animation isn’t currently active.

animationTransitionTime(anim)

Returns the transition time of the animation. This is the time during which this animation and the next one will be blended in transition.

animations()

Returns an array of the currently active Keyframe Animation Models.

attachEntity(joint, entity)

This method is used to attach an Entity to a joint of your Sub Scene. For example, it can be used to attach an item to the hand of your character.

isAnimationPlaying(anim)

Returns true if the given animation is playing, false if not.

jointRotation(name)

Returns the rotation of the given joint in degrees. Joints are named within the 3D modeling software used to create the fbx file.

jointRotationQuat(name)

Returns the rotation of the given joint in Quaternion. Joints are named within the 3D modeling software used to create the fbx file.

jointScale(name)

Returns the scale of the given joint. Joints are named within the 3D modeling software used to create the fbx file.

jointTranslation(name)

Returns the translation of the given joint. Joints are named within the 3D modeling software used to create the fbx file.

jointWeight(name)

Returns the weight of the given joint. Joints are named within the 3D modeling software used to create the fbx file.

meshComponents()

Returns an array containing all the 3D Models associated with the Sub Scene.

playAnimation(anim)

Plays the given Keyframe Animation Model. Optionally takes a second parameter bool looped to make the animation loop.

position()

Returns the position of the Sub Scene. The Sub Scene’s position is relative to its parent Entity.

rotation()

Returns the rotation of the Sub Scene in degrees. The Sub Scene’s rotation is relative to its parent Entity.

rotationQuat()

Returns the rotation of the Sub Scene in Quaternion. The Sub Scene’s rotation is relative to its parent Entity.

scale()

Returns the scale of the Sub Scene. The Sub Scene’s scale is relative to its parent Entity.

setAnimationSpeed(anim, speed)

This method sets the animation speed for the given Keyframe Animation Model.

setAnimationTransitionTime(anim, value)

Sets the transition time of the animation. This is the time during which this animation and the next one will be blended in transition.

setColor(r, g, b, a)

Sets the RGB color of the Sub Scene. Alpha is optional.

setJointRotation(name, value)

Sets the rotation of the given joint in degrees. Joints are named within the 3D modeling software used to create the fbx file.

setJointRotationQuat(quat)

Sets the rotation of the given joint in Quaternion. Joints are named within the 3D modeling software used to create the fbx file.

setJointScale(name, value)

Sets the scale of the given joint. Joints are named within the 3D modeling software used to create the fbx file. The scale can be given in Vec3 or as setJointScale(name, x, y, z).

setJointTranslation(name, value)

Sets the translation of the given joint. Joints are named within the 3D modeling software used to create the fbx file. The translation can be given in Vec3 or as setJointTranslation(name, x, y, z).

setJointWeight(name, value)

Sets the weight of the given joint. Joints are named within the 3D modeling software used to create the fbx file.

setPosition(value)

Sets the position of the Sub Scene. The Sub Scene’s position is relative to its parent Entity. The position can be given as Vec3 or as setPosition(x, y, z).

setRotation(value)

Sets the rotation of the Sub Scene in degrees. The Sub Scene’s rotation is relative to its parent Entity. The rotation can be given as Vec3 or as setRotation(x, y, z).

setRotationQuat(quat)

Sets the rotation of the Sub Scene in Quaternion. The Sub Scene’s rotation is relative to its parent Entity.

setScale(value)

Sets the scale of the Sub Scene. The Sub Scene’s scale is relative to its parent Entity. The scale can be given as Vec3 or as setScale(x, y, z).

stopAnimation(anim)

Stops the given Keyframe Animation Model.


animationSpeed(anim)

This method takes a Keyframe Animation Model object and returns the animation’s speed. It will return 0 if the animation isn’t currently active.

Parameters

Keyframe Animation Model – the animation

Returns

number the speed of the animation

↑ Back to top


animationTimeElapsed(anim)

This method takes a Keyframe Animation Model object and returns the time elapsed as an active animation. The time elapsed is a value from 0-1, 1 being the completion of the animation. This method will return -1 if the animation isn’t currently active.

Parameters

Keyframe Animation Model – the animation

Returns

number the time elapsed of the animation

↑ Back to top


animationTransitionTime(anim)

Returns the transition time of the animation. This is the time during which this animation and the next one will be blended in transition.

Parameters

Keyframe Animation Model – the animation

Returns

number the transition time

↑ Back to top


animations()

Returns an array of the currently active Keyframe Animation Models.

Returns

Array the array of currently active Keyframe Animation Models.

↑ Back to top


attachEntity(joint, entity)

This method is used to attach an Entity to a joint of your Sub Scene. For example, it can be used to attach an item to the hand of your character.

Parameters

string joint – the joint name
Entity entity – the entity

↑ Back to top


isAnimationPlaying(anim)

Returns true if the given animation is playing, false if not.

Parameters

Keyframe Animation Model anim – the animation to check

Returns

boolean true if the animation is playing, false if not

↑ Back to top


jointRotation(name)

Returns the rotation of the given joint in degrees. Joints are named within the 3D modeling software used to create the fbx file.

Parameters

string name – the name of the joint

Returns

Vec3 the rotation of the joint in degrees

↑ Back to top


jointRotationQuat(name)

Returns the rotation of the given joint in degrees. Joints are named within the 3D modeling software used to create the fbx file.

Parameters

string name – the name of the joint

Returns

Quaternion the rotation of the joint in Quaternion

↑ Back to top


jointScale(name)

Returns the scale of the given joint. Joints are named within the 3D modeling software used to create the fbx file.

Parameters

string name – the name of the joint

Returns

Vec3 the {x, y, z} scale of the joint

↑ Back to top


jointTranslation(name)

Returns the translation of the given joint. Joints are named within the 3D modeling software used to create the fbx file.

Parameters

string name – the name of the joint

Returns

Vec3 the translation of the joint

↑ Back to top


jointWeight(name)

Returns the weight of the given joint. Joints are named within the 3D modeling software used to create the fbx file.

Parameters

string name – the name of the joint

Returns

number the weight of the joint

↑ Back to top


meshComponents()

Returns an array containing all the 3D Models associated with the Sub Scene.

Returns

Array – an array of 3D Models

Returns

number the weight of the joint

↑ Back to top


playAnimation(anim)

Plays the given Keyframe Animation Model. Optionally takes a second parameter bool looped to make the animation loop.

Parameters

Keyframe Animation Model anim – the animation
bool looped – (optional) true if the animation should loop, false if not

↑ Back to top


position()

Returns the position of the Sub Scene. The Sub Scene’s position is relative to its parent Entity.

Returns

Vec3 the {x, y, z} position of the Sub Scene

↑ Back to top


rotation()

Returns the rotation of the Sub Scene in degrees. The Sub Scene’s rotation is relative to its parent Entity.

Returns

Vec3 the {x, y, z} rotation of the Sub Scene

↑ Back to top


rotationQuat()

Returns the rotation of the Sub Scene in Quaternion. The Sub Scene’s rotation is relative to its parent Entity.

Returns

Quaternion the rotation of the Sub Scene in Quaternion

↑ Back to top


scale()

Returns the scale of the Sub Scene. The Sub Scene’s scale is relative to its parent Entity.

Returns

Vec3 the {x, y, z} scale of the Sub Scene

↑ Back to top


setAnimationSpeed(anim, speed)

This method sets the animation speed for the given Keyframe Animation Model.

Parameters

Keyframe Animation Model anim – the animation
number speed – the speed

↑ Back to top


setAnimationTransitionTime(anim, value)

Sets the transition time of the animation. This is the time during which this animation and the next one will be blended in transition.

Parameters

Keyframe Animation Model anim – the animation number value the transition time

↑ Back to top


setColor(r, g, b, a)

Sets the RGB color of the Sub Scene. Alpha is optional.

Parameters

number r – the red component of the color range 0-255
number g – the green component of the color range 0-255
number b – the blue component of the color range 0-255
number a – (optional) the alpha component of the color range 0-255

↑ Back to top


setJointRotation(name, value)

Sets the rotation of the given joint in degrees. Joints are named within the 3D modeling software used to create the fbx file.

Parameters

string name – the name of the joint
Vec3 value – the rotation in degrees

// example: rotate the models head to follow the players touch
let subScene;
let prev;
let delta = new Vec2(0,0);

function init(){
    subScene = this.attribute('Scene')[0]; // the sub scene is connected to this node by reference
    this.enableTouch(true);
}

function touchBegan(point){
    // save the point where the touch started
    prev = point;
}
component.touchBegan = touchBegan;

function touchMove(point){
    // calculate the distance between this touch point and the last one
    delta = new Vec2 ( delta.x + prev.x - point.x, 
                       delta.y + prev.y - point.y);
    prev = point;
}
component.touchMove = touchMove;

function update(dt){
    // change the rotation of the head joint based on the touch
    subScene.setJointRotation('head', new Vec3(-delta.x,0,-delta.y));
}

↑ Back to top


setJointRotationQuat(quat)

Sets the rotation of the given joint in Quaternion. Joints are named within the 3D modeling software used to create the fbx file.

Parameters

string name – the name of the joint
Quaternion value – the rotation in Quaternion

↑ Back to top


setJointScale(name, value)

Sets the scale of the given joint. Joints are named within the 3D modeling software used to create the fbx file. The scale can be given in Vec3 or as setJointScale(name, x, y, z).

Parameters

string name – the name of the joint
Vec3 value – the {x, y, z} scale of the joint

↑ Back to top


setJointTranslation(name, value)

Sets the translation of the given joint. Joints are named within the 3D modeling software used to create the fbx file. The translation can be given in Vec3 or as setJointTranslation(name, x, y, z).

Parameters

string name – the name of the joint
Vec3 value – the {x, y, z} translation of the joint

↑ Back to top


setJointWeight(name, value)

Sets the weight of the given joint. Joints are named within the 3D modeling software used to create the fbx file.

Parameters

string name – the name of the joint
number value – the weight of the joint

↑ Back to top


setPosition(value)

Sets the position of the Sub Scene. The Sub Scene’s position is relative to its parent Entity. The position can be given as Vec3 or as setPosition(x, y, z).

Parameters

Vec3 value – the position of the Sub Scene

↑ Back to top


setRotation(value)

Sets the rotation of the Sub Scene in degrees. The Sub Scene’s rotation is relative to its parent Entity. The rotation can be given as Vec3 or as setRotation(x, y, z).

Parameters

Vec3 value – the rotation of the Sub Scene

↑ Back to top


setRotationQuat(quat)

Sets the rotation of the Sub Scene in Quaternion. The Sub Scene’s rotation is relative to its parent Entity.

Parameters

Quaternion quat – the rotation of the Sub Scene

↑ Back to top


setScale(value)

Sets the scale of the Sub Scene. The Sub Scene’s scale is relative to its parent Entity. The scale can be given as Vec3 or as setScale(x, y, z).

Parameters

Vec3 value – the {x, y, z} scale of the Sub Scene

↑ Back to top


stopAnimation(anim)

Stops the given Keyframe Animation Model.

Parameters

Keyframe Animation Model anim – the animation to stop

↑ Back to top

Did you find this page useful?

Please give it a rating:

Please provide some feedback!

This is very helpful to us.

Tell us how we can improve this post?