Exemplo n.º 1
0
    def set_locators_coll_draw_size(obj):
        """Set Collision Locator drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        new_draw_size = 0.5
        if obj.scs_props.locator_collider_type == 'Box':
            bigest_value = max(obj.scs_props.locator_collider_box_x,
                               obj.scs_props.locator_collider_box_y,
                               obj.scs_props.locator_collider_box_z)
            new_draw_size = (0.1 * bigest_value) * 12
        elif obj.scs_props.locator_collider_type in ('Sphere', 'Capsule',
                                                     'Cylinder'):
            new_draw_size = (0.1 * obj.scs_props.locator_collider_dia) * 12
        elif obj.scs_props.locator_collider_type == 'Convex':
            bbox = obj.scs_props.get("coll_convex_bbox", None)
            bbcenter = obj.scs_props.get("coll_convex_bbcenter", None)
            if bbox and bbcenter:
                scaling = _math_utils.scaling_width_margin(
                    bbox, obj.scs_props.locator_collider_margin)
                val = []
                for axis in range(3):
                    val.append(
                        (bbox[axis] + abs(bbcenter[axis])) * scaling[axis])
                bigest_value = max(val)
                new_draw_size = (0.1 * bigest_value) * 12
        _object_utils.set_attr_if_different(obj, "empty_draw_size",
                                            new_draw_size)
        _object_utils.set_attr_if_different(obj, "empty_draw_type",
                                            'PLAIN_AXES')
Exemplo n.º 2
0
    def set_locators_prefab_draw_size(obj):
        """Set Prefab Locator drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        new_draw_size = scene.scs_props.locator_empty_size * scene.scs_props.locator_size
        _object_utils.set_attr_if_different(obj, "empty_draw_size", new_draw_size)
        _object_utils.set_attr_if_different(obj, "empty_draw_type", 'PLAIN_AXES')
Exemplo n.º 3
0
    def store_locators_original_draw_size(obj):
        """Set Prefab Locator drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        if obj.scs_props.locators_orig_draw_size == 0.0:
            _object_utils.set_attr_if_different(obj.scs_props, "locators_orig_draw_size", obj.empty_draw_size)
            _object_utils.set_attr_if_different(obj.scs_props, "locators_orig_draw_type", obj.empty_draw_type)
Exemplo n.º 4
0
    def set_locators_model_draw_size(obj):
        """Set Model Locator drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        new_draw_size = scs_globals.locator_empty_size * scs_globals.locator_size
        _object_utils.set_attr_if_different(obj, "empty_draw_size", new_draw_size)
        _object_utils.set_attr_if_different(obj, "empty_draw_type", 'PLAIN_AXES')
Exemplo n.º 5
0
    def store_locators_original_draw_size(obj):
        """Set Prefab Locator drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        if obj.scs_props.locators_orig_draw_size == 0.0:
            _object_utils.set_attr_if_different(obj.scs_props, "locators_orig_draw_size", obj.empty_draw_size)
            _object_utils.set_attr_if_different(obj.scs_props, "locators_orig_draw_type", obj.empty_draw_type)
Exemplo n.º 6
0
    def set_locators_coll_draw_size(obj):
        """Set Collision Locator drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        new_draw_size = 0.5
        if obj.scs_props.locator_collider_type == 'Box':
            bigest_value = max(obj.scs_props.locator_collider_box_x, obj.scs_props.locator_collider_box_y, obj.scs_props.locator_collider_box_z)
            new_draw_size = (0.1 * bigest_value) * 12
        elif obj.scs_props.locator_collider_type in ('Sphere', 'Capsule', 'Cylinder'):
            new_draw_size = (0.1 * obj.scs_props.locator_collider_dia) * 12
        elif obj.scs_props.locator_collider_type == 'Convex':
            bbox = obj.scs_props.get("coll_convex_bbox", None)
            bbcenter = obj.scs_props.get("coll_convex_bbcenter", None)
            if bbox and bbcenter:
                scaling = _math_utils.scaling_width_margin(bbox, obj.scs_props.locator_collider_margin)
                val = []
                for axis in range(3):
                    val.append((bbox[axis] + abs(bbcenter[axis])) * scaling[axis])
                bigest_value = max(val)
                new_draw_size = (0.1 * bigest_value) * 12
        _object_utils.set_attr_if_different(obj, "empty_draw_size", new_draw_size)
        _object_utils.set_attr_if_different(obj, "empty_draw_type", 'PLAIN_AXES')
Exemplo n.º 7
0
def set_shader_data_to_material(material, section, preset_effect, is_import=False, override_back_data=True):
    """
    :param material:
    :type material: bpy.types.Material
    :param section:
    :param preset_effect:
    :return:
    """

    defined_tex_types = ("base", "flakenoise", "iamod", "lightmap", "mask", "mult", "oclu", "over", "paintjob", "reflection", "nmap")

    material.use_transparency = preset_effect.endswith(".a")
    _object.set_attr_if_different(material, "transparency_method", "MASK")

    attributes = {}
    textures = {}
    attribute_i = 0
    texture_i = 0
    # dictionary for listing of texture types which are used and should be overlooked during clearing of texture slots
    used_texture_types = {}
    for item in section.sections:

        if item.type == "Attribute":
            attribute_data = {}
            for prop in item.props:
                key, value = prop

                # # GETTING RID OF "[" AND "]" CHARS...
                if type(value) is str:
                    value = value.replace("[", "").replace("]", "")

                attribute_data[key] = value

            attribute_type = attribute_data['Tag']
            # APPLY PRESET ATTRIBUTE VALUES FROM PRESET
            if attribute_type == 'diffuse':
                material.scs_props.shader_attribute_diffuse = attribute_data['Value']
                if is_import:
                    material.scs_props.update_diffuse(material)
            elif attribute_type == 'specular':
                material.scs_props.shader_attribute_specular = attribute_data['Value']
                if is_import:
                    material.scs_props.update_specular(material)
            elif attribute_type == 'shininess':
                material.scs_props.shader_attribute_shininess = attribute_data['Value'][0]
                if is_import:
                    material.scs_props.update_shininess(material)
            elif attribute_type == 'add_ambient':
                material.scs_props.shader_attribute_add_ambient = attribute_data['Value'][0]
                if is_import:
                    material.scs_props.update_add_ambient(material)
            elif attribute_type == 'reflection':
                material.scs_props.shader_attribute_reflection = attribute_data['Value'][0]
                if is_import:
                    material.scs_props.update_reflection(material)
            elif attribute_type == 'reflection2':
                material.scs_props.shader_attribute_reflection2 = attribute_data['Value'][0]
                if is_import:
                    material.scs_props.update_reflection(material)
            elif attribute_type == 'shadow_bias':
                material.scs_props.shader_attribute_shadow_bias = attribute_data['Value'][0]
                if is_import:
                    material.scs_props.update_shadow_bias(material)
            elif attribute_type == 'env_factor':
                material.scs_props.shader_attribute_env_factor = attribute_data['Value']
                if is_import:
                    material.scs_props.update_env_factor(material)
            elif attribute_type == 'fresnel':
                material.scs_props.shader_attribute_fresnel = attribute_data['Value']
            elif attribute_type == 'tint':
                material.scs_props.shader_attribute_tint = attribute_data['Value']
            elif attribute_type == 'tint_opacity':
                material.scs_props.shader_attribute_tint_opacity = attribute_data['Value'][0]
            elif attribute_type in ("aux3", "aux5", "aux6", "aux7", "aux8"):

                auxiliary_prop = getattr(material.scs_props, "shader_attribute_" + attribute_type, None)

                # clean old values possible left from previous shader
                while len(auxiliary_prop) > 0:
                    auxiliary_prop.remove(0)

                for val in attribute_data['Value']:
                    item = auxiliary_prop.add()
                    item.value = val

            attributes[str(attribute_i)] = attribute_data
            attribute_i += 1

        elif item.type == "Texture":
            texture_data = {}
            for prop in item.props:
                # print('      prop: "%s"' % str(prop))
                texture_data[prop[0]] = prop[1]

            # APPLY SECTION TEXTURE VALUES
            texture_type = texture_data['Tag'].split(':')[1]
            slot_id = texture_type[8:]

            # set only defined textures
            if slot_id in defined_tex_types:

                texture_mappings = getattr(material.scs_props, "shader_texture_" + slot_id + "_uv")

                # clear all texture mapping for current texture from previous shader
                if override_back_data:
                    while len(texture_mappings) > 0:
                        texture_mappings.remove(0)

                # if shader is imported try to create custom tex coord mappings on material
                if material.scs_props.active_shader_preset_name == "<imported>" and "scs_tex_aliases" in material:
                    custom_maps = material.scs_props.shader_custom_tex_coord_maps

                    for tex_coord_key in sorted(material["scs_tex_aliases"].keys()):

                        if _invetory.get_index(custom_maps, "tex_coord_" + tex_coord_key) == -1:
                            new_map = custom_maps.add()
                            new_map.name = "tex_coord_" + tex_coord_key
                            new_map.value = material["scs_tex_aliases"][tex_coord_key]

                    # add one mapping field for using it as a preview uv layer in case of imported shader
                    mapping = texture_mappings.add()
                    mapping.texture_type = slot_id
                    mapping.tex_coord = -1

                # if there is an info about mapping in shader use it (in case of imported material this condition will fall!)
                elif "TexCoord" in texture_data:

                    for tex_coord in texture_data['TexCoord']:
                        tex_coord = int(tex_coord)

                        if tex_coord != -1:
                            mapping = texture_mappings.add()
                            mapping.texture_type = slot_id
                            mapping.tex_coord = tex_coord

                            if "scs_tex_aliases" in material:
                                mapping.value = material["scs_tex_aliases"][str(tex_coord)]

                used_texture_types[slot_id] = 1

                bitmap_filepath = _path.get_bitmap_filepath(texture_data['Value'])

                if bitmap_filepath and bitmap_filepath != "":
                    setattr(material.scs_props, "shader_texture_" + slot_id, bitmap_filepath)

                    if is_import:
                        update_texture_slots(material, bitmap_filepath, slot_id)

                        # only if shader is imported then make sure that by default imported values will be used
                        if material.scs_props.active_shader_preset_name == "<imported>":
                            setattr(material.scs_props, "shader_texture_" + slot_id + "_use_imported", True)
                            setattr(material.scs_props, "shader_texture_" + slot_id + "_imported_tobj", texture_data['Value'])

                    texture_slot = get_texture_slot(material, slot_id)
                    if slot_id == 'base' and texture_slot:
                        set_diffuse(texture_slot, material, material.scs_props.shader_attribute_diffuse)
                    elif slot_id == 'reflection' and texture_slot:
                        set_env_factor(texture_slot, material.scs_props.shader_attribute_env_factor)

            textures[str(texture_i)] = texture_data
            texture_i += 1

    if override_back_data:

        # clear texture slots for unused textures from previous preset
        for tex_type in defined_tex_types:
            if tex_type not in used_texture_types:  # delete unused texture slots
                clear_texture_slots(material, tex_type)

        shader_data = {'effect': preset_effect,
                       'attributes': attributes,
                       'textures': textures}
        material["scs_shader_attributes"] = shader_data