mirror of
https://github.com/Ultimaker/Cura.git
synced 2026-02-15 08:59:32 -07:00
Calculate and apply UV coordinates
Some checks failed
conan-package-resources / conan-package (push) Has been cancelled
conan-package / conan-package (push) Has been cancelled
printer-linter-format / Printer linter auto format (push) Has been cancelled
unit-test / Run unit tests (push) Has been cancelled
conan-package-resources / signal-curator (push) Has been cancelled
Some checks failed
conan-package-resources / conan-package (push) Has been cancelled
conan-package / conan-package (push) Has been cancelled
printer-linter-format / Printer linter auto format (push) Has been cancelled
unit-test / Run unit tests (push) Has been cancelled
conan-package-resources / signal-curator (push) Has been cancelled
CURA-12528
This commit is contained in:
parent
4cb7a0dc9f
commit
55ee4ec6e1
4 changed files with 28 additions and 18 deletions
|
|
@ -12,10 +12,6 @@ from UM.View.GL.OpenGL import OpenGL
|
|||
from UM.View.GL.Texture import Texture
|
||||
|
||||
|
||||
# FIXME: When the texture UV-unwrapping is done, these two values will need to be set to a proper value (suggest 4096 for both).
|
||||
TEXTURE_WIDTH = 512
|
||||
TEXTURE_HEIGHT = 512
|
||||
|
||||
class SliceableObjectDecorator(SceneNodeDecorator):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
|
@ -25,15 +21,10 @@ class SliceableObjectDecorator(SceneNodeDecorator):
|
|||
def isSliceable(self) -> bool:
|
||||
return True
|
||||
|
||||
def getPaintTexture(self, create_if_required: bool = True) -> Optional[UM.View.GL.Texture.Texture]:
|
||||
if self._paint_texture is None and create_if_required:
|
||||
self._paint_texture = OpenGL.getInstance().createTexture(TEXTURE_WIDTH, TEXTURE_HEIGHT)
|
||||
image = QImage(TEXTURE_WIDTH, TEXTURE_HEIGHT, QImage.Format.Format_RGB32)
|
||||
image.fill(0)
|
||||
self._paint_texture.setImage(image)
|
||||
def getPaintTexture(self) -> Optional[Texture]:
|
||||
return self._paint_texture
|
||||
|
||||
def setPaintTexture(self, texture: UM.View.GL.Texture) -> None:
|
||||
def setPaintTexture(self, texture: Texture) -> None:
|
||||
self._paint_texture = texture
|
||||
|
||||
def getTextureDataMapping(self) -> Dict[str, tuple[int, int]]:
|
||||
|
|
@ -42,6 +33,13 @@ class SliceableObjectDecorator(SceneNodeDecorator):
|
|||
def setTextureDataMapping(self, mapping: Dict[str, tuple[int, int]]) -> None:
|
||||
self._texture_data_mapping = mapping
|
||||
|
||||
def prepareTexture(self, width: int, height: int) -> None:
|
||||
if self._paint_texture is None:
|
||||
self._paint_texture = OpenGL.getInstance().createTexture(width, height)
|
||||
image = QImage(width, height, QImage.Format.Format_RGB32)
|
||||
image.fill(0)
|
||||
self._paint_texture.setImage(image)
|
||||
|
||||
def packTexture(self) -> Optional[bytearray]:
|
||||
if self._paint_texture is None:
|
||||
return None
|
||||
|
|
@ -60,6 +58,6 @@ class SliceableObjectDecorator(SceneNodeDecorator):
|
|||
|
||||
def __deepcopy__(self, memo) -> "SliceableObjectDecorator":
|
||||
copied_decorator = SliceableObjectDecorator()
|
||||
copied_decorator.setPaintTexture(copy.deepcopy(self.getPaintTexture(create_if_required = False)))
|
||||
copied_decorator.setPaintTexture(copy.deepcopy(self.getPaintTexture()))
|
||||
copied_decorator.setTextureDataMapping(copy.deepcopy(self.getTextureDataMapping()))
|
||||
return copied_decorator
|
||||
|
|
|
|||
|
|
@ -153,8 +153,6 @@ class ThreeMFReader(MeshReader):
|
|||
# It is only set for the root node of the 3mf file
|
||||
mesh_builder.setFileName(file_name)
|
||||
|
||||
mesh_builder.unwrapNewUvs()
|
||||
|
||||
mesh_data = mesh_builder.build()
|
||||
|
||||
if len(mesh_data.getVertices()):
|
||||
|
|
|
|||
|
|
@ -164,17 +164,22 @@ Item
|
|||
width: parent.width
|
||||
indicatorVisible: false
|
||||
|
||||
from: 1
|
||||
to: 40
|
||||
value: 10
|
||||
from: 10
|
||||
to: 1000
|
||||
value: 200
|
||||
|
||||
onPressedChanged: function(pressed)
|
||||
{
|
||||
if(! pressed)
|
||||
{
|
||||
UM.Controller.triggerActionWithData("setBrushSize", shapeSizeSlider.value)
|
||||
setBrushSize()
|
||||
}
|
||||
}
|
||||
|
||||
function setBrushSize()
|
||||
{
|
||||
UM.Controller.triggerActionWithData("setBrushSize", shapeSizeSlider.value)
|
||||
}
|
||||
}
|
||||
|
||||
//Line between the sections.
|
||||
|
|
@ -233,5 +238,6 @@ Item
|
|||
rowPaintMode.children[0].setMode()
|
||||
rowBrushColor.children[1].setColor()
|
||||
rowBrushShape.children[1].setShape()
|
||||
shapeSizeSlider.setBrushSize()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,6 +147,14 @@ class PaintView(View):
|
|||
paint_data_mapping[paint_type] = new_mapping
|
||||
node.callDecoration("setTextureDataMapping", paint_data_mapping)
|
||||
|
||||
mesh = node.getMeshData()
|
||||
if not mesh.hasUVCoordinates():
|
||||
texture_width, texture_height = mesh.calculateUnwrappedUVCoordinates(4096)
|
||||
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)
|
||||
|
||||
self._current_paint_type = paint_type
|
||||
self._current_bits_ranges = paint_data_mapping[paint_type]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue