コード例 #1
0
def createCustomProperty(context,
                         ob,
                         name,
                         default_value,
                         description,
                         soft_max=1.0,
                         soft_min=0.0):
    # refer: bpy.ops.wm.properties_add(data_path="object")
    from rna_prop_ui import rna_idprop_ui_create

    o = context.active_object
    context.view_layer.objects.active = ob

    data_path = "object"
    item = eval("context.%s" % data_path)

    rna_idprop_ui_create(
        item,
        name,
        default=default_value,
        description=description,
        soft_min=soft_max,
        soft_max=soft_min,
    )

    # reset
    context.view_layer.objects.active = o
コード例 #2
0
def make_property(owner,
                  name,
                  default,
                  *,
                  min=0.0,
                  max=1.0,
                  soft_min=None,
                  soft_max=None,
                  description=None,
                  overridable=True,
                  **options):
    """
    Creates and initializes a custom property of owner.

    The soft_min and soft_max parameters default to min and max.
    Description defaults to the property name.
    """

    # Some keyword argument defaults differ
    rna_idprop_ui_create(owner,
                         name,
                         default=default,
                         min=min,
                         max=max,
                         soft_min=soft_min,
                         soft_max=soft_max,
                         description=description or name,
                         overridable=overridable,
                         **options)
コード例 #3
0
def sliding_joint_finalize(rig, upper_bone, lower_bone, side, influence):
    bones = rig.pose.bones

    mch_name = "MCH-{}.{}".format(lower_bone, side)
    tweak_name = "{}_tweak.{}".format(lower_bone, side)
    old_tweak = "{}_tweak.{}.002".format(upper_bone, side)

    obone = bones[old_tweak]
    bone = bones[tweak_name]
    bone.custom_shape = obone.custom_shape
    bone.bone_group = obone.bone_group
    bone.lock_rotation = (True, False, True)
    bone.lock_scale = (False, True, False)

    # Make rubber tweak property, but lock it to zero
    rna_idprop_ui_create(bone, "rubber_tweak", default=0, min=0, max=0)

    utils.lock_obj(bones[mch_name], True)

    c = bones[mch_name].constraints.new("COPY_ROTATION")
    c.target = rig
    c.subtarget = "ORG-{}.{}".format(lower_bone, side)
    c.use_y = False
    c.use_z = False
    c.influence = influence
    c.owner_space = "LOCAL"
    c.target_space = "LOCAL"

    c = bones["MCH-{}_tweak.{}".format(lower_bone,
                                       side)].constraints.new("COPY_SCALE")
    c.target = rig
    c.subtarget = "root"
    c.use_make_uniform = True

    def replace_tweak(bone):
        for c in bone.constraints:
            if c.type == "COPY_TRANSFORMS" and c.target == rig and c.subtarget == old_tweak:
                c.subtarget = tweak_name

    replace_tweak(bones["DEF-{}.{}".format(lower_bone, side)])
    replace_tweak(bones["MCH-{}.001".format(tweak_name)])
コード例 #4
0
 def make_real(self, owner):
     """Apply this custom property to a real Blender ID, such as an object or a bone."""
     return rna_idprop_ui_create(owner,
                                 self.name,
                                 default=self.default,
                                 min=self.min,
                                 max=self.max,
                                 soft_min=self.soft_min,
                                 soft_max=self.soft_max,
                                 description=self.description,
                                 overridable=self.overridable,
                                 subtype=self.subtype)
コード例 #5
0
 def add_prop(pose_bone: bpy.types.PoseBone,
              prop_name: str,
              default=0.000,
              min=0.000,
              max=1.000,
              soft_min=None,
              soft_max=None,
              description=None,
              overridable=True,
              subtype=None):
     # pylint: disable=redefined-builtin,too-many-arguments
     rna_prop_ui.rna_idprop_ui_create(pose_bone,
                                      prop_name,
                                      default=default,
                                      min=min,
                                      max=max,
                                      soft_min=soft_min,
                                      soft_max=soft_max,
                                      description=description,
                                      overridable=overridable,
                                      subtype=subtype)
コード例 #6
0
def createParticleProperty(context,
                           particle,
                           sa_strength,
                           pr_strength,
                           plant_type,
                           anchor,
                           parent=None):
    context.view_layer.objects.active = particle
    # refer: bpy.ops.wm.properties_add(data_path="object")
    from rna_prop_ui import rna_idprop_ui_create

    data_path = "object"
    item = eval("context.%s" % data_path)

    rna_idprop_ui_create(
        item,
        "SA",
        default=sa_strength,
        description=SurfaceAdaptionStrength[1]['description'],
        soft_min=SurfaceAdaptionStrength[1]['soft_min'],
        soft_max=SurfaceAdaptionStrength[1]['soft_max'],
    )
    rna_idprop_ui_create(
        item,
        "PR",
        default=pr_strength,
        description=PhototropismResponseStrength[1]['description'],
        soft_min=PhototropismResponseStrength[1]['soft_min'],
        soft_max=PhototropismResponseStrength[1]['soft_max'],
    )
    # rna_idprop_ui_create(
    #     item, "Size",
    #     default     =particle.dimensions,
    #     description =ParticleSize[1]['description'])
    # rna_idprop_ui_create(
    #     item, "Depth",
    #     default     =depth,
    #     description =plant_depth[1]['description'],
    #     soft_min    =plant_depth[1]['soft_min'],
    #     soft_max    =plant_depth[1]['soft_max'], )
    rna_idprop_ui_create(item, "Type", default=plant_type)
    rna_idprop_ui_create(item,
                         "Anchor",
                         default=anchor,
                         description=ParticleAnchor[1]['description'])
    rna_idprop_ui_create(item, "Childs", default=[])
    rna_idprop_ui_create(item, "Parent", default=[])

    if (parent):
        particle['Parent'] = parent
        if (parent['Childs']):
            parent['Childs'] += [particle]
        else:
            parent['Childs'] = [particle]