# glb **Repository Path**: cesiumjs/glb ## Basic Information - **Project Name**: glb - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-09-10 - **Last Updated**: 2025-09-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # @3dtiles/glb A TypeScript library for parsing and processing GLB 3D model files. ## Features - Parse GLB files into structured data - Validate GLB file integrity and structure - Serialize GLB data back into binary format - Support for GLB version 2 - Handle both JSON and binary chunks ## Installation ```bash npm install @3dtiles/glb ``` ## Usage ### Parsing a GLB file ```typescript import { parseGLB, validateGLB } from '@3dtiles/glb'; import { readFileSync } from 'fs'; // Read GLB file as binary const data = readFileSync('model.glb'); const glbFile = parseGLB(new Uint8Array(data.buffer)); // Validate the parsed file if (validateGLB(glbFile)) { console.log('Valid GLB file'); console.log('JSON content:', glbFile.jsonContent); console.log('Has binary chunk:', !!glbFile.binaryChunk); } else { console.error('Invalid GLB file'); } ``` ### Serializing a GLB file ```typescript import { serializeGLB, GLBFile } from '@3dtiles/glb'; import { writeFileSync } from 'fs'; // Create or modify a GLBFile object const glbFile: GLBFile = { header: { magic: 0x46546C67, version: 2, length: 0 // Will be calculated automatically }, jsonContent: { scenes: [{ nodes: [] }], nodes: [] }, // ... add other chunks as needed }; // Serialize to binary const binaryData = serializeGLB(glbFile); // Write to file writeFileSync('new-model.glb', binaryData); ``` ## API ### `parseGLB(data: Uint8Array): GLBFile` Parses binary data into a GLBFile structure. ### `validateGLB(file: GLBFile): boolean` Validates the structure and integrity of a parsed GLBFile. ### `serializeGLB(file: GLBFile): Uint8Array` Serializes a GLBFile back into binary format. ### [GLBParser](file://d:\hub\代码测试\proj4ts\glb-ts-library\src\index.ts#L23-L191) class Provides the core functionality with methods: - `parse(data: Uint8Array): GLBFile` - `validate(file: GLBFile): boolean` - `serialize(file: GLBFile): Uint8Array` ## License MIT