Merge branch 'master' into xr-controller-support

This commit is contained in:
Peter Kim 2021-08-20 20:48:39 +09:00
commit f51fa40f11
9 changed files with 142 additions and 89 deletions

View File

@ -2,8 +2,8 @@
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# of the License.
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of

View File

@ -21,8 +21,8 @@
bl_info = {
"name": "Snap_Utilities_Line",
"author": "Germano Cavalcante",
"version": (6, 9, 23),
"blender": (2, 93, 0),
"version": (6, 9, 3),
"blender": (3, 0, 0),
"location": "View3D > TOOLS > Line Tool",
"description": "Extends Blender Snap controls",
"doc_url" : "https://blenderartists.org/t/cad-snap-utilities",

View File

@ -211,12 +211,13 @@ class GPU_Indices_Mesh():
atexit.unregister(cls.end_opengl)
atexit.register(cls.end_opengl)
cls.shader = gpu.types.GPUShader(load_shader("ID_color_vert.glsl"),
load_shader("ID_color_frag.glsl"),)
#cls.unif_use_clip_planes =
#cls.shader.uniform_from_name('use_clip_planes')
#cls.unif_clip_plane = cls.shader.uniform_from_name('clip_plane')
cls.shader = gpu.types.GPUShader(
load_shader("ID_color_vert.glsl"),
load_shader("ID_color_frag.glsl"),
defines="#define USE_CLIP_PLANES\n")
cls.unif_offset = cls.shader.uniform_from_name('offset')
cls.use_clip_planes = False
def __init__(self, depsgraph, obj, draw_tris, draw_edges, draw_verts):
@ -332,8 +333,12 @@ class GPU_Indices_Mesh():
gpu.matrix.push()
gpu.matrix.push_projection()
gpu.matrix.multiply_matrix(ob_mat)
self.shader.bind()
if GPU_Indices_Mesh.use_clip_planes:
self.shader.uniform_float("ModelMatrix", ob_mat)
if self.draw_tris:
self.shader.bind()
self.shader.uniform_int("offset", (index_offset,))
self.batch_tris.draw(self.shader)
index_offset += len(self.tri_verts)
@ -359,7 +364,6 @@ class GPU_Indices_Mesh():
gpu.matrix.load_projection_matrix(winmat)
if self.draw_edges:
self.shader.bind()
self.shader.uniform_int("offset", (index_offset,))
#bgl.glLineWidth(3.0)
self.batch_edges.draw(self.shader)
@ -367,7 +371,6 @@ class GPU_Indices_Mesh():
index_offset += len(self.edge_verts)
if self.draw_verts:
self.shader.bind()
self.shader.uniform_int("offset", (index_offset,))
self.batch_lverts.draw(self.shader)
@ -427,17 +430,17 @@ def gpu_Indices_restore_state():
def gpu_Indices_use_clip_planes(rv3d, value):
pass #TODO
#if rv3d.use_clip_planes:
#planes = bgl.Buffer(bgl.GL_FLOAT, (6, 4), rv3d.clip_planes)
GPU_Indices_Mesh.init_opengl()
shader = GPU_Indices_Mesh.shader
shader.bind()
if value and rv3d.use_clip_planes:
GPU_Indices_Mesh.use_clip_planes = True
planes = gpu.types.Buffer('FLOAT', (6, 4), rv3d.clip_planes)
shader.uniform_vector_float(shader.uniform_from_name("clip_plane"), planes, 4, 4)
else:
GPU_Indices_Mesh.use_clip_planes = False
#_store_current_shader_state(PreviousGLState)
#GPU_Indices_Mesh.init_opengl()
#bgl.glUseProgram(GPU_Indices_Mesh.shader.program)
#bgl.glUniform1i(GPU_Indices_Mesh.unif_use_clip_planes, value)
shader.uniform_bool("use_clip_planes", (GPU_Indices_Mesh.use_clip_planes,))
#bgl.glUniform4fv(GPU_Indices_Mesh.unif_clip_plane, 4, planes)
#_restore_shader_state(PreviousGLState)
def gpu_Indices_mesh_cache_clear():
GPU_Indices_Mesh._Hash.clear()

View File

@ -1,7 +1,7 @@
uniform mat4 ModelViewProjectionMatrix;
#ifdef USE_CLIP_PLANES
uniform mat4 ModelViewMatrix;
uniform mat4 ModelMatrix;
uniform bool use_clip_planes;
uniform vec4 clip_plane[4];
out vec4 clip_distance;
@ -13,7 +13,7 @@ void main()
{
#ifdef USE_CLIP_PLANES
if (use_clip_planes) {
vec4 g_pos = ModelViewMatrix * vec4(pos, 1.0);
vec4 g_pos = ModelMatrix * vec4(pos, 1.0);
for (int i = 0; i != 4; i++) {
clip_distance[i] = dot(clip_plane[i], g_pos);

View File

@ -32,7 +32,7 @@ from ...utils.rig import get_parent_rigs
from ...utils.node_merger import MainMergeNode, QueryMergeNode
from .skin_parents import ControlBoneParentLayer, ControlBoneWeakParentLayer
from .skin_parents import ControlBoneParentLayer, ControlBoneWeakParentLayer, ControlBoneParentMix
from .skin_rigs import BaseSkinRig, BaseSkinChainRig
@ -253,6 +253,8 @@ class ControlBoneNode(MainMergeNode, BaseSkinNode):
if isinstance(parent, ControlBoneParentLayer):
parent.parent = self.intern_parent(node, parent.parent)
elif isinstance(parent, ControlBoneParentMix):
parent.parents = [self.intern_parent(node, p) for p in parent.parents]
return parent
@ -267,11 +269,9 @@ class ControlBoneNode(MainMergeNode, BaseSkinNode):
if parent not in requests:
# If the actual reparent would be generated, weak parent will be needed.
if self.has_weak_parent and not self.use_weak_parent:
if self.use_mix_parent or parent != self.node_parent:
if parent is not self.node_parent:
self.use_weak_parent = True
for weak_parent in self.node_parent_list_weak:
self.register_use_parent(weak_parent)
self.register_use_parent(self.node_parent_weak)
self.register_use_parent(parent)
requests.append(parent)
@ -308,24 +308,34 @@ class ControlBoneNode(MainMergeNode, BaseSkinNode):
self.matrix.translation = self.point
# Create parents and decide if mix would be needed
parent_list = [node.build_parent(use=False) for node in mirror_sibling_list]
weak_parent_list = [node.build_parent(use=False) for node in mirror_sibling_list]
if all(parent == self.node_parent for parent in parent_list):
self.use_mix_parent = False
parent_list = [self.node_parent]
if all(parent == self.node_parent for parent in weak_parent_list):
weak_parent_list = [self.node_parent]
self.node_parent_weak = self.node_parent
else:
self.use_mix_parent = True
self.node_parent_weak = ControlBoneParentMix(self.rig, self, weak_parent_list)
# Prepare parenting without weak layers
parent_list = [ControlBoneWeakParentLayer.strip(p) for p in weak_parent_list]
self.use_weak_parent = False
self.node_parent_list_weak = parent_list
self.node_parent_list = [ControlBoneWeakParentLayer.strip(p) for p in parent_list]
self.has_weak_parent = any((p is not pw)
for p, pw in zip(self.node_parent_list, parent_list))
for p, pw in zip(weak_parent_list, parent_list))
for parent in self.node_parent_list:
self.register_use_parent(parent)
if not self.has_weak_parent:
self.node_parent = self.node_parent_weak
elif len(parent_list) > 1:
self.node_parent = ControlBoneParentMix(
self.rig, self, parent_list, suffix='_mix_base')
else:
self.node_parent = parent_list[0]
# Mirror siblings share the mixed parent for reparent
self.register_use_parent(self.node_parent)
for node in mirror_sibling_list:
node.node_parent = self.node_parent
# All nodes
if self.node_needs_parent or self.node_needs_reparent:
@ -392,16 +402,8 @@ class ControlBoneNode(MainMergeNode, BaseSkinNode):
self.weak_parent_bone = self.make_bone(
make_derived_name(self._control_bone, 'mch', '_weak_parent'), 1/2)
# Make mix parent if needed
self.reparent_bones = {}
if self.use_mix_parent:
self.mix_parent_bone = self.make_bone(
make_derived_name(self._control_bone, 'mch', '_mix_parent'), 1/2)
else:
self.reparent_bones[id(self.node_parent)] = self._control_bone
# Make requested reparents
self.reparent_bones = {id(self.node_parent): self._control_bone}
self.reparent_bones_fake = set(self.reparent_bones.values())
for parent in self.reparent_requests:
@ -421,21 +423,12 @@ class ControlBoneNode(MainMergeNode, BaseSkinNode):
def parent_bones(self):
if self.is_master_node:
if self.use_mix_parent:
self.set_bone_parent(self._control_bone, self.mix_parent_bone,
inherit_scale='AVERAGE')
self.rig.generator.disable_auto_parent(self.mix_parent_bone)
else:
self.set_bone_parent(self._control_bone, self.node_parent_list[0].output_bone,
inherit_scale='AVERAGE')
self.set_bone_parent(
self._control_bone, self.node_parent.output_bone, inherit_scale='AVERAGE')
if self.use_weak_parent:
if self.use_mix_parent:
self.rig.generator.disable_auto_parent(self.weak_parent_bone)
else:
parent = self.node_parent_list_weak[0]
self.set_bone_parent(self.weak_parent_bone, parent.output_bone,
inherit_scale=parent.inherit_scale_mode)
self.set_bone_parent(
self.weak_parent_bone, self.node_parent_weak.output_bone, inherit_scale='FULL')
for parent in self.reparent_requests:
bone = self.reparent_bones[id(parent)]
@ -454,12 +447,6 @@ class ControlBoneNode(MainMergeNode, BaseSkinNode):
def rig_bones(self):
if self.is_master_node:
# Rig the mixed parent
if self.use_mix_parent:
targets = [parent.output_bone for parent in self.node_parent_list]
self.make_constraint(self.mix_parent_bone, 'ARMATURE',
targets=targets, use_deform_preserve_volume=True)
# Invoke parent rig callbacks
for rig in reversed(self.rig.get_all_parent_skin_rigs()):
rig.extend_control_node_rig(self)
@ -473,11 +460,6 @@ class ControlBoneNode(MainMergeNode, BaseSkinNode):
self.make_constraint(reparent_source, 'COPY_TRANSFORMS',
self.control_bone, space='LOCAL')
if self.use_mix_parent:
targets = [parent.output_bone for parent in self.node_parent_list_weak]
self.make_constraint(self.weak_parent_bone, 'ARMATURE',
targets=targets, use_deform_preserve_volume=True)
set_bone_widget_transform(self.obj, self.control_bone, reparent_source)
for parent in self.reparent_requests:

View File

@ -145,6 +145,66 @@ class ControlBoneParentArmature(ControlBoneParentBase):
self.make_constraint(self.output_bone, 'COPY_SCALE', self.copy_scale)
class ControlBoneParentMix(ControlBoneParentBase):
"""Combine multiple parent mechanisms using the Armature constraint."""
def __init__(self, rig, node, parents, *, suffix=None):
super().__init__(rig, node)
self.parents = []
self.parent_weights = []
self.suffix = suffix
self.add_parents(parents)
def add_parents(self, parents):
for item in parents:
if isinstance(item, tuple):
parent, weight = item
else:
parent, weight = item, 1
for i, cur in enumerate(self.parents):
if parent == cur:
self.parent_weights[i] += weight
break
else:
self.parents.append(parent)
self.parent_weights.append(weight)
def enable_component(self):
for parent in self.parents:
parent.enable_component()
super().enable_component()
def __eq__(self, other):
return (
isinstance(other, ControlBoneParentMix) and
self.parents == other.parents and
self.parent_weights == other.parent_weights
)
def generate_bones(self):
self.output_bone = self.node.make_bone(
make_derived_name(self.node.name, 'mch', self.suffix or '_mix'), 1/2, rig=self.rig)
self.rig.generator.disable_auto_parent(self.output_bone)
def parent_bones(self):
if len(self.parents) == 1:
self.set_bone_parent(self.output_bone, target)
def rig_bones(self):
if len(self.parents) > 1:
targets = [(p.output_bone, w) for p, w in zip(self.parents, self.parent_weights)]
self.make_constraint(
self.output_bone, 'ARMATURE', targets=targets,
use_deform_preserve_volume=True
)
class ControlBoneParentLayer(ControlBoneParentBase):
"""Base class for parent generators that build on top of another mechanism."""
@ -164,9 +224,6 @@ class ControlBoneWeakParentLayer(ControlBoneParentLayer):
that have controls merged into this one.
"""
# Inherit mode used to parent the pseudo-control to the output of this generator.
inherit_scale_mode = 'AVERAGE'
@staticmethod
def strip(parent):
while isinstance(parent, ControlBoneWeakParentLayer):

View File

@ -394,7 +394,6 @@ class ControlBoneChainPropagate(ControlBoneWeakParentLayer):
Parent mechanism generator that propagates chain twist/scale
to the reparent system, if Propagate To Controls is used.
"""
inherit_scale_mode = 'FULL'
def __eq__(self, other):
return (

View File

@ -21,7 +21,7 @@
bl_info = {
"name": "Manage UI translations",
"author": "Bastien Montagne",
"version": (1, 3, 1),
"version": (1, 3, 2),
"blender": (2, 92, 0),
"location": "Main \"File\" menu, text editor, any UI control",
"description": "Allows managing UI translations directly from Blender "

View File

@ -159,11 +159,14 @@ class UI_PT_i18n_update_translations_settings(Panel):
i18n_sett = context.window_manager.i18n_update_svn_settings
if not i18n_sett.is_init and bpy.ops.ui.i18n_updatetranslation_svn_init_settings.poll():
bpy.ops.ui.i18n_updatetranslation_svn_init_settings()
# Cannot call the operator from here, this code might run while `pyrna_write_check()` returns False
# (which prevents any operator call from Python), during initalization of Blender.
UI_OT_i18n_updatetranslation_svn_init_settings.execute_static(context, settings.settings)
if not i18n_sett.is_init:
layout.label(text="Could not init languages data!")
layout.label(text="Please edit the preferences of the UI Translate add-on")
layout.operator("ui.i18n_updatetranslation_svn_init_settings", text="Init Settings")
else:
split = layout.split(factor=0.75)
split.template_list("UI_UL_i18n_languages", "", i18n_sett, "langs", i18n_sett, "active_lang", rows=8)
@ -220,20 +223,20 @@ class UI_OT_i18n_updatetranslation_svn_init_settings(Operator):
def poll(cls, context):
return context.window_manager is not None
def execute(self, context):
if not hasattr(self, "settings"):
self.settings = settings.settings
@staticmethod
def execute_static(context, self_settings):
i18n_sett = context.window_manager.i18n_update_svn_settings
# First, create the list of languages from settings.
i18n_sett.langs.clear()
root_br = self.settings.BRANCHES_DIR
root_tr_po = self.settings.TRUNK_PO_DIR
root_git_po = self.settings.GIT_I18N_PO_DIR
root_tr_mo = os.path.join(self.settings.TRUNK_DIR, self.settings.MO_PATH_TEMPLATE, self.settings.MO_FILE_NAME)
root_br = self_settings.BRANCHES_DIR
root_tr_po = self_settings.TRUNK_PO_DIR
root_git_po = self_settings.GIT_I18N_PO_DIR
root_tr_mo = os.path.join(self_settings.TRUNK_DIR, self_settings.MO_PATH_TEMPLATE, self_settings.MO_FILE_NAME)
if not (os.path.isdir(root_br) and os.path.isdir(root_tr_po)):
return {'CANCELLED'}
for can_use, uid, num_id, name, isocode, po_path_branch in utils_i18n.list_po_dir(root_br, self.settings):
i18n_sett.is_init = False
return;
for can_use, uid, num_id, name, isocode, po_path_branch in utils_i18n.list_po_dir(root_br, self_settings):
lng = i18n_sett.langs.add()
lng.use = can_use
lng.uid = uid
@ -245,8 +248,17 @@ class UI_OT_i18n_updatetranslation_svn_init_settings(Operator):
lng.mo_path_trunk = root_tr_mo.format(isocode)
lng.po_path_git = os.path.join(root_git_po, isocode + ".po")
i18n_sett.pot_path = self.settings.FILE_NAME_POT
i18n_sett.pot_path = self_settings.FILE_NAME_POT
i18n_sett.is_init = True
def execute(self, context):
if not hasattr(self, "settings"):
self.settings = settings.settings
self.execute_static(context, self.settings)
if context.window_manager.i18n_update_svn_settings.is_init is False:
return {'CANCELLED'}
return {'FINISHED'}