Skip to content
Snippets Groups Projects
render.py 262 KiB
Newer Older
  • Learn to ignore specific revisions
  •                         # bringing the total back to one.
                            frontDiffuse = backDiffuse = 0.5
                        # Let the highest value stay the highest value.
                        elif frontDiffuse > backDiffuse:
                            # clamps the sum below 1
                            backDiffuse = min(backDiffuse, (1.0 - frontDiffuse))
    
    Maurice Raybaud's avatar
     
    Maurice Raybaud committed
                            frontDiffuse = min(frontDiffuse, (1.0 - backDiffuse))
    
    
                    # map hardness between 0.0 and 1.0
                    roughness = ((1.0 - ((material.specular_hardness - 1.0) / 510.0)))
                    ## scale from 0.0 to 0.1
    
                    # add a small value because 0.0 is invalid.
    
                    roughness += (1.0 / 511.0)
    
                    ################################Diffuse Shader######################################
                    # Not used for Full spec (Level=3) of the shader.
    
                    if material.diffuse_shader == 'OREN_NAYAR' and Level != 3:
    
                        # Blender roughness is what is generally called oren nayar Sigma,
                        # and brilliance in POV-Ray.
                        tabWrite("brilliance %.3g\n" % (0.9 + material.roughness))
    
                    if material.diffuse_shader == 'TOON' and Level != 3:
    
                        tabWrite("brilliance %.3g\n" % (0.01 + material.diffuse_toon_smooth * 0.25))
    
                        # Lower diffuse and increase specular for toon effect seems to look better
                        # in POV-Ray.
                        frontDiffuse *= 0.5
    
                    if material.diffuse_shader == 'MINNAERT' and Level != 3:
    
                        #tabWrite("aoi %.3g\n" % material.darkness)
    
                        pass  # let's keep things simple for now
    
                    if material.diffuse_shader == 'FRESNEL' and Level != 3:
    
                        #tabWrite("aoi %.3g\n" % material.diffuse_fresnel_factor)
    
                        pass  # let's keep things simple for now
    
                    if material.diffuse_shader == 'LAMBERT' and Level != 3:
    
                        # trying to best match lambert attenuation by that constant brilliance value
                        tabWrite("brilliance 1.8\n")
    
                        ###########################Specular Shader######################################
                        # No difference between phong and cook torrence in blender HaHa!
                        if (material.specular_shader == 'COOKTORR' or
                            material.specular_shader == 'PHONG'):
    
                            tabWrite("phong %.3g\n" % (material.specular_intensity))
                            tabWrite("phong_size %.3g\n" % (material.specular_hardness / 2 + 0.25))
    
                        # POV-Ray 'specular' keyword corresponds to a Blinn model, without the ior.
                        elif material.specular_shader == 'BLINN':
                            # Use blender Blinn's IOR just as some factor for spec intensity
                            tabWrite("specular %.3g\n" % (material.specular_intensity *
                                                          (material.specular_ior / 4.0)))
    
                            tabWrite("roughness %.3g\n" % roughness)
    
                            #Could use brilliance 2(or varying around 2 depending on ior or factor) too.
    
    
                        elif material.specular_shader == 'TOON':
    
                            tabWrite("phong %.3g\n" % (material.specular_intensity * 2.0))
    
                            tabWrite("phong_size %.3g\n" % (0.1 + material.specular_toon_smooth / 2.0))
    
                        elif material.specular_shader == 'WARDISO':
    
                            # find best suited default constant for brilliance Use both phong and
                            # specular for some values.
                            tabWrite("specular %.3g\n" % (material.specular_intensity /
                                                          (material.specular_slope + 0.0005)))
                            # find best suited default constant for brilliance Use both phong and
                            # specular for some values.
                            tabWrite("roughness %.4g\n" % (0.0005 + material.specular_slope / 10.0))
                            # find best suited default constant for brilliance Use both phong and
                            # specular for some values.
                            tabWrite("brilliance %.4g\n" % (1.8 - material.specular_slope * 1.8))
    
                    ####################################################################################
    
                        tabWrite("specular 1\n")
                    tabWrite("diffuse %.3g %.3g\n" % (frontDiffuse, backDiffuse))
    
                    tabWrite("ambient %.3g\n" % material.ambient)
    
                    # POV-Ray blends the global value
                    #tabWrite("ambient rgb <%.3g, %.3g, %.3g>\n" % \
                    #         tuple([c*material.ambient for c in world.ambient_color]))
    
                    tabWrite("emission %.3g\n" % material.emit)  # New in POV-Ray 3.7
    
                    #POV-Ray just ignores roughness if there's no specular keyword
                    #tabWrite("roughness %.3g\n" % roughness)
    
                    if material.pov.conserve_energy:
                        # added for more realistic shading. Needs some checking to see if it
                        # really works. --Maurice.
                        tabWrite("conserve_energy\n")
    
                    if colored_specular_found == True:
                         tabWrite("metallic\n")          
    
    
                    # 'phong 70.0 '
                    if Level != 1:
                        if material.raytrace_mirror.use:
                            raytrace_mirror = material.raytrace_mirror
                            if raytrace_mirror.reflect_factor:
    
                                tabWrite("rgb <%.3g, %.3g, %.3g>\n" % material.mirror_color[:])                          
    
                                    tabWrite("metallic %.3g\n" % (raytrace_mirror.reflect_factor))
                                # Blurry reflections for UberPOV
                                if using_uberpov and raytrace_mirror.gloss_factor < 1.0:
                                    #tabWrite("#ifdef(unofficial) #if(unofficial = \"patch\") #if(patch(\"upov-reflection-roughness\") > 0)\n")
    
                                    tabWrite("roughness %.6f\n" % \
    
                                             (0.000001/raytrace_mirror.gloss_factor))
    
                                    #tabWrite("#end #end #end\n") # This and previous comment for backward compatibility, messier pov code
    
                                if material.pov.mirror_use_IOR:  # WORKING ?
                                    # Removed from the line below: gives a more physically correct
                                    # material but needs proper IOR. --Maurice
                                    tabWrite("fresnel 1 ")
                                tabWrite("falloff %.3g exponent %.3g} " % \
                                         (raytrace_mirror.fresnel, raytrace_mirror.fresnel_factor))
    
                    if material.subsurface_scattering.use:
                        subsurface_scattering = material.subsurface_scattering
    
                        tabWrite("subsurface { translucency <%.3g, %.3g, %.3g> }\n" % (
    
                                 (subsurface_scattering.radius[0]),
                                 (subsurface_scattering.radius[1]),
    
    Campbell Barton's avatar
    Campbell Barton committed
                                 (subsurface_scattering.radius[2]),
    
                    if material.pov.irid_enable:
                        tabWrite("irid { %.4g thickness %.4g turbulence %.4g }" % \
                                 (material.pov.irid_amount, material.pov.irid_thickness,
                                  material.pov.irid_turbulence))
    
                    tabWrite("diffuse 0.8\n")
                    tabWrite("phong 70.0\n")
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                # This is written into the object
                '''
                if material and material.transparency_method=='RAYTRACE':
                    'interior { ior %.3g} ' % material.raytrace_transparency.ior
                '''
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                #tabWrite("crand 1.0\n") # Sand granyness
                #tabWrite("metallic %.6f\n" % material.spec)
                #tabWrite("phong %.6f\n" % material.spec)
                #tabWrite("phong_size %.6f\n" % material.spec)
                #tabWrite("brilliance %.6f " % (material.specular_hardness/256.0) # Like hardness
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
            # Level=2 Means translation of spec and mir levels for when no map influences them
            povHasnoSpecularMaps(Level=2)
    
                special_texture_found = False
                for t in material.texture_slots:
    
                    if t and t.use:
                        if (t.texture.type == 'IMAGE' and t.texture.image) or t.texture.type != 'IMAGE':
                            validPath=True
                    else:
                        validPath=False
                    if(t and t.use and validPath and
    
                       (t.use_map_specular or t.use_map_raymir or t.use_map_normal or t.use_map_alpha)):
    
                        special_texture_found = True
    
                        continue  # Some texture found
    
    
                if special_texture_found or colored_specular_found:
    
                    # Level=1 Means No specular nor Mirror reflection
                    povHasnoSpecularMaps(Level=1)
    
                    # Level=3 Means Maximum Spec and Mirror
                    povHasnoSpecularMaps(Level=3)
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
        def exportCamera():
            camera = scene.camera
    
            # DH disabled for now, this isn't the correct context
    
            active_object = None  # bpy.context.active_object # does not always work  MR
    
            matrix = global_matrix * camera.matrix_world
    
            focal_point = camera.data.dof_distance
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
            # compute resolution
    
            Qsize = render.resolution_x / render.resolution_y
    
            tabWrite("#declare camLocation  = <%.6f, %.6f, %.6f>;\n" %
                     matrix.translation[:])
            tabWrite("#declare camLookAt = <%.6f, %.6f, %.6f>;\n" %
    
                     tuple([degrees(e) for e in matrix.to_3x3().to_euler()]))
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
            if scene.pov.baking_enable and active_object and active_object.type == 'MESH':
    
                tabWrite("mesh_camera{ 1 3\n")  # distribution 3 is what we want here
                tabWrite("mesh{%s}\n" % active_object.name)
                tabWrite("}\n")
                tabWrite("location <0,0,.01>")
                tabWrite("direction <0,0,-1>")
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            # Using standard camera otherwise
            else:
    
                tabWrite("location  <0, 0, 0>\n")
                tabWrite("look_at  <0, 0, -1>\n")
                tabWrite("right <%s, 0, 0>\n" % - Qsize)
                tabWrite("up <0, 1, 0>\n")
                tabWrite("angle  %f\n" % (360.0 * atan(16.0 / camera.data.lens) / pi))
    
    
                tabWrite("rotate  <%.6f, %.6f, %.6f>\n" % \
                         tuple([degrees(e) for e in matrix.to_3x3().to_euler()]))
    
                tabWrite("translate <%.6f, %.6f, %.6f>\n" % matrix.translation[:])
    
                if camera.data.pov.dof_enable and focal_point != 0:
                    tabWrite("aperture %.3g\n" % camera.data.pov.dof_aperture)
                    tabWrite("blur_samples %d %d\n" % \
                             (camera.data.pov.dof_samples_min, camera.data.pov.dof_samples_max))
                    tabWrite("variance 1/%d\n" % camera.data.pov.dof_variance)
                    tabWrite("confidence %.3g\n" % camera.data.pov.dof_confidence)
    
                    tabWrite("focal_point <0, 0, %f>\n" % focal_point)
            tabWrite("}\n")
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
    Luca Bonavita's avatar
    Luca Bonavita committed
        def exportLamps(lamps):
    
            # Incremented after each lamp export to declare its target
            # currently used for Fresnel diffuse shader as their slope vector:
            global lampCount
            lampCount = 0
    
    Luca Bonavita's avatar
    Luca Bonavita committed
            # Get all lamps
            for ob in lamps:
                lamp = ob.data
    
    
                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))
    
    ####################################################################################################
    
    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 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000
        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: