1.1.5 • Published 6 years ago

altspacevr-behaviors v1.1.5

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

AltspaceUtil

Provides helper functions, behaviors and A-Frame components for common functionality compatible with AltspaceSDK.

Usage

Include the utility library in your project:

<script src="https://cdn.jsdelivr.net/npm/altspacevr-behaviors@1.1.5/js/altspaceutil.min.js"></script>

API Reference

Functions

Behaviors

Events

Classes

A-Frame Components

Functions

altspaceutil.getFullspaceApp

Gets an initialized fullspace app instance. The app will be initialized on the first call to this function, which sets up the render loop, fullspace enclosure and anchors.

Parameters

NameTypeDefaultDescription
configObjectOptional parameters.
config.serializationBufferSizeNumber500000Initial size of the serialization buffer. See altspaceutil.expandSerializationBuffer for more information.

Returns

TypeDescription
PromiseA promise that resolves to a FullspaceApp.

altspaceutil.getFullspaceEnclosure

Gets the fullspace enclosure for the app.

Returns

TypeDescription
PromiseA promise that resolves to a fullspace Enclosure.

altspaceutil.getAbsoluteURL

Create an absolute URL from the specified relative URL, using the current host as the URL base.

Parameters

NameTypeDescription
urlStringA relative URL. Providing an absolute URL will return itself unchanged.

Returns

TypeDescription
StringAn absolute URL of the given relative URL.

altspaceutil.getBasePath

Create a base path from the specified file URL.

Parameters

NameTypeDescription
urlStringA URL to a file.

Returns

TypeDescription
StringA URL to the file's base path.

altspaceutil.isMobileApp

Indicates whether the app is being loaded on a mobile version of the Altspace client. This is typically determined by the user agent exposed to the app.

Returns

TypeDescription
BooleanWhether the app is running on a mobile client. Returns true for mobile clients, false otherwise.

altspaceutil.expandSerializationBuffer

Expands the Altspace client's serialization buffer to improve loading performance.

Parameters

NameTypeDescription
sizeNumberThe size to expand the serialization buffer by, in bytes.

altspaceutil.profileSerializationBuffer

Enables or disables the profiler for the Altspace client's serialization buffer to determine whether the buffer needs to be expanded. Profiler messages will be displayed in the console when enabled.

Parameters

NameTypeDescription
enabledBooleanSpecifies whether the serialization buffer is to be enabled.

altspaceutil.setCursorCollider

Sets the Altspace cursor collider property for the specified object.

Parameters

NameTypeDefaultDescription
object3dTHREE.Object3DAn object to set the cursor collider property for.
isCursorColliderBooleanSpecifies if the object is a cursor collider.
recursiveBooleanfalseSpecifies if the property change should also be applied recursively to all children of the object.

altspaceutil.isCursorCollider

Gets the Altspace cursor collider property for the specified object.

Parameters

NameTypeDescription
object3dTHREE.Object3DAn object to retrieve the cursor collider property from.

Returns

TypeDescription
BooleanWhether the object is a cursor collider.

altspaceutil.loadTexture

Loads a three.js texture from the specified texture file URL, optimizing for faster loading times in the Altspace client where appropriate.

Parameters

NameTypeDescription
urlStringA URL to a texture file.
configObjectOptional parameters to be passed to the texture loader (e.g. crossOrigin, withCredentials, path).

Returns

TypeDescription
THREE.TextureThe loaded texture.

altspaceutil.loadScript

Loads and executes a script from the specified JavaScript file URL.

Parameters

NameTypeDefaultDescription
urlStringA URL to a JavaScript file.
configObjectOptional parameters for specialized cases.
config.scriptTestFunctionnullA predicate function that tests whether the script contents has loaded. A return value of true indicates that the loaded script content exists, false otherwise.
config.loadOnceBooleantrueIndicates whether the script should be loaded if it was previously loaded. If true, the script will not be loaded again on subsequent calls if it was previously loaded.

Returns

TypeDescription
PromiseA promise that resolves when the javascript file has been loaded.

altspaceutil.loadScripts

Loads and executes one or more scripts from the specified JavaScript file URL.

Parameters (1)

NameTypeDescription
scriptsString[]An array of JavaScript file URLs to be loaded.

Parameters (2)

NameTypeDescription
scriptsScript[]An array of objects containing a URL and optional config parameters for the scripts to be loaded. See below for object parameters.

Script parameters.

NameTypeDefaultDescription
urlStringA URL to a JavaScript file.
scriptTestFunctionnullA predicate function that tests whether the script contents has loaded. A return value of true indicates that the loaded script content exists, false otherwise.
loadOnceBooleantrueIndicates whether the script should be loaded if it was previously loaded. If true, the script will not be loaded again on subsequent calls if it was previously loaded.

Returns

TypeDescription
PromiseA promise that resolves when the javascript files have been loaded.

altspaceutil.loadAsset (Example)

Loads an asset from the specified URL.

Default formats supported:

Additional formats can be loaded by registering a custom file handler using addAssetLoader.

Parameters

NameTypeDefaultDescription
urlStringA URL to the asset to be loaded.
configObjectOptional parameters.
config.applyTransformBooleantrueWhen true, the position/rotation/quaternion/scale properties will be applied to the loaded asset.
config.cursorColliderBooleanfalseSpecified whether cursor collision is enabled on the loaded asset.
config.nativeBooleantrueWhen true, assets loaded in the Altspace client will be loaded as native objects where appropriate (e.g. n-gltf for glTF assets), otherwise standard browser behavior will be followed.
config.positionTHREE.Vector3{ x: 0, y: 0, z: 0 }Position to be applied to the loaded asset.
config.rotationTHREE.Euler{ x: 0, y: 0, z: 0 }Rotation to be applied to the loaded asset, in radians.
config.quaternionTHREE.Quaternion{ x: 0, y: 0, z: 0, w: 1 }Quaternion to be applied to the loaded asset. Specifying quaternion will override the rotation property.
config.scaleTHREE.Vector3{ x: 1, y: 1, z: 1 }Scale to be applied to the loaded asset. Alternatively, uniform scaling is applied when a number is specified.
config.onLoadedFunctionnullA callback function to execute when the asset has been loaded. A reference to the loaded asset will be passed into this function.
config.crossOriginStringanonymousSpecifies the cross-origin state for loading textures.

Returns

TypeDescription
PromiseA promise that resolves to the loaded asset.

altspaceutil.loadAssets (Example)

Loads one or more assets from the specified URLs.

Parameters (1)

NameTypeDescription
assetsAsset[]An array of assets to be loaded.

Parameters (2)

NameTypeDescription
assetsObjectAn object of unordered, named assets to be loaded.

Asset parameters.

NameTypeDefaultDescription
urlStringA URL to a JavaScript file.
applyTransformBooleantrueWhen true, the position/rotation/quaternion/scale properties will be applied to the loaded asset.
cursorColliderBooleanfalseSpecified whether cursor collision is enabled on the loaded asset.
nativeBooleantrueWhen true, assets loaded in the Altspace client will be loaded as native objects where appropriate (e.g. n-gltf for glTF assets), otherwise standard browser behavior will be followed.
positionTHREE.Vector3{ x: 0, y: 0, z: 0 }Position to be applied to the loaded asset.
rotationTHREE.Euler{ x: 0, y: 0, z: 0 }Rotation to be applied to the loaded asset, in radians.
quaternionTHREE.Quaternion{ x: 0, y: 0, z: 0, w: 1 }Quaternion to be applied to the loaded asset. Specifying quaternion will override the rotation property.
scaleTHREE.Vector3{ x: 1, y: 1, z: 1 }Scale to be applied to the loaded asset. Alternatively, uniform scaling is applied when a number is specified.
onLoadedFunctionnullA callback function to execute when the asset has been loaded. A reference to the loaded asset will be passed into this function.
crossOriginStringanonymousSpecifies the cross-origin state for loading textures.

Returns

TypeDescription
PromiseA promise that resolves to the loaded assets, either as an array or object of named assets depending on the supplied parameters.

altspaceutil.addAssetLoader (Example)

Registers a handler that will load and construct the specified asset type when loadAsset or loadAssets is called.

Parameters

NameTypeDescription
regexRegExpThe regular expression that will be used to identify an asset from its URL (e.g. /\.dae$/i to match the file extension for Collada assets.)
handlerAssetLoaderHandlerA handler function that accepts a URL and configuration parameters that will load and construct the asset. The function must return a promise that resolves that resolves to the loaded asset, or a rejected promise on failure.

AssetLoaderHandler parameters.

NameTypeDescription
urlStringA URL to the asset to be loaded.
configObjectOptional parameters.

altspaceutil.removeAssetLoader

Unregisters a handler for the specified asset type that is used when loadAsset or loadAssets is called.

Parameters

NameTypeDefaultDescription
regexRegExpThe regular expression associated with an asset handler.
handlerAssetLoaderHandlernullAn asset handler function that is associated with the specified regular expression. If omitted, all handlers for the specified regular expression will be removed.

altspaceutil.overrideTextureLoader

Enables or disables texture loading optimizations in the Altspace client. Enabling texture loader optimizations can drastically improve texture loading times, reduce resource usage and correct compability issues with embedded textures in the Altspace client.

Please note that these optimizations are enabled by default, and can be disabled when compatibility issues with other libraries arise.

Parameters

NameTypeDescription
overrideBooleanSpecifies whether texture loader optimizations are enabled.

Behaviors

altspaceutil.behaviors.NativeComponent (Example)

Provides support for AltspaceVR native components to be attached to objects, providing sane configuration defaults where appropriate.

Parameters

type - Native component type.

data - Native component properties. See here for available properties and defaults.

config - Optional parameters for specialized use cases. Many of these properties are provided only to override the internal behavior of a component in specialized use cases.

NameTypeDefaultDescription
targetEntityTHREE.Object3DnullAn object in the scene that a user will teleport to when entering a native portal.
useColliderBooleanfalseSpecifies whether cursor collision should be disabled on the native component.
sharedComponentBooleantrueSpecifies whether the native component should share the same THREE.Mesh instance with other native components.
recursiveMeshBooleanfalseSpecifies whether the native component is applied recursively to all THREE.Mesh children.
recursiveBooleanfalseSpecifies whether the native component is applied recursively to all children.
sendUpdatesBooleantrueSpecifies whether the native component should send updates to the native Altspace client.
updateOnStaleDataBooleantrueSpecifies whether the native component should send updates to the native Altspace client when a property has changed.
inheritParentDataBooleanfalseSpecifies whether the native component should inherit its property state from a parent component.
meshComponentBooleanfalseSpecifies whether the native component is treated as a mesh-specific component. This is used as a performance optimization to defer initialization of mesh-specific components (e.g. native parents and colliders) attached to placeholder objects, until another component is added that gives them functionality (e.g. text, spawner).

Methods

callComponentAction

Invokes an action associated with the native component, and does not provide a return value.

NameTypeDescription
actionNameStringThe action name to invoke on the native component.
actionArgsObjectArguments that will be passed along with the action when invoked.

callComponentFunc

Calls a function associated with the native component, and returns a promise of the value that will be returned by the native component function.

NameTypeDescription
functionNameStringThe function name to invoke on the native component.
functionArgsObjectArguments that will be passed to the function when called.

callComponent

This function has been Deprecated. See callComponentAction.

getAttribute

Retrieves an attribute associated with a native component. See here for available attributes.

NameTypeDescription
attributeNameStringAn attribute name associated with the native component.

Native Component Attributes

Attributes associated with a native component can be retrieved using the getAttribute method.

n-sound

NameTypeDescription
loadedBooleanIndicates that the component has been loaded by the AltspaceVR client.

n-gltf

NameTypeDescription
loadedBooleanIndicates that the component has been loaded by the AltspaceVR client.

n-container

NameTypeDescription
countNumberThe number of objects in the n-container.

Native Component Properties

n-object

data: {
	res: 'architecture/wall-4w-4h'
}

n-spawner

data: {
	res: 'interactables/basketball'
}

n-text

data: {
	text: '',
	fontSize: 10,
	width: 10,
	height: 1,
	horizontalAlign: 'middle',
	verticalAlign: 'middle'
}

n-sphere-collider

data: {
	isTrigger: false,
	center: { 'x': 0, 'y': 0, 'z': 0 },
	radius: 0,
	type: 'environment'
}

n-box-collider

data: {
	isTrigger: false,
	center: { 'x': 0, 'y': 0, 'z': 0 },
	size: { 'x': 0, 'y': 0, 'z': 0 },
	type: 'environment'
}

n-capsule-collider

data: {
	isTrigger: false,
	center: { 'x': 0, 'y': 0, 'z': 0 },
	radius: 0,
	height: 0,
	direction: 'y',
	type: 'environment'
}

n-mesh-collider

data: {
	isTrigger: false,
	convex: true,
	type: 'environment'
}

n-container

data: {
	capacity: 4
}

n-sound

data: {
	on: '',
	res: '',
	src: '',
	loop: false,
	volume: 1,
	autoplay: false,
	oneshot: false,
	spatialBlend: 1,
	pitch: 1,
	minDistance: 1,
	maxDistance: 12,
	rolloff: 'logarithmic'
}

n-skeleton-parent

data: {
	part: 'head',
	side: 'center',
	index: 0,
	userId: null // defaults to current user when omitted
}

n-cockpit-parent

No properties to be configured.

n-billboard

No properties to be configured.

n-layout-browser

data: {
	url: 'about:blank',
	isEnclosure: false
}

n-portal

data: {
	targetSpace: null, // defaults to current space when omited
	targetEvent: null, // defaults to current space when omited
	targetPosition: { x: 0, y: 0, z: 0 },
	targetQuaternion: { x: 0, y: 0, z: 0, w: 1 }
}

n-gltf

data: {
        sceneIndex: 0,
        url: ''
}

n-rigidbody

Experimental! This native component is not yet officially supported by the AltspaceSDK.

data: {
	mass: 1,
	drag: 0,
	angularDrag: 0.05,
	useGravity: true,
	isKinematic: false,
	positionConstraints: [false, false, false],
	rotationConstraints: [false, false, false],
}

altspaceutil.behaviors.NativeComponentSync (Example)

Provides support for AltspaceVR native component data to be synchronized over Firebase. The behavior must be used in conjunction with SceneSync, Object3DSync and a NativeComponent of the same type specified for NativeComponentSync.

Parameters

type - Type of native component to be synchronized. To retrieve the behavior using the getBehaviorByType method, prepend sync- to the name of the native component type (e.g. sync-n-text for an n-text native component).

config - Optional parameters.

NameTypeDefaultDescription
syncRefaltspace.utilities.behaviors.Object3DSyncnullA reference to the object syncing component. Defaults to using the syncing component of the object the behavior is attached to.

altspaceutil.behaviors.TransformControls (Example)

Enables an object's position, rotation and scale to be manipulated in AltspaceVR using a draggable transform gizmo.

Parameters

config - Optional parameters.

NameTypeDefaultDescription
controlTypeStringnoneThe default control type to be selected. Supported control types are none, position, rotate or scale.
showButtonsBooleanfalseSpecifies whether buttons should be displayed to toggle between control types.
followTargetBooleantrueSpecified whether the transform gizmo should follow the object that is being manipulated.
targetTHREE.Object3DnullThe target that the transform gizmo should manipulate when interacted with. If omitted, the object that the behavior is associated with will be used as the target.
scaleNumber1Adjusts the scale of the transform gizmo.
allowNegativeScaleBooleanfalseSpecifies whether the scale transform gizmo will allow the target's scale to be negative.
positionAxisLockObjectSpecifies which axes of the position gizmo can be displayed and manipulated.
positionAxisLock.xBooleantrueX axis of the position gizmo.
positionAxisLock.yBooleantrueY axis of the position gizmo.
positionAxisLock.zBooleantrueZ axis of the position gizmo.
rotateAxisLockObjectSpecifies which axes of the rotate gizmo can be displayed and manipulated.
rotateAxisLock.xBooleantrueX axis of the rotate gizmo.
rotateAxisLock.yBooleantrueY axis of the rotate gizmo.
rotateAxisLock.zBooleantrueZ axis of the rotate gizmo.
scaleAxisLockObjectSpecifies which axes of the scale gizmo can be displayed and manipulated.
scaleAxisLock.xBooleantrueX axis of the scale gizmo.
scaleAxisLock.yBooleantrueY axis of the scale gizmo.
scaleAxisLock.zBooleantrueZ axis of the scale gizmo.
disableCollidersBooleantrueSpecifies whether colliders on the target object should be disabled.
disableChildCollidersBooleantrueSpecifies whether colliders on the target's children should be disabled.

Events

transform-controls-dragmove

Fires an event when the transform gizmo is being dragged.

NameTypeDescription
behaviorTransformControlsThe behavior that controls the transform gizmo.
parentTHREE.Object3DThe object that the transform gizmo is parented to.
transformTargetTHREE.Object3DThe object that the transform gizmo will manipulate.
transformTypeStringThe type of transform being performed. Possible values are position, rotate and scale.
transformAxisStringThe axis that the transform is being performed on. Possible values are x, y, z (for single axes) and xyz (for all axes).
transformDeltaTHREE.Vector3The transform delta that was applied to the target object.

transform-controls-dragbegin

Fires an event when the transform gizmo starts being dragged.

NameTypeDescription
behaviorTransformControlsThe behavior that controls the transform gizmo.
parentTHREE.Object3DThe object that the transform gizmo is parented to.
transformTargetTHREE.Object3DThe object that the transform gizmo will manipulate.
transformTypeStringThe type of transform being performed. Possible values are position, rotate and scale.
transformAxisStringThe axis that the transform is being performed on. Possible values are x, y, z (for single axes) and xyz (for all axes).

transform-controls-dragend

Fires an event when the transform gizmo is no longer being dragged.

NameTypeDescription
behaviorTransformControlsThe behavior that controls the transform gizmo.
parentTHREE.Object3DThe object that the transform gizmo is parented to.
transformTargetTHREE.Object3DThe object that the transform gizmo will manipulate.
transformTypeStringThe type of transform being performed. Possible values are position, rotate and scale.
transformAxisStringThe axis that the transform is being performed on. Possible values are x, y, z (for single axes) and xyz (for all axes).

altspaceutil.behaviors.OrbitControls (Example)

Provides a convenience wrapper for THREE.OrbitControls when working with altspace.utilities.Simulation.

altspaceutil.behaviors.UserEvents (Example)

Subscribes to avatar and user preference update events for a given list of users, and dispatches events which have been triggered by a given user changing their avatar and/or account preferences.

Parameters

config - Optional parameters.

NameTypeDefaultDescription
userIdsString[]nullAn array of (legacy) User IDs for each user to dispatch events for. When omitted, only avatar change events for the user currently logged in will be handled.
onRequestDataonRequestDatanullA precondition callback returning a boolean that determines if a user should have their data requested. User data is requested if the callback returns true, otherwise no action is taken.
refreshTimeNumber5000Duration to wait between user updates, in milliseconds.
traceBooleanfalseSpecifies whether debugging information should be displayed.

Callbacks

onRequestData

A precondition callback returning a boolean that determines if a user should have their data requested. User data is requested if the callback returns true, otherwise no action is taken.

NameTypeDescription
userIdStringUser ID of a user who will have their data requested.
objectTHREE.Object3DThe object that will emit the request.

Methods

subscribeUser

Subscribe to receiving events for a given User ID.

NameTypeDescription
userIdStringUser ID to receive events for.

unsubscribeUser

Unsubscribe from receiving events for a given User ID.

NameTypeDescription
userIdStringUser ID to stop receiving events for.

Events

avatarchange

Fires an event when the user changes avatar preferences.

NameTypeDescription
userIdStringUser ID of the user.
avatarIdStringAvatar type identifier that was selected by the user.
avatarClassStringAvatar type classification. Typically one of Pod, Robothead or Rubenoid, or empty when unclassified.
colorsObjectTHREE.Color preferences of the avatar. This typically provides primary and highlight properties for Pod avatars, and highlight for Robothead avatars.
rawColorsObjectRaw color preferences of the avatar. This typically provides primary and highlight properties for Pod avatars, and highlight for Robothead avatars.
texturesObjectTexture identifier preferences for the avatar. This typically provides hair, skin and clothing properties for Rubenoid avatars.
targetTHREE.Object3DThe object which emitted the event.

userchange

Fires an event when the user changes account preferences.

NameTypeDescription
userIdStringUser ID of the user.
usernameStringUsername of the user.
displayNameStringDisplay name of the user.
targetTHREE.Object3DThe object which emitted the event.

avatarstatus

Fires an event when the user's connection status changes.

NameTypeDescription
userIdStringUser ID of the user.
displayNameStringDisplay name of the user.
onlineBooleanSpecifies whether user is currently logged in.
targetTHREE.Object3DThe object which emitted the event.

altspaceutil.behaviors.PreloadNativeSounds (Example)

Preloads the specified sound files used by n-sound to ensure the resources are cached for subsequent uses. The behavior will remove itself automatically once the sound files have been preloaded or the specified timeout threshold has been reached.

Parameters

sounds - Native sound resources to be preloaded. Can either be an array of sound file paths or an array of NativeComponent n-sound data objects (e.g. { src: 'file.wav', volume: 1.5 }).

config - Optional parameters.

NameTypeDefaultDescription
disposeBooleantrueSpecifies whether the preloaded native sound objects will be destroyed after the preload has completed. By default, preloaded sound objects will be destroyed after being cached.
timeoutNumber10000Time in milliseconds to wait before ending the preload. A n-sound-preloaded event will be fired with a timeout property set to true when the timeout threshold has been reached. Specifying a zero or negative value will disable the timeout.

Events

n-sound-preloaded

Fires an event once all sounds have been preloaded, or the specified timeout threshold has been reached.

NameTypeDescription
behaviorPreloadNativeSoundsThe behavior that preloaded the sounds.
soundsTHREE.Object3D[]The sound objects that were preloaded. Sound objects are children of the object the behavior is associated with.
timeoutBooleanIndicates whether the timeout threshold has been reached before all sounds were preloaded.

altspaceutil.behaviors.HoverMaterialOpacity (Example)

Changes the opacity of an object's material when the cursor hovers over it, and restores the original opacity when the cursor is no longer hovering over the object.

Parameters

config - Optional parameters.

NameTypeDefaultDescription
materialTHREE.MaterialnullA reference to the material whose opacity will be updated. Defaults to material of the object the behavior is attached to.
opacityNumber1The value that will be applied to the object's current material opacity when the cursor hovers over it.
beginDurationNumber75Duration the hovered opacity adjustment effect is intended to take to complete, in milliseconds.
endDurationNumber75Duration the unhovered opacity adjustment effect is intended to take to complete, in milliseconds.
revertOnDisposeBooleantrueSpecifies whether the object's original material opacity should be restored when the behavior has been destroyed.
eventListenerTHREE.Object3DnullSpecifies an optional object that will listen for cursor events. By default the object that the behavior is attached to will be used as the event listener.
hoverChildrenBooleantrueSpecifies whether hovering over children of the event listener object should invoke the hover effect.

altspaceutil.behaviors.HoverMaterialColor (Example)

Changes the color of an object's material when the cursor hovers over it, and restores the original color when the cursor is no longer hovering over the object.

Parameters

config - Optional parameters.

NameTypeDefaultDescription
materialTHREE.MaterialnullA reference to the material whose color will be updated. Defaults to material of the object the behavior is attached to.
colorTHREE.Colornew THREE.Color('yellow')The value that will be applied to the object's material color when the cursor hovers over it.
beginDurationNumber75Duration the hovered color adjustment effect is intended to take to complete, in milliseconds.
endDurationNumber75Duration the unhovered color adjustment effect is intended to take to complete, in milliseconds.
revertOnDisposeBooleantrueSpecifies whether the object's original material color should be restored when the behavior has been destroyed.
eventListenerTHREE.Object3DnullSpecifies an optional object that will listen for cursor events. By default the object that the behavior is attached to will be used as the event listener.
hoverChildrenBooleantrueSpecifies whether hovering over children of the event listener object should invoke the hover effect.

altspaceutil.behaviors.NativeTextMaterial (Example)

Updates the color and opacity of a n-text native component using a material source.

Parameters

config - Optional parameters.

NameTypeDefaultDescription
materialTHREE.MaterialnullA reference to the material whose properties will be applied to the n-text native component. Defaults to material of the object the behavior is attached to.
colorBooleantrueSpecifies whether the n-text native component should use the color of the source material.
opacityBooleantrueSpecifies whether the n-text native component should use the opacity of the source material.

altspaceutil.behaviors.TWEEN (Example)

Provides a convenience wrapper for tween.js to manage and update TWEEN and TWEEN.Group objects. Refer to the tween.js user guide for further information.

Parameters

NameTypeDefaultDescription
tweengroupTWEEN.GroupTWEENA tween group to be managed by the behavior. When ommitted, the global TWEEN object will be managed by the behavior.

altspaceutil.behaviors.Billboard (Example)

The Billboard behavior updates the orientation of an object to face the camera.

Parameters

NameTypeDefaultDescription
configObjectOptional parameters.
config.targetTHREE.Object3DnullA target that the object should face. If omitted, the scene camera will be used.
config.xBooleantrueSpecifies whether the X-axis of the object should be reoriented to face the camera.
config.yBooleantrueSpecifies whether the Y-axis of the object should be reoriented to face the camera.
config.zBooleantrueSpecifies whether the Z-axis of the object should be reoriented to face the camera.
config.nativeBooleantrueSpecifies whether a native billboard (n-billboard) component will be used when running the app in the Altspace client.

altspaceutil.behaviors.Text (Example)

The Text behavior displays a text string using an SDF font, supporting line breaks, text alignment and inline formatting tags.

e.g. <color=#FFFFFF>The</color> <color="red">quick <#FFFF00>brown <alpha=#33>fox <color=#FFFFFFFF> jumps over the <noparse><alpha=#DD>lazy</noparse> dog.

Supported Tags

  • <color=...>Text</color>
  • <color="name"> - Changes the color of the text using the specified color name. Supported color names are black, blue, green, orange, purple, red, yellow or white.
  • <color=#RRGGBB> <color=#RGB> <color=#RRGGBBAA> <color=#RGBA> <#RRGGBB> <#RGB> <#RRGGBBAA> <#RGBA> - Changes the color and opacity of text using the specified hexidecimal code.
  • <alpha=#AA> - Changes the opacity of any text that follows.
  • <b>Text</b> - Applies a bold effect to the text.
  • <i>Text</i> - Applies an italic effect to the text.
  • <noparse>Text</noparse> - Prevents formatting tags from being parsed.

Parameters

NameTypeDefaultDescription
configObjectOptional parameters.
config.textStringThe text to be displayed.
config.fontSizeNumber10The size of the text.
config.widthNumber10The width of the text block to display before text wrapping occurs.
config.heightNumber1The height offset of the text block.
config.horizontalAlignStringmiddleThe horizontal alignment of the text block.
config.verticalAlignStringmiddleThe vertical alignment of the text block.
config.nativeBooleantrueSpecifies whether a native text (n-text) component will be used when running the app in the Altspace client.

altspaceutil.behaviors.GLTF (Example)

The GLTF behavior loads and displays a glTF model asset.

Parameters

NameTypeDefaultDescription
configObjectOptional parameters.
config.urlStringA URL to the GLTF model file to be loaded.
config.sceneIndexNumber0Specifies the scene to load when the GLTF model contains multiple scenes.
config.nativeBooleantrueSpecifies whether a native glTF (n-gltf) component will be used when running the app in the Altspace client.

Members

NameTypeDescription
loadedBooleanIndicates whether the sound has been loaded.

Methods

getBoundingBox

Retreives the axis aligned bounding box of the loaded glTF model.

Returns

TypeDescription
PromiseResolves to a THREE.Box3 representing an axis aligned bounding box of the loaded glTF model.

Events

gltf-loaded

Fires an event once the glTF model has been loaded.

altspaceutil.behaviors.Sound (Example)

The Sound behavior loads and plays a sound asset supporting positional audio.

Parameters

NameTypeDefaultDescription
configObjectOptional parameters.
config.targetTHREE.Object3DA target that will listen for the sound being played. If omitted, the scene camera will be used.
config.srcStringA URL to the sound file to be loaded.
config.resStringA sound resource identifier to be loaded.
config.onStringName of the event that will trigger the sound to be played.
config.loopBooleanfalseSpecifies whether the sound should loop back to the beginning once playback has finished.
config.autoplayBooleanfalseSpecifies whether the sound will play automatically when the parent object is loaded into the scene.
config.oneshotBooleanfalseSpecifies whether multiple instances of the sound can be played simultaneously. Note that one-shot sounds cannot be paused, stopped or seeked into, and instances will clean themselves up automatically when playback has finished.
config.volumeNumber1Volume that the sound should play at.
config.spatialBlendNumber1Specifies how the sound will be perceived spactially, ranging from 0 (2D stereo without panning between left and right sound channels) up to 1 (localized 3D with panning between left and right sound channels).
config.pitchNumber1The speed and octave adjustment that the sound will play at. 0.5 for half speed at a lower octave, 2 for double speed at a higher octave.
config.minDistanceNumber1The minimum distance that the sound will play at full volume.
config.maxDistanceNumber12The maximum distance that the sound will play before volume reaches silent when a linear/cosine rolloff algorithm is specified, otherwise the volume will stop lowering after the specified distance when a logarithmic rolloff algorithm is specified.
config.rolloffStringlogarithmicVolume can reach a silent level when a linear/cosine rolloff algorithm is specified, otherwise the volume will stop lowering after the specified distance when a logarithmic rolloff algorithm is specified.
config.nativeBooleantrueSpecifies whether a native sound (n-sound) component will be used when running the app in the Altspace client.

Members

NameTypeDescription
loadedBooleanIndicates whether the sound has been loaded.

Methods

play

Begins playback of the sound, and emits a sound-played event.

pause

Pauses playback of the sound at the current position, and emits a sound-paused event.

stop

Stops playback of the sound, and emits a sound-stopped event.

seek

Skips playback to a specific time point in the sound.

Parameters

NameTypeDescription
timeNumberNumber of milliseconds from the beginning of the sound to skip playback to.

Events

sound-loaded

Fires an event once the sound has been loaded.

sound-played

Fires an event when playback of the sound begins.

sound-paused

Fires an event when playback of the sound is paused.

sound-stopped

Fires an event when playback of the sound is stopped.

Classes

FullspaceApp

Manages the render and update loop and creation of anchor points for a three.js app. This class is not intended to be created directly, but should be retrieved using altspaceutil.getFullspaceApp.

Anchor Points

Overview

Anchor points (also referred to as Anchors) are nodes in a scene which can be positioned, rotated and scaled externally by end users using URL parameters passed in when the app is loaded into an enclosure, allowing an app to be customized for any environment layout.

By default, all apps using altspaceutil.getFullspaceApp are provided with a root anchor point which encompasses all objects in the scene. Additional user-defined anchor points which are transformed relative to the root anchor may also be used to split a scene into seperately customizable parts. Scene objects should be attached to either the root anchor point, or a user-defined anchor point obtained from anchors to ensure that apps can be customized by end users as appropriate.

Example Usage

Imagine a concert environment app containing a skybox, a stage for performers and a seating area for an audience, where each part of the scene can be arranged independently of each other.

https://example.com/concertapp/index.html

altspaceutil.getFullspaceApp(app => {
	app.anchor.add(skyboxModel);
	app.anchors('performerstage').add(concertStageModel);
	app.anchors('audiencestand').add(audienceStandModel);
});

https://path/to/manifest.json

{
	"enclosure": {
		"position": { "x": 0, "y": 0, "z": 0 }, "rotation": { "x": 0, "y": 0, "z": 0 }, "scale": { "x": 1, "y": 1, "z": 1 }
	},
	"anchors": [
		{ "name": "performerstage", "position": { "x": 5, "y": 0, "z": -3 }, "rotation": { "x": 0, "y": 0, "z": 0 }, "scale": { "x": 2, "y": 0.5, "z": 3 } },
		{ "name": "audiencestand", "position": { "x": 1, "y": 0, "z": 0 }, "rotation": { "x": 0, "y": 0, "z": 0 }, "scale": { "x": 1, "y": 1, "z": 1 } }
	]
}

Manifest file example: https://example.com/concertapp/index.html?altvr.manifest=https://path/to/manifest.json

Anchors can be customized without a manifest file with URL parameters: https://example.com/concertapp/index.html?altvr.enclosure.position=0,0,0&altvr.enclosure.rotation=0,0,0&altvr.anchors.performerstage.position=5,0,-3&altvr.anchors.performerstage.scale=2,0.5,3&altvr.anchors.audiencestand.position=1,0,0

URL parameters can also be used to override a manifest file: https://example.com/concertapp/index.html?altvr.manifest=https://path/to/manifest.json&altvr.enclosure.scale=0.1&altvr.anchors.performerstage.position=4,0,-2&altvr.anchors.performerstage.scale=1,0.6,4&altvr.anchors.audiencestand.position=2,0,0

Members

NameTypeDescription
sceneTHREE.SceneThe scene associated with the app.
rendererAltRenderer(https://altspacevr.github.
1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago