Skip to content

Commit

Permalink
fix 3MF imports that lack model transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
stewartoallen committed Sep 8, 2024
1 parent d20e51a commit 731b45e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/kiri/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ function platformLoadFiles(files, group) {
load.TMF.parseAsync(data).then(models => {
api.hide.alert(msg);
if (models.length > 1 && !group) {
UC.confirm(`group ${models.length} objects?`).then(ok => {
api.uc.confirm(`group ${models.length} objects?`).then(ok => {
if (ok) {
group = [];
}
Expand Down
22 changes: 13 additions & 9 deletions src/load/3mf.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,21 @@ function loadModel(doc) {
model = node.getAttribute("name") || undefined;
query(node, ["components","+component"], (type, node) => {
let objectid = node.getAttribute('objectid');
let mat = node.getAttribute('transform').split(' ').map(v => parseFloat(v));
mat = [
...mat.slice(0,3), 0,
...mat.slice(3,6), 0,
...mat.slice(6,9), 0,
...mat.slice(9,12), 1
];
let ref = byid[objectid];
if (!ref) return;
let m4 = new Matrix4().fromArray(mat);
let pos = new BufferAttribute(ref.faces.toFloat32(), 3).applyMatrix4(m4);
let pos = new BufferAttribute(ref.faces.toFloat32(), 3);
let transform = node.getAttribute('transform');
if (transform) {
let mat = transform.split(' ').map(v => parseFloat(v));
mat = [
...mat.slice(0,3), 0,
...mat.slice(3,6), 0,
...mat.slice(6,9), 0,
...mat.slice(9,12), 1
];
let m4 = new Matrix4().fromArray(mat);
pos = pos.applyMatrix4(m4);
}
faces.appendAll(pos.array);
});
break;
Expand Down

0 comments on commit 731b45e

Please sign in to comment.