MCPcopy Create free account
hub / github.com/esengine/esengine / parse

Method parse

packages/asset-system/src/loaders/GLTFLoader.ts:195–251  ·  view source on GitHub ↗

* Parse GLTF/GLB content * 解析 GLTF/GLB 内容

(content: IAssetContent, context: IAssetParseContext)

Source from the content-addressed store, hash-verified

193 * 解析 GLTF/GLB 内容
194 */
195 async parse(content: IAssetContent, context: IAssetParseContext): Promise<IGLTFAsset> {
196 const binary = content.binary;
197 if (!binary) {
198 throw new Error('GLTF loader requires binary content');
199 }
200
201 const isGLB = this.isGLB(binary);
202 let json: GLTFJson;
203 let binaryChunk: ArrayBuffer | null = null;
204
205 if (isGLB) {
206 const glbData = this.parseGLB(binary);
207 json = glbData.json;
208 binaryChunk = glbData.binary;
209 } else {
210 // GLTF is JSON text
211 const decoder = new TextDecoder('utf-8');
212 const text = decoder.decode(binary);
213 json = JSON.parse(text) as GLTFJson;
214 }
215
216 // Validate GLTF version
217 if (!json.asset?.version?.startsWith('2.')) {
218 throw new Error(`Unsupported GLTF version: ${json.asset?.version}. Only GLTF 2.x is supported.`);
219 }
220
221 // Load external buffers if needed
222 const buffers = await this.loadBuffers(json, binaryChunk, context);
223
224 // Parse all components
225 const meshes = this.parseMeshes(json, buffers);
226 const materials = this.parseMaterials(json);
227 const textures = await this.parseTextures(json, buffers, context);
228 const nodes = this.parseNodes(json);
229 const rootNodes = this.getRootNodes(json);
230 const animations = this.parseAnimations(json, buffers);
231 const skeleton = this.parseSkeleton(json, buffers);
232 const bounds = this.calculateBounds(meshes);
233
234 // Get model name from file path
235 const pathParts = context.metadata.path.split(/[\\/]/);
236 const fileName = pathParts[pathParts.length - 1];
237 const name = fileName.replace(/\.(gltf|glb)$/i, '');
238
239 return {
240 name,
241 meshes,
242 materials,
243 textures,
244 nodes,
245 rootNodes,
246 animations: animations.length > 0 ? animations : undefined,
247 skeleton,
248 bounds,
249 sourcePath: context.metadata.path
250 };
251 }
252

Callers 2

ContentBrowserFunction · 0.95
AnimationPreviewPanelFunction · 0.95

Calls 13

isGLBMethod · 0.95
parseGLBMethod · 0.95
loadBuffersMethod · 0.95
parseMeshesMethod · 0.95
parseMaterialsMethod · 0.95
parseTexturesMethod · 0.95
parseNodesMethod · 0.95
getRootNodesMethod · 0.95
parseAnimationsMethod · 0.95
parseSkeletonMethod · 0.95
calculateBoundsMethod · 0.95
parseMethod · 0.65

Tested by

no test coverage detected