Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKalle-Samuli Riihikoski <haikalle@gmail.com>2018-10-29 15:20:42 +0300
committerKalle-Samuli Riihikoski <haikalle@gmail.com>2018-10-29 15:20:42 +0300
commitd65bc48926b7ea3b2ae7a87db1b0a92f1537fea6 (patch)
tree6f8d3ea395f4c632effd91c18fb77d24461fefab /io_coat3D/tex.py
parent194cd6e8b2d23c91f7fa78dd11f855234c7851c9 (diff)
Export preset bug fixed.
Diffstat (limited to 'io_coat3D/tex.py')
-rw-r--r--io_coat3D/tex.py67
1 files changed, 36 insertions, 31 deletions
diff --git a/io_coat3D/tex.py b/io_coat3D/tex.py
index a42d974c..c9feec95 100644
--- a/io_coat3D/tex.py
+++ b/io_coat3D/tex.py
@@ -42,9 +42,7 @@ def RemoveFbxNodes(objekti):
Node_Tree.links.new(Prin_mat.outputs[0], output.inputs[0])
-def readtexturefolder(objekti,is_new): #read textures from texture file
-
- obj_coat = objekti.coat3D
+def readtexturefolder(mat_list,texturelist,is_new): #read textures from texture file
texcoat = {}
texcoat['color'] = []
@@ -52,26 +50,23 @@ def readtexturefolder(objekti,is_new): #read textures from texture file
texcoat['rough'] = []
texcoat['nmap'] = []
texcoat['disp'] = []
+ texcoat['emissive'] = []
- files_dir = os.path.dirname(os.path.abspath(objekti.coat3D.applink_address))
- files = os.listdir(files_dir)
- materiaali_muutos = objekti.active_material.name
- uusin_mat = materiaali_muutos
- if(is_new == True and objekti.coat3D.obj_mat == ''):
- obj_coat.obj_mat = (objekti.coat3D.applink_name + '_' + objekti.data.uv_layers[0].name)
- elif (objekti.coat3D.obj_mat == ''):
- obj_coat.obj_mat = (objekti.coat3D.applink_name + '_' + uusin_mat)
-
- new_name = obj_coat.obj_mat + '_'
- for i in files:
- if(i.startswith(new_name)):
- koko_osoite = files_dir + os.sep + i
- listed = re.split(r'[_.]', i)
- tex_name = listed[-2]
- texcoat[tex_name].append(koko_osoite)
+ for texture_info in texturelist:
+ if texture_info[0] == mat_list[0].name:
+ if texture_info[2] == 'color' or texture_info[2] == 'diffuse':
+ texcoat['color'].append(texture_info[3])
+ if texture_info[2] == 'metalness' or texture_info[2] == 'reflection':
+ texcoat['metalness'].append(texture_info[3])
+ if texture_info[2] == 'rough' or texture_info[2] == 'roughness':
+ texcoat['rough'].append(texture_info[3])
+ if texture_info[2] == 'nmap' or texture_info[2] == 'normal_map':
+ texcoat['nmap'].append(texture_info[3])
+ if texture_info[2] == 'emissive':
+ texcoat['emissive'].append(texture_info[3])
- createnodes(objekti, texcoat)
+ createnodes(mat_list, texcoat)
def checkmaterial(mat_list, objekti): #check how many materials object has
mat_list = []
@@ -80,7 +75,7 @@ def checkmaterial(mat_list, objekti): #check how many materials object has
if(obj_mate.material.use_nodes == False):
obj_mate.material.use_nodes = True
-def createnodes(objekti,texcoat): #luo nodes palikat ja linkittaa tekstuurit niihin
+def createnodes(mat_list,texcoat): #luo nodes palikat ja linkittaa tekstuurit niihin
bring_color = True #naiden tarkoitus on tsekata onko tarvetta luoda uusi node vai riittaako paivitys
bring_metalness = True
bring_roughness = True
@@ -88,15 +83,16 @@ def createnodes(objekti,texcoat): #luo nodes palikat ja linkittaa tekstuurit nii
bring_disp = True
coat3D = bpy.context.scene.coat3D
+ coatMat = mat_list[0]
- if(objekti.active_material.use_nodes == False):
- objekti.active_material.use_nodes = True
- act_material = objekti.active_material.node_tree
- main_material = objekti.active_material.node_tree
+ if(coatMat.use_nodes == False):
+ coatMat.use_nodes = True
+ act_material = coatMat.node_tree
+ main_material = coatMat.node_tree
applink_group_node = False
#ensimmaiseksi kaydaan kaikki image nodet lapi ja tarkistetaan onko nimi 3DC alkunen jos on niin reload
-
+ print('texcoat:',texcoat)
for node in act_material.nodes:
if(node.name == '3DC_Applink' and node.type == 'GROUP'):
applink_group_node = True
@@ -107,7 +103,6 @@ def createnodes(objekti,texcoat): #luo nodes palikat ja linkittaa tekstuurit nii
for node in act_material.nodes:
if(node.type == 'TEX_IMAGE'):
if(node.name == '3DC_color'):
- print('halloo helsinki')
bring_color = False
node.image.reload()
elif(node.name == '3DC_metalness'):
@@ -140,10 +135,21 @@ def createnodes(objekti,texcoat): #luo nodes palikat ja linkittaa tekstuurit nii
input_index = 0
#Color
if(bring_color == True and texcoat['color'] != []):
+ print('image:', bpy.data.images)
node = act_material.nodes.new('ShaderNodeTexImage')
node.name = '3DC_color'
if (texcoat['color']):
- node.image = bpy.data.images.load(texcoat['color'][0])
+ sameimage = False
+ for image in bpy.data.images:
+ if(image.filepath == texcoat['color'][0]):
+ sameimage = True
+ imagename = image
+ break
+
+ if sameimage == True:
+ node.image = imagename
+ else:
+ node.image = bpy.data.images.load(texcoat['color'][0])
if(coat3D.createnodes):
curvenode = act_material.nodes.new('ShaderNodeRGBCurve')
curvenode.name = '3DC_RGBCurve'
@@ -172,7 +178,6 @@ def createnodes(objekti,texcoat): #luo nodes palikat ja linkittaa tekstuurit nii
node.location = -400,400
if (input_color != -1):
act_material.links.new(node.outputs[0], glue_mat.inputs[input_color])
-
#Metalness
if(bring_metalness == True and texcoat['metalness'] != []):
node = act_material.nodes.new('ShaderNodeTexImage')
@@ -266,7 +271,7 @@ def createnodes(objekti,texcoat): #luo nodes palikat ja linkittaa tekstuurit nii
-def matlab(mat_list, objekti, scene,is_new):
+def matlab(objekti,mat_list,texturelist,is_new):
''' FBX Materials: remove all nodes and create princibles node'''
if(is_new):
@@ -274,6 +279,6 @@ def matlab(mat_list, objekti, scene,is_new):
'''Main Loop for Texture Update'''
#checkmaterial(mat_list, objekti)
- readtexturefolder(objekti,is_new)
+ readtexturefolder(mat_list,texturelist,is_new)
return('FINISHED')