Exemplo n.º 1
0
def _set_simple_modifier_value(scene,
                               blender_object,
                               section,
                               category,
                               value,
                               side="unsided",
                               load_target_if_needed=True):
    """This modifier is not a combination of opposing targets ("decr-incr", "in-out"...)"""
    name = category["name"]
    if side == "right":
        name = "r-" + name
    if side == "left":
        name = "l-" + name
    if not TargetService.has_target(blender_object, name):
        target_path = os.path.join(_TARGETS_DIR, section, name + ".target.gz")
        _LOG.debug("Will implicitly attempt a load of a system target",
                   target_path)
        TargetService.load_target(blender_object,
                                  target_path,
                                  weight=value,
                                  name=name)
    else:
        TargetService.set_target_value(blender_object,
                                       name,
                                       value,
                                       delete_target_on_zero=True)
Exemplo n.º 2
0
    def execute(self, context):

        blender_object = context.active_object
        TargetService.symmetrize_shape_key(blender_object, "PrimaryTarget", False)

        self.report({'INFO'}, "Target symmetrized")
        return {'FINISHED'}
Exemplo n.º 3
0
    def execute(self, context):
        blender_object = context.active_object
        info = TargetService.get_shape_key_as_dict(blender_object,
                                                   "PrimaryTarget")

        _LOG.dump("Shape key", info)

        print(TargetService.shape_key_info_as_target_string(info))

        self.report({'INFO'}, "Target printed to console")
        return {'FINISHED'}
Exemplo n.º 4
0
    def execute(self, context):
        blender_object = context.active_object
        info = TargetService.get_shape_key_as_dict(blender_object,
                                                   "PrimaryTarget")

        _LOG.dump("Shape key", info)

        with open(self.filepath, "w") as target_file:
            target_file.write(
                TargetService.shape_key_info_as_target_string(info))

        self.report({'INFO'}, "Target was saved as " + str(self.filepath))
        return {'FINISHED'}
Exemplo n.º 5
0
    def execute(self, context):
        blender_object = context.active_object
        TargetService.create_shape_key(blender_object, "PrimaryTarget")

        # This might look strange, but it is to ensure the name attribute of the object
        # is not still null if left at its default
        name = MakeTargetObjectProperties.get_value(
            "name", entity_reference=blender_object)
        MakeTargetObjectProperties.set_value("name",
                                             name,
                                             entity_reference=blender_object)

        self.report({'INFO'}, "Primary target created")
        return {'FINISHED'}
Exemplo n.º 6
0
def _get_opposed_modifier_value(scene,
                                blender_object,
                                section,
                                category,
                                side="unsided"):
    """This modifier is a combination of opposing targets ("decr-incr", "in-out"...)"""
    positive = category["opposites"]["positive-" + side]
    negative = category["opposites"]["negative-" + side]

    if TargetService.has_target(blender_object, positive):
        return TargetService.get_target_value(blender_object, positive)

    if TargetService.has_target(blender_object, negative):
        return -TargetService.get_target_value(blender_object, negative)

    return 0.0
Exemplo n.º 7
0
    def create_human(mask_helpers=True, detailed_helpers=True, extra_vertex_groups=True, feet_on_ground=True, scale=0.1, macro_detail_dict=None):
        exclude = []

        if not detailed_helpers:
            groups = ObjectService.get_base_mesh_vertex_group_definition()
            for group_name in groups.keys():
                if str(group_name).startswith("helper-") or str(group_name).startswith("joint-"):
                    exclude.append(str(group_name))

        if not extra_vertex_groups:
            # rather than extend in order to explicitly cast to str
            for group_name in BASEMESH_EXTRA_GROUPS.keys():
                exclude.append(str(group_name))
            exclude.extend(["Mid", "Right", "Left"])

        basemesh = ObjectService.load_base_mesh(context=bpy.context, scale_factor=scale, load_vertex_groups=True, exclude_vertex_groups=exclude)

        if macro_detail_dict is None:
            macro_detail_dict = TargetService.get_default_macro_info_dict()

        for key in macro_detail_dict.keys():
            name = str(key)
            if name != "race":
                HumanObjectProperties.set_value(name, macro_detail_dict[key], entity_reference=basemesh)

        for key in macro_detail_dict["race"].keys():
            name = str(key)
            HumanObjectProperties.set_value(name, macro_detail_dict["race"][key], entity_reference=basemesh)

        TargetService.reapply_macro_details(basemesh)

        if mask_helpers:
            modifier = basemesh.modifiers.new("Hide helpers", 'MASK')
            modifier.vertex_group = "body"
            modifier.show_in_editmode = True
            modifier.show_on_cage = True

        HumanObjectProperties.set_value("is_human_project", True, entity_reference=basemesh)

        if feet_on_ground:
            lowest_point = ObjectService.get_lowest_point(basemesh)
            basemesh.location = (0.0, 0.0, abs(lowest_point))
            bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)

        return basemesh
Exemplo n.º 8
0
    def build_basemesh_position_info(self, take_shape_keys_into_account=True):
        """Populate the position information hash with positions from the base mesh.
        We will here also extract and stor vertex positions and store them in the hash,
        as these positions may be influenced by shape keys."""

        self.position_info = dict()

        self.position_info["cubes"] = dict()
        cubes = self.position_info["cubes"]

        self.position_info["vertices"] = []
        vertices = self.position_info["vertices"]

        cube_groups = dict()
        group_index_to_name = dict()

        basemesh = self.basemesh

        for group in basemesh.vertex_groups:
            idx = int(group.index)
            name = str(group.name)
            if "joint" in name:
                cube_groups[name] = []
                group_index_to_name[idx] = name

        coords = basemesh.data.vertices
        shape_key = None
        key_name = None
        if take_shape_keys_into_account and basemesh.data.shape_keys and basemesh.data.shape_keys.key_blocks and len(basemesh.data.shape_keys.key_blocks) > 0:
            from mpfb.services.targetservice import TargetService
            key_name = "temporary_fit_rig_key." + str(random.randrange(1000, 9999))
            shape_key = TargetService.create_shape_key(basemesh, key_name, also_create_basis=True, create_from_mix=True)
            coords = shape_key.data

        for vertex in basemesh.data.vertices:
            vertex_coords = list(coords[vertex.index].co) # Either actual vertex or the corresponding shape key point
            vertices.append(vertex_coords)
            for group in vertex.groups:
                idx = int(group.group)
                if idx in group_index_to_name:
                    name = group_index_to_name[idx]
                    cube_groups[name].append(vertex_coords)

        if shape_key:
            basemesh.shape_key_remove(shape_key)

        _LOG.dump("cube_groups", cube_groups)

        for name in group_index_to_name.values():
            group = cube_groups[name]
            sum_pos = [0.0, 0.0, 0.0]
            for i in range(len(group)):
                for n in range(3):
                    sum_pos[n] = sum_pos[n] + group[i][n]
            for n in range(3):
                sum_pos[n] = sum_pos[n] / float(len(group))
            cubes[name] = sum_pos
Exemplo n.º 9
0
    def execute(self, context):

        blender_object = context.active_object
        target_string = Path(self.filepath).read_text()

        TargetService.target_string_to_shape_key(target_string,
                                                 "PrimaryTarget",
                                                 blender_object)

        # This might look strange, but it is to ensure the name attribute of the object
        # is not still null if left at its default
        name = MakeTargetObjectProperties.get_value(
            "name", entity_reference=blender_object)
        MakeTargetObjectProperties.set_value("name",
                                             name,
                                             entity_reference=blender_object)

        self.report({'INFO'}, "Target was imported as shape key")
        return {'FINISHED'}
Exemplo n.º 10
0
def _get_simple_modifier_value(scene,
                               blender_object,
                               section,
                               category,
                               side="unsided"):
    """This modifier is not a combination of opposing targets ("decr-incr", "in-out"...)"""
    name = category["name"]
    if side == "right":
        name = "r-" + name
    if side == "left":
        name = "l-" + name
    return TargetService.get_target_value(blender_object, name)
Exemplo n.º 11
0
 def _create_default_human_info_dict():
     human_info = dict()
     human_info["phenotype"] = TargetService.get_default_macro_info_dict()
     human_info["rig"] = ""
     human_info["eyes"] = ""
     human_info["eyebrows"] = ""
     human_info["eyelashes"] = ""
     human_info["tongue"] = ""
     human_info["teeth"] = ""
     human_info["hair"] = ""
     human_info["proxy"] = ""
     human_info["tongue"] = ""
     human_info["targets"] = []
     human_info["clothes"] = []
     human_info["skin_mhmat"] = ""
     human_info["skin_material_type"] = "NONE"
     human_info["eyes_material_type"] = "MAKESKIN"
     human_info["skin_material_settings"] = dict()
     human_info["eyes_material_settings"] = dict()
     return human_info
Exemplo n.º 12
0
 def _populate_human_info_with_basemesh_info(human_info, basemesh):
     human_info["phenotype"] = TargetService.get_macro_info_dict_from_basemesh(basemesh)
     human_info["targets"] = TargetService.get_target_stack(basemesh, exclude_starts_with="$md-")
Exemplo n.º 13
0
def _general_set_target_value(name, value):
    _LOG.trace("_general_set_target_value", (name, value))
    basemesh = bpy.context.object
    HumanObjectProperties.set_value(name, value, entity_reference=basemesh)
    TargetService.reapply_macro_details(basemesh)
Exemplo n.º 14
0
def _set_opposed_modifier_value(scene,
                                blender_object,
                                section,
                                category,
                                value,
                                side="unsided"):
    """This modifier is a combination of opposing targets ("decr-incr", "in-out"...)"""
    positive = category["opposites"]["positive-" + side]
    negative = category["opposites"]["negative-" + side]

    if value < 0.0001 and TargetService.has_target(blender_object, positive):
        TargetService.set_target_value(blender_object,
                                       positive,
                                       0.0,
                                       delete_target_on_zero=True)

    if value > -0.0001 and TargetService.has_target(blender_object, negative):
        TargetService.set_target_value(blender_object,
                                       negative,
                                       0.0,
                                       delete_target_on_zero=True)

    if value > 0.0:
        if not TargetService.has_target(blender_object, positive):
            target_path = os.path.join(_TARGETS_DIR, section,
                                       positive + ".target.gz")
            _LOG.debug("Will implicitly attempt a load of a system target",
                       target_path)
            TargetService.load_target(blender_object,
                                      target_path,
                                      weight=value,
                                      name=positive)
        else:
            TargetService.set_target_value(blender_object,
                                           positive,
                                           value,
                                           delete_target_on_zero=True)

    if value < 0.0:
        if not TargetService.has_target(blender_object, negative):
            target_path = os.path.join(_TARGETS_DIR, section,
                                       negative + ".target.gz")
            _LOG.debug("Will implicitly attempt a load of a system target",
                       target_path)
            TargetService.load_target(blender_object,
                                      target_path,
                                      weight=abs(value),
                                      name=negative)
        else:
            TargetService.set_target_value(blender_object,
                                           negative,
                                           abs(value),
                                           delete_target_on_zero=True)
Exemplo n.º 15
0
    def execute(self, context):

        from mpfb.ui.newhuman.newhumanpanel import NEW_HUMAN_PROPERTIES  # pylint: disable=C0415

        detailed_helpers = NEW_HUMAN_PROPERTIES.get_value(
            "detailed_helpers", entity_reference=context.scene)
        extra_vertex_groups = NEW_HUMAN_PROPERTIES.get_value(
            "extra_vertex_groups", entity_reference=context.scene)
        scale_factor = NEW_HUMAN_PROPERTIES.get_value(
            "scale_factor", entity_reference=context.scene)

        scale = 0.1

        if scale_factor == "DECIMETER":
            scale = 1.0

        if scale_factor == "CENTIMETER":
            scale = 10.0

        mask_helpers = NEW_HUMAN_PROPERTIES.get_value(
            "mask_helpers", entity_reference=context.scene)
        add_phenotype = NEW_HUMAN_PROPERTIES.get_value(
            "add_phenotype", entity_reference=context.scene)
        macro_details = None

        if add_phenotype:
            macro_details = TargetService.get_default_macro_info_dict()

            age = NEW_HUMAN_PROPERTIES.get_value(
                "phenotype_age", entity_reference=context.scene)
            gender = NEW_HUMAN_PROPERTIES.get_value(
                "phenotype_gender", entity_reference=context.scene)
            muscle = NEW_HUMAN_PROPERTIES.get_value(
                "phenotype_muscle", entity_reference=context.scene)
            weight = NEW_HUMAN_PROPERTIES.get_value(
                "phenotype_weight", entity_reference=context.scene)
            height = NEW_HUMAN_PROPERTIES.get_value(
                "phenotype_height", entity_reference=context.scene)
            race = NEW_HUMAN_PROPERTIES.get_value(
                "phenotype_race", entity_reference=context.scene)
            influence = NEW_HUMAN_PROPERTIES.get_value(
                "phenotype_influence", entity_reference=context.scene)
            firmness = NEW_HUMAN_PROPERTIES.get_value(
                "phenotype_breastfirmness", entity_reference=context.scene)
            cup = NEW_HUMAN_PROPERTIES.get_value(
                "phenotype_breastsize", entity_reference=context.scene)
            breast_influence = NEW_HUMAN_PROPERTIES.get_value(
                "breast_influence", entity_reference=context.scene)
            add_breast = NEW_HUMAN_PROPERTIES.get_value(
                "add_breast", entity_reference=context.scene)

            ### RACE ###

            if race == "universal":
                macro_details["race"]["african"] = 0.33
                macro_details["race"]["asian"] = 0.33
                macro_details["race"]["caucasian"] = 0.33
            else:
                macro_details["race"]["african"] = 0.0
                macro_details["race"]["asian"] = 0.0
                macro_details["race"]["caucasian"] = 0.0
                macro_details["race"][race] = 1.0

            ### GENDER ###

            if gender == "male":
                macro_details["gender"] = 0.5 + influence * 0.5

            if gender == "female":
                macro_details["gender"] = 0.5 - influence * 0.5

            ### AGE ###

            if age == "baby":
                macro_details["age"] = 0.0

            if age == "child":
                macro_details["age"] = 0.1875

            if age == "young":
                macro_details["age"] = 0.5

            if age == "old":
                macro_details["age"] = 1.0

            ### MUSCLE ###

            if muscle == "minmuscle":
                macro_details["muscle"] = 0.5 - influence * 0.5

            if muscle == "maxmuscle":
                macro_details["muscle"] = 0.5 + influence * 0.5

            ### WEIGHT ###

            if weight == "minweight":
                macro_details["weight"] = 0.5 - influence * 0.5

            if weight == "maxweight":
                macro_details["weight"] = 0.5 + influence * 0.5

            ### HEIGHT ###

            if height == "minheight":
                macro_details["height"] = 0.5 - influence * 0.5

            if height == "maxheight":
                macro_details["height"] = 0.5 + influence * 0.5

            if not add_breast:
                macro_details["cupsize"] = 0.5
                macro_details["firmness"] = 0.5
            else:
                ### CUP SIZE ###

                if cup == "mincup":
                    macro_details["cupsize"] = 0.5 - breast_influence * 0.5

                if cup == "maxcup":
                    macro_details["cupsize"] = 0.5 + breast_influence * 0.5

                ### FIRMNESS ###

                if firmness == "minfirmness":
                    macro_details["firmness"] = 0.5 - breast_influence * 0.5

                if firmness == "maxfirmness":
                    macro_details["firmness"] = 0.5 + breast_influence * 0.5

            _LOG.dump("macro_details", macro_details)
            basemesh = HumanService.create_human(
                mask_helpers=mask_helpers,
                detailed_helpers=detailed_helpers,
                extra_vertex_groups=extra_vertex_groups,
                feet_on_ground=True,
                scale=scale,
                macro_detail_dict=macro_details)
            self.report({
                'INFO'
            }, "Human created. You can adjust the phenotype values on the modeling panel."
                        )
        else:
            basemesh = HumanService.create_human(
                mask_helpers=mask_helpers,
                detailed_helpers=detailed_helpers,
                extra_vertex_groups=extra_vertex_groups,
                feet_on_ground=True,
                scale=scale)
            self.report({'INFO'}, "Human created.")

        _LOG.debug("Basemesh", basemesh)

        bpy.ops.object.select_all(action='DESELECT')
        bpy.context.view_layer.objects.active = basemesh
        basemesh.select_set(True)

        return {'FINISHED'}