Skip to content

Commit

Permalink
Fix Rotation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadowkitten47 committed Nov 17, 2024
1 parent 9118da3 commit f20323c
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions plugins/meshy/meshy.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
purgeEvents(codec);
codec = Codecs['bedrock_old'];
purgeEvents(codec);


},
});
Expand Down Expand Up @@ -266,16 +266,16 @@
const mesh = new Mesh({name: meta.name, autouv: 0, color: group.color, vertices: []});
meta.rotation ??= [0, 0, 0];
meta.origin ??= [0, 0, 0];


mesh.origin = meta.origin;
mesh.rotation = meta.rotation;
const polys = polyMesh.polys.slice(meta.start, meta.start + meta.length);
for ( let face of polys ) {
const unique = new Set();
const vertices = []
const uvs = {}


//Low key pissed rn assign origin first
mesh.origin = meta.origin;
mesh.rotation = meta.rotation;
for (let point of face ) {

//Make sure we don't add the same vertex twice ( This means that a quad was folded in half )
Expand All @@ -284,11 +284,13 @@

//Do the transformations to revert the vertices
let postion = polyMesh.positions[point[0]]

postion = postion.map((coord, i) => coord - meta.origin[i]);
console.log(postion)
postion = rotatePoint(postion, meta.origin, multiplyScalar(meta.rotation, -1))
postion[0] /= -1;

//No reason to use "clone" here but I did it becuase I didn't want to change it
let clone = [...postion]
clone[0] *= -1
clone = rotatePoint(clone, mesh.origin, [ mesh.rotation[0] * -1, mesh.rotation[1] * -1, mesh.rotation[2] * -1 ])
clone = clone.V3_add(-mesh.origin[0], -mesh.origin[1], -mesh.origin[2])
postion = clone
//Save the point to the mesh
mesh.vertices[`v${point[0]}`] = postion;
vertices.push(`v${point[0]}`);
Expand All @@ -303,7 +305,7 @@
}
mesh.addFaces(new MeshFace(mesh, { uv: uvs, vertices }));
}

mesh.addTo(group).init();
}
}
Expand Down Expand Up @@ -348,8 +350,8 @@
//gets vertices of a Mesh and applys transformations to the points so that they can be exported
function getVertices(mesh) {
const verts = Object.entries(mesh.vertices).map( ( [key, point ]) => {
point = rotatePoint(point, mesh.origin, mesh.rotation)
point.V3_add(mesh.origin[0], mesh.origin[1], mesh.origin[2])
point = rotatePoint(point, mesh.origin, mesh.rotation)
point[0] *= -1;
return [ key, point ]
})
Expand Down

0 comments on commit f20323c

Please sign in to comment.