three-stdlib 2.32.0 → 2.32.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_polyfill/uv1.cjs +6 -0
- package/_polyfill/uv1.cjs.map +1 -0
- package/_polyfill/uv1.d.ts +5 -0
- package/_polyfill/uv1.js +6 -0
- package/_polyfill/uv1.js.map +1 -0
- package/exporters/ColladaExporter.cjs +3 -2
- package/exporters/ColladaExporter.cjs.map +1 -1
- package/exporters/ColladaExporter.js +3 -2
- package/exporters/ColladaExporter.js.map +1 -1
- package/lines/LineSegments2.cjs +3 -2
- package/lines/LineSegments2.cjs.map +1 -1
- package/lines/LineSegments2.js +3 -2
- package/lines/LineSegments2.js.map +1 -1
- package/loaders/ColladaLoader.cjs +7 -6
- package/loaders/ColladaLoader.cjs.map +1 -1
- package/loaders/ColladaLoader.js +7 -6
- package/loaders/ColladaLoader.js.map +1 -1
- package/loaders/FBXLoader.cjs +4 -4
- package/loaders/FBXLoader.cjs.map +1 -1
- package/loaders/FBXLoader.js +4 -4
- package/loaders/FBXLoader.js.map +1 -1
- package/loaders/LWOLoader.cjs +3 -1
- package/loaders/LWOLoader.cjs.map +1 -1
- package/loaders/LWOLoader.js +3 -1
- package/loaders/LWOLoader.js.map +1 -1
- package/misc/ProgressiveLightmap.cjs +12 -10
- package/misc/ProgressiveLightmap.cjs.map +1 -1
- package/misc/ProgressiveLightmap.js +12 -10
- package/misc/ProgressiveLightmap.js.map +1 -1
- package/modifiers/TessellateModifier.cjs +20 -19
- package/modifiers/TessellateModifier.cjs.map +1 -1
- package/modifiers/TessellateModifier.js +20 -19
- package/modifiers/TessellateModifier.js.map +1 -1
- package/package.json +1 -1
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"uv1.cjs","sources":["../../src/_polyfill/uv1.ts"],"sourcesContent":["import { version } from \"./constants\";\n\n/** uv2 renamed to uv1 in r125\n * \n * https://github.com/mrdoob/three.js/pull/25943\n*/\nexport const UV1 = version >= 125 ? 'uv1' : 'uv2'"],"names":["version"],"mappings":";;;AAMa,MAAA,MAAMA,UAAAA,WAAW,MAAM,QAAQ;;"}
|
package/_polyfill/uv1.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"uv1.js","sources":["../../src/_polyfill/uv1.ts"],"sourcesContent":["import { version } from \"./constants\";\n\n/** uv2 renamed to uv1 in r125\n * \n * https://github.com/mrdoob/three.js/pull/25943\n*/\nexport const UV1 = version >= 125 ? 'uv1' : 'uv2'"],"names":[],"mappings":";AAMa,MAAA,MAAM,WAAW,MAAM,QAAQ;"}
|
@@ -7,6 +7,7 @@ var __publicField = (obj, key, value) => {
|
|
7
7
|
};
|
8
8
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
9
9
|
const THREE = require("three");
|
10
|
+
const uv1 = require("../_polyfill/uv1.cjs");
|
10
11
|
class ColladaExporter {
|
11
12
|
constructor() {
|
12
13
|
__publicField(this, "options");
|
@@ -191,9 +192,9 @@ class ColladaExporter {
|
|
191
192
|
gnode += this.getAttribute(bufferGeometry.attributes.uv, uvName, ["S", "T"], "float");
|
192
193
|
triangleInputs += `<input semantic="TEXCOORD" source="#${uvName}" offset="0" set="0" />`;
|
193
194
|
}
|
194
|
-
if (
|
195
|
+
if (uv1.UV1 in bufferGeometry.attributes) {
|
195
196
|
const uvName = `${meshid}-texcoord2`;
|
196
|
-
gnode += this.getAttribute(bufferGeometry.attributes.
|
197
|
+
gnode += this.getAttribute(bufferGeometry.attributes[uv1.UV1], uvName, ["S", "T"], "float");
|
197
198
|
triangleInputs += `<input semantic="TEXCOORD" source="#${uvName}" offset="0" set="1" />`;
|
198
199
|
}
|
199
200
|
if ("color" in bufferGeometry.attributes) {
|
@@ -1 +1 @@
|
|
1
|
-
{"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'\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><contributor><authoring_tool>three.js Collada Exporter</authoring_tool>${\n this.options.author !== null ? `<author>${this.options.author}</author>` : ''\n }</contributor>${`<created>${new Date().toISOString()}</created>`}${`<modified>${new Date().toISOString()}</modified>`}<up_axis>Y_UP</up_axis></asset>`\n\n dae += `<library_images>${this.libraryImages.join('')}</library_images>`\n\n dae += `<library_effects>${this.libraryEffects.join('')}</library_effects>`\n\n dae += `<library_materials>${this.libraryMaterials.join('')}</library_materials>`\n\n dae += `<library_geometries>${this.libraryGeometries.join('')}</library_geometries>`\n\n dae += `<library_visual_scenes><visual_scene id=\"Scene\" name=\"scene\">${libraryVisualScenes}</visual_scene></library_visual_scenes>`\n\n dae += '<scene><instance_visual_scene url=\"#Scene\"/></scene>'\n\n dae += '</COLLADA>'\n\n const res = {\n data: this.format(dae),\n textures: this.textures,\n }\n\n if (typeof onDone === 'function') {\n requestAnimationFrame(() => onDone(res))\n }\n\n return res\n }\n\n // Convert the urdf xml into a well-formatted, indented format\n private format(urdf: string): string {\n const IS_END_TAG = /^<\\//\n const IS_SELF_CLOSING = /(\\?>$)|(\\/>$)/\n const HAS_TEXT = /<[^>]+>[^<]*<\\/[^<]+>/\n\n const pad = (ch: string, num: number): string => (num > 0 ? ch + pad(ch, num - 1) : '')\n\n let tagnum = 0\n\n return (\n urdf\n .match(/(<[^>]+>[^<]+<\\/[^<]+>)|(<[^>]+>)/g)\n ?.map((tag) => {\n if (!HAS_TEXT.test(tag) && !IS_SELF_CLOSING.test(tag) && IS_END_TAG.test(tag)) {\n tagnum--\n }\n\n const res = `${pad(' ', tagnum)}${tag}`\n\n if (!HAS_TEXT.test(tag) && !IS_SELF_CLOSING.test(tag) && !IS_END_TAG.test(tag)) {\n tagnum++\n }\n\n return res\n })\n .join('\\n') ?? ''\n )\n }\n\n // Convert an image into a png format for saving\n private base64ToBuffer(str: string): Uint8Array {\n const b = atob(str)\n const buf = new Uint8Array(b.length)\n\n for (let i = 0, l = buf.length; i < l; i++) {\n buf[i] = b.charCodeAt(i)\n }\n\n return buf\n }\n\n private imageToData(image: CanvasImageSource, ext: string): Uint8Array {\n this.canvas = this.canvas || document.createElement('canvas')\n this.ctx = this.ctx || this.canvas.getContext('2d')\n\n this.canvas.width = image.width instanceof SVGAnimatedLength ? 0 : image.width\n this.canvas.height = image.height instanceof SVGAnimatedLength ? 0 : image.height\n\n this.ctx?.drawImage(image, 0, 0)\n\n // Get the base64 encoded data\n const base64data = this.canvas.toDataURL(`image/${ext}`, 1).replace(/^data:image\\/(png|jpg);base64,/, '')\n\n // Convert to a uint8 array\n return this.base64ToBuffer(base64data)\n }\n\n // gets the attribute array. Generate a new array if the attribute is interleaved\n private attrBufferToArray(attr: InterleavedBufferAttribute | BufferAttribute): number[] | ArrayLike<number> {\n if (attr instanceof InterleavedBufferAttribute && attr.isInterleavedBufferAttribute) {\n // use the typed array constructor to save on memory\n const TypedArrayConstructor: TypedArrayConstructors = attr.array.constructor\n // @ts-ignore\n const arr: number[] = new TypedArrayConstructor(attr.count * attr.itemSize)\n const size = attr.itemSize\n\n for (let i = 0, l = attr.count; i < l; i++) {\n for (let j = 0; j < size; j++) {\n arr[i * size + j] = attr[this.getFuncs[j]](i)\n }\n }\n\n return arr\n } else {\n return attr.array\n }\n }\n\n // Returns an array of the same type starting at the `st` index,\n // and `ct` length\n private subArray(arr: number[] | ArrayLike<number>, st: number, ct: number): TypedArray | number[] {\n if (Array.isArray(arr)) {\n return arr.slice(st, st + ct)\n } else {\n const TypedArrayConstructor: TypedArrayConstructors = arr.constructor\n // @ts-ignore\n return new TypedArrayConstructor(arr.buffer, st * arr.BYTES_PER_ELEMENT, ct)\n }\n }\n\n // Returns the string for a geometry's attribute\n private getAttribute(\n attr: InterleavedBufferAttribute | BufferAttribute,\n name: string,\n params: string[],\n type: string,\n ): string {\n const array = this.attrBufferToArray(attr)\n const res = Array.isArray(array)\n ? `${\n `<source id=\"${name}\">` + `<float_array id=\"${name}-array\" count=\"${array.length}\">` + array.join(' ')\n }</float_array><technique_common>${`<accessor source=\"#${name}-array\" count=\"${Math.floor(\n array.length / attr.itemSize,\n )}\" stride=\"${attr.itemSize}\">`}${params\n .map((n) => `<param name=\"${n}\" type=\"${type}\" />`)\n .join('')}</accessor></technique_common></source>`\n : ''\n\n return res\n }\n\n // Returns the string for a node's transform information\n private getTransform(o: Object3D): string {\n // ensure the object's matrix is up to date\n // before saving the transform\n o.updateMatrix()\n\n this.transMat = this.transMat || new Matrix4()\n this.transMat.copy(o.matrix)\n this.transMat.transpose()\n return `<matrix>${this.transMat.toArray().join(' ')}</matrix>`\n }\n\n // Process the given piece of geometry into the geometry library\n // Returns the mesh id\n private processGeometry(g: BufferGeometry): GeometryInfo {\n let info = this.geometryInfo.get(g)\n\n if (!info) {\n // convert the geometry to bufferGeometry if it isn't already\n const bufferGeometry = g\n\n if (!bufferGeometry.isBufferGeometry) {\n throw new Error('THREE.ColladaExporter: Geometry is not of type THREE.BufferGeometry.')\n }\n\n const meshid = `Mesh${this.libraryGeometries.length + 1}`\n\n const indexCount = bufferGeometry.index\n ? bufferGeometry.index.count * bufferGeometry.index.itemSize\n : bufferGeometry.attributes.position.count\n\n const groups =\n bufferGeometry.groups != null && bufferGeometry.groups.length !== 0\n ? bufferGeometry.groups\n : [{ start: 0, count: indexCount, materialIndex: 0 }]\n\n const gname = g.name ? ` name=\"${g.name}\"` : ''\n let gnode = `<geometry id=\"${meshid}\"${gname}><mesh>`\n\n // define the geometry node and the vertices for the geometry\n const posName = `${meshid}-position`\n const vertName = `${meshid}-vertices`\n gnode += this.getAttribute(bufferGeometry.attributes.position, posName, ['X', 'Y', 'Z'], 'float')\n gnode += `<vertices id=\"${vertName}\"><input semantic=\"POSITION\" source=\"#${posName}\" /></vertices>`\n\n // NOTE: We're not optimizing the attribute arrays here, so they're all the same length and\n // can therefore share the same triangle indices. However, MeshLab seems to have trouble opening\n // models with attributes that share an offset.\n // MeshLab Bug#424: https://sourceforge.net/p/meshlab/bugs/424/\n\n // serialize normals\n let triangleInputs = `<input semantic=\"VERTEX\" source=\"#${vertName}\" offset=\"0\" />`\n if ('normal' in bufferGeometry.attributes) {\n const normName = `${meshid}-normal`\n gnode += this.getAttribute(bufferGeometry.attributes.normal, normName, ['X', 'Y', 'Z'], 'float')\n triangleInputs += `<input semantic=\"NORMAL\" source=\"#${normName}\" offset=\"0\" />`\n }\n\n // serialize uvs\n if ('uv' in bufferGeometry.attributes) {\n const uvName = `${meshid}-texcoord`\n gnode += this.getAttribute(bufferGeometry.attributes.uv, uvName, ['S', 'T'], 'float')\n triangleInputs += `<input semantic=\"TEXCOORD\" source=\"#${uvName}\" offset=\"0\" set=\"0\" />`\n }\n\n // serialize lightmap uvs\n if ('uv2' in bufferGeometry.attributes) {\n const uvName = `${meshid}-texcoord2`\n gnode += this.getAttribute(bufferGeometry.attributes.uv2, uvName, ['S', 'T'], 'float')\n triangleInputs += `<input semantic=\"TEXCOORD\" source=\"#${uvName}\" offset=\"0\" set=\"1\" />`\n }\n\n // serialize colors\n if ('color' in bufferGeometry.attributes) {\n const colName = `${meshid}-color`\n gnode += this.getAttribute(bufferGeometry.attributes.color, colName, ['X', 'Y', 'Z'], 'uint8')\n triangleInputs += `<input semantic=\"COLOR\" source=\"#${colName}\" offset=\"0\" />`\n }\n\n let indexArray: number[] | ArrayLike<number> | null = null\n if (bufferGeometry.index) {\n indexArray = this.attrBufferToArray(bufferGeometry.index)\n } else {\n indexArray = new Array(indexCount)\n for (let i = 0, l = indexArray.length; i < l && Array.isArray(indexArray); i++) indexArray[i] = i\n }\n\n for (let i = 0, l = groups.length; i < l; i++) {\n const group = groups[i]\n const subarr = this.subArray(indexArray, group.start, group.count)\n const polycount = subarr.length / 3\n gnode += `<triangles material=\"MESH_MATERIAL_${group.materialIndex}\" count=\"${polycount}\">`\n gnode += triangleInputs\n\n gnode += `<p>${subarr.join(' ')}</p>`\n gnode += '</triangles>'\n }\n\n gnode += '</mesh></geometry>'\n\n this.libraryGeometries.push(gnode)\n\n info = { meshid, bufferGeometry }\n this.geometryInfo.set(g, info)\n }\n\n return info\n }\n\n // Process the given texture into the image library\n // Returns the image library\n private processTexture(tex: Texture): string {\n let texid = this.imageMap.get(tex)\n if (texid == null) {\n texid = `image-${this.libraryImages.length + 1}`\n\n const ext = 'png'\n const name = tex.name || texid\n let imageNode = `<image id=\"${texid}\" name=\"${name}\">`\n\n if (this.options.version === '1.5.0') {\n imageNode += `<init_from><ref>${this.options.textureDirectory}${name}.${ext}</ref></init_from>`\n } else {\n // version image node 1.4.1\n imageNode += `<init_from>${this.options.textureDirectory}${name}.${ext}</init_from>`\n }\n\n imageNode += '</image>'\n\n this.libraryImages.push(imageNode)\n this.imageMap.set(tex, texid)\n this.textures.push({\n directory: this.options.textureDirectory,\n name,\n ext,\n data: this.imageToData(tex.image, ext),\n original: tex,\n })\n }\n\n return texid\n }\n\n // Process the given material into the material and effect libraries\n // Returns the material id\n private processMaterial(m: MaterialRepresentation): string {\n let matid = this.materialMap.get(m)\n\n if (matid == null) {\n matid = `Mat${this.libraryEffects.length + 1}`\n\n let type = 'phong'\n\n if (m instanceof MeshLambertMaterial) {\n type = 'lambert'\n } else if (m instanceof MeshBasicMaterial) {\n type = 'constant'\n\n if (m.map !== null) {\n // The Collada spec does not support diffuse texture maps with the\n // constant shader type.\n // mrdoob/three.js#15469\n console.warn('ColladaExporter: Texture maps not supported with MeshBasicMaterial.')\n }\n }\n\n if (m instanceof MeshPhongMaterial) {\n const emissive = m.emissive ? m.emissive : new Color(0, 0, 0)\n const diffuse = m.color ? m.color : new Color(0, 0, 0)\n const specular = m.specular ? m.specular : new Color(1, 1, 1)\n const shininess = m.shininess || 0\n const reflectivity = m.reflectivity || 0\n\n // Do not export and alpha map for the reasons mentioned in issue (#13792)\n // in three.js alpha maps are black and white, but collada expects the alpha\n // channel to specify the transparency\n let transparencyNode = ''\n if (m.transparent) {\n transparencyNode += `<transparent>${\n m.map ? '<texture texture=\"diffuse-sampler\"></texture>' : '<float>1</float>'\n }</transparent>`\n\n if (m.opacity < 1) {\n transparencyNode += `<transparency><float>${m.opacity}</float></transparency>`\n }\n }\n\n const techniqueNode = `${`<technique sid=\"common\"><${type}>`}<emission>${\n m.emissiveMap\n ? '<texture texture=\"emissive-sampler\" texcoord=\"TEXCOORD\" />'\n : `<color sid=\"emission\">${emissive.r} ${emissive.g} ${emissive.b} 1</color>`\n }</emission>${\n type !== 'constant'\n ? `<diffuse>${\n m.map\n ? '<texture texture=\"diffuse-sampler\" texcoord=\"TEXCOORD\" />'\n : `<color sid=\"diffuse\">${diffuse.r} ${diffuse.g} ${diffuse.b} 1</color>`\n }</diffuse>`\n : ''\n }${\n type !== 'constant'\n ? `<bump>${m.normalMap ? '<texture texture=\"bump-sampler\" texcoord=\"TEXCOORD\" />' : ''}</bump>`\n : ''\n }${\n type === 'phong'\n ? `${`<specular><color sid=\"specular\">${specular.r} ${specular.g} ${specular.b} 1</color></specular>`}<shininess>${\n m.specularMap\n ? '<texture texture=\"specular-sampler\" texcoord=\"TEXCOORD\" />'\n : `<float sid=\"shininess\">${shininess}</float>`\n }</shininess>`\n : ''\n }${`<reflective><color>${diffuse.r} ${diffuse.g} ${diffuse.b} 1</color></reflective>`}${`<reflectivity><float>${reflectivity}</float></reflectivity>`}${transparencyNode}${`</${type}></technique>`}`\n\n const effectnode = `${`<effect id=\"${matid}-effect\">`}<profile_COMMON>${\n m.map\n ? `<newparam sid=\"diffuse-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.map,\n )}</init_from>`}</surface></newparam><newparam sid=\"diffuse-sampler\"><sampler2D><source>diffuse-surface</source></sampler2D></newparam>`\n : ''\n }${\n m.specularMap\n ? `<newparam sid=\"specular-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.specularMap,\n )}</init_from>`}</surface></newparam><newparam sid=\"specular-sampler\"><sampler2D><source>specular-surface</source></sampler2D></newparam>`\n : ''\n }${\n m.emissiveMap\n ? `<newparam sid=\"emissive-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.emissiveMap,\n )}</init_from>`}</surface></newparam><newparam sid=\"emissive-sampler\"><sampler2D><source>emissive-surface</source></sampler2D></newparam>`\n : ''\n }${\n m.normalMap\n ? `<newparam sid=\"bump-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.normalMap,\n )}</init_from>`}</surface></newparam><newparam sid=\"bump-sampler\"><sampler2D><source>bump-surface</source></sampler2D></newparam>`\n : ''\n }${techniqueNode}${\n m.side === DoubleSide\n ? '<extra><technique profile=\"THREEJS\"><double_sided sid=\"double_sided\" type=\"int\">1</double_sided></technique></extra>'\n : ''\n }</profile_COMMON></effect>`\n\n const materialName = m.name ? ` name=\"${m.name}\"` : ''\n const materialNode = `<material id=\"${matid}\"${materialName}><instance_effect url=\"#${matid}-effect\" /></material>`\n\n this.libraryMaterials.push(materialNode)\n this.libraryEffects.push(effectnode)\n this.materialMap.set(m, matid)\n }\n }\n\n return matid\n }\n\n // Recursively process the object into a scene\n private processObject(o: Object3D): string {\n let node = `<node name=\"${o.name}\">`\n\n node += this.getTransform(o)\n const a: Mesh<BufferGeometry, Material | Material[]> = new Mesh()\n a.geometry\n\n if (o instanceof Mesh && o.isMesh && o.geometry !== null) {\n // function returns the id associated with the mesh and a \"BufferGeometry\" version\n // of the geometry in case it's not a geometry.\n const geomInfo = this.processGeometry(o.geometry)\n const meshid = geomInfo.meshid\n const geometry = geomInfo.bufferGeometry\n\n // ids of the materials to bind to the geometry\n let matids = null\n let matidsArray\n\n // get a list of materials to bind to the sub groups of the geometry.\n // If the amount of subgroups is greater than the materials, than reuse\n // the materials.\n const mat: MaterialRepresentation | MaterialRepresentation[] = o.material || new MeshBasicMaterial()\n const materials = Array.isArray(mat) ? mat : [mat]\n\n if (geometry.groups.length > materials.length) {\n matidsArray = new Array(geometry.groups.length)\n } else {\n matidsArray = new Array(materials.length)\n }\n\n matids = matidsArray.fill(null).map((_, i) => this.processMaterial(materials[i % materials.length]))\n\n node += `${\n `<instance_geometry url=\"#${meshid}\">` +\n (matids != null\n ? `<bind_material><technique_common>${matids\n .map(\n (id, i) =>\n `${`<instance_material symbol=\"MESH_MATERIAL_${i}\" target=\"#${id}\" >`}<bind_vertex_input semantic=\"TEXCOORD\" input_semantic=\"TEXCOORD\" input_set=\"0\" /></instance_material>`,\n )\n .join('')}</technique_common></bind_material>`\n : '')\n }</instance_geometry>`\n }\n\n o.children.forEach((c) => (node += this.processObject(c)))\n\n node += '</node>'\n\n return node\n }\n}\n\nexport { ColladaExporter }\n"],"names":["InterleavedBufferAttribute","Matrix4","MeshLambertMaterial","MeshBasicMaterial","MeshPhongMaterial","Color","DoubleSide","Mesh"],"mappings":";;;;;;;;;AA4CA,MAAM,gBAAgB;AAAA,EAiCpB,cAAc;AAhCN;AASA;AACA;AACA;AACA;AAQA;AACA;AACA;AACA;AA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U,OACP,oCAAoC,OACjC;AAAA,QACC,CAAC,IAAI,MACH,GAAG,4CAA4C,eAAe;AAAA,MAAA,EAEjE,KAAK,EAAE,yCACV;AAAA,IAER;AAEE,MAAA,SAAS,QAAQ,CAAC,MAAO,QAAQ,KAAK,cAAc,CAAC,CAAE;AAEjD,YAAA;AAED,WAAA;AAAA,EACT;AACF;;"}
|
1
|
+
{"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><contributor><authoring_tool>three.js Collada Exporter</authoring_tool>${\n this.options.author !== null ? `<author>${this.options.author}</author>` : ''\n }</contributor>${`<created>${new Date().toISOString()}</created>`}${`<modified>${new Date().toISOString()}</modified>`}<up_axis>Y_UP</up_axis></asset>`\n\n dae += `<library_images>${this.libraryImages.join('')}</library_images>`\n\n dae += `<library_effects>${this.libraryEffects.join('')}</library_effects>`\n\n dae += `<library_materials>${this.libraryMaterials.join('')}</library_materials>`\n\n dae += `<library_geometries>${this.libraryGeometries.join('')}</library_geometries>`\n\n dae += `<library_visual_scenes><visual_scene id=\"Scene\" name=\"scene\">${libraryVisualScenes}</visual_scene></library_visual_scenes>`\n\n dae += '<scene><instance_visual_scene url=\"#Scene\"/></scene>'\n\n dae += '</COLLADA>'\n\n const res = {\n data: this.format(dae),\n textures: this.textures,\n }\n\n if (typeof onDone === 'function') {\n requestAnimationFrame(() => onDone(res))\n }\n\n return res\n }\n\n // Convert the urdf xml into a well-formatted, indented format\n private format(urdf: string): string {\n const IS_END_TAG = /^<\\//\n const IS_SELF_CLOSING = /(\\?>$)|(\\/>$)/\n const HAS_TEXT = /<[^>]+>[^<]*<\\/[^<]+>/\n\n const pad = (ch: string, num: number): string => (num > 0 ? ch + pad(ch, num - 1) : '')\n\n let tagnum = 0\n\n return (\n urdf\n .match(/(<[^>]+>[^<]+<\\/[^<]+>)|(<[^>]+>)/g)\n ?.map((tag) => {\n if (!HAS_TEXT.test(tag) && !IS_SELF_CLOSING.test(tag) && IS_END_TAG.test(tag)) {\n tagnum--\n }\n\n const res = `${pad(' ', tagnum)}${tag}`\n\n if (!HAS_TEXT.test(tag) && !IS_SELF_CLOSING.test(tag) && !IS_END_TAG.test(tag)) {\n tagnum++\n }\n\n return res\n })\n .join('\\n') ?? ''\n )\n }\n\n // Convert an image into a png format for saving\n private base64ToBuffer(str: string): Uint8Array {\n const b = atob(str)\n const buf = new Uint8Array(b.length)\n\n for (let i = 0, l = buf.length; i < l; i++) {\n buf[i] = b.charCodeAt(i)\n }\n\n return buf\n }\n\n private imageToData(image: CanvasImageSource, ext: string): Uint8Array {\n this.canvas = this.canvas || document.createElement('canvas')\n this.ctx = this.ctx || this.canvas.getContext('2d')\n\n this.canvas.width = image.width instanceof SVGAnimatedLength ? 0 : image.width\n this.canvas.height = image.height instanceof SVGAnimatedLength ? 0 : image.height\n\n this.ctx?.drawImage(image, 0, 0)\n\n // Get the base64 encoded data\n const base64data = this.canvas.toDataURL(`image/${ext}`, 1).replace(/^data:image\\/(png|jpg);base64,/, '')\n\n // Convert to a uint8 array\n return this.base64ToBuffer(base64data)\n }\n\n // gets the attribute array. Generate a new array if the attribute is interleaved\n private attrBufferToArray(attr: InterleavedBufferAttribute | BufferAttribute): number[] | ArrayLike<number> {\n if (attr instanceof InterleavedBufferAttribute && attr.isInterleavedBufferAttribute) {\n // use the typed array constructor to save on memory\n const TypedArrayConstructor: TypedArrayConstructors = attr.array.constructor\n // @ts-ignore\n const arr: number[] = new TypedArrayConstructor(attr.count * attr.itemSize)\n const size = attr.itemSize\n\n for (let i = 0, l = attr.count; i < l; i++) {\n for (let j = 0; j < size; j++) {\n arr[i * size + j] = attr[this.getFuncs[j]](i)\n }\n }\n\n return arr\n } else {\n return attr.array\n }\n }\n\n // Returns an array of the same type starting at the `st` index,\n // and `ct` length\n private subArray(arr: number[] | ArrayLike<number>, st: number, ct: number): TypedArray | number[] {\n if (Array.isArray(arr)) {\n return arr.slice(st, st + ct)\n } else {\n const TypedArrayConstructor: TypedArrayConstructors = arr.constructor\n // @ts-ignore\n return new TypedArrayConstructor(arr.buffer, st * arr.BYTES_PER_ELEMENT, ct)\n }\n }\n\n // Returns the string for a geometry's attribute\n private getAttribute(\n attr: InterleavedBufferAttribute | BufferAttribute,\n name: string,\n params: string[],\n type: string,\n ): string {\n const array = this.attrBufferToArray(attr)\n const res = Array.isArray(array)\n ? `${\n `<source id=\"${name}\">` + `<float_array id=\"${name}-array\" count=\"${array.length}\">` + array.join(' ')\n }</float_array><technique_common>${`<accessor source=\"#${name}-array\" count=\"${Math.floor(\n array.length / attr.itemSize,\n )}\" stride=\"${attr.itemSize}\">`}${params\n .map((n) => `<param name=\"${n}\" type=\"${type}\" />`)\n .join('')}</accessor></technique_common></source>`\n : ''\n\n return res\n }\n\n // Returns the string for a node's transform information\n private getTransform(o: Object3D): string {\n // ensure the object's matrix is up to date\n // before saving the transform\n o.updateMatrix()\n\n this.transMat = this.transMat || new Matrix4()\n this.transMat.copy(o.matrix)\n this.transMat.transpose()\n return `<matrix>${this.transMat.toArray().join(' ')}</matrix>`\n }\n\n // Process the given piece of geometry into the geometry library\n // Returns the mesh id\n private processGeometry(g: BufferGeometry): GeometryInfo {\n let info = this.geometryInfo.get(g)\n\n if (!info) {\n // convert the geometry to bufferGeometry if it isn't already\n const bufferGeometry = g\n\n if (!bufferGeometry.isBufferGeometry) {\n throw new Error('THREE.ColladaExporter: Geometry is not of type THREE.BufferGeometry.')\n }\n\n const meshid = `Mesh${this.libraryGeometries.length + 1}`\n\n const indexCount = bufferGeometry.index\n ? bufferGeometry.index.count * bufferGeometry.index.itemSize\n : bufferGeometry.attributes.position.count\n\n const groups =\n bufferGeometry.groups != null && bufferGeometry.groups.length !== 0\n ? bufferGeometry.groups\n : [{ start: 0, count: indexCount, materialIndex: 0 }]\n\n const gname = g.name ? ` name=\"${g.name}\"` : ''\n let gnode = `<geometry id=\"${meshid}\"${gname}><mesh>`\n\n // define the geometry node and the vertices for the geometry\n const posName = `${meshid}-position`\n const vertName = `${meshid}-vertices`\n gnode += this.getAttribute(bufferGeometry.attributes.position, posName, ['X', 'Y', 'Z'], 'float')\n gnode += `<vertices id=\"${vertName}\"><input semantic=\"POSITION\" source=\"#${posName}\" /></vertices>`\n\n // NOTE: We're not optimizing the attribute arrays here, so they're all the same length and\n // can therefore share the same triangle indices. However, MeshLab seems to have trouble opening\n // models with attributes that share an offset.\n // MeshLab Bug#424: https://sourceforge.net/p/meshlab/bugs/424/\n\n // serialize normals\n let triangleInputs = `<input semantic=\"VERTEX\" source=\"#${vertName}\" offset=\"0\" />`\n if ('normal' in bufferGeometry.attributes) {\n const normName = `${meshid}-normal`\n gnode += this.getAttribute(bufferGeometry.attributes.normal, normName, ['X', 'Y', 'Z'], 'float')\n triangleInputs += `<input semantic=\"NORMAL\" source=\"#${normName}\" offset=\"0\" />`\n }\n\n // serialize uvs\n if ('uv' in bufferGeometry.attributes) {\n const uvName = `${meshid}-texcoord`\n gnode += this.getAttribute(bufferGeometry.attributes.uv, uvName, ['S', 'T'], 'float')\n triangleInputs += `<input semantic=\"TEXCOORD\" source=\"#${uvName}\" offset=\"0\" set=\"0\" />`\n }\n\n // serialize lightmap uvs\n if (UV1 in bufferGeometry.attributes) {\n const uvName = `${meshid}-texcoord2`\n gnode += this.getAttribute(bufferGeometry.attributes[UV1], uvName, ['S', 'T'], 'float')\n triangleInputs += `<input semantic=\"TEXCOORD\" source=\"#${uvName}\" offset=\"0\" set=\"1\" />`\n }\n\n // serialize colors\n if ('color' in bufferGeometry.attributes) {\n const colName = `${meshid}-color`\n gnode += this.getAttribute(bufferGeometry.attributes.color, colName, ['X', 'Y', 'Z'], 'uint8')\n triangleInputs += `<input semantic=\"COLOR\" source=\"#${colName}\" offset=\"0\" />`\n }\n\n let indexArray: number[] | ArrayLike<number> | null = null\n if (bufferGeometry.index) {\n indexArray = this.attrBufferToArray(bufferGeometry.index)\n } else {\n indexArray = new Array(indexCount)\n for (let i = 0, l = indexArray.length; i < l && Array.isArray(indexArray); i++) indexArray[i] = i\n }\n\n for (let i = 0, l = groups.length; i < l; i++) {\n const group = groups[i]\n const subarr = this.subArray(indexArray, group.start, group.count)\n const polycount = subarr.length / 3\n gnode += `<triangles material=\"MESH_MATERIAL_${group.materialIndex}\" count=\"${polycount}\">`\n gnode += triangleInputs\n\n gnode += `<p>${subarr.join(' ')}</p>`\n gnode += '</triangles>'\n }\n\n gnode += '</mesh></geometry>'\n\n this.libraryGeometries.push(gnode)\n\n info = { meshid, bufferGeometry }\n this.geometryInfo.set(g, info)\n }\n\n return info\n }\n\n // Process the given texture into the image library\n // Returns the image library\n private processTexture(tex: Texture): string {\n let texid = this.imageMap.get(tex)\n if (texid == null) {\n texid = `image-${this.libraryImages.length + 1}`\n\n const ext = 'png'\n const name = tex.name || texid\n let imageNode = `<image id=\"${texid}\" name=\"${name}\">`\n\n if (this.options.version === '1.5.0') {\n imageNode += `<init_from><ref>${this.options.textureDirectory}${name}.${ext}</ref></init_from>`\n } else {\n // version image node 1.4.1\n imageNode += `<init_from>${this.options.textureDirectory}${name}.${ext}</init_from>`\n }\n\n imageNode += '</image>'\n\n this.libraryImages.push(imageNode)\n this.imageMap.set(tex, texid)\n this.textures.push({\n directory: this.options.textureDirectory,\n name,\n ext,\n data: this.imageToData(tex.image, ext),\n original: tex,\n })\n }\n\n return texid\n }\n\n // Process the given material into the material and effect libraries\n // Returns the material id\n private processMaterial(m: MaterialRepresentation): string {\n let matid = this.materialMap.get(m)\n\n if (matid == null) {\n matid = `Mat${this.libraryEffects.length + 1}`\n\n let type = 'phong'\n\n if (m instanceof MeshLambertMaterial) {\n type = 'lambert'\n } else if (m instanceof MeshBasicMaterial) {\n type = 'constant'\n\n if (m.map !== null) {\n // The Collada spec does not support diffuse texture maps with the\n // constant shader type.\n // mrdoob/three.js#15469\n console.warn('ColladaExporter: Texture maps not supported with MeshBasicMaterial.')\n }\n }\n\n if (m instanceof MeshPhongMaterial) {\n const emissive = m.emissive ? m.emissive : new Color(0, 0, 0)\n const diffuse = m.color ? m.color : new Color(0, 0, 0)\n const specular = m.specular ? m.specular : new Color(1, 1, 1)\n const shininess = m.shininess || 0\n const reflectivity = m.reflectivity || 0\n\n // Do not export and alpha map for the reasons mentioned in issue (#13792)\n // in three.js alpha maps are black and white, but collada expects the alpha\n // channel to specify the transparency\n let transparencyNode = ''\n if (m.transparent) {\n transparencyNode += `<transparent>${\n m.map ? '<texture texture=\"diffuse-sampler\"></texture>' : '<float>1</float>'\n }</transparent>`\n\n if (m.opacity < 1) {\n transparencyNode += `<transparency><float>${m.opacity}</float></transparency>`\n }\n }\n\n const techniqueNode = `${`<technique sid=\"common\"><${type}>`}<emission>${\n m.emissiveMap\n ? '<texture texture=\"emissive-sampler\" texcoord=\"TEXCOORD\" />'\n : `<color sid=\"emission\">${emissive.r} ${emissive.g} ${emissive.b} 1</color>`\n }</emission>${\n type !== 'constant'\n ? `<diffuse>${\n m.map\n ? '<texture texture=\"diffuse-sampler\" texcoord=\"TEXCOORD\" />'\n : `<color sid=\"diffuse\">${diffuse.r} ${diffuse.g} ${diffuse.b} 1</color>`\n }</diffuse>`\n : ''\n }${\n type !== 'constant'\n ? `<bump>${m.normalMap ? '<texture texture=\"bump-sampler\" texcoord=\"TEXCOORD\" />' : ''}</bump>`\n : ''\n }${\n type === 'phong'\n ? `${`<specular><color sid=\"specular\">${specular.r} ${specular.g} ${specular.b} 1</color></specular>`}<shininess>${\n m.specularMap\n ? '<texture texture=\"specular-sampler\" texcoord=\"TEXCOORD\" />'\n : `<float sid=\"shininess\">${shininess}</float>`\n }</shininess>`\n : ''\n }${`<reflective><color>${diffuse.r} ${diffuse.g} ${diffuse.b} 1</color></reflective>`}${`<reflectivity><float>${reflectivity}</float></reflectivity>`}${transparencyNode}${`</${type}></technique>`}`\n\n const effectnode = `${`<effect id=\"${matid}-effect\">`}<profile_COMMON>${\n m.map\n ? `<newparam sid=\"diffuse-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.map,\n )}</init_from>`}</surface></newparam><newparam sid=\"diffuse-sampler\"><sampler2D><source>diffuse-surface</source></sampler2D></newparam>`\n : ''\n }${\n m.specularMap\n ? `<newparam sid=\"specular-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.specularMap,\n )}</init_from>`}</surface></newparam><newparam sid=\"specular-sampler\"><sampler2D><source>specular-surface</source></sampler2D></newparam>`\n : ''\n }${\n m.emissiveMap\n ? `<newparam sid=\"emissive-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.emissiveMap,\n )}</init_from>`}</surface></newparam><newparam sid=\"emissive-sampler\"><sampler2D><source>emissive-surface</source></sampler2D></newparam>`\n : ''\n }${\n m.normalMap\n ? `<newparam sid=\"bump-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.normalMap,\n )}</init_from>`}</surface></newparam><newparam sid=\"bump-sampler\"><sampler2D><source>bump-surface</source></sampler2D></newparam>`\n : ''\n }${techniqueNode}${\n m.side === DoubleSide\n ? '<extra><technique profile=\"THREEJS\"><double_sided sid=\"double_sided\" type=\"int\">1</double_sided></technique></extra>'\n : ''\n }</profile_COMMON></effect>`\n\n const materialName = m.name ? ` name=\"${m.name}\"` : ''\n const materialNode = `<material id=\"${matid}\"${materialName}><instance_effect url=\"#${matid}-effect\" /></material>`\n\n this.libraryMaterials.push(materialNode)\n this.libraryEffects.push(effectnode)\n this.materialMap.set(m, matid)\n }\n }\n\n return matid\n }\n\n // Recursively process the object into a scene\n private processObject(o: Object3D): string {\n let node = `<node name=\"${o.name}\">`\n\n node += this.getTransform(o)\n const a: Mesh<BufferGeometry, Material | Material[]> = new Mesh()\n a.geometry\n\n if (o instanceof Mesh && o.isMesh && o.geometry !== null) {\n // function returns the id associated with the mesh and a \"BufferGeometry\" version\n // of the geometry in case it's not a geometry.\n const geomInfo = this.processGeometry(o.geometry)\n const meshid = geomInfo.meshid\n const geometry = geomInfo.bufferGeometry\n\n // ids of the materials to bind to the geometry\n let matids = null\n let matidsArray\n\n // get a list of materials to bind to the sub groups of the geometry.\n // If the amount of subgroups is greater than the materials, than reuse\n // the materials.\n const mat: MaterialRepresentation | MaterialRepresentation[] = o.material || new MeshBasicMaterial()\n const materials = Array.isArray(mat) ? mat : [mat]\n\n if (geometry.groups.length > materials.length) {\n matidsArray = new Array(geometry.groups.length)\n } else {\n matidsArray = new Array(materials.length)\n }\n\n matids = matidsArray.fill(null).map((_, i) => this.processMaterial(materials[i % materials.length]))\n\n node += `${\n `<instance_geometry url=\"#${meshid}\">` +\n (matids != null\n ? `<bind_material><technique_common>${matids\n .map(\n (id, i) =>\n `${`<instance_material symbol=\"MESH_MATERIAL_${i}\" target=\"#${id}\" >`}<bind_vertex_input semantic=\"TEXCOORD\" input_semantic=\"TEXCOORD\" input_set=\"0\" /></instance_material>`,\n )\n .join('')}</technique_common></bind_material>`\n : '')\n }</instance_geometry>`\n }\n\n o.children.forEach((c) => (node += this.processObject(c)))\n\n node += '</node>'\n\n return node\n }\n}\n\nexport { ColladaExporter }\n"],"names":["InterleavedBufferAttribute","Matrix4","UV1","MeshLambertMaterial","MeshBasicMaterial","MeshPhongMaterial","Color","DoubleSide","Mesh"],"mappings":";;;;;;;;;;AA6CA,MAAM,gBAAgB;AAAA,EAiCpB,cAAc;AAhCN;AASA;AACA;AACA;AACA;AAQA;AACA;AACA;AACA;AAEA;AACA;AAEA;AAEA,oCAAW,CAAC,QAAQ,QAAQ,QAAQ,MAAM;AAGhD,SAAK,UAAU;AAAA,MACb,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,kBAAkB;AAAA,MAClB,QAAQ;AAAA,MACR,UAAU;AAAA,MACV,WAAW;AAAA,IAAA;AAGR,SAAA,mCAAmB;AACnB,SAAA,kCAAkB;AAClB,SAAA,+BAAe;AACpB,SAAK,WAAW;AAEhB,SAAK,gBAAgB;AACrB,SAAK,oBAAoB;AACzB,SAAK,iBAAiB;AACtB,SAAK,mBAAmB;AAExB,SAAK,SAAS;AACd,SAAK,MAAM;AAEX,SAAK,WAAW;AAAA,EAClB;AAAA,EAEO,MACL,QACA,QACA,UAAkC,CAAA,GACJ;AAC9B,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,GAAG;AAErC,QAAI,KAAK,QAAQ,OAAO,MAAM,YAAY,MAAM,MAAM;AACpD,cAAQ,MAAM,uEAAuE;AAC9E,aAAA;AAAA,IACT;AAEA,QAAI,KAAK,QAAQ,aAAa,QAAQ,KAAK,QAAQ,cAAc,MAAM;AACrE,cAAQ,MAAM,4EAA4E;AACnF,aAAA;AAAA,IACT;AAEA,QAAI,KAAK,QAAQ,cAAc,QAAQ,KAAK,QAAQ,aAAa,MAAM;AACrE,cAAQ,MAAM,4EAA4E;AACnF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YAAM,MAAyD,EAAE,YAAY,IAAIJ,MAAkB,kBAAA;AACnG,YAAM,YAAY,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG;AAEjD,UAAI,SAAS,OAAO,SAAS,UAAU,QAAQ;AAC7C,sBAAc,IAAI,MAAM,SAAS,OAAO,MAAM;AAAA,MAAA,OACzC;AACS,sBAAA,IAAI,MAAM,UAAU,MAAM;AAAA,MAC1C;AAEA,eAAS,YAAY,KAAK,IAAI,EAAE,IAAI,CAAC,GAAG,MAAM,KAAK,gBAAgB,UAAU,IAAI,UAAU,MAAM,CAAC,CAAC;AAEnG,cAAQ,GACN,4BAA4B,cAC3B,UAAU,OACP,oCAAoC,OACjC;AAAA,QACC,CAAC,IAAI,MACH,GAAG,4CAA4C,eAAe;AAAA,MAAA,EAEjE,KAAK,EAAE,yCACV;AAAA,IAER;AAEE,MAAA,SAAS,QAAQ,CAAC,MAAO,QAAQ,KAAK,cAAc,CAAC,CAAE;AAEjD,YAAA;AAED,WAAA;AAAA,EACT;AACF;;"}
|
@@ -5,6 +5,7 @@ var __publicField = (obj, key, value) => {
|
|
5
5
|
return value;
|
6
6
|
};
|
7
7
|
import { InterleavedBufferAttribute, Matrix4, MeshLambertMaterial, MeshBasicMaterial, MeshPhongMaterial, Color, DoubleSide, Mesh } from "three";
|
8
|
+
import { UV1 } from "../_polyfill/uv1.js";
|
8
9
|
class ColladaExporter {
|
9
10
|
constructor() {
|
10
11
|
__publicField(this, "options");
|
@@ -189,9 +190,9 @@ class ColladaExporter {
|
|
189
190
|
gnode += this.getAttribute(bufferGeometry.attributes.uv, uvName, ["S", "T"], "float");
|
190
191
|
triangleInputs += `<input semantic="TEXCOORD" source="#${uvName}" offset="0" set="0" />`;
|
191
192
|
}
|
192
|
-
if (
|
193
|
+
if (UV1 in bufferGeometry.attributes) {
|
193
194
|
const uvName = `${meshid}-texcoord2`;
|
194
|
-
gnode += this.getAttribute(bufferGeometry.attributes
|
195
|
+
gnode += this.getAttribute(bufferGeometry.attributes[UV1], uvName, ["S", "T"], "float");
|
195
196
|
triangleInputs += `<input semantic="TEXCOORD" source="#${uvName}" offset="0" set="1" />`;
|
196
197
|
}
|
197
198
|
if ("color" in bufferGeometry.attributes) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ColladaExporter.js","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'\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><contributor><authoring_tool>three.js Collada Exporter</authoring_tool>${\n this.options.author !== null ? `<author>${this.options.author}</author>` : ''\n }</contributor>${`<created>${new Date().toISOString()}</created>`}${`<modified>${new Date().toISOString()}</modified>`}<up_axis>Y_UP</up_axis></asset>`\n\n dae += `<library_images>${this.libraryImages.join('')}</library_images>`\n\n dae += `<library_effects>${this.libraryEffects.join('')}</library_effects>`\n\n dae += `<library_materials>${this.libraryMaterials.join('')}</library_materials>`\n\n dae += `<library_geometries>${this.libraryGeometries.join('')}</library_geometries>`\n\n dae += `<library_visual_scenes><visual_scene id=\"Scene\" name=\"scene\">${libraryVisualScenes}</visual_scene></library_visual_scenes>`\n\n dae += '<scene><instance_visual_scene url=\"#Scene\"/></scene>'\n\n dae += '</COLLADA>'\n\n const res = {\n data: this.format(dae),\n textures: this.textures,\n }\n\n if (typeof onDone === 'function') {\n requestAnimationFrame(() => onDone(res))\n }\n\n return res\n }\n\n // Convert the urdf xml into a well-formatted, indented format\n private format(urdf: string): string {\n const IS_END_TAG = /^<\\//\n const IS_SELF_CLOSING = /(\\?>$)|(\\/>$)/\n const HAS_TEXT = /<[^>]+>[^<]*<\\/[^<]+>/\n\n const pad = (ch: string, num: number): string => (num > 0 ? ch + pad(ch, num - 1) : '')\n\n let tagnum = 0\n\n return (\n urdf\n .match(/(<[^>]+>[^<]+<\\/[^<]+>)|(<[^>]+>)/g)\n ?.map((tag) => {\n if (!HAS_TEXT.test(tag) && !IS_SELF_CLOSING.test(tag) && IS_END_TAG.test(tag)) {\n tagnum--\n }\n\n const res = `${pad(' ', tagnum)}${tag}`\n\n if (!HAS_TEXT.test(tag) && !IS_SELF_CLOSING.test(tag) && !IS_END_TAG.test(tag)) {\n tagnum++\n }\n\n return res\n })\n .join('\\n') ?? ''\n )\n }\n\n // Convert an image into a png format for saving\n private base64ToBuffer(str: string): Uint8Array {\n const b = atob(str)\n const buf = new Uint8Array(b.length)\n\n for (let i = 0, l = buf.length; i < l; i++) {\n buf[i] = b.charCodeAt(i)\n }\n\n return buf\n }\n\n private imageToData(image: CanvasImageSource, ext: string): Uint8Array {\n this.canvas = this.canvas || document.createElement('canvas')\n this.ctx = this.ctx || this.canvas.getContext('2d')\n\n this.canvas.width = image.width instanceof SVGAnimatedLength ? 0 : image.width\n this.canvas.height = image.height instanceof SVGAnimatedLength ? 0 : image.height\n\n this.ctx?.drawImage(image, 0, 0)\n\n // Get the base64 encoded data\n const base64data = this.canvas.toDataURL(`image/${ext}`, 1).replace(/^data:image\\/(png|jpg);base64,/, '')\n\n // Convert to a uint8 array\n return this.base64ToBuffer(base64data)\n }\n\n // gets the attribute array. Generate a new array if the attribute is interleaved\n private attrBufferToArray(attr: InterleavedBufferAttribute | BufferAttribute): number[] | ArrayLike<number> {\n if (attr instanceof InterleavedBufferAttribute && attr.isInterleavedBufferAttribute) {\n // use the typed array constructor to save on memory\n const TypedArrayConstructor: TypedArrayConstructors = attr.array.constructor\n // @ts-ignore\n const arr: number[] = new TypedArrayConstructor(attr.count * attr.itemSize)\n const size = attr.itemSize\n\n for (let i = 0, l = attr.count; i < l; i++) {\n for (let j = 0; j < size; j++) {\n arr[i * size + j] = attr[this.getFuncs[j]](i)\n }\n }\n\n return arr\n } else {\n return attr.array\n }\n }\n\n // Returns an array of the same type starting at the `st` index,\n // and `ct` length\n private subArray(arr: number[] | ArrayLike<number>, st: number, ct: number): TypedArray | number[] {\n if (Array.isArray(arr)) {\n return arr.slice(st, st + ct)\n } else {\n const TypedArrayConstructor: TypedArrayConstructors = arr.constructor\n // @ts-ignore\n return new TypedArrayConstructor(arr.buffer, st * arr.BYTES_PER_ELEMENT, ct)\n }\n }\n\n // Returns the string for a geometry's attribute\n private getAttribute(\n attr: InterleavedBufferAttribute | BufferAttribute,\n name: string,\n params: string[],\n type: string,\n ): string {\n const array = this.attrBufferToArray(attr)\n const res = Array.isArray(array)\n ? `${\n `<source id=\"${name}\">` + `<float_array id=\"${name}-array\" count=\"${array.length}\">` + array.join(' ')\n }</float_array><technique_common>${`<accessor source=\"#${name}-array\" count=\"${Math.floor(\n array.length / attr.itemSize,\n )}\" stride=\"${attr.itemSize}\">`}${params\n .map((n) => `<param name=\"${n}\" type=\"${type}\" />`)\n .join('')}</accessor></technique_common></source>`\n : ''\n\n return res\n }\n\n // Returns the string for a node's transform information\n private getTransform(o: Object3D): string {\n // ensure the object's matrix is up to date\n // before saving the transform\n o.updateMatrix()\n\n this.transMat = this.transMat || new Matrix4()\n this.transMat.copy(o.matrix)\n this.transMat.transpose()\n return `<matrix>${this.transMat.toArray().join(' ')}</matrix>`\n }\n\n // Process the given piece of geometry into the geometry library\n // Returns the mesh id\n private processGeometry(g: BufferGeometry): GeometryInfo {\n let info = this.geometryInfo.get(g)\n\n if (!info) {\n // convert the geometry to bufferGeometry if it isn't already\n const bufferGeometry = g\n\n if (!bufferGeometry.isBufferGeometry) {\n throw new Error('THREE.ColladaExporter: Geometry is not of type THREE.BufferGeometry.')\n }\n\n const meshid = `Mesh${this.libraryGeometries.length + 1}`\n\n const indexCount = bufferGeometry.index\n ? bufferGeometry.index.count * bufferGeometry.index.itemSize\n : bufferGeometry.attributes.position.count\n\n const groups =\n bufferGeometry.groups != null && bufferGeometry.groups.length !== 0\n ? bufferGeometry.groups\n : [{ start: 0, count: indexCount, materialIndex: 0 }]\n\n const gname = g.name ? ` name=\"${g.name}\"` : ''\n let gnode = `<geometry id=\"${meshid}\"${gname}><mesh>`\n\n // define the geometry node and the vertices for the geometry\n const posName = `${meshid}-position`\n const vertName = `${meshid}-vertices`\n gnode += this.getAttribute(bufferGeometry.attributes.position, posName, ['X', 'Y', 'Z'], 'float')\n gnode += `<vertices id=\"${vertName}\"><input semantic=\"POSITION\" source=\"#${posName}\" /></vertices>`\n\n // NOTE: We're not optimizing the attribute arrays here, so they're all the same length and\n // can therefore share the same triangle indices. However, MeshLab seems to have trouble opening\n // models with attributes that share an offset.\n // MeshLab Bug#424: https://sourceforge.net/p/meshlab/bugs/424/\n\n // serialize normals\n let triangleInputs = `<input semantic=\"VERTEX\" source=\"#${vertName}\" offset=\"0\" />`\n if ('normal' in bufferGeometry.attributes) {\n const normName = `${meshid}-normal`\n gnode += this.getAttribute(bufferGeometry.attributes.normal, normName, ['X', 'Y', 'Z'], 'float')\n triangleInputs += `<input semantic=\"NORMAL\" source=\"#${normName}\" offset=\"0\" />`\n }\n\n // serialize uvs\n if ('uv' in bufferGeometry.attributes) {\n const uvName = `${meshid}-texcoord`\n gnode += this.getAttribute(bufferGeometry.attributes.uv, uvName, ['S', 'T'], 'float')\n triangleInputs += `<input semantic=\"TEXCOORD\" source=\"#${uvName}\" offset=\"0\" set=\"0\" />`\n }\n\n // serialize lightmap uvs\n if ('uv2' in bufferGeometry.attributes) {\n const uvName = `${meshid}-texcoord2`\n gnode += this.getAttribute(bufferGeometry.attributes.uv2, uvName, ['S', 'T'], 'float')\n triangleInputs += `<input semantic=\"TEXCOORD\" source=\"#${uvName}\" offset=\"0\" set=\"1\" />`\n }\n\n // serialize colors\n if ('color' in bufferGeometry.attributes) {\n const colName = `${meshid}-color`\n gnode += this.getAttribute(bufferGeometry.attributes.color, colName, ['X', 'Y', 'Z'], 'uint8')\n triangleInputs += `<input semantic=\"COLOR\" source=\"#${colName}\" offset=\"0\" />`\n }\n\n let indexArray: number[] | ArrayLike<number> | null = null\n if (bufferGeometry.index) {\n indexArray = this.attrBufferToArray(bufferGeometry.index)\n } else {\n indexArray = new Array(indexCount)\n for (let i = 0, l = indexArray.length; i < l && Array.isArray(indexArray); i++) indexArray[i] = i\n }\n\n for (let i = 0, l = groups.length; i < l; i++) {\n const group = groups[i]\n const subarr = this.subArray(indexArray, group.start, group.count)\n const polycount = subarr.length / 3\n gnode += `<triangles material=\"MESH_MATERIAL_${group.materialIndex}\" count=\"${polycount}\">`\n gnode += triangleInputs\n\n gnode += `<p>${subarr.join(' ')}</p>`\n gnode += '</triangles>'\n }\n\n gnode += '</mesh></geometry>'\n\n this.libraryGeometries.push(gnode)\n\n info = { meshid, bufferGeometry }\n this.geometryInfo.set(g, info)\n }\n\n return info\n }\n\n // Process the given texture into the image library\n // Returns the image library\n private processTexture(tex: Texture): string {\n let texid = this.imageMap.get(tex)\n if (texid == null) {\n texid = `image-${this.libraryImages.length + 1}`\n\n const ext = 'png'\n const name = tex.name || texid\n let imageNode = `<image id=\"${texid}\" name=\"${name}\">`\n\n if (this.options.version === '1.5.0') {\n imageNode += `<init_from><ref>${this.options.textureDirectory}${name}.${ext}</ref></init_from>`\n } else {\n // version image node 1.4.1\n imageNode += `<init_from>${this.options.textureDirectory}${name}.${ext}</init_from>`\n }\n\n imageNode += '</image>'\n\n this.libraryImages.push(imageNode)\n this.imageMap.set(tex, texid)\n this.textures.push({\n directory: this.options.textureDirectory,\n name,\n ext,\n data: this.imageToData(tex.image, ext),\n original: tex,\n })\n }\n\n return texid\n }\n\n // Process the given material into the material and effect libraries\n // Returns the material id\n private processMaterial(m: MaterialRepresentation): string {\n let matid = this.materialMap.get(m)\n\n if (matid == null) {\n matid = `Mat${this.libraryEffects.length + 1}`\n\n let type = 'phong'\n\n if (m instanceof MeshLambertMaterial) {\n type = 'lambert'\n } else if (m instanceof MeshBasicMaterial) {\n type = 'constant'\n\n if (m.map !== null) {\n // The Collada spec does not support diffuse texture maps with the\n // constant shader type.\n // mrdoob/three.js#15469\n console.warn('ColladaExporter: Texture maps not supported with MeshBasicMaterial.')\n }\n }\n\n if (m instanceof MeshPhongMaterial) {\n const emissive = m.emissive ? m.emissive : new Color(0, 0, 0)\n const diffuse = m.color ? m.color : new Color(0, 0, 0)\n const specular = m.specular ? m.specular : new Color(1, 1, 1)\n const shininess = m.shininess || 0\n const reflectivity = m.reflectivity || 0\n\n // Do not export and alpha map for the reasons mentioned in issue (#13792)\n // in three.js alpha maps are black and white, but collada expects the alpha\n // channel to specify the transparency\n let transparencyNode = ''\n if (m.transparent) {\n transparencyNode += `<transparent>${\n m.map ? '<texture texture=\"diffuse-sampler\"></texture>' : '<float>1</float>'\n }</transparent>`\n\n if (m.opacity < 1) {\n transparencyNode += `<transparency><float>${m.opacity}</float></transparency>`\n }\n }\n\n const techniqueNode = `${`<technique sid=\"common\"><${type}>`}<emission>${\n m.emissiveMap\n ? '<texture texture=\"emissive-sampler\" texcoord=\"TEXCOORD\" />'\n : `<color sid=\"emission\">${emissive.r} ${emissive.g} ${emissive.b} 1</color>`\n }</emission>${\n type !== 'constant'\n ? `<diffuse>${\n m.map\n ? '<texture texture=\"diffuse-sampler\" texcoord=\"TEXCOORD\" />'\n : `<color sid=\"diffuse\">${diffuse.r} ${diffuse.g} ${diffuse.b} 1</color>`\n }</diffuse>`\n : ''\n }${\n type !== 'constant'\n ? `<bump>${m.normalMap ? '<texture texture=\"bump-sampler\" texcoord=\"TEXCOORD\" />' : ''}</bump>`\n : ''\n }${\n type === 'phong'\n ? `${`<specular><color sid=\"specular\">${specular.r} ${specular.g} ${specular.b} 1</color></specular>`}<shininess>${\n m.specularMap\n ? '<texture texture=\"specular-sampler\" texcoord=\"TEXCOORD\" />'\n : `<float sid=\"shininess\">${shininess}</float>`\n }</shininess>`\n : ''\n }${`<reflective><color>${diffuse.r} ${diffuse.g} ${diffuse.b} 1</color></reflective>`}${`<reflectivity><float>${reflectivity}</float></reflectivity>`}${transparencyNode}${`</${type}></technique>`}`\n\n const effectnode = `${`<effect id=\"${matid}-effect\">`}<profile_COMMON>${\n m.map\n ? `<newparam sid=\"diffuse-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.map,\n )}</init_from>`}</surface></newparam><newparam sid=\"diffuse-sampler\"><sampler2D><source>diffuse-surface</source></sampler2D></newparam>`\n : ''\n }${\n m.specularMap\n ? `<newparam sid=\"specular-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.specularMap,\n )}</init_from>`}</surface></newparam><newparam sid=\"specular-sampler\"><sampler2D><source>specular-surface</source></sampler2D></newparam>`\n : ''\n }${\n m.emissiveMap\n ? `<newparam sid=\"emissive-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.emissiveMap,\n )}</init_from>`}</surface></newparam><newparam sid=\"emissive-sampler\"><sampler2D><source>emissive-surface</source></sampler2D></newparam>`\n : ''\n }${\n m.normalMap\n ? `<newparam sid=\"bump-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.normalMap,\n )}</init_from>`}</surface></newparam><newparam sid=\"bump-sampler\"><sampler2D><source>bump-surface</source></sampler2D></newparam>`\n : ''\n }${techniqueNode}${\n m.side === DoubleSide\n ? '<extra><technique profile=\"THREEJS\"><double_sided sid=\"double_sided\" type=\"int\">1</double_sided></technique></extra>'\n : ''\n }</profile_COMMON></effect>`\n\n const materialName = m.name ? ` name=\"${m.name}\"` : ''\n const materialNode = `<material id=\"${matid}\"${materialName}><instance_effect url=\"#${matid}-effect\" /></material>`\n\n this.libraryMaterials.push(materialNode)\n this.libraryEffects.push(effectnode)\n this.materialMap.set(m, matid)\n }\n }\n\n return matid\n }\n\n // Recursively process the object into a scene\n private processObject(o: Object3D): string {\n let node = `<node name=\"${o.name}\">`\n\n node += this.getTransform(o)\n const a: Mesh<BufferGeometry, Material | Material[]> = new Mesh()\n a.geometry\n\n if (o instanceof Mesh && o.isMesh && o.geometry !== null) {\n // function returns the id associated with the mesh and a \"BufferGeometry\" version\n // of the geometry in case it's not a geometry.\n const geomInfo = this.processGeometry(o.geometry)\n const meshid = geomInfo.meshid\n const geometry = geomInfo.bufferGeometry\n\n // ids of the materials to bind to the geometry\n let matids = null\n let matidsArray\n\n // get a list of materials to bind to the sub groups of the geometry.\n // If the amount of subgroups is greater than the materials, than reuse\n // the materials.\n const mat: MaterialRepresentation | MaterialRepresentation[] = o.material || new MeshBasicMaterial()\n const materials = Array.isArray(mat) ? mat : [mat]\n\n if (geometry.groups.length > materials.length) {\n matidsArray = new Array(geometry.groups.length)\n } else {\n matidsArray = new Array(materials.length)\n }\n\n matids = matidsArray.fill(null).map((_, i) => this.processMaterial(materials[i % materials.length]))\n\n node += `${\n `<instance_geometry url=\"#${meshid}\">` +\n (matids != null\n ? `<bind_material><technique_common>${matids\n .map(\n (id, i) =>\n `${`<instance_material symbol=\"MESH_MATERIAL_${i}\" target=\"#${id}\" >`}<bind_vertex_input semantic=\"TEXCOORD\" input_semantic=\"TEXCOORD\" input_set=\"0\" /></instance_material>`,\n )\n .join('')}</technique_common></bind_material>`\n : '')\n }</instance_geometry>`\n }\n\n o.children.forEach((c) => (node += this.processObject(c)))\n\n node += '</node>'\n\n return node\n }\n}\n\nexport { ColladaExporter }\n"],"names":[],"mappings":";;;;;;;AA4CA,MAAM,gBAAgB;AAAA,EAiCpB,cAAc;AAhCN;AASA;AACA;AACA;AACA;AAQA;AACA;AACA;AACA;AAEA;AACA;AAEA;AAEA,oCAAW,CAAC,QAAQ,QAAQ,QAAQ,MAAM;AAGhD,SAAK,UAAU;AAAA,MACb,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,kBAAkB;AAAA,MAClB,QAAQ;AAAA,MACR,UAAU;AAAA,MACV,WAAW;AAAA,IAAA;AAGR,SAAA,mCAAmB;AACnB,SAAA,kCAAkB;AAClB,SAAA,+BAAe;AACpB,SAAK,WAAW;AAEhB,SAAK,gBAAgB;AACrB,SAAK,oBAAoB;AACzB,SAAK,iBAAiB;AACtB,SAAK,mBAAmB;AAExB,SAAK,SAAS;AACd,SAAK,MAAM;AAEX,SAAK,WAAW;AAAA,EAClB;AAAA,EAEO,MACL,QACA,QACA,UAAkC,CAAA,GACJ;AAC9B,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,GAAG;AAErC,QAAI,KAAK,QAAQ,OAAO,MAAM,YAAY,MAAM,MAAM;AACpD,cAAQ,MAAM,uEAAuE;AAC9E,aAAA;AAAA,IACT;AAEA,QAAI,KAAK,QAAQ,aAAa,QAAQ,KAAK,QAAQ,cAAc,MAAM;AACrE,cAAQ,MAAM,4EAA4E;AACnF,aAAA;AAAA,IACT;AAEA,QAAI,KAAK,QAAQ,cAAc,QAAQ,KAAK,QAAQ,aAAa,MAAM;AACrE,cAAQ,MAAM,4EAA4E;AACnF,aAAA;AAAA,IACT;AAEI,QAAA,KAAK,QAAQ,qBAAqB,IAAI;AACxC,WAAK,QAAQ,mBAAmB,GAAG,KAAK,QAAQ,oBAAoB,QAAQ,OAAO,GAAG,EAAE,QAAQ,QAAQ,GAAG;AAAA,IAC7G;AAEA,QAAI,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AAI,EAAE,IAAI,CAAC,GAAG,MAAM,KAAK,gBAAgB,UAAU,IAAI,UAAU,MAAM,CAAC,CAAC;AAEnG,cAAQ,GACN,4BAA4B,cAC3B,UAAU,OACP,oCAAoC,OACjC;AAAA,QACC,CAAC,IAAI,MACH,GAAG,4CAA4C,eAAe;AAAA,MAAA,EAEjE,KAAK,EAAE,yCACV;AAAA,IAER;AAEE,MAAA,SAAS,QAAQ,CAAC,MAAO,QAAQ,KAAK,cAAc,CAAC,CAAE;AAEjD,YAAA;AAED,WAAA;AAAA,EACT;AACF;"}
|
1
|
+
{"version":3,"file":"ColladaExporter.js","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><contributor><authoring_tool>three.js Collada Exporter</authoring_tool>${\n this.options.author !== null ? `<author>${this.options.author}</author>` : ''\n }</contributor>${`<created>${new Date().toISOString()}</created>`}${`<modified>${new Date().toISOString()}</modified>`}<up_axis>Y_UP</up_axis></asset>`\n\n dae += `<library_images>${this.libraryImages.join('')}</library_images>`\n\n dae += `<library_effects>${this.libraryEffects.join('')}</library_effects>`\n\n dae += `<library_materials>${this.libraryMaterials.join('')}</library_materials>`\n\n dae += `<library_geometries>${this.libraryGeometries.join('')}</library_geometries>`\n\n dae += `<library_visual_scenes><visual_scene id=\"Scene\" name=\"scene\">${libraryVisualScenes}</visual_scene></library_visual_scenes>`\n\n dae += '<scene><instance_visual_scene url=\"#Scene\"/></scene>'\n\n dae += '</COLLADA>'\n\n const res = {\n data: this.format(dae),\n textures: this.textures,\n }\n\n if (typeof onDone === 'function') {\n requestAnimationFrame(() => onDone(res))\n }\n\n return res\n }\n\n // Convert the urdf xml into a well-formatted, indented format\n private format(urdf: string): string {\n const IS_END_TAG = /^<\\//\n const IS_SELF_CLOSING = /(\\?>$)|(\\/>$)/\n const HAS_TEXT = /<[^>]+>[^<]*<\\/[^<]+>/\n\n const pad = (ch: string, num: number): string => (num > 0 ? ch + pad(ch, num - 1) : '')\n\n let tagnum = 0\n\n return (\n urdf\n .match(/(<[^>]+>[^<]+<\\/[^<]+>)|(<[^>]+>)/g)\n ?.map((tag) => {\n if (!HAS_TEXT.test(tag) && !IS_SELF_CLOSING.test(tag) && IS_END_TAG.test(tag)) {\n tagnum--\n }\n\n const res = `${pad(' ', tagnum)}${tag}`\n\n if (!HAS_TEXT.test(tag) && !IS_SELF_CLOSING.test(tag) && !IS_END_TAG.test(tag)) {\n tagnum++\n }\n\n return res\n })\n .join('\\n') ?? ''\n )\n }\n\n // Convert an image into a png format for saving\n private base64ToBuffer(str: string): Uint8Array {\n const b = atob(str)\n const buf = new Uint8Array(b.length)\n\n for (let i = 0, l = buf.length; i < l; i++) {\n buf[i] = b.charCodeAt(i)\n }\n\n return buf\n }\n\n private imageToData(image: CanvasImageSource, ext: string): Uint8Array {\n this.canvas = this.canvas || document.createElement('canvas')\n this.ctx = this.ctx || this.canvas.getContext('2d')\n\n this.canvas.width = image.width instanceof SVGAnimatedLength ? 0 : image.width\n this.canvas.height = image.height instanceof SVGAnimatedLength ? 0 : image.height\n\n this.ctx?.drawImage(image, 0, 0)\n\n // Get the base64 encoded data\n const base64data = this.canvas.toDataURL(`image/${ext}`, 1).replace(/^data:image\\/(png|jpg);base64,/, '')\n\n // Convert to a uint8 array\n return this.base64ToBuffer(base64data)\n }\n\n // gets the attribute array. Generate a new array if the attribute is interleaved\n private attrBufferToArray(attr: InterleavedBufferAttribute | BufferAttribute): number[] | ArrayLike<number> {\n if (attr instanceof InterleavedBufferAttribute && attr.isInterleavedBufferAttribute) {\n // use the typed array constructor to save on memory\n const TypedArrayConstructor: TypedArrayConstructors = attr.array.constructor\n // @ts-ignore\n const arr: number[] = new TypedArrayConstructor(attr.count * attr.itemSize)\n const size = attr.itemSize\n\n for (let i = 0, l = attr.count; i < l; i++) {\n for (let j = 0; j < size; j++) {\n arr[i * size + j] = attr[this.getFuncs[j]](i)\n }\n }\n\n return arr\n } else {\n return attr.array\n }\n }\n\n // Returns an array of the same type starting at the `st` index,\n // and `ct` length\n private subArray(arr: number[] | ArrayLike<number>, st: number, ct: number): TypedArray | number[] {\n if (Array.isArray(arr)) {\n return arr.slice(st, st + ct)\n } else {\n const TypedArrayConstructor: TypedArrayConstructors = arr.constructor\n // @ts-ignore\n return new TypedArrayConstructor(arr.buffer, st * arr.BYTES_PER_ELEMENT, ct)\n }\n }\n\n // Returns the string for a geometry's attribute\n private getAttribute(\n attr: InterleavedBufferAttribute | BufferAttribute,\n name: string,\n params: string[],\n type: string,\n ): string {\n const array = this.attrBufferToArray(attr)\n const res = Array.isArray(array)\n ? `${\n `<source id=\"${name}\">` + `<float_array id=\"${name}-array\" count=\"${array.length}\">` + array.join(' ')\n }</float_array><technique_common>${`<accessor source=\"#${name}-array\" count=\"${Math.floor(\n array.length / attr.itemSize,\n )}\" stride=\"${attr.itemSize}\">`}${params\n .map((n) => `<param name=\"${n}\" type=\"${type}\" />`)\n .join('')}</accessor></technique_common></source>`\n : ''\n\n return res\n }\n\n // Returns the string for a node's transform information\n private getTransform(o: Object3D): string {\n // ensure the object's matrix is up to date\n // before saving the transform\n o.updateMatrix()\n\n this.transMat = this.transMat || new Matrix4()\n this.transMat.copy(o.matrix)\n this.transMat.transpose()\n return `<matrix>${this.transMat.toArray().join(' ')}</matrix>`\n }\n\n // Process the given piece of geometry into the geometry library\n // Returns the mesh id\n private processGeometry(g: BufferGeometry): GeometryInfo {\n let info = this.geometryInfo.get(g)\n\n if (!info) {\n // convert the geometry to bufferGeometry if it isn't already\n const bufferGeometry = g\n\n if (!bufferGeometry.isBufferGeometry) {\n throw new Error('THREE.ColladaExporter: Geometry is not of type THREE.BufferGeometry.')\n }\n\n const meshid = `Mesh${this.libraryGeometries.length + 1}`\n\n const indexCount = bufferGeometry.index\n ? bufferGeometry.index.count * bufferGeometry.index.itemSize\n : bufferGeometry.attributes.position.count\n\n const groups =\n bufferGeometry.groups != null && bufferGeometry.groups.length !== 0\n ? bufferGeometry.groups\n : [{ start: 0, count: indexCount, materialIndex: 0 }]\n\n const gname = g.name ? ` name=\"${g.name}\"` : ''\n let gnode = `<geometry id=\"${meshid}\"${gname}><mesh>`\n\n // define the geometry node and the vertices for the geometry\n const posName = `${meshid}-position`\n const vertName = `${meshid}-vertices`\n gnode += this.getAttribute(bufferGeometry.attributes.position, posName, ['X', 'Y', 'Z'], 'float')\n gnode += `<vertices id=\"${vertName}\"><input semantic=\"POSITION\" source=\"#${posName}\" /></vertices>`\n\n // NOTE: We're not optimizing the attribute arrays here, so they're all the same length and\n // can therefore share the same triangle indices. However, MeshLab seems to have trouble opening\n // models with attributes that share an offset.\n // MeshLab Bug#424: https://sourceforge.net/p/meshlab/bugs/424/\n\n // serialize normals\n let triangleInputs = `<input semantic=\"VERTEX\" source=\"#${vertName}\" offset=\"0\" />`\n if ('normal' in bufferGeometry.attributes) {\n const normName = `${meshid}-normal`\n gnode += this.getAttribute(bufferGeometry.attributes.normal, normName, ['X', 'Y', 'Z'], 'float')\n triangleInputs += `<input semantic=\"NORMAL\" source=\"#${normName}\" offset=\"0\" />`\n }\n\n // serialize uvs\n if ('uv' in bufferGeometry.attributes) {\n const uvName = `${meshid}-texcoord`\n gnode += this.getAttribute(bufferGeometry.attributes.uv, uvName, ['S', 'T'], 'float')\n triangleInputs += `<input semantic=\"TEXCOORD\" source=\"#${uvName}\" offset=\"0\" set=\"0\" />`\n }\n\n // serialize lightmap uvs\n if (UV1 in bufferGeometry.attributes) {\n const uvName = `${meshid}-texcoord2`\n gnode += this.getAttribute(bufferGeometry.attributes[UV1], uvName, ['S', 'T'], 'float')\n triangleInputs += `<input semantic=\"TEXCOORD\" source=\"#${uvName}\" offset=\"0\" set=\"1\" />`\n }\n\n // serialize colors\n if ('color' in bufferGeometry.attributes) {\n const colName = `${meshid}-color`\n gnode += this.getAttribute(bufferGeometry.attributes.color, colName, ['X', 'Y', 'Z'], 'uint8')\n triangleInputs += `<input semantic=\"COLOR\" source=\"#${colName}\" offset=\"0\" />`\n }\n\n let indexArray: number[] | ArrayLike<number> | null = null\n if (bufferGeometry.index) {\n indexArray = this.attrBufferToArray(bufferGeometry.index)\n } else {\n indexArray = new Array(indexCount)\n for (let i = 0, l = indexArray.length; i < l && Array.isArray(indexArray); i++) indexArray[i] = i\n }\n\n for (let i = 0, l = groups.length; i < l; i++) {\n const group = groups[i]\n const subarr = this.subArray(indexArray, group.start, group.count)\n const polycount = subarr.length / 3\n gnode += `<triangles material=\"MESH_MATERIAL_${group.materialIndex}\" count=\"${polycount}\">`\n gnode += triangleInputs\n\n gnode += `<p>${subarr.join(' ')}</p>`\n gnode += '</triangles>'\n }\n\n gnode += '</mesh></geometry>'\n\n this.libraryGeometries.push(gnode)\n\n info = { meshid, bufferGeometry }\n this.geometryInfo.set(g, info)\n }\n\n return info\n }\n\n // Process the given texture into the image library\n // Returns the image library\n private processTexture(tex: Texture): string {\n let texid = this.imageMap.get(tex)\n if (texid == null) {\n texid = `image-${this.libraryImages.length + 1}`\n\n const ext = 'png'\n const name = tex.name || texid\n let imageNode = `<image id=\"${texid}\" name=\"${name}\">`\n\n if (this.options.version === '1.5.0') {\n imageNode += `<init_from><ref>${this.options.textureDirectory}${name}.${ext}</ref></init_from>`\n } else {\n // version image node 1.4.1\n imageNode += `<init_from>${this.options.textureDirectory}${name}.${ext}</init_from>`\n }\n\n imageNode += '</image>'\n\n this.libraryImages.push(imageNode)\n this.imageMap.set(tex, texid)\n this.textures.push({\n directory: this.options.textureDirectory,\n name,\n ext,\n data: this.imageToData(tex.image, ext),\n original: tex,\n })\n }\n\n return texid\n }\n\n // Process the given material into the material and effect libraries\n // Returns the material id\n private processMaterial(m: MaterialRepresentation): string {\n let matid = this.materialMap.get(m)\n\n if (matid == null) {\n matid = `Mat${this.libraryEffects.length + 1}`\n\n let type = 'phong'\n\n if (m instanceof MeshLambertMaterial) {\n type = 'lambert'\n } else if (m instanceof MeshBasicMaterial) {\n type = 'constant'\n\n if (m.map !== null) {\n // The Collada spec does not support diffuse texture maps with the\n // constant shader type.\n // mrdoob/three.js#15469\n console.warn('ColladaExporter: Texture maps not supported with MeshBasicMaterial.')\n }\n }\n\n if (m instanceof MeshPhongMaterial) {\n const emissive = m.emissive ? m.emissive : new Color(0, 0, 0)\n const diffuse = m.color ? m.color : new Color(0, 0, 0)\n const specular = m.specular ? m.specular : new Color(1, 1, 1)\n const shininess = m.shininess || 0\n const reflectivity = m.reflectivity || 0\n\n // Do not export and alpha map for the reasons mentioned in issue (#13792)\n // in three.js alpha maps are black and white, but collada expects the alpha\n // channel to specify the transparency\n let transparencyNode = ''\n if (m.transparent) {\n transparencyNode += `<transparent>${\n m.map ? '<texture texture=\"diffuse-sampler\"></texture>' : '<float>1</float>'\n }</transparent>`\n\n if (m.opacity < 1) {\n transparencyNode += `<transparency><float>${m.opacity}</float></transparency>`\n }\n }\n\n const techniqueNode = `${`<technique sid=\"common\"><${type}>`}<emission>${\n m.emissiveMap\n ? '<texture texture=\"emissive-sampler\" texcoord=\"TEXCOORD\" />'\n : `<color sid=\"emission\">${emissive.r} ${emissive.g} ${emissive.b} 1</color>`\n }</emission>${\n type !== 'constant'\n ? `<diffuse>${\n m.map\n ? '<texture texture=\"diffuse-sampler\" texcoord=\"TEXCOORD\" />'\n : `<color sid=\"diffuse\">${diffuse.r} ${diffuse.g} ${diffuse.b} 1</color>`\n }</diffuse>`\n : ''\n }${\n type !== 'constant'\n ? `<bump>${m.normalMap ? '<texture texture=\"bump-sampler\" texcoord=\"TEXCOORD\" />' : ''}</bump>`\n : ''\n }${\n type === 'phong'\n ? `${`<specular><color sid=\"specular\">${specular.r} ${specular.g} ${specular.b} 1</color></specular>`}<shininess>${\n m.specularMap\n ? '<texture texture=\"specular-sampler\" texcoord=\"TEXCOORD\" />'\n : `<float sid=\"shininess\">${shininess}</float>`\n }</shininess>`\n : ''\n }${`<reflective><color>${diffuse.r} ${diffuse.g} ${diffuse.b} 1</color></reflective>`}${`<reflectivity><float>${reflectivity}</float></reflectivity>`}${transparencyNode}${`</${type}></technique>`}`\n\n const effectnode = `${`<effect id=\"${matid}-effect\">`}<profile_COMMON>${\n m.map\n ? `<newparam sid=\"diffuse-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.map,\n )}</init_from>`}</surface></newparam><newparam sid=\"diffuse-sampler\"><sampler2D><source>diffuse-surface</source></sampler2D></newparam>`\n : ''\n }${\n m.specularMap\n ? `<newparam sid=\"specular-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.specularMap,\n )}</init_from>`}</surface></newparam><newparam sid=\"specular-sampler\"><sampler2D><source>specular-surface</source></sampler2D></newparam>`\n : ''\n }${\n m.emissiveMap\n ? `<newparam sid=\"emissive-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.emissiveMap,\n )}</init_from>`}</surface></newparam><newparam sid=\"emissive-sampler\"><sampler2D><source>emissive-surface</source></sampler2D></newparam>`\n : ''\n }${\n m.normalMap\n ? `<newparam sid=\"bump-surface\"><surface type=\"2D\">${`<init_from>${this.processTexture(\n m.normalMap,\n )}</init_from>`}</surface></newparam><newparam sid=\"bump-sampler\"><sampler2D><source>bump-surface</source></sampler2D></newparam>`\n : ''\n }${techniqueNode}${\n m.side === DoubleSide\n ? '<extra><technique profile=\"THREEJS\"><double_sided sid=\"double_sided\" type=\"int\">1</double_sided></technique></extra>'\n : ''\n }</profile_COMMON></effect>`\n\n const materialName = m.name ? ` name=\"${m.name}\"` : ''\n const materialNode = `<material id=\"${matid}\"${materialName}><instance_effect url=\"#${matid}-effect\" /></material>`\n\n this.libraryMaterials.push(materialNode)\n this.libraryEffects.push(effectnode)\n this.materialMap.set(m, matid)\n }\n }\n\n return matid\n }\n\n // Recursively process the object into a scene\n private processObject(o: Object3D): string {\n let node = `<node name=\"${o.name}\">`\n\n node += this.getTransform(o)\n const a: Mesh<BufferGeometry, Material | Material[]> = new Mesh()\n a.geometry\n\n if (o instanceof Mesh && o.isMesh && o.geometry !== null) {\n // function returns the id associated with the mesh and a \"BufferGeometry\" version\n // of the geometry in case it's not a geometry.\n const geomInfo = this.processGeometry(o.geometry)\n const meshid = geomInfo.meshid\n const geometry = geomInfo.bufferGeometry\n\n // ids of the materials to bind to the geometry\n let matids = null\n let matidsArray\n\n // get a list of materials to bind to the sub groups of the geometry.\n // If the amount of subgroups is greater than the materials, than reuse\n // the materials.\n const mat: MaterialRepresentation | MaterialRepresentation[] = o.material || new MeshBasicMaterial()\n const materials = Array.isArray(mat) ? mat : [mat]\n\n if (geometry.groups.length > materials.length) {\n matidsArray = new Array(geometry.groups.length)\n } else {\n matidsArray = new Array(materials.length)\n }\n\n matids = matidsArray.fill(null).map((_, i) => this.processMaterial(materials[i % materials.length]))\n\n node += `${\n `<instance_geometry url=\"#${meshid}\">` +\n (matids != null\n ? `<bind_material><technique_common>${matids\n .map(\n (id, i) =>\n `${`<instance_material symbol=\"MESH_MATERIAL_${i}\" target=\"#${id}\" >`}<bind_vertex_input semantic=\"TEXCOORD\" input_semantic=\"TEXCOORD\" input_set=\"0\" /></instance_material>`,\n )\n .join('')}</technique_common></bind_material>`\n : '')\n }</instance_geometry>`\n }\n\n o.children.forEach((c) => (node += this.processObject(c)))\n\n node += '</node>'\n\n return node\n }\n}\n\nexport { ColladaExporter }\n"],"names":[],"mappings":";;;;;;;;AA6CA,MAAM,gBAAgB;AAAA,EAiCpB,cAAc;AAhCN;AASA;AACA;AACA;AACA;AAQA;AACA;AACA;AACA;AAEA;AACA;AAEA;AAEA,oCAAW,CAAC,QAAQ,QAAQ,QAAQ,MAAM;AAGhD,SAAK,UAAU;AAAA,MACb,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,kBAAkB;AAAA,MAClB,QAAQ;AAAA,MACR,UAAU;AAAA,MACV,WAAW;AAAA,IAAA;AAGR,SAAA,mCAAmB;AACnB,SAAA,kCAAkB;AAClB,SAAA,+BAAe;AACpB,SAAK,WAAW;AAEhB,SAAK,gBAAgB;AACrB,SAAK,oBAAoB;AACzB,SAAK,iBAAiB;AACtB,SAAK,mBAAmB;AAExB,SAAK,SAAS;AACd,SAAK,MAAM;AAEX,SAAK,WAAW;AAAA,EAClB;AAAA,EAEO,MACL,QACA,QACA,UAAkC,CAAA,GACJ;AAC9B,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,GAAG;AAErC,QAAI,KAAK,QAAQ,OAAO,MAAM,YAAY,MAAM,MAAM;AACpD,cAAQ,MAAM,uEAAuE;AAC9E,aAAA;AAAA,IACT;AAEA,QAAI,KAAK,QAAQ,aAAa,QAAQ,KAAK,QAAQ,cAAc,MAAM;AACrE,cAAQ,MAAM,4EAA4E;AACnF,aAAA;AAAA,IACT;AAEA,QAAI,KAAK,QAAQ,cAAc,QAAQ,KAAK,QAAQ,aAAa,MAAM;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AM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG;AAEjD,UAAI,SAAS,OAAO,SAAS,UAAU,QAAQ;AAC7C,sBAAc,IAAI,MAAM,SAAS,OAAO,MAAM;AAAA,MAAA,OACzC;AACS,sBAAA,IAAI,MAAM,UAAU,MAAM;AAAA,MAC1C;AAEA,eAAS,YAAY,KAAK,IAAI,EAAE,IAAI,CAAC,GAAG,MAAM,KAAK,gBAAgB,UAAU,IAAI,UAAU,MAAM,CAAC,CAAC;AAEnG,cAAQ,GACN,4BAA4B,cAC3B,UAAU,OACP,oCAAoC,OACjC;AAAA,QACC,CAAC,IAAI,MACH,GAAG,4CAA4C,eAAe;AAAA,MAAA,EAEjE,KAAK,EAAE,yCACV;AAAA,IAER;AAEE,MAAA,SAAS,QAAQ,CAAC,MAAO,QAAQ,KAAK,cAAc,CAAC,CAAE;AAEjD,YAAA;AAED,WAAA;AAAA,EACT;AACF;"}
|
package/lines/LineSegments2.cjs
CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const THREE = require("three");
|
4
4
|
const LineSegmentsGeometry = require("./LineSegmentsGeometry.cjs");
|
5
5
|
const LineMaterial = require("./LineMaterial.cjs");
|
6
|
+
const uv1 = require("../_polyfill/uv1.cjs");
|
6
7
|
const _viewport = new THREE.Vector4();
|
7
8
|
const _start = new THREE.Vector3();
|
8
9
|
const _end = new THREE.Vector3();
|
@@ -49,7 +50,7 @@ function raycastWorldUnits(lineSegments, intersects) {
|
|
49
50
|
face: null,
|
50
51
|
faceIndex: i,
|
51
52
|
uv: null,
|
52
|
-
|
53
|
+
[uv1.UV1]: null
|
53
54
|
});
|
54
55
|
}
|
55
56
|
}
|
@@ -127,7 +128,7 @@ function raycastScreenSpace(lineSegments, camera, intersects) {
|
|
127
128
|
face: null,
|
128
129
|
faceIndex: i,
|
129
130
|
uv: null,
|
130
|
-
|
131
|
+
[uv1.UV1]: null
|
131
132
|
});
|
132
133
|
}
|
133
134
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"LineSegments2.cjs","sources":["../../src/lines/LineSegments2.js"],"sourcesContent":["import {\n Box3,\n InstancedInterleavedBuffer,\n InterleavedBufferAttribute,\n Line3,\n MathUtils,\n Matrix4,\n Mesh,\n Sphere,\n Vector3,\n Vector4,\n} from 'three'\nimport { LineSegmentsGeometry } from '../lines/LineSegmentsGeometry'\nimport { LineMaterial } from '../lines/LineMaterial'\n\nconst _viewport = new Vector4();\n\nconst _start = new Vector3()\nconst _end = new Vector3()\n\nconst _start4 = new Vector4()\nconst _end4 = new Vector4()\n\nconst _ssOrigin = new Vector4()\nconst _ssOrigin3 = new Vector3()\nconst _mvMatrix = new Matrix4()\nconst _line = new Line3()\nconst _closestPoint = new Vector3()\n\nconst _box = new Box3()\nconst _sphere = new Sphere()\nconst _clipToWorldVector = new Vector4()\n\nlet _ray, _lineWidth\n\n// Returns the margin required to expand by in world space given the distance from the camera,\n// line width, resolution, and camera projection\nfunction getWorldSpaceHalfWidth(camera, distance, resolution) {\n // transform into clip space, adjust the x and y values by the pixel width offset, then\n // transform back into world space to get world offset. Note clip space is [-1, 1] so full\n // width does not need to be halved.\n _clipToWorldVector.set(0, 0, -distance, 1.0).applyMatrix4(camera.projectionMatrix)\n _clipToWorldVector.multiplyScalar(1.0 / _clipToWorldVector.w)\n _clipToWorldVector.x = _lineWidth / resolution.width\n _clipToWorldVector.y = _lineWidth / resolution.height\n _clipToWorldVector.applyMatrix4(camera.projectionMatrixInverse)\n _clipToWorldVector.multiplyScalar(1.0 / _clipToWorldVector.w)\n\n return Math.abs(Math.max(_clipToWorldVector.x, _clipToWorldVector.y))\n}\n\nfunction raycastWorldUnits(lineSegments, intersects) {\n\n const matrixWorld = lineSegments.matrixWorld;\n const geometry = lineSegments.geometry;\n const instanceStart = geometry.attributes.instanceStart;\n const instanceEnd = geometry.attributes.instanceEnd;\n const segmentCount = Math.min(geometry.instanceCount, instanceStart.count);\n\n for (let i = 0, l = segmentCount; i < l; i++) {\n _line.start.fromBufferAttribute(instanceStart, i)\n _line.end.fromBufferAttribute(instanceEnd, i)\n\n _line.applyMatrix4(matrixWorld);\n\n const pointOnLine = new Vector3()\n const point = new Vector3()\n\n _ray.distanceSqToSegment(_line.start, _line.end, point, pointOnLine)\n const isInside = point.distanceTo(pointOnLine) < _lineWidth * 0.5\n\n if (isInside) {\n intersects.push({\n point,\n pointOnLine,\n distance: _ray.origin.distanceTo(point),\n object: lineSegments,\n face: null,\n faceIndex: i,\n uv: null,\n uv2: null,\n })\n }\n }\n}\n\nfunction raycastScreenSpace(lineSegments, camera, intersects) {\n const projectionMatrix = camera.projectionMatrix\n const material = lineSegments.material\n const resolution = material.resolution\n const matrixWorld = lineSegments.matrixWorld\n\n const geometry = lineSegments.geometry\n const instanceStart = geometry.attributes.instanceStart\n const instanceEnd = geometry.attributes.instanceEnd\n const segmentCount = Math.min(geometry.instanceCount, instanceStart.count);\n\n const near = -camera.near\n\n //\n\n // pick a point 1 unit out along the ray to avoid the ray origin\n // sitting at the camera origin which will cause \"w\" to be 0 when\n // applying the projection matrix.\n _ray.at(1, _ssOrigin)\n\n // ndc space [ - 1.0, 1.0 ]\n _ssOrigin.w = 1\n _ssOrigin.applyMatrix4(camera.matrixWorldInverse)\n _ssOrigin.applyMatrix4(projectionMatrix)\n _ssOrigin.multiplyScalar(1 / _ssOrigin.w)\n\n // screen space\n _ssOrigin.x *= resolution.x / 2\n _ssOrigin.y *= resolution.y / 2\n _ssOrigin.z = 0\n\n _ssOrigin3.copy(_ssOrigin)\n\n _mvMatrix.multiplyMatrices(camera.matrixWorldInverse, matrixWorld)\n\n for (let i = 0, l = segmentCount; i < l; i++) {\n _start4.fromBufferAttribute(instanceStart, i)\n _end4.fromBufferAttribute(instanceEnd, i)\n\n _start4.w = 1\n _end4.w = 1\n\n // camera space\n _start4.applyMatrix4(_mvMatrix)\n _end4.applyMatrix4(_mvMatrix)\n\n // skip the segment if it's entirely behind the camera\n const isBehindCameraNear = _start4.z > near && _end4.z > near\n if (isBehindCameraNear) {\n continue\n }\n\n // trim the segment if it extends behind camera near\n if (_start4.z > near) {\n const deltaDist = _start4.z - _end4.z\n const t = (_start4.z - near) / deltaDist\n _start4.lerp(_end4, t)\n } else if (_end4.z > near) {\n const deltaDist = _end4.z - _start4.z\n const t = (_end4.z - near) / deltaDist\n _end4.lerp(_start4, t)\n }\n\n // clip space\n _start4.applyMatrix4(projectionMatrix)\n _end4.applyMatrix4(projectionMatrix)\n\n // ndc space [ - 1.0, 1.0 ]\n _start4.multiplyScalar(1 / _start4.w)\n _end4.multiplyScalar(1 / _end4.w)\n\n // screen space\n _start4.x *= resolution.x / 2\n _start4.y *= resolution.y / 2\n\n _end4.x *= resolution.x / 2\n _end4.y *= resolution.y / 2\n\n // create 2d segment\n _line.start.copy(_start4)\n _line.start.z = 0\n\n _line.end.copy(_end4)\n _line.end.z = 0\n\n // get closest point on ray to segment\n const param = _line.closestPointToPointParameter(_ssOrigin3, true)\n _line.at(param, _closestPoint)\n\n // check if the intersection point is within clip space\n const zPos = MathUtils.lerp(_start4.z, _end4.z, param)\n const isInClipSpace = zPos >= -1 && zPos <= 1\n\n const isInside = _ssOrigin3.distanceTo(_closestPoint) < _lineWidth * 0.5\n\n if (isInClipSpace && isInside) {\n _line.start.fromBufferAttribute(instanceStart, i)\n _line.end.fromBufferAttribute(instanceEnd, i)\n\n _line.start.applyMatrix4(matrixWorld)\n _line.end.applyMatrix4(matrixWorld)\n\n const pointOnLine = new Vector3()\n const point = new Vector3()\n\n _ray.distanceSqToSegment(_line.start, _line.end, point, pointOnLine)\n\n intersects.push({\n point: point,\n pointOnLine: pointOnLine,\n distance: _ray.origin.distanceTo(point),\n object: lineSegments,\n face: null,\n faceIndex: i,\n uv: null,\n uv2: null,\n })\n }\n }\n}\n\nclass LineSegments2 extends Mesh {\n constructor(geometry = new LineSegmentsGeometry(), material = new LineMaterial({ color: Math.random() * 0xffffff })) {\n super(geometry, material)\n\n this.isLineSegments2 = true\n\n this.type = 'LineSegments2'\n }\n\n // for backwards-compatibility, but could be a method of LineSegmentsGeometry...\n\n computeLineDistances() {\n const geometry = this.geometry\n\n const instanceStart = geometry.attributes.instanceStart\n const instanceEnd = geometry.attributes.instanceEnd\n const lineDistances = new Float32Array(2 * instanceStart.count)\n\n for (let i = 0, j = 0, l = instanceStart.count; i < l; i++, j += 2) {\n _start.fromBufferAttribute(instanceStart, i)\n _end.fromBufferAttribute(instanceEnd, i)\n\n lineDistances[j] = j === 0 ? 0 : lineDistances[j - 1]\n lineDistances[j + 1] = lineDistances[j] + _start.distanceTo(_end)\n }\n\n const instanceDistanceBuffer = new InstancedInterleavedBuffer(lineDistances, 2, 1) // d0, d1\n\n geometry.setAttribute('instanceDistanceStart', new InterleavedBufferAttribute(instanceDistanceBuffer, 1, 0)) // d0\n geometry.setAttribute('instanceDistanceEnd', new InterleavedBufferAttribute(instanceDistanceBuffer, 1, 1)) // d1\n\n return this\n }\n\n raycast(raycaster, intersects) {\n const worldUnits = this.material.worldUnits\n const camera = raycaster.camera\n\n if (camera === null && !worldUnits) {\n console.error(\n 'LineSegments2: \"Raycaster.camera\" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.',\n )\n }\n\n const threshold = raycaster.params.Line2 !== undefined ? raycaster.params.Line2.threshold || 0 : 0\n\n _ray = raycaster.ray\n\n const matrixWorld = this.matrixWorld\n const geometry = this.geometry\n const material = this.material\n\n _lineWidth = material.linewidth + threshold\n\n // check if we intersect the sphere bounds\n if (geometry.boundingSphere === null) {\n geometry.computeBoundingSphere()\n }\n\n _sphere.copy(geometry.boundingSphere).applyMatrix4(matrixWorld)\n\n // increase the sphere bounds by the worst case line screen space width\n let sphereMargin\n if (worldUnits) {\n sphereMargin = _lineWidth * 0.5\n } else {\n const distanceToSphere = Math.max(camera.near, _sphere.distanceToPoint(_ray.origin))\n sphereMargin = getWorldSpaceHalfWidth(camera, distanceToSphere, material.resolution)\n }\n\n _sphere.radius += sphereMargin\n\n if (_ray.intersectsSphere(_sphere) === false) {\n return\n }\n\n // check if we intersect the box bounds\n if (geometry.boundingBox === null) {\n geometry.computeBoundingBox()\n }\n\n _box.copy(geometry.boundingBox).applyMatrix4(matrixWorld)\n\n // increase the box bounds by the worst case line width\n let boxMargin\n if (worldUnits) {\n boxMargin = _lineWidth * 0.5\n } else {\n const distanceToBox = Math.max(camera.near, _box.distanceToPoint(_ray.origin))\n boxMargin = getWorldSpaceHalfWidth(camera, distanceToBox, material.resolution)\n }\n\n _box.expandByScalar(boxMargin)\n\n if (_ray.intersectsBox(_box) === false) {\n return\n }\n\n if (worldUnits) {\n raycastWorldUnits(this, intersects)\n } else {\n raycastScreenSpace(this, camera, intersects)\n }\n }\n\n onBeforeRender(renderer) {\n\n const uniforms = this.material.uniforms;\n\n if (uniforms && uniforms.resolution) {\n\n renderer.getViewport(_viewport);\n this.material.uniforms.resolution.value.set(_viewport.z, _viewport.w);\n\n }\n\n }\n}\n\nexport { LineSegments2 }\n"],"names":["Vector4","Vector3","Matrix4","Line3","Box3","Sphere","MathUtils","Mesh","LineSegmentsGeometry","LineMaterial","InstancedInterleavedBuffer","InterleavedBufferAttribute"],"mappings":";;;;;AAeA,MAAM,YAAY,IAAIA,MAAAA;AAEtB,MAAM,SAAS,IAAIC,MAAAA,QAAS;AAC5B,MAAM,OAAO,IAAIA,MAAAA,QAAS;AAE1B,MAAM,UAAU,IAAID,MAAAA,QAAS;AAC7B,MAAM,QAAQ,IAAIA,MAAAA,QAAS;AAE3B,MAAM,YAAY,IAAIA,MAAAA,QAAS;AAC/B,MAAM,aAAa,IAAIC,MAAAA,QAAS;AAChC,MAAM,YAAY,IAAIC,MAAAA,QAAS;AAC/B,MAAM,QAAQ,IAAIC,MAAAA,MAAO;AACzB,MAAM,gBAAgB,IAAIF,MAAAA,QAAS;AAEnC,MAAM,OAAO,IAAIG,MAAAA,KAAM;AACvB,MAAM,UAAU,IAAIC,MAAAA,OAAQ;AAC5B,MAAM,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AY;AACd,qBAAe,aAAa;AAAA,IAClC,OAAW;AACL,YAAM,mBAAmB,KAAK,IAAI,OAAO,MAAM,QAAQ,gBAAgB,KAAK,MAAM,CAAC;AACnF,qBAAe,uBAAuB,QAAQ,kBAAkB,SAAS,UAAU;AAAA,IACpF;AAED,YAAQ,UAAU;AAElB,QAAI,KAAK,iBAAiB,OAAO,MAAM,OAAO;AAC5C;AAAA,IACD;AAGD,QAAI,SAAS,gBAAgB,MAAM;AACjC,eAAS,mBAAoB;AAAA,IAC9B;AAED,SAAK,KAAK,SAAS,WAAW,EAAE,aAAa,WAAW;AAGxD,QAAI;AACJ,QAAI,YAAY;AACd,kBAAY,aAAa;AAAA,IAC/B,OAAW;AACL,YAAM,gBAAgB,KAAK,IAAI,OAAO,MAAM,KAAK,gBAAgB,KAAK,MAAM,CAAC;AAC7E,kBAAY,uBAAuB,QAAQ,eAAe,SAAS,UAAU;AAAA,IAC9E;AAED,SAAK,eAAe,SAAS;AAE7B,QAAI,KAAK,cAAc,IAAI,MAAM,OAAO;AACtC;AAAA,IACD;AAED,QAAI,YAAY;AACd,wBAAkB,MAAM,UAAU;AAAA,IACxC,OAAW;AACL,yBAAmB,MAAM,QAAQ,UAAU;AAAA,IAC5C;AAAA,EACF;AAAA,EAED,eAAe,UAAU;AAEvB,UAAM,WAAW,KAAK,SAAS;AAE/B,QAAI,YAAY,SAAS,YAAY;AAEnC,eAAS,YAAY,SAAS;AAC9B,WAAK,SAAS,SAAS,WAAW,MAAM,IAAI,UAAU,GAAG,UAAU,CAAC;AAAA,IAErE;AAAA,EAEF;AACH;;"}
|
1
|
+
{"version":3,"file":"LineSegments2.cjs","sources":["../../src/lines/LineSegments2.js"],"sourcesContent":["import {\n Box3,\n InstancedInterleavedBuffer,\n InterleavedBufferAttribute,\n Line3,\n MathUtils,\n Matrix4,\n Mesh,\n Sphere,\n Vector3,\n Vector4,\n} from 'three'\nimport { LineSegmentsGeometry } from '../lines/LineSegmentsGeometry'\nimport { LineMaterial } from '../lines/LineMaterial'\nimport { UV1 } from '../_polyfill/uv1'\n\nconst _viewport = new Vector4();\n\nconst _start = new Vector3()\nconst _end = new Vector3()\n\nconst _start4 = new Vector4()\nconst _end4 = new Vector4()\n\nconst _ssOrigin = new Vector4()\nconst _ssOrigin3 = new Vector3()\nconst _mvMatrix = new Matrix4()\nconst _line = new Line3()\nconst _closestPoint = new Vector3()\n\nconst _box = new Box3()\nconst _sphere = new Sphere()\nconst _clipToWorldVector = new Vector4()\n\nlet _ray, _lineWidth\n\n// Returns the margin required to expand by in world space given the distance from the camera,\n// line width, resolution, and camera projection\nfunction getWorldSpaceHalfWidth(camera, distance, resolution) {\n // transform into clip space, adjust the x and y values by the pixel width offset, then\n // transform back into world space to get world offset. Note clip space is [-1, 1] so full\n // width does not need to be halved.\n _clipToWorldVector.set(0, 0, -distance, 1.0).applyMatrix4(camera.projectionMatrix)\n _clipToWorldVector.multiplyScalar(1.0 / _clipToWorldVector.w)\n _clipToWorldVector.x = _lineWidth / resolution.width\n _clipToWorldVector.y = _lineWidth / resolution.height\n _clipToWorldVector.applyMatrix4(camera.projectionMatrixInverse)\n _clipToWorldVector.multiplyScalar(1.0 / _clipToWorldVector.w)\n\n return Math.abs(Math.max(_clipToWorldVector.x, _clipToWorldVector.y))\n}\n\nfunction raycastWorldUnits(lineSegments, intersects) {\n\n const matrixWorld = lineSegments.matrixWorld;\n const geometry = lineSegments.geometry;\n const instanceStart = geometry.attributes.instanceStart;\n const instanceEnd = geometry.attributes.instanceEnd;\n const segmentCount = Math.min(geometry.instanceCount, instanceStart.count);\n\n for (let i = 0, l = segmentCount; i < l; i++) {\n _line.start.fromBufferAttribute(instanceStart, i)\n _line.end.fromBufferAttribute(instanceEnd, i)\n\n _line.applyMatrix4(matrixWorld);\n\n const pointOnLine = new Vector3()\n const point = new Vector3()\n\n _ray.distanceSqToSegment(_line.start, _line.end, point, pointOnLine)\n const isInside = point.distanceTo(pointOnLine) < _lineWidth * 0.5\n\n if (isInside) {\n intersects.push({\n point,\n pointOnLine,\n distance: _ray.origin.distanceTo(point),\n object: lineSegments,\n face: null,\n faceIndex: i,\n uv: null,\n [UV1]: null,\n })\n }\n }\n}\n\nfunction raycastScreenSpace(lineSegments, camera, intersects) {\n const projectionMatrix = camera.projectionMatrix\n const material = lineSegments.material\n const resolution = material.resolution\n const matrixWorld = lineSegments.matrixWorld\n\n const geometry = lineSegments.geometry\n const instanceStart = geometry.attributes.instanceStart\n const instanceEnd = geometry.attributes.instanceEnd\n const segmentCount = Math.min(geometry.instanceCount, instanceStart.count);\n\n const near = -camera.near\n\n //\n\n // pick a point 1 unit out along the ray to avoid the ray origin\n // sitting at the camera origin which will cause \"w\" to be 0 when\n // applying the projection matrix.\n _ray.at(1, _ssOrigin)\n\n // ndc space [ - 1.0, 1.0 ]\n _ssOrigin.w = 1\n _ssOrigin.applyMatrix4(camera.matrixWorldInverse)\n _ssOrigin.applyMatrix4(projectionMatrix)\n _ssOrigin.multiplyScalar(1 / _ssOrigin.w)\n\n // screen space\n _ssOrigin.x *= resolution.x / 2\n _ssOrigin.y *= resolution.y / 2\n _ssOrigin.z = 0\n\n _ssOrigin3.copy(_ssOrigin)\n\n _mvMatrix.multiplyMatrices(camera.matrixWorldInverse, matrixWorld)\n\n for (let i = 0, l = segmentCount; i < l; i++) {\n _start4.fromBufferAttribute(instanceStart, i)\n _end4.fromBufferAttribute(instanceEnd, i)\n\n _start4.w = 1\n _end4.w = 1\n\n // camera space\n _start4.applyMatrix4(_mvMatrix)\n _end4.applyMatrix4(_mvMatrix)\n\n // skip the segment if it's entirely behind the camera\n const isBehindCameraNear = _start4.z > near && _end4.z > near\n if (isBehindCameraNear) {\n continue\n }\n\n // trim the segment if it extends behind camera near\n if (_start4.z > near) {\n const deltaDist = _start4.z - _end4.z\n const t = (_start4.z - near) / deltaDist\n _start4.lerp(_end4, t)\n } else if (_end4.z > near) {\n const deltaDist = _end4.z - _start4.z\n const t = (_end4.z - near) / deltaDist\n _end4.lerp(_start4, t)\n }\n\n // clip space\n _start4.applyMatrix4(projectionMatrix)\n _end4.applyMatrix4(projectionMatrix)\n\n // ndc space [ - 1.0, 1.0 ]\n _start4.multiplyScalar(1 / _start4.w)\n _end4.multiplyScalar(1 / _end4.w)\n\n // screen space\n _start4.x *= resolution.x / 2\n _start4.y *= resolution.y / 2\n\n _end4.x *= resolution.x / 2\n _end4.y *= resolution.y / 2\n\n // create 2d segment\n _line.start.copy(_start4)\n _line.start.z = 0\n\n _line.end.copy(_end4)\n _line.end.z = 0\n\n // get closest point on ray to segment\n const param = _line.closestPointToPointParameter(_ssOrigin3, true)\n _line.at(param, _closestPoint)\n\n // check if the intersection point is within clip space\n const zPos = MathUtils.lerp(_start4.z, _end4.z, param)\n const isInClipSpace = zPos >= -1 && zPos <= 1\n\n const isInside = _ssOrigin3.distanceTo(_closestPoint) < _lineWidth * 0.5\n\n if (isInClipSpace && isInside) {\n _line.start.fromBufferAttribute(instanceStart, i)\n _line.end.fromBufferAttribute(instanceEnd, i)\n\n _line.start.applyMatrix4(matrixWorld)\n _line.end.applyMatrix4(matrixWorld)\n\n const pointOnLine = new Vector3()\n const point = new Vector3()\n\n _ray.distanceSqToSegment(_line.start, _line.end, point, pointOnLine)\n\n intersects.push({\n point: point,\n pointOnLine: pointOnLine,\n distance: _ray.origin.distanceTo(point),\n object: lineSegments,\n face: null,\n faceIndex: i,\n uv: null,\n [UV1]: null,\n })\n }\n }\n}\n\nclass LineSegments2 extends Mesh {\n constructor(geometry = new LineSegmentsGeometry(), material = new LineMaterial({ color: Math.random() * 0xffffff })) {\n super(geometry, material)\n\n this.isLineSegments2 = true\n\n this.type = 'LineSegments2'\n }\n\n // for backwards-compatibility, but could be a method of LineSegmentsGeometry...\n\n computeLineDistances() {\n const geometry = this.geometry\n\n const instanceStart = geometry.attributes.instanceStart\n const instanceEnd = geometry.attributes.instanceEnd\n const lineDistances = new Float32Array(2 * instanceStart.count)\n\n for (let i = 0, j = 0, l = instanceStart.count; i < l; i++, j += 2) {\n _start.fromBufferAttribute(instanceStart, i)\n _end.fromBufferAttribute(instanceEnd, i)\n\n lineDistances[j] = j === 0 ? 0 : lineDistances[j - 1]\n lineDistances[j + 1] = lineDistances[j] + _start.distanceTo(_end)\n }\n\n const instanceDistanceBuffer = new InstancedInterleavedBuffer(lineDistances, 2, 1) // d0, d1\n\n geometry.setAttribute('instanceDistanceStart', new InterleavedBufferAttribute(instanceDistanceBuffer, 1, 0)) // d0\n geometry.setAttribute('instanceDistanceEnd', new InterleavedBufferAttribute(instanceDistanceBuffer, 1, 1)) // d1\n\n return this\n }\n\n raycast(raycaster, intersects) {\n const worldUnits = this.material.worldUnits\n const camera = raycaster.camera\n\n if (camera === null && !worldUnits) {\n console.error(\n 'LineSegments2: \"Raycaster.camera\" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.',\n )\n }\n\n const threshold = raycaster.params.Line2 !== undefined ? raycaster.params.Line2.threshold || 0 : 0\n\n _ray = raycaster.ray\n\n const matrixWorld = this.matrixWorld\n const geometry = this.geometry\n const material = this.material\n\n _lineWidth = material.linewidth + threshold\n\n // check if we intersect the sphere bounds\n if (geometry.boundingSphere === null) {\n geometry.computeBoundingSphere()\n }\n\n _sphere.copy(geometry.boundingSphere).applyMatrix4(matrixWorld)\n\n // increase the sphere bounds by the worst case line screen space width\n let sphereMargin\n if (worldUnits) {\n sphereMargin = _lineWidth * 0.5\n } else {\n const distanceToSphere = Math.max(camera.near, _sphere.distanceToPoint(_ray.origin))\n sphereMargin = getWorldSpaceHalfWidth(camera, distanceToSphere, material.resolution)\n }\n\n _sphere.radius += sphereMargin\n\n if (_ray.intersectsSphere(_sphere) === false) {\n return\n }\n\n // check if we intersect the box bounds\n if (geometry.boundingBox === null) {\n geometry.computeBoundingBox()\n }\n\n _box.copy(geometry.boundingBox).applyMatrix4(matrixWorld)\n\n // increase the box bounds by the worst case line width\n let boxMargin\n if (worldUnits) {\n boxMargin = _lineWidth * 0.5\n } else {\n const distanceToBox = Math.max(camera.near, _box.distanceToPoint(_ray.origin))\n boxMargin = getWorldSpaceHalfWidth(camera, distanceToBox, material.resolution)\n }\n\n _box.expandByScalar(boxMargin)\n\n if (_ray.intersectsBox(_box) === false) {\n return\n }\n\n if (worldUnits) {\n raycastWorldUnits(this, intersects)\n } else {\n raycastScreenSpace(this, camera, intersects)\n }\n }\n\n onBeforeRender(renderer) {\n\n const uniforms = this.material.uniforms;\n\n if (uniforms && uniforms.resolution) {\n\n renderer.getViewport(_viewport);\n this.material.uniforms.resolution.value.set(_viewport.z, _viewport.w);\n\n }\n\n }\n}\n\nexport { LineSegments2 }\n"],"names":["Vector4","Vector3","Matrix4","Line3","Box3","Sphere","UV1","MathUtils","Mesh","LineSegmentsGeometry","LineMaterial","InstancedInterleavedBuffer","InterleavedBufferAttribute"],"mappings":";;;;;;AAgBA,MAAM,YAAY,IAAIA,MAAAA;AAEtB,MAAM,SAAS,IAAIC,MAAAA,QAAS;AAC5B,MAAM,OAAO,IAAIA,MAAAA,QAAS;AAE1B,MAAM,UAAU,IAAID,MAAAA,QAAS;AAC7B,MAAM,QAAQ,IAAIA,MAAAA,QAAS;AAE3B,MAAM,YAAY,IAAIA,MAAAA,QAAS;AAC/B,MAAM,aAAa,IAAIC,MAAAA,QAAS;AAChC,MAAM,YAAY,IAAIC,MAAAA,QAAS;AAC/B,MAAM,QAAQ,IAAIC,MAAAA,MAAO;AACzB,MAAM,gBAAgB,IAAIF,MAAAA,QAAS;AAEnC,MAAM,OAAO,IAAIG,MAAAA,KAAM;AACvB,MAAM,UAAU,IAAIC,MAAAA,OAAQ;AAC5B,MAAM,qBAAqB,IAAIL,MAAAA,QAAS;AAExC,IAAI,MAAM;AAIV,SAAS,uBAAuB,QAAQ,UAAU,YAAY;AAI5D,qBAAmB,IAAI,GAAG,GAAG,CAAC,UAAU,CAAG,EAAE,aAAa,OAAO,gBAAgB;AACjF,qBAAmB,eAAe,IAAM,mBAAmB,CAAC;AAC5D,qBAAmB,IAAI,aAAa,WAAW;A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AI,KAAK,iBAAiB,OAAO,MAAM,OAAO;AAC5C;AAAA,IACD;AAGD,QAAI,SAAS,gBAAgB,MAAM;AACjC,eAAS,mBAAoB;AAAA,IAC9B;AAED,SAAK,KAAK,SAAS,WAAW,EAAE,aAAa,WAAW;AAGxD,QAAI;AACJ,QAAI,YAAY;AACd,kBAAY,aAAa;AAAA,IAC/B,OAAW;AACL,YAAM,gBAAgB,KAAK,IAAI,OAAO,MAAM,KAAK,gBAAgB,KAAK,MAAM,CAAC;AAC7E,kBAAY,uBAAuB,QAAQ,eAAe,SAAS,UAAU;AAAA,IAC9E;AAED,SAAK,eAAe,SAAS;AAE7B,QAAI,KAAK,cAAc,IAAI,MAAM,OAAO;AACtC;AAAA,IACD;AAED,QAAI,YAAY;AACd,wBAAkB,MAAM,UAAU;AAAA,IACxC,OAAW;AACL,yBAAmB,MAAM,QAAQ,UAAU;AAAA,IAC5C;AAAA,EACF;AAAA,EAED,eAAe,UAAU;AAEvB,UAAM,WAAW,KAAK,SAAS;AAE/B,QAAI,YAAY,SAAS,YAAY;AAEnC,eAAS,YAAY,SAAS;AAC9B,WAAK,SAAS,SAAS,WAAW,MAAM,IAAI,UAAU,GAAG,UAAU,CAAC;AAAA,IAErE;AAAA,EAEF;AACH;;"}
|
package/lines/LineSegments2.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { Vector4, Vector3, Matrix4, Line3, Box3, Sphere, Mesh, InstancedInterleavedBuffer, InterleavedBufferAttribute, MathUtils } from "three";
|
2
2
|
import { LineSegmentsGeometry } from "./LineSegmentsGeometry.js";
|
3
3
|
import { LineMaterial } from "./LineMaterial.js";
|
4
|
+
import { UV1 } from "../_polyfill/uv1.js";
|
4
5
|
const _viewport = new Vector4();
|
5
6
|
const _start = new Vector3();
|
6
7
|
const _end = new Vector3();
|
@@ -47,7 +48,7 @@ function raycastWorldUnits(lineSegments, intersects) {
|
|
47
48
|
face: null,
|
48
49
|
faceIndex: i,
|
49
50
|
uv: null,
|
50
|
-
|
51
|
+
[UV1]: null
|
51
52
|
});
|
52
53
|
}
|
53
54
|
}
|
@@ -125,7 +126,7 @@ function raycastScreenSpace(lineSegments, camera, intersects) {
|
|
125
126
|
face: null,
|
126
127
|
faceIndex: i,
|
127
128
|
uv: null,
|
128
|
-
|
129
|
+
[UV1]: null
|
129
130
|
});
|
130
131
|
}
|
131
132
|
}
|