Linking JavaScript Files – API Reference

By |

Linking JavaScript Files

The Buildbox JavaScript panel allows you to link a custom node script to a JavaScript file on your computer, allowing you to use an external text editor to update and change your custom node script. Whether you update the file in the Buildbox JavaScript panel or external editor, it will be updated in both locations

To access the JavaScript panel, on an asset’s node map, double-click a node or click its edit icon.

To link a file to the JavaScript panel, click Link File at the bottom-right of the JavaScript panel, and depending on whether you need to export the file from or import it to Buildbox, choose one of the following procedures below.

Export to File & Link
  1. Select Export File & Link. The Save As window appears.
  2. Select the location where you want to save the file.
  3. Name the file and click Save.

A JavaScript file with the custom node script is now created locally on your computer and is linked to your custom node inside Buildbox.

Import from File & Link
  1. Select Import from File & Link.
  2. On your computer, navigate to the JavaScript file that contains your custom node script.
  3. Click Open.

The script from your JavaScript file appears in the Buildbox JavaScript panel and is linked to your local file.

To avoid breaking the link to your JavaScript file, avoid moving or renaming the JavaScript file on your computer, or deleting the linked node in Buildbox,

After you link a JavaScript file to a node, click the icon at the bottom right of the JavaScript panel to view the following options:

Option Description
Open Externally Opens the linked JavaScript file using your default script editor.
Show in Folder Opens the folder that contains the linked JavaScript file.
Export to File & Link Creates and saves a JavaScript file that contains your custom node script locally on your computer and links the file to the Buildbox JavaScript panel.
Import from File & Link Imports and creates a link to a JavaScript file from your computer to the Buildbox JavaScript panel.
Unlink Unlinks the JavaScript file from the Buildbox JavaScript panel. The updates will no longer be synchronized.

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?

Sound – API Reference

By |

Sound

The Sound Node plays an mp3 file.

Function Description
isPlaying()

Returns true if the sound is currently playing, false if not.

setVolume(value)

Sets the volume of the sound, from 0-1. The sound must already be playing before you set the sound with this function, and must be looped or non-overlapping.

volume()

Returns the volume of the sound if it is playing, from 0-1.


isPlaying()

Returns true if the sound is currently playing, false if not.

Returns

boolean – true if the sound is playing, false if not

↑ Back to top


setVolume(value)

Sets the volume of the sound, from 0-1. The sound must already be playing before you set the sound with this function, and must be looped or non-overlapping.

Parameters

number value – the volume of the sound

↑ Back to top

let fadein = false;
let mySound;
let volume = 0;

function start() {
	// start the fade in at the start of the scene
	fadein = true;
	mySound = this.entity().component("My Sound");
}

function update(dt) {
	// stops adjusting volume once volume goes over 1
	if (fadein && volume <= 1) {
		// check if the sound is playing
		if (mySound.isPlaying()) {
			// set the volume, and then increase the volume for the next update loop
			mySound.setVolume(volume);
			volume += 0.001;
		}
	}
}

volume()

Returns the volume of the sound if it is playing, from 0-1.

Returns

number - the volume of the sound

↑ 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?

LevelSector – API Reference

By |

LevelSector

The LevelSector class represents a Scene Selector “level” at the bottom of the screen in a 3D World. You can get the LevelSector that an Entity exists in with this.entity().level().

Function Description
isRemoved()

Returns true if the level has been removed, false if not. This can be used to make sure you’re not accessing a level that has been unloaded before you try using it (which would cause errors).

name()

Returns the name of the level.


isRemoved()

Returns true if the level has been removed, false if not. This can be used to make sure you’re not accessing a level that has been unloaded before you try using it (which would cause errors).

Returns

boolean true if the level is removed, false if not

↑ Back to top


name()

Returns the name of the level.

Returns

string the name of the level

↑ 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?

Custom Nodes – API Reference

By |

Custom Nodes

A node is a piece of functionality that exists within a Node Map. If you have an idea for a custom node, you can make one yourself and share it online as a .bbnode file with JSON formatting.

To create a custom node, you need a basic understanding of JSON formatting and a text editor of your choice. To modify a pre-existing node, see Customizing Nodes.

Writing your own Custom Node

Let’s look at a simple example – the “Set Color” node. Here’s the full .bbnode file:

{
	"name" : "Set Color",
	"attributes": [
		{
			"name" : "Set",
			"type" : "Boolean",
			"connection" : "Input",
			"editable" : false		
		},
		{
			"name" : "Done",
			"type" : "Boolean",
			"connection" : "Output",
			"editable" : false		
		},
		{
			"name" : "Color",
                        "type" : "Color",
			"connection" : "None",
			"editable" : true
		}

	],
	"script":"
        function init(){
        }


        function update(dt){
        }


        function signal(name, value) {
            //Check the incoming signals
            if (name == 'Set' && value) {
                //get the node attributes
                let col = this.attribute('Color');
                
                //set the entity color
                this.entity().setColor(col.r, col.g, col.b, col.a);
                
                //Emit signal to indicate the node finished
                this.emitSignal('Done', true);
            }
        }
    "

}

This results in the following node and attributes:

Now let’s look at it line by line.


name

"name" : "Set Color",

This defines what name this node will have.


attributes

"attributes": []

This array defines what attributes the node will have in the attributes sidebar. It also details any input or output connections the node will have. Please note that the Fields and Possible Values here are all cAsE sEnSiTiVe!

Field Description Possible Values
name Required. The name of the attribute or connection. Any string
*do not give two attributes in the same node the same name!
type Required. What data type the attribute contains. Asset
Animation
Boolean
Color
Dropdown
Mesh
Number
Slider
Text
Vector2D
Vector3D
connection Required. Whether this attribute is an input or output connection. Input
Output
None
editable Required.
Attribute: Whether this attribute is visible & editable in the attribute sidebar.
Connection: Whether the name of this connection can be altered.
true
false
essential Optional (defaults to false). If this field is set to true, then this attribute will be displayed on the Entity’s attribute sidebar when clicked in the asset window. You are marking this attribute as important enough to be accessible from the world view instead of just the entity’s mind map. true
false
self Optional. If you’d like your node to be able to be referenced by other nodes without using signals, set this to true to make the purple connection circle visible. (See requested() for more information) “self”: { “visible” : true }
“self”: { “visible” : false }
value Optional field used to define a default value for the attribute. For instance, your Number type attribute could have a default value of 100 with “value”: 100.
Value is required for a Dropdown type attribute because all possible values are pre-defined.
Dropdown Example from Advanced Move node:

"value": {
    "default": "kReplace",
    "options": {
        "Replace": "kReplace",
        "Add": "kAdd",
        "Multiply": "kMultiply"
    }
}

Example for a Vector3D attribute (leaving the X and Z values blank with null):
“value”: [null, 20, null]

sliderMin
sliderMax
sliderStepSize
sliderDefaultValue
Required fields for a Slider type attribute. sliderMin and sliderMax define the range of the slider, sliderStepSize defines the increment of the slider, and sliderDefaultValue defines the initial value of the slider. Example of a Slider attribute:

{
    "name": "My Slider",
    "type": "Slider",
    "connection": "None",
    "editable": true,
    "sliderMin": 0,
    "sliderMax": 10,
    "sliderStepSize": 2,
    "sliderDefaultValue": 2
}

script

"script":"

Anything you put in this string will be inserted into the Script section of the Node. Since it’s all defined within a string, make sure to use single quotes (‘) instead of double quotes (“) to avoid terminating the string early.

If you save your .bbnode file as a .json file and use a program that has syntax highlighting (such as Visual Studio Code), this section will highlight with errors. This is because normal JSON doesn’t allow multiline strings; this is an area where the .bbnode format differs from JSON.

Here’s another script example, this time from the Jump node. This code snippet is entirely contained within the “script”: ” … ” section of the Jump.bbnode file.

    //Input Signal variables
    let _enabled = true;

    //Node attribute variables
    let _jumpLimit;
    let _jumpForce;

    //working variables
    let _physics;
    let _jumpCount = 0;

    function init(){
        //get the node attributes
        _jumpForce = this.attribute('Jump Force');
        _jumpLimit = this.attribute('Jump Limit');
    
        //Get and check the Physics status of this entity
        _physics = this.entity().physics();
        if(_physics && _physics.type() != 'kDynamic'){
            warning('Jump Node only works with [Dynamic] bodies. Enabling by default');

            _physics.setType('kDynamic');
        }
    }

    function start(){

    }

    function update(dt){

    }

    function signal(name, value){
        //Check the incoming signals
        if(name == 'Jump' && value){
            //check we have dynamic physics on the entity
            if(_physics){
                //check here if the signal to jump again is valid
                //we need to check we are with the jump limit
                if(_jumpLimit == 0 || _jumpCount < _jumpLimit){
                    //calculate the jump force to be applied
                    let vel = _physics.linearVelocity();
                    if(_jumpForce.x != null){
                        vel.x = _jumpForce.x;
                    }
                    if(_jumpForce.y != null){
                        vel.y = _jumpForce.y;
                    }
                    if(_jumpForce.z != null){
                        vel.z = _jumpForce.z;
                    }
                    
                    //apply the jump velocity
                    _physics.setLinearVelocity( vel.x, vel.y, vel.z );

                    //track the jump count
                    _jumpCount++;
                }
            }
        }
        else if(name == 'Reset' && value){
            //Signal to reset the jump so we just reset the 
            //jumpcount variable
            _jumpCount = 0;
        }
    }

Import a Node

To import a node into BuildBox, drag it from your file explorer into the mind map of the Entity you’d like to add it to. Voilà!

Troubleshooting

If you drag your .bbnode into the mind map and nothing happens, that probably means there’s a typo somewhere.

– Make sure that each attribute includes all the required fields.
– Make sure that you have no trailing commas.
– A JSON Validator will give you errors based on the Script section, because as noted above, JSON doesn’t normally allow multiline strings. You can try pasting your .bbnode contents into a JSON Validator and then deleting the script section to look for errors elsewhere.

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?

Label Node – API Reference

By |

Label Node

Function Description
globalDepth()

Returns the depth of the Label in a 2D World.

isRemoved() Returns true if the Label is removed, false if not.
opacity()

Returns the opacity of the label.

position()

Returns the position of the label.

setGlobalDepth(value)

Set the depth of the Label node in a 2D World.

setOpacity(value)

Sets the opacity of the label.

setPosition(x, y)

Sets the position of the label.

setText(value)

Sets the text for the label.


globalDepth()

Returns the global depth of the Label node. Depth decides which object is on top in a 2D World. A higher value will be above a lower number in the Scene.

Returns

number value – The global depth of the Label

↑ Back to top


isRemoved()

Returns true if the Label is removed, false if not.

Returns

boolean true if Label is removed, false if not

↑ Back to top


opacity()

Returns the opacity of the label. Ranges from 0 (invisible) to 255 (fully opaque)

Returns

number the opacity of the label

↑ Back to top


position()

Returns the position of the label.

Returns

Vec2 the {x, y} position of the label.

↑ Back to top


setGlobalDepth(value)

Sets the global depth of the Label node. Depth decides which object is on top in a 2D World. A higher value will be above a lower number in the Scene.

Parameters

number value – The global depth of the Label

↑ Back to top


setOpacity(value)

Sets the opacity of the label. Ranges from 0 (invisible) to 255 (fully opaque)

Parameters

number value – The opacity of the label

↑ Back to top


setPosition(x, y)

Sets the position of the label.

Parameters

number x – the x coordinate position
number y – the y coordinate position
number z – the z coordinate position (optional)

↑ Back to top


setText(value)

Sets the text for the label.

Parameters

string value – The string that will be displayed by the label.

↑ 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?

Spot Light – API Reference

By |

Spot Light

The Spot Light is a way to add additional light sources to your game.

the sp

Function Description
color()

Returns the color of the Light in RGB (Red, Green, Blue) format.

cutOffAngle()

Returns the cutoff angle of the Spot Light, in degrees.

intensity()

Returns the intensity of the Light.

isRemoved() Returns true if the Light is removed, false if not.
isVisible()

Returns true if the light is visible, false if not.

position()

Returns the Light’s position coordinates relative to its parent.

range()

Returns the range of the Light.

remove()

Remove the light from the Scene.

rotation()

Returns the rotation of the Light in degrees.

rotationQuat()

Returns the rotation of the Light in quaternion.

setColor(color)

Sets the color of the Light.

setCutOffAngle(value)

Sets the cutoff angle of the Light, in degrees. This changes how wide or narrow the Spot Light is.

setIntensity(value)

Sets the intensity of the Light.

setPosition(x, y, z)

Sets the new position relative to the Light’s parent. If the Light has no parent, this sets the world position of the Light.

setRange(value)

Sets the range of the Light.

setRotation(x, y, z)

Sets the rotation value of the Light, in degrees.

setRotationQuat(value)

Sets rotation value in Quaternion.

setVisible(value)

Sets the visibility of the Light; true if the Light is visible, false if not.

setWorldPosition()

Sets the Light’s position coordinates in the world (absolute position).

worldPosition()

Returns the Light’s position coordinates in the world (absolute position).


color()

Returns the Light’s color in RGB (Red, Green, Blue) format. The minimum value is 0 and the maximum is 1 (think of it as the 0-255 scale divided by 255). For example, {r:0, g:0, b:0} is black and {r:1, g:1, b:1} is white.

Returns

Vec3 {x, y, z} color pigment of the Light.

let light = this.scene().findFirst("Spot Light");
log(light.color().x); // result: the red component of the light's color.

↑ Back to top


cutOffAngle()

Returns the cutoff angle of the Spot Light, in degrees.

Returns

number the cutoff angle of the Spot Light


intensity()

Returns the intensity of the Light.

Returns

number The intensity of the Light. Range is 0-1000.

↑ Back to top


isRemoved()

Returns if the Light is removed.

Returns

boolean true if the Light is removed, false if the Light is not.

↑ Back to top


isVisible()

Returns if the Light is visible.

Returns

boolean true if the Light is visible, false if the Light is not.

↑ Back to top


position()

Returns the Light’s position relative to its parent. If the Light has no parent, the result of this function will be no different than worldPosition.

Returns

Vec3 {x, y, z} relative coordinates of the Light.

↑ Back to top


range()

Returns the range of the Light. The range is how far the light reaches.

Returns

Number The range of the Light.

↑ Back to top


remove()

Remove the Light from the Scene.

↑ Back to top


rotation()

Returns the rotation of the Light in degrees.

Returns

Vec3 The {x, y, z} rotation value of the Light, in degrees.

↑ Back to top


rotationQuat()

Returns the rotation of the Light in Quaternion.

Returns

Quaternion The rotation value in Quaternion.

↑ Back to top


setColor(color)

Sets the color of the Light. Expected range of {r, g, b} is 0-1.

Parameters

Vec3 color – the {r, g, b} color

↑ Back to top


setCutOffAngle(value)

Sets the cutoff angle of the Light, in degrees. This changes how wide or narrow the Spot light is.

Parameters

number value – the cutoff angle to be used

↑ Back to top


setIntensity(value)

Sets the intensity of the Light.

Parameters

Number value – the intensity of the Light, ranging from 0-1000.

↑ Back to top


setPosition(x, y, z)

Sets the new position relative to the Light’s parent. If the Light has no parent, this sets the world position of the Light.

Parameters

number x – X coordinate in 3D space
number y – Y coordinate in 3D space
number z – Z coordinate in 3D space

↑ Back to top


setRange(value)

Sets the range of the Light.

Parameters

Number value – the range of the Light

↑ Back to top


setRotation(x, y, z)

Sets the rotation value of the Light, in degrees.

Parameters

number x – the X rotation of the Light
number y – the Y rotation of the Light
number z – the Z rotation of the Light

↑ Back to top


setRotationQuat(value)

Sets rotation value in Quaternion.

Parameters

Quaternion value – The Quaternion rotation value to be set

↑ Back to top


setVisible(value)

Sets the visibility of the Light; true if the Light is visible, false if not.

Parameters

boolean value – the visibility of the Light.

↑ Back to top


setWorldPosition(value)

Sets the Light’s position coordinates in the world (absolute position).

Parameters

Vec3 value – the {x, y, z} absolute position of the Light.

↑ Back to top


worldPosition()

Returns the Light’s position coordinates in the world (absolute position).

Returns

Vec3 the {x, y, z} world coordinates of the Light

let pos = this.scene().find("Spot Light")[0].worldPosition();
log('X World Position = ' + pos.x);

↑ 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?

What’s New JS API

By |

What’s new in Buildbox 3.3 JS API

3.3.1

Sun – API Reference

By |

Sun

The Sun is a light source that comes default in every World. It can be accessed by running this.scene().findFirst(‘Light Sun’);.

Function Description
color()

Returns the color of the Sun in RGB (Red, Green, Blue) format. The minimum value is 0 and the maximum is 1 (think of it as the 0-255 scale divided by 255). For example, {r:0, g:0, b:0} is black and {r:1, g:1, b:1} is white.

intensity()

Returns the intensity of the Sun.

rotation()

Returns the rotation of the Sun in degrees.

rotationQuat()

Returns the rotation of the Sun in Quaternion.

setColor(value)

Sets the color of the Sun. Expected range of {r, g, b} is 0-1.

setIntensity(value)

Sets the intensity of the Sun.

setRotation(value)

Sets the rotation value of the Sun, in degrees.

setRotationQuat(value)

Sets the rotation value of the Sun, in Quaternion.


color()

Returns the color of the Sun in RGB (Red, Green, Blue) format. The minimum value is 0 and the maximum is 1 (think of it as the 0-255 scale divided by 255). For example, {r:0, g:0, b:0} is black and {r:1, g:1, b:1} is white.

Returns

Vec3 the color of the Sun

↑ Back to top


intensity()

Returns the intensity of the Sun.

Returns

number the intensity of the Sun. Range is 0-1000.

↑ Back to top


rotation()

Returns the rotation of the Sun in degrees.

Returns

Vec3 the {x, y, z} rotation value of the Sun

↑ Back to top


rotationQuat()

Returns the rotation of the Sun in Quaternion.

Returns

Quaternion the Quaternion rotation value

↑ Back to top


setColor(value)

Sets the color of the Sun. Expected range of {r, g, b} is 0-1.

Parameters

Vec3 value – the {r, g, b} color

↑ Back to top


setIntensity(value)

Sets the intensity of the Sun.

Parameters

number value – the intensity of the Light, ranging from 0-1000

↑ Back to top


setRotation(value)

Sets the rotation value of the Sun, in degrees.

Parameters

Vec3 – the {x, y, z} rotation value

↑ Back to top


setRotationQuat(value)

Sets the rotation value of the Sun, in Quaternion.

Parameters

Quaternion – the Quaternion rotation value

↑ 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?

Keyframe Animation Model – API Reference

By |

Keyframe Animation Model

Keyframe Animaion Models are used with Sub Scenes to control FBX assets. Check the manual page for more information.

Function Description
duration()

Returns the duration of the Keyframe Animation Model.

name()

Returns the name of the Keyframe Animation Model.


duration()

Returns the duration of the Keyframe Animation Model.

Returns

number the duration of the animation

↑ Back to top


name()

Returns the name of the Keyframe Animation Model.

Returns

string the name of the animation

↑ 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?

Sub Scene – API Reference

By |

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()

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

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()

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
number g – the green component of the color
number b – the blue component of the color
number a – (optional) the alpha component of the color

↑ 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

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
Vec3 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?