1 line
36 KiB
Plaintext
1 line
36 KiB
Plaintext
|
|
{"version":3,"file":"OBJLoader.cjs","sources":["../../src/loaders/OBJLoader.js"],"sourcesContent":["import {\n BufferGeometry,\n FileLoader,\n Float32BufferAttribute,\n Group,\n LineBasicMaterial,\n LineSegments,\n Loader,\n Material,\n Mesh,\n MeshPhongMaterial,\n Points,\n PointsMaterial,\n Vector3,\n} from 'three'\n\n// o object_name | g group_name\nconst _object_pattern = /^[og]\\s*(.+)?/\n// mtllib file_reference\nconst _material_library_pattern = /^mtllib /\n// usemtl material_name\nconst _material_use_pattern = /^usemtl /\n// usemap map_name\nconst _map_use_pattern = /^usemap /\n\nconst _vA = /* @__PURE__ */ new Vector3()\nconst _vB = /* @__PURE__ */ new Vector3()\nconst _vC = /* @__PURE__ */ new Vector3()\n\nconst _ab = /* @__PURE__ */ new Vector3()\nconst _cb = /* @__PURE__ */ new Vector3()\n\nfunction ParserState() {\n const state = {\n objects: [],\n object: {},\n\n vertices: [],\n normals: [],\n colors: [],\n uvs: [],\n\n materials: {},\n materialLibraries: [],\n\n startObject: function (name, fromDeclaration) {\n // If the current object (initial from reset) is not from a g/o declaration in the parsed\n // file. We need to use it for the first parsed g/o to keep things in sync.\n if (this.object && this.object.fromDeclaration === false) {\n this.object.name = name\n this.object.fromDeclaration = fromDeclaration !== false\n return\n }\n\n const previousMaterial =\n this.object && typeof this.object.currentMaterial === 'function' ? this.object.currentMaterial() : undefined\n\n if (this.object && typeof this.object._finalize === 'function') {\n this.object._finalize(true)\n }\n\n this.object = {\n name: name || '',\n fromDeclaration: fromDeclaration !== false,\n\n geometry: {\n vertices: [],\n normals: [],\n colors: [],\n uvs: [],\n hasUVIndices: false,\n },\n materials: [],\n smooth: true,\n\n startMaterial: function (name, libraries) {\n const previous = this._finalize(false)\n\n // New usemtl declaration overwrites an inherited material, except if faces were declared\n // after the material, then it must be preserved for proper MultiMaterial continuation.\n if (previous && (previous.inherited || previous.groupCount <= 0)) {\n this.materials.splice(previous.index, 1)\n }\n\n const material = {\n index: this.materials.length,\n name: name || '',\n mtllib: Array.isArray(libraries) && libraries.length > 0 ? libraries[libraries.length - 1] : '',\n smooth: previous !== undefined ? previous.smooth : this.smooth,\n groupStart: previous !== undefined ? previous.groupEnd : 0,\n groupEnd: -1,\n groupCount: -1,\n inherited: false,\n\n clone: function (index) {\n const cloned = {\n index: typeof index === 'number' ? index : this.index,\n name: this.name,\n mtllib: this.mtllib,\n smooth: this.smooth,\n groupStart: 0,\n groupEnd: -1,\n groupCount: -1,\n inherited: false,\n }\n cloned.clone = this.clone.bind(cloned)\n return cloned\n },\n }\n\n this.materials.push(material)\n\n return material\n },\n\n currentMaterial: function () {\n if (this.materials.length > 0) {\n return this.materials[this.materials.length - 1]\n }\n\n return undefined\n },\n\n _finalize: function (end) {\n const lastMultiMaterial = this.currentMaterial()\n if (lastMultiMaterial && lastMultiMaterial.groupEnd === -1) {\n lastMultiMaterial.groupEnd = this.geometry.vertices.length / 3\n lastMultiMaterial.groupCount = lastMultiMaterial.groupEnd - lastMultiMaterial.groupStart\n
|