mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-01-18 15:26:19 +08:00
3D brush outlinne support for cubes + rotation fix
This commit is contained in:
parent
16b72b017e
commit
dc479ce9ce
@ -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});
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user