pov-out.cpp revision 8eedd32fec442b11bd26c213c06c2e780209a825
/*
* 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 <ishmalius@gmail.com>
*
* Copyright (C) 2004-2007 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"
#include <string>
#include <stdio.h>
#include <stdarg.h>
namespace Inkscape
{
namespace Extension
{
namespace Internal
{
//########################################################################
//# U T I L I T Y
//########################################################################
/**
* 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)
{
}
static double
{
double ret = 1.0;
{
}
return ret;
}
//########################################################################
//# OUTPUT FORMATTING
//########################################################################
{
return (const char *)g_ascii_formatd(sbuffer,
}
/**
* Not-threadsafe version
*/
static const char *dstr(double d)
{
return formatDouble(_dstr_buf, d);
}
/**
* Output data to the buffer, printf()-style
*/
{
}
/**
* Output a 3d vector
*/
{
}
/**
* Output a 3d vector
*/
{
}
/**
* Output a v4d ector
*/
{
}
/**
* Output an rgbf color vector
*/
{
//"rgbf < %1.3f, %1.3f, %1.3f %1.3f>"
vec4(r, g, b, f);
}
/**
* Output one bezier's start, start-control, end-control, and end nodes
*/
{
//" /*%4d*/ <%f, %f>, <%f, %f>, <%f,%f>, <%f,%f>"
char buf[32];
}
/**
* Output the file header
*/
{
out("/*###################################################################\n");
out("### This PovRay document was generated by Inkscape\n");
out("### http://www.inkscape.org\n");
out("#####################################################################\n");
out("### NOTES:\n");
out("### ============\n");
out("### POVRay information can be found at\n");
out("### http://www.povray.org\n");
out("###\n");
out("### The 'AllShapes' objects at the bottom are provided as a\n");
out("### preview of how the output would look in a trace. However,\n");
out("### the main intent of this file is to provide the individual\n");
out("### shapes for inclusion in a POV project.\n");
out("###\n");
out("### For an example of how to use this file, look at\n");
out("### share/examples/istest.pov\n");
out("###################################################################*/\n");
out("\n\n");
out("/*###################################################################\n");
out("## Exports in this file\n");
out("##==========================\n");
out("###################################################################*/\n");
out("\n\n\n");
}
/**
* Output the file footer
*/
{
out("\n\n");
out("/*###################################################################\n");
out("### E N D F I L E\n");
out("###################################################################*/\n");
out("\n\n");
}
/**
* Output the curve data to buffer
*/
{
//findElementsByTagName(results, SP_ACTIVE_DOCUMENT->rroot, "path");
return;
double bignum = 1000000.0;
{
//### Fetch the object from the repr info
if (!str)
continue;
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;
nrShapes++;
//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);
}
//Count the NR_CURVETOs/LINETOs
int segmentCount=0;
segmentCount++;
double lastx = 0.0;
double lasty = 0.0;
out("/*###################################################\n");
out("###################################################*/\n");
out(" linear_sweep\n");
out(" bezier_spline\n");
out(" 1.0, //top\n");
out(" 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);
nrNodes += 8;
if (segmentNr < segmentCount)
out(",\n");
else
out("\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);
nrNodes += 8;
if (segmentNr < segmentCount)
out(",\n");
else
out("\n");
//fprintf(f, "lineto\n");
break;
}
case NR_END:
{
//fprintf(f, "end\n");
break;
}
}
bp++;
}
out("}\n");
out("#declare %s_COLOR = %s;\n",
out("/*###################################################\n");
out("###################################################*/\n\n\n\n");
}//for
//## Let's make a union of all of the Shapes
{
out("/*###################################################\n");
out("### UNION OF ALL SHAPES IN DOCUMENT\n");
out("###################################################*/\n");
out("\n\n");
out("/**\n");
out(" * Allow the user to redefine the finish{}\n");
out(" * by declaring it before #including this file\n");
out(" */\n");
out(" phong 0.5\n");
out(" reflection 0.3\n");
out(" specular 0.5\n");
out("}\n");
out("#end\n");
out("\n\n");
{
out(" texture { \n");
else
out(" pigment { rgb <0,0,0> }\n");
out(" } \n");
out(" } \n");
}
out("}\n\n\n\n");
out("/*#### Same union, but with Z-diffs (actually Y in pov) ####*/\n");
out("\n\n");
out("/**\n");
out(" * Allow the user to redefine the Z-Increment\n");
out(" */\n");
out("#ifndef (AllShapes_Z_Increment)\n");
out("#end\n");
out("\n");
out("#declare AllShapes_Z_Scale = 1.0;\n");
out("\n\n");
{
out(" texture { \n");
else
out(" pigment { rgb <0,0,0> }\n");
out(" } \n");
out(" } \n");
out("#declare %s_Z_Scale = %s_Z_Scale + %s_Z_Increment;\n\n",
}
out("}\n");
out("/*##############################################\n");
out("##############################################*/\n");
out("\n\n");
}
}
//########################################################################
//# M A I N O U T P U T
//########################################################################
/**
* Set values back to initial state
*/
{
nrNodes = 0;
nrSegments = 0;
nrShapes = 0;
}
/**
* Saves the <paths> of an Inkscape SVG file as PovRay spline definitions
*/
{
reset();
//###### SAVE IN POV FORMAT TO BUFFER
//# Lets do the curves first, to get the stats
doHeader();
doTail();
//###### WRITE TO FILE
if (!f)
return;
{
}
fclose(f);
}
//########################################################################
//# EXTENSION API
//########################################################################
#include "clear-n_.h"
/**
* API call to save document
*/
void
{
}
/**
* Make sure that we are in the database
*/
{
/* We don't need a Key
if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_POV))
return FALSE;
*/
return true;
}
/**
* 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 :