Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | GodotRobot |
For initial generation of mesh using SurfaceTool (and adding smoothing group above add_vertex calls, and adding ‘generate_normals’ after adding the verts / indices works quite nicely.
However, if I make adjustments to the mesh using MeshDataTool, then use SurfaceTool to commit that (arraymesh) to the object being updated, the normals no longer seem to work even when calling ‘generate_normals’ again on the surfacetool.
Has anyone else seen this issue – could very well be an issue with my code. I’ll paste it here later on today if this doesn’t sound familiar to anyone as to why this may occur. Any thoughts?
So, I took a lot at SurfaceTool source, and it appears at the end of “SurfaceTool::generate_normals”, there’s a call to clear the smooth groups
if (was_indexed) {
index();
smooth_groups.clear();
}
Not sure why this is cleared here, but sure there’s some reason. If I add the call to " back before calling generate_normals, it doesn’t seem to help though, so not sure this is my issue…
My update code is basically this this:
func update_mesh(delta):
if _result_mesh == null:
_result_mesh = self.mesh
_mesh_data_tool.create_from_surface(_result_mesh, 0)
for i in range(_mesh_data_tool.get_vertex_count()):
_vertex = _mesh_data_tool.get_vertex(i)
#... some code to perform vertex adjustment and call _mesh_data_tool.set_vertex
_result_mesh.surface_remove(0)
_mesh_data_tool.commit_to_surface(_result_mesh)
_surface_tool.create_from(_result_mesh, 0)
#_surface_tool.add_smooth_group(true) # gave this a try - didn't work
_surface_tool.generate_normals(true)
_result_mesh = _surface_tool.commit()
self.mesh = _result_mesh
The initial programmatic mesh looks smooth, but as soon as the first update to it runs, the shading is no longer smooth. Anyone happen to have any thoughts or suggestions?
GodotRobot | 2020-05-02 22:18