From dc479ce9ce15844daeddcd8da09f1fdec5ef4b91 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Sun, 25 Jun 2023 19:13:43 +0200 Subject: [PATCH] 3D brush outlinne support for cubes + rotation fix --- js/outliner/cube.js | 39 +++++++++++++++++++++++++++++++++++++++ js/preview/preview.js | 6 +++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/js/outliner/cube.js b/js/outliner/cube.js index b0ab026b..ccf3a154 100644 --- a/js/outliner/cube.js +++ b/js/outliner/cube.js @@ -49,6 +49,45 @@ class CubeFace extends Face { case 'down': return [7, 2, 3, 6]; } } + UVToLocal(point) { + let {from, to} = this.cube; + let vector = new THREE.Vector3().fromArray(from); + + let lerp_x = Math.getLerp(this.uv[0], this.uv[2], point[0]); + let lerp_y = Math.getLerp(this.uv[1], this.uv[3], point[1]); + + if (this.direction == 'east') { + vector.x = to[0]; + vector.y = Math.lerp(to[1], from[1], lerp_y); + vector.z = Math.lerp(to[2], from[2], lerp_x); + } + if (this.direction == 'west') { + vector.y = Math.lerp(to[1], from[1], lerp_y); + vector.z = Math.lerp(from[2], to[2], lerp_x); + } + if (this.direction == 'up') { + vector.y = to[1]; + vector.z = Math.lerp(from[2], to[2], lerp_y); + vector.x = Math.lerp(from[0], to[0], lerp_x); + } + if (this.direction == 'down') { + vector.z = Math.lerp(to[2], from[2], lerp_y); + vector.x = Math.lerp(from[0], to[0], lerp_x); + } + if (this.direction == 'south') { + vector.z = to[2]; + vector.y = Math.lerp(to[1], from[1], lerp_y); + vector.x = Math.lerp(from[0], to[0], lerp_x); + } + if (this.direction == 'north') { + vector.y = Math.lerp(to[1], from[1], lerp_y); + vector.x = Math.lerp(to[0], from[0], lerp_x); + } + vector.x -= this.cube.origin[0]; + vector.y -= this.cube.origin[1]; + vector.z -= this.cube.origin[2]; + return vector; + } } new Property(CubeFace, 'number', 'rotation', {default: 0}); new Property(CubeFace, 'number', 'tint', {default: -1}); diff --git a/js/preview/preview.js b/js/preview/preview.js index 51e1917e..3a88aa61 100644 --- a/js/preview/preview.js +++ b/js/preview/preview.js @@ -1053,12 +1053,16 @@ class Preview { Canvas.brush_outline.position.addScaledVector(world_normal, z_fight_offset); // rotation - Canvas.brush_outline.quaternion.setFromUnitVectors(new THREE.Vector3(0, 0, 1), world_normal); + Canvas.brush_outline.quaternion.setFromUnitVectors(new THREE.Vector3(0, 0, 1), intersect.face.normal); + Canvas.brush_outline.rotation.z = 0; let inverse = Reusable.quat2.copy(Canvas.brush_outline.quaternion).invert(); brush_coord_difference.applyQuaternion(inverse); let rotation = Math.atan2(brush_coord_difference.x, -brush_coord_difference.y); Canvas.brush_outline.rotation.z = rotation; + + + Canvas.brush_outline.quaternion.premultiply(world_quaternion); } } }