Zylann / godot_voxel

Voxel module for Godot Engine
MIT License
2.52k stars 237 forks source link

How should I properly use the OBJ model exported from Blender? #674

Open qrf0220 opened 3 weeks ago

qrf0220 commented 3 weeks ago

Hello!

When I use an .obj model with UV mapping exported from Blender, if I instantiate an .obj model with UV mapping as a MeshInstance3D directly in the scene, the UV map renders correctly.

However, when I import this .obj model into VoxelTerrain -> VoxelNode -> Mesher (VoxelMesherBlocky) -> voxelBlockyLibrary -> VoxelBlockyModeMesh, the UV map does not render correctly (it appears normal in the preview), but during gameplay, the model appears white.

If I manually specify a material in VoxelTerrain -> VoxelNode -> Mesher (VoxelMesherBlocky) -> voxelBlockyLibrary -> VoxelBlockyModeMesh -> Material Overrides, then the manually specified material displays correctly during gameplay.

Is there a way to directly use the UV map included in the .obj model (by specifying it at VoxelTerrain -> VoxelNode -> Mesher (VoxelMesherBlocky) -> voxelBlockyLibrary -> VoxelBlockyModeMesh -> Mesh -> Surface 0 -> Material)?

MGilleronFJ commented 3 weeks ago

A UV map does not render anything by itself, materials do. But no, the system does not currently use materials that are already assigned to the mesh itself, it uses what's assigned in the model resource of the blocky library.

EDIT: actually it seems there is code for it: https://github.com/Zylann/godot_voxel/blob/28e2e67e118230602704e8771d9f1228a9261bd4/meshers/blocky/voxel_blocky_model_mesh.cpp#L426 But I'm not sure why they might not be used in your case. Maybe caused by this section: https://github.com/Zylann/godot_voxel/blob/28e2e67e118230602704e8771d9f1228a9261bd4/meshers/blocky/voxel_blocky_model.cpp#L265 Where there doesnt seem to be a check for null, therefore "empty material override" counts as an override too.

Though as said below, keep in mind any extra material you add causes an extra mesh to be created per chunk (which then causes extra work for Godot to cull it and adds an extra draw call, sometimes also a shader switch).

NuclearPhoenixx commented 3 weeks ago

The normal workflow would be to use a single material with a texture atlas to be used on as many voxels as possible. This reduces draw calls to the GPU because multiple voxel will be essentially using the same material/graphics.

You might be able to export a material in blender with the obj and then use that. However, for performance reasons it's much better to use the texture atlas approach with a single custom material for multiple voxels. In general, try to use as few individual materials as possible.

Zylann commented 2 weeks ago

Should be fixed in a3d91655e37bd247db043057585d872da4c91ccb Though another thing to keep in mind, materials are limited to 2 per model.