mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Fix rendering support eraser cubes
MeshBuilder.addCube creates cubes that don't have per-vertex normals. Geometry like that does not render properly in most shaders used in Cura. This becomes obvious when a user changes the "Mesh Type" using Per Model Settings.
This commit is contained in:
parent
9239e82b1f
commit
d7e8cc9224
1 changed files with 28 additions and 2 deletions
|
@ -25,6 +25,8 @@ from cura.Scene.BuildPlateDecorator import BuildPlateDecorator
|
|||
|
||||
from UM.Settings.SettingInstance import SettingInstance
|
||||
|
||||
import numpy
|
||||
|
||||
class SupportEraser(Tool):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -96,8 +98,7 @@ class SupportEraser(Tool):
|
|||
|
||||
node.setName("Eraser")
|
||||
node.setSelectable(True)
|
||||
mesh = MeshBuilder()
|
||||
mesh.addCube(10,10,10)
|
||||
mesh = self._createCube(10)
|
||||
node.setMeshData(mesh.build())
|
||||
|
||||
active_build_plate = CuraApplication.getInstance().getMultiBuildPlateModel().activeBuildPlate
|
||||
|
@ -160,3 +161,28 @@ class SupportEraser(Tool):
|
|||
self._skip_press = False
|
||||
|
||||
self._had_selection = has_selection
|
||||
|
||||
def _createCube(self, size):
|
||||
mesh = MeshBuilder()
|
||||
|
||||
# Can't use MeshBuilder.addCube() because that does not get per-vertex normals
|
||||
# Per-vertex normals require duplication of vertices
|
||||
s = size / 2
|
||||
verts = [ # 6 faces with 4 corners each
|
||||
[-s, -s, s], [-s, s, s], [ s, s, s], [ s, -s, s],
|
||||
[-s, s, -s], [-s, -s, -s], [ s, -s, -s], [ s, s, -s],
|
||||
[ s, -s, -s], [-s, -s, -s], [-s, -s, s], [ s, -s, s],
|
||||
[-s, s, -s], [ s, s, -s], [ s, s, s], [-s, s, s],
|
||||
[-s, -s, s], [-s, -s, -s], [-s, s, -s], [-s, s, s],
|
||||
[ s, -s, -s], [ s, -s, s], [ s, s, s], [ s, s, -s]
|
||||
]
|
||||
mesh.setVertices(numpy.asarray(verts, dtype=numpy.float32))
|
||||
|
||||
indices = []
|
||||
for i in range(0, 24, 4): # All 6 quads (12 triangles)
|
||||
indices.append([i, i+2, i+1])
|
||||
indices.append([i, i+3, i+2])
|
||||
mesh.setIndices(numpy.asarray(indices, dtype=numpy.int32))
|
||||
|
||||
mesh.calculateNormals()
|
||||
return mesh
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue