@vrspace/babylonjs
Version:
vrspace.org babylonjs client
243 lines (242 loc) • 8.93 kB
TypeScript
/**
Main UI class, provides utility methods and basic UI elements.
@class
*/
export class VRSpaceUI {
static instance: any;
/** babylon scene*/
scene: any;
/** content base (prefix), default empty (same host) */
contentBase: string;
/** Path to logo, null defaults to contentBase+/babylon (vrspace.org logo)*/
logoPath: any;
/** Logo file name, defaults to logo.glb */
logoFile: string;
/** vrspace.org logo mesh */
logo: any;
/** Path to logo, null defaults to contentBase+/babylon/portal */
portalPath: any;
/** Portal file name, defaults to scene.gltf */
portalFile: string;
/** portal mesh */
portal: any;
/** debug output enabled */
debug: boolean;
/** frames per second */
fps: number;
/** Pointer to function, defaults to this.loadProgressIndiciatorFactory */
loadProgressIndicator: (scene: any, camera: any) => Promise<LoadProgressIndicator>;
/** Head-up display
* @type {HUD}
*/
hud: HUD;
selectables: any[];
/** babylon GUI manager - multiple instances may cause issues with transparency */
guiManager: any;
/** Script loader */
scriptLoader: ScriptLoader;
/** VR availability */
canVR: any;
/** AR availability */
canAR: any;
/** @private */
private indicator;
/** @private */
private initialized;
/** @private */
private optimizingScene;
/** reference to VRSpace singleton */
VRSPACE: import("../client/vrspace.js").VRSpace;
/** reference to AssetLoader singleton */
assetLoader: AssetLoader;
/** UI Material, created from init, defaults to color 0.2,0.2,0.3, with 0.7 alpha */
uiMaterial: any;
/**
* Creates asset loader, preloads vrspace.org logo and portal for later use.
@param scene babylon.js scene to operate with.
*/
init(scene: any): Promise<this>;
/** Used in init, return logPath if exists, or default path to vrspace.org logo */
logoDir(): any;
/** Returns portalPath if exists, defaults to contentBase+/babylon/portal */
portalDir(): any;
/** Creates default LoadProgressIndicator bound to given camera, if one does not already exist.
@param scene
@param camera
@returns load progress indicator
*/
loadProgressIndicatorFactory(scene: any, camera: any): Promise<LoadProgressIndicator>;
/** Logs to js console if debug is enabled
@param something to log
*/
log(something: any): void;
/** loads the portal
@param scene
*/
loadPortal(scene: any): Promise<any>;
/**
lists files on a server directory
@param theUrl url to load from
@param callback to call load, passing it XMLHttpRequest
*/
listFiles(theUrl: any, callback: any): XMLHttpRequest;
/**
lists files on a server directory
@param theUrl url to load from
@returns Promise with XMLHttpRequest
*/
listFilesAsync(theUrl: any): Promise<any>;
/** list folders with their jpg thumbnails (files ending with .jpg)
@param dir directory to list
@param callback to call
*/
listThumbnails(dir: any, callback: any): void;
/** list character folders and their fix files
@param dir directory to list
@param callback to call
*/
listCharacters(dir: any, callback: any): void;
/** list character folders and their fix files
@param dir directory to list
*/
listCharactersAsync(dir: any): Promise<ServerFolder[]>;
/**
List files in a server folder
@param dir directory to list
@param callback receives string array with urls
@param suffix optional suffix of listed files
*/
listDirectory(dir: any, callback: any, suffix: any): XMLHttpRequest;
/**
list server folders along with their matching files
i.e. files with the same name, plus given suffix
@param dir directory to list
@param callback to call, receives ServerFolder array as argument
@param suffix of related file
*/
listMatchingFiles(dir: any, callback: any, suffix: any): XMLHttpRequest;
/**
list server folders along with their matching files
i.e. files with the same name, plus given suffix
@param dir directory to list
@param suffix of related file
@returns Promise with ServerFolder array
*/
listMatchingFilesAsync(dir: any, suffix: any): Promise<ServerFolder[]>;
/**
Utility method, should a node and its children receive shadows.
@param node a babylonjs node
@param shadows true ofr false
*/
receiveShadows(node: any, shadows: any): void;
/**
Utility method to instantiate if possible, or otherwise clone a mesh, including all children recursivelly.
Both instance and clone use the same material, but only the clone has own lightning effects (e.g. shadows, environment).
@param mesh to instantiate/clone
@param parent optional, copy will have this parent
@param replaceParent optional
@returns copied mesh
*/
copyMesh(mesh: any, parent: any, replaceParent: any): any;
/**
Utility method - create x,y,z animation of a mesh field.
@param mesh to animate
@param field name of field to animate, e.g. "position" or "rotation"
@param fps frames per second, defaults to fps field value
@returns babylonjs AnimationGroup
*/
createAnimation(mesh: any, field: any, fps: any): any;
_appendAnimation(group: any, from: any, to: any): void;
/**
Utility method - update x,y,z animation of a mesh field.
Add the animation to be played after the current animation ends.
@param group AnimationGroup to update
@param node Babylonjs node to animate
@param {string} field node field to animate, e.g. position or rotation
@param to Vector3
*/
chainAnimation(group: any, node: any, field: string, to: any): void;
/**
Utility method - update x,y,z animation of a mesh field.
If the animation group is playing, it is stopped first (may result in jumpy animation).
After the update, starts to play, not looping.
@param group AnimationGroup to update
@param from Vector3
@param to Vector3
*/
updateAnimation(group: any, from: any, to: any): void;
/**
Utility method - create quaternion animation of a mesh field
@param mesh to animate
@param field name of field to animate, e.g. "rotationQuaternion"
@param fps frames per second, defaults to fps field value
@returns babylonjs AnimationGroup
*/
createQuaternionAnimation(mesh: any, field: any, fps: any): any;
/**
Utility method - update quaternion animation of a mesh field around Y axis.
@param group AnimationGroup to update
@param from Vector3
@param to Vector3
*/
updateQuaternionAnimationFromVec(group: any, from: any, to: any): void;
/**
Utility method - update quaternion animation of a mesh field around Y axis.
@param group AnimationGroup to update
@param from Quaternion
@param to Quaternion
*/
updateQuaternionAnimation(group: any, from: any, to: any): void;
/** Optimize the scene for better frame rate */
optimizeScene(scene: any): void;
/**
Utility method - returns the top parent node in hierarchy
*/
findRootNode(mesh: any): any;
/**
Utility method to save a file with given name and file content.
@param filename to save
@param content of the file, typically some JSON string
*/
saveFile(filename: any, content: any): void;
/**
* Save the entire scene as a GLB file.
* @param fileName defaults to "scene"
*/
saveSceneGlb(fileName?: string): void;
/**
* Save the entire scene as GLTF: fileName.gltf, fileName.bin, textures, etc.
* @param fileName defaults to "scene"
*/
saveSceneGltf(fileName?: string): void;
/**
* Save scene as babylon json file. This only works for very simple scenes,
* and is likely to fail for any vrspace world with TypeError: cyclic object value.
* Furthermore, it does not save instances.
* @param fileName defaults to "scene.babylon"
*/
saveSceneBabylon(fileName?: string): void;
hasTouchScreen(): boolean;
/**
* Add a selectable Form, Area, etc - something that may be interacted with in XR.
* It must have isSelectableMesh(mesh) method.
*/
addSelectable(item: any): void;
/**
* Remove a selectable element.
*/
removeSelectable(item: any): void;
/**
* Returns for a mesh that belongs to a selectable UI element.
*/
isSelectableMesh(mesh: any): boolean;
}
/**
* @type {VRSpaceUI}
*/
export let VRSPACEUI: VRSpaceUI;
import { LoadProgressIndicator } from './load-progress-indicator.js';
import { HUD } from './hud.js';
import { ScriptLoader } from '../client/script-loader.js';
import { AssetLoader } from '../core/asset-loader.js';
import { ServerFolder } from '../core/server-folder.js';