1 line
30 KiB
Plaintext
1 line
30 KiB
Plaintext
|
|
{"version":3,"file":"ColladaExporter.cjs","sources":["../../src/exporters/ColladaExporter.ts"],"sourcesContent":["import {\n BufferAttribute,\n BufferGeometry,\n Color,\n DoubleSide,\n InterleavedBufferAttribute,\n Material,\n Matrix4,\n Mesh,\n MeshBasicMaterial,\n MeshLambertMaterial,\n MeshPhongMaterial,\n Object3D,\n Texture,\n} from 'three'\nimport type { TypedArray, TypedArrayConstructors } from '../types/shared'\nimport { UV1 } from '../_polyfill/uv1'\n\n/**\n * https://github.com/gkjohnson/collada-exporter-js\n *\n * Usage:\n * const exporter = new ColladaExporter();\n *\n * const data = exporter.parse(mesh);\n *\n * Format Definition:\n * https://www.khronos.org/collada/\n */\n\nexport interface ColladaExporterOptions {\n author?: string\n textureDirectory?: string\n version?: string\n}\n\nexport interface ColladaExporterResult {\n data: string\n textures: object[]\n}\n\ntype GeometryInfo = { meshid: string; bufferGeometry: BufferGeometry }\n\ntype MaterialRepresentation = MeshPhongMaterial | MeshBasicMaterial | MeshLambertMaterial\n\nclass ColladaExporter {\n private options: {\n version: string\n author: string | null\n textureDirectory: string\n upAxis: string\n unitName: string | null\n unitMeter: string | null\n }\n\n private geometryInfo: WeakMap<BufferGeometry, GeometryInfo>\n private materialMap: WeakMap<MaterialRepresentation, string>\n private imageMap: WeakMap<Texture, string>\n private textures: {\n directory: string\n name: string\n ext: string\n data: Uint8Array\n original: Texture\n }[]\n\n private libraryImages: string[]\n private libraryGeometries: string[]\n private libraryEffects: string[]\n private libraryMaterials: string[]\n\n private canvas: HTMLCanvasElement | null\n private ctx: CanvasRenderingContext2D | null\n\n private transMat: Matrix4 | null\n\n private getFuncs = ['getX', 'getY', 'getZ', 'getW'] as const\n\n constructor() {\n this.options = {\n version: '1.4.1',\n author: null,\n textureDirectory: '',\n upAxis: 'Y_UP',\n unitName: null,\n unitMeter: null,\n }\n\n this.geometryInfo = new WeakMap()\n this.materialMap = new WeakMap()\n this.imageMap = new WeakMap()\n this.textures = []\n\n this.libraryImages = []\n this.libraryGeometries = []\n this.libraryEffects = []\n this.libraryMaterials = []\n\n this.canvas = null\n this.ctx = null\n\n this.transMat = null\n }\n\n public parse(\n object: Object3D,\n onDone: (res: ColladaExporterResult) => void,\n options: ColladaExporterOptions = {},\n ): ColladaExporterResult | null {\n this.options = { ...this.options, ...options }\n\n if (this.options.upAxis.match(/^[XYZ]_UP$/) === null) {\n console.error('ColladaExporter: Invalid upAxis: valid values are X_UP, Y_UP or Z_UP.')\n return null\n }\n\n if (this.options.unitName !== null && this.options.unitMeter === null) {\n console.error('ColladaExporter: unitMeter needs to be specified if unitName is specified.')\n return null\n }\n\n if (this.options.unitMeter !== null && this.options.unitName === null) {\n console.error('ColladaExporter: unitName needs to be specified if unitMeter is specified.')\n return null\n }\n\n if (this.options.textureDirectory !== '') {\n this.options.textureDirectory = `${this.options.textureDirectory}/`.replace(/\\\\/g, '/').replace(/\\/+/g, '/')\n }\n\n if (this.options.version !== '1.4.1' && this.options.version !== '1.5.0') {\n console.warn(`ColladaExporter : Version ${this.options.version} not supported for export. Only 1.4.1 and 1.5.0.`)\n return null\n }\n\n const libraryVisualScenes = this.processObject(object)\n\n const specLink =\n this.options.version === '1.4.1'\n ? 'http://www.collada.org/2005/11/COLLADASchema'\n : 'https://www.khronos.org/collada/'\n let dae = `<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>${`<COLLADA xmlns=\"${specLink}\" version=\"${this.options.version}\">`}<asset>
|