mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 07:23:00 +00:00
img2brush: allow customising the channel to pull from
This commit is contained in:
parent
dea51cb9a3
commit
410841562a
2 changed files with 32 additions and 3 deletions
|
@ -13,6 +13,23 @@ window.addEventListener("load", () => {
|
|||
})
|
||||
});
|
||||
|
||||
function get_source_channel_offset() {
|
||||
const select = document.querySelector("#img2brush-channel");
|
||||
console.info(`get_source_channel_offset: channel is ${select.value}`)
|
||||
switch(select.value) {
|
||||
case "alpha":
|
||||
return 3;
|
||||
case "red":
|
||||
return 0;
|
||||
case "green":
|
||||
return 1;
|
||||
case "blue":
|
||||
return 2;
|
||||
default:
|
||||
throw new Error(`Error : Unknown channel name ${select.value}.`);
|
||||
}
|
||||
}
|
||||
|
||||
function select_output() {
|
||||
let output = document.querySelector("#brushimg-tsv");
|
||||
|
||||
|
@ -26,7 +43,6 @@ function select_output() {
|
|||
selection.addRange(range);
|
||||
}
|
||||
|
||||
|
||||
function handle_drag_enter(event) {
|
||||
event.target.classList.add("dropzone-active");
|
||||
}
|
||||
|
@ -80,12 +96,15 @@ function handle_new_image(image) {
|
|||
}
|
||||
|
||||
function pixels2tsv(pixels) {
|
||||
const offset = get_source_channel_offset();
|
||||
console.info(`pixels2tsv: offset is ${offset}`);
|
||||
let result = "";
|
||||
for(let y = 0; y < pixels.height; y++) {
|
||||
let row = [];
|
||||
for(let x = 0; x < pixels.width; x++) {
|
||||
// No need to rescale here - this is done automagically by WorldEditAdditions.
|
||||
row.push(pixels.data[((y*pixels.width + x) * 4) + 3] / 255);
|
||||
// r/b/g/alpha
|
||||
row.push(pixels.data[((y*pixels.width + x) * 4) + offset] / 255);
|
||||
}
|
||||
result += row.join(`\t`) + `\n`;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,17 @@ title: Image to brush converter
|
|||
<section class="panel-generic">
|
||||
<h1>Image to sculpting brush converter</h1>
|
||||
|
||||
<p>Convert any image to a sculpting brush here! The <strong>alpha (opacity) channel</strong> is used to determine the weight of the brush - <strong>all colour is ignored</strong>.</p>
|
||||
<p>Convert any image to a sculpting brush here!</p>
|
||||
<p>
|
||||
<strong>Use this channel to convert:</strong>
|
||||
<select name="img2brush-channel" id="img2brush-channel">
|
||||
<option value="alpha" selected>Alpha (opacity)</option>
|
||||
<option value="red">Red</option>
|
||||
<option value="green">Green</option>
|
||||
<option value="blue">Blue</option>
|
||||
</select>
|
||||
</p>
|
||||
<p>Only the selected channel is used to determine the weight of the brush - <strong>all other channels are ignored</strong>! Change the channel option <strong>before</strong> you drag + drop the image onto this page.</p>
|
||||
</section>
|
||||
|
||||
<section id="dropzone" class="bigbox panel-generic">
|
||||
|
|
Loading…
Reference in a new issue