Skip to content
Snippets Groups Projects
render.py 251 KiB
Newer Older
  • Learn to ignore specific revisions
  • Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                matrix = global_matrix * ob.matrix_world
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                # Color is modified by energy #muiltiplie by 2 for a better match --Maurice
    
                color = tuple([c * lamp.energy * 2.0 for c in lamp.color])
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                tabWrite("light_source {\n")
                tabWrite("< 0,0,0 >\n")
                tabWrite("color rgb<%.3g, %.3g, %.3g>\n" % color)
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                if lamp.type == 'POINT':
    
    Luca Bonavita's avatar
    Luca Bonavita committed
                    pass
    
                elif lamp.type == 'SPOT':
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
                    # Falloff is the main radius from the centre line
    
                    tabWrite("falloff %.2f\n" % (degrees(lamp.spot_size) / 2.0))  # 1 TO 179 FOR BOTH
    
                    tabWrite("radius %.6f\n" % \
                             ((degrees(lamp.spot_size) / 2.0) * (1.0 - lamp.spot_blend)))
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
                    # Blender does not have a tightness equivilent, 0 is most like blender default.
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
    Luca Bonavita's avatar
    Luca Bonavita committed
                elif lamp.type == 'SUN':
    
                    tabWrite("parallel\n")
                    tabWrite("point_at  <0, 0, -1>\n")  # *must* be after 'parallel'
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
                elif lamp.type == 'AREA':
    
                    tabWrite("area_illumination\n")
                    tabWrite("fade_distance %.6f\n" % (lamp.distance / 2.0))
    
                    # Area lights have no falloff type, so always use blenders lamp quad equivalent
                    # for those?
                    tabWrite("fade_power %d\n" % 2)
    
    Luca Bonavita's avatar
    Luca Bonavita committed
                    size_x = lamp.size
                    samples_x = lamp.shadow_ray_samples_x
                    if lamp.shape == 'SQUARE':
                        size_y = size_x
                        samples_y = samples_x
                    else:
                        size_y = lamp.size_y
                        samples_y = lamp.shadow_ray_samples_y
    
    
                    tabWrite("area_light <%.6f,0,0>,<0,%.6f,0> %d, %d\n" % \
    
                             (size_x, size_y, samples_x, samples_y))
    
                    if lamp.shadow_ray_sample_method == 'CONSTANT_JITTERED':
    
    Luca Bonavita's avatar
    Luca Bonavita committed
                    else:
    
                        tabWrite("adaptive 1\n")
                        tabWrite("jitter\n")
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                # HEMI never has any shadow_method attribute
                if(not scene.render.use_shadows or lamp.type == 'HEMI' or
                   (lamp.type != 'HEMI' and lamp.shadow_method == 'NOSHADOW')):
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                # Sun shouldn't be attenuated. Hemi and area lights have no falloff attribute so they
                # are put to type 2 attenuation a little higher above.
    
                if lamp.type not in {'SUN', 'AREA', 'HEMI'}:
    
                    tabWrite("fade_distance %.6f\n" % (lamp.distance / 2.0))
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
                    if lamp.falloff_type == 'INVERSE_SQUARE':
    
                        tabWrite("fade_power %d\n" % 2)  # Use blenders lamp quad equivalent
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
                    elif lamp.falloff_type == 'INVERSE_LINEAR':
    
                        tabWrite("fade_power %d\n" % 1)  # Use blenders lamp linear
    
                    # supposing using no fade power keyword would default to constant, no attenuation.
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
                        pass
    
                    # Using Custom curve for fade power 3 for now.
                    elif lamp.falloff_type == 'CUSTOM_CURVE':
    
    Luca Bonavita's avatar
    Luca Bonavita committed
                writeMatrix(matrix)
    
    
    
                lampCount += 1
    
                # v(A,B) rotates vector A about origin by vector B.
    
                file.write("#declare lampTarget%s= vrotate(<%.4g,%.4g,%.4g>,<%.4g,%.4g,%.4g>);\n" % \
                           (lampCount, -(ob.location.x), -(ob.location.y), -(ob.location.z),
                            ob.rotation_euler.x, ob.rotation_euler.y, ob.rotation_euler.z))
    
    ####################################################################################################
    
    1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791
        def exportRainbows(rainbows):
            for ob in rainbows:
                povdataname = ob.data.name #enough?
                angle = degrees(ob.data.spot_size/2.5) #radians in blender (2
                width = ob.data.spot_blend *10
                distance = ob.data.shadow_buffer_clip_start 
                #eps=0.0000001
                #angle = br/(cr+eps) * 10 #eps is small epsilon variable to avoid dividing by zero
                #width = ob.dimensions[2] #now let's say width of rainbow is the actual proxy height
                # formerly:
                #cz-bz # let's say width of the rainbow is height of the cone (interfacing choice
                
                # v(A,B) rotates vector A about origin by vector B.
                # and avoid a 0 length vector by adding 1
                
                # file.write("#declare %s_Target= vrotate(<%.6g,%.6g,%.6g>,<%.4g,%.4g,%.4g>);\n" % \
                           # (povdataname, -(ob.location.x+0.1), -(ob.location.y+0.1), -(ob.location.z+0.1),
                            # ob.rotation_euler.x, ob.rotation_euler.y, ob.rotation_euler.z))                    
                
                direction = (ob.location.x,ob.location.y,ob.location.z) # not taking matrix into account
                rmatrix = global_matrix * ob.matrix_world
                
                #ob.rotation_euler.to_matrix().to_4x4() * mathutils.Vector((0,0,1))
                # XXX Is result of the below offset by 90 degrees?
                up =ob.matrix_world.to_3x3()[1].xyz #* global_matrix 
    
    
                # XXX TO CHANGE: 
                #formerly:
                #tabWrite("#declare %s = rainbow {\n"%povdataname) 
                
                # clumsy for now but remove the rainbow from instancing
                # system because not an object. use lamps later instead of meshes
                
                #del data_ref[dataname]
                tabWrite("rainbow {\n")
    
                tabWrite("angle %.4f\n"%angle)
                tabWrite("width %.4f\n"%width)
                tabWrite("distance %.4f\n"%distance)
                tabWrite("arc_angle %.4f\n"%ob.pov.arc_angle)
                tabWrite("falloff_angle %.4f\n"%ob.pov.falloff_angle)
                tabWrite("direction <%.4f,%.4f,%.4f>\n"%rmatrix.translation[:])
                tabWrite("up <%.4f,%.4f,%.4f>\n"%(up[0],up[1],up[2]))
                tabWrite("color_map {\n")
                tabWrite("[0.000  color rgbt<1.0, 0.5, 1.0, 1.0>]\n")
                tabWrite("[0.130  color rgbt<0.5, 0.5, 1.0, 0.9>]\n")
                tabWrite("[0.298  color rgbt<0.2, 0.2, 1.0, 0.7>]\n")
                tabWrite("[0.412  color rgbt<0.2, 1.0, 1.0, 0.4>]\n")
                tabWrite("[0.526  color rgbt<0.2, 1.0, 0.2, 0.4>]\n")
                tabWrite("[0.640  color rgbt<1.0, 1.0, 0.2, 0.4>]\n")
                tabWrite("[0.754  color rgbt<1.0, 0.5, 0.2, 0.6>]\n")
                tabWrite("[0.900  color rgbt<1.0, 0.2, 0.2, 0.7>]\n")
                tabWrite("[1.000  color rgbt<1.0, 0.2, 0.2, 1.0>]\n")
                tabWrite("}\n")
                
                
                povMatName = "Default_texture"
                #tabWrite("texture {%s}\n"%povMatName)
                write_object_modifiers(scene,ob,file)
                #tabWrite("rotate x*90\n")
                #matrix = global_matrix * ob.matrix_world
                #writeMatrix(matrix)
                tabWrite("}\n")
                #continue #Don't render proxy mesh, skip to next object
                
    ################################XXX LOFT, ETC.
        def exportCurves(scene, ob):
            name_orig = "OB" + ob.name
            dataname_orig = "DATA" + ob.data.name
    
            name = string_strip_hyphen(bpy.path.clean_name(name_orig))
            dataname = string_strip_hyphen(bpy.path.clean_name(dataname_orig))
    
            global_matrix = mathutils.Matrix.Rotation(-pi / 2.0, 4, 'X')
            matrix=global_matrix*ob.matrix_world
            bezier_sweep = False
            if ob.pov.curveshape == 'sphere_sweep':
                for spl in ob.data.splines:
                    if spl.type == "BEZIER":
                        bezier_sweep = True
            if ob.pov.curveshape in {'loft','birail'}:
                n=0
                for spline in ob.data.splines:
                    n+=1
                    tabWrite('#declare %s%s=spline {\n'%(dataname,n))
                    tabWrite('cubic_spline\n')
                    lp = len(spline.points)
                    delta = 1/(lp)
                    d=-delta
                    point = spline.points[lp-1]
                    x,y,z,w  = point.co[:]
                    tabWrite('%.6f, <%.6f,%.6f,%.6f>\n'%(d,x,y,z))
                    d+=delta
                    for point in spline.points:
                        x,y,z,w  = point.co[:]
                        tabWrite('%.6f, <%.6f,%.6f,%.6f>\n'%(d,x,y,z))
                        d+=delta
                    for i in range(2):
                        point = spline.points[i]
                        x,y,z,w  = point.co[:]
                        tabWrite('%.6f, <%.6f,%.6f,%.6f>\n'%(d,x,y,z))
                        d+=delta
                    tabWrite('}\n')
                if ob.pov.curveshape in {'loft'}:
                    n = len(ob.data.splines)
                    tabWrite('#declare %s = array[%s]{\n'%(dataname,(n+3)))
                    tabWrite('spline{%s%s},\n'%(dataname,n))
                    for i in range(n):
                        tabWrite('spline{%s%s},\n'%(dataname,(i+1)))
                    tabWrite('spline{%s1},\n'%(dataname))
                    tabWrite('spline{%s2}\n'%(dataname))
                    tabWrite('}\n')
                # Use some of the Meshmaker.inc macro, here inlined
                file.write('#macro CheckFileName(FileName)\n')
                file.write('   #local Len=strlen(FileName);\n')
                file.write('   #if(Len>0)\n')
                file.write('      #if(file_exists(FileName))\n')
                file.write('         #if(Len>=4)\n')
                file.write('            #local Ext=strlwr(substr(FileName,Len-3,4))\n')
                file.write('            #if (strcmp(Ext,".obj")=0 | strcmp(Ext,".pcm")=0 | strcmp(Ext,".arr")=0)\n')
                file.write('               #local Return=99;\n')
                file.write('            #else\n')
                file.write('               #local Return=0;\n')
                file.write('            #end\n')
                file.write('         #else\n')
                file.write('            #local Return=0;\n')
                file.write('         #end\n')
                file.write('      #else\n')
                file.write('         #if(Len>=4)\n')
                file.write('            #local Ext=strlwr(substr(FileName,Len-3,4))\n')
                file.write('            #if (strcmp(Ext,".obj")=0 | strcmp(Ext,".pcm")=0 | strcmp(Ext,".arr")=0)\n')
                file.write('               #if (strcmp(Ext,".obj")=0)\n')
                file.write('                  #local Return=2;\n')
                file.write('               #end\n')
                file.write('               #if (strcmp(Ext,".pcm")=0)\n')
                file.write('                  #local Return=3;\n')
                file.write('               #end\n')
                file.write('               #if (strcmp(Ext,".arr")=0)\n')
                file.write('                  #local Return=4;\n')
                file.write('               #end\n')
                file.write('            #else\n')
                file.write('               #local Return=1;\n')
                file.write('            #end\n')
                file.write('         #else\n')
                file.write('            #local Return=1;\n')
                file.write('         #end\n')
                file.write('      #end\n')
                file.write('   #else\n')
                file.write('      #local Return=1;\n')
                file.write('   #end\n')
                file.write('   (Return)\n')
                file.write('#end\n')
    
                file.write('#macro BuildSpline(Arr, SplType)\n')
                file.write('   #local Ds=dimension_size(Arr,1);\n')
                file.write('   #local Asc=asc(strupr(SplType));\n')
                file.write('   #if(Asc!=67 & Asc!=76 & Asc!=81) \n')
                file.write('      #local Asc=76;\n')
                file.write('      #debug "\nWrong spline type defined (C/c/L/l/N/n/Q/q), using default linear_spline\\n"\n')
                file.write('   #end\n')
                file.write('   spline {\n')
                file.write('      #switch (Asc)\n')
                file.write('         #case (67) //C  cubic_spline\n')
                file.write('            cubic_spline\n')
                file.write('         #break\n')
                file.write('         #case (76) //L  linear_spline\n')
                file.write('            linear_spline\n')
                file.write('         #break\n')
                file.write('         #case (78) //N  linear_spline\n')
                file.write('            natural_spline\n')
                file.write('         #break\n')
                file.write('         #case (81) //Q  Quadratic_spline\n')
                file.write('            quadratic_spline\n')
                file.write('         #break\n')
                file.write('      #end\n')
                file.write('      #local Add=1/((Ds-2)-1);\n')
                file.write('      #local J=0-Add;\n')
                file.write('      #local I=0;\n')
                file.write('      #while (I<Ds)\n')
                file.write('         J\n')
                file.write('         Arr[I]\n')
                file.write('         #local I=I+1;\n')
                file.write('         #local J=J+Add;\n')
                file.write('      #end\n')
                file.write('   }\n')
                file.write('#end\n')
    
    
                file.write('#macro BuildWriteMesh2(VecArr, NormArr, UVArr, U, V, FileName)\n')
                #suppressed some file checking from original macro because no more separate files
                file.write(' #local Write=0;\n')
                file.write(' #debug concat("\\n\\n Building mesh2: \\n   - vertex_vectors\\n")\n')
                file.write('  #local NumVertices=dimension_size(VecArr,1);\n')
                file.write('  #switch (Write)\n')
                file.write('     #case(1)\n')
                file.write('        #write(\n')
                file.write('           MeshFile,\n')
                file.write('           "  vertex_vectors {\\n",\n')
                file.write('           "    ", str(NumVertices,0,0),"\\n    "\n')
                file.write('        )\n')
                file.write('     #break\n')
                file.write('     #case(2)\n')
                file.write('        #write(\n')
                file.write('           MeshFile,\n')
                file.write('           "# Vertices: ",str(NumVertices,0,0),"\\n"\n')
                file.write('        )\n')
                file.write('     #break\n')
                file.write('     #case(3)\n')
                file.write('        #write(\n')
                file.write('           MeshFile,\n')
                file.write('           str(2*NumVertices,0,0),",\\n"\n')
                file.write('        )\n')
                file.write('     #break\n')
                file.write('     #case(4)\n')
                file.write('        #write(\n')
                file.write('           MeshFile,\n')
                file.write('           "#declare VertexVectors= array[",str(NumVertices,0,0),"] {\\n  "\n')
                file.write('        )\n')
                file.write('     #break\n')
                file.write('  #end\n')
                file.write('  mesh2 {\n')
                file.write('     vertex_vectors {\n')
                file.write('        NumVertices\n')
                file.write('        #local I=0;\n')
                file.write('        #while (I<NumVertices)\n')
                file.write('           VecArr[I]\n')
                file.write('           #switch(Write)\n')
                file.write('              #case(1)\n')
                file.write('                 #write(MeshFile, VecArr[I])\n')
                file.write('              #break\n')
                file.write('              #case(2)\n')
                file.write('                 #write(\n')
                file.write('                    MeshFile,\n')
                file.write('                    "v ", VecArr[I].x," ", VecArr[I].y," ", VecArr[I].z,"\\n"\n')
                file.write('                 )\n')
                file.write('              #break\n')
                file.write('              #case(3)\n')
                file.write('                 #write(\n')
                file.write('                    MeshFile,\n')
                file.write('                    VecArr[I].x,",", VecArr[I].y,",", VecArr[I].z,",\\n"\n')
                file.write('                 )\n')
                file.write('              #break\n')
                file.write('              #case(4)\n')
                file.write('                 #write(MeshFile, VecArr[I])\n')
                file.write('              #break\n')
                file.write('           #end\n')
                file.write('           #local I=I+1;\n')
                file.write('           #if(Write=1 | Write=4)\n')
                file.write('              #if(mod(I,3)=0)\n')
                file.write('                 #write(MeshFile,"\\n    ")\n')
                file.write('              #end\n')
                file.write('           #end \n')
                file.write('        #end\n')
                file.write('        #switch(Write)\n')
                file.write('           #case(1)\n')
                file.write('              #write(MeshFile,"\\n  }\\n")\n')
                file.write('           #break\n')
                file.write('           #case(2)\n')
                file.write('              #write(MeshFile,"\\n")\n')
                file.write('           #break\n')
                file.write('           #case(3)\n')
                file.write('              // do nothing\n')
                file.write('           #break\n')
                file.write('           #case(4) \n')
                file.write('              #write(MeshFile,"\\n}\\n")\n')
                file.write('           #break\n')
                file.write('        #end\n')
                file.write('     }\n')
    
                file.write('     #debug concat("   - normal_vectors\\n")    \n')
                file.write('     #local NumVertices=dimension_size(NormArr,1);\n')
                file.write('     #switch(Write)\n')
                file.write('        #case(1)\n')
                file.write('           #write(\n')
                file.write('              MeshFile,\n')
                file.write('              "  normal_vectors {\\n",\n')
                file.write('              "    ", str(NumVertices,0,0),"\\n    "\n')
                file.write('           )\n')
                file.write('        #break\n')
                file.write('        #case(2)\n')
                file.write('           #write(\n')
                file.write('              MeshFile,\n')
                file.write('              "# Normals: ",str(NumVertices,0,0),"\\n"\n')
                file.write('           )\n')
                file.write('        #break\n')
                file.write('        #case(3)\n')
                file.write('           // do nothing\n')
                file.write('        #break\n')
                file.write('        #case(4)\n')
                file.write('           #write(\n')
                file.write('              MeshFile,\n')
                file.write('              "#declare NormalVectors= array[",str(NumVertices,0,0),"] {\\n  "\n')
                file.write('           )\n')
                file.write('        #break\n')
                file.write('     #end\n')
                file.write('     normal_vectors {\n')
                file.write('        NumVertices\n')
                file.write('        #local I=0;\n')
                file.write('        #while (I<NumVertices)\n')
                file.write('           NormArr[I]\n')
                file.write('           #switch(Write)\n')
                file.write('              #case(1)\n')
                file.write('                 #write(MeshFile NormArr[I])\n')
                file.write('              #break\n')
                file.write('              #case(2)\n')
                file.write('                 #write(\n')
                file.write('                    MeshFile,\n')
                file.write('                    "vn ", NormArr[I].x," ", NormArr[I].y," ", NormArr[I].z,"\\n"\n')
                file.write('                 )\n')
                file.write('              #break\n')
                file.write('              #case(3)\n')
                file.write('                 #write(\n')
                file.write('                    MeshFile,\n')
                file.write('                    NormArr[I].x,",", NormArr[I].y,",", NormArr[I].z,",\\n"\n')
                file.write('                 )\n')
                file.write('              #break\n')
                file.write('              #case(4)\n')
                file.write('                 #write(MeshFile NormArr[I])\n')
                file.write('              #break\n')
                file.write('           #end\n')
                file.write('           #local I=I+1;\n')
                file.write('           #if(Write=1 | Write=4) \n')
                file.write('              #if(mod(I,3)=0)\n')
                file.write('                 #write(MeshFile,"\\n    ")\n')
                file.write('              #end\n')
                file.write('           #end\n')
                file.write('        #end\n')
                file.write('        #switch(Write)\n')
                file.write('           #case(1)\n')
                file.write('              #write(MeshFile,"\\n  }\\n")\n')
                file.write('           #break\n')
                file.write('           #case(2)\n')
                file.write('              #write(MeshFile,"\\n")\n')
                file.write('           #break\n')
                file.write('           #case(3)\n')
                file.write('              //do nothing\n')
                file.write('           #break\n')
                file.write('           #case(4)\n')
                file.write('              #write(MeshFile,"\\n}\\n")\n')
                file.write('           #break\n')
                file.write('        #end\n')
                file.write('     }\n')
         
                file.write('     #debug concat("   - uv_vectors\\n")   \n')
                file.write('     #local NumVertices=dimension_size(UVArr,1);\n')
                file.write('     #switch(Write)\n')
                file.write('        #case(1)\n')
                file.write('           #write(\n')
                file.write('              MeshFile, \n')
                file.write('              "  uv_vectors {\\n",\n')
                file.write('              "    ", str(NumVertices,0,0),"\\n    "\n')
                file.write('           )\n')
                file.write('         #break\n')
                file.write('         #case(2)\n')
                file.write('           #write(\n')
                file.write('              MeshFile,\n')
                file.write('              "# UV-vectors: ",str(NumVertices,0,0),"\\n"\n')
                file.write('           )\n')
                file.write('         #break\n')
                file.write('         #case(3)\n')
                file.write('           // do nothing, *.pcm does not support uv-vectors\n')
                file.write('         #break\n')
                file.write('         #case(4)\n')
                file.write('            #write(\n')
                file.write('               MeshFile,\n')
                file.write('               "#declare UVVectors= array[",str(NumVertices,0,0),"] {\\n  "\n')
                file.write('            )\n')
                file.write('         #break\n')
                file.write('     #end\n')
                file.write('     uv_vectors {\n')
                file.write('        NumVertices\n')
                file.write('        #local I=0;\n')
                file.write('        #while (I<NumVertices)\n')
                file.write('           UVArr[I]\n')
                file.write('           #switch(Write)\n')
                file.write('              #case(1)\n')
                file.write('                 #write(MeshFile UVArr[I])\n')
                file.write('              #break\n')
                file.write('              #case(2)\n')
                file.write('                 #write(\n')
                file.write('                    MeshFile,\n')
                file.write('                    "vt ", UVArr[I].u," ", UVArr[I].v,"\\n"\n')
                file.write('                 )\n')
                file.write('              #break\n')
                file.write('              #case(3)\n')
                file.write('                 //do nothing\n')
                file.write('              #break\n')
                file.write('              #case(4)\n')
                file.write('                 #write(MeshFile UVArr[I])\n')
                file.write('              #break\n')
                file.write('           #end\n')
                file.write('           #local I=I+1; \n')
                file.write('           #if(Write=1 | Write=4)\n')
                file.write('              #if(mod(I,3)=0)\n')
                file.write('                 #write(MeshFile,"\\n    ")\n')
                file.write('              #end \n')
                file.write('           #end\n')
                file.write('        #end \n')
                file.write('        #switch(Write)\n')
                file.write('           #case(1)\n')
                file.write('              #write(MeshFile,"\\n  }\\n")\n')
                file.write('           #break\n')
                file.write('           #case(2)\n')
                file.write('              #write(MeshFile,"\\n")\n')
                file.write('           #break\n')
                file.write('           #case(3)\n')
                file.write('              //do nothing\n')
                file.write('           #break\n')
                file.write('           #case(4)\n')
                file.write('              #write(MeshFile,"\\n}\\n")\n')
                file.write('           #break\n')
                file.write('        #end\n')
                file.write('     }\n')
                file.write('\n')
                file.write('     #debug concat("   - face_indices\\n")   \n')
                file.write('     #declare NumFaces=U*V*2;\n')
                file.write('     #switch(Write)\n')
                file.write('        #case(1)\n')
                file.write('           #write(\n')
                file.write('              MeshFile,\n')
                file.write('              "  face_indices {\\n"\n')
                file.write('              "    ", str(NumFaces,0,0),"\\n    "\n')
                file.write('           )\n')
                file.write('        #break\n')
                file.write('        #case(2)\n')
                file.write('           #write (\n')
                file.write('              MeshFile,\n')
                file.write('              "# faces: ",str(NumFaces,0,0),"\\n"\n')
                file.write('           )\n')
                file.write('        #break\n')
                file.write('        #case(3)\n')
                file.write('           #write (\n')
                file.write('              MeshFile,\n')
                file.write('              "0,",str(NumFaces,0,0),",\\n"\n')
                file.write('           )\n')
                file.write('        #break\n')
                file.write('        #case(4)\n')
                file.write('           #write(\n')
                file.write('              MeshFile,\n')
                file.write('              "#declare FaceIndices= array[",str(NumFaces,0,0),"] {\\n  "\n')
                file.write('           )\n')
                file.write('        #break\n')
                file.write('     #end\n')
                file.write('     face_indices {\n')
                file.write('        NumFaces\n')
                file.write('        #local I=0;\n')
                file.write('        #local H=0;\n')
                file.write('        #local NumVertices=dimension_size(VecArr,1);\n')
                file.write('        #while (I<V)\n')
                file.write('           #local J=0;\n')
                file.write('           #while (J<U)\n')
                file.write('              #local Ind=(I*U)+I+J;\n')
                file.write('              <Ind, Ind+1, Ind+U+2>, <Ind, Ind+U+1, Ind+U+2>\n')
                file.write('              #switch(Write)\n')
                file.write('                 #case(1)\n')
                file.write('                    #write(\n')
                file.write('                       MeshFile,\n')
                file.write('                       <Ind, Ind+1, Ind+U+2>, <Ind, Ind+U+1, Ind+U+2>\n')
                file.write('                    )\n')
                file.write('                 #break\n')
                file.write('                 #case(2)\n')
                file.write('                    #write(\n')
                file.write('                       MeshFile,\n')
                file.write('                       "f ",Ind+1,"/",Ind+1,"/",Ind+1," ",Ind+1+1,"/",Ind+1+1,"/",Ind+1+1," ",Ind+U+2+1,"/",Ind+U+2+1,"/",Ind+U+2+1,"\\n",\n')
                file.write('                       "f ",Ind+U+1+1,"/",Ind+U+1+1,"/",Ind+U+1+1," ",Ind+1,"/",Ind+1,"/",Ind+1," ",Ind+U+2+1,"/",Ind+U+2+1,"/",Ind+U+2+1,"\\n"\n')
                file.write('                    )\n')
                file.write('                 #break\n')
                file.write('                 #case(3)\n')
                file.write('                    #write(\n')
                file.write('                       MeshFile,\n')
                file.write('                       Ind,",",Ind+NumVertices,",",Ind+1,",",Ind+1+NumVertices,",",Ind+U+2,",",Ind+U+2+NumVertices,",\\n"\n')
                file.write('                       Ind+U+1,",",Ind+U+1+NumVertices,",",Ind,",",Ind+NumVertices,",",Ind+U+2,",",Ind+U+2+NumVertices,",\\n"\n')
                file.write('                    )\n')
                file.write('                 #break\n')
                file.write('                 #case(4)\n')
                file.write('                    #write(\n')
                file.write('                       MeshFile,\n')
                file.write('                       <Ind, Ind+1, Ind+U+2>, <Ind, Ind+U+1, Ind+U+2>\n')
                file.write('                    )\n')
                file.write('                 #break\n')
                file.write('              #end\n')
                file.write('              #local J=J+1;\n')
                file.write('              #local H=H+1;\n')
                file.write('              #if(Write=1 | Write=4)\n')
                file.write('                 #if(mod(H,3)=0)\n')
                file.write('                    #write(MeshFile,"\\n    ")\n')
                file.write('                 #end \n')
                file.write('              #end\n')
                file.write('           #end\n')
                file.write('           #local I=I+1;\n')
                file.write('        #end\n')
                file.write('     }\n')
                file.write('     #switch(Write)\n')
                file.write('        #case(1)\n')
                file.write('           #write(MeshFile, "\\n  }\\n}")\n')
                file.write('           #fclose MeshFile\n')
                file.write('           #debug concat(" Done writing\\n")\n')
                file.write('        #break\n')
                file.write('        #case(2)\n')
                file.write('           #fclose MeshFile\n')
                file.write('           #debug concat(" Done writing\\n")\n')
                file.write('        #break\n')
                file.write('        #case(3)\n')
                file.write('           #fclose MeshFile\n')
                file.write('           #debug concat(" Done writing\\n")\n')
                file.write('        #break\n')
                file.write('        #case(4)\n')
                file.write('           #write(MeshFile, "\\n}\\n}")\n')
                file.write('           #fclose MeshFile\n')
                file.write('           #debug concat(" Done writing\\n")\n')
                file.write('        #break\n')
                file.write('     #end\n')
                file.write('  }\n')
                file.write('#end\n')
                
                file.write('#macro MSM(SplineArray, SplRes, Interp_type,  InterpRes, FileName)\n')
                file.write('    #declare Build=CheckFileName(FileName);\n')
                file.write('    #if(Build=0)\n')
                file.write('        #debug concat("\\n Parsing mesh2 from file: ", FileName, "\\n")\n')
                file.write('        #include FileName\n')
                file.write('        object{Surface}\n')
                file.write('    #else\n')
                file.write('        #local NumVertices=(SplRes+1)*(InterpRes+1);\n')
                file.write('        #local NumFaces=SplRes*InterpRes*2;\n')
                file.write('        #debug concat("\\n Calculating ",str(NumVertices,0,0)," vertices for ", str(NumFaces,0,0)," triangles\\n\\n")\n')
                file.write('        #local VecArr=array[NumVertices]\n')
                file.write('        #local NormArr=array[NumVertices]\n')
                file.write('        #local UVArr=array[NumVertices]\n')
                file.write('        #local N=dimension_size(SplineArray,1);\n')
                file.write('        #local TempSplArr0=array[N];\n')
                file.write('        #local TempSplArr1=array[N];\n')
                file.write('        #local TempSplArr2=array[N];\n')
                file.write('        #local PosStep=1/SplRes;\n')
                file.write('        #local InterpStep=1/InterpRes;\n')
                file.write('        #local Count=0;\n')
                file.write('        #local Pos=0;\n')
                file.write('        #while(Pos<=1)\n')
                file.write('            #local I=0;\n')
                file.write('            #if (Pos=0)\n')
                file.write('                #while (I<N)\n')
                file.write('                    #local Spl=spline{SplineArray[I]}\n')
                file.write('                    #local TempSplArr0[I]=<0,0,0>+Spl(Pos);\n')
                file.write('                    #local TempSplArr1[I]=<0,0,0>+Spl(Pos+PosStep);\n')
                file.write('                    #local TempSplArr2[I]=<0,0,0>+Spl(Pos-PosStep);\n')
                file.write('                    #local I=I+1;\n')
                file.write('                #end\n')
                file.write('                #local S0=BuildSpline(TempSplArr0, Interp_type)\n')
                file.write('                #local S1=BuildSpline(TempSplArr1, Interp_type)\n')
                file.write('                #local S2=BuildSpline(TempSplArr2, Interp_type)\n')
                file.write('            #else\n')
                file.write('                #while (I<N)\n')
                file.write('                    #local Spl=spline{SplineArray[I]}\n')
                file.write('                    #local TempSplArr1[I]=<0,0,0>+Spl(Pos+PosStep);\n')
                file.write('                    #local I=I+1;\n')
                file.write('                #end\n')
                file.write('                #local S1=BuildSpline(TempSplArr1, Interp_type)\n')
                file.write('            #end\n')
                file.write('            #local J=0;\n')
                file.write('            #while (J<=1)\n')
                file.write('                #local P0=<0,0,0>+S0(J);\n')
                file.write('                #local P1=<0,0,0>+S1(J);\n')
                file.write('                #local P2=<0,0,0>+S2(J);\n')
                file.write('                #local P3=<0,0,0>+S0(J+InterpStep);\n')
                file.write('                #local P4=<0,0,0>+S0(J-InterpStep);\n')
                file.write('                #local B1=P4-P0;\n')
                file.write('                #local B2=P2-P0;\n')
                file.write('                #local B3=P3-P0;\n')
                file.write('                #local B4=P1-P0;\n')
                file.write('                #local N1=vcross(B1,B2);\n')
                file.write('                #local N2=vcross(B2,B3);\n')
                file.write('                #local N3=vcross(B3,B4);\n')
                file.write('                #local N4=vcross(B4,B1);\n')
                file.write('                #local Norm=vnormalize((N1+N2+N3+N4));\n')
                file.write('                #local VecArr[Count]=P0;\n')
                file.write('                #local NormArr[Count]=Norm;\n')
                file.write('                #local UVArr[Count]=<J,Pos>;\n')
                file.write('                #local J=J+InterpStep;\n')
                file.write('                #local Count=Count+1;\n')
                file.write('            #end\n')
                file.write('            #local S2=spline{S0}\n')
                file.write('            #local S0=spline{S1}\n')
                file.write('            #debug concat("\\r Done ", str(Count,0,0)," vertices : ", str(100*Count/NumVertices,0,2)," %")\n')
                file.write('            #local Pos=Pos+PosStep;\n')
                file.write('        #end\n')
                file.write('        BuildWriteMesh2(VecArr, NormArr, UVArr, InterpRes, SplRes, "")\n')
                file.write('    #end\n')
                file.write('#end\n\n')
    
                file.write('#macro Coons(Spl1, Spl2, Spl3, Spl4, Iter_U, Iter_V, FileName)\n')
                file.write('   #declare Build=CheckFileName(FileName);\n')
                file.write('   #if(Build=0)\n')
                file.write('      #debug concat("\\n Parsing mesh2 from file: ", FileName, "\\n")\n')
                file.write('      #include FileName\n')
                file.write('      object{Surface}\n')
                file.write('   #else\n')
                file.write('      #local NumVertices=(Iter_U+1)*(Iter_V+1);\n')
                file.write('      #local NumFaces=Iter_U*Iter_V*2;\n')
                file.write('      #debug concat("\\n Calculating ", str(NumVertices,0,0), " vertices for ",str(NumFaces,0,0), " triangles\\n\\n")\n')
                file.write('      #declare VecArr=array[NumVertices]   \n')
                file.write('      #declare NormArr=array[NumVertices]   \n')
                file.write('      #local UVArr=array[NumVertices]      \n')
                file.write('      #local Spl1_0=Spl1(0);\n')
                file.write('      #local Spl2_0=Spl2(0);\n')
                file.write('      #local Spl3_0=Spl3(0);\n')
                file.write('      #local Spl4_0=Spl4(0);\n')
                file.write('      #local UStep=1/Iter_U;\n')
                file.write('      #local VStep=1/Iter_V;\n')
                file.write('      #local Count=0;\n')
                file.write('      #local I=0;\n')
                file.write('      #while (I<=1)\n')
                file.write('         #local Im=1-I;\n')
                file.write('         #local J=0;\n')
                file.write('         #while (J<=1)\n')
                file.write('            #local Jm=1-J;\n')
                file.write('            #local C0=Im*Jm*(Spl1_0)+Im*J*(Spl2_0)+I*J*(Spl3_0)+I*Jm*(Spl4_0);\n')
                file.write('            #local P0=LInterpolate(I, Spl1(J), Spl3(Jm)) + \n')
                file.write('               LInterpolate(Jm, Spl2(I), Spl4(Im))-C0;\n')
                file.write('            #declare VecArr[Count]=P0;\n')
                file.write('            #local UVArr[Count]=<J,I>;\n')
                file.write('            #local J=J+UStep;\n')
                file.write('            #local Count=Count+1;\n')
                file.write('         #end\n')
                file.write('         #debug concat(\n')
                file.write('            "\r Done ", str(Count,0,0)," vertices :         ",\n')
                file.write('            str(100*Count/NumVertices,0,2)," %"\n')
                file.write('         )\n')
                file.write('         #local I=I+VStep;\n')
                file.write('      #end\n')
                file.write('      #debug "\r Normals                                  "\n')
                file.write('      #local Count=0;\n')
                file.write('      #local I=0;\n')
                file.write('      #while (I<=Iter_V)\n')
                file.write('         #local J=0;\n')
                file.write('         #while (J<=Iter_U)\n')
                file.write('            #local Ind=(I*Iter_U)+I+J;\n')
                file.write('            #local P0=VecArr[Ind];\n')
                file.write('            #if(J=0)\n')
                file.write('               #local P1=P0+(P0-VecArr[Ind+1]);\n')
                file.write('            #else\n')
                file.write('               #local P1=VecArr[Ind-1];\n')
                file.write('            #end\n')
                file.write('            #if (J=Iter_U)\n')
                file.write('               #local P2=P0+(P0-VecArr[Ind-1]);\n')
                file.write('            #else\n')
                file.write('               #local P2=VecArr[Ind+1];\n')
                file.write('            #end\n')
                file.write('            #if (I=0)\n')
                file.write('               #local P3=P0+(P0-VecArr[Ind+Iter_U+1]);\n')
                file.write('            #else\n')
                file.write('               #local P3=VecArr[Ind-Iter_U-1];\n')
                file.write('            #end\n')
                file.write('            #if (I=Iter_V)\n')
                file.write('               #local P4=P0+(P0-VecArr[Ind-Iter_U-1]);\n')
                file.write('            #else\n')
                file.write('               #local P4=VecArr[Ind+Iter_U+1];\n')
                file.write('            #end\n')
                file.write('            #local B1=P4-P0;\n')
                file.write('            #local B2=P2-P0;\n')
                file.write('            #local B3=P3-P0;\n')
                file.write('            #local B4=P1-P0;\n')
                file.write('            #local N1=vcross(B1,B2);\n')
                file.write('            #local N2=vcross(B2,B3);\n')
                file.write('            #local N3=vcross(B3,B4);\n')
                file.write('            #local N4=vcross(B4,B1);\n')
                file.write('            #local Norm=vnormalize((N1+N2+N3+N4));\n')
                file.write('            #declare NormArr[Count]=Norm;\n')
                file.write('            #local J=J+1;\n')
                file.write('            #local Count=Count+1;\n')
                file.write('         #end\n')
                file.write('         #debug concat("\r Done ", str(Count,0,0)," normals : ",str(100*Count/NumVertices,0,2), " %")\n')
                file.write('         #local I=I+1;\n')
                file.write('      #end\n')
                file.write('      BuildWriteMesh2(VecArr, NormArr, UVArr, Iter_U, Iter_V, FileName)\n')
                file.write('   #end\n')
                file.write('#end\n\n')
                
            if bezier_sweep == False:
                tabWrite("#declare %s =\n"%dataname)
            if ob.pov.curveshape == 'sphere_sweep' and bezier_sweep == False:
                tabWrite("union {\n")
                for spl in ob.data.splines:
                    if spl.type != "BEZIER":
                        spl_type = "linear"
                        if spl.type == "NURBS":
                            spl_type = "cubic"
                        points=spl.points
                        numPoints=len(points)
                        if spl.use_cyclic_u:
                            numPoints+=3
    
                        tabWrite("sphere_sweep { %s_spline %s,\n"%(spl_type,numPoints))
                        if spl.use_cyclic_u:
                            pt1 = points[len(points)-1]
                            wpt1 = pt1.co
                            tabWrite("<%.4g,%.4g,%.4g>,%.4g\n" %(wpt1[0], wpt1[1], wpt1[2], pt1.radius*ob.data.bevel_depth))
                        for pt in points:
                            wpt = pt.co
                            tabWrite("<%.4g,%.4g,%.4g>,%.4g\n" %(wpt[0], wpt[1], wpt[2], pt.radius*ob.data.bevel_depth))
                        if spl.use_cyclic_u:
                            for i in range (0,2):
                                endPt=points[i]
                                wpt = endPt.co
                                tabWrite("<%.4g,%.4g,%.4g>,%.4g\n" %(wpt[0], wpt[1], wpt[2], endPt.radius*ob.data.bevel_depth))
    
                        
                    tabWrite("}\n")
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
            if ob.pov.curveshape == 'sor':
                for spl in ob.data.splines:
                    if spl.type in {'POLY','NURBS'}:
                        points=spl.points
                        numPoints=len(points)
                        tabWrite("sor { %s,\n"%numPoints)
                        for pt in points:
                            wpt = pt.co
                            tabWrite("<%.4g,%.4g>\n" %(wpt[0], wpt[1]))
                    else:
                        tabWrite("box { 0,0\n")
            if ob.pov.curveshape in {'lathe','prism'}:
                spl = ob.data.splines[0]
                if spl.type == "BEZIER":
                    points=spl.bezier_points
                    lenCur=len(points)-1
                    lenPts=lenCur*4
                    ifprism = ''
                    if ob.pov.curveshape in {'prism'}:
                        height = ob.data.extrude
                        ifprism = '-%s, %s,'%(height, height)
                        lenCur+=1
                        lenPts+=4
                    tabWrite("%s { bezier_spline %s %s,\n"%(ob.pov.curveshape,ifprism,lenPts))
                    for i in range(0,lenCur):
                        p1=points[i].co
                        pR=points[i].handle_right
                        end = i+1
                        if i == lenCur-1 and ob.pov.curveshape in {'prism'}:
                            end = 0
                        pL=points[end].handle_left
                        p2=points[end].co
                        line="<%.4g,%.4g>"%(p1[0],p1[1])
                        line+="<%.4g,%.4g>"%(pR[0],pR[1])
                        line+="<%.4g,%.4g>"%(pL[0],pL[1])
                        line+="<%.4g,%.4g>"%(p2[0],p2[1])
                        tabWrite("%s\n" %line)
                else:
                    points=spl.points
                    lenCur=len(points)
                    lenPts=lenCur
                    ifprism = ''
                    if ob.pov.curveshape in {'prism'}:
                        height = ob.data.extrude
                        ifprism = '-%s, %s,'%(height, height)
                        lenPts+=3
                    spl_type = 'quadratic'
                    if spl.type == 'POLY':
                        spl_type = 'linear'
                    tabWrite("%s { %s_spline %s %s,\n"%(ob.pov.curveshape,spl_type,ifprism,lenPts))
                    if ob.pov.curveshape in {'prism'}:
                        pt = points[len(points)-1]
                        wpt = pt.co
                        tabWrite("<%.4g,%.4g>\n" %(wpt[0], wpt[1]))
                    for pt in points:
                        wpt = pt.co
                        tabWrite("<%.4g,%.4g>\n" %(wpt[0], wpt[1]))
                    if ob.pov.curveshape in {'prism'}:
                        for i in range(2):
                            pt = points[i]
                            wpt = pt.co
                            tabWrite("<%.4g,%.4g>\n" %(wpt[0], wpt[1]))
            if bezier_sweep:
                spl = ob.data.splines[0]
                points=spl.bezier_points
                lenCur = len(points)-1
                numPoints = lenCur*4
                if spl.use_cyclic_u:
                    lenCur += 1
                    numPoints += 4
                tabWrite("#declare %s_bezier_points = array[%s]{\n"%(dataname,numPoints))
                for i in range(lenCur):
                    p1=points[i].co
                    pR=points[i].handle_right
                    end = i+1
                    if spl.use_cyclic_u and i == (lenCur - 1):
                        end = 0
                    pL=points[end].handle_left
                    p2=points[end].co
                    line="<%.4g,%.4g,%.4f>"%(p1[0],p1[1],p1[2])
                    line+="<%.4g,%.4g,%.4f>"%(pR[0],pR[1],pR[2])
                    line+="<%.4g,%.4g,%.4f>"%(pL[0],pL[1],pL[2])
                    line+="<%.4g,%.4g,%.4f>"%(p2[0],p2[1],p2[2])
                    tabWrite("%s\n" %line)
                tabWrite("}\n")
                #tabWrite('#include "bezier_spheresweep.inc"\n') #now inlined
                tabWrite('#declare %s = object{Shape_Bezierpoints_Sphere_Sweep(%s, %s_bezier_points, %.4f) \n'%(dataname,ob.data.resolution_u,dataname,ob.data.bevel_depth))
            if ob.pov.curveshape in {'loft'}:
                tabWrite('object {MSM(%s,%s,"c",%s,"")\n'%(dataname,ob.pov.res_u,ob.pov.res_v))
            if ob.pov.curveshape in {'birail'}:
                splines = '%s1,%s2,%s3,%s4'%(dataname,dataname,dataname,dataname)
                tabWrite('object {Coons(%s, %s, %s, "")\n'%(splines,ob.pov.res_u,ob.pov.res_v))
            povMatName = "Default_texture"
            if ob.active_material:
                #povMatName = string_strip_hyphen(bpy.path.clean_name(ob.active_material.name))
                try:
                    material = ob.active_material
                    writeObjectMaterial(material, ob)
                except IndexError:
                    print(me)
            #tabWrite("texture {%s}\n"%povMatName)
            if ob.pov.curveshape in {'prism'}:
                tabWrite("rotate <90,0,0>\n")
                tabWrite("scale y*-1\n" )
            tabWrite("}\n")
            
    #################################################################        
            
                
    
    Luca Bonavita's avatar
    Luca Bonavita committed
        def exportMeta(metas):
    
            # TODO - blenders 'motherball' naming is not supported.
    
            if comments and len(metas) >= 1:
    
                file.write("//--Blob objects--\n\n")
    
    Luca Bonavita's avatar
    Luca Bonavita committed
            for ob in metas:
                meta = ob.data
    
    
                # important because no elements will break parsing.
    
                elements = [elem for elem in meta.elements if elem.type in {'BALL', 'ELLIPSOID'}]
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                    tabWrite("blob {\n")
                    tabWrite("threshold %.4g\n" % meta.threshold)
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                        material = meta.materials[0]  # lame! - blender cant do enything else.
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                    for elem in elements:
                        loc = elem.co
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                        stiffness = elem.stiffness
                        if elem.use_negative:
                            stiffness = - stiffness
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                        if elem.type == 'BALL':
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                            tabWrite("sphere { <%.6g, %.6g, %.6g>, %.4g, %.4g }\n" % \
                                     (loc.x, loc.y, loc.z, elem.radius, stiffness))
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                            # After this wecould do something simple like...
    
                            # except we'll write the color
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                        elif elem.type == 'ELLIPSOID':
                            # location is modified by scale
    
                            tabWrite("sphere { <%.6g, %.6g, %.6g>, %.4g, %.4g }\n" % \
                                     (loc.x / elem.size_x, loc.y / elem.size_y, loc.z / elem.size_z,
                                      elem.radius, stiffness))
                            tabWrite("scale <%.6g, %.6g, %.6g> \n" % \
                                     (elem.size_x, elem.size_y, elem.size_z))
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                    if material:
                        diffuse_color = material.diffuse_color
    
                        if material.use_transparency and material.transparency_method == 'RAYTRACE':
    
                            povFilter = material.raytrace_transparency.filter * (1.0 - material.alpha)
                            trans = (1.0 - material.alpha) - povFilter
    
                            povFilter = 0.0
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                        material_finish = materialNames[material.name]
    
                        tabWrite("pigment {rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>} \n" % \
                                 (diffuse_color[0], diffuse_color[1], diffuse_color[2],
                                  povFilter, trans))
    
                        tabWrite("finish {%s}\n" % safety(material_finish, Level=2))
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                        tabWrite("pigment {rgb<1 1 1>} \n")
    
                        # Write the finish last.
                        tabWrite("finish {%s}\n" % (safety(DEF_MAT_NAME, Level=2)))
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                    writeObjectMaterial(material, ob)
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                    writeMatrix(global_matrix * ob.matrix_world)
    
                    # Importance for radiosity sampling added here
    
                    tabWrite("radiosity { \n")
                    tabWrite("importance %3g \n" % importance)
                    tabWrite("}\n")
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                    tabWrite("}\n")  # End of Metaball block
    
                    if comments and len(metas) >= 1:
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
        def exportMeshes(scene, sel):
    #        obmatslist = []
    #        def hasUniqueMaterial():
    #            # Grab materials attached to object instances ...
    #            if hasattr(ob, 'material_slots'):
    #                for ms in ob.material_slots:
    
    #                    if ms.material is not None and ms.link == 'OBJECT':
    
    #                        if ms.material in obmatslist:
    #                            return False
    #                        else:
    #                            obmatslist.append(ms.material)
    #                            return True
    #        def hasObjectMaterial(ob):
    #            # Grab materials attached to object instances ...
    #            if hasattr(ob, 'material_slots'):