是否可以使用过滤器模块将 povray 文件直接放入 ConTeXt 文档中?我尝试使用此示例,但得到的是白页。也许它更复杂?(我使用 Linux)
\setuppapersize[A4][A4]
\setupcolors[state=start]
\usemodule[filter]
\defineexternalfilter
[povray]
[
directory=povtemp/,
output={\externalfilterbasefile.png},
filtercommand={povray "\externalfilterbasefile" "povtemp/\externalfilterbasefile" "\externalfilterinputfile"},
]
\starttext
My first povray render file :
\startbuffer[test.pov]
// PoVRay 3.7 Scene File " ... .pov"
// author: ...
// date: ...
//--------------------------------------------------------------------------
#version 3.7;
global_settings{ assumed_gamma 1.0 }
#default{ finish{ ambient 0.1 diffuse 0.9 }}
//--------------------------------------------------------------------------
#include "colors.inc"
#include "textures.inc"
#include "glass.inc"
#include "metals.inc"
#include "golds.inc"
#include "stones.inc"
#include "woods.inc"
#include "shapes.inc"
#include "shapes2.inc"
#include "functions.inc"
#include "math.inc"
#include "transforms.inc"
//--------------------------------------------------------------------------
// camera ------------------------------------------------------------------
#declare Camera_0 = camera {/*ultra_wide_angle*/ angle 75 // front view
location <-3.0 , 1.0 ,-3.0>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
#declare Camera_1 = camera {/*ultra_wide_angle*/ angle 90 // diagonal view
location <2.0 , 2.5 ,-3.0>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
#declare Camera_2 = camera {/*ultra_wide_angle*/ angle 90 //right side view
location <-3 , 1 , 0.0>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
#declare Camera_3 = camera {/*ultra_wide_angle*/ angle 90 // top view
location <0.0 , 4.0 ,-1>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
camera{Camera_0}
// sun ---------------------------------------------------------------------
light_source{< -3000, 3000, -3000> color White}
// sky ---------------------------------------------------------------------
sky_sphere { pigment { color rgb <1.0,1.0,1.0>}
} //end of skysphere
// = = = = = = = = = = ==
#declare White_Marble_Map =
color_map {
[0.0 rgb <0.9, 0.9, 0.9>]
[0.8 rgb <0.5, 0.5, 0.5>]
[1.0 rgb <0.2, 0.2, 0.2>]
}
//-------------------------------------
box {
<-1,0,-1>,<1,0,1>
texture { pigment{ color rgb<23,128,237>/255 filter .66 } // < 0.0, 0.5, 1.0> greenish blue
// normal { bumps 0.5 scale 0.05 }
finish { phong 1}
} // end of texture
}
//-------------------------------------------------------
sphere { <0,0,0>, 0.5
texture{pigment{color Yellow filter .66 }finish{phong .8}}
scale<1,1,1> rotate<0,0,0> translate<0,0.5,0>
} // end of sphere -----------------------------------
\stopbuffer
\stoptext
答案1
这更像是一个扩展的评论... Marjin 发布的解决方法可以稍微改进一下。首先,您可以使用 来cache=yes
确保连续的文件获得不同的编号。我还将常用选项收集在缓冲区中,然后使用以下bufferbefore
选项将其包括在内:
\usemodule[filter]
\define[1]\readPNGfile{\externalfigure[#1]}
\defineexternalfilter
[povray]
[
filtercommand={povray +O\externalfilteroutputfile\space +I\externalfilterinputfile},
output={\externalfilterbasefile.png},
readcommand=\readPNGfile,
cache=yes,
bufferbefore=pov-header,
]
\startbuffer[pov-header]
// PoVRay 3.7 Scene File " ... .pov"
// author: ...
// date: ...
//--------------------------------------------------------------------------
#version 3.7;
global_settings{ assumed_gamma 1.0 }
#default{ finish{ ambient 0.1 diffuse 0.9 }}
//--------------------------------------------------------------------------
#include "colors.inc"
#include "textures.inc"
#include "glass.inc"
#include "metals.inc"
#include "golds.inc"
#include "stones.inc"
#include "woods.inc"
#include "shapes.inc"
#include "shapes2.inc"
#include "functions.inc"
#include "math.inc"
#include "transforms.inc"
//--------------------------------------------------------------------------
// camera ------------------------------------------------------------------
#declare Camera_0 = camera {/*ultra_wide_angle*/ angle 75 // front view
location <-3.0 , 1.0 ,-3.0>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
#declare Camera_1 = camera {/*ultra_wide_angle*/ angle 90 // diagonal view
location <2.0 , 2.5 ,-3.0>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
#declare Camera_2 = camera {/*ultra_wide_angle*/ angle 90 //right side view
location <-3 , 1 , 0.0>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
#declare Camera_3 = camera {/*ultra_wide_angle*/ angle 90 // top view
location <0.0 , 4.0 ,-1>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
\stopbuffer
\starttext
My first povray render file :
\startpovray
camera{Camera_0}
// sun
light_source{< -3000, 3000, -3000> color White}
// sky
sky_sphere { pigment {color rgb <1.0,1.0,1.0>} }
#declare White_Marble_Map = color_map {
[0.0 rgb <0.9, 0.9, 0.9>]
[0.8 rgb <0.5, 0.5, 0.5>]
[1.0 rgb <0.2, 0.2, 0.2>]
}
box { <-1,0,-1>,<1,0,1>
texture { pigment{ color rgb<23,128,237>/255 filter .66 }
finish { phong 1}
}
}
sphere { <0,0,0>, 0.5
texture{ pigment{ color Yellow filter .66 }
finish { phong .8 }
}
scale<1,1,1> rotate<0,0,0> translate<0,0.5,0>
}
\stoppovray
and another one
\startpovray
camera{Camera_0}
// sun
light_source{< -3000, 3000, -3000> color White}
// sky
sky_sphere { pigment {color rgb <1.0,1.0,1.0>} }
#declare White_Marble_Map = color_map {
[0.0 rgb <0.9, 0.9, 0.9>]
[0.8 rgb <0.5, 0.5, 0.5>]
[1.0 rgb <0.2, 0.2, 0.2>]
}
box { <-1,0,-1>,<1,0,1>
texture { pigment{ color rgb<23,128,237>/255 filter .66 }
finish { phong 1}
}
}
sphere { <0,0,0>, 0.5
texture { pigment{color Red filter .66 }
finish{phong .8}
}
scale<1,1,1> rotate<0,0,0> translate<0,0.5,0>
}
\stoppovray
\stoptext
答案2
基本povray
语法是povray +Ooutputfile.png inputfile.pov
。如果输入文件没有.pov
扩展名(但例如.tmp
),则命令应该是povray +Ooutputfile.png +Iinputfile.tmp
,因此+I
必须将其添加到文件名前面。此外,两个选项之间的空格被 LaTeX 删除,因此您需要\space
在那里添加显式。
filter
ConTeXt 模块可以以多种方式使用,下面我使用了使用变体,\start[filtername]
如\stop[filtername]
所述https://github.com/adityam/filter,因此在这种情况下\startpovray
和\endpovray
。
一个重要的问题是,过滤器默认将过滤器的输出直接包含在文档中,即它期望 ConTeXt 语法作为输出,或者至少是纯文本。在povray
这种情况下,输出是一个.png
文件,因此您需要readcommand
在过滤器中明确设置以包含图形文件。
编辑:如果您想包含多个povray
输出,则需要在运行之间更改输出文件名,否则新运行将覆盖前一次运行的 PNG 文件。这可以通过使用命令\startpovray
合并到设置中的可选参数来完成。第一个代码块不需要这个可选参数,如果您只想包含单个图像,这可能会很方便。下面示例中的第二个块现在用于将可选参数设置为将在此块的文件名中使用的值。output
\externalfilterparameter
\startpovray[id=second]
second
梅威瑟:
\setuppapersize[A4][A4]
\setupcolors[state=start]
\usemodule[filter]
\def\readPNGfile#1{\externalfigure[#1]}
\defineexternalfilter
[povray]
[filtercommand={povray +O\externalfilteroutputfile\space +I\externalfilterinputfile},
id=default,
output={\externalfilterparameter{id}.png},
readcommand=\readPNGfile,
]
\starttext
My first povray render file :
\startpovray
// PoVRay 3.7 Scene File " ... .pov"
// author: ...
// date: ...
//--------------------------------------------------------------------------
#version 3.7;
global_settings{ assumed_gamma 1.0 }
#default{ finish{ ambient 0.1 diffuse 0.9 }}
//--------------------------------------------------------------------------
#include "colors.inc"
#include "textures.inc"
#include "glass.inc"
#include "metals.inc"
#include "golds.inc"
#include "stones.inc"
#include "woods.inc"
#include "shapes.inc"
#include "shapes2.inc"
#include "functions.inc"
#include "math.inc"
#include "transforms.inc"
//--------------------------------------------------------------------------
// camera ------------------------------------------------------------------
#declare Camera_0 = camera {/*ultra_wide_angle*/ angle 75 // front view
location <-3.0 , 1.0 ,-3.0>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
#declare Camera_1 = camera {/*ultra_wide_angle*/ angle 90 // diagonal view
location <2.0 , 2.5 ,-3.0>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
#declare Camera_2 = camera {/*ultra_wide_angle*/ angle 90 //right side view
location <-3 , 1 , 0.0>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
#declare Camera_3 = camera {/*ultra_wide_angle*/ angle 90 // top view
location <0.0 , 4.0 ,-1>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
camera{Camera_0}
// sun ---------------------------------------------------------------------
light_source{< -3000, 3000, -3000> color White}
// sky ---------------------------------------------------------------------
sky_sphere { pigment { color rgb <1.0,1.0,1.0>}
} //end of skysphere
// = = = = = = = = = = ==
#declare White_Marble_Map =
color_map {
[0.0 rgb <0.9, 0.9, 0.9>]
[0.8 rgb <0.5, 0.5, 0.5>]
[1.0 rgb <0.2, 0.2, 0.2>]
}
//-------------------------------------
box {
<-1,0,-1>,<1,0,1>
texture { pigment{ color rgb<23,128,237>/255 filter .66 } // < 0.0, 0.5, 1.0> greenish blue
// normal { bumps 0.5 scale 0.05 }
finish { phong 1}
} // end of texture
}
//-------------------------------------------------------
sphere { <0,0,0>, 0.5
texture{pigment{color Yellow filter .66 }finish{phong .8}}
scale<1,1,1> rotate<0,0,0> translate<0,0.5,0>
} // end of sphere -----------------------------------
\stoppovray
and another one
\startpovray[id=second]
// PoVRay 3.7 Scene File " ... .pov"
// author: ...
// date: ...
//--------------------------------------------------------------------------
#version 3.7;
global_settings{ assumed_gamma 1.0 }
#default{ finish{ ambient 0.1 diffuse 0.9 }}
//--------------------------------------------------------------------------
#include "colors.inc"
#include "textures.inc"
#include "glass.inc"
#include "metals.inc"
#include "golds.inc"
#include "stones.inc"
#include "woods.inc"
#include "shapes.inc"
#include "shapes2.inc"
#include "functions.inc"
#include "math.inc"
#include "transforms.inc"
//--------------------------------------------------------------------------
// camera ------------------------------------------------------------------
#declare Camera_0 = camera {/*ultra_wide_angle*/ angle 75 // front view
location <-3.0 , 1.0 ,-3.0>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
#declare Camera_1 = camera {/*ultra_wide_angle*/ angle 90 // diagonal view
location <2.0 , 2.5 ,-3.0>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
#declare Camera_2 = camera {/*ultra_wide_angle*/ angle 90 //right side view
location <-3 , 1 , 0.0>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
#declare Camera_3 = camera {/*ultra_wide_angle*/ angle 90 // top view
location <0.0 , 4.0 ,-1>
right x*image_width/image_height
look_at <0.0 , 1.0 , 0.0>}
camera{Camera_0}
// sun ---------------------------------------------------------------------
light_source{< -3000, 3000, -3000> color White}
// sky ---------------------------------------------------------------------
sky_sphere { pigment { color rgb <1.0,1.0,1.0>}
} //end of skysphere
// = = = = = = = = = = ==
#declare White_Marble_Map =
color_map {
[0.0 rgb <0.9, 0.9, 0.9>]
[0.8 rgb <0.5, 0.5, 0.5>]
[1.0 rgb <0.2, 0.2, 0.2>]
}
//-------------------------------------
box {
<-1,0,-1>,<1,0,1>
texture { pigment{ color rgb<23,128,237>/255 filter .66 } // < 0.0, 0.5, 1.0> greenish blue
// normal { bumps 0.5 scale 0.05 }
finish { phong 1}
} // end of texture
}
//-------------------------------------------------------
sphere { <0,0,0>, 0.5
texture{pigment{color Red filter .66 }finish{phong .8}}
scale<1,1,1> rotate<0,0,0> translate<0,0.5,0>
} // end of sphere -----------------------------------
\stoppovray
\stoptext
结果: