pov-out.cpp revision 77eda576f455eeb23c7b92510f38bc60738473ab
/*
* 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 <ishmal@inkscape.org>
*
* Copyright (C) 2004-2008 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 <inkscape_version.h>
#include <sp-path.h>
#include <style.h>
#include "helper/geom-curves.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
//########################################################################
/**
* We want to control floating output format
*/
{
"%.8f", (gdouble)d);
return s;
}
/**
* Output data to the buffer, printf()-style
*/
{
}
/**
* Output a 2d vector
*/
{
}
/**
* Output a 3d vector
*/
{
}
/**
* Output a v4d ector
*/
{
}
/**
* Output an rgbf color vector
*/
{
//"rgbf < %1.3f, %1.3f, %1.3f %1.3f>"
out("rgbf ");
vec4(r, g, b, f);
}
/**
* Output one bezier's start, start-control, end-control, and end nodes
*/
double startCtrlX, double startCtrlY,
{
//" /*%4d*/ <%f, %f>, <%f, %f>, <%f,%f>, <%f,%f>"
out(", ");
out(", ");
out(", ");
}
/**
* 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("### If you have any problems with this output, please see the\n");
out("### Inkscape project at http://www.inkscape.org, or visit\n");
out("### the #inkscape channel on irc.freenode.net . \n");
out("###\n");
out("###################################################################*/\n");
out("\n\n");
out("/*###################################################################\n");
out("## Exports in this file\n");
out("##==========================\n");
out("###################################################################*/\n");
out("\n\n\n");
return true;
}
/**
* Output the file footer
*/
{
out("\n\n");
out("/*###################################################################\n");
out("### E N D F I L E\n");
out("###################################################################*/\n");
out("\n\n");
return true;
}
/**
* Output the curve data to buffer
*/
{
using Geom::X;
using Geom::Y;
//### Get the Shape
return true;
return true;
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. */
if (style)
{
{
// 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);
}
}
// convert the path to only lineto's and cubic curveto's:
//Count the NR_CURVETOs/LINETOs (including closing line segment)
int segmentCount = 0;
{
segmentCount += 1;
}
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;
/**
* at moment of writing, 2geom lacks proper initialization of empty intervals in rect...
*/
/**
* For all Subpaths in the <path>
*/
{
/**
* For all segments in the subpath
*/
{
if( is_straight_curve(*cit) )
{
nrNodes += 8;
}
{
nrNodes += 8;
}
else
{
g_warning("logical error, because pathv_to_linear_and_cubic_beziers was used");
return false;
}
if (segmentNr < segmentCount)
out(",\n");
else
out("\n");
}
}
out("}\n");
out("#declare %s_COLOR = %s;\n",
out("/*###################################################\n");
out("###################################################*/\n\n\n\n");
return true;
}
/**
* Output the curve data to buffer
*/
{
/**
* If the object is an Item, try processing it
*/
{
return false;
}
/**
* Descend into children
*/
{
return false;
}
return true;
}
/**
* Output the curve data to buffer
*/
{
double bignum = 1000000.0;
return false;
//## 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");
}
return true;
}
//########################################################################
//# M A I N O U T P U T
//########################################################################
/**
* Set values back to initial state
*/
{
nrNodes = 0;
nrSegments = 0;
nrShapes = 0;
}
/**
* Saves the Shapes 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
{
return;
}
if (!doHeader())
{
return;
}
if (!doTail())
{
return;
}
//###### 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
{
"<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 :