Decimate modifier not working in operator settings #60722

Closed
opened 2019-01-21 21:04:22 +01:00 by Zachary · 6 comments

System Information
Windows 10 x64
GTX 950M

Blender Version
Broken:
Date: 2019-01-18
Hash: c59370bf64

Looks like the decimate modifier doesn't work when used in operator settings. Every other modifier seems to work fine.

Exact steps for others to reproduce the error
1: Select a mesh object
2: Run script, run operator, and enable Decimate.
3: Increase Subsurf Amount and watch it change.
4: Adjust Decimate Amount (Nothing happens other than number changing on modifier).
5: Adjust Iterations under modifier settings and watch it work like it should.

import bpy

			
def main(context, strip_surf_amount, strip_decimate_amount):
	
	ACT_OBJ = bpy.context.active_object
			
	#Subsurf Modifier
	SUB_MOD = ACT_OBJ.modifiers.new(name="Subsurf_Strips", type='SUBSURF')
	SUB_MOD.levels = strip_surf_amount
	SUB_MOD.subdivision_type = 'CATMULL_CLARK'
	bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subsurf_Strips")

	#Decimate Modifier
	DECIMATE_MOD = ACT_OBJ.modifiers.new(name="Decimate_Strips", type='DECIMATE')
	DECIMATE_MOD.decimate_type = 'UNSUBDIV'
	DECIMATE_MOD.iterations = strip_decimate_amount

	#smooth modifier
	SMOOTH_MOD_1 = ACT_OBJ.modifiers.new("Smooth_Strips_1", 'SMOOTH')
	SMOOTH_MOD_1.use_x = True
	SMOOTH_MOD_1.use_y = True
	SMOOTH_MOD_1.use_z = True
	SMOOTH_MOD_1.factor = 0.5
	SMOOTH_MOD_1.iterations = 2 #4


class SimpleOperator(bpy.types.Operator):
	"""Tooltip"""
	bl_idname = "object.simple_operator"
	bl_label = "Simple Object Operator"
	bl_options = {'REGISTER', 'UNDO'}
	

	strip_surf_amount: bpy.props.IntProperty(
			name="Subsurf Amount",
			description="Amount of subsurf",
			default=1,
			)

	strip_decimate: bpy.props.BoolProperty(
			name="Decimate",
			description="Decimate",
			default=False,
			)

	strip_decimate_amount: bpy.props.IntProperty(
			name="Decimate Amount",
			description="Amount to decimate",
			default=2, 		
			)


	def draw(self, context):
		layout = self.layout

		#Topology
		box = layout.box()  	  
		col = box.column(align=True)
		col.label(text="Topology")
		col.prop(self, "strip_surf_amount", text="Subsurf Amount")
		col.prop(self, "strip_decimate", text="Decimate")
		if self.strip_decimate: 	   
			col.prop(self, "strip_decimate_amount", text="Decimate Amount")


	def execute(self, context):
		main(context, self.strip_surf_amount, self.strip_decimate_amount)
		return {'FINISHED'}


def register():
	bpy.utils.register_class(SimpleOperator)


def unregister():
	bpy.utils.unregister_class(SimpleOperator)


if __name__ == "__main__":
	register()
**System Information** Windows 10 x64 GTX 950M **Blender Version** Broken: Date: 2019-01-18 Hash: c59370bf643f Looks like the decimate modifier doesn't work when used in operator settings. Every other modifier seems to work fine. **Exact steps for others to reproduce the error** 1: Select a mesh object 2: Run script, run operator, and enable Decimate. 3: Increase Subsurf Amount and watch it change. 4: Adjust Decimate Amount (Nothing happens other than number changing on modifier). 5: Adjust Iterations under modifier settings and watch it work like it should. ``` import bpy def main(context, strip_surf_amount, strip_decimate_amount): ACT_OBJ = bpy.context.active_object #Subsurf Modifier SUB_MOD = ACT_OBJ.modifiers.new(name="Subsurf_Strips", type='SUBSURF') SUB_MOD.levels = strip_surf_amount SUB_MOD.subdivision_type = 'CATMULL_CLARK' bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subsurf_Strips") #Decimate Modifier DECIMATE_MOD = ACT_OBJ.modifiers.new(name="Decimate_Strips", type='DECIMATE') DECIMATE_MOD.decimate_type = 'UNSUBDIV' DECIMATE_MOD.iterations = strip_decimate_amount #smooth modifier SMOOTH_MOD_1 = ACT_OBJ.modifiers.new("Smooth_Strips_1", 'SMOOTH') SMOOTH_MOD_1.use_x = True SMOOTH_MOD_1.use_y = True SMOOTH_MOD_1.use_z = True SMOOTH_MOD_1.factor = 0.5 SMOOTH_MOD_1.iterations = 2 #4 class SimpleOperator(bpy.types.Operator): """Tooltip""" bl_idname = "object.simple_operator" bl_label = "Simple Object Operator" bl_options = {'REGISTER', 'UNDO'} strip_surf_amount: bpy.props.IntProperty( name="Subsurf Amount", description="Amount of subsurf", default=1, ) strip_decimate: bpy.props.BoolProperty( name="Decimate", description="Decimate", default=False, ) strip_decimate_amount: bpy.props.IntProperty( name="Decimate Amount", description="Amount to decimate", default=2, ) def draw(self, context): layout = self.layout #Topology box = layout.box() col = box.column(align=True) col.label(text="Topology") col.prop(self, "strip_surf_amount", text="Subsurf Amount") col.prop(self, "strip_decimate", text="Decimate") if self.strip_decimate: col.prop(self, "strip_decimate_amount", text="Decimate Amount") def execute(self, context): main(context, self.strip_surf_amount, self.strip_decimate_amount) return {'FINISHED'} def register(): bpy.utils.register_class(SimpleOperator) def unregister(): bpy.utils.unregister_class(SimpleOperator) if __name__ == "__main__": register() ```
Author

Added subscriber: @AFWS

Added subscriber: @AFWS
Member

Added subscribers: @brecht, @lichtwerk

Added subscribers: @brecht, @lichtwerk
Brecht Van Lommel was assigned by Philipp Oeser 2019-01-22 10:31:01 +01:00
Member

Something up front:
I guess it might be good practice to not make new modifiers on redo but instead look for existing ones and change settings on those.
I would also make sure you cap subsurf levels to a reasonable max [just had the case where the UI hang and I had to reboot because I apparently went into insane amount of subdivisions...]

That being said there was 2ca4f4f0cb that made a change here that might be the reason...
Prior to this commit both original DecimateModifierData facecount and evaluated DecimateModifierData facecount were updated, after 2ca4f4f0cb only the original is.
With that happening, I am getting the modifier error (at least with the setup in your script, not sure how to reproduce otherwise):

Modifier requires more than 3 input faces

That somehow results in undo/redo not doing a clean job and undesired things happen:

  • a new subdiv modifier gets added after the existing decimate / smooth
  • this subdiv modifier cannot be applied cleanly (it is not the first in the list anymore)
  • additional decimate / smooth modifiers get added (see above comment about not adding new ones but looking for existing ones...)

anyways: regarding the change in 2ca4f4f0cb, I am drpping this here [not 100% sure this is neccesary]:
P893: #60722 snippet



diff --git a/source/blender/modifiers/intern/MOD_decimate.c b/source/blender/modifiers/intern/MOD_decimate.c
index fff94e0d836..8068ef4ea09 100644
--- a/source/blender/modifiers/intern/MOD_decimate.c
+++ b/source/blender/modifiers/intern/MOD_decimate.c
@@ -89,13 +89,14 @@ static DecimateModifierData *getOriginalModifierData(
 }
 
 static void updateFaceCount(
-        const ModifierEvalContext *ctx, const DecimateModifierData *dmd, int face_count)
+        const ModifierEvalContext *ctx, DecimateModifierData *dmd, int face_count)
 {
 	if (DEG_is_active(ctx->depsgraph)) {
 		/* update for display only */
 		DecimateModifierData *dmd_orig = getOriginalModifierData(dmd, ctx);
 		dmd_orig->face_count = face_count;
 	}
+	dmd->face_count = face_count;
 }
 
 static Mesh *applyModifier(

@brecht: confirming for now, mind checking?

Something up front: I guess it might be good practice to not make new modifiers on redo but instead look for existing ones and change settings on those. I would also make sure you cap subsurf levels to a reasonable max [just had the case where the UI hang and I had to reboot because I apparently went into insane amount of subdivisions...] That being said there was 2ca4f4f0cb that made a change here that *might* be the reason... Prior to this commit both original `DecimateModifierData` facecount **and** evaluated `DecimateModifierData` facecount were updated, after 2ca4f4f0cb only the original is. With that happening, I am getting the modifier error (at least with the setup in your script, not sure how to reproduce otherwise): > Modifier requires more than 3 input faces That somehow results in undo/redo not doing a clean job and undesired things happen: - a new subdiv modifier gets added **after** the existing `decimate` / `smooth` - this subdiv modifier cannot be applied cleanly (it is not the first in the list anymore) - additional `decimate` / `smooth` modifiers get added (see above comment about not adding new ones but looking for existing ones...) anyways: regarding the change in 2ca4f4f0cb, I am drpping this here [not 100% sure this is neccesary]: [P893: #60722 snippet](https://archive.blender.org/developer/P893.txt) ``` diff --git a/source/blender/modifiers/intern/MOD_decimate.c b/source/blender/modifiers/intern/MOD_decimate.c index fff94e0d836..8068ef4ea09 100644 --- a/source/blender/modifiers/intern/MOD_decimate.c +++ b/source/blender/modifiers/intern/MOD_decimate.c @@ -89,13 +89,14 @@ static DecimateModifierData *getOriginalModifierData( } static void updateFaceCount( - const ModifierEvalContext *ctx, const DecimateModifierData *dmd, int face_count) + const ModifierEvalContext *ctx, DecimateModifierData *dmd, int face_count) { if (DEG_is_active(ctx->depsgraph)) { /* update for display only */ DecimateModifierData *dmd_orig = getOriginalModifierData(dmd, ctx); dmd_orig->face_count = face_count; } + dmd->face_count = face_count; } static Mesh *applyModifier( ``` @brecht: confirming for now, mind checking?
Author

You can also remove everything ,but the decimate modifier and you still get the same results and error.

import bpy

			
def main(context, strip_decimate_amount):
	
	ACT_OBJ = bpy.context.active_object

	#Decimate Modifier
	DECIMATE_MOD = ACT_OBJ.modifiers.new(name="Decimate_Strips", type='DECIMATE')
	DECIMATE_MOD.decimate_type = 'UNSUBDIV'
	DECIMATE_MOD.iterations = strip_decimate_amount


class SimpleOperator(bpy.types.Operator):
	"""Tooltip"""
	bl_idname = "object.simple_operator"
	bl_label = "Simple Object Operator"
	bl_options = {'REGISTER', 'UNDO'}
	

	strip_decimate: bpy.props.BoolProperty(
			name="Decimate",
			description="Decimate",
			default=False,
			)

	strip_decimate_amount: bpy.props.IntProperty(
			name="Decimate Amount",
			description="Amount to decimate",
			default=2, 		
			)


	def draw(self, context):
		layout = self.layout

		#Topology
		box = layout.box()  	  
		col = box.column(align=True)
		col.label(text="Topology")
		col.prop(self, "strip_decimate", text="Decimate")
		if self.strip_decimate: 	   
			col.prop(self, "strip_decimate_amount", text="Decimate Amount")


	def execute(self, context):
		main(context, self.strip_decimate_amount)
		return {'FINISHED'}


def register():
	bpy.utils.register_class(SimpleOperator)


def unregister():
	bpy.utils.unregister_class(SimpleOperator)


if __name__ == "__main__":
	register()
You can also remove everything ,but the decimate modifier and you still get the same results and error. ``` import bpy def main(context, strip_decimate_amount): ACT_OBJ = bpy.context.active_object #Decimate Modifier DECIMATE_MOD = ACT_OBJ.modifiers.new(name="Decimate_Strips", type='DECIMATE') DECIMATE_MOD.decimate_type = 'UNSUBDIV' DECIMATE_MOD.iterations = strip_decimate_amount class SimpleOperator(bpy.types.Operator): """Tooltip""" bl_idname = "object.simple_operator" bl_label = "Simple Object Operator" bl_options = {'REGISTER', 'UNDO'} strip_decimate: bpy.props.BoolProperty( name="Decimate", description="Decimate", default=False, ) strip_decimate_amount: bpy.props.IntProperty( name="Decimate Amount", description="Amount to decimate", default=2, ) def draw(self, context): layout = self.layout #Topology box = layout.box() col = box.column(align=True) col.label(text="Topology") col.prop(self, "strip_decimate", text="Decimate") if self.strip_decimate: col.prop(self, "strip_decimate_amount", text="Decimate Amount") def execute(self, context): main(context, self.strip_decimate_amount) return {'FINISHED'} def register(): bpy.utils.register_class(SimpleOperator) def unregister(): bpy.utils.unregister_class(SimpleOperator) if __name__ == "__main__": register() ```

This issue was referenced by fa5ce915df

This issue was referenced by fa5ce915df299ea917bf014749cc905fa1e2028e

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#60722
No description provided.