mirror of
https://github.com/JannisX11/blockbench.git
synced 2024-11-21 01:13:37 +08:00
Knife tool WIP
This commit is contained in:
parent
1deccb8967
commit
aada92eb38
@ -2062,6 +2062,7 @@ const BARS = {
|
|||||||
'pivot_tool',
|
'pivot_tool',
|
||||||
'vertex_snap_tool',
|
'vertex_snap_tool',
|
||||||
'stretch_tool',
|
'stretch_tool',
|
||||||
|
'knife_tool',
|
||||||
'seam_tool',
|
'seam_tool',
|
||||||
'pan_tool',
|
'pan_tool',
|
||||||
'brush_tool',
|
'brush_tool',
|
||||||
|
@ -98,6 +98,54 @@ const ProportionalEdit = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class KnifeToolContext {
|
||||||
|
/**
|
||||||
|
* Click
|
||||||
|
* Create point
|
||||||
|
* Snap point to face or edge
|
||||||
|
* Connect points with lines
|
||||||
|
* Press something to apply
|
||||||
|
*
|
||||||
|
* Iterate over faces
|
||||||
|
* Remove former face, refill section between old edges and new edges
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
this.meshes = [];
|
||||||
|
this.points = [];
|
||||||
|
|
||||||
|
this.points_geo = new THREE.BufferGeometry();
|
||||||
|
let points_material = new THREE.PointsMaterial({size: 7, sizeAttenuation: false, vertexColors: true});
|
||||||
|
this.points_mesh = new THREE.Points(this.points_geo, points_material);
|
||||||
|
this.lines_mesh = new THREE.Points(this.points_geo, points_material);
|
||||||
|
|
||||||
|
outline.add(points);
|
||||||
|
}
|
||||||
|
addPoint(data) {
|
||||||
|
if (data.element instanceof Mesh == false) return;
|
||||||
|
console.log(data);
|
||||||
|
this.meshes.safePush(data.element);
|
||||||
|
}
|
||||||
|
apply() {
|
||||||
|
|
||||||
|
Undo.initEdit({elements: this.meshes});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Undo.finishEdit('Use knife tool');
|
||||||
|
this.remove();
|
||||||
|
}
|
||||||
|
discard() {
|
||||||
|
this.remove();
|
||||||
|
}
|
||||||
|
remove() {
|
||||||
|
Canvas.scene.remove(this.points_mesh);
|
||||||
|
Canvas.scene.remove(this.lines_mesh);
|
||||||
|
KnifeToolContext.current = null;
|
||||||
|
}
|
||||||
|
static current = null;
|
||||||
|
}
|
||||||
|
|
||||||
async function autoFixMeshEdit() {
|
async function autoFixMeshEdit() {
|
||||||
let meshes = Mesh.selected;
|
let meshes = Mesh.selected;
|
||||||
@ -1000,6 +1048,27 @@ BARS.defineActions(function() {
|
|||||||
BarItems.view_mode.onChange();
|
BarItems.view_mode.onChange();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
new Tool('knife_tool', {
|
||||||
|
icon: 'surgical',
|
||||||
|
transformerMode: 'hidden',
|
||||||
|
category: 'tools',
|
||||||
|
selectElements: true,
|
||||||
|
modes: ['edit'],
|
||||||
|
condition: () => Modes.edit && Mesh.hasAny(),
|
||||||
|
onCanvasClick(data) {
|
||||||
|
if (!data) return;
|
||||||
|
if (!KnifeToolContext.current) KnifeToolContext.current = new KnifeToolContext();
|
||||||
|
let context = KnifeToolContext.current;
|
||||||
|
context.addPoint(data);
|
||||||
|
},
|
||||||
|
onSelect() {
|
||||||
|
},
|
||||||
|
onUnselect() {
|
||||||
|
if (KnifeToolContext.current) {
|
||||||
|
KnifeToolContext.current.apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
new BarSelect('select_seam', {
|
new BarSelect('select_seam', {
|
||||||
options: {
|
options: {
|
||||||
auto: true,
|
auto: true,
|
||||||
|
@ -1183,6 +1183,8 @@
|
|||||||
"action.rotate_tool.desc": "Tool to select and rotate elements",
|
"action.rotate_tool.desc": "Tool to select and rotate elements",
|
||||||
"action.pivot_tool": "Pivot Tool",
|
"action.pivot_tool": "Pivot Tool",
|
||||||
"action.pivot_tool.desc": "Tool to change the pivot point of elements and bones",
|
"action.pivot_tool.desc": "Tool to change the pivot point of elements and bones",
|
||||||
|
"action.knife_tool": "Knife Tool",
|
||||||
|
"action.knife_tool.desc": "Tool to cut mesh faces into smaller pieces",
|
||||||
"action.seam_tool": "Seam Tool",
|
"action.seam_tool": "Seam Tool",
|
||||||
"action.seam_tool.desc": "Tool to define UV seams on mesh edges",
|
"action.seam_tool.desc": "Tool to define UV seams on mesh edges",
|
||||||
"action.pan_tool": "Pan Tool",
|
"action.pan_tool": "Pan Tool",
|
||||||
|
Loading…
Reference in New Issue
Block a user