pov-out.cpp revision 07b7f1aaaf1087716e784a50cf574a059f7018d3
1434N/A * A simple utility for exporting Inkscape svg Shapes as PovRay bezier 492N/A * prisms. Note that this is output-only, and would thus seem to be 492N/A * better placed as an 'export' rather than 'output'. However, Export 919N/A * handles all or partial documents, while this outputs ALL shapes in 919N/A * the current SVG document. 919N/A * For information on the PovRay file format, see: 919N/A * Bob Jamison <ishmal@inkscape.org> 919N/A * Copyright (C) 2004-2008 Authors 919N/A * Released under GNU GPL, read the file 'COPYING' for more information 492N/A//######################################################################## 492N/A//######################################################################## //######################################################################## //######################################################################## // TODO investigate this. The early return seems that it would abort early. // Plus is will emit a warning, which may not be proper here. //######################################################################## //######################################################################## * We want to control floating output format * Output data to the buffer, printf()-style * Output an rgbf color vector //"rgbf < %1.3f, %1.3f, %1.3f %1.3f>" * Output one bezier's start, start-control, end-control, and end nodes //" /*%4d*/ <%f, %f>, <%f, %f>, <%f,%f>, <%f,%f>" out(
"/*###################################################################\n");
out(
"### This PovRay document was generated by Inkscape\n");
out(
"#####################################################################\n");
out(
"### ============\n");
out(
"### POVRay information can be found at\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(
"### For an example of how to use this file, look at\n");
out(
"### If you have any problems with this output, please see the\n");
out(
"### the #inkscape channel on irc.freenode.net . \n");
out(
"###################################################################*/\n");
out(
"/*###################################################################\n");
out(
"## Exports in this file\n");
out(
"##==========================\n");
out(
"###################################################################*/\n");
out(
"/*###################################################################\n");
out(
"### E N D F I L E\n");
out(
"###################################################################*/\n");
* Output the curve data to buffer //Try to get the fill color of the shape /* fixme: Handle other fill types, even if this means translating gradients to a single // see color.h for how to parse SPColor //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: * closing line segment) before we write out segment data. Since we are * going to skip degenerate (zero length) paths, we need to loop over all * subpaths and segments first. * For all Subpaths in the <path> * For all segments in the subpath, including extra closing segment defined by 2geom // Skip zero length segments. out(
"/*###################################################\n");
out(
"###################################################*/\n");
* 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, including extra closing segment defined by 2geom // Skip zero length segments err(
"logical error, because pathv_to_linear_and_cubic_beziers was used");
err(
"Too many segments");
out(
"#declare %s_COLOR = %s;\n",
out(
"/*###################################################\n");
out(
"###################################################*/\n\n\n\n");
* Descend the svg tree recursively, translating data * Output the curve data to buffer //## Let's make a union of all of the Shapes out(
"/*###################################################\n");
out(
"### UNION OF ALL SHAPES IN DOCUMENT\n");
out(
"###################################################*/\n");
out(
" * Allow the user to redefine the finish{}\n");
out(
" * by declaring it before #including this file\n");
out(
"#ifndef (%s_Finish)\n",
pfx);
out(
"#declare %s_Finish = finish {\n",
pfx);
out(
" reflection 0.3\n");
out(
" pigment { rgb <0,0,0> }\n");
out(
" finish { %s_Finish }\n",
pfx);
out(
"/*#### Same union, but with Z-diffs (actually Y in pov) ####*/\n");
out(
" * Allow the user to redefine the Z-Increment\n");
out(
"#ifndef (AllShapes_Z_Increment)\n");
out(
"#declare AllShapes_Z_Increment = %s;\n",
DSTR(
zinc));
out(
"#declare AllShapes_Z_Scale = 1.0;\n");
out(
"#declare %s_Z = union {\n",
pfx);
out(
" pigment { rgb <0,0,0> }\n");
out(
" finish { %s_Finish }\n",
pfx);
out(
" scale <1, %s_Z_Scale, 1>\n",
pfx);
out(
"#declare %s_Z_Scale = %s_Z_Scale + %s_Z_Increment;\n\n",
out(
"/*##############################################\n");
out(
"##############################################*/\n");
//######################################################################## //######################################################################## * Set values back to initial state * Saves the Shapes of an Inkscape SVG file as PovRay spline definitions //###### SAVE IN POV FORMAT TO BUFFER //# Lets do the curves first, to get the stats //######################################################################## //######################################################################## * API call to save document /* See comments in JavaFSOutput::save re the name `filename_utf8'. */ * Make sure that we are in the database if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_POV)) * This is the definition of PovRay output. This function just * calls the extension system with the memory allocated XML that "<name>" N_(
"PovRay Output")
"</name>\n" "<id>org.inkscape.output.pov</id>\n" "<extension>.pov</extension>\n" "<filetypename>" N_(
"PovRay (*.pov) (paths and shapes only)")
"</filetypename>\n" "<filetypetooltip>" N_(
"PovRay Raytracer File")
"</filetypetooltip>\n" c-file-style:"stroustrup" c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :