mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-02-11 16:12:06 +08:00
Add template generator padding option
This commit is contained in:
parent
d4adacca7c
commit
1976889a43
@ -1553,8 +1553,8 @@ function initCanvas() {
|
||||
resizeWindow()
|
||||
}
|
||||
function animate() {
|
||||
TickUpdates.Run()
|
||||
requestAnimationFrame( animate );
|
||||
TickUpdates.Run()
|
||||
Preview.all.forEach(function(prev) {
|
||||
if (prev.canvas.isConnected) {
|
||||
prev.render()
|
||||
|
@ -35,6 +35,7 @@ const TextureGenerator = {
|
||||
power: {label: 'dialog.create_texture.power', type: 'checkbox', value: true},
|
||||
double_use: {label: 'dialog.create_texture.double_use', type: 'checkbox', value: true, condition: Project.box_uv},
|
||||
box_uv: {label: 'dialog.project.box_uv', type: 'checkbox', value: false, condition: !Project.box_uv},
|
||||
padding: {label: 'dialog.create_texture.padding', type: 'checkbox', value: false},
|
||||
color: {label: 'data.color', type: 'color', colorpicker: TextureGenerator.background_color},
|
||||
resolution: {label: 'dialog.create_texture.resolution', type: 'select', value: 16, options: {
|
||||
16: '16',
|
||||
@ -214,9 +215,14 @@ const TextureGenerator = {
|
||||
return fill_map[x] && fill_map[x][y]
|
||||
}
|
||||
function forTemplatePixel(tpl, sx, sy, cb) {
|
||||
for (var x = 0; x < tpl.width; x++) {
|
||||
for (var y = 0; y < tpl.height; y++) {
|
||||
if (y >= tpl.z || (x >= tpl.z && x < (tpl.z + 2*tpl.x))) {
|
||||
let w = tpl.width;
|
||||
let h = tpl.height;
|
||||
if (options.padding) {
|
||||
w++; h++;
|
||||
}
|
||||
for (var x = 0; x < w; x++) {
|
||||
for (var y = 0; y < h; y++) {
|
||||
if (y >= tpl.z || (x >= tpl.z && x < (tpl.z + 2*tpl.x + (options.padding ? 1 : 0)))) {
|
||||
if (cb(sx+x, sy+y)) return;
|
||||
}
|
||||
}
|
||||
@ -278,23 +284,28 @@ const TextureGenerator = {
|
||||
var max_height = 0
|
||||
//Find the maximum height of the line
|
||||
temps.forEach(function(t) {
|
||||
max_height = Math.max(max_height, t.height)
|
||||
max_height = Math.max(max_height, t.height + (options.padding ? 1 : 0))
|
||||
})
|
||||
//Place
|
||||
temps.forEach(function(t) {
|
||||
if (y_pos > 0 && (y_pos + t.height) <= max_height) {
|
||||
let w = t.width;
|
||||
let h = t.height;
|
||||
if (options.padding) {
|
||||
w++; h++;
|
||||
}
|
||||
if (y_pos > 0 && (y_pos + h) <= max_height) {
|
||||
//same column
|
||||
t.posx = x_pos
|
||||
t.posy = y_pos + extend_y
|
||||
filled_x_pos = Math.max(filled_x_pos, x_pos+t.width)
|
||||
y_pos += t.height
|
||||
filled_x_pos = Math.max(filled_x_pos, x_pos + w)
|
||||
y_pos += h
|
||||
} else {
|
||||
//new column
|
||||
x_pos = filled_x_pos
|
||||
y_pos = t.height
|
||||
y_pos = h
|
||||
t.posx = x_pos
|
||||
t.posy = extend_y
|
||||
filled_x_pos = Math.max(filled_x_pos, x_pos+t.width)
|
||||
filled_x_pos = Math.max(filled_x_pos, x_pos + w)
|
||||
}
|
||||
//size of widest bone
|
||||
extend_x = Math.max(extend_x, filled_x_pos)
|
||||
@ -564,8 +575,13 @@ const TextureGenerator = {
|
||||
return fill_map[x] && fill_map[x][y]
|
||||
}
|
||||
function forTemplatePixel(tpl, sx, sy, cb) {
|
||||
for (var x = 0; x < tpl.width; x++) {
|
||||
for (var y = 0; y < tpl.height; y++) {
|
||||
let w = tpl.width;
|
||||
let h = tpl.height;
|
||||
if (options.padding) {
|
||||
w++; h++;
|
||||
}
|
||||
for (var x = 0; x < w; x++) {
|
||||
for (var y = 0; y < h; y++) {
|
||||
if (cb(sx+x, sy+y)) return;
|
||||
}
|
||||
}
|
||||
|
@ -311,6 +311,7 @@
|
||||
"dialog.create_texture.compress": "Compress Template",
|
||||
"dialog.create_texture.power": "Power-of-2 Size",
|
||||
"dialog.create_texture.double_use": "Keep Multi Texture Occupancy",
|
||||
"dialog.create_texture.padding": "Padding",
|
||||
"dialog.create_texture.resolution": "Resolution",
|
||||
|
||||
"dialog.create_gif.title": "Record GIF",
|
||||
|
Loading…
Reference in New Issue
Block a user