pov-out.cpp revision 8e7d89783f2ce56b712b76c928a27372ba542a57
/*
* A simple utility for exporting Inkscape svg Shapes as PovRay bezier
* prisms. Note that this is output-only, and would thus seem to be
* better placed as an 'export' rather than 'output'. However, Export
* handles all or partial documents, while this outputs ALL shapes in
* the current SVG document.
*
* For information on the PovRay file format, see:
*
* Authors:
* Bob Jamison <rjamison@titan.com>
*
* Copyright (C) 2004 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "pov-out.h"
#include "inkscape.h"
#include "sp-path.h"
#include <style.h>
#include "libnr/n-art-bpath.h"
namespace Inkscape
{
namespace Extension
{
namespace Internal
{
static const char *
{
return (const char *)g_ascii_formatd(sbuffer,
}
/**
* Make sure that we are in the database
*/
bool
{
/* We don't need a Key
if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_POV))
return FALSE;
*/
return TRUE;
}
/**
* This function searches the Repr tree recursively from the given node,
* and adds refs to all nodes with the given name, to the result vector
*/
static void
char const *name)
{
if ( !name
}
}
/**
* used for saving information about shapes
*/
class PovShapeInfo
{
public:
{}
virtual ~PovShapeInfo()
{}
};
static double
{
double ret = 1.0;
}
return ret;
}
/**
* Saves the <paths> of an Inkscape SVG file as PovRay spline definitions
*/
void
{
//findElementsByTagName(results, SP_ACTIVE_DOCUMENT->rroot, "path");
return;
if (!f)
return;
fprintf(f, "/*#################################################\n");
fprintf(f, "### This PovRay document was generated by Inkscape\n");
fprintf(f, "### http://www.inkscape.org\n");
fprintf(f, "##################################################*/\n\n\n");
//we only need 8 for printf() calls that call dstr() 8 times
double bignum = 1000000.0;
unsigned indx;
{
//### Fetch the object from the repr info
if (!reprobj)
continue;
//### Get the transform of the item
if (!SP_IS_ITEM(reprobj))
{
continue;
}
//### Get the Shape
{
continue;
}
if (sp_curve_empty(curve))
continue;
//Try to get the fill color of the shape
/* fixme: Handle other fill types, even if this means translating gradients to a single
flat colour. */
// see color.h for how to parse SPColor
float rgb[3];
* effective_opacity(shape) );
//gchar *str = g_strdup_printf("rgbf < %1.3f, %1.3f, %1.3f %1.3f>",
// rgb[0], rgb[1], rgb[2], 1.0 - dopacity);
}
int curveNr;
//Count the NR_CURVETOs/LINETOs
int segmentCount=0;
segmentCount++;
double lastx = 0.0;
double lasty = 0.0;
fprintf(f, "/*##############################################\n");
fprintf(f, "##############################################*/\n");
fprintf(f, " linear_sweep\n");
fprintf(f, " bezier_spline\n");
fprintf(f, " 1.0, //top\n");
fprintf(f, " 0.0, //bottom\n");
int segmentNr = 0;
using NR::X;
using NR::Y;
case NR_MOVETO:
case NR_MOVETO_OPEN:
//fprintf(f, "moveto: %f %f\n", bp->x3, bp->y3);
break;
case NR_CURVETO:
//fprintf(f, " /*%4d*/ <%f, %f>, <%f, %f>, <%f,%f>, <%f,%f>",
// segmentNr++, lastx, lasty, x1, y1, x2, y2, x3, y3);
fprintf(f, " /*%4d*/ <%s, %s>, <%s, %s>, <%s,%s>, <%s,%s>",
segmentNr++,
if (segmentNr < segmentCount)
fprintf(f, ",\n");
else
fprintf(f, "\n");
break;
case NR_LINETO:
//fprintf(f, " /*%4d*/ <%f, %f>, <%f, %f>, <%f,%f>, <%f,%f>",
// segmentNr++, lastx, lasty, lastx, lasty, x3, y3, x3, y3);
fprintf(f, " /*%4d*/ <%s, %s>, <%s, %s>, <%s,%s>, <%s,%s>",
segmentNr++,
if (segmentNr < segmentCount)
fprintf(f, ",\n");
else
fprintf(f, "\n");
//fprintf(f, "lineto\n");
break;
case NR_END:
//fprintf(f, "end\n");
break;
}
}
fprintf(f, "}\n");
/*
fprintf(f, "#declare %s_MIN_X = %4.3f;\n", id, cminx);
fprintf(f, "#declare %s_CENTER_X = %4.3f;\n", id, (cmaxx+cminx)/2.0);
fprintf(f, "#declare %s_MAX_X = %4.3f;\n", id, cmaxx);
fprintf(f, "#declare %s_WIDTH = %4.3f;\n", id, cmaxx-cminx);
fprintf(f, "#declare %s_MIN_Y = %4.3f;\n", id, cminy);
fprintf(f, "#declare %s_CENTER_Y = %4.3f;\n", id, (cmaxy+cminy)/2.0);
fprintf(f, "#declare %s_MAX_Y = %4.3f;\n", id, cmaxy);
fprintf(f, "#declare %s_HEIGHT = %4.3f;\n", id, cmaxy-cminy);
*/
fprintf(f, "#declare %s_COLOR = %s;\n",
fprintf(f, "/*##############################################\n");
fprintf(f, "##############################################*/\n\n\n\n");
}//for
//## Let's make a union of all of the Shapes
char const *id = "AllShapes";
fprintf(f, "/*##############################################\n");
fprintf(f, "### UNION OF ALL SHAPES IN DOCUMENT\n");
fprintf(f, "##############################################*/\n");
fprintf(f, "\n\n");
fprintf(f, "/**\n");
fprintf(f, " * Allow the user to redefine the finish{}\n");
fprintf(f, " * by declaring it before #including this file\n");
fprintf(f, " */\n");
fprintf(f, " phong 0.5\n");
fprintf(f, " reflection 0.3\n");
fprintf(f, " specular 0.5\n");
fprintf(f, "}\n");
fprintf(f, "#end\n");
fprintf(f, "\n\n");
fprintf(f, " texture { \n");
else
fprintf(f, " pigment { rgb <0,0,0> }\n");
fprintf(f, " } \n");
fprintf(f, " } \n");
}
fprintf(f, "}\n\n\n\n");
fprintf(f, "/*#### Same union, but with Z-diffs (actually Y in pov) ####*/\n");
fprintf(f, "\n\n");
fprintf(f, "/**\n");
fprintf(f, " * Allow the user to redefine the Z-Increment\n");
fprintf(f, " */\n");
fprintf(f, "#ifndef (AllShapes_Z_Increment)\n");
fprintf(f, "#end\n");
fprintf(f, "\n");
fprintf(f, "#declare AllShapes_Z_Scale = 1.0;\n");
fprintf(f, "\n\n");
fprintf(f, " texture { \n");
else
fprintf(f, " pigment { rgb <0,0,0> }\n");
fprintf(f, " } \n");
fprintf(f, " } \n");
fprintf(f, "#declare %s_Z_Scale = %s_Z_Scale + %s_Z_Increment;\n\n",
}
fprintf(f, "}\n");
/*
fprintf(f, "#declare %s_MIN_X = %4.3f;\n", id, minx);
fprintf(f, "#declare %s_CENTER_X = %4.3f;\n", id, (maxx+minx)/2.0);
fprintf(f, "#declare %s_MAX_X = %4.3f;\n", id, maxx);
fprintf(f, "#declare %s_WIDTH = %4.3f;\n", id, maxx-minx);
fprintf(f, "#declare %s_MIN_Y = %4.3f;\n", id, miny);
fprintf(f, "#declare %s_CENTER_Y = %4.3f;\n", id, (maxy+miny)/2.0);
fprintf(f, "#declare %s_MAX_Y = %4.3f;\n", id, maxy);
fprintf(f, "#declare %s_HEIGHT = %4.3f;\n", id, maxy-miny);
*/
fprintf(f, "/*##############################################\n");
fprintf(f, "##############################################*/\n\n\n\n");
}
//All done
fclose(f);
}
#include "clear-n_.h"
/**
* This is the definition of PovRay output. This function just
* calls the extension system with the memory allocated XML that
* describes the data.
*/
void
{
"<inkscape-extension>\n"
"<id>org.inkscape.output.pov</id>\n"
"<output>\n"
"<extension>.pov</extension>\n"
"<mimetype>text/x-povray-script</mimetype>\n"
"</output>\n"
"</inkscape-extension>",
new PovOutput());
}
} //namespace Internal
} //namespace Extension
} //namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :