import { Application } from '../../src' import { ExampleSystem } from './example-system' const el: any = document.getElementById('app') import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter' const app = new Application(el, { disablePhysicsDebug: true }) app.start() const system = new ExampleSystem() app.addSystem(system) function downloadGLB(model) { const exporter = new GLTFExporter() const options = { trs: true, // 是否保留位置、旋转、缩放信息 animations: [], // 导出的动画 binary: true, // 是否以二进制格式输出 embedImages: true, //是否嵌入贴图 onlyVisible: true, //是否只导出可见物体 forcePowerOfTwoTextures: true, includeCustomMaterials: true, //指定是否包含自定义材质 includeCustomAttributes: true, // 指定是否包含自定义属性 includeCustomTextures: true, // 指定是否包含自定义纹理 includeCustomSamplers: true, // 指定是否包含自定义采样器 includeCustomImages: true, // 指定是否包含自定义图像 includeCustomTechniques: true, // 指定是否包含自定义技术 includeCustomMaterialsCommon: true, //指定是否包含自定义 MaterialsCommon includeCustomMeshes: true, //指定是否包含自定义网格 includeCustomSkins: true, //指定是否包含自定义皮肤 includeCustomNodes: true, // 指定是否包含自定义节点 includeCustomGeometries: true, //指定是否包含自定义几何体 includeCustomPrograms: true, // 指定是否包含自定义程序 includeCustomShaders: true, //指定是否包含自定义着色器 includeCustomExtensions: true //指定是否包含自定义扩展。如果设置为true,则会包含在导出中定义的自定义GLTF扩展 } exporter.parse( model, (result) => { // 处理导出结果 const blob = new Blob([result], { type: 'application/octet-stream' }) const url = URL.createObjectURL(blob) const link = document.createElement('a') link.href = url link.download = 'model.glb' document.body.appendChild(link) link.click() document.body.removeChild(link) }, (err) => { console.error(err) }, options ) } // document.getElementById('generate')?.addEventListener('click', () => { // const { SystemManager, EntityManager } = app // const model = (SystemManager.getSystem(ExampleSystem) as any).fixObject.clone() // model.position.set(0, 0, 0) // saveModeToPako(model, 'cr20') // saveModeToBase64(model, 'cr20') // downloadGLB(model) // }) setTimeout(() => { const { SystemManager, EntityManager } = app const model = (SystemManager.getSystem(ExampleSystem) as any).getEntity('cr20').group model.userData = {} model.position.set(0, 0, 0) downloadGLB(model) }, 3000)