@babylonjs/viewer 6.38.1 → 6.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configuration/mappers.d.ts +1 -0
- package/configuration/mappers.js +2 -0
- package/configuration/mappers.js.map +1 -1
- package/configuration/types/index.d.ts +1 -0
- package/configuration/types/index.js +1 -0
- package/configuration/types/index.js.map +1 -1
- package/helper/index.d.ts +3 -0
- package/helper/index.js +3 -0
- package/helper/index.js.map +1 -1
- package/loader/modelLoader.d.ts +8 -0
- package/loader/modelLoader.js +8 -0
- package/loader/modelLoader.js.map +1 -1
- package/loader/plugins/index.d.ts +1 -0
- package/loader/plugins/index.js +1 -0
- package/loader/plugins/index.js.map +1 -1
- package/managers/sceneManager.d.ts +2 -1
- package/managers/sceneManager.js +2 -1
- package/managers/sceneManager.js.map +1 -1
- package/model/viewerModel.d.ts +4 -0
- package/model/viewerModel.js +4 -0
- package/model/viewerModel.js.map +1 -1
- package/optimizer/custom/extended.d.ts +2 -0
- package/optimizer/custom/extended.js +2 -0
- package/optimizer/custom/extended.js.map +1 -1
- package/optimizer/custom/index.d.ts +1 -0
- package/optimizer/custom/index.js +1 -0
- package/optimizer/custom/index.js.map +1 -1
- package/package.json +5 -5
- package/templating/templateManager.d.ts +8 -1
- package/templating/templateManager.js +8 -1
- package/templating/templateManager.js.map +1 -1
- package/viewer/defaultViewer.d.ts +8 -0
- package/viewer/defaultViewer.js +33 -11
- package/viewer/defaultViewer.js.map +1 -1
- package/viewer/viewer.d.ts +4 -1
- package/viewer/viewer.js +4 -1
- package/viewer/viewer.js.map +1 -1
- package/viewer/viewerManager.d.ts +3 -0
- package/viewer/viewerManager.js +3 -0
- package/viewer/viewerManager.js.map +1 -1
package/configuration/mappers.js
CHANGED
|
@@ -24,6 +24,7 @@ var HTMLMapper = /** @class */ (function () {
|
|
|
24
24
|
/**
|
|
25
25
|
* Map a specific element and get configuration from it
|
|
26
26
|
* @param element the HTML element to analyze.
|
|
27
|
+
* @returns a ViewerConfiguration object from the provided HTML Element
|
|
27
28
|
*/
|
|
28
29
|
HTMLMapper.prototype.map = function (element) {
|
|
29
30
|
var config = {};
|
|
@@ -153,6 +154,7 @@ export var MapperManager = /** @class */ (function () {
|
|
|
153
154
|
* Get a specific configuration mapper.
|
|
154
155
|
*
|
|
155
156
|
* @param type the name of the mapper to load
|
|
157
|
+
* @returns the mapper
|
|
156
158
|
*/
|
|
157
159
|
MapperManager.prototype.getMapper = function (type) {
|
|
158
160
|
if (!this._mappers[type]) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mappers.js","sourceRoot":"","sources":["../../../../tools/viewer/src/configuration/mappers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAGxC,sDAAsD;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAS/C;;;;;;;;;;;;;;;;GAgBG;AACH;IAAA;IA8CA,CAAC;IA7CG;;;OAGG;IACH,wBAAG,GAAH,UAAI,OAAoB;QACpB,IAAM,MAAM,GAAG,EAAE,CAAC;gCACT,OAAO;YACZ,IAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC9C,IAAI,CAAC,IAAI,EAAE;;aAEV;YACD,0DAA0D;YAC1D,IAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACvC,KAAK,CAAC,MAAM,CAAC,UAAC,aAAqC,EAAE,GAAG,EAAE,GAAG;gBACzD,kCAAkC;gBAClC,IAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;gBACnC,IAAI,GAAG,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;oBAC1B,IAAI,GAAG,GAAQ,IAAK,CAAC,SAAS,CAAC,CAAC,6EAA6E;oBAC7G,IAAI,GAAG,KAAK,MAAM,EAAE;wBAChB,G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configuration\";\r\n\r\n// eslint-disable-next-line import/no-internal-modules\r\nimport { kebabToCamel } from \"../helper/index\";\r\n\r\n/**\r\n * This is the mapper's interface. Implement this function to create your own mapper and register it at the mapper manager\r\n */\r\nexport interface IMapper {\r\n map(rawSource: any): ViewerConfiguration;\r\n}\r\n\r\n/**\r\n * This is a simple HTML mapper.\r\n * This mapper parses a single HTML element and returns the configuration from its attributes.\r\n * it parses numbers and boolean values to the corresponding variable types.\r\n * The following HTML element:\r\n * <div test=\"1\" random-flag=\"true\" a.string.object=\"test\"> will result in the following configuration:\r\n *\r\n * {\r\n * test: 1, //a number!\r\n * randomFlag: boolean, //camelCase and boolean\r\n * a: {\r\n * string: {\r\n * object: \"test\" //dot-separated object levels\r\n * }\r\n * }\r\n * }\r\n */\r\nclass HTMLMapper implements IMapper {\r\n /**\r\n * Map a specific element and get configuration from it\r\n * @param element the HTML element to analyze.\r\n */\r\n map(element: HTMLElement): ViewerConfiguration {\r\n const config = {};\r\n for (let attrIdx = 0; attrIdx < element.attributes.length; ++attrIdx) {\r\n const attr = element.attributes.item(attrIdx);\r\n if (!attr) {\r\n continue;\r\n }\r\n // map \"object.property\" to the right configuration place.\r\n const split = attr.nodeName.split(\".\");\r\n split.reduce((currentConfig: { [key: string]: any }, key, idx) => {\r\n //convert html-style to json-style\r\n const camelKey = kebabToCamel(key);\r\n if (idx === split.length - 1) {\r\n let val: any = attr!.nodeValue; // firefox warns nodeValue is deprecated, but I found no sign of it anywhere.\r\n if (val === \"true\") {\r\n val = true;\r\n } else if (val === \"false\") {\r\n val = false;\r\n } else if (val === \"undefined\") {\r\n val = undefined;\r\n } else if (val === \"null\") {\r\n val = null;\r\n } else {\r\n const isnum = !isNaN(parseFloat(val)) && isFinite(val); ///^\\d+$/.test(val);\r\n if (isnum) {\r\n const number = parseFloat(val);\r\n if (!isNaN(number)) {\r\n val = number;\r\n }\r\n }\r\n }\r\n currentConfig[camelKey] = val;\r\n } else {\r\n currentConfig[camelKey] = currentConfig[camelKey] || {};\r\n }\r\n return currentConfig[camelKey];\r\n }, config);\r\n }\r\n\r\n return config;\r\n }\r\n}\r\n\r\n/**\r\n * A simple string-to-JSON mapper.\r\n * This is the main mapper, used to analyze downloaded JSON-Configuration or JSON payload\r\n */\r\nclass JSONMapper implements IMapper {\r\n map(rawSource: string) {\r\n return JSON.parse(rawSource);\r\n }\r\n}\r\n\r\n/**\r\n * The DOM Mapper will traverse an entire DOM Tree and will load the configuration from the\r\n * DOM elements and attributes.\r\n */\r\nclass DOMMapper implements IMapper {\r\n /**\r\n * The mapping function that will convert HTML data to a viewer configuration object\r\n * @param baseElement the baseElement from which to start traversing\r\n * @returns a ViewerConfiguration object from the provided HTML Element\r\n */\r\n map(baseElement: HTMLElement): ViewerConfiguration {\r\n const htmlMapper = new HTMLMapper();\r\n const config = htmlMapper.map(baseElement);\r\n\r\n const traverseChildren = function (element: HTMLElement, partConfig: any) {\r\n const children = element.children;\r\n if (children.length) {\r\n for (let i = 0; i < children.length; ++i) {\r\n const item = <HTMLElement>children.item(i);\r\n // use the HTML Mapper to read configuration from a single element\r\n const configMapped = htmlMapper.map(item);\r\n const key = kebabToCamel(item.nodeName.toLowerCase());\r\n if (item.attributes.getNamedItem(\"array\") && item.attributes.getNamedItem(\"array\")!.nodeValue === \"true\") {\r\n partConfig[key] = [];\r\n } else {\r\n if (element.attributes.getNamedItem(\"array\") && element.attributes.getNamedItem(\"array\")!.nodeValue === \"true\") {\r\n partConfig.push(configMapped);\r\n } else if (partConfig[key]) {\r\n //exists already! probably an array\r\n element.setAttribute(\"array\", \"true\");\r\n const oldItem = partConfig[key];\r\n partConfig = [oldItem, configMapped];\r\n } else {\r\n partConfig[key] = configMapped;\r\n }\r\n }\r\n traverseChildren(item, partConfig[key] || configMapped);\r\n }\r\n }\r\n return partConfig;\r\n };\r\n\r\n traverseChildren(baseElement, config);\r\n\r\n return config;\r\n }\r\n}\r\n\r\n/**\r\n * The MapperManager manages the different implemented mappers.\r\n * It allows the user to register new mappers as well and use them to parse their own configuration data\r\n */\r\nexport class MapperManager {\r\n private _mappers: { [key: string]: IMapper };\r\n /**\r\n * The default mapper is the JSON mapper.\r\n */\r\n public static DefaultMapper = \"json\";\r\n\r\n constructor() {\r\n this._mappers = {\r\n html: new HTMLMapper(),\r\n json: new JSONMapper(),\r\n dom: new DOMMapper(),\r\n };\r\n }\r\n\r\n /**\r\n * Get a specific configuration mapper.\r\n *\r\n * @param type the name of the mapper to load\r\n */\r\n public getMapper(type: string) {\r\n if (!this._mappers[type]) {\r\n Tools.Error(\"No mapper defined for \" + type);\r\n }\r\n return this._mappers[type];\r\n }\r\n\r\n /**\r\n * Use this function to register your own configuration mapper.\r\n * After a mapper is registered, it can be used to parse the specific type fo configuration to the standard ViewerConfiguration.\r\n * @param type the name of the mapper. This will be used to define the configuration type and/or to get the mapper\r\n * @param mapper The implemented mapper\r\n */\r\n public registerMapper(type: string, mapper: IMapper) {\r\n this._mappers[type] = mapper;\r\n }\r\n\r\n /**\r\n * Dispose the mapper manager and all of its mappers.\r\n */\r\n public dispose() {\r\n this._mappers = {};\r\n }\r\n}\r\n\r\n/**\r\n * mapperManager is a singleton of the type MapperManager.\r\n * The mapperManager can be disposed directly with calling mapperManager.dispose()\r\n * or indirectly with using BabylonViewer.disposeAll()\r\n */\r\nexport const mapperManager = new MapperManager();\r\n"]}
|
|
1
|
+
{"version":3,"file":"mappers.js","sourceRoot":"","sources":["../../../../tools/viewer/src/configuration/mappers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAGxC,sDAAsD;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAS/C;;;;;;;;;;;;;;;;GAgBG;AACH;IAAA;IA+CA,CAAC;IA9CG;;;;OAIG;IACH,wBAAG,GAAH,UAAI,OAAoB;QACpB,IAAM,MAAM,GAAG,EAAE,CAAC;gCACT,OAAO;YACZ,IAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,IAA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AAQ,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACI,sCAAc,GAArB,UAAsB,IAAY,EAAE,MAAe;QAC/C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,+BAAO,GAAd;QACI,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACvB,CAAC;IAzCD;;OAEG;IACW,2BAAa,GAAG,MAAM,CAAC;IAuCzC,oBAAC;CAAA,AA5CD,IA4CC;AAED;;;;GAIG;AACH,MAAM,CAAC,IAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC","sourcesContent":["import { Tools } from \"core/Misc/tools\";\r\nimport type { ViewerConfiguration } from \"./configuration\";\r\n\r\n// eslint-disable-next-line import/no-internal-modules\r\nimport { kebabToCamel } from \"../helper/index\";\r\n\r\n/**\r\n * This is the mapper's interface. Implement this function to create your own mapper and register it at the mapper manager\r\n */\r\nexport interface IMapper {\r\n map(rawSource: any): ViewerConfiguration;\r\n}\r\n\r\n/**\r\n * This is a simple HTML mapper.\r\n * This mapper parses a single HTML element and returns the configuration from its attributes.\r\n * it parses numbers and boolean values to the corresponding variable types.\r\n * The following HTML element:\r\n * <div test=\"1\" random-flag=\"true\" a.string.object=\"test\"> will result in the following configuration:\r\n *\r\n * {\r\n * test: 1, //a number!\r\n * randomFlag: boolean, //camelCase and boolean\r\n * a: {\r\n * string: {\r\n * object: \"test\" //dot-separated object levels\r\n * }\r\n * }\r\n * }\r\n */\r\nclass HTMLMapper implements IMapper {\r\n /**\r\n * Map a specific element and get configuration from it\r\n * @param element the HTML element to analyze.\r\n * @returns a ViewerConfiguration object from the provided HTML Element\r\n */\r\n map(element: HTMLElement): ViewerConfiguration {\r\n const config = {};\r\n for (let attrIdx = 0; attrIdx < element.attributes.length; ++attrIdx) {\r\n const attr = element.attributes.item(attrIdx);\r\n if (!attr) {\r\n continue;\r\n }\r\n // map \"object.property\" to the right configuration place.\r\n const split = attr.nodeName.split(\".\");\r\n split.reduce((currentConfig: { [key: string]: any }, key, idx) => {\r\n //convert html-style to json-style\r\n const camelKey = kebabToCamel(key);\r\n if (idx === split.length - 1) {\r\n let val: any = attr!.nodeValue; // firefox warns nodeValue is deprecated, but I found no sign of it anywhere.\r\n if (val === \"true\") {\r\n val = true;\r\n } else if (val === \"false\") {\r\n val = false;\r\n } else if (val === \"undefined\") {\r\n val = undefined;\r\n } else if (val === \"null\") {\r\n val = null;\r\n } else {\r\n const isnum = !isNaN(parseFloat(val)) && isFinite(val); ///^\\d+$/.test(val);\r\n if (isnum) {\r\n const number = parseFloat(val);\r\n if (!isNaN(number)) {\r\n val = number;\r\n }\r\n }\r\n }\r\n currentConfig[camelKey] = val;\r\n } else {\r\n currentConfig[camelKey] = currentConfig[camelKey] || {};\r\n }\r\n return currentConfig[camelKey];\r\n }, config);\r\n }\r\n\r\n return config;\r\n }\r\n}\r\n\r\n/**\r\n * A simple string-to-JSON mapper.\r\n * This is the main mapper, used to analyze downloaded JSON-Configuration or JSON payload\r\n */\r\nclass JSONMapper implements IMapper {\r\n map(rawSource: string) {\r\n return JSON.parse(rawSource);\r\n }\r\n}\r\n\r\n/**\r\n * The DOM Mapper will traverse an entire DOM Tree and will load the configuration from the\r\n * DOM elements and attributes.\r\n */\r\nclass DOMMapper implements IMapper {\r\n /**\r\n * The mapping function that will convert HTML data to a viewer configuration object\r\n * @param baseElement the baseElement from which to start traversing\r\n * @returns a ViewerConfiguration object from the provided HTML Element\r\n */\r\n map(baseElement: HTMLElement): ViewerConfiguration {\r\n const htmlMapper = new HTMLMapper();\r\n const config = htmlMapper.map(baseElement);\r\n\r\n const traverseChildren = function (element: HTMLElement, partConfig: any) {\r\n const children = element.children;\r\n if (children.length) {\r\n for (let i = 0; i < children.length; ++i) {\r\n const item = <HTMLElement>children.item(i);\r\n // use the HTML Mapper to read configuration from a single element\r\n const configMapped = htmlMapper.map(item);\r\n const key = kebabToCamel(item.nodeName.toLowerCase());\r\n if (item.attributes.getNamedItem(\"array\") && item.attributes.getNamedItem(\"array\")!.nodeValue === \"true\") {\r\n partConfig[key] = [];\r\n } else {\r\n if (element.attributes.getNamedItem(\"array\") && element.attributes.getNamedItem(\"array\")!.nodeValue === \"true\") {\r\n partConfig.push(configMapped);\r\n } else if (partConfig[key]) {\r\n //exists already! probably an array\r\n element.setAttribute(\"array\", \"true\");\r\n const oldItem = partConfig[key];\r\n partConfig = [oldItem, configMapped];\r\n } else {\r\n partConfig[key] = configMapped;\r\n }\r\n }\r\n traverseChildren(item, partConfig[key] || configMapped);\r\n }\r\n }\r\n return partConfig;\r\n };\r\n\r\n traverseChildren(baseElement, config);\r\n\r\n return config;\r\n }\r\n}\r\n\r\n/**\r\n * The MapperManager manages the different implemented mappers.\r\n * It allows the user to register new mappers as well and use them to parse their own configuration data\r\n */\r\nexport class MapperManager {\r\n private _mappers: { [key: string]: IMapper };\r\n /**\r\n * The default mapper is the JSON mapper.\r\n */\r\n public static DefaultMapper = \"json\";\r\n\r\n constructor() {\r\n this._mappers = {\r\n html: new HTMLMapper(),\r\n json: new JSONMapper(),\r\n dom: new DOMMapper(),\r\n };\r\n }\r\n\r\n /**\r\n * Get a specific configuration mapper.\r\n *\r\n * @param type the name of the mapper to load\r\n * @returns the mapper\r\n */\r\n public getMapper(type: string) {\r\n if (!this._mappers[type]) {\r\n Tools.Error(\"No mapper defined for \" + type);\r\n }\r\n return this._mappers[type];\r\n }\r\n\r\n /**\r\n * Use this function to register your own configuration mapper.\r\n * After a mapper is registered, it can be used to parse the specific type fo configuration to the standard ViewerConfiguration.\r\n * @param type the name of the mapper. This will be used to define the configuration type and/or to get the mapper\r\n * @param mapper The implemented mapper\r\n */\r\n public registerMapper(type: string, mapper: IMapper) {\r\n this._mappers[type] = mapper;\r\n }\r\n\r\n /**\r\n * Dispose the mapper manager and all of its mappers.\r\n */\r\n public dispose() {\r\n this._mappers = {};\r\n }\r\n}\r\n\r\n/**\r\n * mapperManager is a singleton of the type MapperManager.\r\n * The mapperManager can be disposed directly with calling mapperManager.dispose()\r\n * or indirectly with using BabylonViewer.disposeAll()\r\n */\r\nexport const mapperManager = new MapperManager();\r\n"]}
|
|
@@ -8,6 +8,7 @@ import type { ViewerConfiguration } from "../configuration";
|
|
|
8
8
|
* "default, environmentMap" will first load the default configuration and will extend it using the environmentMap configuration.
|
|
9
9
|
*
|
|
10
10
|
* @param types a comma-separated string of the type(s) or configuration to load.
|
|
11
|
+
* @returns the configuration object
|
|
11
12
|
*/
|
|
12
13
|
declare const getConfigurationType: (types: string) => ViewerConfiguration;
|
|
13
14
|
export { getConfigurationType, defaultConfiguration, minimalConfiguration };
|
|
@@ -12,6 +12,7 @@ import { deepmerge } from "../../helper/index.js";
|
|
|
12
12
|
* "default, environmentMap" will first load the default configuration and will extend it using the environmentMap configuration.
|
|
13
13
|
*
|
|
14
14
|
* @param types a comma-separated string of the type(s) or configuration to load.
|
|
15
|
+
* @returns the configuration object
|
|
15
16
|
*/
|
|
16
17
|
var getConfigurationType = function (types) {
|
|
17
18
|
var config = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../tools/viewer/src/configuration/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EAAE,mCAAmC,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAC;AACnG,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAC/D,sDAAsD;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../tools/viewer/src/configuration/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oB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SAAS,CAAC,MAAM,EAAE,oBAAoB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;SACpE;IACL,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["import { minimalConfiguration } from \"./minimal\";\r\nimport { defaultConfiguration } from \"./default\";\r\nimport { extendedConfiguration } from \"./extended\";\r\nimport type { ViewerConfiguration } from \"../configuration\";\r\nimport { shadowDirectionalLightConfiguration, shadowSpotlLightConfiguration } from \"./shadowLight\";\r\nimport { environmentMapConfiguration } from \"./environmentMap\";\r\n// eslint-disable-next-line import/no-internal-modules\r\nimport { deepmerge } from \"../../helper/index\";\r\n\r\n/**\r\n * Get the configuration type you need to use as the base for your viewer.\r\n * The types can either be a single string, or comma separated types that will extend each other. for example:\r\n *\r\n * \"default, environmentMap\" will first load the default configuration and will extend it using the environmentMap configuration.\r\n *\r\n * @param types a comma-separated string of the type(s) or configuration to load.\r\n * @returns the configuration object\r\n */\r\nconst getConfigurationType = function (types: string): ViewerConfiguration {\r\n let config: ViewerConfiguration = {};\r\n const typesSeparated = types.split(\",\");\r\n typesSeparated.forEach((type) => {\r\n switch (type.trim()) {\r\n case \"environmentMap\":\r\n config = deepmerge(config, environmentMapConfiguration);\r\n break;\r\n case \"shadowDirectionalLight\":\r\n config = deepmerge(config, shadowDirectionalLightConfiguration);\r\n break;\r\n case \"shadowSpotLight\":\r\n config = deepmerge(config, shadowSpotlLightConfiguration);\r\n break;\r\n case \"default\":\r\n config = deepmerge(config, defaultConfiguration);\r\n break;\r\n case \"minimal\":\r\n config = deepmerge(config, minimalConfiguration);\r\n break;\r\n case \"none\":\r\n break;\r\n case \"extended\":\r\n default:\r\n config = deepmerge(config, extendedConfiguration);\r\n break;\r\n }\r\n\r\n if (config.extends) {\r\n config = deepmerge(config, getConfigurationType(config.extends));\r\n }\r\n });\r\n return config;\r\n};\r\n\r\nexport { getConfigurationType, defaultConfiguration, minimalConfiguration };\r\n"]}
|
package/helper/index.d.ts
CHANGED
|
@@ -4,16 +4,19 @@ export { expDm as deepmerge };
|
|
|
4
4
|
* Is the provided string a URL?
|
|
5
5
|
*
|
|
6
6
|
* @param urlToCheck the url to inspect
|
|
7
|
+
* @returns true if the string is a URL
|
|
7
8
|
*/
|
|
8
9
|
export declare function isUrl(urlToCheck: string): boolean;
|
|
9
10
|
/**
|
|
10
11
|
* Convert a string from kebab-case to camelCase
|
|
11
12
|
* @param s string to convert
|
|
13
|
+
* @returns the converted string
|
|
12
14
|
*/
|
|
13
15
|
export declare function kebabToCamel(s: string): string;
|
|
14
16
|
/**
|
|
15
17
|
* Convert a string from camelCase to kebab-case
|
|
16
18
|
* @param str string to convert
|
|
19
|
+
* @returns the converted string
|
|
17
20
|
*/
|
|
18
21
|
export declare function camelToKebab(str: string): string | null;
|
|
19
22
|
/**
|
package/helper/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { expDm as deepmerge };
|
|
|
5
5
|
* Is the provided string a URL?
|
|
6
6
|
*
|
|
7
7
|
* @param urlToCheck the url to inspect
|
|
8
|
+
* @returns true if the string is a URL
|
|
8
9
|
*/
|
|
9
10
|
export function isUrl(urlToCheck) {
|
|
10
11
|
if (urlToCheck.indexOf("http") === 0 || urlToCheck.indexOf("/") === 0 || urlToCheck.indexOf("./") === 0 || urlToCheck.indexOf("../") === 0) {
|
|
@@ -15,6 +16,7 @@ export function isUrl(urlToCheck) {
|
|
|
15
16
|
/**
|
|
16
17
|
* Convert a string from kebab-case to camelCase
|
|
17
18
|
* @param s string to convert
|
|
19
|
+
* @returns the converted string
|
|
18
20
|
*/
|
|
19
21
|
export function kebabToCamel(s) {
|
|
20
22
|
return s.replace(/(-\w)/g, function (m) {
|
|
@@ -25,6 +27,7 @@ export function kebabToCamel(s) {
|
|
|
25
27
|
/**
|
|
26
28
|
* Convert a string from camelCase to kebab-case
|
|
27
29
|
* @param str string to convert
|
|
30
|
+
* @returns the converted string
|
|
28
31
|
*/
|
|
29
32
|
export function camelToKebab(str) {
|
|
30
33
|
return !str
|
package/helper/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../tools/viewer/src/helper/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAEvC,IAAM,KAAK,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;AACnC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,CAAC;AAE9B
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../tools/viewer/src/helper/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAEvC,IAAM,KAAK,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;AACnC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,UAAkB;IACpC,IAAI,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QACxI,OAAO,IAAI,CAAC;KACf;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,CAAS;IAClC,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC;QAClC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;AACP,CAAC;AAED,uDAAuD;AACvD;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACpC,OAAO,CAAC,GAAG;QACP,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC;YAC/B,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACpC,CAAC,CAAC,CAAC;AACb,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAW,EAAE,MAAW;IAC1D,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QACvC,OAAO;KACV;IACD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAU,GAAG;QACrC,IAAI,GAAG,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,UAAU,EAAE;YACpD,iDAAiD;YACjD,oEAAoE;YACpE,6GAA6G;YAC7G,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,CAAC,EAAE;gBAC9F,qBAAqB,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;aACnD;iBAAM;gBACH,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE;oBAC3B,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;iBAC7B;aACJ;SACJ;IACL,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import * as deepmerge from \"deepmerge\";\r\n\r\nconst expDm = deepmerge[\"default\"];\r\nexport { expDm as deepmerge };\r\n\r\n/**\r\n * Is the provided string a URL?\r\n *\r\n * @param urlToCheck the url to inspect\r\n * @returns true if the string is a URL\r\n */\r\nexport function isUrl(urlToCheck: string): boolean {\r\n if (urlToCheck.indexOf(\"http\") === 0 || urlToCheck.indexOf(\"/\") === 0 || urlToCheck.indexOf(\"./\") === 0 || urlToCheck.indexOf(\"../\") === 0) {\r\n return true;\r\n }\r\n return false;\r\n}\r\n\r\n/**\r\n * Convert a string from kebab-case to camelCase\r\n * @param s string to convert\r\n * @returns the converted string\r\n */\r\nexport function kebabToCamel(s: string) {\r\n return s.replace(/(-\\w)/g, function (m) {\r\n return m[1].toUpperCase();\r\n });\r\n}\r\n\r\n//https://gist.github.com/youssman/745578062609e8acac9f\r\n/**\r\n * Convert a string from camelCase to kebab-case\r\n * @param str string to convert\r\n * @returns the converted string\r\n */\r\nexport function camelToKebab(str: string) {\r\n return !str\r\n ? null\r\n : str.replace(/([A-Z])/g, function (g) {\r\n return \"-\" + g[0].toLowerCase();\r\n });\r\n}\r\n\r\n/**\r\n * This will extend an object with configuration values.\r\n * What it practically does it take the keys from the configuration and set them on the object.\r\n * If the configuration is a tree, it will traverse into the tree.\r\n * @param object the object to extend\r\n * @param config the configuration object that will extend the object\r\n */\r\nexport function extendClassWithConfig(object: any, config: any) {\r\n if (!config || typeof config !== \"object\") {\r\n return;\r\n }\r\n Object.keys(config).forEach(function (key) {\r\n if (key in object && typeof object[key] !== \"function\") {\r\n // if (typeof object[key] === 'function') return;\r\n // if it is an object, iterate internally until reaching basic types\r\n // but null is an object so if its null and config[key] is not an object eg. number, the number should be set\r\n if (typeof object[key] === \"object\" && (object[key] !== null || typeof config[key] === \"object\")) {\r\n extendClassWithConfig(object[key], config[key]);\r\n } else {\r\n if (config[key] !== undefined) {\r\n object[key] = config[key];\r\n }\r\n }\r\n }\r\n });\r\n}\r\n"]}
|
package/loader/modelLoader.d.ts
CHANGED
|
@@ -20,6 +20,9 @@ export declare class ModelLoader {
|
|
|
20
20
|
private _loaders;
|
|
21
21
|
private _plugins;
|
|
22
22
|
private _baseUrl;
|
|
23
|
+
/**
|
|
24
|
+
* @returns the base url of the model loader
|
|
25
|
+
*/
|
|
23
26
|
get baseUrl(): string;
|
|
24
27
|
/**
|
|
25
28
|
* Create a new Model loader
|
|
@@ -36,8 +39,13 @@ export declare class ModelLoader {
|
|
|
36
39
|
/**
|
|
37
40
|
* Load a model using predefined configuration
|
|
38
41
|
* @param modelConfiguration the modelConfiguration to use to load the model
|
|
42
|
+
* @returns the loaded model
|
|
39
43
|
*/
|
|
40
44
|
load(modelConfiguration: IModelConfiguration): ViewerModel;
|
|
45
|
+
/**
|
|
46
|
+
* Cancel the loading of a model.
|
|
47
|
+
* @param model the model to cancel the loading of
|
|
48
|
+
*/
|
|
41
49
|
cancelLoad(model: ViewerModel): void;
|
|
42
50
|
/**
|
|
43
51
|
* dispose the model loader.
|
package/loader/modelLoader.js
CHANGED
|
@@ -28,6 +28,9 @@ var ModelLoader = /** @class */ (function () {
|
|
|
28
28
|
this._plugins = [];
|
|
29
29
|
}
|
|
30
30
|
Object.defineProperty(ModelLoader.prototype, "baseUrl", {
|
|
31
|
+
/**
|
|
32
|
+
* @returns the base url of the model loader
|
|
33
|
+
*/
|
|
31
34
|
get: function () {
|
|
32
35
|
return this._baseUrl;
|
|
33
36
|
},
|
|
@@ -57,6 +60,7 @@ var ModelLoader = /** @class */ (function () {
|
|
|
57
60
|
/**
|
|
58
61
|
* Load a model using predefined configuration
|
|
59
62
|
* @param modelConfiguration the modelConfiguration to use to load the model
|
|
63
|
+
* @returns the loaded model
|
|
60
64
|
*/
|
|
61
65
|
ModelLoader.prototype.load = function (modelConfiguration) {
|
|
62
66
|
var _this = this;
|
|
@@ -142,6 +146,10 @@ var ModelLoader = /** @class */ (function () {
|
|
|
142
146
|
this._loaders.push(model.loader);
|
|
143
147
|
return model;
|
|
144
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* Cancel the loading of a model.
|
|
151
|
+
* @param model the model to cancel the loading of
|
|
152
|
+
*/
|
|
145
153
|
ModelLoader.prototype.cancelLoad = function (model) {
|
|
146
154
|
var loader = model.loader || this._loaders[model.loadId];
|
|
147
155
|
// ATM only available in the GLTF Loader
|
|
@@ -1 +1 @@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CAAC;IAC1B,CAAC;IAEO,kCAAY,GAApB,UAAqB,YAAoB;QAAzC,iBAWC;QAX0C,iBAAsB;aAAtB,UAAsB,EAAtB,qBAAsB,EAAtB,IAAsB;YAAtB,gCAAsB;;QAC7D,IAAI,IAAI,CAAC,SAAS,EAAE;YAChB,OAAO;SACV;QACD,IAAI,CAAC,QAAQ;aACR,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,YAAmC,CAAC,EAAtC,CAAsC,CAAC;aACrD,OAAO,CAAC,UAAC,MAAM;YACZ,IAAI;gBACC,MAAc,CAAC,YAAmC,CAAC,CAAC,KAAK,CAAC,KAAI,EAAE,OAAO,CAAC,CAAC;aAC7E;YAAC,OAAO,CAAC,EAAE,GAAE;QAClB,CAAC,CAAC,CAAC;IACX,CAAC;IACL,kBAAC;AAAD,CAAC,AArMD,IAqMC","sourcesContent":["/* eslint-disable import/no-internal-modules */\r\nimport type { GLTFFileLoader } from \"loaders/glTF/glTFFileLoader\";\r\nimport { GLTFLoaderAnimationStartMode } from \"loaders/glTF/glTFFileLoader\";\r\nimport type { ISceneLoaderPlugin, ISceneLoaderPluginAsync } from \"core/Loading/sceneLoader\";\r\nimport { SceneLoader } from \"core/Loading/sceneLoader\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { Tags } from \"core/Misc/tags\";\r\nimport \"core/Misc/observable.extensions\";\r\nimport type { ConfigurationContainer } from \"../configuration/configurationContainer\";\r\nimport type { IModelConfiguration } from \"../configuration/interfaces/modelConfiguration\";\r\nimport type { ObservablesManager } from \"../managers/observablesManager\";\r\nimport { ModelState, ViewerModel } from \"../model/viewerModel\";\r\nimport type { ILoaderPlugin } from \"./plugins/index\";\r\nimport { getLoaderPluginByName } from \"./plugins/index\";\r\nimport \"loaders/glTF/index\";\r\nimport \"core/Loading/Plugins/babylonFileLoader\";\r\n\r\n/**\r\n * An instance of the class is in charge of loading the model correctly.\r\n * This class will continuously be expended with tasks required from the specific loaders Babylon has.\r\n *\r\n * A Model loader is unique per (Abstract)Viewer. It is being generated by the viewer\r\n */\r\nexport class ModelLoader {\r\n private _loadId: number;\r\n private _disposed = false;\r\n\r\n private _loaders: Array<ISceneLoaderPlugin | ISceneLoaderPluginAsync>;\r\n\r\n private _plugins: Array<ILoaderPlugin>;\r\n\r\n private _baseUrl: string;\r\n\r\n public get baseUrl(): string {\r\n return this._baseUrl;\r\n }\r\n\r\n /**\r\n * Create a new Model loader\r\n * @param _observablesManager\r\n * @param _configurationContainer\r\n */\r\n constructor(\r\n private _observablesManager: ObservablesManager,\r\n private _configurationContainer?: ConfigurationContainer\r\n ) {\r\n this._loaders = [];\r\n this._loadId = 0;\r\n this._plugins = [];\r\n }\r\n\r\n /**\r\n * Adds a new plugin to the loader process.\r\n *\r\n * @param plugin the plugin name or the plugin itself\r\n */\r\n public addPlugin(plugin: ILoaderPlugin | string) {\r\n let actualPlugin: ILoaderPlugin = {};\r\n if (typeof plugin === \"string\") {\r\n const loadedPlugin = getLoaderPluginByName(plugin);\r\n if (loadedPlugin) {\r\n actualPlugin = loadedPlugin;\r\n }\r\n } else {\r\n actualPlugin = plugin;\r\n }\r\n if (actualPlugin && this._plugins.indexOf(actualPlugin) === -1) {\r\n this._plugins.push(actualPlugin);\r\n }\r\n }\r\n\r\n /**\r\n * Load a model using predefined configuration\r\n * @param modelConfiguration the modelConfiguration to use to load the model\r\n */\r\n public load(modelConfiguration: IModelConfiguration): ViewerModel {\r\n const model = new ViewerModel(this._observablesManager, modelConfiguration, this._configurationContainer);\r\n\r\n model.loadId = this._loadId++;\r\n\r\n let filename: any;\r\n if (modelConfiguration.file) {\r\n this._baseUrl = \"file:\";\r\n filename = modelConfiguration.file;\r\n } else if (modelConfiguration.url) {\r\n filename = Tools.GetFilename(modelConfiguration.url) || modelConfiguration.url;\r\n this._baseUrl = modelConfiguration.root || Tools.GetFolderPath(modelConfiguration.url);\r\n }\r\n\r\n if (!filename || !this._baseUrl) {\r\n model.state = ModelState.ERROR;\r\n Tools.Error(\"No URL provided\");\r\n return model;\r\n }\r\n\r\n const plugin = modelConfiguration.loader;\r\n\r\n const scene = model.rootMesh.getScene();\r\n\r\n model.loader = SceneLoader.ImportMesh(\r\n undefined,\r\n this._baseUrl,\r\n filename,\r\n scene,\r\n (meshes, particleSystems, skeletons, animationGroups) => {\r\n meshes.forEach((mesh) => {\r\n Tags.AddTagsTo(mesh, \"viewerMesh\");\r\n model.addMesh(mesh);\r\n });\r\n model.particleSystems = particleSystems;\r\n model.skeletons = skeletons;\r\n\r\n for (const animationGroup of animationGroups) {\r\n model.addAnimationGroup(animationGroup);\r\n }\r\n\r\n this._checkAndRun(\"onLoaded\", model);\r\n scene.executeWhenReady(() => {\r\n model.onLoadedObservable.notifyObservers(model);\r\n });\r\n },\r\n (progressEvent) => {\r\n this._checkAndRun(\"onProgress\", progressEvent);\r\n model.onLoadProgressObservable.notifyObserversWithPromise(progressEvent);\r\n },\r\n (scene, m, exception) => {\r\n model.state = ModelState.ERROR;\r\n Tools.Error(\"Load Error: There was an error loading the model. \" + m);\r\n this._checkAndRun(\"onError\", m, exception);\r\n model.onLoadErrorObservable.notifyObserversWithPromise({ message: m, exception: exception });\r\n },\r\n plugin\r\n )!;\r\n\r\n if (model.loader.name === \"gltf\") {\r\n const gltfLoader = <GLTFFileLoader>model.loader;\r\n gltfLoader.animationStartMode = GLTFLoaderAnimationStartMode.NONE;\r\n gltfLoader.compileMaterials = true;\r\n\r\n if (!modelConfiguration.file) {\r\n gltfLoader.rewriteRootURL = (rootURL, responseURL) => {\r\n return modelConfiguration.root || Tools.GetFolderPath(responseURL || modelConfiguration.url || \"\");\r\n };\r\n }\r\n // if ground is set to \"mirror\":\r\n if (\r\n this._configurationContainer &&\r\n this._configurationContainer.configuration &&\r\n this._configurationContainer.configuration.ground &&\r\n typeof this._configurationContainer.configuration.ground === \"object\" &&\r\n this._configurationContainer.configuration.ground.mirror\r\n ) {\r\n gltfLoader.useClipPlane = true;\r\n }\r\n Object.keys(gltfLoader)\r\n .filter((name) => name.indexOf(\"on\") === 0 && name.indexOf(\"Observable\") !== -1)\r\n .forEach((functionName) => {\r\n (gltfLoader as any)[functionName].add((payload: any[]) => {\r\n this._checkAndRun(functionName.replace(\"Observable\", \"\"), payload);\r\n });\r\n });\r\n\r\n gltfLoader.onParsedObservable.add((data) => {\r\n if (data && data.json && (data.json as any)[\"asset\"]) {\r\n model.loadInfo = (data.json as any)[\"asset\"];\r\n }\r\n });\r\n\r\n gltfLoader.onCompleteObservable.add(() => {\r\n model.loaderDone = true;\r\n });\r\n } else {\r\n model.loaderDone = true;\r\n }\r\n\r\n this._checkAndRun(\"onInit\", model.loader, model);\r\n\r\n this._loaders.push(model.loader);\r\n\r\n return model;\r\n }\r\n\r\n public cancelLoad(model: ViewerModel) {\r\n const loader = model.loader || this._loaders[model.loadId];\r\n // ATM only available in the GLTF Loader\r\n if (loader && loader.name === \"gltf\") {\r\n const gltfLoader = <GLTFFileLoader>loader;\r\n gltfLoader.dispose();\r\n model.state = ModelState.CANCELED;\r\n } else {\r\n Tools.Warn(\"This type of loader cannot cancel the request\");\r\n }\r\n }\r\n\r\n /**\r\n * dispose the model loader.\r\n * If loaders are registered and are in the middle of loading, they will be disposed and the request(s) will be cancelled.\r\n */\r\n public dispose() {\r\n this._loaders.forEach((loader) => {\r\n if (loader.name === \"gltf\") {\r\n (<GLTFFileLoader>loader).dispose();\r\n }\r\n });\r\n this._loaders.length = 0;\r\n this._disposed = true;\r\n }\r\n\r\n private _checkAndRun(functionName: string, ...payload: Array<any>) {\r\n if (this._disposed) {\r\n return;\r\n }\r\n this._plugins\r\n .filter((p) => p[functionName as keyof ILoaderPlugin])\r\n .forEach((plugin) => {\r\n try {\r\n (plugin as any)[functionName as keyof ILoaderPlugin].apply(this, payload);\r\n } catch (e) {}\r\n });\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"modelLoader.js","sourceRoot":"","sources":["../../../../tools/viewer/src/loader/modelLoader.ts"],"names":[],"mappings":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X0C,iBAAsB;aAAtB,UAAsB,EAAtB,qBAAsB,EAAtB,IAAsB;YAAtB,gCAAsB;;QAC7D,IAAI,IAAI,CAAC,SAAS,EAAE;YAChB,OAAO;SACV;QACD,IAAI,CAAC,QAAQ;aACR,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,YAAmC,CAAC,EAAtC,CAAsC,CAAC;aACrD,OAAO,CAAC,UAAC,MAAM;YACZ,IAAI;gBACC,MAAc,CAAC,YAAmC,CAAC,CAAC,KAAK,CAAC,KAAI,EAAE,OAAO,CAAC,CAAC;aAC7E;YAAC,OAAO,CAAC,EAAE,GAAE;QAClB,CAAC,CAAC,CAAC;IACX,CAAC;IACL,kBAAC;AAAD,CAAC,AA7MD,IA6MC","sourcesContent":["/* eslint-disable import/no-internal-modules */\r\nimport type { GLTFFileLoader } from \"loaders/glTF/glTFFileLoader\";\r\nimport { GLTFLoaderAnimationStartMode } from \"loaders/glTF/glTFFileLoader\";\r\nimport type { ISceneLoaderPlugin, ISceneLoaderPluginAsync } from \"core/Loading/sceneLoader\";\r\nimport { SceneLoader } from \"core/Loading/sceneLoader\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { Tags } from \"core/Misc/tags\";\r\nimport \"core/Misc/observable.extensions\";\r\nimport type { ConfigurationContainer } from \"../configuration/configurationContainer\";\r\nimport type { IModelConfiguration } from \"../configuration/interfaces/modelConfiguration\";\r\nimport type { ObservablesManager } from \"../managers/observablesManager\";\r\nimport { ModelState, ViewerModel } from \"../model/viewerModel\";\r\nimport type { ILoaderPlugin } from \"./plugins/index\";\r\nimport { getLoaderPluginByName } from \"./plugins/index\";\r\nimport \"loaders/glTF/index\";\r\nimport \"core/Loading/Plugins/babylonFileLoader\";\r\n\r\n/**\r\n * An instance of the class is in charge of loading the model correctly.\r\n * This class will continuously be expended with tasks required from the specific loaders Babylon has.\r\n *\r\n * A Model loader is unique per (Abstract)Viewer. It is being generated by the viewer\r\n */\r\nexport class ModelLoader {\r\n private _loadId: number;\r\n private _disposed = false;\r\n\r\n private _loaders: Array<ISceneLoaderPlugin | ISceneLoaderPluginAsync>;\r\n\r\n private _plugins: Array<ILoaderPlugin>;\r\n\r\n private _baseUrl: string;\r\n\r\n /**\r\n * @returns the base url of the model loader\r\n */\r\n public get baseUrl(): string {\r\n return this._baseUrl;\r\n }\r\n\r\n /**\r\n * Create a new Model loader\r\n * @param _observablesManager\r\n * @param _configurationContainer\r\n */\r\n constructor(\r\n private _observablesManager: ObservablesManager,\r\n private _configurationContainer?: ConfigurationContainer\r\n ) {\r\n this._loaders = [];\r\n this._loadId = 0;\r\n this._plugins = [];\r\n }\r\n\r\n /**\r\n * Adds a new plugin to the loader process.\r\n *\r\n * @param plugin the plugin name or the plugin itself\r\n */\r\n public addPlugin(plugin: ILoaderPlugin | string) {\r\n let actualPlugin: ILoaderPlugin = {};\r\n if (typeof plugin === \"string\") {\r\n const loadedPlugin = getLoaderPluginByName(plugin);\r\n if (loadedPlugin) {\r\n actualPlugin = loadedPlugin;\r\n }\r\n } else {\r\n actualPlugin = plugin;\r\n }\r\n if (actualPlugin && this._plugins.indexOf(actualPlugin) === -1) {\r\n this._plugins.push(actualPlugin);\r\n }\r\n }\r\n\r\n /**\r\n * Load a model using predefined configuration\r\n * @param modelConfiguration the modelConfiguration to use to load the model\r\n * @returns the loaded model\r\n */\r\n public load(modelConfiguration: IModelConfiguration): ViewerModel {\r\n const model = new ViewerModel(this._observablesManager, modelConfiguration, this._configurationContainer);\r\n\r\n model.loadId = this._loadId++;\r\n\r\n let filename: any;\r\n if (modelConfiguration.file) {\r\n this._baseUrl = \"file:\";\r\n filename = modelConfiguration.file;\r\n } else if (modelConfiguration.url) {\r\n filename = Tools.GetFilename(modelConfiguration.url) || modelConfiguration.url;\r\n this._baseUrl = modelConfiguration.root || Tools.GetFolderPath(modelConfiguration.url);\r\n }\r\n\r\n if (!filename || !this._baseUrl) {\r\n model.state = ModelState.ERROR;\r\n Tools.Error(\"No URL provided\");\r\n return model;\r\n }\r\n\r\n const plugin = modelConfiguration.loader;\r\n\r\n const scene = model.rootMesh.getScene();\r\n\r\n model.loader = SceneLoader.ImportMesh(\r\n undefined,\r\n this._baseUrl,\r\n filename,\r\n scene,\r\n (meshes, particleSystems, skeletons, animationGroups) => {\r\n meshes.forEach((mesh) => {\r\n Tags.AddTagsTo(mesh, \"viewerMesh\");\r\n model.addMesh(mesh);\r\n });\r\n model.particleSystems = particleSystems;\r\n model.skeletons = skeletons;\r\n\r\n for (const animationGroup of animationGroups) {\r\n model.addAnimationGroup(animationGroup);\r\n }\r\n\r\n this._checkAndRun(\"onLoaded\", model);\r\n scene.executeWhenReady(() => {\r\n model.onLoadedObservable.notifyObservers(model);\r\n });\r\n },\r\n (progressEvent) => {\r\n this._checkAndRun(\"onProgress\", progressEvent);\r\n model.onLoadProgressObservable.notifyObserversWithPromise(progressEvent);\r\n },\r\n (scene, m, exception) => {\r\n model.state = ModelState.ERROR;\r\n Tools.Error(\"Load Error: There was an error loading the model. \" + m);\r\n this._checkAndRun(\"onError\", m, exception);\r\n model.onLoadErrorObservable.notifyObserversWithPromise({ message: m, exception: exception });\r\n },\r\n plugin\r\n )!;\r\n\r\n if (model.loader.name === \"gltf\") {\r\n const gltfLoader = <GLTFFileLoader>model.loader;\r\n gltfLoader.animationStartMode = GLTFLoaderAnimationStartMode.NONE;\r\n gltfLoader.compileMaterials = true;\r\n\r\n if (!modelConfiguration.file) {\r\n gltfLoader.rewriteRootURL = (rootURL, responseURL) => {\r\n return modelConfiguration.root || Tools.GetFolderPath(responseURL || modelConfiguration.url || \"\");\r\n };\r\n }\r\n // if ground is set to \"mirror\":\r\n if (\r\n this._configurationContainer &&\r\n this._configurationContainer.configuration &&\r\n this._configurationContainer.configuration.ground &&\r\n typeof this._configurationContainer.configuration.ground === \"object\" &&\r\n this._configurationContainer.configuration.ground.mirror\r\n ) {\r\n gltfLoader.useClipPlane = true;\r\n }\r\n Object.keys(gltfLoader)\r\n .filter((name) => name.indexOf(\"on\") === 0 && name.indexOf(\"Observable\") !== -1)\r\n .forEach((functionName) => {\r\n (gltfLoader as any)[functionName].add((payload: any[]) => {\r\n this._checkAndRun(functionName.replace(\"Observable\", \"\"), payload);\r\n });\r\n });\r\n\r\n gltfLoader.onParsedObservable.add((data) => {\r\n if (data && data.json && (data.json as any)[\"asset\"]) {\r\n model.loadInfo = (data.json as any)[\"asset\"];\r\n }\r\n });\r\n\r\n gltfLoader.onCompleteObservable.add(() => {\r\n model.loaderDone = true;\r\n });\r\n } else {\r\n model.loaderDone = true;\r\n }\r\n\r\n this._checkAndRun(\"onInit\", model.loader, model);\r\n\r\n this._loaders.push(model.loader);\r\n\r\n return model;\r\n }\r\n\r\n /**\r\n * Cancel the loading of a model.\r\n * @param model the model to cancel the loading of\r\n */\r\n public cancelLoad(model: ViewerModel) {\r\n const loader = model.loader || this._loaders[model.loadId];\r\n // ATM only available in the GLTF Loader\r\n if (loader && loader.name === \"gltf\") {\r\n const gltfLoader = <GLTFFileLoader>loader;\r\n gltfLoader.dispose();\r\n model.state = ModelState.CANCELED;\r\n } else {\r\n Tools.Warn(\"This type of loader cannot cancel the request\");\r\n }\r\n }\r\n\r\n /**\r\n * dispose the model loader.\r\n * If loaders are registered and are in the middle of loading, they will be disposed and the request(s) will be cancelled.\r\n */\r\n public dispose() {\r\n this._loaders.forEach((loader) => {\r\n if (loader.name === \"gltf\") {\r\n (<GLTFFileLoader>loader).dispose();\r\n }\r\n });\r\n this._loaders.length = 0;\r\n this._disposed = true;\r\n }\r\n\r\n private _checkAndRun(functionName: string, ...payload: Array<any>) {\r\n if (this._disposed) {\r\n return;\r\n }\r\n this._plugins\r\n .filter((p) => p[functionName as keyof ILoaderPlugin])\r\n .forEach((plugin) => {\r\n try {\r\n (plugin as any)[functionName as keyof ILoaderPlugin].apply(this, payload);\r\n } catch (e) {}\r\n });\r\n }\r\n}\r\n"]}
|
|
@@ -9,6 +9,7 @@ export { TelemetryLoaderPlugin, ILoaderPlugin, MSFTLodLoaderPlugin, ApplyMateria
|
|
|
9
9
|
* The plugin will be cached and will be reused if called for again.
|
|
10
10
|
*
|
|
11
11
|
* @param name the name of the plugin
|
|
12
|
+
* @returns the plugin
|
|
12
13
|
*/
|
|
13
14
|
export declare function getLoaderPluginByName(name: string): ILoaderPlugin;
|
|
14
15
|
/**
|
package/loader/plugins/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export { TelemetryLoaderPlugin, MSFTLodLoaderPlugin, ApplyMaterialConfigPlugin,
|
|
|
10
10
|
* The plugin will be cached and will be reused if called for again.
|
|
11
11
|
*
|
|
12
12
|
* @param name the name of the plugin
|
|
13
|
+
* @returns the plugin
|
|
13
14
|
*/
|
|
14
15
|
export function getLoaderPluginByName(name) {
|
|
15
16
|
if (!pluginCache[name]) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../tools/viewer/src/loader/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAExC,IAAM,WAAW,GAAqC,EAAE,CAAC;AAEzD,OAAO,EAAE,qBAAqB,EAAiB,mBAAmB,EAAE,yBAAyB,EAAE,4BAA4B,EAAE,CAAC;AAE9H
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../tools/viewer/src/loader/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAExC,IAAM,WAAW,GAAqC,EAAE,CAAC;AAEzD,OAAO,EAAE,qBAAqB,EAAiB,mBAAmB,EAAE,yBAAyB,EAAE,4BAA4B,EAAE,CAAC;AAE9H;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAC9C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE;QACpB,QAAQ,IAAI,EAAE;YACV,KAAK,WAAW;gBACZ,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,qBAAqB,EAAE,CAAC;gBAChD,MAAM;YACV,KAAK,SAAS;gBACV,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,mBAAmB,EAAE,CAAC;gBAC9C,MAAM;YACV,KAAK,qBAAqB;gBACtB,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,yBAAyB,EAAE,CAAC;gBACpD,MAAM;YACV,KAAK,kBAAkB;gBACnB,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,4BAA4B,EAAE,CAAC;gBACvD,MAAM;SACb;KACJ;IAED,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,MAAqB;IAC/D,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE;QACnB,KAAK,CAAC,IAAI,CAAC,0CAA0C,GAAG,IAAI,CAAC,CAAC;KACjE;IACD,WAAW,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAC/B,CAAC","sourcesContent":["import { TelemetryLoaderPlugin } from \"./telemetryLoaderPlugin\";\r\nimport { ILoaderPlugin } from \"./loaderPlugin\";\r\nimport { MSFTLodLoaderPlugin } from \"./msftLodLoaderPlugin\";\r\nimport { ApplyMaterialConfigPlugin } from \"./applyMaterialConfig\";\r\nimport { ExtendedMaterialLoaderPlugin } from \"./extendedMaterialLoaderPlugin\";\r\nimport { Tools } from \"core/Misc/tools\";\r\n\r\nconst pluginCache: { [key: string]: ILoaderPlugin } = {};\r\n\r\nexport { TelemetryLoaderPlugin, ILoaderPlugin, MSFTLodLoaderPlugin, ApplyMaterialConfigPlugin, ExtendedMaterialLoaderPlugin };\r\n\r\n/**\r\n * Get a loader plugin according to its name.\r\n * The plugin will be cached and will be reused if called for again.\r\n *\r\n * @param name the name of the plugin\r\n * @returns the plugin\r\n */\r\nexport function getLoaderPluginByName(name: string) {\r\n if (!pluginCache[name]) {\r\n switch (name) {\r\n case \"telemetry\":\r\n pluginCache[name] = new TelemetryLoaderPlugin();\r\n break;\r\n case \"msftLod\":\r\n pluginCache[name] = new MSFTLodLoaderPlugin();\r\n break;\r\n case \"applyMaterialConfig\":\r\n pluginCache[name] = new ApplyMaterialConfigPlugin();\r\n break;\r\n case \"extendedMaterial\":\r\n pluginCache[name] = new ExtendedMaterialLoaderPlugin();\r\n break;\r\n }\r\n }\r\n\r\n return pluginCache[name];\r\n}\r\n\r\n/**\r\n * @param name\r\n * @param plugin\r\n */\r\nexport function addLoaderPlugin(name: string, plugin: ILoaderPlugin) {\r\n if (pluginCache[name]) {\r\n Tools.Warn(\"Overwriting plugin with the same name - \" + name);\r\n }\r\n pluginCache[name] = plugin;\r\n}\r\n"]}
|
|
@@ -163,7 +163,8 @@ export declare class SceneManager {
|
|
|
163
163
|
unlockBabylonFeatures(): void;
|
|
164
164
|
/**
|
|
165
165
|
* initialize the scene. Calling this function again will dispose the old scene, if exists.
|
|
166
|
-
* @param sceneConfiguration
|
|
166
|
+
* @param sceneConfiguration the configuration of the scene
|
|
167
|
+
* @returns a promise that resolves when the scene is ready
|
|
167
168
|
*/
|
|
168
169
|
initScene(sceneConfiguration?: ISceneConfiguration): Promise<Scene>;
|
|
169
170
|
clearScene(clearModels?: boolean, clearLights?: boolean): void;
|
package/managers/sceneManager.js
CHANGED
|
@@ -318,7 +318,8 @@ var SceneManager = /** @class */ (function () {
|
|
|
318
318
|
};
|
|
319
319
|
/**
|
|
320
320
|
* initialize the scene. Calling this function again will dispose the old scene, if exists.
|
|
321
|
-
* @param sceneConfiguration
|
|
321
|
+
* @param sceneConfiguration the configuration of the scene
|
|
322
|
+
* @returns a promise that resolves when the scene is ready
|
|
322
323
|
*/
|
|
323
324
|
SceneManager.prototype.initScene = function (sceneConfiguration) {
|
|
324
325
|
if (sceneConfiguration === void 0) { sceneConfiguration = {}; }
|