本文整理汇总了Python中UM.View.GL.OpenGL.OpenGL.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Python OpenGL.getInstance方法的具体用法?Python OpenGL.getInstance怎么用?Python OpenGL.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UM.View.GL.OpenGL.OpenGL
的用法示例。
在下文中一共展示了OpenGL.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _initialize
# 需要导入模块: from UM.View.GL.OpenGL import OpenGL [as 别名]
# 或者: from UM.View.GL.OpenGL.OpenGL import getInstance [as 别名]
def _initialize(self):
OpenGL.setInstance(QtOpenGL())
self._gl = OpenGL.getInstance().getBindingsObject()
self._default_material = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader"))
self._render_passes.add(DefaultPass(self._viewport_width, self._viewport_height))
self._render_passes.add(SelectionPass(self._viewport_width, self._viewport_height))
self._render_passes.add(CompositePass(self._viewport_width, self._viewport_height))
buffer = QOpenGLBuffer(QOpenGLBuffer.VertexBuffer)
buffer.create()
buffer.bind()
buffer.allocate(120)
data = numpy.array([
-1.0, -1.0, 0.0,
1.0, 1.0, 0.0,
-1.0, 1.0, 0.0,
-1.0, -1.0, 0.0,
1.0, -1.0, 0.0,
1.0, 1.0, 0.0,
0.0, 0.0,
1.0, 1.0,
0.0, 1.0,
0.0, 0.0,
1.0, 0.0,
1.0, 1.0
], dtype = numpy.float32).tostring()
buffer.write(0, data, len(data))
buffer.release()
self._quad_buffer = buffer
self._initialized = True
示例2: __init__
# 需要导入模块: from UM.View.GL.OpenGL import OpenGL [as 别名]
# 或者: from UM.View.GL.OpenGL.OpenGL import getInstance [as 别名]
def __init__(self, width, height):
super().__init__("selection", width, height, -999)
self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "selection.shader"))
self._tool_handle_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader"))
self._gl = OpenGL.getInstance().getBindingsObject()
self._scene = Application.getInstance().getController().getScene()
self._renderer = Application.getInstance().getRenderer()
self._selection_map = {}
self._toolhandle_selection_map = {
self._dropAlpha(ToolHandle.DisabledSelectionColor): ToolHandle.NoAxis,
self._dropAlpha(ToolHandle.XAxisSelectionColor): ToolHandle.XAxis,
self._dropAlpha(ToolHandle.YAxisSelectionColor): ToolHandle.YAxis,
self._dropAlpha(ToolHandle.ZAxisSelectionColor): ToolHandle.ZAxis,
self._dropAlpha(ToolHandle.AllAxisSelectionColor): ToolHandle.AllAxis,
ToolHandle.DisabledSelectionColor: ToolHandle.NoAxis,
ToolHandle.XAxisSelectionColor: ToolHandle.XAxis,
ToolHandle.YAxisSelectionColor: ToolHandle.YAxis,
ToolHandle.ZAxisSelectionColor: ToolHandle.ZAxis,
ToolHandle.AllAxisSelectionColor: ToolHandle.AllAxis
}
self._output = None
示例3: beginRendering
# 需要导入模块: from UM.View.GL.OpenGL import OpenGL [as 别名]
# 或者: from UM.View.GL.OpenGL.OpenGL import getInstance [as 别名]
def beginRendering(self):
scene = self.getController().getScene()
renderer = self.getRenderer()
if not self._enabled_shader:
self._enabled_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "overhang.shader"))
if not self._disabled_shader:
self._disabled_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "striped.shader"))
self._disabled_shader.setUniformValue("u_diffuseColor1", [0.48, 0.48, 0.48, 1.0])
self._disabled_shader.setUniformValue("u_diffuseColor2", [0.68, 0.68, 0.68, 1.0])
self._disabled_shader.setUniformValue("u_width", 50.0)
if Application.getInstance().getGlobalContainerStack():
if Preferences.getInstance().getValue("view/show_overhang"):
angle = Application.getInstance().getGlobalContainerStack().getProperty("support_angle", "value")
if angle is not None:
self._enabled_shader.setUniformValue("u_overhangAngle", math.cos(math.radians(90 - angle)))
else:
self._enabled_shader.setUniformValue("u_overhangAngle", math.cos(math.radians(0))) #Overhang angle of 0 causes no area at all to be marked as overhang.
else:
self._enabled_shader.setUniformValue("u_overhangAngle", math.cos(math.radians(0)))
for node in DepthFirstIterator(scene.getRoot()):
if not node.render(renderer):
if node.getMeshData() and node.isVisible():
# TODO: Find a better way to handle this
#if node.getBoundingBoxMesh():
# renderer.queueNode(scene.getRoot(), mesh = node.getBoundingBoxMesh(),mode = Renderer.RenderLines)
uniforms = {}
if self._extruders_model.rowCount() > 0:
# Get color to render this mesh in from ExtrudersModel
extruder_index = 0
extruder_id = node.callDecoration("getActiveExtruder")
if extruder_id:
extruder_index = max(0, self._extruders_model.find("id", extruder_id))
extruder_color = self._extruders_model.getItem(extruder_index)["colour"]
try:
# Colors are passed as rgb hex strings (eg "#ffffff"), and the shader needs
# an rgba list of floats (eg [1.0, 1.0, 1.0, 1.0])
uniforms["diffuse_color"] = [
int(extruder_color[1:3], 16) / 255,
int(extruder_color[3:5], 16) / 255,
int(extruder_color[5:7], 16) / 255,
1.0
]
except ValueError:
pass
if hasattr(node, "_outside_buildarea"):
if node._outside_buildarea:
renderer.queueNode(node, shader = self._disabled_shader)
else:
renderer.queueNode(node, shader = self._enabled_shader, uniforms = uniforms)
else:
renderer.queueNode(node, material = self._enabled_shader, uniforms = uniforms)
if node.callDecoration("isGroup"):
renderer.queueNode(scene.getRoot(), mesh = node.getBoundingBoxMesh(), mode = Renderer.RenderLines)
示例4: __init__
# 需要导入模块: from UM.View.GL.OpenGL import OpenGL [as 别名]
# 或者: from UM.View.GL.OpenGL.OpenGL import getInstance [as 别名]
def __init__(self, width, height):
super().__init__("composite", width, height, RenderPass.MaximumPriority)
self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "composite.shader"))
self._gl = OpenGL.getInstance().getBindingsObject()
self._renderer = Application.getInstance().getRenderer()
self._layer_bindings = [ "default", "selection" ]
示例5: __init__
# 需要导入模块: from UM.View.GL.OpenGL import OpenGL [as 别名]
# 或者: from UM.View.GL.OpenGL.OpenGL import getInstance [as 别名]
def __init__(self, width, height):
super().__init__("composite", width, height, RenderPass.MaximumPriority)
self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "composite.shader"))
theme = Application.getInstance().getTheme()
self._shader.setUniformValue("u_background_color", Color(*theme.getColor("viewport_background").getRgb()))
self._shader.setUniformValue("u_outline_color", Color(*theme.getColor("model_selection_outline").getRgb()))
self._gl = OpenGL.getInstance().getBindingsObject()
self._renderer = Application.getInstance().getRenderer()
self._layer_bindings = [ "default", "selection" ]
示例6: __init__
# 需要导入模块: from UM.View.GL.OpenGL import OpenGL [as 别名]
# 或者: from UM.View.GL.OpenGL.OpenGL import getInstance [as 别名]
def __init__(self, width, height):
super().__init__("selection", width, height, -999)
self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "selection.shader"))
self._tool_handle_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader"))
self._gl = OpenGL.getInstance().getBindingsObject()
self._scene = Application.getInstance().getController().getScene()
self._renderer = Application.getInstance().getRenderer()
self._selection_map = {}
self._output = None
示例7: render
# 需要导入模块: from UM.View.GL.OpenGL import OpenGL [as 别名]
# 或者: from UM.View.GL.OpenGL.OpenGL import getInstance [as 别名]
def render(self):
if not self._layer_shader:
self._layer_shader = OpenGL.getInstance().createShaderProgram(os.path.join(PluginRegistry.getInstance().getPluginPath("LayerView"), "layers.shader"))
# Use extruder 0 if the extruder manager reports extruder index -1 (for single extrusion printers)
self._layer_shader.setUniformValue("u_active_extruder", float(max(0, self._extruder_manager.activeExtruderIndex)))
if not self._tool_handle_shader:
self._tool_handle_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "toolhandle.shader"))
self.bind()
tool_handle_batch = RenderBatch(self._tool_handle_shader, type = RenderBatch.RenderType.Overlay)
for node in DepthFirstIterator(self._scene.getRoot()):
if isinstance(node, ToolHandle):
tool_handle_batch.addItem(node.getWorldTransformation(), mesh = node.getSolidMesh())
elif isinstance(node, SceneNode) and node.getMeshData() and node.isVisible():
layer_data = node.callDecoration("getLayerData")
if not layer_data:
continue
# Render all layers below a certain number as line mesh instead of vertices.
if self._layerview._current_layer_num - self._layerview._solid_layers > -1 and not self._layerview._only_show_top_layers:
start = 0
end = 0
element_counts = layer_data.getElementCounts()
for layer, counts in element_counts.items():
if layer + self._layerview._solid_layers > self._layerview._current_layer_num:
break
end += counts
# This uses glDrawRangeElements internally to only draw a certain range of lines.
batch = RenderBatch(self._layer_shader, type = RenderBatch.RenderType.Solid, mode = RenderBatch.RenderMode.Lines, range = (start, end))
batch.addItem(node.getWorldTransformation(), layer_data)
batch.render(self._scene.getActiveCamera())
# Create a new batch that is not range-limited
batch = RenderBatch(self._layer_shader, type = RenderBatch.RenderType.Solid)
if self._layerview._current_layer_mesh:
batch.addItem(node.getWorldTransformation(), self._layerview._current_layer_mesh)
if self._layerview._current_layer_jumps:
batch.addItem(node.getWorldTransformation(), self._layerview._current_layer_jumps)
if len(batch.items) > 0:
batch.render(self._scene.getActiveCamera())
# Render toolhandles on top of the layerview
if len(tool_handle_batch.items) > 0:
tool_handle_batch.render(self._scene.getActiveCamera())
self.release()
示例8: render
# 需要导入模块: from UM.View.GL.OpenGL import OpenGL [as 别名]
# 或者: from UM.View.GL.OpenGL.OpenGL import getInstance [as 别名]
def render(self, renderer):
if not self.getMeshData():
return True
if not self._shader:
self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader"))
self._grid_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "grid.shader"))
renderer.queueNode(self, mode = RenderBatch.RenderMode.Lines)
renderer.queueNode(self, mesh = self._grid_mesh, shader = self._grid_shader, backface_cull = True)
if self._disallowed_area_mesh:
renderer.queueNode(self, mesh = self._disallowed_area_mesh, shader = self._shader, transparent = True, backface_cull = True, sort = -9)
return True
示例9: _updateTexture
# 需要导入模块: from UM.View.GL.OpenGL import OpenGL [as 别名]
# 或者: from UM.View.GL.OpenGL.OpenGL import getInstance [as 别名]
def _updateTexture(self):
if not self._machine_instance or not OpenGL.getInstance():
return
texture_file = self._machine_instance.getMachineDefinition().getPlatformTexture()
if texture_file:
self._texture = OpenGL.getInstance().createTexture()
self._texture.load(Resources.getPath(Resources.Images, texture_file))
if self._shader:
self._shader.setTexture(0, self._texture)
else:
self._texture = None
if self._shader:
self._shader.setTexture(0, None)
示例10: _updateTexture
# 需要导入模块: from UM.View.GL.OpenGL import OpenGL [as 别名]
# 或者: from UM.View.GL.OpenGL.OpenGL import getInstance [as 别名]
def _updateTexture(self):
if not self._global_container_stack or not OpenGL.getInstance():
return
self._texture = OpenGL.getInstance().createTexture()
container = self._global_container_stack.findContainer({"platform_texture":"*"})
if container:
texture_file = container.getMetaDataEntry("platform_texture")
self._texture.load(Resources.getPath(Resources.Images, texture_file))
# Note: if no texture file is specified, a 1 x 1 pixel transparent image is created
# by UM.GL.QtTexture to prevent rendering issues
if self._shader:
self._shader.setTexture(0, self._texture)
示例11: event
# 需要导入模块: from UM.View.GL.OpenGL import OpenGL [as 别名]
# 或者: from UM.View.GL.OpenGL.OpenGL import getInstance [as 别名]
def event(self, event):
if event.type == Event.ViewActivateEvent:
if not self._xray_pass:
# Currently the RenderPass constructor requires a size > 0
# This should be fixed in RenderPass's constructor.
self._xray_pass = XRayPass.XRayPass(1, 1)
self.getRenderer().addRenderPass(self._xray_pass)
if not self._xray_composite_shader:
self._xray_composite_shader = OpenGL.getInstance().createShaderProgram(os.path.join(PluginRegistry.getInstance().getPluginPath("XRayView"), "xray_composite.shader"))
theme = Application.getInstance().getTheme()
self._xray_composite_shader.setUniformValue("u_background_color", Color(*theme.getColor("viewport_background").getRgb()))
self._xray_composite_shader.setUniformValue("u_error_color", Color(*theme.getColor("xray_error").getRgb()))
self._xray_composite_shader.setUniformValue("u_outline_color", Color(*theme.getColor("model_selection_outline").getRgb()))
if not self._composite_pass:
self._composite_pass = self.getRenderer().getRenderPass("composite")
self._old_layer_bindings = self._composite_pass.getLayerBindings()
self._composite_pass.setLayerBindings(["default", "selection", "xray"])
self._old_composite_shader = self._composite_pass.getCompositeShader()
self._composite_pass.setCompositeShader(self._xray_composite_shader)
if event.type == Event.ViewDeactivateEvent:
self._composite_pass.setLayerBindings(self._old_layer_bindings)
self._composite_pass.setCompositeShader(self._old_composite_shader)
示例12: createMaterial
# 需要导入模块: from UM.View.GL.OpenGL import OpenGL [as 别名]
# 或者: from UM.View.GL.OpenGL.OpenGL import getInstance [as 别名]
def createMaterial(self):
self._material = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader"))
self._material.setUniformValue("u_ambientColor", Color(0.3, 0.3, 0.3, 1.0))
self._material.setUniformValue("u_diffuseColor", self._color)
self._material.setUniformValue("u_specularColor", Color(1.0, 1.0, 1.0, 1.0))
self._material.setUniformValue("u_shininess", 50.0)
示例13: _updateTexture
# 需要导入模块: from UM.View.GL.OpenGL import OpenGL [as 别名]
# 或者: from UM.View.GL.OpenGL.OpenGL import getInstance [as 别名]
def _updateTexture(self):
if not self._global_container_stack or not OpenGL.getInstance():
return
container = self._global_container_stack.findContainer({"platform_texture":"*"})
if container:
texture_file = container.getMetaDataEntry("platform_texture")
if texture_file:
self._texture = OpenGL.getInstance().createTexture()
self._texture.load(Resources.getPath(Resources.Images, texture_file))
if self._shader:
self._shader.setTexture(0, self._texture)
else:
self._texture = None
if self._shader:
self._shader.setTexture(0, None)
示例14: __init__
# 需要导入模块: from UM.View.GL.OpenGL import OpenGL [as 别名]
# 或者: from UM.View.GL.OpenGL.OpenGL import getInstance [as 别名]
def __init__(self, name: str, width: int, height: int, priority: int = 0) -> None:
self._name = name #type: str
self._width = width #type: int
self._height = height #type: int
self._priority = priority #type: int
self._gl = OpenGL.getInstance().getBindingsObject()
self._fbo = None #type: Optional[FrameBufferObject]
示例15: __init__
# 需要导入模块: from UM.View.GL.OpenGL import OpenGL [as 别名]
# 或者: from UM.View.GL.OpenGL.OpenGL import getInstance [as 别名]
def __init__(self, width, height):
super().__init__("layerview", width, height)
self._layer_shader = None
self._tool_handle_shader = None
self._gl = OpenGL.getInstance().getBindingsObject()
self._scene = Application.getInstance().getController().getScene()
self._extruder_manager = ExtruderManager.getInstance()
self._layer_view = None