FectarBlocks API
Table of Contents
Animation module
Move it.
Classes
SpotAnimation
Spot specific animation related functions and variables
Properties
Name
Type
Read/Write
Description
clips
ArrayOfString
Read
Name of every animation inside the spot.
isPausing
boolean
ReadWrite
Returns true when animation is paused. Set true to pause or false to resume.
length
number
Read
Duration of the animation in seconds.
parameters
ArrayOfString
Read
Type and name of every animator parameter inside the spot.
speed
number
ReadWrite
Playback multiplier to get or set. 0.5 means half speed, 1 is normal speed, 2 means double speed etc. (default 1).
time
number
ReadWrite
Absolute playback time in seconds. Set to jump to time.
timeProgress
number
ReadWrite
Relative playback time. Value is from 0 to 1 where 1 is the end of the animation. Set to jump to time.
Public Methods
bigint addTrigger(Function onTrigger, number time, TimeTriggerType timeTriggerType, number customRange)
Adds a trigger event which is fired when the animation reaches the set time. Returns a handle to use with removeTrigger.
Parameter
Type
Description
onTrigger
Function
Function to call or code to execute.
time
number
Time in seconds, the animation has been playing before the function (specified in onTrigger) is executed.
timeTriggerType
TimeTriggerType
Type of timerange used to execute the trigger (Optional). (default TimeTriggerType.momentary)
customRange
number
Only for TimeTriggerType.custom. Specify your time offset (in seconds) in which the trigger should be executed (Optional). (default 0.5)
boolean getBool(string name)
Gets the boolean value of an animator parameter.
Parameter
Type
Description
name
string
Name of the parameter to get (e.g. ‘IsActive’).
number getFloat(string name)
Gets the float value of an animator parameter.
Parameter
Type
Description
name
string
Name of the parameter to get (e.g. ‘_Progress’).
number getInteger(string name)
Gets the integer value of an animator parameter.
Parameter
Type
Description
name
string
Name of the parameter to get (e.g. ‘_Type’).
SpotAnimation lookAtCamera()
Keep looking at the camera. NOTE: Only compatible with humanoid animator in .FCP spots and where IK pass on your animator is enabled.
SpotAnimation lookAtPosition(Vector3 position)
Keep looking at a fixed position. NOTE: Only compatible with humanoid animator in .FCP spots and where IK pass on your animator is enabled.
Parameter
Type
Description
position
Vector3
Position.
SpotAnimation lookAtSpeed(number speed)
Transition speed of the head turning to look at a subject. NOTE: Only compatible with humanoid animator in .FCP spots and where IK pass on your animator is enabled.
Parameter
Type
Description
speed
number
Speed in degrees per second. A value of 45 means it takes one second to focus on the target at a 45 degrees angle (default 90).
SpotAnimation lookAtSpot(Spot spot)
Keep looking at specified target spot. NOTE: Only compatible with humanoid animator in .FCP spots and where IK pass on your animator is enabled.
Parameter
Type
Description
spot
Spot
Reference to a spot.
SpotAnimation lookAtStop()
Stops looking at any target. NOTE: Only compatible with humanoid animator in .FCP spots and where IK pass on your animator is enabled.
SpotAnimation lookAtTriggerAngles(number horizontal, number vertical)
Maximum angle of peripheral vision (field of view). Targets within this range will be triggering a ‘look at’ action.NOTE: Only compatible with humanoid animator in .FCP spots and where IK pass on your animator is enabled.
Parameter
Type
Description
horizontal
number
Value from 0 to 360 degrees. When for instance set to 180, all objects behind will be ignored. (default 120).
vertical
number
Value from 0 to 360 which specifies the amount of influence the head has on the ‘look at’ movement (default 100).
SpotAnimation lookAtWeights(number body, number head, number eyes, number limit)
Influence amount of body parts on the ‘look at’ movement. NOTE: Only compatible with humanoid animator in .FCP spots and where IK pass on your animator is enabled.
Parameter
Type
Description
body
number
Value from 0 to 1 which specifies the amount of influence the body has on the ‘look at’ movement (default 1).
head
number
Value from 0 to 1 which specifies the amount of influence the head has on the ‘look at’ movement (default 1).
eyes
number
Value from 0 to 1 which specifies the amount of influence the eyes have on the ‘look at’ movement (default 1).
limit
number
Value from 0 to 1 which specifies the limit all parts have on the ‘look at’ movement (default 0.5). Where 1 means no movement is possible, 0.5 tells all parts can rotate 180 degrees, 0 means unlimited 360 degrees (default 0.5).
pause()
Pauses the animation.
SpotAnimation play(string name)
Plays the animation.
Parameter
Type
Description
name
string
Name of the state or clip to play. When no name is given, it resumes the last played animation.
removeTrigger(bigint triggerHandle)
Removes a trigger event.
Parameter
Type
Description
triggerHandle
bigint
The ID value returned by addTrigger().
reset()
Resets all animation properties and parameters to their initial values.
resetTrigger(bigint triggerHandle)
Resets (rearms) a trigger event. First make sure the time of the animation is set outside the triggerable time range or the trigger will be executed immediately.
Parameter
Type
Description
triggerHandle
bigint
The ID value returned by addTrigger().
resume()
Resumes playback of the animation.
rewind()
Resets the playhead to the beginning of the animation.
SpotAnimation setBool(string name, number value)
Sets the boolean value of an animator parameter and returns the SpotAnimation object for chaining.
Parameter
Type
Description
name
string
Name of the parameter to set (e.g. ‘_Progress’).
value
number
Value to set (e.g. ‘0.5’).
SpotAnimation setFloat(string name, number value)
Sets the float value of an animator parameter and returns the SpotAnimation object for chaining.
Parameter
Type
Description
name
string
Name of the parameter to set (e.g. ‘_Progress’).
value
number
Value to set (e.g. ‘0.5’).
SpotAnimation setInteger(string name, number value)
Sets the integer value of an animator parameter and returns the SpotAnimation object for chaining.
Parameter
Type
Description
name
string
Name of the property to set (e.g. ‘_Type’).
value
number
Value to set (e.g. ‘2’).
SpotAnimation setSpeed(number value)
Sets the playback speed.
Parameter
Type
Description
value
number
Playback multiplier to set. 0.5 means half speed, 1 is normal speed, 2 means double speed etc. (default 1).
Core module
Fectar Blocks core primitive types
Classes
Vector3
Representation of 3D vectors and points.
Static Properties
Name
Type
Read/Write
Description
back
Vector3
Read
Shorthand for writing Vector3(0, 0, -1).
down
Vector3
Read
Shorthand for writing Vector3(0, -1, 0).
forward
Vector3
Read
Shorthand for writing Vector3(0, 0, 1).
left
Vector3
Read
Shorthand for writing Vector3(-1, 0, 0).
one
Vector3
Read
Shorthand for writing Vector3(1, 1, 1).
right
Vector3
Read
Shorthand for writing Vector3(1, 0, 0).
up
Vector3
Read
Shorthand for writing Vector3(0, 1, 0).
zero
Vector3
Read
Shorthand for writing Vector3(0, 0, 0).
Properties
Name
Type
Read/Write
Description
magnitude
number
Read
Returns the length of this vector.
normalized
number
Read
Returns this vector with a magnitude of 1.
x
number
ReadWrite
X component. Axis points to the right.
y
number
ReadWrite
Y component. Axis points upwards
z
number
ReadWrite
Z component. Axis points away.
Constructors
Vector3 Vector3(number x, number y, number z)
Creates a new vector with given x, y, z components.
Parameter
Type
Description
x
number
y
number
z
number
Example
// Set a clicked spot to x,y,z-coordinates: (0, 0.5, 1).
function onClick(eventParams)
{
eventParams.spot.position = new Vector3(0, 0.5, 1);
}
Static Methods
number Angle(Vector3 from, Vector3 to)
Returns the angle in degrees between the two vectors.
Parameter
Type
Description
from
Vector3
The vector from which the angular difference is measured.
to
Vector3
The vector to which the angular difference is measured.
Vector3 Cross(Vector3 lhs, Vector3 rhs)
Cross Product of two vectors.
Parameter
Type
Description
lhs
Vector3
Left hand side vector.
rhs
Vector3
Right hand side vector.
number Distance(Vector3 a, Vector3 b)
Returns the distance between a and b.
Parameter
Type
Description
a
Vector3
First position.
b
Vector3
Second position.
number Dot(Vector3 lhs, Vector3 rhs)
Dot Product of two vectors.
Parameter
Type
Description
lhs
Vector3
Left hand side vector.
rhs
Vector3
Right hand side vector.
Example
// Detect if spot 'mySpot' is behind the camera.
setInterval(()=> {
var mySpot = Space.getSpot('mySpot');
var offset = mySpot.position - Space.camera.position;
if (Vector3.Dot(Space.camera.forward, offset) < 0)
log('Object is behind me');
else
log('Object is in front of me');
}, 1000);
Vector3 Lerp(Vector3 a, Vector3 b, number t)
Linearly interpolates between two points.
Parameter
Type
Description
a
Vector3
Start value, returned when t = 0.
b
Vector3
End value, returned when t = 1.
t
number
Value used to interpolate between a and b.
Vector4
Representation of four dimensional vector.
Static Properties
Name
Type
Read/Write
Description
one
Vector4
Read
Shorthand for writing Vector4(1, 1, 1, 1).
zero
Vector4
Read
Shorthand for writing Vector4(0, 0, 0, 0).
Properties
Name
Type
Read/Write
Description
magnitude
number
Read
Returns the length of this vector.
normalized
number
Read
Returns this vector with a magnitude of 1.
w
number
ReadWrite
W component.
x
number
ReadWrite
X component.
y
number
ReadWrite
Y component.
z
number
ReadWrite
Z component.
Constructors
Vector4 Vector4(number x, number y, number z, number w)
Creates a new vector with given x, y, z, w components.
Parameter
Type
Description
x
number
X component.
y
number
Y component.
z
number
Z component.
w
number
W component.
Static Methods
number Distance(Vector4 a, Vector4 b)
Returns the distance between a and b.
Parameter
Type
Description
a
Vector4
First position.
b
Vector4
Second position.
number Dot(Vector4 lhs, Vector4 rhs)
Dot Product of two vectors.
Parameter
Type
Description
lhs
Vector4
Left hand side vector.
rhs
Vector4
Right hand side vector.
Vector4 Lerp(Vector4 a, Vector4 b, number t)
Linearly interpolates between two points.
Parameter
Type
Description
a
Vector4
Start value, returned when t = 0.
b
Vector4
End value, returned when t = 1.
t
number
Value used to interpolate between a and b.
Quaternion
Representation of rotations. Beware this is a value type. If you want to set the rotation of the spot, you have to reassign the modified quaternion or use the rotationEuler property of the spot.
Static Properties
Name
Type
Read/Write
Description
identity
Quaternion
Read
The identity rotation.
Properties
Name
Type
Read/Write
Description
eulerAngles
Vector3
ReadWrite
Returns or sets the euler angle representation of the rotation.
Constructors
Quaternion Quaternion(number x, number y, number z, number w)
Constructs new Quaternion with given x,y,z,w components.
Parameter
Type
Description
x
number
y
number
z
number
w
number
Static Methods
Quaternion Euler(number x, number y, number z)
Returns a rotation that rotates z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis; applied in that order.
Parameter
Type
Description
x
number
y
number
z
number
Quaternion Slerp(Quaternion a, Quaternion b, number t)
Spherically interpolates between quaternions a and b by ratio t. The parameter t is clamped to the range [0, 1].
Parameter
Type
Description
a
Quaternion
Start value, returned when t = 0.
b
Quaternion
End value, returned when t = 1.
t
number
Value used to interpolate between a and b.
Public Methods
Quaternion setLookRotation(Vector3 view, Vector3 up)
Creates a rotation with the specified forward and upwards directions.
Parameter
Type
Description
view
Vector3
The direction to look in.
up
Vector3
Optional up vector. The vector that defines in which direction up is. (Default Vector3.up).
Color
Representation of RGBA colors.
Properties
Name
Type
Read/Write
Description
a
number
ReadWrite
Alpha component.
b
number
ReadWrite
Blue component.
g
number
ReadWrite
Green component.
r
number
ReadWrite
Red component.
Constructors
Color Color(number r, number g, number b, number a)
Constructs a new Color with given r,g,b,a components.
Parameter
Type
Description
r
number
Red component.
g
number
Green component.
b
number
Blue component.
a
number
Alpha component.
Color Color(number r, number g, number b)
Constructs a new Color with given r,g,b components and sets a to 1.
Parameter
Type
Description
r
number
Red component.
g
number
Green component.
b
number
Blue component.
Application (static) New
Application related functions and variables
Debug module
All debug related functions and constants.
Public Methods
log(Object message)
Log any data to the debug log.
Parameter
Type
Description
message
Object
Object to write as string to the log.
Example
// Log the name of a clicked spot.
function onClick(eventParams)
{
log(eventParams.spot.name);
}
Event module
All event related functions and constants.
Public Methods
onClick(Event params)
Implement this event handler to handle all click events.
Parameter
Type
Description
params
Event
event parameters
Example
// Implement an onClick event handler like this, to catch all clicks and taps.
// This example hides the spot that was clicked.
function onClick(eventParams)
{
eventParams.spot.hide();
}
onCollision(CollisionEvent params)
Implement this event handler in the global init() to handle all collision events.
Parameter
Type
Description
params
CollisionEvent
collision event parameters
onStateChanged(Event params) New
Implement this event handler in the global init() to handle all state changed events.
Parameter
Type
Description
params
Event
event parameters
Classes
Event
Event related functions and variables of the current event. You can use the globally declared Event instance to get information about the event triggered or implement a custom event handler to get an instance to this object as a parameter.
Properties
Name
Type
Read/Write
Description
spot
Spot
N/A
Spot object (null if not part of the event context).
CollisionEvent
Inherits from: Event
CollisionEvents are triggered when objects with physics enabled, collide. You can use the globally declared Event instance to get information about the event triggered or implement a custom event handler to get an instance to this object as a parameter.
Properties
Name
Type
Read/Write
Description
otherSpot
Spot
N/A
Other spot or floor (null) which spot collided with. When floor collision events are enabled the otherSpot will be null in case of a collision with the floor.
New">Network module New
All network related functions and constants.
Classes
Net (static)
Core network functionality.
Static Methods
everyone(string functionName)
Call a function for everyone within the session.
Parameter
Type
Description
functionName
string
Function call as string to invoke (may include parameters else end with '()').
others(string functionName)
Call a function for all others within the session.
Parameter
Type
Description
functionName
string
Function call as string to invoke (may include parameters else end with '()').
Physics module
Let's get physical
Classes
Floor (static)
Object representing a floor used for collisions
Static Properties
Name
Type
Read/Write
Description
enableCollisionEvents
boolean
ReadWrite
Enable OnCollision events for spot collisions with the floor plane (default false).
enabled
boolean
ReadWrite
Floor collider is enabled (default true). Set to false if you want to use your own floor collider.
Physics (static)
Physics related functions and variables
Static Properties
Name
Type
Read/Write
Description
floor
Floor
N/A
Invisible floor object used for collisions
SpotPhysics
Spot specific physics related functions and variables
Properties
Name
Type
Read/Write
Description
angularDrag New
number
ReadWrite
Angular drag (angular velocity reduction over time) of the spot.
angularVelocity New
Vector3
ReadWrite
The angular velocity of the spot measured in radians per second.
drag New
number
ReadWrite
Drag (velocity reduction over time) of the spot.
enabled
boolean
ReadWrite
Enable physics for a spot. Spot will be influenced by external forces when not moved by script and (when collisions is true) will influence other spots with physics enabled.
mass New
number
ReadWrite
Mass of the spot in kg.
useGravity
boolean
ReadWrite
Controls whether gravity affects this spot.
velocity New
Vector3
ReadWrite
Velocity of the object (length in meters per second).
Public Methods
addForce(Vector3 force)
Apply an impulse force to the physics enabled spot and change the velocity by force / mass.
Parameter
Type
Description
force
Vector3
Force vector in world coordinates, with length in Newtons per second.
addTorque(Vector3 force)
Apply angular momentum to the physics enabled spot and change the angular velocity by torque / mass.
Parameter
Type
Description
force
Vector3
Force vector relative to the spot, in kilogram-meters-squared per second.
Question module
Question
Classes
SpotQuestion
Spot specific question related functions and variables
Public Methods
SpotQuestion onAnswered(Function onAnswered)
Sets onComplete callback event handler.
Parameter
Type
Description
onAnswered
Function
OnAnswered(SpotQuestionAnswerArguments) function called when question is answered. Pass null to clear the event.
SpotQuestion start()
Starts the question spot.
SpotQuestionAnswerArguments
Arguments that contain information about a given answer.
Properties
Name
Type
Read/Write
Description
answer
string
Read
Answer that was given.
isCorrect
boolean
Read
When true the correct answer was given.
Space module
Everything space related
Classes
Camera
An object representing a camera.
Properties
Name
Type
Read/Write
Description
forward
Vector3
Read
The forward vector of the camera. (Readonly)
position
Vector3
Read
Representation of 3D vectors and points. (Readonly)
rotation
Quaternion
Read
A Quaternion that stores the rotation of the Transform in world space. (Readonly)
rotationEuler
Vector3
Read
The rotation as Euler angles in degrees. (Readonly)
Spot
An object representing a spot.
Properties
Name
Type
Read/Write
Description
attachedTo
Spot
N/A
Parent spot to which current spot is attached to. Returns null when it's attached to nothing or camera.
forward
Vector3
Read
The forward vector of the spot. (Readonly)
id
string
Read
Identifier (GUID) of the spot.
isAlwaysFacingCamera
boolean
ReadWrite
Get this value to determine if camera facing is active. When set to true, FacingCameraStart(false) will be used to let this spot always face the camera.
isAttached
boolean
Read
True when current spot is attached to another spot or camera, using the attachTo() or attachToCamera() methods.
isAttachedToCamera
boolean
Read
True when current spot is attached to camera, using the attachToCamera() method.
isAttachedToSpot
boolean
Read
True when current spot is attached to another spot, using the attachTo() method.
isMoving New
boolean
Read
When this value is true, the spot is moving by automation (ex. by moveTo()).
isPausing
boolean
ReadWrite
When this value is true, the spot will show no movement (except video, rotation of objects facing camera). [Unavailable during a network session]
isResizing
boolean
Read
When this value is true, the spot is resizing by automation (ex. by resizeTo()).
isRotating New
boolean
Read
When this value is true, the spot is rotating by automation (ex. by rotate()).
isVisible
boolean
ReadWrite
When this value is true, the spot is visible.
material
SpotMaterial
N/A
Reference to a SpotMaterial object. Enables control over all material related parameters. You can use this property to get or set a material. Only available on Image, GLTF, OBJ, Unity3D and 3D Text spots.
name
string
Read
Name of the spot.
physics
SpotPhysics
N/A
Reference to a SpotPhysics object (see Physics Module). Enables control over all physics related parameters.
position
Vector3
ReadWrite
Get position in world space (relative to space origin) coordinates. Set to move the spot to its new location.
Example
// Set position of a spot named 'mySpot' to (0,0,0) when clicked.
function onClick(eventParams)
{
let clickedSpot = eventParams.spot;
if (clickedSpot.name == 'mySpot')
clickedSpot.position = Vector3.zero;
}
rotation
Quaternion
ReadWrite
Get or set the rotation using a quaternion.
rotationEuler
Vector3
ReadWrite
Get or set the rotation using euler angles in degrees.
scale
Vector3
ReadWrite
Get or set the scale.
type
string
Read
Returns name of the type of the spot.
Public Methods
Spot attachTo(Spot spot, string meshName)
Attach spot to another parent spot and returns spot for chaining. Position and rotation will be updated each frame to match the parent spot. The spot will be detached automatically when you change the position or rotation by changing its properties or applying automated movement (like move(), rotate() etc.).
Parameter
Type
Description
spot
Spot
The parent spot to follow.
meshName
string
The mesh name or part of the mesh name to select (case-insensitive). (Optional)
Spot attachToCamera(AttachType attachType)
Attach spot to the main camera and returns spot for chaining. Position and rotation will be updated each frame to match the camera. The spot will be detached automatically when you change the position or rotation by changing its properties or applying automated movement (like move(), rotate() etc.).
Parameter
Type
Description
attachType
AttachType
How to follow the camera movement (default normal).
Spot detach()
Detach spot from any parent spot or camera set with attachTo() or attachToCamera() methods.
Parameter
Type
Description
facingCameraStart(boolean allAxis)
Spot will always be facing the camera.
Parameter
Type
Description
allAxis
boolean
When true it will rotate over all axis (X,Y,Z). When left empty or to false (default) it will only rotate over Y-axis (billboarding).
Example
// Make any clicked spot always turn towards the camera when clicked.
function onClick(eventParams)
{
eventParams.spot.facingCameraStart();
}
facingCameraStop()
Spot will stop facing the camera. It will be left at its current position. Use Spot.Reset() to return it to its initial position.
hide()
Hide a spot.
MoveFunc move(Vector3 translation, number duration, Function onComplete) New
Move a spot from its current position to a target position. This uses a relative target value. Use moveTo() for an absolute change.
Parameter
Type
Description
translation
Vector3
Moves the spot in the direction and distance of translation.
duration
number
Duration in seconds (default 1).
onComplete
Function
Optional parameter. OnComplete function called on movement completion.
MoveFunc moveTo(Vector3 targetPos, number duration, Function onComplete) New
Move a spot from its current position to a target position. This uses an absolute target value. Use move() for a relative change.
Parameter
Type
Description
targetPos
Vector3
Target position
duration
number
Duration in seconds
onComplete
Function
Optional parameter. OnComplete function called on movement completion.
Example
// Move spot mySpot to the position of a spot myTarget within 2 seconds. Hide mySpot when target is reached.
function onClick(eventParams)
{
let clickedSpot = eventParams.spot;
if (clickedSpot.name == 'mySpot')
clickedSpot.moveTo(Space.getSpot('myTarget').position, 2, function(){
clickedSpot.hide();
});
}
BlocksSpot onCollision(Function onCollision)
Sets onCollision event handler. Returns BlocksSpot object for chaining.
Parameter
Type
Description
onCollision
Function
OnCollision(EventModule.CollisionEventParameters) function called when any collision occurs. Pass null to clear the event.
pause()
Pause a spot. All movement will stop (except video, rotation of objects facing camera). [Unavailable during a network session]
reset()
Resets position, rotation and scale to their initial values.
ResizeFunc resize(Vector3 changeInScale, number duration, Function onComplete)
Resize a spot from its current scale to a target scale. This uses a relative target value. Use resizeTo() for an absolute change.
Parameter
Type
Description
changeInScale
Vector3
Resizes the spot by adding this value to the current scale. Negative values allowed, but resulting scale will clamp to 0.
duration
number
Duration in seconds (default 1).
onComplete
Function
Optional parameter. OnComplete function called on movement completion.
ResizeFunc resizeTo(Vector3 targetScale, number duration, Function onComplete)
Move a spot from its current position to a target position. This uses an absolute target value. Use resize() for a relative change.
Parameter
Type
Description
targetScale
Vector3
Target scale (no negative values).
duration
number
Duration in seconds
onComplete
Function
Optional parameter. OnComplete function called on movement completion.
resume()
Resume a paused spot. Movement will continue from its current position (except video, rotation of objects facing camera). [Unavailable during a network session]
RotateFunc rotate(Vector3 eulerRot, number duration, Function onComplete) New
Rotate a spot by the specified angles per local axis in degrees (uses euler internally, use rotateTo if you need to rotate using a quaternion). This uses a relative target value. Use rotateTo() for an absolute change.
Parameter
Type
Description
eulerRot
Vector3
The rotation to apply in euler angles.
duration
number
Duration in seconds (default 1).
onComplete
Function
Optional parameter. OnComplete function called on rotation completion.
Example
Example 1:
// Rotate spot mySpot 360 degrees in 3 seconds around the y-axis.
function onClick(eventParams)
{
let clickedSpot = eventParams.spot;
if (clickedSpot.name == 'mySpot')
{
// First parameter Vector3 is our target angle we wish to rotate.
// The second parameter '3' is the duration in seconds the rotation should take.
clickedSpot.rotate(new Vector3(0, 360, 0), 3);
}
}
Example 2:
// Rotate spot mySpot 90 degrees in 1 second around the y-axis and reset rotation back to its initial rotation when finished.
function onClick(eventParams)
{
let clickedSpot = eventParams.spot;
if (clickedSpot.name == 'mySpot')
{
let initialRotation = clickedSpot.rotation;
// First parameter Vector3 is our target angle we wish to rotate.
// The second parameter '1' is the duration in seconds the rotation should take.
// The onComplete method is our callback where we reset the rotation back to its initial rotation.
clickedSpot.rotate(new Vector3(0, 90, 0), 1).onComplete(() => {
clickedSpot.rotation = initialRotation;
});
}
}
Example 3:
// Rotate spot mySpot 180 degrees in 2 seconds around the y-axis and rotate back to 0 degrees and repeat this infinitely.
function onClick(eventParams)
{
let clickedSpot = eventParams.spot;
if (clickedSpot.name == 'mySpot')
{
// First parameter Vector3 is our target angle we wish to rotate.
// The second parameter '2' is the duration in seconds one rotation loop should take.
// The 'loop' method, with value '-1', says we are looping this rotation for infinite time. You can stop this by calling stop() or stopRotate() on this spot.
// The 'loopType' method, with value LoopType.pingPong, tells we want the loop to ping-pong/yoyo forth and back.
clickedSpot.rotate(new Vector3(0, 180, 0), 2).loop(-1).loopType(LoopType.pingPong);
}
}
RotateFunc rotateTo(Vector3 eulerRot, number duration, Function onComplete) New
Rotate a spot from its current rotation to the nearest absolute target rotation (uses quaternion internally). This uses an absolute target value. Use rotate() for a relative change.
Parameter
Type
Description
eulerRot
Vector3
Rotation in euler angles.
duration
number
Duration in seconds.
onComplete
Function
Optional parameter. OnComplete function called on rotation completion.
show()
Show a spot.
stop()
Stops all automated movement (except video, rotation of objects facing camera). [Unavailable during a network session]
stopMove()
Stops all automated movement started with move/moveTo. [Unavailable during a network session]
stopResize()
Stops all automated movement started with resize/resizeTo. [Unavailable during a network session]
stopRotate()
Stops all automated rotation started with rotate/rotateTo. [Unavailable during a network session]
Classes
AttachType (static)
Constants used for setting the AttachType.
Static Properties
Name
Type
Read/Write
Description
keepYUp
number
Read
Spot follows parent position and rotation but always keeps Y pointing upwards. (value 1)
normal
number
Read
Spot follows parent position and rotation. (value 0, default)
noRotation
number
Read
Spot follows parent position and rotation without rotating the spot. (value 2)
MoveFunc New
Object used for function chaining.
Public Methods
MoveFunc duration(number duration) New
Sets duration and restarts movement.
Parameter
Type
Description
duration
number
Duration in seconds.
MoveFunc ease(EaseType easeType) New
Sets how to ease.
Parameter
Type
Description
easeType
EaseType
Ease type. (default EaseType.linear)
MoveFunc from(Vector3 from) New
Sets start position of spot and restarts movement.
Parameter
Type
Description
from
Vector3
Start position.
MoveFunc loop(number loopCount) New
Sets number of loops to play.
Parameter
Type
Description
loopCount
number
-1 = infinite, 1 = play once, 2 = play twice etc. (default 1)
MoveFunc loopType(LoopType loopType) New
Sets how to loop.
Parameter
Type
Description
loopType
LoopType
Loop type. (default LoopType.normal)
MoveFunc onComplete(Function onComplete) New
Sets onComplete callback event handler.
Parameter
Type
Description
onComplete
Function
OnComplete function called on movement completion. Pass null to clear the event.
ResizeFunc
Object used for function chaining.
Public Methods
ResizeFunc duration(number duration)
Sets duration and restarts resize motion.
Parameter
Type
Description
duration
number
Duration in seconds.
ResizeFunc ease(EaseType easeType)
Sets how to ease.
Parameter
Type
Description
easeType
EaseType
Ease type. (default EaseType.linear)
ResizeFunc from(Vector3 from)
Sets start position of spot and restarts resize motion.
Parameter
Type
Description
from
Vector3
Start position.
ResizeFunc loop(number loopCount)
Sets number of loops to play.
Parameter
Type
Description
loopCount
number
-1 = infinite, 1 = play once, 2 = play twice etc. (default 1)
ResizeFunc loopType(LoopType loopType)
Sets how to loop.
Parameter
Type
Description
loopType
LoopType
Loop type. (default LoopType.normal)
ResizeFunc onComplete(Function onComplete)
Sets onComplete callback event handler.
Parameter
Type
Description
onComplete
Function
OnComplete function called on resize completion. Pass null to clear the event.
RotateFunc New
Object used for function chaining.
Public Methods
RotateFunc duration(number duration) New
Sets duration and restarts rotation.
Parameter
Type
Description
duration
number
Duration in seconds.
RotateFunc ease(EaseType easeType) New
Sets how to ease.
Parameter
Type
Description
easeType
EaseType
Ease type. (default EaseType.linear)
RotateFunc from(Quaternion from) New
Sets start rotation of spot and restarts rotation.
Parameter
Type
Description
from
Quaternion
Start rotation as quaternion.
RotateFunc fromEuler(Vector3 fromEuler) New
Sets start rotation of spot and restarts rotation.
Parameter
Type
Description
fromEuler
Vector3
Start rotation in euler angles.
RotateFunc loop(number loopCount) New
Sets number of loops to play.
Parameter
Type
Description
loopCount
number
-1 = infinite, 1 = play once, 2 = play twice etc. (default 1)
RotateFunc loopType(LoopType loopType) New
Sets how to loop.
Parameter
Type
Description
loopType
LoopType
Loop type. (default LoopType.normal)
RotateFunc onComplete(Function onComplete) New
Sets onComplete callback event handler.
Parameter
Type
Description
onComplete
Function
OnComplete function called on rotation completion. Pass null to clear the event.
SpotMaterial
Properties and chainable functions to set or modify the visual material of a spot.
Properties
Name
Type
Read/Write
Description
color
Color
ReadWrite
Get or set the main color of all materials. Uses the shader property named '_Color'. When using Unity's ShaderLab code you can also use the [MainColor] property attribute.
Public Methods
Color getColor(string name)
Gets the color value of a shader property.
Parameter
Type
Description
name
string
Name of the property to get (e.g. '_Albedo').
number getFloat(string name)
Gets the float value of a shader property.
Parameter
Type
Description
name
string
Name of the property to get (e.g. '_Progress').
number getInteger(string name)
Gets the integer value of a shader property.
Parameter
Type
Description
name
string
Name of the property to get (e.g. '_Type').
Vector4 getVector(string name)
Gets the vector value of a shader property.
Parameter
Type
Description
name
string
Name of the property to get (e.g. '_Direction').
SpotMaterial materialId(number materialId)
Selects only the material at specified slot number.
Parameter
Type
Description
materialId
number
The material slot number to select.
SpotMaterial meshName(string meshName)
Selects only the material from specified mesh name. This mesh can also be any submesh in the internal hierarchy of the spot.
Parameter
Type
Description
meshName
string
The mesh name to select.
SpotMaterial reset()
Resets the material back to its original and returns the SpotMaterial object for chaining.
SpotMaterial set(SpotMaterial material)
Sets the material and returns the SpotMaterial object for chaining.
Parameter
Type
Description
material
SpotMaterial
The material to assign.
SpotMaterial setColor(Color color)
Sets the main color and returns the SpotMaterial object for chaining. Same as setting the color property.
Parameter
Type
Description
color
Color
The new color. Sets the value of the shader property named '_Color'. When using Unity's ShaderLab code you can also use the [MainColor] property attribute.
SpotMaterial setColor(string name, Color value)
Sets the color value of a shader property and returns the SpotMaterial object for chaining.
Parameter
Type
Description
name
string
Name of the property to set (e.g. '_Albedo').
value
Color
Value to set (e.g. 'new Color(1, 0, 0, 1)').
SpotMaterial setFloat(string name, number value)
Sets the float value of a shader property and returns the SpotMaterial object for chaining.
Parameter
Type
Description
name
string
Name of the property to set (e.g. '_Progress').
value
number
Value to set (e.g. '0.5').
SpotMaterial setInteger(string name, number value)
Sets the integer value of a shader property and returns the SpotMaterial object for chaining.
Parameter
Type
Description
name
string
Name of the property to set (e.g. '_Type').
value
number
Value to set (e.g. '2').
SpotMaterial setVector(string name, Vector4 value)
Sets the vector value of a shader property and returns the SpotMaterial object for chaining.
Parameter
Type
Description
name
string
Name of the property to set (e.g. '_Direction').
value
Vector4
Value to set (e.g. 'new Vector4(1.2, 3.4, 5, 0)').
CodeSpot
Inherits from: Spot
An object representing a code spot.
Public Methods
Object getVar(string name)
Get a value of a publicly available variable of this code spot.
Parameter
Type
Description
name
string
Name of the variable to get (case-sensitive).
invoke(string name, Object parameters)
Invoke a publicly available function of this code spot.
Parameter
Type
Description
name
string
Name of the function to execute (case-sensitive).
parameters
Object
One or more arguments to pass to the function (optional).
setVar(string name, Object value)
Set a publicly available variable of this code spot to a value.
Parameter
Type
Description
name
string
Name of the variable to set (case-sensitive).
value
Object
Value of the variable to set.
Text3D
Inherits from: Spot
An object representing a 3D Text spot.
Properties
Name
Type
Read/Write
Description
color
Color
ReadWrite
Color of the text.
text
string
ReadWrite
Text to show.
VideoBasedSpot
Inherits from: Spot
An object representing a video based spot.
Properties
Name
Type
Read/Write
Description
video
SpotVideo
N/A
Reference to a SpotVideo object (see Video Module). Enables control over all video related parameters.
Video
Inherits from: VideoBasedSpot
An object representing a video spot.
HoloPresenter
Inherits from: VideoBasedSpot
An object representing a holo presenter spot.
Space (static)
Space related functions and variables
Static Properties
Name
Type
Read/Write
Description
camera
Camera
N/A
Main camera.
isPausing
boolean
ReadWrite
When this value is true, all spots will show no movement.
spotIds
ArrayOfString
Read
All spot ids.
spotNames
ArrayOfString
Read
All spot names.
spots
ArrayOfSpot
Read
All spot instances.
Example
// Go through all spots in the space and place them next to eachother.
for (let i = 0; i < Space.spots.length; i++)
Space.spots[i].position = new Vector3(i, 0, 0);
Static Methods
Spot getSpot(string spotName)
Get a spot object by name. Returns first spot matching the given name.
Parameter
Type
Description
spotName
string
Name of the spot (case-insensitive)
Example
// Get the spot named 'mySpot' and write the position to the log.
log(Space.getSpot('mySpot').position);
Spot getSpotById(string uuid)
Get a spot object by its identifier. Returns first spot matching the given uuid.
Parameter
Type
Description
uuid
string
Guid of the spot
boolean hide(string spotName)
Hide a spot. Returns true if spot was found and deactivated.
Parameter
Type
Description
spotName
string
Name of the spot (case-insensitive)
pause()
Pause all spots. All movement will stop.
reset()
Resets the space to its initial state.
resume()
Resume all paused spots. Movement will continue from its current position.
boolean show(string spotName)
Show a spot. Returns true if spot was found and activated.
Parameter
Type
Description
spotName
string
Name of the spot (case-insensitive)
LoopType (static) New
Constants used for setting the loopType.
Static Properties
Name
Type
Read/Write
Description
incremental New
number
Read
Continue motion by extrapolating from previous range. (value 2)
normal New
number
Read
Restarts from beginning after each iteration. (value 0, default)
pingPong New
number
Read
Reverse motion after each iteration. (value 1)
EaseType (static) New
Constants used for setting the easeType.
Static Properties
Name
Type
Read/Write
Description
inBack New
number
Read
Interpolation starts slowly, and then progressively speeds up until the end, at which point it stops abruptly. (value 26)
inBounce New
number
Read
Interpolation starts slowly, and then progressively speeds up until the end, at which point it stops abruptly. (value 29)
inCirc New
number
Read
Interpolation starts slowly, and then progressively speeds up until the end, at which point it stops abruptly. (value 20)
inCubic New
number
Read
Interpolation starts slowly, and then progressively speeds up until the end, at which point it stops abruptly. (value 8)
inElastic New
number
Read
Interpolation starts slowly, and then progressively speeds up until the end, at which point it stops abruptly. (value 23)
inExpo New
number
Read
Interpolation starts slowly, and then progressively speeds up until the end, at which point it stops abruptly. (value 17)
inOutBack New
number
Read
Interpolation starts slowly, speeds up, and then slows down towards the end. (value 28)
inOutBounce New
number
Read
Interpolation starts slowly, speeds up, and then slows down towards the end. (value 31)
inOutCirc New
number
Read
Interpolation starts slowly, speeds up, and then slows down towards the end. (value 22)
inOutCubic New
number
Read
Interpolation starts slowly, speeds up, and then slows down towards the end. (value 10)
inOutElastic New
number
Read
Interpolation starts slowly, speeds up, and then slows down towards the end. (value 25)
inOutExpo New
number
Read
Interpolation starts slowly, speeds up, and then slows down towards the end. (value 19)
inOutQuad New
number
Read
Interpolation starts slowly, speeds up, and then slows down towards the end. (value 7)
inOutQuart New
number
Read
Interpolation starts slowly, speeds up, and then slows down towards the end. (value 13)
inOutQuint New
number
Read
Interpolation starts slowly, speeds up, and then slows down towards the end. (value 16)
inOutSine New
number
Read
Interpolation starts slowly, speeds up, and then slows down towards the end. (value 4)
inQuad New
number
Read
Interpolation starts slowly, and then progressively speeds up until the end, at which point it stops abruptly. (value 5)
inQuart New
number
Read
Interpolation starts slowly, and then progressively speeds up until the end, at which point it stops abruptly. (value 11)
inQuint New
number
Read
Interpolation starts slowly, and then progressively speeds up until the end, at which point it stops abruptly. (value 14)
inSine New
number
Read
Interpolation starts slowly, and then progressively speeds up until the end, at which point it stops abruptly. (value 2)
linear New
number
Read
Straight linear interpolation (value 1, default)
outBack New
number
Read
Interpolation starts abruptly, and then progressively slows down towards the end. (value 27)
outBounce New
number
Read
Interpolation starts abruptly, and then progressively slows down towards the end. (value 30)
outCirc New
number
Read
Interpolation starts abruptly, and then progressively slows down towards the end. (value 21)
outCubic New
number
Read
Interpolation starts abruptly, and then progressively slows down towards the end. (value 9)
outElastic New
number
Read
Interpolation starts abruptly, and then progressively slows down towards the end. (value 24)
outExpo New
number
Read
Interpolation starts abruptly, and then progressively slows down towards the end. (value 18)
outQuad New
number
Read
Interpolation starts abruptly, and then progressively slows down towards the end. (value 6)
outQuart New
number
Read
Interpolation starts abruptly, and then progressively slows down towards the end. (value 12)
outQuint New
number
Read
Interpolation starts abruptly, and then progressively slows down towards the end. (value 15)
outSine New
number
Read
Interpolation starts abruptly, and then progressively slows down towards the end. (value 3)
Time module
All time related functions and constants.
Public Methods
bigint setTimeout(Function onTimeout, number delay)
The setTimeout() method sets a timer which executes a function or specified piece of code once the timer expires. Returns a handle to use with clearTimeout.
Parameter
Type
Description
onTimeout
Function
Function to call or code to execute.
delay
number
The time, in milliseconds that the timer should wait before the specified function or code is executed.
clearTimeout(bigint timeoutHandle)
The clearTimeout() method clears a timer set with the setTimeout() method.
Parameter
Type
Description
timeoutHandle
bigint
The ID value returned by setTimeout().
bigint setInterval(Function onInterval, number delay)
The setInterval() method repeatedly calls a function or executes a code snippet, with a fixed time delay between each call. Returns a handle to use with clearInterval.
Parameter
Type
Description
onInterval
Function
Function to call or code to execute.
delay
number
Interval in milliseconds.
Example
Example 1:
// Create a log entry every 5 seconds
setInterval(() => log('Another 5 seconds have passed.'), 5000);
Example 2:
// Rotate three spots to create a realtime analog clock
let hands = ['hourHand', 'minutesHand', 'secondsHand'];
// Get spot instances based on the names in the hands array
let hourSpot = Space.getSpot(hands[0]);
let minuteSpot = Space.getSpot(hands[1]);
let secondSpot = Space.getSpot(hands[2]);
// Set interval to update the clock every 1000 milliseconds (1 second)
setInterval(() => {
// Get the current time
let now = new Date();
let seconds = now.getSeconds();
let minutes = now.getMinutes();
let hours = now.getHours() + (minutes / 60);
// Get the rotations based on the time
let rotationHours = Quaternion.Euler(0, 0, hours / 12 * 360);
let rotationMinutes = Quaternion.Euler(0, 0, minutes / 60 * 360);
let rotationSeconds = Quaternion.Euler(0, 0, seconds / 60 * 360);
// Rotate around Z
hourSpot.rotation = rotationHours;
minuteSpot.rotation = rotationMinutes;
secondSpot.rotation = rotationSeconds;
// Position the spots
hourSpot.position = rotationHours * Vector3.up;
minuteSpot.position = rotationMinutes * Vector3.up;
secondSpot.position = rotationSeconds * Vector3.up;
}, 1000);
clearInterval(bigint intervalHandle)
The clearInterval() method clears a timer set with the setInterval() method.
Parameter
Type
Description
intervalHandle
bigint
The ID value returned by setInterval().
Example
// Hide and show 'mySpot' every 500 milliseconds for a total of 3 seconds.
let mySpot = Space.getSpot('mySpot');
// Toggle visibility every 500 ms and store a handle to the interval in myInterval.
let myInterval = setInterval(() => mySpot.isVisible = !mySpot.isVisible, 500);
// Clear the interval after 3 seconds have passed.
setTimeout(() => {
clearInterval(myInterval);
// Make sure the spot is visible at the end of this blinking sequence.
mySpot.isVisible = true;
}, 3000);
Classes
Time (static)
Time related class with functions and constants.
Static Properties
Name
Type
Read/Write
Description
deltaTime
number
Read
The interval in seconds from the last frame to the current one.
time
number
Read
The time in seconds since the start of the application.
TimeTriggerType (static)
Constants used for setting the timeTriggerType.
Static Properties
Name
Type
Read/Write
Description
always
number
Read
Trigger fires once when time has passed set time. (value 1)
custom
number
Read
Trigger fires once when time is between the set time and the given range. (value 2)
momentary
number
Read
Trigger fires once at exact set time. (value 0, default)
Utility module
All utility related functions and constants.
Classes
Util (static)
Utility related class with functions and constants.
Static Methods
Color hexToColor(string hexColor)
Converts hexadecimal string to color object. Returns black color with alpha 0 when parse fails.
Parameter
Type
Description
hexColor
string
Hexadecimal color (ex. #FF0000 is red)
Video module
Video killed the radio star
Classes
SpotVideo
Spot specific video related functions and variables
Properties
Name
Type
Read/Write
Description
isLooping
boolean
ReadWrite
Returns true when video is played in a loop. Set true to let video repeat itself indefinitely.
isPausing
boolean
ReadWrite
Returns true when video is paused. Set true to pause or false to resume.
length
number
Read
Duration of the video in seconds.
pauseOnClick
boolean
ReadWrite
Pause video on click. (default: true)
time
number
ReadWrite
Absolute playback time in seconds. Set to jump to time.
timeProgress
number
ReadWrite
Relative playback time. Value is from 0 to 1 where 1 is the end of the video. Set to jump to time.
Public Methods
bigint addTrigger(Function onTrigger, number time, TimeTriggerType timeTriggerType, number customRange)
Adds a trigger event which is fired when the video reaches the set time. Returns a handle to use with removeTrigger.
Parameter
Type
Description
onTrigger
Function
Function to call or code to execute.
time
number
Time in seconds, the video has been playing before the function (specified in onTrigger) is executed.
timeTriggerType
TimeTriggerType
Type of timerange used to execute the trigger (Optional). (default TimeTriggerType.momentary)
customRange
number
Only for TimeTriggerType.custom. Specify your time offset (in seconds) in which the trigger should be executed (Optional). (default 0.5)
pause()
Pauses the video.
removeTrigger(bigint triggerHandle)
Removes a trigger event.
Parameter
Type
Description
triggerHandle
bigint
The ID value returned by addTrigger().
resetTrigger(bigint triggerHandle)
Resets (rearms) a trigger event. First make sure the time of the video is set outside the triggerable time range or the trigger will be executed immediately.
Parameter
Type
Description
triggerHandle
bigint
The ID value returned by addTrigger().
resume()
Resumes playback of the video.
rewind()
Resets the playhead to the beginning of the video.
Web module
All web related functions and constants.
Classes
Web (static)
Web functionality.
Static Methods
WebRequestFunc create(string url)
Create a web request.
Parameter
Type
Description
url
string
Web address (including 'https://' prefix).
Classes
WebRequestFunc
Object used for function chaining.
Public Methods
WebRequestFunc bearer(string token)
Bearer token to submit in the header as 'Authorization' value. (Optional)
Parameter
Type
Description
token
string
Bearer token without the 'Bearer ' prefix.
delete()
Performs the HTTP call using the DELETE method. Time between calls may not be lower than 0.5 seconds.
get()
Performs the HTTP call using the GET method. Time between calls may not be lower than 0.5 seconds.
WebRequestFunc header(string key, string value)
Set an HTTP request header to a custom value. (Optional)
Parameter
Type
Description
key
string
Key part of the request header (part before '='-sign). Like 'Content-Type'.
value
string
Value part of the request header (part after '='-sign). Like 'application/json'.
WebRequestFunc onComplete(WebResult webResult)
Callback invoked when response data is received after a call was made. (Optional)
Parameter
Type
Description
webResult
WebResult
WebResult containing the data received.
WebRequestFunc param(string key, string value)
Query parameter which will be URL encoded. (Optional)
Parameter
Type
Description
key
string
Key (part before '='-sign).
value
string
Value (part after '='-sign).
WebRequestFunc payload(Object data)
Data to submit in the body. (Optional)
Parameter
Type
Description
data
Object
Javascript object to submit as JSON.
post()
Performs the HTTP call using the POST method. Time between calls may not be lower than 0.5 seconds.
put()
Performs the HTTP call using the PUT method. Time between calls may not be lower than 0.5 seconds.
WebResult
Response object containing all data sent back from server requests.
Properties
Name
Type
Read/Write
Description
data
ArrayOfByte
Read
Byte array representation of the server result.
object
Object
N/A
Object deserialized from text interpreted as JSON.
size
number
Read
Number of bytes.
text
string
Read
String representation of the server result.