Exemplo n.º 1
0
 def get_background_spectrum(self):
     if self.env_bg_SP_type == 'rgb':
         from indigo.export.materials.spectra import rgb
         return rgb([i for i in self.env_bg_SP_rgb])
     elif self.env_bg_SP_type == 'uniform':
         from indigo.export.materials.spectra import uniform
         return uniform([
             self.env_bg_SP_uniform_val * \
             10**self.env_bg_SP_uniform_exp
         ])
     elif self.env_bg_SP_type == 'blackbody':
         from indigo.export.materials.spectra import blackbody
         return blackbody([self.env_bg_SP_blackbody_temp],
                          [self.env_bg_SP_blackbody_gain])
Exemplo n.º 2
0
 def get_background_spectrum(self):
     if self.env_bg_SP_type == 'rgb':
         from indigo.export.materials.spectra import rgb
         return rgb([i for i in self.env_bg_SP_rgb])
     elif self.env_bg_SP_type == 'uniform':
         from indigo.export.materials.spectra import uniform
         return uniform([
             self.env_bg_SP_uniform_val * \
             10**self.env_bg_SP_uniform_exp
         ])
     elif self.env_bg_SP_type == 'blackbody':
         from indigo.export.materials.spectra import blackbody
         return blackbody(
             [self.env_bg_SP_blackbody_temp],
             [self.env_bg_SP_blackbody_gain]
         )
Exemplo n.º 3
0
    def get_channel(self, property_group, channel_name, channel_prop_name):
        d = {}

        channel_type = getattr(property_group, channel_prop_name + '_type')

        if channel_type == 'spectrum':
            spectrum_type = getattr(property_group,
                                    channel_prop_name + '_SP_type')
            if spectrum_type == 'rgb':
                d[channel_name] = {
                    'constant':
                    rgb([
                        i for i in getattr(property_group, channel_prop_name +
                                           '_SP_rgb') *
                        getattr(property_group, channel_prop_name +
                                '_SP_rgb_gain', 1.0)
                    ])
                }
            elif spectrum_type == 'uniform':
                d[channel_name] = {
                    'constant': uniform([
                        getattr(property_group, channel_prop_name + '_SP_uniform_val') * \
                        10**getattr(property_group, channel_prop_name + '_SP_uniform_exp')
                    ])
                }
            elif spectrum_type == 'blackbody':
                d[channel_name] = {
                    'constant':
                    blackbody([
                        getattr(property_group,
                                channel_prop_name + '_SP_blackbody_temp')
                    ], [
                        getattr(property_group,
                                channel_prop_name + '_SP_blackbody_gain')
                    ])
                }

        elif channel_type == 'texture':
            tex_name = getattr(property_group,
                               channel_prop_name + '_TX_texture')

            if tex_name:  # string is not empty
                if channel_prop_name not in self.found_texture_indices:
                    self.found_texture_indices.append(channel_prop_name)

                    if not tex_name in bpy.data.textures:
                        raise Exception(
                            "Texture \"%s\" assigned to material \"%s\" doesn't exist!"
                            % (tex_name, self.material_name))

                    tex_property_group = bpy.data.textures[
                        tex_name].indigo_texture

                    if tex_property_group.image_ref == 'file':
                        relative_texture_path = efutil.path_relative_to_export(
                            getattr(tex_property_group, 'path'))
                    elif tex_property_group.image_ref == 'blender':
                        if not tex_property_group.image in bpy.data.images:
                            raise Exception(
                                "Error with image reference on texture \"%s\""
                                % tex_name)

                        img = bpy.data.images[tex_property_group.image]

                        if img.filepath == '':
                            bl_img_path = 'blendigo_extracted_image_%s.png' % bpy.path.clean_name(
                                tex_name)
                        else:
                            bl_img_path = img.filepath

                        if img.source != 'FILE' or img.packed_file:
                            bl_file_formatted = os.path.splitext(
                                os.path.basename(bl_img_path))[0]
                            bl_file_formatted = '%s.%s' % (
                                bl_file_formatted,
                                self.scene.render.image_settings.file_format)
                            bl_img_path = os.path.join(
                                efutil.export_path, efutil.scene_filename(),
                                bpy.path.clean_name(self.scene.name),
                                '%05d' % self.scene.frame_current,
                                bl_file_formatted)
                            img.save_render(bl_img_path, self.scene)

                        relative_texture_path = efutil.path_relative_to_export(
                            bl_img_path)

                    if not getattr(property_group,
                                   channel_prop_name + '_TX_abc_from_tex'):
                        abc_property_group = property_group
                        abc_prefix = channel_prop_name + '_TX_'
                    else:
                        abc_property_group = tex_property_group
                        abc_prefix = ''

                    uv_set_name = getattr(property_group,
                                          channel_prop_name + '_TX_uvset')
                    try:
                        uv_set_index = self.obj.data.uv_textures.keys().index(
                            uv_set_name)
                    except:
                        uv_set_index = 0

                    self.found_textures.append({
                        'uv_set_index': [
                            uv_set_index
                        ],  #getattr(property_group, channel_prop_name + '_TX_uv_index')],
                        'path': [relative_texture_path],
                        'exponent': [getattr(tex_property_group, 'gamma')],
                        'a': [getattr(abc_property_group, abc_prefix + 'A')],
                        'b': [getattr(abc_property_group, abc_prefix + 'B')],
                        'c': [getattr(abc_property_group, abc_prefix + 'C')],
                        'smooth': [
                            str(
                                getattr(property_group, channel_prop_name +
                                        '_TX_smooth')).lower()
                        ]
                    })

                d[channel_name] = {
                    'texture': {
                        'texture_index':
                        [self.found_texture_indices.index(channel_prop_name)],
                    }
                }

        elif channel_type == 'shader':
            try:
                shader_name = getattr(property_group,
                                      channel_prop_name + '_SH_text')
                if not shader_name in bpy.data.texts:
                    raise Exception(
                        'Referenced Text "%s" for shader on material "%s" not found'
                        % (shader_name, self.material_name))

                shader_text = '\n' + bpy.data.texts[shader_name].as_string()
                d[channel_name] = {
                    'shader': {
                        'shader': xml_cdata(shader_text)
                    }
                }
            except:
                pass

        return d
Exemplo n.º 4
0
 def get_channel(self, property_group, channel_name, channel_prop_name):
     d = {}
     
     channel_type = getattr(property_group, channel_prop_name + '_type')
     
     if channel_type == 'spectrum':
         spectrum_type = getattr(property_group, channel_prop_name + '_SP_type')
         if spectrum_type == 'rgb':
             d[channel_name] = {
                 'constant': rgb([i for i in getattr(property_group, channel_prop_name + '_SP_rgb') * getattr(property_group, channel_prop_name + '_SP_rgb_gain', 1.0)])
             }
         elif spectrum_type == 'uniform':
             d[channel_name] = {
                 'constant': uniform([
                     getattr(property_group, channel_prop_name + '_SP_uniform_val') * \
                     10**getattr(property_group, channel_prop_name + '_SP_uniform_exp')
                 ])
             }
         elif spectrum_type == 'blackbody':
             d[channel_name] = {
                 'constant': blackbody(
                     [getattr(property_group, channel_prop_name + '_SP_blackbody_temp')],
                     [getattr(property_group, channel_prop_name + '_SP_blackbody_gain')]
                 )
             }
     
     elif channel_type == 'texture':
         tex_name = getattr(property_group, channel_prop_name + '_TX_texture')
         
         if tex_name: # string is not empty
             if channel_prop_name not in self.found_texture_indices:
                 self.found_texture_indices.append(channel_prop_name)
                 
                 if not tex_name in bpy.data.textures:
                     raise Exception("Texture \"%s\" assigned to material \"%s\" doesn't exist!" %(tex_name, self.material_name))
                 
                 tex_property_group = bpy.data.textures[tex_name].indigo_texture
                 
                 if tex_property_group.image_ref == 'file':
                     relative_texture_path = efutil.path_relative_to_export(
                         getattr(tex_property_group, 'path')
                     )
                 elif tex_property_group.image_ref == 'blender':
                     if not tex_property_group.image in bpy.data.images:
                         raise Exception("Error with image reference on texture \"%s\"" % tex_name)
                     
                     img = bpy.data.images[tex_property_group.image]
                     
                     if img.filepath == '':
                         bl_img_path = 'blendigo_extracted_image_%s.png' % bpy.path.clean_name(tex_name)
                     else:
                         bl_img_path = img.filepath
                     
                     if img.source != 'FILE' or img.packed_file:
                         bl_file_formatted = os.path.splitext(os.path.basename(bl_img_path))[0]
                         bl_file_formatted = '%s.%s' % (bl_file_formatted, self.scene.render.image_settings.file_format)
                         bl_img_path = os.path.join(
                             efutil.export_path,
                             efutil.scene_filename(),
                             bpy.path.clean_name(self.scene.name),
                             '%05d' % self.scene.frame_current,
                             bl_file_formatted
                         )
                         img.save_render(bl_img_path, self.scene)
                     
                     relative_texture_path = efutil.path_relative_to_export(bl_img_path)
                 
                 if not getattr(property_group, channel_prop_name + '_TX_abc_from_tex'):
                     abc_property_group = property_group
                     abc_prefix = channel_prop_name + '_TX_'
                 else:
                     abc_property_group = tex_property_group
                     abc_prefix = ''
                 
                 uv_set_name  = getattr(property_group, channel_prop_name + '_TX_uvset')
                 try:
                     uv_set_index = self.obj.data.uv_textures.keys().index(uv_set_name)
                 except:
                     uv_set_index = 0
                 
                 self.found_textures.append({
                     'uv_set_index':    [uv_set_index], #getattr(property_group, channel_prop_name + '_TX_uv_index')],
                     'path':            [relative_texture_path],
                     'exponent':        [getattr(tex_property_group, 'gamma')],
                     'a':            [getattr(abc_property_group, abc_prefix + 'A')],
                     'b':            [getattr(abc_property_group, abc_prefix + 'B')],
                     'c':            [getattr(abc_property_group, abc_prefix + 'C')],
                     'smooth':        [str(getattr(property_group, channel_prop_name + '_TX_smooth')).lower()]
                 })
             
             d[channel_name] = {
                 'texture': {
                     'texture_index': [ self.found_texture_indices.index(channel_prop_name) ],
                 }
             }
     
     elif channel_type == 'shader':
         try:
             shader_name = getattr(property_group, channel_prop_name + '_SH_text')
             if not shader_name in bpy.data.texts:
                 raise Exception('Referenced Text "%s" for shader on material "%s" not found' % (shader_name, self.material_name))
             
             shader_text = '\n' + bpy.data.texts[shader_name].as_string()
             d[channel_name] = {
                 'shader': {
                     'shader': xml_cdata(shader_text)
                 }
             }
         except:
             pass
     
     return d