Example #1
0
 def build_xml_element(self, context):
     xml = self.Element('material')
     self.build_subelements(
         context, {
             'name': ['blendigo_clay'],
             'diffuse': {
                 'albedo': {
                     'constant': rgb([0.8, 0.8, 0.8])
                 }
             }
         }, xml)
     return xml
Example #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])
Example #3
0
 def build_xml_element(self, context):
     xml = self.Element('material')
     self.build_subelements(
         context,
         {
             'name': ['blendigo_clay'],
             'diffuse': {
                 'albedo': {
                     'constant':  rgb([0.8, 0.8, 0.8])
                 }
             }
         },
         xml
     )
     return xml
Example #4
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]
         )
Example #5
0
 def get_format(self):
    medium_data = self.medium_data.medium_type
    
    fmt = {
        'name': [self.medium_name + '_medium'],
        'uid': [self.medium_index + 10000 ],
        'precedence': [self.medium_data.precedence],
        self.medium_data.medium_type: {}
    }
    
    if self.medium_data.medium_type == 'basic':
        fmt[self.medium_data.medium_type] = {
            'ior': [self.medium_data.medium_ior],
            'cauchy_b_coeff': [self.medium_data.medium_cauchy_b]
        }
        if self.medium_data.medium_type_SP_type == 'rgb':
            fmt[self.medium_data.medium_type]['absorption_coefficient_spectrum'] = rgb([(1.0-i)*self.medium_data.medium_type_SP_rgb_gain for i in self.medium_data.medium_type_SP_rgb])
        elif self.medium_data.medium_type_SP_type == 'uniform':
            fmt[self.medium_data.medium_type]['absorption_coefficient_spectrum'] = uniform([
                self.medium_data.medium_type_SP_uniform_val * \
                10**self.medium_data.medium_type_SP_uniform_exp
            ])
        
        if self.medium_data.sss:
             if self.medium_data.sss_scatter_SP_type == 'rgb':
                SCS = rgb([i*self.medium_data.sss_scatter_SP_rgb_gain for i in self.medium_data.sss_scatter_SP_rgb])
             elif self.medium_data.sss_scatter_SP_type == 'uniform':
                SCS = uniform([
                    self.medium_data.sss_scatter_SP_uniform_val * \
                    10**self.medium_data.sss_scatter_SP_uniform_exp
                ])
            
             if self.medium_data.sss_phase_function == 'uniform':
                PF = { 'uniform': {} }
             elif self.medium_data.sss_phase_function == 'hg':
                if self.medium_data.sss_phase_hg_SP_type == 'rgb':
                    PF_HG_GS = rgb([i*self.medium_data.sss_phase_hg_SP_rgb_gain for i in self.medium_data.sss_phase_hg_SP_rgb])
                elif self.medium_data.sss_phase_hg_SP_type == 'uniform':
                    PF_HG_GS = uniform([
                        self.medium_data.sss_phase_hg_SP_uniform_val * \
                        10**self.medium_data.sss_phase_hg_SP_uniform_exp
                    ])
                PF = {
                    'henyey_greenstein': {
                        'g_spectrum': PF_HG_GS
                    }
                }
             fmt[self.medium_data.medium_type]['subsurface_scattering'] = {
                'scattering_coefficient_spectrum': SCS,
                'phase_function': PF,
            }
     
    elif self.medium_data.medium_type == 'dermis':
        fmt[self.medium_data.medium_type] = {
            'hemoglobin_fraction': [self.medium_data.medium_haemoglobin],
        }
    elif self.medium_data.medium_type == 'epidermis':
        fmt[self.medium_data.medium_type] = {
            'melanin_fraction': [self.medium_data.medium_melanin],
            'melanin_type_blend': [self.medium_data.medium_eumelanin],
        }
    elif self.medium_data.medium_type == 'atmosphere':
        fmt[self.medium_data.medium_type] = {
            'turbidity': [self.medium_data.medium_turbidity],
            'center': [ str(self.medium_data.medium_posx) + ' ' + str(self.medium_data.medium_posy) + ' ' + str(self.medium_data.medium_posz)],
        }
    return fmt
Example #6
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
Example #7
0
    def get_format(self):
        medium_data = self.medium_data.medium_type

        fmt = {'name': [self.medium_name + '_medium']}
        if self.medium_index != -1:
            fmt.update({
                'uid': [self.medium_index + 10],
            })  # indigo uid starts at 10
        fmt.update({
            'precedence': [self.medium_data.precedence],
            self.medium_data.medium_type: {}
        })

        if self.medium_data.medium_type == 'basic':
            fmt[self.medium_data.medium_type] = {
                'ior': [self.medium_data.medium_ior],
                'cauchy_b_coeff': [self.medium_data.medium_cauchy_b],
                'max_extinction_coeff':
                [self.medium_data.max_extinction_coeff]
            }
            if self.medium_data.medium_type_SP_type == 'rgb':
                SP = rgb([(1.0 - i) * self.medium_data.medium_type_SP_rgb_gain
                          for i in self.medium_data.medium_type_SP_rgb])
            elif self.medium_data.medium_type_SP_type == 'uniform':
                SP = uniform([
                    self.medium_data.medium_type_SP_uniform_val * \
                    10**self.medium_data.medium_type_SP_uniform_exp
                ])

            fmt[self.medium_data.medium_type]['absorption_coefficient'] = {
                'constant': SP
            }

            if self.medium_data.sss:
                if self.medium_data.sss_scatter_SP_type == 'rgb':
                    SCS = rgb([
                        i * self.medium_data.sss_scatter_SP_rgb_gain
                        for i in self.medium_data.sss_scatter_SP_rgb
                    ])
                elif self.medium_data.sss_scatter_SP_type == 'uniform':
                    SCS = uniform([
                        self.medium_data.sss_scatter_SP_uniform_val * \
                        10**self.medium_data.sss_scatter_SP_uniform_exp
                    ])

                if self.medium_data.sss_phase_function == 'uniform':
                    PF = {'uniform': {}}
                elif self.medium_data.sss_phase_function == 'hg':
                    if self.medium_data.sss_phase_hg_SP_type == 'rgb':
                        PF_HG_GS = rgb([
                            i * self.medium_data.sss_phase_hg_SP_rgb_gain
                            for i in self.medium_data.sss_phase_hg_SP_rgb
                        ])
                    elif self.medium_data.sss_phase_hg_SP_type == 'uniform':
                        PF_HG_GS = uniform([
                            self.medium_data.sss_phase_hg_SP_uniform_val * \
                            10**self.medium_data.sss_phase_hg_SP_uniform_exp
                        ])
                    PF = {'henyey_greenstein': {'g_spectrum': PF_HG_GS}}
                fmt[self.medium_data.medium_type]['subsurface_scattering'] = {
                    'scattering_coefficient_spectrum': SCS,
                    'phase_function': PF,
                }

        elif self.medium_data.medium_type == 'dermis':
            fmt[self.medium_data.medium_type] = {
                'hemoglobin_fraction': [self.medium_data.medium_haemoglobin],
            }
        elif self.medium_data.medium_type == 'epidermis':
            fmt[self.medium_data.medium_type] = {
                'melanin_fraction': [self.medium_data.medium_melanin],
                'melanin_type_blend': [self.medium_data.medium_eumelanin],
            }
        return fmt
Example #8
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
Example #9
0
 def get_format(self):
    medium_data = self.medium_data.medium_type
    
    fmt = {
        'name': [self.medium_name + '_medium']}
    if self.medium_index != -1:
            fmt.update( {'uid': [self.medium_index + 10 ],})  # indigo uid starts at 10
    fmt.update( {'precedence': [self.medium_data.precedence],
        self.medium_data.medium_type: {}
    })
    
    if self.medium_data.medium_type == 'basic':
        fmt[self.medium_data.medium_type] = {
            'ior': [self.medium_data.medium_ior],
            'cauchy_b_coeff': [self.medium_data.medium_cauchy_b],
            'max_extinction_coeff': [self.medium_data.max_extinction_coeff]
        }
        if self.medium_data.medium_type_SP_type == 'rgb':
            SP = rgb([(1.0-i)*self.medium_data.medium_type_SP_rgb_gain for i in self.medium_data.medium_type_SP_rgb])
        elif self.medium_data.medium_type_SP_type == 'uniform':
            SP = uniform([
                self.medium_data.medium_type_SP_uniform_val * \
                10**self.medium_data.medium_type_SP_uniform_exp
            ])
        
        fmt[self.medium_data.medium_type]['absorption_coefficient'] = { 'constant': SP }
        
        if self.medium_data.sss:
             if self.medium_data.sss_scatter_SP_type == 'rgb':
                SCS = rgb([i*self.medium_data.sss_scatter_SP_rgb_gain for i in self.medium_data.sss_scatter_SP_rgb])
             elif self.medium_data.sss_scatter_SP_type == 'uniform':
                SCS = uniform([
                    self.medium_data.sss_scatter_SP_uniform_val * \
                    10**self.medium_data.sss_scatter_SP_uniform_exp
                ])
            
             if self.medium_data.sss_phase_function == 'uniform':
                PF = { 'uniform': {} }
             elif self.medium_data.sss_phase_function == 'hg':
                if self.medium_data.sss_phase_hg_SP_type == 'rgb':
                    PF_HG_GS = rgb([i*self.medium_data.sss_phase_hg_SP_rgb_gain for i in self.medium_data.sss_phase_hg_SP_rgb])
                elif self.medium_data.sss_phase_hg_SP_type == 'uniform':
                    PF_HG_GS = uniform([
                        self.medium_data.sss_phase_hg_SP_uniform_val * \
                        10**self.medium_data.sss_phase_hg_SP_uniform_exp
                    ])
                PF = {
                    'henyey_greenstein': {
                        'g_spectrum': PF_HG_GS
                    }
                }
             fmt[self.medium_data.medium_type]['subsurface_scattering'] = {
                'scattering_coefficient_spectrum': SCS,
                'phase_function': PF,
            }
     
    elif self.medium_data.medium_type == 'dermis':
        fmt[self.medium_data.medium_type] = {
            'hemoglobin_fraction': [self.medium_data.medium_haemoglobin],
        }
    elif self.medium_data.medium_type == 'epidermis':
        fmt[self.medium_data.medium_type] = {
            'melanin_fraction': [self.medium_data.medium_melanin],
            'melanin_type_blend': [self.medium_data.medium_eumelanin],
        }
    return fmt