Skip to content

Commit

Permalink
Fix #1: Terrain doodad layers do not immediately take effect when added
Browse files Browse the repository at this point in the history
The problem was that the doodad itself was not being tagged after
changes were made to its properties. This meant meant that the drivers
on the terrain info modifiers would be referencing out-of-date
information.
  • Loading branch information
cmbasnett committed Aug 3, 2024
1 parent dc0e915 commit 06c656d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
9 changes: 6 additions & 3 deletions bdk_addon/terrain/doodad/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def execute(self, context: Context):
ensure_scatter_layer_modifiers(context, terrain_doodad)

# Add a new modifier to the terrain info object.
terrain_info_object = terrain_doodad.terrain_info_object
ensure_terrain_info_modifiers(context, terrain_info_object.bdk.terrain_info)
object_copy.update_tag()
ensure_terrain_info_modifiers(context, terrain_doodad.terrain_info_object.bdk.terrain_info)

# Deselect the active object.
terrain_doodad_object.select_set(False)
Expand Down Expand Up @@ -644,7 +644,8 @@ def poll(cls, context: Context):
return poll_has_terrain_doodad_selected(cls, context)

def execute(self, context: Context):
terrain_doodad = get_terrain_doodad(context.active_object)
terrain_doodad_object = context.active_object
terrain_doodad = get_terrain_doodad(terrain_doodad_object)

terrain_info_object = terrain_doodad.terrain_info_object

Expand All @@ -667,6 +668,8 @@ def execute(self, context: Context):
copy_simple_property_group(scatter_layer, new_scatter_layer, ignore={'id', 'objects', 'terrain_doodad_object'})
break

terrain_doodad_object.update_tag()

# Ensure the modifiers
ensure_terrain_info_modifiers(context, terrain_info_object.bdk.terrain_info)

Expand Down
20 changes: 16 additions & 4 deletions bdk_addon/terrain/doodad/paint/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ def execute(self, context: Context):
# Update all the indices of the components.
ensure_terrain_doodad_layer_indices(terrain_doodad)

# Update the geometry node tree.
ensure_terrain_info_modifiers(context, terrain_doodad.terrain_info_object.bdk.terrain_info)

# Set the paint layer index to the new paint layer.
terrain_doodad.paint_layers_index = len(terrain_doodad.paint_layers) - 1

# Mark the terrain info object as needing to be updated in the dependency graph.
# This needs to happen *before* the geometry node tree is updated, since the drivers in the geometry node tree
# depend on the data in the terrain info object.
terrain_doodad_object.update_tag()

# Update the geometry node tree.
ensure_terrain_info_modifiers(context, terrain_doodad.terrain_info_object.bdk.terrain_info)

return {'FINISHED'}


Expand All @@ -54,7 +59,8 @@ def poll(cls, context: Context):
return poll_has_terrain_doodad_selected_paint_layer(cls, context)

def execute(self, context: Context):
terrain_doodad = get_terrain_doodad(context.active_object)
terrain_doodad_object = context.active_object
terrain_doodad = get_terrain_doodad(terrain_doodad_object)
paint_layers = terrain_doodad.paint_layers
paint_layers_index = terrain_doodad.paint_layers_index

Expand All @@ -65,6 +71,8 @@ def execute(self, context: Context):
paint_layers.move(paint_layers_index, paint_layers_index + 1)
terrain_doodad.paint_layers_index += 1

terrain_doodad_object.update_tag()

ensure_terrain_info_modifiers(context, terrain_doodad.terrain_info_object.bdk.terrain_info)

return {'FINISHED'}
Expand All @@ -90,6 +98,8 @@ def execute(self, context: Context):
# Update all the indices of the components.
ensure_terrain_doodad_layer_indices(terrain_doodad)

terrain_doodad_object.update_tag()

# Update the geometry node tree.
ensure_terrain_info_modifiers(context, terrain_doodad.terrain_info_object.bdk.terrain_info)

Expand Down Expand Up @@ -126,6 +136,8 @@ def execute(self, context: Context):
# Update all the indices of the components.
ensure_terrain_doodad_layer_indices(terrain_doodad)

terrain_doodad_object.update_tag()

# Update the geometry node tree.
ensure_terrain_info_modifiers(context, terrain_doodad.terrain_info_object.bdk.terrain_info)

Expand Down
6 changes: 2 additions & 4 deletions bdk_addon/terrain/doodad/sculpt/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ def execute(self, context: Context):
# Set the sculpting component index to the new sculpting component.
terrain_doodad.sculpt_layers_index = len(terrain_doodad.sculpt_layers) - 1

terrain_doodad_object.update_tag()

# Update the geometry node tree.
ensure_terrain_info_modifiers(context, terrain_doodad.terrain_info_object.bdk.terrain_info)

# Mark the terrain info object as needing to be updated in the dependency graph.
terrain_doodad_object.update_tag()
terrain_doodad.terrain_info_object.update_tag()

return {'FINISHED'}


Expand Down

0 comments on commit 06c656d

Please sign in to comment.