Add Chromium-only Blender WebEngine parity work

This commit is contained in:
mes123456
2026-08-12 04:47:48 -04:00
commit 9fd26010f6
18225 changed files with 11622124 additions and 0 deletions

View File

@@ -0,0 +1,157 @@
# Example of a custom widget that defines its own geometry.
#
# Usage: Select a light in the 3D view and drag the arrow at it's rear
# to change it's energy value.
#
import bpy
from bpy.types import (
Gizmo,
GizmoGroup,
)
# Coordinates (each one is a triangle).
custom_shape_verts = (
(3.0, 1.0, -1.0), (2.0, 2.0, -1.0), (3.0, 3.0, -1.0),
(1.0, 3.0, 1.0), (3.0, 3.0, -1.0), (1.0, 3.0, -1.0),
(3.0, 3.0, 1.0), (3.0, 1.0, -1.0), (3.0, 3.0, -1.0),
(2.0, 0.0, 1.0), (3.0, 1.0, -1.0), (3.0, 1.0, 1.0),
(2.0, 0.0, -1.0), (2.0, 2.0, 1.0), (2.0, 2.0, -1.0),
(2.0, 2.0, -1.0), (0.0, 2.0, 1.0), (0.0, 2.0, -1.0),
(1.0, 3.0, 1.0), (2.0, 2.0, 1.0), (3.0, 3.0, 1.0),
(0.0, 2.0, -1.0), (1.0, 3.0, 1.0), (1.0, 3.0, -1.0),
(2.0, 2.0, 1.0), (3.0, 1.0, 1.0), (3.0, 3.0, 1.0),
(2.0, 2.0, -1.0), (1.0, 3.0, -1.0), (3.0, 3.0, -1.0),
(-3.0, -1.0, -1.0), (-2.0, -2.0, -1.0), (-3.0, -3.0, -1.0),
(-1.0, -3.0, 1.0), (-3.0, -3.0, -1.0), (-1.0, -3.0, -1.0),
(-3.0, -3.0, 1.0), (-3.0, -1.0, -1.0), (-3.0, -3.0, -1.0),
(-2.0, 0.0, 1.0), (-3.0, -1.0, -1.0), (-3.0, -1.0, 1.0),
(-2.0, 0.0, -1.0), (-2.0, -2.0, 1.0), (-2.0, -2.0, -1.0),
(-2.0, -2.0, -1.0), (0.0, -2.0, 1.0), (0.0, -2.0, -1.0),
(-1.0, -3.0, 1.0), (-2.0, -2.0, 1.0), (-3.0, -3.0, 1.0),
(0.0, -2.0, -1.0), (-1.0, -3.0, 1.0), (-1.0, -3.0, -1.0),
(-2.0, -2.0, 1.0), (-3.0, -1.0, 1.0), (-3.0, -3.0, 1.0),
(-2.0, -2.0, -1.0), (-1.0, -3.0, -1.0), (-3.0, -3.0, -1.0),
(1.0, -1.0, 0.0), (-1.0, -1.0, 0.0), (0.0, 0.0, -5.0),
(-1.0, -1.0, 0.0), (1.0, -1.0, 0.0), (0.0, 0.0, 5.0),
(1.0, -1.0, 0.0), (1.0, 1.0, 0.0), (0.0, 0.0, 5.0),
(1.0, 1.0, 0.0), (-1.0, 1.0, 0.0), (0.0, 0.0, 5.0),
(-1.0, 1.0, 0.0), (-1.0, -1.0, 0.0), (0.0, 0.0, 5.0),
(-1.0, -1.0, 0.0), (-1.0, 1.0, 0.0), (0.0, 0.0, -5.0),
(-1.0, 1.0, 0.0), (1.0, 1.0, 0.0), (0.0, 0.0, -5.0),
(1.0, 1.0, 0.0), (1.0, -1.0, 0.0), (0.0, 0.0, -5.0),
(3.0, 1.0, -1.0), (2.0, 0.0, -1.0), (2.0, 2.0, -1.0),
(1.0, 3.0, 1.0), (3.0, 3.0, 1.0), (3.0, 3.0, -1.0),
(3.0, 3.0, 1.0), (3.0, 1.0, 1.0), (3.0, 1.0, -1.0),
(2.0, 0.0, 1.0), (2.0, 0.0, -1.0), (3.0, 1.0, -1.0),
(2.0, 0.0, -1.0), (2.0, 0.0, 1.0), (2.0, 2.0, 1.0),
(2.0, 2.0, -1.0), (2.0, 2.0, 1.0), (0.0, 2.0, 1.0),
(1.0, 3.0, 1.0), (0.0, 2.0, 1.0), (2.0, 2.0, 1.0),
(0.0, 2.0, -1.0), (0.0, 2.0, 1.0), (1.0, 3.0, 1.0),
(2.0, 2.0, 1.0), (2.0, 0.0, 1.0), (3.0, 1.0, 1.0),
(2.0, 2.0, -1.0), (0.0, 2.0, -1.0), (1.0, 3.0, -1.0),
(-3.0, -1.0, -1.0), (-2.0, 0.0, -1.0), (-2.0, -2.0, -1.0),
(-1.0, -3.0, 1.0), (-3.0, -3.0, 1.0), (-3.0, -3.0, -1.0),
(-3.0, -3.0, 1.0), (-3.0, -1.0, 1.0), (-3.0, -1.0, -1.0),
(-2.0, 0.0, 1.0), (-2.0, 0.0, -1.0), (-3.0, -1.0, -1.0),
(-2.0, 0.0, -1.0), (-2.0, 0.0, 1.0), (-2.0, -2.0, 1.0),
(-2.0, -2.0, -1.0), (-2.0, -2.0, 1.0), (0.0, -2.0, 1.0),
(-1.0, -3.0, 1.0), (0.0, -2.0, 1.0), (-2.0, -2.0, 1.0),
(0.0, -2.0, -1.0), (0.0, -2.0, 1.0), (-1.0, -3.0, 1.0),
(-2.0, -2.0, 1.0), (-2.0, 0.0, 1.0), (-3.0, -1.0, 1.0),
(-2.0, -2.0, -1.0), (0.0, -2.0, -1.0), (-1.0, -3.0, -1.0),
)
class MyCustomShapeWidget(Gizmo):
bl_idname = "VIEW3D_GT_custom_shape_widget"
bl_target_properties = (
{"id": "offset", "type": 'FLOAT', "array_length": 1},
)
__slots__ = (
"custom_shape",
"init_mouse_y",
"init_value",
)
def _update_offset_matrix(self):
# offset behind the light
self.matrix_offset.col[3][2] = self.target_get_value("offset") / -10.0
def draw(self, context):
self._update_offset_matrix()
self.draw_custom_shape(self.custom_shape)
def draw_select(self, context, select_id):
self._update_offset_matrix()
self.draw_custom_shape(self.custom_shape, select_id=select_id)
def setup(self):
if not hasattr(self, "custom_shape"):
self.custom_shape = self.new_custom_shape('TRIS', custom_shape_verts)
def invoke(self, context, event):
self.init_mouse_y = event.mouse_y
self.init_value = self.target_get_value("offset")
return {'RUNNING_MODAL'}
def exit(self, context, cancel):
context.area.header_text_set(None)
if cancel:
self.target_set_value("offset", self.init_value)
def modal(self, context, event, tweak):
delta = (event.mouse_y - self.init_mouse_y) / 10.0
if 'SNAP' in tweak:
delta = round(delta)
if 'PRECISE' in tweak:
delta /= 10.0
value = self.init_value - delta
self.target_set_value("offset", value)
context.area.header_text_set("My Gizmo: {:.4f}".format(value))
return {'RUNNING_MODAL'}
class MyCustomShapeWidgetGroup(GizmoGroup):
bl_idname = "OBJECT_GGT_light_test"
bl_label = "Test Light Widget"
bl_space_type = 'VIEW_3D'
bl_region_type = 'WINDOW'
bl_options = {'3D', 'PERSISTENT'}
@classmethod
def poll(cls, context):
ob = context.object
return (ob and ob.type == 'LIGHT')
def setup(self, context):
# Assign the `offset` target property to the light energy.
ob = context.object
gz = self.gizmos.new(MyCustomShapeWidget.bl_idname)
gz.target_set_prop("offset", ob.data, "energy")
gz.color = 1.0, 0.5, 1.0
gz.alpha = 0.5
gz.color_highlight = 1.0, 1.0, 1.0
gz.alpha_highlight = 0.5
# units are large, so shrink to something more reasonable.
gz.scale_basis = 0.1
gz.use_draw_modal = True
self.energy_gizmo = gz
def refresh(self, context):
ob = context.object
gz = self.energy_gizmo
gz.matrix_basis = ob.matrix_world.normalized()
classes = (
MyCustomShapeWidget,
MyCustomShapeWidgetGroup,
)
for cls in classes:
bpy.utils.register_class(cls)

View File

@@ -0,0 +1,235 @@
# Example of an operator which uses gizmos to control its properties.
#
# Usage: Run this script, then in mesh edit-mode press F3
# to activate the operator "Select Side of Plane"
# The gizmos can then be used to adjust the plane in the 3D view.
#
import bpy
import bmesh
from bpy.types import (
Operator,
GizmoGroup,
)
from bpy.props import (
FloatVectorProperty,
)
def main(context, plane_co, plane_no):
obj = context.active_object
matrix = obj.matrix_world.copy()
me = obj.data
bm = bmesh.from_edit_mesh(me)
plane_dot = plane_no.dot(plane_co)
for v in bm.verts:
co = matrix @ v.co
v.select = (plane_no.dot(co) > plane_dot)
bm.select_flush_mode()
bmesh.update_edit_mesh(me)
class SelectSideOfPlane(Operator):
"""Select all vertices on one side of a plane defined by a location and a direction"""
bl_idname = "mesh.select_side_of_plane"
bl_label = "Select Side of Plane"
bl_options = {'REGISTER', 'UNDO'}
plane_co: FloatVectorProperty(
size=3,
default=(0, 0, 0),
)
plane_no: FloatVectorProperty(
size=3,
default=(0, 0, 1),
)
@classmethod
def poll(cls, context):
return (context.mode == 'EDIT_MESH')
def invoke(self, context, event):
if not self.properties.is_property_set("plane_co"):
self.plane_co = context.scene.cursor.location
if not self.properties.is_property_set("plane_no"):
if context.space_data.type == 'VIEW_3D':
rv3d = context.space_data.region_3d
view_inv = rv3d.view_matrix.to_3x3()
# view y axis
self.plane_no = view_inv[1].normalized()
self.execute(context)
if context.space_data.type == 'VIEW_3D':
wm = context.window_manager
wm.gizmo_group_type_ensure(SelectSideOfPlaneGizmoGroup.bl_idname)
return {'FINISHED'}
def execute(self, context):
from mathutils import Vector
main(context, Vector(self.plane_co), Vector(self.plane_no))
return {'FINISHED'}
# Gizmos for plane_co, plane_no
class SelectSideOfPlaneGizmoGroup(GizmoGroup):
bl_idname = "MESH_GGT_select_side_of_plane"
bl_label = "Side of Plane Gizmo"
bl_space_type = 'VIEW_3D'
bl_region_type = 'WINDOW'
bl_options = {'3D', 'EXCLUDE_MODAL'}
# Helper functions
@staticmethod
def my_target_operator(context):
wm = context.window_manager
op = wm.operators[-1] if wm.operators else None
if isinstance(op, SelectSideOfPlane):
return op
return None
@staticmethod
def my_view_orientation(context):
rv3d = context.space_data.region_3d
view_inv = rv3d.view_matrix.to_3x3()
return view_inv.normalized()
@classmethod
def poll(cls, context):
op = cls.my_target_operator(context)
if op is None:
wm = context.window_manager
wm.gizmo_group_type_unlink_delayed(SelectSideOfPlaneGizmoGroup.bl_idname)
return False
return True
def setup(self, context):
from mathutils import Matrix, Vector
# ----
# Move
def move_get_cb():
op = SelectSideOfPlaneGizmoGroup.my_target_operator(context)
return op.plane_co
def move_set_cb(value):
op = SelectSideOfPlaneGizmoGroup.my_target_operator(context)
op.plane_co = value
# XXX, this may change!
op.execute(context)
gz = self.gizmos.new("GIZMO_GT_move_3d")
gz.target_set_handler("offset", get=move_get_cb, set=move_set_cb)
gz.use_draw_value = True
gz.color = 0.8, 0.8, 0.8
gz.alpha = 0.5
gz.color_highlight = 1.0, 1.0, 1.0
gz.alpha_highlight = 1.0
gz.scale_basis = 0.2
self.gizmo_move = gz
# ----
# Dial
def direction_get_cb():
op = SelectSideOfPlaneGizmoGroup.my_target_operator(context)
no_a = self.gizmo_dial.matrix_basis.col[1].xyz
no_b = Vector(op.plane_no)
no_a = (no_a @ self.view_inv).xy.normalized()
no_b = (no_b @ self.view_inv).xy.normalized()
return no_a.angle_signed(no_b)
def direction_set_cb(value):
op = SelectSideOfPlaneGizmoGroup.my_target_operator(context)
matrix_rotate = Matrix.Rotation(-value, 3, self.rotate_axis)
no = matrix_rotate @ self.gizmo_dial.matrix_basis.col[1].xyz
op.plane_no = no
op.execute(context)
gz = self.gizmos.new("GIZMO_GT_dial_3d")
gz.target_set_handler("offset", get=direction_get_cb, set=direction_set_cb)
gz.draw_options = {'ANGLE_START_Y'}
gz.use_draw_value = True
gz.color = 0.8, 0.8, 0.8
gz.alpha = 0.5
gz.color_highlight = 1.0, 1.0, 1.0
gz.alpha_highlight = 1.0
self.gizmo_dial = gz
def draw_prepare(self, context):
from mathutils import Vector
view_inv = self.my_view_orientation(context)
self.view_inv = view_inv
self.rotate_axis = view_inv[2].xyz
self.rotate_up = view_inv[1].xyz
op = self.my_target_operator(context)
co = Vector(op.plane_co)
no = Vector(op.plane_no).normalized()
# Move
no_z = no
no_y = no_z.orthogonal()
no_x = no_z.cross(no_y)
matrix = self.gizmo_move.matrix_basis
matrix.identity()
matrix.col[0].xyz = no_x
matrix.col[1].xyz = no_y
matrix.col[2].xyz = no_z
# The location callback handles the location.
# `matrix.col[3].xyz = co`.
# Dial
no_z = self.rotate_axis
no_y = (no - (no.project(no_z))).normalized()
no_x = self.rotate_axis.cross(no_y)
matrix = self.gizmo_dial.matrix_basis
matrix.identity()
matrix.col[0].xyz = no_x
matrix.col[1].xyz = no_y
matrix.col[2].xyz = no_z
matrix.col[3].xyz = co
classes = (
SelectSideOfPlane,
SelectSideOfPlaneGizmoGroup,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()

View File

@@ -0,0 +1,50 @@
# Example of a gizmo that activates an operator
# using the predefined dial gizmo to change the camera roll.
#
# Usage: Run this script and select a camera in the 3D view.
#
import bpy
from bpy.types import (
GizmoGroup,
)
class MyCameraWidgetGroup(GizmoGroup):
bl_idname = "OBJECT_GGT_test_camera"
bl_label = "Object Camera Test Widget"
bl_space_type = 'VIEW_3D'
bl_region_type = 'WINDOW'
bl_options = {'3D', 'PERSISTENT'}
@classmethod
def poll(cls, context):
ob = context.object
return (ob and ob.type == 'CAMERA')
def setup(self, context):
# Run an operator using the dial gizmo
ob = context.object
gz = self.gizmos.new("GIZMO_GT_dial_3d")
props = gz.target_set_operator("transform.rotate")
props.constraint_axis = False, False, True
props.orient_type = 'LOCAL'
props.release_confirm = True
gz.matrix_basis = ob.matrix_world.normalized()
gz.line_width = 3
gz.color = 0.8, 0.8, 0.8
gz.alpha = 0.5
gz.color_highlight = 1.0, 1.0, 1.0
gz.alpha_highlight = 1.0
self.roll_gizmo = gz
def refresh(self, context):
ob = context.object
gz = self.roll_gizmo
gz.matrix_basis = ob.matrix_world.normalized()
bpy.utils.register_class(MyCameraWidgetGroup)

View File

@@ -0,0 +1,59 @@
# Example of a group that lets you move an object in the 3D view
# using the default translate transform operator.
#
# Usage: Select and object and drag the Gizmo to
# move it in the 3D Viewport.
#
import bpy
from bpy.types import (
GizmoGroup,
)
class MyTranslateWidgetGroup(GizmoGroup):
bl_idname = "OBJECT_GGT_translate_test"
bl_label = "Test Translate Widget"
bl_space_type = 'VIEW_3D'
bl_region_type = 'WINDOW'
bl_options = {'PERSISTENT', 'SCALE'}
@classmethod
def poll(cls, context):
ob = context.object
return ob is not None
def draw_prepare(self, context):
region = context.region
# Place the Gizmo in the lower center of the 3D Viewport.
self.translate_gizmo.matrix_basis[0][3] = region.width / 2
self.translate_gizmo.matrix_basis[1][3] = region.height / 16
def setup(self, context):
gz = self.gizmos.new("GIZMO_GT_button_2d")
gz.target_set_operator("transform.translate")
gz.draw_options = {'BACKDROP', 'OUTLINE'}
gz.color = 0.0, 0.5, 1.0
gz.alpha = 0.2
gz.backdrop_fill_alpha = 0.1
gz.color_highlight = 1.0, 0.5, 0.0
gz.alpha_highlight = 0.8
gz.use_tooltip = True
gz.line_width = 1.5
# Same as buttons defined in C++ code.
gz.scale_basis = (80 * 0.35) / 2
# Show a dragging mouse cursor when hovering the gizmo.
gz.show_drag = True
# Can also use gz.icon_value to use a custom/generated preview icon.
gz.icon = 'EMPTY_ARROWS'
self.translate_gizmo = gz
bpy.utils.register_class(MyTranslateWidgetGroup)

View File

@@ -0,0 +1,47 @@
# Example of a group that edits a single property
# using the predefined gizmo arrow.
#
# Usage: Select a light in the 3D view and drag the arrow at its rear
# to change its energy value.
#
import bpy
from bpy.types import (
GizmoGroup,
)
class MyLightWidgetGroup(GizmoGroup):
bl_idname = "OBJECT_GGT_light_test"
bl_label = "Test Light Widget"
bl_space_type = 'VIEW_3D'
bl_region_type = 'WINDOW'
bl_options = {'3D', 'PERSISTENT'}
@classmethod
def poll(cls, context):
ob = context.object
return (ob and ob.type == 'LIGHT')
def setup(self, context):
# Arrow gizmo has one `offset` property we can assign to the light energy.
ob = context.object
gz = self.gizmos.new("GIZMO_GT_arrow_3d")
gz.target_set_prop("offset", ob.data, "energy")
gz.matrix_basis = ob.matrix_world.normalized()
gz.draw_style = 'BOX'
gz.color = 1.0, 0.5, 0.0
gz.alpha = 0.5
gz.color_highlight = 1.0, 0.5, 1.0
gz.alpha_highlight = 0.5
self.energy_gizmo = gz
def refresh(self, context):
ob = context.object
gz = self.energy_gizmo
gz.matrix_basis = ob.matrix_world.normalized()
bpy.utils.register_class(MyLightWidgetGroup)