~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/addons/render_povray/render.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-02-19 11:24:23 UTC
  • mfrom: (14.2.23 sid)
  • Revision ID: package-import@ubuntu.com-20140219112423-rkmaz2m7ha06d4tk
Tags: 2.69-3ubuntu1
* Merge with Debian; remaining changes:
  - Configure without OpenImageIO on armhf, as it is not available on
    Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
312
312
 
313
313
 
314
314
        comments = scene.pov.comments_enable
315
 
        
 
315
 
316
316
        if material:
317
 
            if (material.specular_color.r == material.specular_color.g) and (material.specular_color.r == material.specular_color.b):
318
 
                colored_specular_found = False
319
 
            else:
320
 
                colored_specular_found = True
321
 
        
322
 
        
323
 
        
 
317
            colored_specular_found = (material.specular_color.s > 0.0)
 
318
 
324
319
        ##################
325
320
        # Several versions of the finish: Level conditions are variations for specular/Mirror
326
321
        # texture channel map with alternative finish of 0 specular and no mirror reflection.
751
746
#            # Grab materials attached to object instances ...
752
747
#            if hasattr(ob, 'material_slots'):
753
748
#                for ms in ob.material_slots:
754
 
#                    if ms.material != None and ms.link == 'OBJECT':
 
749
#                    if ms.material is not None and ms.link == 'OBJECT':
755
750
#                        if ms.material in obmatslist:
756
751
#                            return False
757
752
#                        else:
761
756
#            # Grab materials attached to object instances ...
762
757
#            if hasattr(ob, 'material_slots'):
763
758
#                for ms in ob.material_slots:
764
 
#                    if ms.material != None and ms.link == 'OBJECT':
 
759
#                    if ms.material is not None and ms.link == 'OBJECT':
765
760
#                        # If there is at least one material slot linked to the object
766
761
#                        # and not the data (mesh), always create a new, "private" data instance.
767
762
#                        return True
779
774
                has_local_mats = False
780
775
                key = [dataname]
781
776
                for ms in ob.material_slots:
782
 
                    if ms.material != None:
 
777
                    if ms.material is not None:
783
778
                        key.append(ms.material.name)
784
779
                        if ms.link == 'OBJECT' and not has_local_mats:
785
780
                            has_local_mats = True
881
876
                                        file.write('%i,\n' % (steps))
882
877
                                        
883
878
                                    for step in range(0, steps):
884
 
                                        co = pSys.co_hair(ob, mod, pindex, step)
 
879
                                        co = pSys.co_hair(ob, pindex, step)
885
880
                                    #for controlPoint in particle.hair_keys:
886
881
                                        if pSys.settings.clump_factor != 0:
887
882
                                            hDiameter = pSys.settings.clump_factor / 200.0 * random.uniform(0.5, 1)
1003
998
            name = string_strip_hyphen(bpy.path.clean_name(name_orig))
1004
999
            dataname = string_strip_hyphen(bpy.path.clean_name(dataname_orig))
1005
1000
##            for slot in ob.material_slots:
1006
 
##                if slot.material != None and slot.link == 'OBJECT':
 
1001
##                if slot.material is not None and slot.link == 'OBJECT':
1007
1002
##                    obmaterial = slot.material
1008
1003
 
1009
1004
#############################################
1186
1181
                        LocalMaterialNames = []                        
1187
1182
                        for col, index in vertCols.items():
1188
1183
                            #if me_materials:
1189
 
                            material = me_materials[col[3]]
1190
 
                            if me_materials == None: #XXX working?
 
1184
                            mater = me_materials[col[3]]
 
1185
                            if me_materials is None: #XXX working?
1191
1186
                                material_finish = DEF_MAT_NAME  # not working properly,
1192
1187
                                trans = 0.0
1193
1188
 
1194
1189
                            else:
1195
 
                                material_finish = materialNames[material.name]                        
1196
 
                                if material.use_transparency:
1197
 
                                    trans = 1.0 - material.alpha
 
1190
                                material_finish = materialNames[mater.name]                        
 
1191
                                if mater.use_transparency:
 
1192
                                    trans = 1.0 - mater.alpha
1198
1193
                                else:
1199
1194
                                    trans = 0.0                            
1200
 
                                if (material.specular_color.r == material.specular_color.g) and (material.specular_color.r == material.specular_color.b):
 
1195
                                if (mater.specular_color.r == mater.specular_color.g) and (mater.specular_color.r == mater.specular_color.b):
1201
1196
                                    colored_specular_found = False
1202
1197
                                else:
1203
1198
                                    colored_specular_found = True
1204
1199
 
1205
 
                                if material.use_transparency and material.transparency_method == 'RAYTRACE':
1206
 
                                    povFilter = material.raytrace_transparency.filter * (1.0 - material.alpha)
1207
 
                                    trans = (1.0 - material.alpha) - povFilter
 
1200
                                if mater.use_transparency and mater.transparency_method == 'RAYTRACE':
 
1201
                                    povFilter = mater.raytrace_transparency.filter * (1.0 - mater.alpha)
 
1202
                                    trans = (1.0 - mater.alpha) - povFilter
1208
1203
                                else:
1209
1204
                                    povFilter = 0.0
1210
1205
                                    
1213
1208
                                texturesSpec = ""
1214
1209
                                texturesNorm = ""
1215
1210
                                texturesAlpha = ""
1216
 
                                for t in material.texture_slots:
 
1211
                                for t in mater.texture_slots:
1217
1212
                                    if t and t.texture.type == 'IMAGE' and t.use and t.texture.image:
1218
1213
                                        image_filename = path_image(t.texture.image)
1219
1214
                                        imgGamma = ""
1247
1242
                                file.write("\n")
1248
1243
                                # THIS AREA NEEDS TO LEAVE THE TEXTURE OPEN UNTIL ALL MAPS ARE WRITTEN DOWN.
1249
1244
                                # --MR
1250
 
                                currentMatName = string_strip_hyphen(materialNames[material.name])
 
1245
                                currentMatName = string_strip_hyphen(materialNames[mater.name])
1251
1246
                                LocalMaterialNames.append(currentMatName)
1252
1247
                                file.write("\n #declare MAT_%s = \ntexture{\n" % currentMatName)
1253
1248
 
1254
1249
                                ################################################################################
1255
 
                                if material.diffuse_shader == 'MINNAERT':
 
1250
                                
 
1251
                                if mater.pov.replacement_text != "":
 
1252
                                    file.write("%s\n" % mater.pov.replacement_text)
 
1253
                                #################################################################################
 
1254
                                if mater.diffuse_shader == 'MINNAERT':
1256
1255
                                    tabWrite("\n")
1257
1256
                                    tabWrite("aoi\n")
1258
1257
                                    tabWrite("texture_map {\n")
1259
1258
                                    tabWrite("[%.3g finish {diffuse %.3g}]\n" % \
1260
 
                                             (material.darkness / 2.0, 2.0 - material.darkness))
1261
 
                                    tabWrite("[%.3g\n" % (1.0 - (material.darkness / 2.0)))
 
1259
                                             (mater.darkness / 2.0, 2.0 - mater.darkness))
 
1260
                                    tabWrite("[%.3g\n" % (1.0 - (mater.darkness / 2.0)))
1262
1261
 
1263
 
                                if material.diffuse_shader == 'FRESNEL':
 
1262
                                if mater.diffuse_shader == 'FRESNEL':
1264
1263
                                    # For FRESNEL diffuse in POV, we'll layer slope patterned textures
1265
1264
                                    # with lamp vector as the slope vector and nest one slope per lamp
1266
1265
                                    # into each texture map's entry.
1272
1271
                                        # Diffuse Fresnel value and factor go up to five,
1273
1272
                                        # other kind of values needed: used the number 5 below to remap
1274
1273
                                        tabWrite("[%.3g finish {diffuse %.3g}]\n" % \
1275
 
                                                 ((5.0 - material.diffuse_fresnel) / 5,
1276
 
                                                  (material.diffuse_intensity *
1277
 
                                                   ((5.0 - material.diffuse_fresnel_factor) / 5))))
1278
 
                                        tabWrite("[%.3g\n" % ((material.diffuse_fresnel_factor / 5) *
1279
 
                                                              (material.diffuse_fresnel / 5.0)))
 
1274
                                                 ((5.0 - mater.diffuse_fresnel) / 5,
 
1275
                                                  (mater.diffuse_intensity *
 
1276
                                                   ((5.0 - mater.diffuse_fresnel_factor) / 5))))
 
1277
                                        tabWrite("[%.3g\n" % ((mater.diffuse_fresnel_factor / 5) *
 
1278
                                                              (mater.diffuse_fresnel / 5.0)))
1280
1279
                                        c += 1
1281
1280
 
1282
1281
                                # if shader is a 'FRESNEL' or 'MINNAERT': slope pigment pattern or aoi
1414
1413
                                    ##################Second index for mapping specular max value###############
1415
1414
                                        tabWrite("[1 \n")
1416
1415
 
1417
 
                                if texturesDif == "" and material.pov.replacement_text == "":
 
1416
                                if texturesDif == "" and mater.pov.replacement_text == "":
1418
1417
                                    if texturesAlpha != "":
1419
1418
                                        # POV-Ray "scale" is not a number of repetitions factor, but its inverse,
1420
1419
                                        # a standard scale factor.
1455
1454
                                        # Level 2 is translated specular
1456
1455
                                        tabWrite("finish {%s}\n" % (safety(material_finish, Level=2)))
1457
1456
 
1458
 
                                elif material.pov.replacement_text == "":
 
1457
                                elif mater.pov.replacement_text == "":
1459
1458
                                    # POV-Ray "scale" is not a number of repetitions factor, but its inverse,
1460
1459
                                    # a standard scale factor.
1461
1460
                                    # Offset seems needed relatively to scale so probably center of the scale is
1514
1513
                                    #           "{%s \"%s\" %s}%s} finish {%s}" % \
1515
1514
                                    #           (imageFormat(texturesDif), texturesDif,imgMap(t_dif),
1516
1515
                                    #            mappingDif, safety(material_finish)))
1517
 
                                if texturesNorm != "" and material.pov.replacement_text == "":
 
1516
                                if texturesNorm != "" and mater.pov.replacement_text == "":
1518
1517
                                    ## scale 1 rotate y*0
1519
1518
                                    # POV-Ray "scale" is not a number of repetitions factor, but its inverse,
1520
1519
                                    # a standard scale factor.
1529
1528
                                    tabWrite("normal {uv_mapping bump_map {%s \"%s\" %s  bump_size %.4g }%s}\n" % \
1530
1529
                                             (imageFormat(texturesNorm), texturesNorm, imgMap(t_nor),
1531
1530
                                              t_nor.normal_factor * 10.0, mappingNor))
1532
 
                                if texturesSpec != "" and material.pov.replacement_text == "":
 
1531
                                if texturesSpec != "" and mater.pov.replacement_text == "":
1533
1532
                                    tabWrite("]\n")
1534
1533
 
1535
1534
                                    tabWrite("}\n")
1536
1535
 
1537
1536
                                #End of slope/ior texture_map
1538
 
                                if material.diffuse_shader == 'MINNAERT' and material.pov.replacement_text == "":
 
1537
                                if mater.diffuse_shader == 'MINNAERT' and mater.pov.replacement_text == "":
1539
1538
                                    tabWrite("]\n")
1540
1539
                                    tabWrite("}\n")
1541
 
                                if material.diffuse_shader == 'FRESNEL' and material.pov.replacement_text == "":
 
1540
                                if mater.diffuse_shader == 'FRESNEL' and mater.pov.replacement_text == "":
1542
1541
                                    c = 1
1543
1542
                                    while (c <= lampCount):
1544
1543
                                        tabWrite("]\n")
1550
1549
                                # Close first layer of POV "texture" (Blender material)
1551
1550
                                tabWrite("}\n")
1552
1551
                                
1553
 
                                if (material.specular_color.r == material.specular_color.g) and (material.specular_color.r == material.specular_color.b):
 
1552
                                if (mater.specular_color.r == mater.specular_color.g) and (mater.specular_color.r == mater.specular_color.b):
1554
1553
                                    colored_specular_found = False
1555
1554
                                else:
1556
1555
                                    colored_specular_found = True
1558
1557
                                # Write another layered texture using invisible diffuse and metallic trick 
1559
1558
                                # to emulate colored specular highlights
1560
1559
                                special_texture_found = False
1561
 
                                for t in material.texture_slots:
 
1560
                                for t in mater.texture_slots:
1562
1561
                                    if(t and t.texture.type == 'IMAGE' and t.use and t.texture.image and
1563
1562
                                       (t.use_map_specular or t.use_map_raymir)):
1564
1563
                                        # Specular mapped textures would conflict with colored specular
1573
1572
                                
1574
1573
                                    tabWrite("texture {\n")
1575
1574
                                    tabWrite("pigment {rgbft<%.3g, %.3g, %.3g, 0, 1>}\n" % \
1576
 
                                                     (material.specular_color[0], material.specular_color[1], material.specular_color[2]))
 
1575
                                                     (mater.specular_color[0], mater.specular_color[1], mater.specular_color[2]))
1577
1576
                                    tabWrite("finish {%s}\n" % (safety(material_finish, Level=2))) # Level 2 is translated spec
1578
1577
 
1579
1578
                                    texturesNorm = ""
1580
 
                                    for t in material.texture_slots:
 
1579
                                    for t in mater.texture_slots:
1581
1580
                                        if t and t.texture.type == 'IMAGE' and t.use and t.texture.image:
1582
1581
                                            image_filename = path_image(t.texture.image)
1583
1582
                                            imgGamma = ""
1608
1607
                tabWrite("texture_list {\n")
1609
1608
                file.write(tabStr + "%s" % (len(vertCols)))  # vert count
1610
1609
                    
1611
 
                if material.pov.replacement_text != "":
 
1610
                if mater.pov.replacement_text != "":
1612
1611
                    file.write("\n")
1613
1612
                    file.write(" texture{%s}\n" % material.pov.replacement_text)
1614
1613
 
1971
1970
        tabWrite("}\n")
1972
1971
 
1973
1972
    def exportCustomCode():
1974
 
 
 
1973
        # Write CurrentAnimation Frame for use in Custom POV Code
 
1974
        file.write("#declare CURFRAMENUM = %d;\n" % bpy.context.scene.frame_current)
 
1975
        #Change path and uncomment to add an animated include file by hand:
 
1976
        file.write("//#include \"/home/user/directory/animation_include_file.inc\"\n")
1975
1977
        for txt in bpy.data.texts:
1976
1978
            if txt.pov.custom_code:
1977
1979
                # Why are the newlines needed?
1988
1990
    file.write("#version 3.7;\n")
1989
1991
 
1990
1992
    if not scene.pov.tempfiles_enable and comments:
1991
 
        file.write("\n//--CUSTOM CODE--\n\n")
 
1993
        file.write("\n//--Global settings--\n\n")
 
1994
 
 
1995
    exportGlobalSettings(scene)
 
1996
 
 
1997
    
 
1998
    if not scene.pov.tempfiles_enable and comments:
 
1999
        file.write("\n//--Custom Code--\n\n")
1992
2000
    exportCustomCode()
1993
 
 
1994
 
    if not scene.pov.tempfiles_enable and comments:
1995
 
        file.write("\n//--Global settings and background--\n\n")
1996
 
 
1997
 
    exportGlobalSettings(scene)
1998
 
 
1999
 
    if not scene.pov.tempfiles_enable and comments:
2000
 
        file.write("\n")
 
2001
    
 
2002
    if not scene.pov.tempfiles_enable and comments:
 
2003
        file.write("\n//--Background--\n\n")
2001
2004
 
2002
2005
    exportWorld(scene.world)
2003
2006