Object.to_mesh() does not apply modifier if the object is disabled from the viewport #71556

Closed
opened 2019-11-13 21:07:10 +01:00 by Ryan Guy · 4 comments

System Information
Operating system: Windows 10 Home
Graphics card: GTX 1070 8GB

Blender Version
Broken: 2.81 beta, 1252577580, 2019-11-12
Worked: (optional)

Short description of error

I want to use the Python API to export an object mesh as a triangle mesh. I am doing this by adding a triangulate modifier to the object. When using to_mesh(), the modifier is not applied when the object is disabled in the viewport (Globally disable in viewports).

Here is a script that reproduces the issue

import bpy

cube_object = bpy.data.objects.get("Cube")
triangulation_mod = cube_object.modifiers.new("triangulate", "TRIANGULATE")

depsgraph = bpy.context.evaluated_depsgraph_get()
obj_eval = cube_object.evaluated_get(depsgraph)
to_mesh_result = obj_eval.to_mesh()

print("Number of faces:", len(to_mesh_result.polygons))

cube_object.modifiers.remove(triangulation_mod)

Here is the output when the Cube object is disabled in the viewport:

Number of faces: 6

Here is the output when the Cube object is enabled in the viewport:

Number of faces: 12

This only seems to happen when using the Disable in Viewports icon. The Hide in Viewport icon does not reproduce the issue.

Exact steps for others to reproduce the error

I have attached a .blend file that contains the above script: to_mesh_bug.blend

  1. Open .blend file
  2. Press 'Run Script'
  3. View console output

The number of faces is 6 when the Cube is disabled in viewports and 12 when enabled.

**System Information** Operating system: Windows 10 Home Graphics card: GTX 1070 8GB **Blender Version** Broken: 2.81 beta, 125257758007, 2019-11-12 Worked: (optional) **Short description of error** I want to use the Python API to export an object mesh as a triangle mesh. I am doing this by adding a triangulate modifier to the object. When using to_mesh(), the modifier is not applied when the object is disabled in the viewport (Globally disable in viewports). Here is a script that reproduces the issue ``` import bpy cube_object = bpy.data.objects.get("Cube") triangulation_mod = cube_object.modifiers.new("triangulate", "TRIANGULATE") depsgraph = bpy.context.evaluated_depsgraph_get() obj_eval = cube_object.evaluated_get(depsgraph) to_mesh_result = obj_eval.to_mesh() print("Number of faces:", len(to_mesh_result.polygons)) cube_object.modifiers.remove(triangulation_mod) ``` Here is the output when the Cube object is disabled in the viewport: ``` Number of faces: 6 ``` Here is the output when the Cube object is enabled in the viewport: ``` Number of faces: 12 ``` This only seems to happen when using the Disable in Viewports icon. The Hide in Viewport icon does not reproduce the issue. **Exact steps for others to reproduce the error** I have attached a .blend file that contains the above script: [to_mesh_bug.blend](https://archive.blender.org/developer/F8064142/to_mesh_bug.blend) 1. Open .blend file 2. Press 'Run Script' 3. View console output The number of faces is 6 when the Cube is disabled in viewports and 12 when enabled.
Author

Added subscriber: @rlguy

Added subscriber: @rlguy
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Archived'

Changed status from 'Needs Triage' to: 'Archived'
Philipp Oeser self-assigned this 2020-01-08 19:40:20 +01:00
Member

Hi and thx for the report! (sorry it took a while to answer...)

If I am not mistaken, objects that are globally disabled from viewports also are excluded from the depsgraph, yes.
This way their modifiers are not executed, gaining back performance; you end up with the "original" object.

This is true for all exporters (OBJ, FBX, ...) and is more or less by design.

Afraid we have to close this report (feel free though to comment again if issues persist...)

Hi and thx for the report! (sorry it took a while to answer...) If I am not mistaken, objects that are globally disabled from viewports also are excluded from the depsgraph, yes. This way their modifiers are not executed, gaining back performance; you end up with the "original" object. This is true for all exporters (OBJ, FBX, ...) and is more or less by design. Afraid we have to close this report (feel free though to comment again if issues persist...)
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
2 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#71556
No description provided.