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>2011-09-05 18:08:00 +0400
committerKalle-Samuli Riihikoski <haikalle@gmail.com>2011-09-05 18:08:00 +0400
commit6efe8ccf551e9c3dd7354387da3cf6256dac5bf8 (patch)
treea91557223cc0ad729515b8dd2a7a36c27735283b /io_coat3D/tex.py
parentbc9b0b19ff61eee9b008cd60bcd27137c51712a4 (diff)
Cleaning the code. Also added support for multres objects.
Diffstat (limited to 'io_coat3D/tex.py')
-rw-r--r--io_coat3D/tex.py156
1 files changed, 35 insertions, 121 deletions
diff --git a/io_coat3D/tex.py b/io_coat3D/tex.py
index d3b5f56d..816dacd3 100644
--- a/io_coat3D/tex.py
+++ b/io_coat3D/tex.py
@@ -20,26 +20,6 @@
import bpy
import os
-def objname(path):
-
- path2 = os.path.dirname(path) + os.sep
- pituus = len(path2)
- nimi = path[pituus:]
- return nimi
-
-def justname(name):
- monesko = name.rfind('.')
- justname = name[:monesko]
- return justname
-
-def setgallery():
- newname =''
- tex_name =[]
- index_tex = 0
- for tt in bpy.data.textures:
- tex_name.append(tt.name)
- return tex_name
-
def find_index(objekti):
luku = 0
for tex in objekti.active_material.texture_slots:
@@ -52,7 +32,6 @@ def gettex(mat_list, objekti, scene,export):
coat3D = bpy.context.scene.coat3D
-
if(bpy.context.scene.render.engine == 'VRAY_RENDER' or bpy.context.scene.render.engine == 'VRAY_RENDER_PREVIEW'):
vray = True
else:
@@ -77,7 +56,7 @@ def gettex(mat_list, objekti, scene,export):
if(export):
objekti.coat3D.objpath = export
- nimi = objname(export)
+ nimi = os.path.split(export)[1]
osoite = os.path.dirname(export) + os.sep
for mate in objekti.material_slots:
for tex_slot in mate.material.texture_slots:
@@ -87,13 +66,12 @@ def gettex(mat_list, objekti, scene,export):
tex_slot.texture.image.reload()
else:
coa = objekti.coat3D
- nimi = objname(coa.objectdir)
+ nimi = os.path.split(coa.objectdir)[1]
if(coa.texturefolder):
osoite = os.path.dirname(coa.texturefolder) + os.sep
else:
osoite = os.path.dirname(coa.objectdir) + os.sep
- just_nimi = justname(nimi)
- just_nimi += '_'
+ just_nimi = os.path.splitext(nimi)[0] + '_'
just_nimi_len = len(just_nimi)
if(len(objekti.material_slots) != 0):
@@ -123,69 +101,40 @@ def gettex(mat_list, objekti, scene,export):
koko += osoite
koko += yy
texcoat[tex_name].append(koko)
- #date = os.path.getmtime(texcoat[tex_name][0])
if((texcoat['color'] or texcoat['nmap'] or texcoat['disp'] or texcoat['specular']) and (len(objekti.material_slots)) == 0):
- index = 0
- tuli = False
- lasku = False
- while(lasku == False):
- tuli = False
- new_mat = ("Material.%03d"%(index))
- for i in bpy.data.materials:
- if(i.name == new_mat):
- tuli = True
- break
- if(tuli):
- index += 1
- else:
- lasku = True
- bpy.data.materials.new(new_mat)
+ materials_old = bpy.data.materials.keys()
+ bpy.ops.material.new()
+ materials_new = bpy.data.materials.keys()
+ new_ma = list(set(materials_new).difference(set(materials_old)))
+ new_mat = new_ma[0]
ki = bpy.data.materials[new_mat]
objekti.data.materials.append(ki)
if(bring_color == 1 and texcoat['color']):
- name_tex ='Color_'
- num = []
-
index = find_index(objekti)
-
-
tex = bpy.ops.Texture
objekti.active_material.texture_slots.create(index)
total_mat = len(objekti.active_material.texture_slots.items())
useold = ''
for seekco in bpy.data.textures:
- if((seekco.name[:6] == 'Color_') and (seekco.users_material == ())):
+ if((seekco.name[:5] == 'Color') and (seekco.users_material == ())):
useold = seekco
if(useold == ''):
- indexx = 0
- tuli = False
- lasku = False
- while(lasku == False):
- tuli = False
- name_tex = ("Color_%s"%(indexx))
- for i in bpy.data.textures:
- if(i.name == name_tex):
- tuli = True
- break
- if(tuli):
- indexx += 1
- else:
- lasku = True
-
+ textures_old = bpy.data.textures.keys()
+ bpy.data.textures.new('Color',type='IMAGE')
+ textures_new = bpy.data.textures.keys()
+ name_te = list(set(textures_new).difference(set(textures_old)))
+ name_tex = name_te[0]
bpy.ops.image.new(name=name_tex)
bpy.data.images[name_tex].filepath = texcoat['color'][0]
bpy.data.images[name_tex].source = 'FILE'
-
-
- bpy.data.textures.new(name_tex,type='IMAGE')
objekti.active_material.texture_slots[index].texture = bpy.data.textures[name_tex]
objekti.active_material.texture_slots[index].texture.image = bpy.data.images[name_tex]
@@ -207,9 +156,6 @@ def gettex(mat_list, objekti, scene,export):
if(bring_normal == 1 and texcoat['nmap']):
- name_tex ='Normal_'
- num = []
-
index = find_index(objekti)
tex = bpy.ops.Texture
objekti.active_material.texture_slots.create(index)
@@ -217,38 +163,28 @@ def gettex(mat_list, objekti, scene,export):
useold = ''
for seekco in bpy.data.textures:
- if((seekco.name[:7] == 'Normal_') and (seekco.users_material == ())):
+ if((seekco.name[:6] == 'Normal') and (seekco.users_material == ())):
useold = seekco
if(useold == ''):
- indexx = 0
- tuli = False
- lasku = False
- while(lasku == False):
- tuli = False
- name_tex = ("Normal_%s"%(indexx))
- for i in bpy.data.textures:
- if(i.name == name_tex):
- tuli = True
- break
- if(tuli):
- indexx += 1
- else:
- lasku = True
+ textures_old = bpy.data.textures.keys()
+ bpy.data.textures.new('Normal',type='IMAGE')
+ textures_new = bpy.data.textures.keys()
+ name_te = list(set(textures_new).difference(set(textures_old)))
+ name_tex = name_te[0]
bpy.ops.image.new(name=name_tex)
bpy.data.images[name_tex].filepath = texcoat['nmap'][0]
bpy.data.images[name_tex].source = 'FILE'
-
- bpy.data.textures.new(name_tex,type='IMAGE')
objekti.active_material.texture_slots[index].texture = bpy.data.textures[name_tex]
objekti.active_material.texture_slots[index].texture.image = bpy.data.images[name_tex]
if(objekti.data.uv_textures.active):
objekti.active_material.texture_slots[index].texture_coords = 'UV'
objekti.active_material.texture_slots[index].uv_layer = objekti.data.uv_textures.active.name
+
objekti.active_material.texture_slots[index].use_map_color_diffuse = False
objekti.active_material.texture_slots[index].use_map_normal = True
@@ -277,7 +213,6 @@ def gettex(mat_list, objekti, scene,export):
if(bring_spec == 1 and texcoat['specular']):
- name_tex ='Specular_'
index = find_index(objekti)
@@ -285,38 +220,28 @@ def gettex(mat_list, objekti, scene,export):
useold = ''
for seekco in bpy.data.textures:
- if((seekco.name[:9] == 'Specular_') and (seekco.users_material == ())):
+ if((seekco.name[:8] == 'Specular') and (seekco.users_material == ())):
useold = seekco
if(useold == ''):
- indexx = 0
- tuli = False
- lasku = False
- while(lasku == False):
- tuli = False
- name_tex = ("Specular_%s"%(indexx))
- for i in bpy.data.textures:
- if(i.name == name_tex):
- tuli = True
- break
- if(tuli):
- indexx += 1
- else:
- lasku = True
+ textures_old = bpy.data.textures.keys()
+ bpy.data.textures.new('Specular',type='IMAGE')
+ textures_new = bpy.data.textures.keys()
+ name_te = list(set(textures_new).difference(set(textures_old)))
+ name_tex = name_te[0]
bpy.ops.image.new(name=name_tex)
bpy.data.images[name_tex].filepath = texcoat['specular'][0]
bpy.data.images[name_tex].source = 'FILE'
-
- bpy.data.textures.new(name_tex,type='IMAGE')
objekti.active_material.texture_slots[index].texture = bpy.data.textures[name_tex]
objekti.active_material.texture_slots[index].texture.image = bpy.data.images[name_tex]
if(objekti.data.uv_textures.active):
objekti.active_material.texture_slots[index].texture_coords = 'UV'
objekti.active_material.texture_slots[index].uv_layer = objekti.data.uv_textures.active.name
+
objekti.active_material.texture_slots[index].use_map_color_diffuse = False
objekti.active_material.texture_slots[index].use_map_specular = True
@@ -335,7 +260,6 @@ def gettex(mat_list, objekti, scene,export):
objekti.active_material.texture_slots[index].use_map_specular = True
if(bring_disp == 1 and texcoat['disp']):
- name_tex ='Displacement_'
index = find_index(objekti)
@@ -344,38 +268,28 @@ def gettex(mat_list, objekti, scene,export):
useold = ''
for seekco in bpy.data.textures:
- if((seekco.name[:13] == 'Displacement_') and (seekco.users_material == ())):
+ if((seekco.name[:12] == 'Displacement') and (seekco.users_material == ())):
useold = seekco
if useold == "":
- indexx = 0
- tuli = False
- lasku = False
- while(lasku == False):
- tuli = False
- name_tex = ("Displacement_%s"%(indexx))
- for i in bpy.data.textures:
- if(i.name == name_tex):
- tuli = True
- break
- if(tuli):
- indexx += 1
- else:
- lasku = True
+ textures_old = bpy.data.textures.keys()
+ bpy.data.textures.new('Displacement',type='IMAGE')
+ textures_new = bpy.data.textures.keys()
+ name_te = list(set(textures_new).difference(set(textures_old)))
+ name_tex = name_te[0]
bpy.ops.image.new(name=name_tex)
bpy.data.images[name_tex].filepath = texcoat['disp'][0]
bpy.data.images[name_tex].source = 'FILE'
-
- bpy.data.textures.new(name_tex,type='IMAGE')
objekti.active_material.texture_slots[index].texture = bpy.data.textures[name_tex]
objekti.active_material.texture_slots[index].texture.image = bpy.data.images[name_tex]
if(objekti.data.uv_textures.active):
objekti.active_material.texture_slots[index].texture_coords = 'UV'
objekti.active_material.texture_slots[index].uv_layer = objekti.data.uv_textures.active.name
+
objekti.active_material.texture_slots[index].use_map_color_diffuse = False
objekti.active_material.texture_slots[index].use_map_displacement = True