@babylonjs/loaders 6.27.1 → 6.28.0
Sign up to get free protection for your applications and to get access to all the features.
package/glTF/glTFValidation.d.ts
CHANGED
@@ -13,7 +13,7 @@ export interface IGLTFValidationConfiguration {
|
|
13
13
|
*/
|
14
14
|
export declare class GLTFValidation {
|
15
15
|
/**
|
16
|
-
* The configuration. Defaults to `{ url: "https://
|
16
|
+
* The configuration. Defaults to `{ url: "https://cdn.babylonjs.com/gltf_validator.js" }`.
|
17
17
|
*/
|
18
18
|
static Configuration: IGLTFValidationConfiguration;
|
19
19
|
private static _LoadScriptPromise;
|
package/glTF/glTFValidation.js
CHANGED
@@ -110,9 +110,9 @@ export class GLTFValidation {
|
|
110
110
|
}
|
111
111
|
}
|
112
112
|
/**
|
113
|
-
* The configuration. Defaults to `{ url: "https://
|
113
|
+
* The configuration. Defaults to `{ url: "https://cdn.babylonjs.com/gltf_validator.js" }`.
|
114
114
|
*/
|
115
115
|
GLTFValidation.Configuration = {
|
116
|
-
url:
|
116
|
+
url: `${Tools._DefaultCdnUrl}/gltf_validator.js`,
|
117
117
|
};
|
118
118
|
//# sourceMappingURL=glTFValidation.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"glTFValidation.js","sourceRoot":"","sources":["../../../../dev/loaders/src/glTF/glTFValidation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,sCAAwB;AASxC,SAAS,aAAa,CAClB,IAA0B,EAC1B,OAAe,EACf,QAAgB,EAChB,mBAA0D;IAE1D,MAAM,OAAO,GAAiC;QAC1C,wBAAwB,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;KACrG,CAAC;IAEF,IAAI,QAAQ,EAAE;QACV,OAAO,CAAC,GAAG,GAAG,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,C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,CAAC;gBAEF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC1C,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBAE9C,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBAC3F,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;YACjG,CAAC,CAAC,CAAC;SACN;aAAM;YACH,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE;gBAC1B,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC,sBAAsB,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;aAClF;YAED,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,EAAE;gBACrC,OAAO,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAAC;YAC3E,CAAC,CAAC,CAAC;SACN;IACL,CAAC;;AAlFD;;GAEG;AACW,4BAAa,GAAiC;IACxD,GAAG,EAAE,mBAAmB;CAC3B,CAAC","sourcesContent":["import type * as GLTF2 from \"babylonjs-gltf2interface\";\r\nimport { Tools } from \"core/Misc/tools\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let GLTFValidator: GLTF2.IGLTFValidator;\r\n\r\n// WorkerGlobalScope\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: any, transfer?: any[]): void;\r\n\r\nfunction validateAsync(\r\n data: string | ArrayBuffer,\r\n rootUrl: string,\r\n fileName: string,\r\n getExternalResource: (uri: string) => Promise<ArrayBuffer>\r\n): Promise<GLTF2.IGLTFValidationResults> {\r\n const options: GLTF2.IGLTFValidationOptions = {\r\n externalResourceFunction: (uri) => getExternalResource(uri).then((value) => new Uint8Array(value)),\r\n };\r\n\r\n if (fileName) {\r\n options.uri = rootUrl === \"file:\" ? fileName : rootUrl + fileName;\r\n }\r\n\r\n return data instanceof ArrayBuffer ? GLTFValidator.validateBytes(new Uint8Array(data), options) : GLTFValidator.validateString(data, options);\r\n}\r\n\r\n/**\r\n * The worker function that gets converted to a blob url to pass into a worker.\r\n */\r\nfunction workerFunc(): void {\r\n const pendingExternalResources: Array<{ resolve: (data: any) => void; reject: (reason: any) => void }> = [];\r\n\r\n onmessage = (message) => {\r\n const data = message.data;\r\n switch (data.id) {\r\n case \"init\": {\r\n importScripts(data.url);\r\n break;\r\n }\r\n case \"validate\": {\r\n validateAsync(\r\n data.data,\r\n data.rootUrl,\r\n data.fileName,\r\n (uri) =>\r\n new Promise((resolve, reject) => {\r\n const index = pendingExternalResources.length;\r\n pendingExternalResources.push({ resolve, reject });\r\n postMessage({ id: \"getExternalResource\", index: index, uri: uri });\r\n })\r\n ).then(\r\n (value) => {\r\n postMessage({ id: \"validate.resolve\", value: value });\r\n },\r\n (reason) => {\r\n postMessage({ id: \"validate.reject\", reason: reason });\r\n }\r\n );\r\n break;\r\n }\r\n case \"getExternalResource.resolve\": {\r\n pendingExternalResources[data.index].resolve(data.value);\r\n break;\r\n }\r\n case \"getExternalResource.reject\": {\r\n pendingExternalResources[data.index].reject(data.reason);\r\n break;\r\n }\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Configuration for glTF validation\r\n */\r\nexport interface IGLTFValidationConfiguration {\r\n /**\r\n * The url of the glTF validator.\r\n */\r\n url: string;\r\n}\r\n\r\n/**\r\n * glTF validation\r\n */\r\nexport class GLTFValidation {\r\n /**\r\n * The configuration. Defaults to `{ url: \"https://preview.babylonjs.com/gltf_validator.js\" }`.\r\n */\r\n public static Configuration: IGLTFValidationConfiguration = {\r\n url: \"gltf_validator.js\",\r\n };\r\n\r\n private static _LoadScriptPromise: Promise<void>;\r\n\r\n /**\r\n * Validate a glTF asset using the glTF-Validator.\r\n * @param data The JSON of a glTF or the array buffer of a binary glTF\r\n * @param rootUrl The root url for the glTF\r\n * @param fileName The file name for the glTF\r\n * @param getExternalResource The callback to get external resources for the glTF validator\r\n * @returns A promise that resolves with the glTF validation results once complete\r\n */\r\n public static ValidateAsync(\r\n data: string | ArrayBufferView,\r\n rootUrl: string,\r\n fileName: string,\r\n getExternalResource: (uri: string) => Promise<ArrayBuffer>\r\n ): Promise<GLTF2.IGLTFValidationResults> {\r\n const dataCopy = ArrayBuffer.isView(data) ? (data as Uint8Array).slice().buffer : (data as string);\r\n\r\n if (typeof Worker === \"function\") {\r\n return new Promise((resolve, reject) => {\r\n const workerContent = `${validateAsync}(${workerFunc})()`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n const worker = new Worker(workerBlobUrl);\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n };\r\n\r\n const onMessage = (message: MessageEvent) => {\r\n const data = message.data;\r\n switch (data.id) {\r\n case \"getExternalResource\": {\r\n getExternalResource(data.uri).then(\r\n (value) => {\r\n worker.postMessage({ id: \"getExternalResource.resolve\", index: data.index, value: value }, [value]);\r\n },\r\n (reason) => {\r\n worker.postMessage({ id: \"getExternalResource.reject\", index: data.index, reason: reason });\r\n }\r\n );\r\n break;\r\n }\r\n case \"validate.resolve\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(data.value);\r\n worker.terminate();\r\n break;\r\n }\r\n case \"validate.reject\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(data.reason);\r\n worker.terminate();\r\n }\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n worker.postMessage({ id: \"init\", url: Tools.GetBabylonScriptURL(this.Configuration.url) });\r\n worker.postMessage({ id: \"validate\", data: dataCopy, rootUrl: rootUrl, fileName: fileName });\r\n });\r\n } else {\r\n if (!this._LoadScriptPromise) {\r\n this._LoadScriptPromise = Tools.LoadBabylonScriptAsync(this.Configuration.url);\r\n }\r\n\r\n return this._LoadScriptPromise.then(() => {\r\n return validateAsync(dataCopy, rootUrl, fileName, getExternalResource);\r\n });\r\n }\r\n }\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"glTFValidation.js","sourceRoot":"","sources":["../../../../dev/loaders/src/glTF/glTFValidation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,sCAAwB;AASxC,SAAS,aAAa,CAClB,IAA0B,EAC1B,OAAe,EACf,QAAgB,EAChB,mBAA0D;IAE1D,MAAM,OAAO,GAAiC;QAC1C,wBAAwB,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;KACrG,CAAC;IAEF,IAAI,QAAQ,EAAE;QACV,OAAO,CAAC,GAAG,GAAG,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,GAAG,QAAQ,CAAC;KACrE;IAED,OAAO,IAAI,YAAY,WAAW,CAAC,CAAC,CAAC,aAAa,CAAC,aAAa,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAClJ,CAAC;AAED;;GAEG;AACH,SAAS,UAAU;IACf,MAAM,wBAAwB,GAA2E,EAAE,CAAC;IAE5G,SAAS,GAAG,CAAC,OAAO,EAAE,EAAE;QACpB,MAAM,IA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QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;YACjG,CAAC,CAAC,CAAC;SACN;aAAM;YACH,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE;gBAC1B,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC,sBAAsB,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;aAClF;YAED,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,EAAE;gBACrC,OAAO,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAAC;YAC3E,CAAC,CAAC,CAAC;SACN;IACL,CAAC;;AAlFD;;GAEG;AACW,4BAAa,GAAiC;IACxD,GAAG,EAAE,GAAG,KAAK,CAAC,cAAc,oBAAoB;CACnD,CAAC","sourcesContent":["import type * as GLTF2 from \"babylonjs-gltf2interface\";\r\nimport { Tools } from \"core/Misc/tools\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let GLTFValidator: GLTF2.IGLTFValidator;\r\n\r\n// WorkerGlobalScope\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: any, transfer?: any[]): void;\r\n\r\nfunction validateAsync(\r\n data: string | ArrayBuffer,\r\n rootUrl: string,\r\n fileName: string,\r\n getExternalResource: (uri: string) => Promise<ArrayBuffer>\r\n): Promise<GLTF2.IGLTFValidationResults> {\r\n const options: GLTF2.IGLTFValidationOptions = {\r\n externalResourceFunction: (uri) => getExternalResource(uri).then((value) => new Uint8Array(value)),\r\n };\r\n\r\n if (fileName) {\r\n options.uri = rootUrl === \"file:\" ? fileName : rootUrl + fileName;\r\n }\r\n\r\n return data instanceof ArrayBuffer ? GLTFValidator.validateBytes(new Uint8Array(data), options) : GLTFValidator.validateString(data, options);\r\n}\r\n\r\n/**\r\n * The worker function that gets converted to a blob url to pass into a worker.\r\n */\r\nfunction workerFunc(): void {\r\n const pendingExternalResources: Array<{ resolve: (data: any) => void; reject: (reason: any) => void }> = [];\r\n\r\n onmessage = (message) => {\r\n const data = message.data;\r\n switch (data.id) {\r\n case \"init\": {\r\n importScripts(data.url);\r\n break;\r\n }\r\n case \"validate\": {\r\n validateAsync(\r\n data.data,\r\n data.rootUrl,\r\n data.fileName,\r\n (uri) =>\r\n new Promise((resolve, reject) => {\r\n const index = pendingExternalResources.length;\r\n pendingExternalResources.push({ resolve, reject });\r\n postMessage({ id: \"getExternalResource\", index: index, uri: uri });\r\n })\r\n ).then(\r\n (value) => {\r\n postMessage({ id: \"validate.resolve\", value: value });\r\n },\r\n (reason) => {\r\n postMessage({ id: \"validate.reject\", reason: reason });\r\n }\r\n );\r\n break;\r\n }\r\n case \"getExternalResource.resolve\": {\r\n pendingExternalResources[data.index].resolve(data.value);\r\n break;\r\n }\r\n case \"getExternalResource.reject\": {\r\n pendingExternalResources[data.index].reject(data.reason);\r\n break;\r\n }\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Configuration for glTF validation\r\n */\r\nexport interface IGLTFValidationConfiguration {\r\n /**\r\n * The url of the glTF validator.\r\n */\r\n url: string;\r\n}\r\n\r\n/**\r\n * glTF validation\r\n */\r\nexport class GLTFValidation {\r\n /**\r\n * The configuration. Defaults to `{ url: \"https://cdn.babylonjs.com/gltf_validator.js\" }`.\r\n */\r\n public static Configuration: IGLTFValidationConfiguration = {\r\n url: `${Tools._DefaultCdnUrl}/gltf_validator.js`,\r\n };\r\n\r\n private static _LoadScriptPromise: Promise<void>;\r\n\r\n /**\r\n * Validate a glTF asset using the glTF-Validator.\r\n * @param data The JSON of a glTF or the array buffer of a binary glTF\r\n * @param rootUrl The root url for the glTF\r\n * @param fileName The file name for the glTF\r\n * @param getExternalResource The callback to get external resources for the glTF validator\r\n * @returns A promise that resolves with the glTF validation results once complete\r\n */\r\n public static ValidateAsync(\r\n data: string | ArrayBufferView,\r\n rootUrl: string,\r\n fileName: string,\r\n getExternalResource: (uri: string) => Promise<ArrayBuffer>\r\n ): Promise<GLTF2.IGLTFValidationResults> {\r\n const dataCopy = ArrayBuffer.isView(data) ? (data as Uint8Array).slice().buffer : (data as string);\r\n\r\n if (typeof Worker === \"function\") {\r\n return new Promise((resolve, reject) => {\r\n const workerContent = `${validateAsync}(${workerFunc})()`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n const worker = new Worker(workerBlobUrl);\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n };\r\n\r\n const onMessage = (message: MessageEvent) => {\r\n const data = message.data;\r\n switch (data.id) {\r\n case \"getExternalResource\": {\r\n getExternalResource(data.uri).then(\r\n (value) => {\r\n worker.postMessage({ id: \"getExternalResource.resolve\", index: data.index, value: value }, [value]);\r\n },\r\n (reason) => {\r\n worker.postMessage({ id: \"getExternalResource.reject\", index: data.index, reason: reason });\r\n }\r\n );\r\n break;\r\n }\r\n case \"validate.resolve\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(data.value);\r\n worker.terminate();\r\n break;\r\n }\r\n case \"validate.reject\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(data.reason);\r\n worker.terminate();\r\n }\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n worker.postMessage({ id: \"init\", url: Tools.GetBabylonScriptURL(this.Configuration.url) });\r\n worker.postMessage({ id: \"validate\", data: dataCopy, rootUrl: rootUrl, fileName: fileName });\r\n });\r\n } else {\r\n if (!this._LoadScriptPromise) {\r\n this._LoadScriptPromise = Tools.LoadBabylonScriptAsync(this.Configuration.url);\r\n }\r\n\r\n return this._LoadScriptPromise.then(() => {\r\n return validateAsync(dataCopy, rootUrl, fileName, getExternalResource);\r\n });\r\n }\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babylonjs/loaders",
|
3
|
-
"version": "6.
|
3
|
+
"version": "6.28.0",
|
4
4
|
"main": "index.js",
|
5
5
|
"module": "index.js",
|
6
6
|
"types": "index.d.ts",
|
@@ -18,10 +18,10 @@
|
|
18
18
|
"postcompile": "build-tools -c add-js-to-es6"
|
19
19
|
},
|
20
20
|
"devDependencies": {
|
21
|
-
"@babylonjs/core": "^6.
|
21
|
+
"@babylonjs/core": "^6.28.0",
|
22
22
|
"@dev/build-tools": "^1.0.0",
|
23
23
|
"@lts/loaders": "^1.0.0",
|
24
|
-
"babylonjs-gltf2interface": "^6.
|
24
|
+
"babylonjs-gltf2interface": "^6.28.0"
|
25
25
|
},
|
26
26
|
"peerDependencies": {
|
27
27
|
"@babylonjs/core": "^6.0.0",
|