#Change coordinate system origin to the center of the grid?
380 messages · Page 1 of 1 (latest)
This is handled by the centered_grid format option: https://github.com/JannisX11/blockbench-types/blob/main/types/format.d.ts#L57
Neat, that wasn't on the wiki
Yeah the types are more up-to-date than the wiki
Is there a guide how to set up a typescript project with these types? JS and web environments have never been my strong suit
Yeah you just need to have a NPM project, and then use the command to install the types. Typescript is not even required for this to work if you are using VSCode
If you have forked the blockbench-plugins repository and you're working in that, you just need to run npm install to install the types
My branch of blockbench-types is more up-to-date if you find you're running into missing types
https://github.com/SnaveSutit/blockbench-types
Use BBPlugin
Oh, that's new
Plugin is a built-in libDOM class that is overwritten by BB, but typescript doesn't like it
Also, how do I reference a different types branch?
I have no idea how npm works
(Also, do you have a typescript example project, maybe?)
Well, you'd need to clone the repo locally, and then reference it in a d.ts file:
/// <reference path="path/to/types/repo">
I do actually
It's a type def file. It only contains TS and no JS. Useful for typing JS libraries
Gotcha
If you want my branch of bbtypes using that template:
- Remove the bbtypes dependency
npm uninstall blockbench-types. - Clone my bbtypes branch somewhere on your file system (NOT in your plugin's repo)
- Make a file at
types/blockbench.d.tsin your plugin repo with the content:
/// <reference path="<path_to_bbtypes_repo>/types/index.d.ts">
- In the
tsconfig.jsonreplace"blockbench-types"with a reference to the above file in thetypeslist:
"types": ["node", "./types/blockbench.d.ts"],
Well then
@sinful flume Mind helping me out with a couple more general questions while I feel my way through this?
sure
I made this project a long time ago, so most stuff is outdated
For instance, why is this not valid anymore
const namespace_dialog = new Dialog("export_namespace", {
title: "SAM Export",
id: "export_namespace",
form: { namespace: { label: "Namespace", type: "text" } },
onConfirm(form) { export_sam(form.namespace); }
})```
namespace is apperantly undefined
Dialogs have changed completely
Oh great
Yeah, the lack of docs is a bit of a problem
Right, so here is the idea
I need this plugin to take every element group and export it as a item model seperately
While also offsetting the groups pivot to the origin
How would I approach that?
I did not know that
Oh, was that not a change made recently?
I recall it being mentioned
Oh, maybe it was the addition of a new blank slate dialog?
So then how do I circumvent this?
I assume this is because the form data is just a object
That's a bb type issue
And doesn't explicitly define the form
Yeah, object doesn't allow anything except an empty object
Make an issue in the bb types and I'll fix it on my branch and Jannis will get to it eventually
So you're remaking the Animated Java statue exporter basically?
Kinda
Using the new tech in the snapshot
It's for the new snapshots display entities
Yeah me to
But I also have a server sided plugin that controls animations and AI
So I need to also export certain metadata to generate the resourcepack and be able to load and process it
Take a look at the Outliner in bb types
The idea was to just export the individual pieces, name them properly and also export a manifest that serves as the model and animation data
I did use to have something before
It just seems very broken
Like I said, I tried this before very long ago
function export_sam(namespace: string) {
const geoName = Project.geometry_name;
Blockbench.export({
name: geoName,
type: "SAM Model Definition",
extensions: ["sam"],
content: autoStringify(sam_codec.compile()),
savetype: "text"
}, (p) => {
var save = PathModule.resolve(PathModule.dirname(p), "parts");
fs.mkdirSync(save, {recursive: true});
Project.groups.forEach((group) => {
var path = PathModule.resolve(save, group.name + ".json");
Blockbench.writeFile(path, {
content: autoStringify(serialize_bone_to_item(group, namespace)),
savetype: "text"
}, null);
});
});
}```
Does Project.groups not work anymore?
Ah, sweet
So then, is there a way to get and reuse the existing item serializer codec
const ITEM_CODEC: Codec = Codecs["java_block"];``` This should give me the item codec, correct?
If you open Blockbench and press CTRL + SHIFT + I it will open up the dev tools. Then you can open the console and type Codecs, press ENTER and see for yourself what it contains
Yeah, that's how I got that
Just making sure
Better question, I noticed that a group doesn't keep its position
I need to offset the whole group to the origin, anchored around their pivot
So do I have to iterate through each element and subtrack the pivot?
Fair enough
Where is the autoStringify function actually kept?
Wait, autoStringify doesn't exist anymore?
ALRIGHT, SO
I think I got everything covered
@sinful flume Mind looking it over real quick?
You thinking of compileJSON?
Global function, takes into account formatting rules that blockbench lets you configure
It is pretty simple
Since unlike java models I don't have to generate commands or anything
It looks like it didn't add the export option
It also looks like it doesn't like the compile function
sam_codec.compile!
! after a value tells TypeScript that the value will never be undefined during runtime
Oh, looks like that property is invalidly typed
excellent
This has been my experience with the bbtypes
I spend more time fixing them than I do developing my plugin
Well, it compiles without error, so I guess it's fine
Even if it's marked
Still though, why does the export function not get added to the menu?
Ok got it
That weird event thing was making issues
Aaaand it doesn't do anything
Excellent
I've pushed a fix on my branch of the types
does that file exist in your project?
What's the rest of your tsconfig look like?
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "es2020",
"target": "ES2021",
"jsx": "react",
"allowJs": true,
"moduleResolution": "node",
"strict": true,
"types": ["node", "./types/blockbench.d.ts"],
"resolveJsonModule": true
// "declaration": true,
// "emitDeclarationOnly": true
}
}```
oh, sorry remove the .d.ts extension
That got rid of it
This is what mine looks like
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "es2022",
"target": "ES2022",
"moduleResolution": "node",
"strict": true,
"types": ["node", "svelte", "three", "./types/blockbench-types"],
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true
}
}
Nope
I'm curious why your reference path didn't get highlighted
OH
/// <reference path="D:/github-repos/blockbench-types/types/index.d.ts"/>
I think I forgot a / at the end
Ah, we love xml
Yeah, there we go
Excellent
Ok, do the same with Codec and find the compile method's def
huh
This is what my branch looks like ^
Huh, I just cloned it though
From my branch or Jannis'?
How did you initially clone it?
Well, I can't tell you what's going on
Maybe see if deleting the repo and re-cloning it works?
I've just removed it manually for now
¯_(ツ)_/¯
onload() {
console.log("Loaded!")
var export_action_sam = new Action("export_sam", {
name: "Export SAM",
icon: "archive",
description: "Export as model archive and definition json.",
category: "file",
condition: () => Format.id === "sam",
click: () => sam_codec.export
});
MenuBar.addAction(export_action_sam, "file.export");
}``` The one I add here
Huh
I was wondering why there is a overload for action
I get that with AJ but it doesn't seem to effect it
But we're also just directly injecting our actions into the menus
very ugly but it works
Well, either way
The logic looks to be right
Oh wait, I am missing the brackets again
It's a runnable, not a function field
Yeah, there it goes
Though the action is still not doing it
It opens the file select dialogue, but that's about it
For context, here is the latest state
function export_action() {
console.log("Exporting pieces.")
Blockbench.export({
type: "Server Animatable Model",
extensions: [ "sam.json", "json" ],
content: sam_codec.compile!(),
savetype: "text",
custom_writer: (a, b) => {}
}, (p) => {
console.log("Exporting pieces.");
export_parts("minecraft", path.dirname(p));
});
}```
So apperantly it calls the function
But the export function fails
And the consumer for after writing never gets called
It also calls the compile function
Could it be that the custom writer overwrites it and thus doesn't do anything?`
@sinful flume
I have stubbed it, since I assumed it was a override
But it's a required field and doesn't let me leave it empty
Wait no
That was fixed in my types
Yeah bb's default types force it
Codec.G is probably your codec. Do you have code minification enabled?
I don't think so, but where would it be configured?
What are you using to bundle your ts project
Just yarn build
Indeed
FYI It's using ESBuild as it's typescript/javascript bundler
yarn dev won't minify code and includes a source map for better dev tool debugging
yarn build is for prod
yarn dev builds once, then automatically builds on every file change
Yep, that's working as intended
You can stop it manually using CTRL + C when you're done deving
yeah seems fine
Yeah, idk
The issue seems to be in a foreach though
And I only have one of those
function export_parts(namespace: string, path: string) {
Group.all.forEach((group) => {
var pivotOffset: ArrayVector3 = [group.origin[0] * -1, group.origin[1] * -1, group.origin[2] * -1];
group.forEachChild((element) => {
var cube = element as Cube;
cube.moveVector(pivotOffset, 0, false);
}, Outliner.elements, false);
Blockbench.writeFile(path + `/${Project?.name}_${group.name}.json`, {
content: JSON.stringify(group.compile(false)),
savetype: "text"
});
});
}```
Two, actually
The file it tries to load is not even a directory
It's some binary file
app.asar
Right
Well, still
So what is this about
Also, it has to be something in here
group.forEachChild((element) => {
var cube = element as Cube;
cube.moveVector(pivotOffset, 0, false);
}, Outliner.elements, false);```
Is this not how you define the foreach child?
group can have groups as children
But does the second arg not act as a filter of the child type
function recurse(el: OutlinerNode) {
if (el instanceof Group)
recurse(el)
else
cube.moveVector...
}
recurse(group)
No, that casts it to the Cube type
Ah.
No, that did not solve it
Also, the casting doesn't seem to work, since it's still just a object
You need to filter the element type. Not case the element to a new type
Yes, I have
group.forEachChild((element) => {
if(element instanceof Cube) {
var cube = element as Cube;
cube.moveVector(pivotOffset, 0, false);
}
}, Outliner.elements, false);```
Why are you casting it still
Because it has a stroke about moveVector otherwise
You shouldn't be, TS should automatically understand that it's now a cube since you're now checking it's class in an if statement
Ah, hm
Still no
I think this may be a different issue
Sure would be handy if I could see the mappings
lmao
If you remove that code entirely does it still error
Yes, actually
Then it's probably not that code
oh
I don't think Outliner.elements is a valid type
Outliner.elements is definitely not a class that extends OutlinerNode
You'd want to pass Cube in this case
I pushed an update to the types that should make that clearer
Blockbench dose does this internally, simply figure out how it does that
I would assume I'd need to call compile
On the codec
Giving the group as an option
But the options arg does not actually have a layout
compile's options is unique to every codec
So it's an any
You'll have to check the bb source to find out what java_block's options are
I am not sure
I am looking at it right now
But the options don't seem to define the input elements or groups at all
So what does
Probably the global Project
Oh, that's not good
Welcome to Blockbench
What, so do I need to reimplement the entire java item codec now
yep
Great.
That's why I was surprised your code was so small
I guess I can just copy the existing codec
And replace all the Project calls with the options
The root of a project is a group as well, yes?
Just type-wise
Ah
Right, well I can work around that
OK, I am going to bed now
I have to do this tomorrow
Don't have the energy to fix this today anymore
Well, good night
@sinful flume I think I found another issue
I don't believe rotationAxis should not return, should it?
Void is an indication of no return value
Also, Textures don't include their texture properties like name, id etc
If you make issues on the git repo I can more effectively track and fix issues
I'll make some later
I am pretty close to finally getting this to work
Item exporting and everything is done
Nice
But I am running into some strange issues while exporting the elements to the items
Exporting this element:
Has the following properties, according to the outliner
Which seems accurate
(it's rotated)
However, when trying to access the to and from coordinates from the plugin, they are completely skewed
Name: handle | Pivot: 5.000000000000002,11.999999999999996,-1.7763568394002505e-15 | Offset: -5.000000000000002,-11.999999999999996,1.7763568394002505e-15 | From: -14.999999999999996,-35.5,-0.49999999999999867 | To: 10.00000000000002,-34.5,0.5000000000000011
Going from from[-6, 11.5, -0.5] to from[-15, -35.5, -0.5]
And from to[19, 12.5, 0.5] to to[10, -34.5, 0.5]
i.e. the entire element gets offset by [-9, -46, 0]
And I am at a loss where that is coming from
It's not the pivot point either, that would be [5, 12, 0]
So what is happening here?
The printout is also happening before any transformation to the element happens, for context
No clue
This is kinda breaking everything
@ripe vector Do you maybe have any idea what‘s going on here
Is it intentional that you are moving the position of the cubes? Best practice for an export function would be to make it read-only and not change anything about the model.. But at least you would need to reset it afterwards.
Yes it is, I am moving all bones to the origin of the grid based on their pivot
Do you only handle level one groups, no nesting?
No, I go through every group recursively
Very group is a bone that needs to be exported as its own item
Oh hang on
Is forEachChild recursive?
Yeah
Well damn
You could use group.chidren.forEach() if you don't want to handle soem cubes twice
Let me try
!close