-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix Export offset, Make defining textures easier #342
base: master
Are you sure you want to change the base?
Conversation
This has a few features, Namely you can name your group or cube to apply an texture (will edit this message with screenshots) and of course fix the `-8` offset that Blockbench has, previously the plugin *incorrectly* assumed `x0,y0,z0` was the origin (center) of the workspace, while it is actually `-8x, 0y, -8z`. this adjusts the values when exporting to contain an +8 to properly center it The reason for the lines being all altered is because my editor uses tab indentations and using "format document" made them all consistent as there was a mix of 4space and tab indents everywhere, here are the diff files between my patches (after the indentation was changed) For the Texturing ```diff diff --git a/sam3dj.js b/sam3dj.js index 0e09b71..0092094 100644 --- a/sam3dj.js +++ b/sam3dj.js @@ -34,7 +34,6 @@ for (let dir in cube.faces) { //in ['north', 'east', 'south', 'west', 'up', 'down'] let tmp = cube.faces[dir].getTexture(); - if (!tmp) { if (typeof cube.parent === 'object' && cube.parent.name.includes(":block/")) { texture = cube.parent.name; @@ -50,14 +49,48 @@ missing = true; } } else { - // Generate actual ID - let id = tmp.namespace + ':' + tmp.folder + '/' + (tmp.name.replace(/\.[^/.]+$/, "")) + let id = "" + // if cube is titled <group>:<path>, use that as texture + if (cube.name.includes(":")) { + id = cube.name.replace(/\.[^/.]+$/, "") + } else { + // if cube is in a group, use root group as namepsace + // use the rest of the path as texture name + if (typeof cube.parent === 'object') { + // get all parents + let parents = [] + let parent = cube.parent + while (typeof parent.parent === 'object') { + parents.push(parent.name) + parent = parent.parent + } + parents.push(parent.name) + parents.reverse() + // use the first parent as group + let group = parents[0] + parents.shift() + // if the group is not a folder, use the cube name as texture name + if (!group.includes(":")) { + parents.push(cube.name.replace(/\.[^/.]+$/, "")) + } - if (texture !== id) - faces++; - texture = id; - } - } + // set id to group:path/to/cube + id = group + ":" + parents.join("/") //+ "/" + cube.name.replace(/\.[^/.]+$/, "") + + + } else { + // if cube is not in a group, use the cube name as texture name + id = "minecraft:" + tmp.name.replace(/\.[^/.]+$/, "") + console.log(id+" has no parent") + } + } + + console.log("Exporting " + cube.name + " as " + id) + if (texture !== id) + faces++; + texture = id; + } + } return { texture: texture, ``` For the Offset ```diff diff --git a/sam3dj.js b/sam3dj.js index 0092094..88305d6 100644 --- a/sam3dj.js +++ b/sam3dj.js @@ -51,12 +51,12 @@ } else { let id = "" // if cube is titled <group>:<path>, use that as texture - if (cube.name.includes(":")) { - id = cube.name.replace(/\.[^/.]+$/, "") - } else { + if (cube.name.includes(":")) { + id = cube.name.replace(/\.[^/.]+$/, "") + } else { // if cube is in a group, use root group as namepsace // use the rest of the path as texture name - if (typeof cube.parent === 'object') { + if (typeof cube.parent === 'object') { // get all parents let parents = [] let parent = cube.parent @@ -80,17 +80,17 @@ } else { // if cube is not in a group, use the cube name as texture name - id = "minecraft:" + tmp.name.replace(/\.[^/.]+$/, "") - console.log(id+" has no parent") - } - } - - console.log("Exporting " + cube.name + " as " + id) - if (texture !== id) - faces++; - texture = id; - } - } + id = "minecraft:" + tmp.name.replace(/\.[^/.]+$/, "") + console.log(id + " has no parent") + } + } + + console.log("Exporting " + cube.name + " as " + id) + if (texture !== id) + faces++; + texture = id; + } + } return { texture: texture, @@ -108,13 +108,12 @@ let result = getSingleTexture(cube); let shape = { bounds: [ - cube.from[0], + cube.from[0] + 8, cube.from[1], - cube.from[2], - - cube.to[0], + cube.from[2] + 8, + cube.to[0] + 8, cube.to[1], - cube.to[2], + cube.to[2] + 8, ], texture: result.texture, }; @@ -301,12 +300,23 @@ texture = (getSingleTexture(cube).multipleTexture); if (!border) { - function checkNum(num) { + // NOTE: If you can find a better way to do this, please do so. + // These changes had to be done due to Blockbench's 0,0 origin + // being in the center of the block and not in the bottom left corner. + // causing an malformed export. (off set by 8 in the x and z axis) + function checkNum(num, height) { if (!border) - border = (num < 0 || num > 16); + if (height) + border = (num < -16 || num > 16); + else + border = (num < -8 || num > 8); } - cube.from.forEach(checkNum) - cube.to.forEach(checkNum) + checkNum(cube.from[0]); + checkNum(cube.from[1], true); + checkNum(cube.from[2]); + checkNum(cube.to[0]); + checkNum(cube.to[1], true); + checkNum(cube.to[2]); } // We are done here ```
@1Turtle What do you think? |
@1Turtle bump |
Hmm, I'm not sure. About the fix: It's good to know that the center isn't at 0,0,0, though it's weird that the documentation doesn't mention that. |
I see. The problem you are encountering is that your texture does not have a namespace (e.g. This for sure should get fixed. So for now, ignore the part where I said you should make it optional. You also mentioned that you didn't test this with the on/off states, because you don't know how they work. Other than that, I have nothing against this getting merged, thank you. ^^ |
with the official plugin, if texture is {
"bounds": [-8, 0, -8, 8, 16, 8],
"texture": ":/minecraft:stone",
"tint": "FFFFFF"
}
EDIT: I will update my code to fix texture name output however, maybe even write a program to import textures from an "resourcepack" into a workspace EDIT: Also my modification logs to console what cube is being exported as what texture, current fixing up the logging as it spams even for cubes that are hidden and never exported |
makes texture name take prioritty over cube name/parenting
https://mega.nz/file/etYzjZhR#lb2LVJNiI4ZsWvXyyg5w1HmWQoiNN_PuM9KGZX8OSig bbmodel for this file, actual texture file not really important, just pick a placeholder texture if you dont want to use what I provide here defining texture names supports |
saw small typo give second (in exporting |
fixed typo
|
The plugin version number still isn't increased, as mentioned above. |
I can easily fix the version number And I honestly dont know how to explain how this works in an short and concise way to put in the description, and I personally never got it to export with textures originally anyways The easiest fix to exporting without a texture is to just default to stone. |
Alright I can do the description, it's fine ^^ I was testing things again now, and I really can't reproduce the bug with the textures. Also, it doesn't have an offset? Exporting it to .3dj and then 3d printing it works just fine for me. So taking the changes for the -8 offset is not really an option right now I think. Maybe some kind help description or even video maybe is something this plugin needs? Or a more intuitive way, that would be even better. This plugin also still needs tint support... >.> |
The offset does make sense sometimes. And regarding the description, Blockbench does have a help menu, it is always a possibility to just add an entry, and display a more complex help page, or link to an external one. |
Oh alright, thank you for clarifying! Yeah I guess making a proper format for it would be reasonable. I don't know if I can manage this however, so someone would need to make a PR. |
if (result.border) | ||
warning.form.border = { | ||
type: 'info', | ||
text: '... are out of bounce (16x16x16 Grid / 1x1x1 Block)', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo, "bounce"
function genShape(cube, raw = false) { | ||
let result = getSingleTexture(cube); | ||
let shape = { | ||
bounds: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like I said in my comment, the offset depends on the model format, this should be accounted for, as otherwise users may run into issues.
id = "minecraft:" + tmp.name | ||
} | ||
if (id === "") { | ||
if (cube.name.includes(":")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole section seems questionable to me, if this condition is met, the other renaming logic further down does never run.
I assume file extension removal should always be performed, and be further down, with the other renaming logic.
Though I am not farmiliar with the 3DJ format, therefore please correct me if I am incorrect in my assumptions.
I'll gladly say it a 3rd time, whether Blockbench has 0, 0, at the center, or in the corner. depends solely on the model format you're using. When you're modelling in block/item mode, this will create the exact issue you're trying to solve. And regarding the texture naming:
|
This has a few features,
Namely you can name your group or cube to apply an texture (will edit this message with screenshots)
and of course fix the
-8
offset that Blockbench has, previously the plugin incorrectly assumedx0,y0,z0
was the origin (center) of the workspace, while it is actually-8x, 0y, -8z
. this adjusts the values when exporting to contain an +8 to properly center itThe reason for the lines being all altered is because my editor uses tab indentations and using "format document" made them all consistent as there was a mix of 4space and tab indents everywhere,
here are the diff files between my patches (after the indentation was changed) For the Texturing
For the Offset