Ejemplo n.º 1
0
        def execute(self, context):
            material = context.active_object.active_material

            if material and hasattr(material.scs_props, self.property_str):

                scs_root = _object_utils.get_scs_root(context.active_object)

                if scs_root:
                    altered_looks = _looks.write_through(scs_root, material, self.property_str)
                    if altered_looks > 0:
                        message = "Write through successfully altered %s looks!" % altered_looks
                    else:
                        message = "Nothing to write through."

                    self.report({'INFO'}, message)

            return {'FINISHED'}
Ejemplo n.º 2
0
        def execute(self, context):
            material = context.active_object.active_material

            if material and hasattr(material.scs_props, self.property_str):

                scs_root = _object_utils.get_scs_root(context.active_object)

                if scs_root:
                    altered_looks = _looks.write_through(
                        scs_root, material, self.property_str)
                    if altered_looks > 0:
                        message = "Write through successfully altered %s looks!" % altered_looks
                    else:
                        message = "Nothing to write through."

                    self.report({'INFO'}, message)

            return {'FINISHED'}
Ejemplo n.º 3
0
def post_load(scene):
    # get Blender Tools version from last blend file load
    last_load_bt_ver = _get_scs_globals().last_load_bt_version

    scs_roots = None
    """
    Applies fixes for v0.6 or less:
    1. fixes reflection textures tga's for tobjs as TOBJ load is now supported and unlock that textures
    2. calls update on all set textures to correct paths for them
    3. tries to fix active shader preset name for materials, because of new flavor system
    """
    if _info_utils.cmp_ver_str(last_load_bt_ver, "0.6") <= 0:

        print("INFO\t-  Applying fixes for version <= 0.6")

        for material in bpy.data.materials:

            # ignore materials not related to blender tools
            if material.scs_props.mat_effect_name == "":
                continue

            for tex_type in material.scs_props.get_texture_types().keys():

                texture_attr_str = "shader_texture_" + tex_type
                if texture_attr_str in material.scs_props.keys():

                    # 1. fix reflection textures
                    if tex_type == "reflection":

                        is_building_ref = material.scs_props[
                            texture_attr_str].endswith("/bulding_ref.tga")
                        is_generic_s = material.scs_props[
                            texture_attr_str].endswith(
                                "material/environment/generic_s.tga")
                        is_glass_interior = material.scs_props.active_shader_preset_name == "glass - interior"
                        is_dif_spec_weight_add_env = material.scs_props.active_shader_preset_name == "dif.spec.weight.add.env"
                        is_truckpaint = material.scs_props.active_shader_preset_name.startswith(
                            "truckpaint")

                        # fix paths
                        if is_building_ref:
                            material.scs_props[
                                texture_attr_str] = material.scs_props[
                                    texture_attr_str][:-4]
                            material.scs_props[texture_attr_str +
                                               "_locked"] = False
                        elif is_generic_s:
                            if is_glass_interior:
                                material.scs_props[
                                    texture_attr_str] = "//material/environment/interior_reflection"
                            elif is_dif_spec_weight_add_env:
                                material.scs_props[
                                    texture_attr_str] = "//material/environment/generic_reflection"
                            else:
                                material.scs_props[
                                    texture_attr_str] = "//material/environment/vehicle_reflection"

                            # unlock reflection textures everywhere except on truckpaint shader
                            if not is_truckpaint:
                                material.scs_props[texture_attr_str +
                                                   "_locked"] = False

                        # acquire roots on demand only once
                        scs_roots = _object_utils.gather_scs_roots(
                            bpy.data.objects) if not scs_roots else scs_roots

                        # propagate reflection texture change on all of the looks.
                        # NOTE: We can afford write through because old BT had all reflection textures locked
                        # meaning user had to use same texture on all looks
                        # NOTE#2: Printouts like:
                        # "Look with ID: X doesn't have entry for material 'X' in SCS Root 'X',
                        #  property 'shader_texture_reflection' won't be updated!"
                        # are expected here, because we don't use any safety check,
                        # if material is used on the mesh objects inside scs root
                        for scs_root in scs_roots:
                            _looks.write_through(scs_root, material,
                                                 texture_attr_str)

                    # 2. trigger update function for path reload and reload of possible missing textures
                    update_func = getattr(material.scs_props,
                                          "update_" + texture_attr_str, None)
                    if update_func:
                        update_func(material)

            # ignore already properly set materials
            if material.scs_props.active_shader_preset_name in _get_shader_presets_inventory(
            ):
                continue

            # 3. try to recover "active_shader_preset_name" from none flavor times Blender Tools
            material_textures = {}
            if "scs_shader_attributes" in material and "textures" in material[
                    "scs_shader_attributes"]:
                for texture in material["scs_shader_attributes"][
                        "textures"].values():
                    tex_id = texture["Tag"].split(":")[1]
                    tex_value = texture["Value"]
                    material_textures[tex_id] = tex_value

            (preset_name, preset_section) = _material_utils.find_preset(
                material.scs_props.mat_effect_name, material_textures)
            if preset_name:
                material.scs_props.active_shader_preset_name = preset_name

                # acquire roots on demand only once
                scs_roots = _object_utils.gather_scs_roots(
                    bpy.data.objects) if not scs_roots else scs_roots

                # make sure to fix active preset shader name in all looks
                # NOTE: Printouts like:
                # "Look with ID: X doesn't have entry for material 'X' in SCS Root 'X',
                #  property 'active_shader_preset_name' won't be updated!"
                # are expected here, because we don't use any safety check,
                # if material is used on the mesh objects inside scs root
                for scs_root in scs_roots:
                    _looks.write_through(scs_root, material,
                                         "active_shader_preset_name")

    # as last update "last load" Blender Tools version to current
    _get_scs_globals().last_load_bt_version = get_tools_version()
Ejemplo n.º 4
0
        def execute(self, context):
            material = context.active_object.active_material

            if not material or not hasattr(material.scs_props,
                                           self.property_str):
                return {'CANCELLED'}

            scs_roots = []
            active_scs_root = _object_utils.get_scs_root(context.active_object)
            if active_scs_root:
                scs_roots.append(active_scs_root)

            if self.is_ctrl:
                scs_roots = _object_utils.gather_scs_roots(bpy.data.objects)

            if self.is_shift or not self.is_ctrl:  # WT either on active only or all SCS roots; (Shift + Ctrl) or none

                altered_looks = 0
                for scs_root in scs_roots:
                    altered_looks += _looks.write_through(
                        scs_root, material, self.property_str)

                if altered_looks > 0:
                    message = "Write through successfully altered %s looks on %s SCS Root Objects!" % (
                        altered_looks, len(scs_roots))
                else:
                    message = "Nothing to write through."

                self.report({'INFO'}, message)

            elif self.is_ctrl:  # special WT only into the same look of other SCS Roots

                # get current look id
                look_i = active_scs_root.scs_props.active_scs_look
                look_name = active_scs_root.scs_object_look_inventory[
                    look_i].name if look_i >= 0 else None

                if look_name is None:
                    self.report({
                        'WARNING'
                    }, "Aborting as current object is not in any SCS Game Object, parent it to SCS Root first!"
                                )
                    return {'CANCELLED'}

                altered_looks = 0
                for scs_root in scs_roots:

                    # ignore active root
                    if scs_root == active_scs_root:
                        continue

                    look_id = -1

                    # search for same look by name on other scs root
                    for look in scs_root.scs_object_look_inventory:
                        if look.name == look_name:
                            look_id = look.id
                            break

                    if _looks.write_prop_to_look(scs_root, look_id, material,
                                                 self.property_str):
                        altered_looks += 1

                if len(scs_roots) - 1 != altered_looks:
                    self.report({
                        'WARNING'
                    }, "WT partially done, same look was found on %s/%s other SCS Root Objects!"
                                % (altered_looks, len(scs_roots) - 1))
                else:
                    self.report({
                        'INFO'
                    }, "Write through altered property on %s other SCS Root Objects!"
                                % altered_looks)

            return {'FINISHED'}
Ejemplo n.º 5
0
def post_load(scene):
    # get Blender Tools version from last blend file load
    last_load_bt_ver = _get_scs_globals().last_load_bt_version

    scs_roots = None

    """
    Applies fixes for v0.6 or less:
    1. fixes reflection textures tga's for tobjs as TOBJ load is now supported and unlock that textures
    2. calls update on all set textures to correct paths for them
    3. tries to fix active shader preset name for materials, because of new flavor system
    """
    if _info_utils.cmp_ver_str(last_load_bt_ver, "0.6") <= 0:

        print("INFO\t-  Applying fixes for version <= 0.6")

        for material in bpy.data.materials:

            # ignore materials not related to blender tools
            if material.scs_props.mat_effect_name == "":
                continue

            for tex_type in material.scs_props.get_texture_types().keys():

                texture_attr_str = "shader_texture_" + tex_type
                if texture_attr_str in material.scs_props.keys():

                    # 1. fix reflection textures
                    if tex_type == "reflection":

                        is_building_ref = material.scs_props[texture_attr_str].endswith("/bulding_ref.tga")
                        is_generic_s = material.scs_props[texture_attr_str].endswith("material/environment/generic_s.tga")
                        is_glass_interior = material.scs_props.active_shader_preset_name == "glass - interior"
                        is_dif_spec_weight_add_env = material.scs_props.active_shader_preset_name == "dif.spec.weight.add.env"
                        is_truckpaint = material.scs_props.active_shader_preset_name.startswith("truckpaint")

                        # fix paths
                        if is_building_ref:
                            material.scs_props[texture_attr_str] = material.scs_props[texture_attr_str][:-4]
                            material.scs_props[texture_attr_str + "_locked"] = False
                        elif is_generic_s:
                            if is_glass_interior:
                                material.scs_props[texture_attr_str] = "//material/environment/interior_reflection"
                            elif is_dif_spec_weight_add_env:
                                material.scs_props[texture_attr_str] = "//material/environment/generic_reflection"
                            else:
                                material.scs_props[texture_attr_str] = "//material/environment/vehicle_reflection"

                            # unlock reflection textures everywhere except on truckpaint shader
                            if not is_truckpaint:
                                material.scs_props[texture_attr_str + "_locked"] = False

                        # acquire roots on demand only once
                        scs_roots = _object_utils.gather_scs_roots(bpy.data.objects) if not scs_roots else scs_roots

                        # propagate reflection texture change on all of the looks.
                        # NOTE: We can afford write through because old BT had all reflection textures locked
                        # meaning user had to use same texture on all looks
                        # NOTE#2: Printouts like:
                        # "Look with ID: X doesn't have entry for material 'X' in SCS Root 'X',
                        #  property 'shader_texture_reflection' won't be updated!"
                        # are expected here, because we don't use any safety check,
                        # if material is used on the mesh objects inside scs root
                        for scs_root in scs_roots:
                            _looks.write_through(scs_root, material, texture_attr_str)

                    # 2. trigger update function for path reload and reload of possible missing textures
                    update_func = getattr(material.scs_props, "update_" + texture_attr_str, None)
                    if update_func:
                        update_func(material)

            # ignore already properly set materials
            if material.scs_props.active_shader_preset_name in _get_shader_presets_inventory():
                continue

            # 3. try to recover "active_shader_preset_name" from none flavor times Blender Tools
            material_textures = {}
            if "scs_shader_attributes" in material and "textures" in material["scs_shader_attributes"]:
                for texture in material["scs_shader_attributes"]["textures"].values():
                    tex_id = texture["Tag"].split(":")[1]
                    tex_value = texture["Value"]
                    material_textures[tex_id] = tex_value

            (preset_name, preset_section) = _material_utils.find_preset(material.scs_props.mat_effect_name, material_textures)
            if preset_name:
                material.scs_props.active_shader_preset_name = preset_name

                # acquire roots on demand only once
                scs_roots = _object_utils.gather_scs_roots(bpy.data.objects) if not scs_roots else scs_roots

                # make sure to fix active preset shader name in all looks
                # NOTE: Printouts like:
                # "Look with ID: X doesn't have entry for material 'X' in SCS Root 'X',
                #  property 'active_shader_preset_name' won't be updated!"
                # are expected here, because we don't use any safety check,
                # if material is used on the mesh objects inside scs root
                for scs_root in scs_roots:
                    _looks.write_through(scs_root, material, "active_shader_preset_name")

    # as last update "last load" Blender Tools version to current
    _get_scs_globals().last_load_bt_version = get_tools_version()
Ejemplo n.º 6
0
        def execute(self, context):
            material = context.active_object.active_material

            if not material or not hasattr(material.scs_props, self.property_str):
                return {'CANCELLED'}

            scs_roots = []
            active_scs_root = _object_utils.get_scs_root(context.active_object)
            if active_scs_root:
                scs_roots.append(active_scs_root)

            if self.is_ctrl:
                scs_roots = _object_utils.gather_scs_roots(bpy.data.objects)

            if self.is_shift or not self.is_ctrl:  # WT either on active only or all SCS roots; (Shift + Ctrl) or none

                altered_looks = 0
                for scs_root in scs_roots:
                    altered_looks += _looks.write_through(scs_root, material, self.property_str)

                if altered_looks > 0:
                    message = "Write through successfully altered %s looks on %s SCS Root Objects!" % (altered_looks, len(scs_roots))
                else:
                    message = "Nothing to write through."

                self.report({'INFO'}, message)

            elif self.is_ctrl:  # special WT only into the same look of other SCS Roots

                # get current look id
                look_i = active_scs_root.scs_props.active_scs_look
                look_name = active_scs_root.scs_object_look_inventory[look_i].name if look_i >= 0 else None

                if look_name is None:
                    self.report({'WARNING'}, "Aborting as current object is not in any SCS Game Object, parent it to SCS Root first!")
                    return {'CANCELLED'}

                altered_looks = 0
                for scs_root in scs_roots:

                    # ignore active root
                    if scs_root == active_scs_root:
                        continue

                    look_id = -1

                    # search for same look by name on other scs root
                    for look in scs_root.scs_object_look_inventory:
                        if look.name == look_name:
                            look_id = look.id
                            break

                    if _looks.write_prop_to_look(scs_root, look_id, material, self.property_str):
                        altered_looks += 1

                if len(scs_roots) - 1 != altered_looks:
                    self.report({'WARNING'}, "WT partially done, same look was found on %s/%s other SCS Root Objects!" %
                                (altered_looks, len(scs_roots) - 1))
                else:
                    self.report({'INFO'}, "Write through altered property on %s other SCS Root Objects!" % altered_looks)

            return {'FINISHED'}