Open NumDev2310 opened 2 weeks ago
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 fcc3f504b0d8a4c18c8ed82520798737ac9d0401
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:
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.
It should be using the material you setup in the library: https://github.com/Zylann/voxelgame/blob/fcc3f504b0d8a4c18c8ed82520798737ac9d0401/project/blocky_game/gui/block_sprite_generator.gd#L51
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.
Working beautifully now!
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.
Also don't forget to rename ...sprite_2.png to _sprite.png
Ugh, that was my testing code I forgot to remove... Changed in 9c0f1d805c4061dd60560b4cf57565fd0ba5d066
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):
By editing blocks.gd, I'm able to add them to the game (see "greengrass" here for instance):
Leading them to be addable in-game:![image](https://github.com/Zylann/voxelgame/assets/139594843/e7cb43d7-e27f-4b6a-9d4f-6286744f0108)
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!