mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-01-30 15:42:42 +08:00
Add default mesh UV mapping, closes #1192
Add amend edit options for created mesh
This commit is contained in:
parent
3ac0ffe85b
commit
59a4fe1836
@ -960,8 +960,9 @@ BARS.defineActions(function() {
|
||||
minor_sides: {label: 'dialog.add_primitive.minor_sides', type: 'number', value: 8, min: 2, max: 32, condition: ({shape}) => ['torus'].includes(shape)},
|
||||
},
|
||||
onConfirm(result) {
|
||||
function runEdit(amended, result) {
|
||||
let elements = [];
|
||||
Undo.initEdit({elements});
|
||||
Undo.initEdit({elements}, amended);
|
||||
let mesh = new Mesh({
|
||||
name: result.shape,
|
||||
vertices: {}
|
||||
@ -1201,6 +1202,9 @@ BARS.defineActions(function() {
|
||||
mesh.init()
|
||||
if (Group.selected) Group.selected.unselect()
|
||||
mesh.select()
|
||||
UVEditor.selected_faces.replace(Object.keys(mesh.faces));
|
||||
UVEditor.setAutoSize(null, true);
|
||||
UVEditor.selected_faces.empty();
|
||||
Undo.finishEdit('Add primitive');
|
||||
Blockbench.dispatchEvent( 'add_mesh', {object: mesh} )
|
||||
|
||||
@ -1210,6 +1214,19 @@ BARS.defineActions(function() {
|
||||
}
|
||||
})
|
||||
}
|
||||
runEdit(false, result);
|
||||
|
||||
Undo.amendEdit({
|
||||
diameter: {label: 'dialog.add_primitive.diameter', type: 'number', value: result.diameter},
|
||||
height: {label: 'dialog.add_primitive.height', type: 'number', value: result.height, condition: ['cylinder', 'cone', 'cube', 'pyramid', 'tube'].includes(result.shape)},
|
||||
sides: {label: 'dialog.add_primitive.sides', type: 'number', value: result.sides, min: 3, max: 48, condition: ['cylinder', 'cone', 'circle', 'torus', 'sphere', 'tube'].includes(result.shape)},
|
||||
minor_diameter: {label: 'dialog.add_primitive.minor_diameter', type: 'number', value: result.minor_diameter, condition: ['torus', 'tube'].includes(result.shape)},
|
||||
minor_sides: {label: 'dialog.add_primitive.minor_sides', type: 'number', value: result.minor_sides, min: 2, max: 32, condition: ['torus'].includes(result.shape)},
|
||||
}, form => {
|
||||
Object.assign(result, form);
|
||||
runEdit(true, result);
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
new Action('add_mesh', {
|
||||
|
@ -21,6 +21,7 @@ const TextureGenerator = {
|
||||
}
|
||||
type_options.blank = 'dialog.create_texture.type.blank';
|
||||
|
||||
TextureGenerator.background_color.set('#00000000')
|
||||
var dialog = new Dialog({
|
||||
id: 'add_bitmap',
|
||||
title: tl('action.create_texture'),
|
||||
@ -55,6 +56,9 @@ const TextureGenerator = {
|
||||
if (form.type == 'template' && TextureGenerator.background_color.get().toHex8() === 'ffffffff') {
|
||||
TextureGenerator.background_color.set('#00000000')
|
||||
}
|
||||
if (form.type == 'blank' && TextureGenerator.background_color.get().toHex8() === '00000000') {
|
||||
TextureGenerator.background_color.set('#ffffffff')
|
||||
}
|
||||
},
|
||||
onConfirm: function(results) {
|
||||
results.particle = 'auto';
|
||||
@ -764,7 +768,7 @@ const TextureGenerator = {
|
||||
face_group.size = max_x * max_z;
|
||||
|
||||
let axis = [0, 1, 2].sort((a, b) => {
|
||||
return Math.abs(face_group.normal[b]) - Math.abs(face_group.normal[a])
|
||||
return Math.abs(face_group.normal[b]) - Math.abs(face_group.normal[a]) - 0.0001
|
||||
})[0]
|
||||
if (axis == 0 && face_group.normal[0] >= 0) face_group.face_key = 'east';
|
||||
if (axis == 0 && face_group.normal[0] <= 0) face_group.face_key = 'west';
|
||||
|
@ -707,12 +707,11 @@ const UVEditor = {
|
||||
this.message('uv_editor.turned');
|
||||
this.loadData();
|
||||
},
|
||||
setAutoSize(event) {
|
||||
setAutoSize(event, silent) {
|
||||
let vec1 = new THREE.Vector3(),
|
||||
vec2 = new THREE.Vector3(),
|
||||
vec3 = new THREE.Vector3(),
|
||||
vec4 = new THREE.Vector3(),
|
||||
quat = new THREE.Quaternion(),
|
||||
plane = new THREE.Plane();
|
||||
|
||||
this.getMappableElements().forEach(obj => {
|
||||
@ -758,7 +757,6 @@ const UVEditor = {
|
||||
)
|
||||
let rot = cameraTargetToRotation([0, 0, 0], normal_vec.toArray());
|
||||
let e = new THREE.Euler(Math.degToRad(-rot[1] - 90), Math.degToRad(rot[0]), 0);
|
||||
console.log({rot, e, normal_vec})
|
||||
face.vertices.forEach(vkey => {
|
||||
let coplanar_pos = plane.projectPoint(vec3.fromArray(obj.vertices[vkey]), vec4.set(0, 0, 0));
|
||||
coplanar_pos.applyEuler(e);
|
||||
@ -843,8 +841,8 @@ const UVEditor = {
|
||||
}
|
||||
obj.preview_controller.updateUV(obj);
|
||||
})
|
||||
this.message('uv_editor.autouv')
|
||||
this.loadData()
|
||||
if (!silent) this.message('uv_editor.autouv');
|
||||
this.loadData();
|
||||
},
|
||||
setRelativeAutoSize(event) {
|
||||
var scope = this;
|
||||
|
@ -94,14 +94,17 @@ class UndoSystem {
|
||||
function updateValue() {
|
||||
let form_values = {};
|
||||
for (let key in form) {
|
||||
if (input_elements[key]) {
|
||||
form_values[key] = input_elements[key].get();
|
||||
}
|
||||
}
|
||||
Undo.undo(null, true);
|
||||
callback(form_values);
|
||||
}
|
||||
|
||||
for (let key in form) {
|
||||
let form_line = form[key];
|
||||
if (!Condition(form_line.condition)) continue;
|
||||
let line = document.createElement('div');
|
||||
line.className = 'amend_edit_line';
|
||||
dialog.append(line);
|
||||
|
Loading…
Reference in New Issue
Block a user