本文整理汇总了Python中UM.Mesh.MeshBuilder.MeshBuilder.setVertexUVCoordinates方法的典型用法代码示例。如果您正苦于以下问题:Python MeshBuilder.setVertexUVCoordinates方法的具体用法?Python MeshBuilder.setVertexUVCoordinates怎么用?Python MeshBuilder.setVertexUVCoordinates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UM.Mesh.MeshBuilder.MeshBuilder
的用法示例。
在下文中一共展示了MeshBuilder.setVertexUVCoordinates方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rebuild
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import setVertexUVCoordinates [as 别名]
def rebuild(self):
if not self._width or not self._height or not self._depth:
return
min_w = -self._width / 2
max_w = self._width / 2
min_h = 0.0
max_h = self._height
min_d = -self._depth / 2
max_d = self._depth / 2
mb = MeshBuilder()
# Outline 'cube' of the build volume
mb.addLine(Vector(min_w, min_h, min_d), Vector(max_w, min_h, min_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, max_h, min_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, max_h, min_d), Vector(max_w, max_h, min_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, max_h, min_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, min_h, max_d), Vector(max_w, min_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, min_h, max_d), Vector(min_w, max_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, max_h, max_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(max_w, min_h, max_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, min_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, min_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, max_h, min_d), Vector(min_w, max_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(max_w, max_h, min_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
self.setMeshData(mb.build())
mb = MeshBuilder()
mb.addQuad(
Vector(min_w, min_h - 0.2, min_d),
Vector(max_w, min_h - 0.2, min_d),
Vector(max_w, min_h - 0.2, max_d),
Vector(min_w, min_h - 0.2, max_d)
)
for n in range(0, 6):
v = mb.getVertex(n)
mb.setVertexUVCoordinates(n, v[0], v[2])
self._grid_mesh = mb.build()
disallowed_area_height = 0.1
disallowed_area_size = 0
if self._disallowed_areas:
mb = MeshBuilder()
color = Color(0.0, 0.0, 0.0, 0.15)
for polygon in self._disallowed_areas:
points = polygon.getPoints()
first = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height, self._clamp(points[0][1], min_d, max_d))
previous_point = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height, self._clamp(points[0][1], min_d, max_d))
for point in points:
new_point = Vector(self._clamp(point[0], min_w, max_w), disallowed_area_height, self._clamp(point[1], min_d, max_d))
mb.addFace(first, previous_point, new_point, color = color)
previous_point = new_point
# Find the largest disallowed area to exclude it from the maximum scale bounds.
# This is a very nasty hack. This pretty much only works for UM machines.
# This disallowed area_size needs a -lot- of rework at some point in the future: TODO
if numpy.min(points[:, 1]) >= 0: # This filters out all areas that have points to the left of the centre. This is done to filter the skirt area.
size = abs(numpy.max(points[:, 1]) - numpy.min(points[:, 1]))
else:
size = 0
disallowed_area_size = max(size, disallowed_area_size)
self._disallowed_area_mesh = mb.build()
else:
self._disallowed_area_mesh = None
if self._prime_tower_area:
mb = MeshBuilder()
color = Color(1.0, 0.0, 0.0, 0.5)
points = self._prime_tower_area.getPoints()
first = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height,
self._clamp(points[0][1], min_d, max_d))
previous_point = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height,
self._clamp(points[0][1], min_d, max_d))
for point in points:
new_point = Vector(self._clamp(point[0], min_w, max_w), disallowed_area_height,
self._clamp(point[1], min_d, max_d))
mb.addFace(first, previous_point, new_point, color=color)
previous_point = new_point
self._prime_tower_area_mesh = mb.build()
else:
self._prime_tower_area_mesh = None
self._volume_aabb = AxisAlignedBox(
minimum = Vector(min_w, min_h - 1.0, min_d),
maximum = Vector(max_w, max_h - self._raft_thickness, max_d))
bed_adhesion_size = 0.0
container_stack = Application.getInstance().getGlobalContainerStack()
if container_stack:
bed_adhesion_size = self._getBedAdhesionSize(container_stack)
# As this works better for UM machines, we only add the disallowed_area_size for the z direction.
#.........这里部分代码省略.........
示例2: rebuild
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import setVertexUVCoordinates [as 别名]
def rebuild(self):
if not self._width or not self._height or not self._depth:
return
min_w = -self._width / 2
max_w = self._width / 2
min_h = 0.0
max_h = self._height
min_d = -self._depth / 2
max_d = self._depth / 2
z_fight_distance = 0.2 # Distance between buildplate and disallowed area meshes to prevent z-fighting
if self._shape != "elliptic":
# Outline 'cube' of the build volume
mb = MeshBuilder()
mb.addLine(Vector(min_w, min_h, min_d), Vector(max_w, min_h, min_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, max_h, min_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, max_h, min_d), Vector(max_w, max_h, min_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, max_h, min_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, min_h, max_d), Vector(max_w, min_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, min_h, max_d), Vector(min_w, max_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, max_h, max_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(max_w, min_h, max_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, min_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, min_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, max_h, min_d), Vector(min_w, max_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(max_w, max_h, min_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
self.setMeshData(mb.build())
# Build plate grid mesh
mb = MeshBuilder()
mb.addQuad(
Vector(min_w, min_h - z_fight_distance, min_d),
Vector(max_w, min_h - z_fight_distance, min_d),
Vector(max_w, min_h - z_fight_distance, max_d),
Vector(min_w, min_h - z_fight_distance, max_d)
)
for n in range(0, 6):
v = mb.getVertex(n)
mb.setVertexUVCoordinates(n, v[0], v[2])
self._grid_mesh = mb.build()
else:
# Bottom and top 'ellipse' of the build volume
aspect = 1.0
scale_matrix = Matrix()
if self._width != 0:
# Scale circular meshes by aspect ratio if width != height
aspect = self._height / self._width
scale_matrix.compose(scale = Vector(1, 1, aspect))
mb = MeshBuilder()
mb.addArc(max_w, Vector.Unit_Y, center = (0, min_h - z_fight_distance, 0), color = self.VolumeOutlineColor)
mb.addArc(max_w, Vector.Unit_Y, center = (0, max_h, 0), color = self.VolumeOutlineColor)
self.setMeshData(mb.build().getTransformed(scale_matrix))
# Build plate grid mesh
mb = MeshBuilder()
mb.addVertex(0, min_h - z_fight_distance, 0)
mb.addArc(max_w, Vector.Unit_Y, center = Vector(0, min_h - z_fight_distance, 0))
sections = mb.getVertexCount() - 1 # Center point is not an arc section
indices = []
for n in range(0, sections - 1):
indices.append([0, n + 2, n + 1])
mb.addIndices(numpy.asarray(indices, dtype = numpy.int32))
mb.calculateNormals()
for n in range(0, mb.getVertexCount()):
v = mb.getVertex(n)
mb.setVertexUVCoordinates(n, v[0], v[2] * aspect)
self._grid_mesh = mb.build().getTransformed(scale_matrix)
# Indication of the machine origin
if self._global_container_stack.getProperty("machine_center_is_zero", "value"):
origin = (Vector(min_w, min_h, min_d) + Vector(max_w, min_h, max_d)) / 2
else:
origin = Vector(min_w, min_h, max_d)
mb = MeshBuilder()
mb.addCube(
width = self._origin_line_length,
height = self._origin_line_width,
depth = self._origin_line_width,
center = origin + Vector(self._origin_line_length / 2, 0, 0),
color = self.XAxisColor
)
mb.addCube(
width = self._origin_line_width,
height = self._origin_line_length,
depth = self._origin_line_width,
center = origin + Vector(0, self._origin_line_length / 2, 0),
color = self.YAxisColor
)
mb.addCube(
width = self._origin_line_width,
height = self._origin_line_width,
#.........这里部分代码省略.........
示例3: read
# 需要导入模块: from UM.Mesh.MeshBuilder import MeshBuilder [as 别名]
# 或者: from UM.Mesh.MeshBuilder.MeshBuilder import setVertexUVCoordinates [as 别名]
def read(self, file_name):
scene_node = None
extension = os.path.splitext(file_name)[1]
if extension.lower() in self._supported_extensions:
vertex_list = []
normal_list = []
uv_list = []
face_list = []
scene_node = SceneNode()
mesh_builder = MeshBuilder()
mesh_builder.setFileName(file_name)
f = open(file_name, "rt")
for line in f:
parts = line.split()
if len(parts) < 1:
continue
if parts[0] == "v":
vertex_list.append([float(parts[1]), float(parts[3]), -float(parts[2])])
if parts[0] == "vn":
normal_list.append([float(parts[1]), float(parts[3]), -float(parts[2])])
if parts[0] == "vt":
uv_list.append([float(parts[1]), float(parts[2])])
if parts[0] == "f":
parts = [i for i in map(lambda p: p.split("/"), parts)]
for idx in range(1, len(parts)-2):
data = [int(parts[1][0]), int(parts[idx+1][0]), int(parts[idx+2][0])]
if len(parts[1]) > 2:
data += [int(parts[1][2]), int(parts[idx+1][2]), int(parts[idx+2][2])]
if parts[1][1] and parts[idx+1][1] and parts[idx+2][1]:
data += [int(parts[1][1]), int(parts[idx+1][1]), int(parts[idx+2][1])]
face_list.append(data)
Job.yieldThread()
f.close()
mesh_builder.reserveVertexCount(3 * len(face_list))
num_vertices = len(vertex_list)
num_normals = len(normal_list)
for face in face_list:
# Substract 1 from index, as obj starts counting at 1 instead of 0
i = face[0] - 1
j = face[1] - 1
k = face[2] - 1
if len(face) > 3:
ni = face[3] - 1
nj = face[4] - 1
nk = face[5] - 1
else:
ni = -1
nj = -1
nk = -1
if len(face) > 6:
ui = face[6] - 1
uj = face[7] - 1
uk = face[8] - 1
else:
ui = -1
uj = -1
uk = -1
#TODO: improve this handling, this can cause weird errors (negative indexes are relative indexes, and are not properly handled)
if i < 0 or i >= num_vertices:
i = 0
if j < 0 or j >= num_vertices:
j = 0
if k < 0 or k >= num_vertices:
k = 0
if ni != -1 and nj != -1 and nk != -1:
mesh_builder.addFaceWithNormals(vertex_list[i][0], vertex_list[i][1], vertex_list[i][2], normal_list[ni][0], normal_list[ni][1], normal_list[ni][2], vertex_list[j][0], vertex_list[j][1], vertex_list[j][2], normal_list[nj][0], normal_list[nj][1], normal_list[nj][2], vertex_list[k][0], vertex_list[k][1], vertex_list[k][2],normal_list[nk][0], normal_list[nk][1], normal_list[nk][2])
else:
mesh_builder.addFaceByPoints(vertex_list[i][0], vertex_list[i][1], vertex_list[i][2], vertex_list[j][0], vertex_list[j][1], vertex_list[j][2], vertex_list[k][0], vertex_list[k][1], vertex_list[k][2])
if ui != -1:
mesh_builder.setVertexUVCoordinates(mesh_builder.getVertexCount() - 3, uv_list[ui][0], uv_list[ui][1])
if uj != -1:
mesh_builder.setVertexUVCoordinates(mesh_builder.getVertexCount() - 2, uv_list[uj][0], uv_list[uj][1])
if uk != -1:
mesh_builder.setVertexUVCoordinates(mesh_builder.getVertexCount() - 1, uv_list[uk][0], uv_list[uk][1])
Job.yieldThread()
if not mesh_builder.hasNormals():
mesh_builder.calculateNormals(fast = True)
scene_node.setMeshData(mesh_builder.build())
return scene_node