How to use the translators.translator.ObjectKey function in translators

To help you get started, we’ve selected a few translators examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github appleseedhq / blenderseed / translators / group.py View on Github external
def __create_material_translators(self, obj):
        for slot in obj.material_slots:
            mat = slot.material
            mat_key = ObjectKey(mat)

            if mat_key not in self._material_translators:
                logger.debug("Creating material translator for material %s", mat_key)
                translator = MaterialTranslator(mat, self.asset_handler)
                self._material_translators[mat_key] = translator
github appleseedhq / blenderseed / translators / group.py View on Github external
self._lamp_translators[obj_key] = LampTranslator(obj, self.asset_handler)
                if obj.data.appleseed.osl_node_tree is not None:
                    lamp = obj.data
                    lamp_key = ObjectKey(lamp)
                    translator = MaterialTranslator(lamp, self.asset_handler)
                    self._lamp_material_translators[lamp_key] = translator

            elif self.__is_dupli_source(obj):
                self.__create_material_translators(obj)

                # Sources of duplicated objects are not shown in renders.
                logger.debug("Skipping dupli-source object %s", obj_key)
                continue

            elif obj.type in GroupTranslator.MESH_OBJECTS:
                mesh_key = ObjectKey(obj.data)

                if obj.is_duplicator:
                    logger.debug("Creating dupli translator for object %s", obj_key)
                    self._dupli_translators[obj_key] = DupliTranslator(obj, self.export_mode, self.asset_handler)
                    if obj.dupli_type == 'NONE':
                        for particle_sys in obj.particle_systems:
                            if particle_sys.settings.use_render_emitter:
                                logger.debug("Creating mesh translator for object %s", obj_key)

                                translator = MeshTranslator(obj, self.export_mode, self.asset_handler)
                                self._object_translators[obj_key] = translator

                                if not is_modified:
                                    logger.debug("Saving translator for object %s in instance map", obj_key)
                                    self._datablock_to_translator[mesh_key] = translator
github appleseedhq / blenderseed / translators / mesh.py View on Github external
def create_entities(self, scene):
        logger.debug("Creating mesh entities for object %s", self.bl_obj.name)

        # Materials
        mesh_key = str(ObjectKey(self.bl_obj.data)) + "_obj"
        mesh_name = mesh_key

        asr_obj_props = self.bl_obj.appleseed

        self.__obj_params = {'alpha_map': asr_obj_props.object_alpha}
        if self.bl_obj.appleseed.object_alpha_texture is not None:
            filename = self.asset_handler.process_path(asr_obj_props.object_alpha_texture.filepath, AssetType.TEXTURE_ASSET)
            tex_inst_params = {'addressing_mode': asr_obj_props.object_alpha_texture_wrap_mode,
                               'filtering_mode': 'bilinear',
                               'alpha_mode': asr_obj_props.object_alpha_mode}
            self.__alpha_tex = asr.Texture('disk_texture_2d', mesh_name + "_tex",
                                           {'filename': filename,
                                            'color_space': asr_obj_props.object_alpha_texture_colorspace}, [])
            self.__alpha_tex_inst = asr.TextureInstance(mesh_name + "_tex_inst", tex_inst_params, mesh_name + "_tex",
                                                        asr.Transformf(asr.Matrix4f.identity()))
github appleseedhq / blenderseed / translators / group.py View on Github external
logger.debug("skipping hidden object %s", obj.name)
                continue

            if self.export_mode == ProjectExportMode.INTERACTIVE_RENDER and obj.hide:
                logger.debug("skipping hidden object %s", obj.name)
                continue

            if not inscenelayer(obj, self.bl_group):
                logger.debug("skipping invisible object %s", obj.name)
                continue

            if self.selected_only and not obj.select:
                logger.debug("skipping non-selected object %s", obj.name)
                continue

            obj_key = ObjectKey(obj)

            if obj.type == 'LAMP':
                logger.debug("Creating lamp translator for object %s of type %s", obj_key, obj.data.type)

                if obj.data.type == 'AREA':
                    self._lamp_translators[obj_key] = AreaLampTranslator(obj, self.export_mode, self.asset_handler)
                else:
                    self._lamp_translators[obj_key] = LampTranslator(obj, self.asset_handler)
                if obj.data.appleseed.osl_node_tree is not None:
                    lamp = obj.data
                    lamp_key = ObjectKey(lamp)
                    translator = MaterialTranslator(lamp, self.asset_handler)
                    self._lamp_material_translators[lamp_key] = translator

            elif self.__is_dupli_source(obj):
                self.__create_material_translators(obj)
github appleseedhq / blenderseed / translators / mesh.py View on Github external
def set_deform_key(self, scene, time, key_times):
        # Don't save keys for non deforming meshes.
        if not self.__deforming and self.__key_index > 0:
            logger.debug("Skipping mesh key for non deforming object %s", self.bl_obj.name)
            return

        mesh_key = str(ObjectKey(self.bl_obj.data)) + "_obj"
        mesh_name = mesh_key

        me = self.__get_blender_mesh(scene)

        if self.__export_mode == ProjectExportMode.PROJECT_EXPORT:
            # Write a mesh file for the mesh key.
            logger.debug("Writing mesh file object %s, time = %s", self.bl_obj.name, time)
            self.__mesh_object = asr.MeshObject(mesh_name, self.__obj_params)
            self.__convert_mesh(me)
            self.__write_mesh(mesh_key)
        else:
            if self.__key_index == 0:
                # First key, convert the mesh and reserve keys.
                logger.debug("Converting mesh object %s", self.bl_obj.name)
                self.__mesh_object = asr.MeshObject(mesh_name, self.__obj_params)
                self.__convert_mesh(me)
github appleseedhq / blenderseed / translators / mesh.py View on Github external
self.__obj_params['alpha_map'] = mesh_name + "_tex_inst"

        material_slots = self.bl_obj.material_slots

        if len(material_slots) > 1:
            for i, m in enumerate(material_slots):
                if m.material.appleseed.osl_node_tree is not None:
                    mat_key = str(ObjectKey(m.material)) + "_mat"
                    self.__front_materials["slot-%s" % i] = mat_key
                else:
                    self.__front_materials["slot-%s" % i] = "__default_material"
        else:
            if len(material_slots) == 1:
                if material_slots[0].material.appleseed.osl_node_tree is not None:
                    mat_key = str(ObjectKey(material_slots[0].material)) + "_mat"
                    self.__front_materials["default"] = mat_key
                else:
                    self.__front_materials["default"] = "__default_material"
            else:
                logger.debug("Mesh %s has no materials, assigning default material instead", mesh_name)
                self.__front_materials["default"] = "__default_material"

        double_sided_materials = False if self.bl_obj.appleseed.double_sided is False else True

        if double_sided_materials:
            self.__back_materials = self.__front_materials
github appleseedhq / blenderseed / translators / group.py View on Github external
if self.selected_only and not obj.select:
                logger.debug("skipping non-selected object %s", obj.name)
                continue

            obj_key = ObjectKey(obj)

            if obj.type == 'LAMP':
                logger.debug("Creating lamp translator for object %s of type %s", obj_key, obj.data.type)

                if obj.data.type == 'AREA':
                    self._lamp_translators[obj_key] = AreaLampTranslator(obj, self.export_mode, self.asset_handler)
                else:
                    self._lamp_translators[obj_key] = LampTranslator(obj, self.asset_handler)
                if obj.data.appleseed.osl_node_tree is not None:
                    lamp = obj.data
                    lamp_key = ObjectKey(lamp)
                    translator = MaterialTranslator(lamp, self.asset_handler)
                    self._lamp_material_translators[lamp_key] = translator

            elif self.__is_dupli_source(obj):
                self.__create_material_translators(obj)

                # Sources of duplicated objects are not shown in renders.
                logger.debug("Skipping dupli-source object %s", obj_key)
                continue

            elif obj.type in GroupTranslator.MESH_OBJECTS:
                mesh_key = ObjectKey(obj.data)

                if obj.is_duplicator:
                    logger.debug("Creating dupli translator for object %s", obj_key)
                    self._dupli_translators[obj_key] = DupliTranslator(obj, self.export_mode, self.asset_handler)