Skip to content

Commit

Permalink
index.js: fix ArrayBuffer for handle_special_geometry
Browse files Browse the repository at this point in the history
index.js: change return signature of merge_geometries

+ adapt handle_special_geometry
+ fix handling of multiple materials per group in handle_special_geometry
+ fix line 35
+ simplify handle_special_geometry
  • Loading branch information
ManifoldFR committed May 7, 2024
1 parent 0b0e82a commit 66490d9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dist/main.min.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions dist/main.min.js.THIRD_PARTY_LICENSES.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
"license": "MIT",
"licenseText": "The MIT License\n\nCopyright © 2010-2024 three.js authors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n"
},
{
"name": "three",
"version": "0.160.1",
"author": "mrdoob",
"repository": "https://github.com/mrdoob/three.js",
"source": "https://registry.npmjs.org/three/-/three-0.160.1.tgz",
"license": "MIT",
"licenseText": "The MIT License\n\nCopyright © 2010-2023 three.js authors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n"
},
{
"name": "wtd-core",
"version": "3.0.0",
Expand Down
45 changes: 27 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ extensionCodec.register({
return to_return
},
});

// Float32Array
extensionCodec.register({
type: 0x17,
Expand Down Expand Up @@ -136,20 +137,32 @@ function merge_geometries(object, preserve_materials = false) {
}
collectGeometries(object, root_transform);
let result = null;
let material;
if (geometries.length == 1) {
result = geometries[0];
if (preserve_materials) {
result.material = materials[0];
material = materials[0];
}
} else if (geometries.length > 1) {
result = mergeGeometries(geometries, true);
const ngeom = result.groups.length;
let mts = [];
if (preserve_materials) {
result.material = materials;
for (let i = 0; i < ngeom; i++) {
const group = result.groups[i];
let m = materials[i];
if (Array.isArray(m)) {
mts.push(m[m.length - 1]);
} else {
mts.push(m);
}
}
material = mts;
}
} else {
result = new THREE.BufferGeometry();
}
return result;
return [result, material];
}

// Handler for special texture types that we want to support
Expand Down Expand Up @@ -194,30 +207,28 @@ function handle_special_geometry(geom) {
console.warn("_meshfile is deprecated. Please use _meshfile_geometry for geometries and _meshfile_object for objects with geometry and material");
geom.type = "_meshfile_geometry";
}
let geometry = null;
let m = null;
if (geom.type == "_meshfile_geometry") {
if (geom.format == "obj") {
let loader = new OBJLoader2();
let obj = loader.parse(geom.data + "\n");
let loaded_geom = merge_geometries(obj);
loaded_geom.uuid = geom.uuid;
return loaded_geom;
[geometry, m] = merge_geometries(obj);
geometry.uuid = geom.uuid;
} else if (geom.format == "dae") {
let loader = new ColladaLoader();
let obj = loader.parse(geom.data);
let result = merge_geometries(obj.scene);
result.uuid = geom.uuid;
return result;
[geometry, m] = merge_geometries(obj.scene);
geometry.uuid = geom.uuid;
} else if (geom.format == "stl") {
let loader = new STLLoader();
let loaded_geom = loader.parse(geom.data.buffer);
loaded_geom.uuid = geom.uuid;
return loaded_geom;
geometry = loader.parse(geom.data.buffer);
geometry.uuid = geom.uuid;
} else {
console.error("Unsupported mesh type:", geom);
return null;
}
}
return null;
return geometry;
}

// The ExtensibleObjectLoader extends the THREE.ObjectLoader
Expand Down Expand Up @@ -285,16 +296,14 @@ class ExtensibleObjectLoader extends THREE.ObjectLoader {
this.onTextureLoad();
}
let obj = loader.parse(json.data + "\n", path);
geometry = merge_geometries(obj, true);
[geometry, material] = merge_geometries(obj, true);
geometry.uuid = json.uuid;
material = geometry.material;
} else if (json.format == "dae") {
let loader = new ColladaLoader(manager);
loader.onTextureLoad = this.onTextureLoad;
let obj = loader.parse(json.data, path);
geometry = merge_geometries(obj.scene, true);
[geometry, material] = merge_geometries(obj.scene, true);
geometry.uuid = json.uuid;
material = geometry.material;
} else if (json.format == "stl") {
let loader = new STLLoader();
geometry = loader.parse(json.data.buffer, path);
Expand Down

0 comments on commit 66490d9

Please sign in to comment.