UNPKG

@vrspace/babylonjs

Version:

vrspace.org babylonjs client

119 lines (118 loc) 3.45 kB
/** * Save and load the scene with this class. * * Addesses existing issues with babylon.js serialization: * 1) technical: gltf serialization doesn't support transparency, json serialization fails with with js errors * 2) generated json files may be huge * 3) intelectual property violation - even with open source models, we must comply with the license * * So we take mixed approach to serialize everything - some custom and some babylon. * Most important is not copying everything, use URL of the model whenever possible. */ export class Sceneshot { /** * Save the world: * - all dynamically loaded assets * - skybox * - ground * - camera(s) * - light(s) * - terrain * - shadow generator * - physics * - portal(s) * TODO: make loading these elements optional. * @return world object */ static serializeWorld(world?: World): Promise<{ name: any; baseUrl: string; file: string; worldObjects: any; objectsFile: any; physics: { gravityEnabled: boolean; physicsPlugin: any; }; portals: {}; avatars: {}; videoAvatars: any[]; meshAvatars: {}; scriptedObjects: any[]; buttons: any[]; }>; /** * Serialize the world as json, and save the file. * Calls serializeWorld, then VRSPACEUI.saveFile. * @param {World} world */ static saveJson(world: World): Promise<void>; /** * Serialize the world as json, generate html that creates the scene and loads json, and save the html file. * Calls serializeWorld, then VRSPACEUI.saveFile. * @param {World} world */ static saveHtml(world: World): Promise<void>; /** * Internal * @private */ private static loadComponent; /** * Internal * @private */ private static loadMesh; /** * Internal * @private */ private static loadAvatar; /** * Internal * @private */ private static loadAsset; /** * Internal * @private */ private static loadAssets; /** * Load a world from a json file: fetch the file and call loadWorld * @param engine babylon.js engine created elsewhere * @param file file name, defaults to scene.json */ static loadFile(engine: any, file?: string): Promise<World>; /** * Load a world from a json string: parse the string and call loadWorld * @param engine babylon.js engine created elsewhere * @param text json source */ static loadString(engine: any, text: any): Promise<World>; /** * Load the world. * Creates new World object, and the Scene then loads * - sky box * - ground * - cameras * - lights * - shadow generator * - scene meshes * - button groups * - logo room (that's only for avatar selection) * - terrain * - portals * - general VRObjects (e.g. created by world editor) * - humanoid avatars * - mesh avatars * - video avatars (without video obviously) * - scripted objects * So everything except HUD and forms. * TODO: make loading these elements optional. * @param engine babylon.js engine * @param worldInfo serialized world object */ static loadWorld(engine: any, worldInfo: any): Promise<World>; } import { World } from './world.js';