Cura/plugins/PaintTool/PrepareTextureJob.py
Erwan MATHIEU db514f0be7
Some checks failed
conan-package / conan-package (push) Has been cancelled
unit-test / Run unit tests (push) Has been cancelled
Properly prepare the model for painting
CURA-12660
The UV-unwrapping is now done in a background job, and the UI displays a waiting state. This fixes the issue where the user would start painting but the model was not ready yet, and the first stroke would be missing.
2025-08-07 11:03:51 +02:00

33 lines
1.1 KiB
Python

# Copyright (c) 2025 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from UM.Job import Job
from UM.Scene.SceneNode import SceneNode
from UM.View.GL.OpenGL import OpenGL
class PrepareTextureJob(Job):
"""
Background job to prepare a model for painting, i.e. do the UV-unwrapping and create the appropriate texture image,
which can last a few seconds
"""
def __init__(self, node: SceneNode):
super().__init__()
self._node: SceneNode = node
def run(self) -> None:
# If the model has already-provided UV coordinates, we can only assume that the associated texture
# should be a square
texture_width = texture_height = 4096
mesh = self._node.getMeshData()
if not mesh.hasUVCoordinates():
texture_width, texture_height = mesh.calculateUnwrappedUVCoordinates()
self._node.callDecoration("prepareTexture", texture_width, texture_height)
if hasattr(mesh, OpenGL.VertexBufferProperty):
# Force clear OpenGL buffer so that new UV coordinates will be sent
delattr(mesh, OpenGL.VertexBufferProperty)