Improve face orientations on mesh templates

Fix console error when joining meshes
This commit is contained in:
JannisX11 2021-11-21 18:22:03 +01:00
parent 4b7dc2d829
commit ccc947b885
3 changed files with 9 additions and 6 deletions

View File

@ -2139,7 +2139,7 @@ BARS.defineActions(function() {
category: 'edit',
condition: {modes: ['edit'], features: ['meshes'], method: () => (Mesh.selected.length >= 2)},
click() {
let elements = Mesh.selected
let elements = Mesh.selected.slice();
Undo.initEdit({elements});
let original = Mesh.selected[0];
let vector = new THREE.Vector3();
@ -2171,6 +2171,7 @@ BARS.defineActions(function() {
}
mesh.remove();
elements.remove(mesh);
Mesh.selected.remove(mesh)
})
updateSelection();

View File

@ -196,7 +196,7 @@ const TextureGenerator = {
}
//Cancel if no cubes
if (templates.length == 0) {
Blockbench.showMessage('No valid cubes', 'center')
Blockbench.showMessage('message.no_valid_elements', 'center')
return;
}
templates.sort(function(a,b) {
@ -653,13 +653,14 @@ const TextureGenerator = {
normal_vec,
vec2.fromArray(mesh.vertices[face_group.faces[0].vertices[0]])
)
let rot = cameraTargetToRotation([0, 0, 0], normal_vec.toArray());
let e = new THREE.Euler(Math.degToRad(rot[1] - 90), Math.degToRad(rot[0]), 0);
let vertex_uvs = {};
face_group.faces.forEach(face => {
face.vertices.forEach(vkey => {
if (!vertex_uvs[vkey]) {
let coplanar_pos = plane.projectPoint(vec3.fromArray(mesh.vertices[vkey]), vec4);
let q = new THREE.Quaternion().setFromUnitVectors(normal_vec, THREE.NormalY)
coplanar_pos.applyQuaternion(q);
coplanar_pos.applyEuler(e);
vertex_uvs[vkey] = [
Math.roundTo(coplanar_pos.x, 4),
Math.roundTo(coplanar_pos.z, 4),
@ -777,7 +778,7 @@ const TextureGenerator = {
})
if (face_list.length == 0) {
Blockbench.showMessage('No valid cubes', 'center')
Blockbench.showMessage('message.no_valid_elements', 'center')
return;
}
@ -1042,7 +1043,7 @@ const TextureGenerator = {
})
if (face_list.length == 0) {
Blockbench.showMessage('No valid cubes', 'center')
Blockbench.showMessage('message.no_valid_elements', 'center')
return;
}

View File

@ -253,6 +253,7 @@
"message.no_animation_to_import": "No animations to import",
"message.copy_paste_tool_viewport": "This tool can only be used in the UV panel",
"message.box_uv_for_meshes": "Meshes cannot be used in box UV templates",
"message.no_valid_elements": "No valid elements selected...",
"message.wireframe.enabled": "Wireframe view enabled",
"message.wireframe.disabled": "Wireframe view disabled",