Skip to content
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

Is the block_sprite_generator.tscn broken for when we add new Blocks? #106

Open
NumDev2310 opened this issue Jul 5, 2024 · 5 comments
Open

Comments

@NumDev2310
Copy link

Absolutely wonderful work Zylann.

I'm currently trying to add new types of blocks to the blocky_game demo on Godot. I've been successful at adding them in 3D by editing voxel_library.tres and adding VoxelBlockyModelCube as follows (for instance, this is a grass that is slightly paler green):

image

By editing blocks.gd, I'm able to add them to the game (see "greengrass" here for instance):

image

Leading them to be addable in-game:
image

Now I'm faced with the problem that the sprites aren't generated for the gui for these new blocks (see last picture, empty sprite for that block). It seems that block_sprite_generator.gd is set to start at -1 and the if test in _process never passes because it is always -1. If I tweak those lines by removing the if test, I'm faced with the problem that block.directory does not exist and even fixing it to block.base_info.directory doesn't lead to sprite generation. I get the problem that _mesh_instance.mesh = gui_mesh tells me I'm trying to set a null value.

In brief, it seems like I'm missing something obvious - perhaps there is a manual way to trigger the execution of block_sprite_generator.gd outside the game in a way that it functions? Can any of you help me with this? Thanks a lot and again, Zylann, you have created something very powerful and I thank you for this!

@Zylann
Copy link
Owner

Zylann commented Jul 5, 2024

I havent used this script in a very long time so maybe it no longer works? It was Godot 3 at the time.

_current_block_id starts at -1 because the script uses a viewport to render blocks, which involves waiting a frame, so the first frame indeed doesn't enter the first if, but it will enter the second one after _current_block_id gets incremented, which setups the viewport for rendering the first block, which will be ready next frame. Then next frame it grabs the rendered image of the block that was setup on the previous frame, increments _current_block_id again and sets up the next block, and so on.
So you should not need to change that variable, it's intented.

As for why directory is empty, structure has changed a bit since. It's now in .base_info.
I'm going over the script to fix these things, but I'm also realizing the viewport itself doesn't render properly anymore... Godot has changed and it's broken now as well :(
Lighting has no environment by default now, so I'm adding one. It still looks different, but at least not too bad.
Also, on my end meshes have broken normals since I imported them a very long time ago in Godot 3 and Godot 4 didnt upgrade them properly, so I had to reimport them all manually.
I pushed that in fcc3f50

@NumDev2310
Copy link
Author

Thank you very much for looking into it!

Now the script functions, but somehow the sprite being generated wears the texture from the .obj, not the one in-game. For instance:

image

Here we can see that my addition to voxel_library.tres works in-game, with the paler grass, but the sprite generated is the one from the original .object that I had copied from /blocks/grass/grass.obj.

I guess for the material to be integrated to the sprite generator too I'll have to go in Blender, will research this.

@Zylann
Copy link
Owner

Zylann commented Jul 5, 2024

It should be using the material you setup in the library:

var mat := model.get_material_override(0)

Also the demo expects blocks to use mesh models, I dont know if it will work if you use cube models, might need some changes for that.

@NumDev2310
Copy link
Author

Working beautifully now!

image

If anyone is faced with the same problem I was faced with, it was because I was creating a voxel_library.tres that was a mix of VoxelBlockyModelMesh (from the Github) and my own creations were VoxelBlockyModelCubes (which appear not to be processed in the same way by block_sprite_generator.gd.

So I instead switched my new blocks into Mesh models exported with texture from Blender, using UV mapping to terrain.png.

Also don't forget to rename ...sprite_2.png to _sprite.png if you want the new images to show up in the GUI!

Thank you so much Zylann, I'm having great fun with this.

@Zylann
Copy link
Owner

Zylann commented Jul 5, 2024

Also don't forget to rename ...sprite_2.png to _sprite.png

Ugh, that was my testing code I forgot to remove...
Changed in 9c0f1d8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants