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
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
def _onGlobalContainerStackChanged(self): if self._global_container_stack: self.setMeshData(None) self._global_container_stack = Application.getInstance().getGlobalContainerStack() if self._global_container_stack: container = self._global_container_stack.findContainer({ "platform": "*" }) if container: mesh_file = container.getMetaDataEntry("platform") try: path = Resources.getPath(Resources.Meshes, mesh_file) except FileNotFoundError: Logger.log("w", "Unable to find the platform mesh %s", mesh_file) path = "" if self._load_platform_job: # This prevents a previous load job from triggering texture loads. self._load_platform_job.finished.disconnect(self._onPlatformLoaded) # Perform platform mesh loading in the background self._load_platform_job = _LoadPlatformJob(path) self._load_platform_job.finished.connect(self._onPlatformLoaded) self._load_platform_job.start() self._has_bed = True offset = container.getMetaDataEntry("platform_offset") if offset: if len(offset) == 3: self.setPosition(Vector(offset[0], offset[1], offset[2])) else: Logger.log("w", "Platform offset is invalid: %s", str(offset)) self.setPosition(Vector(0.0, 0.0, 0.0)) else: self.setPosition(Vector(0.0, 0.0, 0.0)) else: settings = Application.getInstance().getGlobalContainerStack() machine_width = settings.getProperty("machine_width", "value") machine_depth = settings.getProperty("machine_depth", "value") line_len = 25 line_wid = 1 handle_size = 3 mb = MeshBuilder() mb.addCube(line_wid, line_len, line_wid, Vector(-machine_width/2, line_len/2, machine_depth/2), ToolHandle.YAxisSelectionColor) mb.addPyramid(handle_size, handle_size, handle_size, center=Vector(-machine_width/2, line_len, machine_depth/2), color=ToolHandle.YAxisSelectionColor) mb.addCube(line_len, line_wid, line_wid, Vector(line_len/2-machine_width/2, 0, machine_depth/2), ToolHandle.XAxisSelectionColor) mb.addPyramid(handle_size, handle_size, handle_size, center=Vector(line_len-machine_width/2, 0, machine_depth/2), color=ToolHandle.XAxisSelectionColor, axis = Vector.Unit_Z, angle = 90) mb.addCube(line_wid, line_wid, line_len, Vector(-machine_width/2, 0, -line_len/2+machine_depth/2), ToolHandle.ZAxisSelectionColor) mb.addPyramid(handle_size, handle_size, handle_size, center=Vector(-machine_width/2, 0, -line_len+machine_depth/2), color=ToolHandle.ZAxisSelectionColor, axis = Vector.Unit_X, angle = 90) self.setMeshData(mb.build()) self.setPosition(Vector(0.0, 0.0, 0.0)) self._has_bed = False
def __init__(self, parent = None): super().__init__(parent) self._handle_width = 8 self._handle_height = 14 self._handle_position = 20 mb = MeshBuilder() mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(0, self._handle_position, 0), color = ToolHandle.YAxisColor ) mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(0, -self._handle_position, 0), color = ToolHandle.YAxisColor, axis = Vector.Unit_X, angle = 180 ) mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(self._handle_position, 0, 0), color = ToolHandle.XAxisColor, axis = Vector.Unit_Z, angle = 90 ) mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(-self._handle_position, 0, 0), color = ToolHandle.XAxisColor, axis = Vector.Unit_Z, angle = -90 ) mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(0, 0, -self._handle_position), color = ToolHandle.ZAxisColor, axis = Vector.Unit_X, angle = 90 ) mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(0, 0, self._handle_position), color = ToolHandle.ZAxisColor, axis = Vector.Unit_X, angle = -90 ) self.setSolidMesh(mb.getData()) self.setSelectionMesh(mb.getData())
def buildMesh(self): mb = MeshBuilder() #SOLIDMESH -> LINES if self.YAxis in self._enabled_axis: mb.addCube(width=self._line_width, height=self._line_length, depth=self._line_width, center=Vector(0, self._handle_position / 2, 0), color=self._y_axis_color) if self.XAxis in self._enabled_axis: mb.addCube(width=self._line_length, height=self._line_width, depth=self._line_width, center=Vector(self._handle_position / 2, 0, 0), color=self._x_axis_color) if self.ZAxis in self._enabled_axis: mb.addCube(width=self._line_width, height=self._line_width, depth=self._line_length, center=Vector(0, 0, self._handle_position / 2), color=self._z_axis_color) #SOLIDMESH -> HANDLES if self.YAxis in self._enabled_axis: mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(0, self._handle_position, 0), color=self._y_axis_color) if self.XAxis in self._enabled_axis: mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(self._handle_position, 0, 0), color=self._x_axis_color, axis=Vector.Unit_Z, angle=90) if self.ZAxis in self._enabled_axis: mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(0, 0, self._handle_position), color=self._z_axis_color, axis=Vector.Unit_X, angle=-90) self.setSolidMesh(mb.build()) mb = MeshBuilder() #SELECTIONMESH -> LINES if self.YAxis in self._enabled_axis: mb.addCube(width=self._active_line_width, height=self._active_line_length, depth=self._active_line_width, center=Vector(0, self._active_handle_position / 2, 0), color=self._y_axis_color) if self.XAxis in self._enabled_axis: mb.addCube(width=self._active_line_length, height=self._active_line_width, depth=self._active_line_width, center=Vector(self._active_handle_position / 2, 0, 0), color=self._x_axis_color) if self.ZAxis in self._enabled_axis: mb.addCube(width=self._active_line_width, height=self._active_line_width, depth=self._active_line_length, center=Vector(0, 0, self._active_handle_position / 2), color=self._z_axis_color) #SELECTIONMESH -> HANDLES mb.addCube(width=self._active_handle_width, height=self._active_handle_width, depth=self._active_handle_width, center=Vector(0, 0, 0), color=ToolHandle.AllAxisSelectionColor) mb.addCube(width=self._active_handle_width, height=self._active_handle_width, depth=self._active_handle_width, center=Vector(0, self._active_handle_position, 0), color=ToolHandle.YAxisSelectionColor) mb.addCube(width=self._active_handle_width, height=self._active_handle_width, depth=self._active_handle_width, center=Vector(self._active_handle_position, 0, 0), color=ToolHandle.XAxisSelectionColor) mb.addCube(width=self._active_handle_width, height=self._active_handle_width, depth=self._active_handle_width, center=Vector(0, 0, self._active_handle_position), color=ToolHandle.ZAxisSelectionColor) self.setSelectionMesh(mb.build())
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) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(0, self._handle_offset_a, -self._handle_offset_b), color=self._x_axis_color, axis=Vector.Unit_X, angle=90 + self._angle_offset) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(0, self._handle_offset_a, self._handle_offset_b), color=self._x_axis_color, axis=Vector.Unit_X, angle=-90 - self._angle_offset) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(self._handle_offset_b, 0, self._handle_offset_a), color=self._y_axis_color, axis=Vector.Unit_Z, angle=90 - self._angle_offset) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(-self._handle_offset_b, 0, self._handle_offset_a), color=self._y_axis_color, axis=Vector.Unit_Z, angle=-90 + self._angle_offset) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(self._handle_offset_a, self._handle_offset_b, 0), color=self._z_axis_color, axis=Vector.Unit_Z, angle=-self._angle_offset) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(self._handle_offset_a, -self._handle_offset_b, 0), color=self._z_axis_color, axis=Vector.Unit_Z, angle=180 + self._angle_offset) 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) mb.addPyramid(width=self._active_handle_width, height=self._active_handle_height, depth=self._active_handle_width, center=Vector(0, self._handle_offset_a, self._handle_offset_b), color=self._extra_widgets_color_map[ self.ExtraWidgets.XPositive90.value], axis=Vector.Unit_X, angle=-90 - self._angle_offset) mb.addPyramid(width=self._active_handle_width, height=self._active_handle_height, depth=self._active_handle_width, center=Vector(0, self._handle_offset_a, -self._handle_offset_b), color=self._extra_widgets_color_map[ self.ExtraWidgets.XNegative90.value], axis=Vector.Unit_X, angle=90 + self._angle_offset) mb.addPyramid(width=self._active_handle_width, height=self._active_handle_height, depth=self._active_handle_width, center=Vector(self._handle_offset_b, 0, self._handle_offset_a), color=self._extra_widgets_color_map[ self.ExtraWidgets.YPositive90.value], axis=Vector.Unit_Z, angle=90 - self._angle_offset) mb.addPyramid(width=self._active_handle_width, height=self._active_handle_height, depth=self._active_handle_width, center=Vector(-self._handle_offset_b, 0, self._handle_offset_a), color=self._extra_widgets_color_map[ self.ExtraWidgets.YNegative90.value], axis=Vector.Unit_Z, angle=-90 + self._angle_offset) mb.addPyramid(width=self._active_handle_width, height=self._active_handle_height, depth=self._active_handle_width, center=Vector(self._handle_offset_a, self._handle_offset_b, 0), color=self._extra_widgets_color_map[ self.ExtraWidgets.ZPositive90.value], axis=Vector.Unit_Z, angle=-self._angle_offset) mb.addPyramid(width=self._active_handle_width, height=self._active_handle_height, depth=self._active_handle_width, center=Vector(self._handle_offset_a, -self._handle_offset_b, 0), color=self._extra_widgets_color_map[ self.ExtraWidgets.ZNegative90.value], axis=Vector.Unit_Z, angle=180 + self._angle_offset) self.setSelectionMesh(mb.build())
def buildMesh(self): mb = MeshBuilder() #SOLIDMESH -> LINES if self.YAxis in self._enabled_axis: mb.addCube( width = self._line_width, height = self._line_length, depth = self._line_width, center = Vector(0, self._handle_position/2, 0), color = self._y_axis_color ) if self.XAxis in self._enabled_axis: mb.addCube( width = self._line_length, height = self._line_width, depth = self._line_width, center = Vector(self._handle_position/2, 0, 0), color = self._x_axis_color ) if self.ZAxis in self._enabled_axis: mb.addCube( width = self._line_width, height = self._line_width, depth = self._line_length, center = Vector(0, 0, self._handle_position/2), color = self._z_axis_color ) #SOLIDMESH -> HANDLES if self.YAxis in self._enabled_axis: mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(0, self._handle_position, 0), color = self._y_axis_color ) if self.XAxis in self._enabled_axis: mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(self._handle_position, 0, 0), color = self._x_axis_color, axis = Vector.Unit_Z, angle = 90 ) if self.ZAxis in self._enabled_axis: mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(0, 0, self._handle_position), color = self._z_axis_color, axis = Vector.Unit_X, angle = -90 ) self.setSolidMesh(mb.build()) mb = MeshBuilder() #SELECTIONMESH -> LINES if self.YAxis in self._enabled_axis: mb.addCube( width = self._active_line_width, height = self._active_line_length, depth = self._active_line_width, center = Vector(0, self._active_handle_position/2, 0), color = self._y_axis_color ) if self.XAxis in self._enabled_axis: mb.addCube( width = self._active_line_length, height = self._active_line_width, depth = self._active_line_width, center = Vector(self._active_handle_position/2, 0, 0), color = self._x_axis_color ) if self.ZAxis in self._enabled_axis: mb.addCube( width = self._active_line_width, height = self._active_line_width, depth = self._active_line_length, center = Vector(0, 0, self._active_handle_position/2), color = self._z_axis_color ) #SELECTIONMESH -> HANDLES mb.addCube( width = self._active_handle_width, height = self._active_handle_width, depth = self._active_handle_width, center = Vector(0, 0, 0), color = ToolHandle.AllAxisSelectionColor ) mb.addCube( width = self._active_handle_width, height = self._active_handle_width, depth = self._active_handle_width, center = Vector(0, self._active_handle_position, 0), color = ToolHandle.YAxisSelectionColor ) mb.addCube( width = self._active_handle_width, height = self._active_handle_width, depth = self._active_handle_width, center = Vector(self._active_handle_position, 0, 0), color = ToolHandle.XAxisSelectionColor ) mb.addCube( width = self._active_handle_width, height = self._active_handle_width, depth = self._active_handle_width, center = Vector(0, 0, self._active_handle_position), color = ToolHandle.ZAxisSelectionColor ) self.setSelectionMesh(mb.build())
def _rebuild(self): mb = MeshBuilder() #SOLIDMESH -> LINES if self.YAxis in self._enabled_axis: mb.addCube(width=self._lineWidth, height=self._lineLength, depth=self._lineWidth, center=Vector(0, self._handlePosition / 2, 0), color=ToolHandle.YAxisColor) if self.XAxis in self._enabled_axis: mb.addCube(width=self._lineLength, height=self._lineWidth, depth=self._lineWidth, center=Vector(self._handlePosition / 2, 0, 0), color=ToolHandle.XAxisColor) if self.ZAxis in self._enabled_axis: mb.addCube(width=self._lineWidth, height=self._lineWidth, depth=self._lineLength, center=Vector(0, 0, self._handlePosition / 2), color=ToolHandle.ZAxisColor) #SOLIDMESH -> HANDLES if self.YAxis in self._enabled_axis: mb.addPyramid(width=self._handleWidth, height=self._handleHeight, depth=self._handleWidth, center=Vector(0, self._handlePosition, 0), color=ToolHandle.YAxisColor) if self.XAxis in self._enabled_axis: mb.addPyramid(width=self._handleWidth, height=self._handleHeight, depth=self._handleWidth, center=Vector(self._handlePosition, 0, 0), color=ToolHandle.XAxisColor, axis=Vector.Unit_Z, angle=90) if self.ZAxis in self._enabled_axis: mb.addPyramid(width=self._handleWidth, height=self._handleHeight, depth=self._handleWidth, center=Vector(0, 0, self._handlePosition), color=ToolHandle.ZAxisColor, axis=Vector.Unit_X, angle=-90) self.setSolidMesh(mb.getData()) mb = MeshBuilder() #ACTIVEMESH -> LINES if self.YAxis in self._enabled_axis: mb.addCube(width=self._activeLineWidth, height=self._activeLineLength, depth=self._activeLineWidth, center=Vector(0, self._activeHandlePosition / 2, 0), color=ToolHandle.YAxisColor) if self.XAxis in self._enabled_axis: mb.addCube(width=self._activeLineLength, height=self._activeLineWidth, depth=self._activeLineWidth, center=Vector(self._activeHandlePosition / 2, 0, 0), color=ToolHandle.XAxisColor) if self.ZAxis in self._enabled_axis: mb.addCube(width=self._activeLineWidth, height=self._activeLineWidth, depth=self._activeLineLength, center=Vector(0, 0, self._activeHandlePosition / 2), color=ToolHandle.ZAxisColor) #SELECTIONMESH -> HANDLES mb.addCube(width=self._activeHandleWidth, height=self._activeHandleWidth, depth=self._activeHandleWidth, center=Vector(0, 0, 0), color=ToolHandle.AllAxisColor) mb.addCube(width=self._activeHandleWidth, height=self._activeHandleWidth, depth=self._activeHandleWidth, center=Vector(0, self._activeHandlePosition, 0), color=ToolHandle.YAxisColor) mb.addCube(width=self._activeHandleWidth, height=self._activeHandleWidth, depth=self._activeHandleWidth, center=Vector(self._activeHandlePosition, 0, 0), color=ToolHandle.XAxisColor) mb.addCube(width=self._activeHandleWidth, height=self._activeHandleWidth, depth=self._activeHandleWidth, center=Vector(0, 0, self._activeHandlePosition), color=ToolHandle.ZAxisColor) self.setSelectionMesh(mb.getData())
def _rebuild(self): mb = MeshBuilder() #SOLIDMESH -> LINES if self.YAxis in self._enabled_axis: mb.addCube( width = self._lineWidth, height = self._lineLength, depth = self._lineWidth, center = Vector(0, self._handlePosition/2, 0), color = ToolHandle.YAxisColor ) if self.XAxis in self._enabled_axis: mb.addCube( width = self._lineLength, height = self._lineWidth, depth = self._lineWidth, center = Vector(self._handlePosition/2, 0, 0), color = ToolHandle.XAxisColor ) if self.ZAxis in self._enabled_axis: mb.addCube( width = self._lineWidth, height = self._lineWidth, depth = self._lineLength, center = Vector(0, 0, self._handlePosition/2), color = ToolHandle.ZAxisColor ) #SOLIDMESH -> HANDLES if self.YAxis in self._enabled_axis: mb.addPyramid( width = self._handleWidth, height = self._handleHeight, depth = self._handleWidth, center = Vector(0, self._handlePosition, 0), color = ToolHandle.YAxisColor ) if self.XAxis in self._enabled_axis: mb.addPyramid( width = self._handleWidth, height = self._handleHeight, depth = self._handleWidth, center = Vector(self._handlePosition, 0, 0), color = ToolHandle.XAxisColor, axis = Vector.Unit_Z, angle = 90 ) if self.ZAxis in self._enabled_axis: mb.addPyramid( width = self._handleWidth, height = self._handleHeight, depth = self._handleWidth, center = Vector(0, 0, self._handlePosition), color = ToolHandle.ZAxisColor, axis = Vector.Unit_X, angle = -90 ) self.setSolidMesh(mb.getData()) mb = MeshBuilder() #ACTIVEMESH -> LINES if self.YAxis in self._enabled_axis: mb.addCube( width = self._activeLineWidth, height = self._activeLineLength, depth = self._activeLineWidth, center = Vector(0, self._activeHandlePosition/2, 0), color = ToolHandle.YAxisColor ) if self.XAxis in self._enabled_axis: mb.addCube( width = self._activeLineLength, height = self._activeLineWidth, depth = self._activeLineWidth, center = Vector(self._activeHandlePosition/2, 0, 0), color = ToolHandle.XAxisColor ) if self.ZAxis in self._enabled_axis: mb.addCube( width = self._activeLineWidth, height = self._activeLineWidth, depth = self._activeLineLength, center = Vector(0, 0, self._activeHandlePosition/2), color = ToolHandle.ZAxisColor ) #SELECTIONMESH -> HANDLES mb.addCube( width = self._activeHandleWidth, height = self._activeHandleWidth, depth = self._activeHandleWidth, center = Vector(0, 0, 0), color = ToolHandle.AllAxisColor ) mb.addCube( width = self._activeHandleWidth, height = self._activeHandleWidth, depth = self._activeHandleWidth, center = Vector(0, self._activeHandlePosition, 0), color = ToolHandle.YAxisColor ) mb.addCube( width = self._activeHandleWidth, height = self._activeHandleWidth, depth = self._activeHandleWidth, center = Vector(self._activeHandlePosition, 0, 0), color = ToolHandle.XAxisColor ) mb.addCube( width = self._activeHandleWidth, height = self._activeHandleWidth, depth = self._activeHandleWidth, center = Vector(0, 0, self._activeHandlePosition), color = ToolHandle.ZAxisColor ) self.setSelectionMesh(mb.getData())
def _rebuild(self): lines = MeshData() offset = 0 if self.YAxis in self._enabled_axis: lines.addVertex(0, 0, 0) lines.addVertex(0, 20, 0) lines.setVertexColor(offset, ToolHandle.YAxisColor) lines.setVertexColor(offset + 1, ToolHandle.YAxisColor) offset += 2 if self.XAxis in self._enabled_axis: lines.addVertex(0, 0, 0) lines.addVertex(20, 0, 0) lines.setVertexColor(offset, ToolHandle.XAxisColor) lines.setVertexColor(offset + 1, ToolHandle.XAxisColor) offset += 2 if self.ZAxis in self._enabled_axis: lines.addVertex(0, 0, 0) lines.addVertex(0, 0, 20) lines.setVertexColor(offset, ToolHandle.ZAxisColor) lines.setVertexColor(offset + 1, ToolHandle.ZAxisColor) offset += 2 self.setLineMesh(lines) mb = MeshBuilder() if self.YAxis in self._enabled_axis: mb.addPyramid( width = 2, height = 4, depth = 2, center = Vector(0, 20, 0), color = ToolHandle.YAxisColor ) if self.XAxis in self._enabled_axis: mb.addPyramid( width = 2, height = 4, depth = 2, center = Vector(20, 0, 0), color = ToolHandle.XAxisColor, axis = Vector.Unit_Z, angle = 90 ) if self.ZAxis in self._enabled_axis: mb.addPyramid( width = 2, height = 4, depth = 2, center = Vector(0, 0, 20), color = ToolHandle.ZAxisColor, axis = Vector.Unit_X, angle = -90 ) self.setSolidMesh(mb.getData()) mb = MeshBuilder() if self.YAxis in self._enabled_axis: mb.addCube( width = 4, height = 20, depth = 4, center = Vector(0, 10, 0), color = ToolHandle.YAxisColor ) mb.addPyramid( width = 4, height = 8, depth = 4, center = Vector(0, 20, 0), color = ToolHandle.YAxisColor ) if self.XAxis in self._enabled_axis: mb.addCube( width = 20, height = 4, depth = 4, center = Vector(10, 0, 0), color = ToolHandle.XAxisColor ) mb.addPyramid( width = 4, height = 8, depth = 4, center = Vector(20, 0, 0), color = ToolHandle.XAxisColor, axis = Vector.Unit_Z, angle = 90 ) if self.ZAxis in self._enabled_axis: mb.addCube( width = 4, height = 4, depth = 20, center = Vector(0, 0, 10), color = ToolHandle.ZAxisColor ) mb.addPyramid( width = 4, height = 8, depth = 4, center = Vector(0, 0, 20), color = ToolHandle.ZAxisColor, axis = Vector.Unit_X, angle = -90 ) self.setSelectionMesh(mb.getData())
def buildMesh(self): mb = MeshBuilder() #SOLIDMESH mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(0, self._handle_position, 0), color=self._y_axis_color) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(0, -self._handle_position, 0), color=self._y_axis_color, axis=Vector.Unit_X, angle=180) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(self._handle_position, 0, 0), color=self._x_axis_color, axis=Vector.Unit_Z, angle=90) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(-self._handle_position, 0, 0), color=self._x_axis_color, axis=Vector.Unit_Z, angle=-90) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(0, 0, -self._handle_position), color=self._z_axis_color, axis=Vector.Unit_X, angle=90) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(0, 0, self._handle_position), color=self._z_axis_color, axis=Vector.Unit_X, angle=-90) self.setSolidMesh(mb.build()) #SELECTIONMESH mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(0, self._handle_position, 0), color=ToolHandle.YAxisSelectionColor) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(0, -self._handle_position, 0), color=ToolHandle.YAxisSelectionColor, axis=Vector.Unit_X, angle=180) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(self._handle_position, 0, 0), color=ToolHandle.XAxisSelectionColor, axis=Vector.Unit_Z, angle=90) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(-self._handle_position, 0, 0), color=ToolHandle.XAxisSelectionColor, axis=Vector.Unit_Z, angle=-90) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(0, 0, -self._handle_position), color=ToolHandle.ZAxisSelectionColor, axis=Vector.Unit_X, angle=90) mb.addPyramid(width=self._handle_width, height=self._handle_height, depth=self._handle_width, center=Vector(0, 0, self._handle_position), color=ToolHandle.ZAxisSelectionColor, axis=Vector.Unit_X, angle=-90) self.setSelectionMesh(mb.build())
def __init__(self, parent = None): super().__init__(parent) mb = MeshBuilder() mb.addPyramid( width = 4, height = 7, depth = 4, center = Vector(0, 10, 0), color = ToolHandle.YAxisColor ) mb.addPyramid( width = 4, height = 7, depth = 4, center = Vector(0, -10, 0), color = ToolHandle.YAxisColor, axis = Vector.Unit_X, angle = 180 ) mb.addPyramid( width = 4, height = 7, depth = 4, center = Vector(10, 0, 0), color = ToolHandle.XAxisColor, axis = Vector.Unit_Z, angle = 90 ) mb.addPyramid( width = 4, height = 7, depth = 4, center = Vector(-10, 0, 0), color = ToolHandle.XAxisColor, axis = Vector.Unit_Z, angle = -90 ) mb.addPyramid( width = 4, height = 7, depth = 4, center = Vector(0, 0, -10), color = ToolHandle.ZAxisColor, axis = Vector.Unit_X, angle = 90 ) mb.addPyramid( width = 4, height = 7, depth = 4, center = Vector(0, 0, 10), color = ToolHandle.ZAxisColor, axis = Vector.Unit_X, angle = -90 ) self.setSolidMesh(mb.getData()) self.setSelectionMesh(mb.getData())
def buildMesh(self): mb = MeshBuilder() #SOLIDMESH mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(0, self._handle_position, 0), color = self._y_axis_color ) mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(0, -self._handle_position, 0), color = self._y_axis_color, axis = Vector.Unit_X, angle = 180 ) mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(self._handle_position, 0, 0), color = self._x_axis_color, axis = Vector.Unit_Z, angle = 90 ) mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(-self._handle_position, 0, 0), color = self._x_axis_color, axis = Vector.Unit_Z, angle = -90 ) mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(0, 0, -self._handle_position), color = self._z_axis_color, axis = Vector.Unit_X, angle = 90 ) mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(0, 0, self._handle_position), color = self._z_axis_color, axis = Vector.Unit_X, angle = -90 ) self.setSolidMesh(mb.build()) #SELECTIONMESH mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(0, self._handle_position, 0), color = ToolHandle.YAxisSelectionColor ) mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(0, -self._handle_position, 0), color = ToolHandle.YAxisSelectionColor, axis = Vector.Unit_X, angle = 180 ) mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(self._handle_position, 0, 0), color = ToolHandle.XAxisSelectionColor, axis = Vector.Unit_Z, angle = 90 ) mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(-self._handle_position, 0, 0), color = ToolHandle.XAxisSelectionColor, axis = Vector.Unit_Z, angle = -90 ) mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(0, 0, -self._handle_position), color = ToolHandle.ZAxisSelectionColor, axis = Vector.Unit_X, angle = 90 ) mb.addPyramid( width = self._handle_width, height = self._handle_height, depth = self._handle_width, center = Vector(0, 0, self._handle_position), color = ToolHandle.ZAxisSelectionColor, axis = Vector.Unit_X, angle = -90 ) self.setSelectionMesh(mb.build())