MCPcopy
hub / github.com/donmccurdy/glTF-Transform / read

Method read

packages/core/src/io/reader.ts:42–552  ·  view source on GitHub ↗
(jsonDoc: JSONDocument, _options: ReaderOptions = DEFAULT_OPTIONS)

Source from the content-addressed store, hash-verified

40/** @internal */
41export class GLTFReader {
42 public static read(jsonDoc: JSONDocument, _options: ReaderOptions = DEFAULT_OPTIONS): Document {
43 const options = { ...DEFAULT_OPTIONS, ..._options } as Required<ReaderOptions>;
44 const { json } = jsonDoc;
45 const document = new Document().setLogger(options.logger);
46
47 this.validate(jsonDoc, options);
48
49 /* Reader context. */
50
51 const context = new ReaderContext(jsonDoc);
52
53 /** Asset. */
54
55 const assetDef = json.asset;
56 const asset = document.getRoot().getAsset();
57
58 if (assetDef.copyright) asset.copyright = assetDef.copyright;
59 if (assetDef.extras) asset.extras = assetDef.extras;
60
61 if (json.extras !== undefined) {
62 document.getRoot().setExtras({ ...json.extras });
63 }
64
65 /** Extensions (1/2). */
66
67 const extensionsUsed = json.extensionsUsed || [];
68 const extensionsRequired = json.extensionsRequired || [];
69
70 options.extensions.sort((a, b) => (a.EXTENSION_NAME > b.EXTENSION_NAME ? 1 : -1));
71
72 for (const Extension of options.extensions) {
73 if (extensionsUsed.includes(Extension.EXTENSION_NAME)) {
74 // Create extension.
75 const extension = document
76 .createExtension(Extension as unknown as new (doc: Document) => Extension)
77 .setRequired(extensionsRequired.includes(Extension.EXTENSION_NAME));
78
79 // Warn on unsupported preread hooks.
80 const unsupportedHooks = extension.prereadTypes.filter((type) => !SUPPORTED_PREREAD_TYPES.has(type));
81 if (unsupportedHooks.length) {
82 options.logger.warn(
83 `Preread hooks for some types (${unsupportedHooks.join()}), requested by extension ` +
84 `${extension.extensionName}, are unsupported. Please file an issue or a PR.`,
85 );
86 }
87
88 // Install dependencies.
89 for (const key of extension.readDependencies) {
90 extension.install(key, options.dependencies[key]);
91 }
92 }
93 }
94
95 /** Buffers. */
96
97 const bufferDefs = json.buffers || [];
98 document
99 .getRoot()

Callers 8

readJSONFunction · 0.45
1-model.tsFile · 0.45
join.test.tsFile · 0.45
partition.test.tsFile · 0.45
inspect.test.tsFile · 0.45
simplify.test.tsFile · 0.45
dedup.test.tsFile · 0.45
deno_test.tsFile · 0.45

Calls 15

validateMethod · 0.95
setTextureInfoMethod · 0.95
getAccessorArrayFunction · 0.85
getSparseArrayFunction · 0.85
setLoggerMethod · 0.80
getAssetMethod · 0.80
getRootMethod · 0.80
setRequiredMethod · 0.80
createExtensionMethod · 0.80
hasMethod · 0.80
listExtensionsUsedMethod · 0.80
createBufferMethod · 0.80

Tested by

no test coverage detected