本文整理汇总了Python中UM.Mesh.MeshBuilder.MeshBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Python MeshBuilder.build方法的具体用法?Python MeshBuilder.build怎么用?Python MeshBuilder.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UM.Mesh.MeshBuilder.MeshBuilder
的用法示例。
在下文中一共展示了MeshBuilder.build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import build [as 别名]
def read(self, file_name):
mesh_builder = MeshBuilder()
scene_node = SceneNode()
self.load_file(file_name, mesh_builder, _use_numpystl = use_numpystl)
mesh = mesh_builder.build()
if use_numpystl:
verts = mesh.getVertices()
# In some cases numpy stl reads incorrectly and the result is that the Z values are all 0
# Add new error cases if you find them.
if numpy.amin(verts[:, 1]) == numpy.amax(verts[:, 1]):
# Something may have gone wrong in numpy stl, start over without numpy stl
Logger.log("w", "All Z coordinates are the same using numpystl, trying again without numpy stl.")
mesh_builder = MeshBuilder()
self.load_file(file_name, mesh_builder, _use_numpystl = False)
mesh = mesh_builder.build()
verts = mesh.getVertices()
if numpy.amin(verts[:, 1]) == numpy.amax(verts[:, 1]):
Logger.log("e", "All Z coordinates are still the same without numpy stl... let's hope for the best")
if mesh_builder.getVertexCount() == 0:
Logger.log("d", "File did not contain valid data, unable to read.")
return None # We didn't load anything.
scene_node.setMeshData(mesh)
Logger.log("d", "Loaded a mesh with %s vertices", mesh_builder.getVertexCount())
return scene_node
示例2: buildMesh
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import build [as 别名]
def buildMesh(self):
#SOLIDMESH
mb = MeshBuilder()
mb.addDonut(
inner_radius = self._inner_radius,
outer_radius = self._outer_radius,
width = self._line_width,
color = self._z_axis_color
)
mb.addDonut(
inner_radius = self._inner_radius,
outer_radius = self._outer_radius,
width = self._line_width,
axis = Vector.Unit_X,
angle = math.pi / 2,
color = self._y_axis_color
)
mb.addDonut(
inner_radius = self._inner_radius,
outer_radius = self._outer_radius,
width = self._line_width,
axis = Vector.Unit_Y,
angle = math.pi / 2,
color = self._x_axis_color
)
self.setSolidMesh(mb.build())
#SELECTIONMESH
mb = MeshBuilder()
mb.addDonut(
inner_radius = self._active_inner_radius,
outer_radius = self._active_outer_radius,
width = self._active_line_width,
color = ToolHandle.ZAxisSelectionColor
)
mb.addDonut(
inner_radius = self._active_inner_radius,
outer_radius = self._active_outer_radius,
width = self._active_line_width,
axis = Vector.Unit_X,
angle = math.pi / 2,
color = ToolHandle.YAxisSelectionColor
)
mb.addDonut(
inner_radius = self._active_inner_radius,
outer_radius = self._active_outer_radius,
width = self._active_line_width,
axis = Vector.Unit_Y,
angle = math.pi / 2,
color = ToolHandle.XAxisSelectionColor
)
self.setSelectionMesh(mb.build())
示例3: _createEraserMesh
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import build [as 别名]
def _createEraserMesh(self, parent: CuraSceneNode, position: Vector):
node = CuraSceneNode()
node.setName("Eraser")
node.setSelectable(True)
mesh = MeshBuilder()
mesh.addCube(10,10,10)
node.setMeshData(mesh.build())
active_build_plate = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
node.addDecorator(BuildPlateDecorator(active_build_plate))
node.addDecorator(SliceableObjectDecorator())
stack = node.callDecoration("getStack") # created by SettingOverrideDecorator that is automatically added to CuraSceneNode
settings = stack.getTop()
definition = stack.getSettingDefinition("anti_overhang_mesh")
new_instance = SettingInstance(definition, settings)
new_instance.setProperty("value", True)
new_instance.resetState() # Ensure that the state is not seen as a user state.
settings.addInstance(new_instance)
op = GroupedOperation()
# First add node to the scene at the correct position/scale, before parenting, so the eraser mesh does not get scaled with the parent
op.addOperation(AddSceneNodeOperation(node, self._controller.getScene().getRoot()))
op.addOperation(SetParentOperation(node, parent))
op.push()
node.setPosition(position, CuraSceneNode.TransformSpace.World)
Application.getInstance().getController().getScene().sceneChanged.emit(node)
示例4: test_render
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import build [as 别名]
def test_render():
mocked_shader = MagicMock()
with patch("UM.View.GL.OpenGL.OpenGL.getInstance"):
render_batch = RenderBatch(mocked_shader)
# Render without a camera shouldn't cause any effect.
render_batch.render(None)
assert mocked_shader.bind.call_count == 0
# Rendering with a camera should cause the shader to be bound and released (even if the batch is empty)
mocked_camera = MagicMock()
mocked_camera.getWorldTransformation = MagicMock(return_value = Matrix())
mocked_camera.getViewProjectionMatrix = MagicMock(return_value=Matrix())
with patch("UM.View.GL.OpenGLContext.OpenGLContext.properties"):
render_batch.render(mocked_camera)
assert mocked_shader.bind.call_count == 1
assert mocked_shader.release.call_count == 1
# Actualy render with an item in the batch
mb = MeshBuilder()
mb.addPyramid(10, 10, 10, color=Color(0.0, 1.0, 0.0, 1.0))
mb.calculateNormals()
mesh_data = mb.build()
render_batch.addItem(Matrix(), mesh_data, {})
with patch("UM.View.GL.OpenGL.OpenGL.getInstance"):
with patch("UM.View.GL.OpenGLContext.OpenGLContext.properties"):
render_batch.render(mocked_camera)
assert mocked_shader.bind.call_count == 2
assert mocked_shader.release.call_count == 2
示例5: __init__
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import build [as 别名]
def __init__(self, node, hull, thickness, parent = None):
super().__init__(parent)
self.setCalculateBoundingBox(False)
self._original_parent = parent
# Color of the drawn convex hull
if Application.getInstance().hasGui():
self._color = Color(*Application.getInstance().getTheme().getColor("convex_hull").getRgb())
else:
self._color = Color(0, 0, 0)
# The y-coordinate of the convex hull mesh. Must not be 0, to prevent z-fighting.
self._mesh_height = 0.1
self._thickness = thickness
# The node this mesh is "watching"
self._node = node
self._convex_hull_head_mesh = None
self._node.decoratorsChanged.connect(self._onNodeDecoratorsChanged)
self._onNodeDecoratorsChanged(self._node)
self._hull = hull
if self._hull:
hull_mesh_builder = MeshBuilder()
if hull_mesh_builder.addConvexPolygonExtrusion(
self._hull.getPoints()[::-1], # bottom layer is reversed
self._mesh_height-thickness, self._mesh_height, color=self._color):
hull_mesh = hull_mesh_builder.build()
self.setMeshData(hull_mesh)
示例6: read
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import build [as 别名]
def read(self, file_name):
mesh_builder = MeshBuilder()
scene_node = SceneNode()
if use_numpystl:
self._loadWithNumpySTL(file_name, mesh_builder)
else:
f = open(file_name, "rb")
if not self._loadBinary(mesh_builder, f):
f.close()
f = open(file_name, "rt")
try:
self._loadAscii(mesh_builder, f)
except UnicodeDecodeError:
return None
f.close()
Job.yieldThread() # Yield somewhat to ensure the GUI has time to update a bit.
mesh_builder.calculateNormals(fast = True)
mesh = mesh_builder.build()
Logger.log("d", "Loaded a mesh with %s vertices", mesh_builder.getVertexCount())
scene_node.setMeshData(mesh)
return scene_node
示例7: _onNodeDecoratorsChanged
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import build [as 别名]
def _onNodeDecoratorsChanged(self, node):
convex_hull_head = self._node.callDecoration("getConvexHullHead")
if convex_hull_head:
convex_hull_head_builder = MeshBuilder()
convex_hull_head_builder.addConvexPolygon(convex_hull_head.getPoints(), self._mesh_height - self._thickness)
self._convex_hull_head_mesh = convex_hull_head_builder.build()
if not node:
return
示例8: read
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import build [as 别名]
def read(self, file_name):
try:
self.defs = {}
self.shapes = []
tree = ET.parse(file_name)
xml_root = tree.getroot()
if xml_root.tag != "X3D":
return None
scale = 1000 # Default X3D unit it one meter, while Cura's is one millimeters
if xml_root[0].tag == "head":
for head_node in xml_root[0]:
if head_node.tag == "unit" and head_node.attrib.get("category") == "length":
scale *= float(head_node.attrib["conversionFactor"])
break
xml_scene = xml_root[1]
else:
xml_scene = xml_root[0]
if xml_scene.tag != "Scene":
return None
self.transform = Matrix()
self.transform.setByScaleFactor(scale)
self.index_base = 0
# Traverse the scene tree, populate the shapes list
self.processChildNodes(xml_scene)
if self.shapes:
builder = MeshBuilder()
builder.setVertices(numpy.concatenate([shape.verts for shape in self.shapes]))
builder.setIndices(numpy.concatenate([shape.faces for shape in self.shapes]))
builder.calculateNormals()
builder.setFileName(file_name)
mesh_data = builder.build()
# Manually try and get the extents of the mesh_data. This should prevent nasty NaN issues from
# leaving the reader.
mesh_data.getExtents()
node = SceneNode()
node.setMeshData(mesh_data)
node.setSelectable(True)
node.setName(file_name)
else:
return None
except Exception:
Logger.logException("e", "Exception in X3D reader")
return None
return node
示例9: test_compute2DConvexHullMeshData
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import build [as 别名]
def test_compute2DConvexHullMeshData(convex_hull_decorator):
node = SceneNode()
mb = MeshBuilder()
mb.addCube(10,10,10)
node.setMeshData(mb.build())
convex_hull_decorator._getSettingProperty = MagicMock(return_value = 0)
with patch("UM.Application.Application.getInstance", MagicMock(return_value=mocked_application)):
convex_hull_decorator.setNode(node)
assert convex_hull_decorator._compute2DConvexHull() == Polygon([[5.0,-5.0], [-5.0,-5.0], [-5.0,5.0], [5.0,5.0]])
示例10: test_getExtents
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import build [as 别名]
def test_getExtents():
# Create a cube mesh at position 0,0,0
builder = MeshBuilder()
builder.addCube(20, 20, 20)
mesh_data = builder.build()
extents = mesh_data.getExtents()
assert extents.width == 20
assert extents.height == 20
assert extents.depth == 20
assert extents.maximum == Vector(10, 10, 10)
assert extents.minimum == Vector(-10, -10, -10)
示例11: createHullMesh
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import build [as 别名]
def createHullMesh(self, hull_points):
# Input checking.
if len(hull_points) < 3:
return None
mesh_builder = MeshBuilder()
point_first = Vector(hull_points[0][0], self._mesh_height, hull_points[0][1])
point_previous = Vector(hull_points[1][0], self._mesh_height, hull_points[1][1])
for point in hull_points[2:]: # Add the faces in the order of a triangle fan.
point_new = Vector(point[0], self._mesh_height, point[1])
mesh_builder.addFace(point_first, point_previous, point_new, color = self._color)
point_previous = point_new # Prepare point_previous for the next triangle.
return mesh_builder.build()
示例12: run
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import build [as 别名]
def run(self):
layer_data = None
for node in DepthFirstIterator(self._scene.getRoot()):
layer_data = node.callDecoration("getLayerData")
if layer_data:
break
if self._cancel or not layer_data:
return
layer_mesh = MeshBuilder()
for i in range(self._solid_layers):
layer_number = self._layer_number - i
if layer_number < 0:
continue
try:
layer = layer_data.getLayer(layer_number).createMesh()
except Exception:
Logger.logException("w", "An exception occurred while creating layer mesh.")
return
if not layer or layer.getVertices() is None:
continue
layer_mesh.addIndices(layer_mesh.getVertexCount() + layer.getIndices())
layer_mesh.addVertices(layer.getVertices())
# Scale layer color by a brightness factor based on the current layer number
# This will result in a range of 0.5 - 1.0 to multiply colors by.
brightness = numpy.ones((1, 4), dtype=numpy.float32) * (2.0 - (i / self._solid_layers)) / 2.0
brightness[0, 3] = 1.0
layer_mesh.addColors(layer.getColors() * brightness)
if self._cancel:
return
Job.yieldThread()
if self._cancel:
return
Job.yieldThread()
jump_mesh = layer_data.getLayer(self._layer_number).createJumps()
if not jump_mesh or jump_mesh.getVertices() is None:
jump_mesh = None
self.setResult({"layers": layer_mesh.build(), "jumps": jump_mesh})
示例13: test_getExtentsTransposed
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import build [as 别名]
def test_getExtentsTransposed():
# Create a cube mesh at position 0,0,0
builder = MeshBuilder()
builder.addCube(20, 20, 20)
mesh_data = builder.build()
transformation_matrix = Matrix()
transformation_matrix.setByTranslation(Vector(10, 10, 10))
extents = mesh_data.getExtents(transformation_matrix)
assert extents.width == 20
assert extents.height == 20
assert extents.depth == 20
assert extents.maximum == Vector(20, 20, 20)
assert extents.minimum == Vector(0, 0, 0)
示例14: createMeshOrJumps
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import build [as 别名]
def createMeshOrJumps(self, make_mesh):
builder = MeshBuilder()
line_count = 0
if make_mesh:
for polygon in self._polygons:
line_count += polygon.meshLineCount
else:
for polygon in self._polygons:
line_count += polygon.jumpCount
# Reserve the neccesary space for the data upfront
builder.reserveFaceAndVertexCount(2 * line_count, 4 * line_count)
for polygon in self._polygons:
# Filter out the types of lines we are not interesed in depending on whether we are drawing the mesh or the jumps.
index_mask = numpy.logical_not(polygon.jumpMask) if make_mesh else polygon.jumpMask
# Create an array with rows [p p+1] and only keep those we whant to draw based on make_mesh
points = numpy.concatenate((polygon.data[:-1], polygon.data[1:]), 1)[index_mask.ravel()]
# Line types of the points we want to draw
line_types = polygon.types[index_mask]
# Shift the z-axis according to previous implementation.
if make_mesh:
points[polygon.isInfillOrSkinType(line_types), 1::3] -= 0.01
else:
points[:, 1::3] += 0.01
# Create an array with normals and tile 2 copies to match size of points variable
normals = numpy.tile( polygon.getNormals()[index_mask.ravel()], (1, 2))
# Scale all normals by the line width of the current line so we can easily offset.
normals *= (polygon.lineWidths[index_mask.ravel()] / 2)
# Create 4 points to draw each line segment, points +- normals results in 2 points each.
# After this we reshape to one point per line.
f_points = numpy.concatenate((points-normals, points+normals), 1).reshape((-1, 3))
# __index_pattern defines which points to use to draw the two faces for each lines egment, the following linesegment is offset by 4
f_indices = ( self.__index_pattern + numpy.arange(0, 4 * len(normals), 4, dtype=numpy.int32).reshape((-1, 1)) ).reshape((-1, 3))
f_colors = numpy.repeat(polygon.mapLineTypeToColor(line_types), 4, 0)
builder.addFacesWithColor(f_points, f_indices, f_colors)
return builder.build()
示例15: calculateBoundingBoxMesh
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import build [as 别名]
def calculateBoundingBoxMesh(self):
aabb = self.getBoundingBox()
if aabb:
bounding_box_mesh = MeshBuilder()
rtf = aabb.maximum
lbb = aabb.minimum
bounding_box_mesh.addVertex(rtf.x, rtf.y, rtf.z) # Right - Top - Front
bounding_box_mesh.addVertex(lbb.x, rtf.y, rtf.z) # Left - Top - Front
bounding_box_mesh.addVertex(lbb.x, rtf.y, rtf.z) # Left - Top - Front
bounding_box_mesh.addVertex(lbb.x, lbb.y, rtf.z) # Left - Bottom - Front
bounding_box_mesh.addVertex(lbb.x, lbb.y, rtf.z) # Left - Bottom - Front
bounding_box_mesh.addVertex(rtf.x, lbb.y, rtf.z) # Right - Bottom - Front
bounding_box_mesh.addVertex(rtf.x, lbb.y, rtf.z) # Right - Bottom - Front
bounding_box_mesh.addVertex(rtf.x, rtf.y, rtf.z) # Right - Top - Front
bounding_box_mesh.addVertex(rtf.x, rtf.y, lbb.z) # Right - Top - Back
bounding_box_mesh.addVertex(lbb.x, rtf.y, lbb.z) # Left - Top - Back
bounding_box_mesh.addVertex(lbb.x, rtf.y, lbb.z) # Left - Top - Back
bounding_box_mesh.addVertex(lbb.x, lbb.y, lbb.z) # Left - Bottom - Back
bounding_box_mesh.addVertex(lbb.x, lbb.y, lbb.z) # Left - Bottom - Back
bounding_box_mesh.addVertex(rtf.x, lbb.y, lbb.z) # Right - Bottom - Back
bounding_box_mesh.addVertex(rtf.x, lbb.y, lbb.z) # Right - Bottom - Back
bounding_box_mesh.addVertex(rtf.x, rtf.y, lbb.z) # Right - Top - Back
bounding_box_mesh.addVertex(rtf.x, rtf.y, rtf.z) # Right - Top - Front
bounding_box_mesh.addVertex(rtf.x, rtf.y, lbb.z) # Right - Top - Back
bounding_box_mesh.addVertex(lbb.x, rtf.y, rtf.z) # Left - Top - Front
bounding_box_mesh.addVertex(lbb.x, rtf.y, lbb.z) # Left - Top - Back
bounding_box_mesh.addVertex(lbb.x, lbb.y, rtf.z) # Left - Bottom - Front
bounding_box_mesh.addVertex(lbb.x, lbb.y, lbb.z) # Left - Bottom - Back
bounding_box_mesh.addVertex(rtf.x, lbb.y, rtf.z) # Right - Bottom - Front
bounding_box_mesh.addVertex(rtf.x, lbb.y, lbb.z) # Right - Bottom - Back
self._bounding_box_mesh = bounding_box_mesh.build()