~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/addons/io_coat3D/tex.py

  • Committer: Bazaar Package Importer
  • Author(s): Kevin Roy
  • Date: 2011-06-24 11:13:28 UTC
  • mto: (14.1.6 experimental) (1.5.1)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20110624111328-27ribg6l36edf2ay
Tags: upstream-2.58-svn37702
ImportĀ upstreamĀ versionĀ 2.58-svn37702

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import os
3
3
import filecmp
4
4
 
5
 
 
6
5
def objname(path):
7
6
 
8
7
    path2 = os.path.dirname(path) + os.sep
9
8
    pituus = len(path2)
10
9
    nimi = path[pituus:]
11
 
 
12
10
    return nimi
13
11
 
14
12
def justname(name):
30
28
                if(not(hasattr(tex,'texture'))):
31
29
                        break
32
30
                luku = luku +1
33
 
                
34
 
 
35
31
        return luku
36
32
 
37
33
def gettex(mat_list, objekti, scene,export):
44
40
    else:
45
41
        vray = False
46
42
    
47
 
        
48
 
    
49
43
    take_color = 0;
50
44
    take_spec = 0;
51
45
    take_normal = 0;
71
65
            for tex_slot in mate.material.texture_slots:
72
66
                if(hasattr(tex_slot,'texture')):
73
67
                    if(tex_slot.texture.type == 'IMAGE'):
74
 
                                                tex_slot.texture.image.reload()
 
68
                        if tex_slot.texture.image is not None:
 
69
                            tex_slot.texture.image.reload()
75
70
    else:
76
 
        coa = bpy.context.scene.objects.active.coat3D
 
71
        coa = objekti.coat3D
77
72
        nimi = objname(coa.objectdir)
78
73
        if(coa.texturefolder):
79
74
            osoite = os.path.dirname(coa.texturefolder) + os.sep
83
78
    just_nimi += '_'
84
79
    just_nimi_len = len(just_nimi)
85
80
        
86
 
    
87
81
    if(len(objekti.material_slots) != 0):
88
82
        for obj_tex in objekti.active_material.texture_slots:
89
83
            if(hasattr(obj_tex,'texture')):
114
108
        #date = os.path.getmtime(texcoat[tex_name][0])
115
109
 
116
110
    if((texcoat['color'] or texcoat['nmap'] or texcoat['disp'] or texcoat['specular']) and (len(objekti.material_slots)) == 0):
117
 
        new_mat = ("%s_Material"%(objekti.name))
 
111
        index = 0
 
112
        tuli = False
 
113
        lasku = False
 
114
        while(lasku == False):
 
115
            tuli = False
 
116
            new_mat = ("Material.%03d"%(index))
 
117
            for i in bpy.data.materials:
 
118
                if(i.name == new_mat):
 
119
                    tuli = True
 
120
                    break
 
121
            if(tuli):
 
122
                index += 1
 
123
            else:
 
124
                lasku = True
118
125
        bpy.data.materials.new(new_mat)
119
126
        ki = bpy.data.materials[new_mat]
120
127
        objekti.data.materials.append(ki)
121
128
        
122
 
        
123
 
            
124
129
    if(bring_color == 1 and texcoat['color']):
125
130
        name_tex ='Color_'
126
131
        num = []
138
143
                useold = seekco
139
144
 
140
145
 
141
 
 
142
146
        if(useold == ''):
143
147
 
144
 
            tex_name = setgallery()
145
 
 
146
 
            for num_tex in tex_name:
147
 
                if(num_tex[:6] == 'Color_'):
148
 
                    num.append(num_tex)
149
 
            luku_tex = len(num)
150
 
            name_tex = ('Color_%s'%(luku_tex))
 
148
            indexx = 0
 
149
            tuli = False
 
150
            lasku = False
 
151
            while(lasku == False):
 
152
                tuli = False
 
153
                name_tex = ("Color_%s"%(indexx))
 
154
                for i in bpy.data.textures:
 
155
                    if(i.name == name_tex):
 
156
                        tuli = True
 
157
                        break
 
158
                if(tuli):
 
159
                    indexx += 1
 
160
                else:
 
161
                    lasku = True
 
162
                
151
163
 
152
164
            bpy.ops.image.new(name=name_tex)
153
165
            bpy.data.images[name_tex].filepath = texcoat['color'][0]
154
166
            bpy.data.images[name_tex].source = 'FILE'
155
167
            
 
168
            
156
169
 
157
170
            bpy.data.textures.new(name_tex,type='IMAGE')
158
171
            objekti.active_material.texture_slots[index].texture = bpy.data.textures[name_tex]
166
179
            
167
180
 
168
181
        elif(useold != ''):
169
 
            
 
182
                        
170
183
            objekti.active_material.texture_slots[index].texture = useold
171
184
            objekti.active_material.texture_slots[index].texture.image.filepath = texcoat['color'][0]
172
185
            if(objekti.data.uv_textures.active):
178
191
        num = []
179
192
        
180
193
        index = find_index(objekti)
181
 
        
182
 
 
183
194
        tex = bpy.ops.Texture
184
195
        objekti.active_material.texture_slots.create(index)
185
196
        total_mat = len(objekti.active_material.texture_slots.items())
189
200
            if((seekco.name[:7] == 'Normal_') and (seekco.users_material == ())):
190
201
                useold = seekco
191
202
 
192
 
        
193
 
 
194
203
        if(useold == ''):
195
204
 
196
 
            tex_name = setgallery()
197
 
 
198
 
            for num_tex in tex_name:
199
 
                if(num_tex[:7] == 'Normal_'):
200
 
                    num.append(num_tex)
201
 
            luku_tex = len(num)
202
 
            name_tex = ('Normal_%s'%(luku_tex))
 
205
            indexx = 0
 
206
            tuli = False
 
207
            lasku = False
 
208
            while(lasku == False):
 
209
                tuli = False
 
210
                name_tex = ("Normal_%s"%(indexx))
 
211
                for i in bpy.data.textures:
 
212
                    if(i.name == name_tex):
 
213
                        tuli = True
 
214
                        break
 
215
                if(tuli):
 
216
                    indexx += 1
 
217
                else:
 
218
                    lasku = True
203
219
 
204
220
            bpy.ops.image.new(name=name_tex)
205
221
            bpy.data.images[name_tex].filepath = texcoat['nmap'][0]
223
239
            else:
224
240
                bpy.data.textures[name_tex].use_normal_map = True
225
241
                objekti.active_material.texture_slots[index].normal_map_space = 'TANGENT'
226
 
                objekti.active_material.texture_slots[index].normal_factor = -1
 
242
                objekti.active_material.texture_slots[index].normal_factor = 1
227
243
 
228
244
            
229
245
 
236
252
                objekti.active_material.texture_slots[index].uv_layer = objekti.data.uv_textures.active.name
237
253
            objekti.active_material.texture_slots[index].use_map_color_diffuse = False
238
254
            objekti.active_material.texture_slots[index].use_map_normal = True
239
 
            objekti.active_material.texture_slots[index].normal_factor = -1
 
255
            objekti.active_material.texture_slots[index].normal_factor = 1
240
256
 
241
257
 
242
258
    if(bring_spec == 1 and texcoat['specular']):
260
276
 
261
277
        if(useold == ''):
262
278
 
263
 
            tex_name = setgallery()
264
 
 
265
 
            for num_tex in tex_name:
266
 
                if(num_tex[:9] == 'Specular_'):
267
 
                    num.append(num_tex)
268
 
            luku_tex = len(num)
269
 
            name_tex = ('Specular_%s'%(luku_tex))
 
279
            indexx = 0
 
280
            tuli = False
 
281
            lasku = False
 
282
            while(lasku == False):
 
283
                tuli = False
 
284
                name_tex = ("Specular_%s"%(indexx))
 
285
                for i in bpy.data.textures:
 
286
                    if(i.name == name_tex):
 
287
                        tuli = True
 
288
                        break
 
289
                if(tuli):
 
290
                    indexx += 1
 
291
                else:
 
292
                    lasku = True
270
293
 
271
294
            bpy.ops.image.new(name=name_tex)
272
295
            bpy.data.images[name_tex].filepath = texcoat['specular'][0]
317
340
 
318
341
        if(useold == ''):
319
342
 
320
 
            tex_name = setgallery()
321
 
 
322
 
            for num_tex in tex_name:
323
 
                if(num_tex[:13] == 'Displacement_'):
324
 
                    num.append(num_tex)
325
 
            luku_tex = len(num)
326
 
            name_tex = ('Displacement_%s'%(luku_tex))
 
343
            indexx = 0
 
344
            tuli = False
 
345
            lasku = False
 
346
            while(lasku == False):
 
347
                tuli = False
 
348
                name_tex = ("Displacement_%s"%(indexx))
 
349
                for i in bpy.data.textures:
 
350
                    if(i.name == name_tex):
 
351
                        tuli = True
 
352
                        break
 
353
                if(tuli):
 
354
                    indexx += 1
 
355
                else:
 
356
                    lasku = True
327
357
 
328
358
            bpy.ops.image.new(name=name_tex)
329
359
            bpy.data.images[name_tex].filepath = texcoat['disp'][0]