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:
fieldOfView 2018-08-08 17:03:57 +02:00
parent 9239e82b1f
commit d7e8cc9224

View file

@ -25,6 +25,8 @@ from cura.Scene.BuildPlateDecorator import BuildPlateDecorator
from UM.Settings.SettingInstance import SettingInstance from UM.Settings.SettingInstance import SettingInstance
import numpy
class SupportEraser(Tool): class SupportEraser(Tool):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
@ -96,8 +98,7 @@ class SupportEraser(Tool):
node.setName("Eraser") node.setName("Eraser")
node.setSelectable(True) node.setSelectable(True)
mesh = MeshBuilder() mesh = self._createCube(10)
mesh.addCube(10,10,10)
node.setMeshData(mesh.build()) node.setMeshData(mesh.build())
active_build_plate = CuraApplication.getInstance().getMultiBuildPlateModel().activeBuildPlate active_build_plate = CuraApplication.getInstance().getMultiBuildPlateModel().activeBuildPlate
@ -160,3 +161,28 @@ class SupportEraser(Tool):
self._skip_press = False self._skip_press = False
self._had_selection = has_selection 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