fix svg load vertex order (normals). pass opts to png loader

This commit is contained in:
Stewart Allen 2022-02-26 00:15:35 -05:00
commit a12161215b
3 changed files with 12 additions and 3 deletions

View file

@ -30,6 +30,6 @@
* `C` add preferences for normal length and color
* `-` add preferences for face selection and matching
* `-` add svg and image import conversion (share code with Kiri:Moto)
* `P` add svg and image import conversion (created shared load. libs)
* `C` add version chooser
* `C` add welcome menu

View file

@ -28,7 +28,7 @@ function nameOf(file, part, i) {
return part ? part : `${file}_${i}`;
}
function load_data(data, file, ext) {
function load_data(data, file, ext, opt = {}) {
ext = ext || name.toLowerCase().split('.').pop();
return new Promise((resolve, reject) => {
let i = 1;
@ -55,6 +55,7 @@ function load_data(data, file, ext) {
break;
case "png":
load.PNG.parse(data, {
...opt,
done(data) {
resolve({ mesh: data, file });
}

View file

@ -34,10 +34,18 @@ function parse(text, opt = {}) {
bevelEnabled: false
});
let array = geom.attributes.position.array;
// invert y (todo: invert vertex order otherwise normals inverted)
// invert y
for (let i=0; i<array.length; i+=3) {
array[i+1] = -array[i+1];
}
// invert vertex order to compensate for inverted y
for (let i=0; i<array.length; i+=9) {
let tmp = array.slice(i,i+3);
for (let j=0; j<3; j++) {
array[i+j] = array[i+j+3];
array[i+j+3] = tmp[j];
}
}
objs.push([ ...array ]);
}