1 line
44 KiB
Plaintext
1 line
44 KiB
Plaintext
|
|
{"version":3,"file":"BufferGeometryUtils.cjs","sources":["../../src/utils/BufferGeometryUtils.ts"],"sourcesContent":["import {\n BufferAttribute,\n BufferGeometry,\n Float32BufferAttribute,\n InterleavedBuffer,\n InterleavedBufferAttribute,\n TriangleFanDrawMode,\n TriangleStripDrawMode,\n TrianglesDrawMode,\n Vector3,\n Mesh,\n Line,\n Points,\n Material,\n SkinnedMesh,\n} from 'three'\n\nimport { getWithKey } from '../types/helpers'\nimport type { TypedArrayConstructors, TypedArray } from '../types/shared'\n\n/**\n * @param {Array<BufferGeometry>} geometries\n * @param {Boolean} useGroups\n * @return {BufferGeometry}\n */\nexport const mergeBufferGeometries = (geometries: BufferGeometry[], useGroups?: boolean): BufferGeometry | null => {\n const isIndexed = geometries[0].index !== null\n\n const attributesUsed = new Set(Object.keys(geometries[0].attributes))\n const morphAttributesUsed = new Set(Object.keys(geometries[0].morphAttributes))\n\n const attributes: { [key: string]: Array<InterleavedBufferAttribute | BufferAttribute> } = {}\n const morphAttributes: { [key: string]: Array<BufferAttribute | InterleavedBufferAttribute>[] } = {}\n\n const morphTargetsRelative = geometries[0].morphTargetsRelative\n\n const mergedGeometry = new BufferGeometry()\n\n let offset = 0\n\n geometries.forEach((geom, i) => {\n let attributesCount = 0\n\n // ensure that all geometries are indexed, or none\n\n if (isIndexed !== (geom.index !== null)) {\n console.error(\n 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' +\n i +\n '. All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.',\n )\n return null\n }\n\n // gather attributes, exit early if they're different\n\n for (let name in geom.attributes) {\n if (!attributesUsed.has(name)) {\n console.error(\n 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' +\n i +\n '. All geometries must have compatible attributes; make sure \"' +\n name +\n '\" attribute exists among all geometries, or in none of them.',\n )\n return null\n }\n\n if (attributes[name] === undefined) {\n attributes[name] = []\n }\n\n attributes[name].push(geom.attributes[name])\n\n attributesCount++\n }\n\n // ensure geometries have the same number of attributes\n\n if (attributesCount !== attributesUsed.size) {\n console.error(\n 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' +\n i +\n '. Make sure all geometries have the same number of attributes.',\n )\n return null\n }\n\n // gather morph attributes, exit early if they're different\n\n if (morphTargetsRelative !== geom.morphTargetsRelative) {\n console.error(\n 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' +\n i +\n '. .morphTargetsRelative must be consistent throughout all geometries.',\n )\n return null\n }\n\n for (let name in geom.morphAttributes) {\n if (!morphAttributesUsed.has(name)) {\n console.error(\n 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' +\n i +\n '. .morphAttributes must be consistent throughout all geometries.',\n )\n return null\n }\n\n if (morphAttributes[name] === undefined) morphAttributes[name] = []\n\n morphAttributes[name].push(geom.morphAttributes[name])\n }\n\n // gather .userData\n\n mergedGeometry.userData.mergedUserData = mergedGeometry.userData.mergedUserData || []\n mergedGeometry.userData.mergedUserData.push(geom.userData)\n\n if (useGroups) {\n let count\n\n if (geom.index) {\n count = geom.index.count\n } else if (geom.attributes.position !== undefined) {\n count = geom.att
|