From K-3D
Description
Script node that acts as a render engine
|
Metadata
Properties
Overview
RenderEngineScript can be used to do custom rendering under script control. "Rendering" in this context means simply converting the contents of a K-3D document into some alternate representation that can be stored in a file on disk. You might write a script that scans the contents of a document and dumps a description to a text file, or one that generates a POVRAY file and pipes it to a waiting render engine - the sky is literally the limit! The following example creates a DOT file (a type of graph representation) and starts a copy of AT&T GraphViz that renders the file to an SVG image:
#python
import k3d
graph = """
digraph G {
node [ shape="box" style="filled" color="black" fillcolor="white" ];
"""
for node in Document.nodes():
graph += str(hash(node))
graph += "[\n"
graph += "label=\"" + node.name + "\"\n"
graph += "URL=\"http://wiki.k-3d.org/" + node.factory().name + "\"\n"
graph += "]\n"
for node in Document.nodes():
for prop in node.properties():
if prop.type == "k3d::inode*":
referenced_node = prop.internal_value
if referenced_node:
graph += str(hash(referenced_node)) + "->" + str(hash(node))
graph += "[\n"
graph += "style=dotted\n"
graph += "label=\"" + prop.name + "\"\n"
graph += "]\n"
source_prop = Document.get_dependency(prop)
if source_prop:
graph += str(hash(source_prop.node)) + "->" + str(hash(prop.node))
graph += "[\n"
graph += "taillabel=\"" + source_prop.name + "\"\n"
graph += "headlabel=\"" + prop.name + "\"\n"
graph += "]\n"
graph += "}"
from subprocess import *
Popen(["dot", "-Tsvg", "-o" + OutputImage], stdin=PIPE).communicate(graph)
Script Environment
The following parameters will be available to your script at runtime (see the documentation for your script engine for details on how these parameters can be accessed programmatically).
Name
| Description
|
Document
| A reference to the document that owns this node.
|
Node
| A reference to this node.
|
OutputImage
| The name of the file to be rendered.
|
ViewImage
| Boolean value indicating whether the rendered image should be displayed to the user (can be ignored).
|