mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-12-25 08:58:35 -07:00
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.
33 lines
1.1 KiB
Python
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)
|
|
|