mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-01-30 15:42:42 +08:00
WIP custom cube limiter
This commit is contained in:
parent
e5e2a7b816
commit
0faf38e346
@ -337,33 +337,13 @@ const Clipbench = {
|
||||
}
|
||||
|
||||
//Canvas Limit
|
||||
if (Format.canvas_limit && !settings.deactivate_size_limit.value) {
|
||||
if (Format.cube_size_limiter && !settings.deactivate_size_limit.value) {
|
||||
|
||||
elements.forEach(s => {
|
||||
if (s instanceof Cube == false) return;
|
||||
//Push elements into 3x3 block box
|
||||
[0, 1, 2].forEach(function(ax) {
|
||||
var overlap = s.to[ax] + s.inflate - 32
|
||||
if (overlap > 0) {
|
||||
//If positive site overlaps
|
||||
s.from[ax] -= overlap
|
||||
s.to[ax] -= overlap
|
||||
|
||||
if (16 + s.from[ax] - s.inflate < 0) {
|
||||
s.from[ax] = -16 + s.inflate
|
||||
}
|
||||
} else {
|
||||
overlap = s.from[ax] - s.inflate + 16
|
||||
if (overlap < 0) {
|
||||
s.from[ax] -= overlap
|
||||
s.to[ax] -= overlap
|
||||
|
||||
if (s.to[ax] + s.inflate > 32) {
|
||||
s.to[ax] = 32 - s.inflate
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
if (s instanceof Cube) {
|
||||
//Push elements into 3x3 block box
|
||||
Format.cube_size_limiter.move(s);
|
||||
}
|
||||
})
|
||||
Canvas.updateView({elements, element_aspects: {transform: true, geometry: true}});
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ class ModelFormat {
|
||||
ModelFormat.properties[id].reset(this);
|
||||
}
|
||||
this.render_sides = data.render_sides;
|
||||
this.cube_size_limiter = data.cube_size_limiter;
|
||||
|
||||
this.codec = data.codec;
|
||||
this.onSetup = data.onSetup;
|
||||
@ -149,7 +150,7 @@ class ModelFormat {
|
||||
}
|
||||
|
||||
//Canvas Limit
|
||||
if (Format.canvas_limit && !old_format.canvas_limit && !settings.deactivate_size_limit.value) {
|
||||
if (Format.cube_size_limiter && !old_format.cube_size_limiter && !settings.deactivate_size_limit.value) {
|
||||
|
||||
Cube.all.forEach(function(s, i) {
|
||||
//Push elements into 3x3 block box
|
||||
@ -227,7 +228,6 @@ new Property(ModelFormat, 'boolean', 'integer_size');
|
||||
new Property(ModelFormat, 'boolean', 'meshes');
|
||||
new Property(ModelFormat, 'boolean', 'texture_meshes');
|
||||
new Property(ModelFormat, 'boolean', 'locators');
|
||||
new Property(ModelFormat, 'boolean', 'canvas_limit');
|
||||
new Property(ModelFormat, 'boolean', 'rotation_limit');
|
||||
new Property(ModelFormat, 'boolean', 'uv_rotation');
|
||||
new Property(ModelFormat, 'boolean', 'java_face_properties');
|
||||
|
@ -113,17 +113,19 @@ var codec = new Codec('java_block', {
|
||||
}
|
||||
element.faces = e_faces
|
||||
|
||||
function inVd(n) {
|
||||
return n < -16 || n > 32;
|
||||
}
|
||||
if (inVd(element.from[0]) ||
|
||||
inVd(element.from[1]) ||
|
||||
inVd(element.from[2]) ||
|
||||
inVd(element.to[0]) ||
|
||||
inVd(element.to[1]) ||
|
||||
inVd(element.to[2])
|
||||
) {
|
||||
overflow_cubes.push(s);
|
||||
if (Format.cube_size_limiter) {
|
||||
function inVd(n) {
|
||||
return n < -16 || n > 32;
|
||||
}
|
||||
if (inVd(element.from[0]) ||
|
||||
inVd(element.from[1]) ||
|
||||
inVd(element.from[2]) ||
|
||||
inVd(element.to[0]) ||
|
||||
inVd(element.to[1]) ||
|
||||
inVd(element.to[2])
|
||||
) {
|
||||
overflow_cubes.push(s);
|
||||
}
|
||||
}
|
||||
if (Object.keys(element.faces).length) {
|
||||
clear_elements.push(element)
|
||||
@ -465,7 +467,6 @@ var format = new ModelFormat({
|
||||
parent_model_id: true,
|
||||
vertex_color_ambient_occlusion: true,
|
||||
rotate_cubes: true,
|
||||
canvas_limit: true,
|
||||
rotation_limit: true,
|
||||
optional_box_uv: true,
|
||||
uv_rotation: true,
|
||||
@ -474,6 +475,60 @@ var format = new ModelFormat({
|
||||
select_texture_for_particles: true,
|
||||
display_mode: true,
|
||||
texture_folder: true,
|
||||
cube_size_limiter: {
|
||||
test(cube, values = 0) {
|
||||
let from = values.from || cube.from;
|
||||
let to = values.to || cube.to;
|
||||
let inflate = values.inflate == undefined ? cube.inflate : values.inflate;
|
||||
|
||||
return undefined !== from.find((v, i) => {
|
||||
return (
|
||||
to[i] + inflate > 40 ||
|
||||
to[i] + inflate < -16 ||
|
||||
from[i] - inflate > 40 ||
|
||||
from[i] - inflate < -16
|
||||
)
|
||||
})
|
||||
},
|
||||
move(cube, values = 0) {
|
||||
let from = values.from || cube.from;
|
||||
let to = values.to || cube.to;
|
||||
let inflate = values.inflate == undefined ? cube.inflate : values.inflate;
|
||||
|
||||
[0, 1, 2].forEach((ax) => {
|
||||
var overlap = to[ax] + inflate - 40
|
||||
if (overlap > 0) {
|
||||
//If positive site overlaps
|
||||
from[ax] -= overlap
|
||||
to[ax] -= overlap
|
||||
|
||||
if (16 + from[ax] - inflate < 0) {
|
||||
from[ax] = -16 + inflate
|
||||
}
|
||||
} else {
|
||||
overlap = from[ax] - inflate + 16
|
||||
if (overlap < 0) {
|
||||
from[ax] -= overlap
|
||||
to[ax] -= overlap
|
||||
|
||||
if (to[ax] + inflate > 40) {
|
||||
to[ax] = 40 - inflate
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
clamp(cube, values = 0) {
|
||||
let from = values.from || cube.from;
|
||||
let to = values.to || cube.to;
|
||||
let inflate = values.inflate == undefined ? cube.inflate : values.inflate;
|
||||
|
||||
[0, 1, 2].forEach((ax) => {
|
||||
from[ax] = Math.clamp(from[ax] - inflate, -16, 40) + inflate;
|
||||
to[ax] = Math.clamp(to[ax] + inflate, -16, 40) - inflate;
|
||||
})
|
||||
}
|
||||
},
|
||||
codec
|
||||
})
|
||||
codec.format = format;
|
||||
|
@ -277,7 +277,7 @@ class Cube extends OutlinerElement {
|
||||
}
|
||||
|
||||
// Check limits
|
||||
if (Format.canvas_limit && !settings.deactivate_size_limit.value) {
|
||||
if (Format.cube_size_limiter && !settings.deactivate_size_limit.value) {
|
||||
let from = this.from.slice(), to = this.to.slice();
|
||||
for (let check_steps = steps; check_steps > 0; check_steps--) {
|
||||
switch(axis) {
|
||||
@ -288,7 +288,7 @@ class Cube extends OutlinerElement {
|
||||
from.V3_set(rotateCoord(from));
|
||||
to.V3_set(rotateCoord(to));
|
||||
}
|
||||
if ([...from, ...to].find(value => (value > 32 || value < -16))) {
|
||||
if (Format.cube_size_limiter.test(this, {from, to})) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1178,16 +1178,13 @@
|
||||
var difference = point[axis] - previousValue
|
||||
|
||||
var overlapping = false
|
||||
if (Format.canvas_limit && !settings.deactivate_size_limit.value) {
|
||||
selected.forEach(function(obj) {
|
||||
if (obj.movable && obj.resizable) {
|
||||
overlapping = overlapping || (
|
||||
obj.to[axisNumber] + difference + obj.inflate > 32 ||
|
||||
obj.to[axisNumber] + difference + obj.inflate < -16 ||
|
||||
obj.from[axisNumber] + difference - obj.inflate > 32 ||
|
||||
obj.from[axisNumber] + difference - obj.inflate < -16
|
||||
)
|
||||
}
|
||||
if (Format.cube_size_limiter && !settings.deactivate_size_limit.value) {
|
||||
Cube.selected.forEach(function(obj) {
|
||||
let from = obj.from.slice();
|
||||
let to = obj.to.slice();
|
||||
from[axisNumber] += difference;
|
||||
to[axisNumber] += difference;
|
||||
overlapping = overlapping || Format.cube_size_limiter.test(obj, {from, to});
|
||||
})
|
||||
}
|
||||
if (!overlapping) {
|
||||
|
@ -77,7 +77,7 @@ function getSelectionCenter(all = false) {
|
||||
}
|
||||
function limitToBox(val, inflate) {
|
||||
if (typeof inflate != 'number') inflate = 0;
|
||||
if (!(Format.canvas_limit && !settings.deactivate_size_limit.value)) {
|
||||
if (!(Format.cube_size_limiter && !settings.deactivate_size_limit.value)) {
|
||||
return val;
|
||||
} else if (val + inflate > 32) {
|
||||
return 32 - inflate;
|
||||
@ -407,11 +407,14 @@ const Vertexsnap = {
|
||||
|
||||
for (i=0; i<3; i++) {
|
||||
if (m[i] === 1) {
|
||||
obj.to[i] = limitToBox(obj.to[i] + cube_pos.getComponent(i), obj.inflate)
|
||||
obj.to[i] = obj.to[i] + cube_pos.getComponent(i);
|
||||
} else {
|
||||
obj.from[i] = limitToBox(obj.from[i] + cube_pos.getComponent(i), -obj.inflate)
|
||||
obj.from[i] = obj.from[i] + cube_pos.getComponent(i);
|
||||
}
|
||||
}
|
||||
if (Format.cube_size_limiter) {
|
||||
Format.cube_size_limiter.clamp(obj)
|
||||
}
|
||||
if (Project.box_uv && obj.visibility) {
|
||||
Canvas.updateUV(obj)
|
||||
}
|
||||
@ -486,14 +489,10 @@ function scaleAll(save, size) {
|
||||
|
||||
if (obj.from) {
|
||||
obj.from[i] = (obj.before.from[i] - obj.inflate - ogn) * size;
|
||||
if (obj.from[i] + ogn > 32 || obj.from[i] + ogn < -16) overflow.push(obj);
|
||||
obj.from[i] = limitToBox(obj.from[i] + obj.inflate + ogn, -obj.inflate);
|
||||
}
|
||||
|
||||
if (obj.to) {
|
||||
obj.to[i] = (obj.before.to[i] + obj.inflate - ogn) * size;
|
||||
if (obj.to[i] + ogn > 32 || obj.to[i] + ogn < -16) overflow.push(obj);
|
||||
obj.to[i] = limitToBox(obj.to[i] - obj.inflate + ogn, obj.inflate);
|
||||
if (Format.integer_size) {
|
||||
obj.to[i] = obj.from[i] + Math.round(obj.to[i] - obj.from[i])
|
||||
}
|
||||
@ -523,6 +522,14 @@ function scaleAll(save, size) {
|
||||
}
|
||||
}
|
||||
})
|
||||
if (obj instanceof Cube && Format.cube_size_limiter) {
|
||||
if (Format.cube_size_limiter.test(obj)) {
|
||||
overflow.push(obj);
|
||||
}
|
||||
if (!settings.deactivate_size_limit.value) {
|
||||
Format.cube_size_limiter.clamp(obj);
|
||||
}
|
||||
}
|
||||
if (save === true) {
|
||||
delete obj.before
|
||||
}
|
||||
@ -538,7 +545,7 @@ function scaleAll(save, size) {
|
||||
delete g.old_origin
|
||||
}
|
||||
}, Group)
|
||||
if (overflow.length && Format.canvas_limit && !settings.deactivate_size_limit.value) {
|
||||
if (overflow.length && Format.cube_size_limiter && !settings.deactivate_size_limit.value) {
|
||||
scaleAll.overflow = overflow;
|
||||
$('#scaling_clipping_warning').text('Model clipping: Your model is too large for the canvas')
|
||||
$('#scale_overflow_btn').css('display', 'inline-block')
|
||||
@ -1236,7 +1243,7 @@ BARS.defineActions(function() {
|
||||
change: function(modify) {
|
||||
Cube.selected.forEach(function(obj, i) {
|
||||
var v = modify(obj.inflate)
|
||||
if (Format.canvas_limit && !settings.deactivate_size_limit.value) {
|
||||
if (Format.cube_size_limiter && !settings.deactivate_size_limit.value) {
|
||||
v = obj.from[0] - Math.clamp(obj.from[0]-v, -16, 32);
|
||||
v = obj.from[1] - Math.clamp(obj.from[1]-v, -16, 32);
|
||||
v = obj.from[2] - Math.clamp(obj.from[2]-v, -16, 32);
|
||||
|
Loading…
Reference in New Issue
Block a user