@@ -109,7 +109,11 @@ def _load_image(self, filepath):
109109 img = bpy .data .images .new (os .path .basename (filepath ), 1 , 1 )
110110 img .source = 'FILE'
111111 img .filepath = filepath
112- img .use_alpha = (img .depth == 32 and img .file_format != 'BMP' )
112+ use_alpha = (img .depth == 32 and img .file_format != 'BMP' )
113+ if hasattr (img , 'use_alpha' ):
114+ img .use_alpha = use_alpha
115+ elif not use_alpha :
116+ img .alpha_mode = 'NONE'
113117 return img
114118
115119 def __load_texture (self , filepath ):
@@ -401,22 +405,27 @@ def use_sphere_texture(self, use_sphere, obj=None):
401405
402406 def create_sphere_texture (self , filepath , obj = None ):
403407 texture = self .__create_texture_node ('mmd_sphere_tex' , filepath , (- 2 , - 2 ))
404- sphere_texture_type = int (self .material .mmd_material .sphere_texture_type )
405- texture .color_space = 'NONE' if sphere_texture_type == 2 else 'COLOR'
406408 self .update_sphere_texture_type (obj )
407409 return _DummyTextureSlot (texture .image )
408410
409411 def update_sphere_texture_type (self , obj = None ):
410412 sphere_texture_type = int (self .material .mmd_material .sphere_texture_type )
413+ is_sph_add = (sphere_texture_type == 2 )
414+
411415 if sphere_texture_type not in (1 , 2 , 3 ):
412416 self .__update_shader_input ('Sphere Tex Fac' , 0 )
413417 else :
414418 self .__update_shader_input ('Sphere Tex Fac' , 1 )
415- self .__update_shader_input ('Sphere Mul/Add' , sphere_texture_type == 2 )
416- self .__update_shader_input ('Sphere Tex' , (0 , 0 , 0 , 1 ) if sphere_texture_type == 2 else (1 , 1 , 1 , 1 ))
419+ self .__update_shader_input ('Sphere Mul/Add' , is_sph_add )
420+ self .__update_shader_input ('Sphere Tex' , (0 , 0 , 0 , 1 ) if is_sph_add else (1 , 1 , 1 , 1 ))
417421
418422 texture = self .__get_texture_node ('mmd_sphere_tex' )
419423 if texture :
424+ if hasattr (texture , 'color_space' ):
425+ texture .color_space = 'NONE' if is_sph_add else 'COLOR'
426+ elif hasattr (texture .image , 'colorspace_settings' ):
427+ texture .image .colorspace_settings .name = 'Linear' if is_sph_add else 'sRGB'
428+
420429 mat = self .material
421430 nodes , links = mat .node_tree .nodes , mat .node_tree .links
422431 if sphere_texture_type == 3 :
@@ -526,13 +535,17 @@ def update_is_double_sided(self):
526535 mmd_mat = mat .mmd_material
527536 if hasattr (mat , 'game_settings' ):
528537 mat .game_settings .use_backface_culling = not mmd_mat .is_double_sided
538+ elif hasattr (mat , 'use_backface_culling' ):
539+ mat .use_backface_culling = not mmd_mat .is_double_sided
529540 self .__update_shader_input ('Double Sided' , mmd_mat .is_double_sided )
530541
531542 def update_self_shadow_map (self ):
532543 mat = self .material
533544 mmd_mat = mat .mmd_material
534545 cast_shadows = mmd_mat .enabled_self_shadow_map if mmd_mat .alpha > 1e-3 else False
535- if hasattr (mat , 'transparent_shadow_method' ):
546+ if hasattr (mat , 'shadow_method' ):
547+ mat .shadow_method = 'HASHED' if cast_shadows else 'NONE'
548+ if hasattr (mat , 'transparent_shadow_method' ): #XXX
536549 mat .transparent_shadow_method = 'HASHED' if cast_shadows else 'NONE'
537550
538551 def update_self_shadow (self ):
0 commit comments