<< PythonからRenderMan その13 戻る jrMan >>

PythonからRenderManシーン記述

レイトレーシングを使わないで、それらしく見せる反射トリックですね。
レンダリングは速いです。
過去のPixarのC言語によるシーン記述をPythonで書き換えてみました。
まだまだ課題がありますが、チャレンジですね。ありがとうございます。
generate_scn.jpg


#generate_scn_pr.py
#Modified from a C program that generates a scene, May,1990, Pixar
#set PYTHONPATH=C:\Python25;C:\Python\Scripts;%RMANTREE%\bin
# import the python renderman library
import prman

ri = prman.Ri() # create an instance of the RenderMan interface
ri.Option("rib", {"string asciistyle": "indented"})

filename = "generate_scn.rib"

"""
* Set RenderMan options for medium quality/speed tradeoff.
"""

REFLECTION=0


def SetupOptions():
global REFLECTION
ASPECT_RATIO=1.33333
TEXTURE_ROWS=256
IMAGE_ROWS=300
gsz = 32
bktsz = [12, 12]
splits = 5

#ri.Option("limits", {"gridsize": gsz,"eyesplits",:splits,"bucketsize": bktsz})
ri.ShadingRate(2.)
ri.PixelSamples(2., 2.)
ri.PixelFilter(ri.BoxFilter, 1., 1.)

if REFLECTION:
ri.Display("refl.tif","file", "rgb")
ri.Format(TEXTURE_ROWS, TEXTURE_ROWS, ASPECT_RATIO);
else:
ri.Display("generate_scn.tif","file", "rgb")
ri.Format(512, 384, -1.0)


"""
/*
* Set RenderMan camera parameters.
*/
"""

def SetupCamera():
global REFLECTION
m = [
.970143, -0.004705, -.24249, 0,
0, .999812, -0.0193992, 0,
.242536, 0.01882, .96996, 0,
-7.27607, -1.96434, 53.406, 1
]

fov = 25.0

ri.Projection(ri.PERSPECTIVE,{ri.FOV:fov})
ri.Transform(m)

if REFLECTION:
#/* Transform z=0 plane to coincide with reflection plane. */
ri.Translate(0., 0., -0.05)

#/* Reflect camera through the reflection plane z=0. */
ri.Scale(1., 1., -1.)
#/* Transform reflection plane back to z=0. */
ri.Translate(0., 0., 0.05);


"""
* The model consists of three "walls" of a room (actually two
* walls and the floor) with a mirror on one of the walls.
* When rendering the REFLECTION image, the mirror
* and the wall it is hanging on are both removed so that
* the camera can see into the room from the other side of
* the wall.
"""

def SetupModel():
global REFLECTION
c = [[ 0.5, 0.4, 0.1], [ 0.3, 0.5, 0.5],[ 1, 1, 1], [ 0.4, 0.2, 0.7]]

if REFLECTION:
NWALLS=2 #/* Just do two walls. */
walls = [ [0, 0, -100, 0, 0, 0, 100, 0, -100, 100, 0, 0],[0, 100, -100, 0, 100, 0, 0, 0, -100, 0, 0, 0]]
else:
#ri.MakeTexture( "refl.tif", "refl.tex", "periodic", "periodic", "gaussian", 1, 1)
NWALLS=3 #/* Do three walls and mirror. */
walls = [ [0, 0, -100, 0, 0, 0, 100, 0, -100, 100, 0, 0],[ 0, 100, -100, 0, 100, 0, 0, 0, -100, 0, 0, 0],[ 0, 100, 0, 100, 100, 0, 0, 0, 0 , 100, 0, 0]]
mirror = [ 5, 10.5, -.05, 10, 10.5, -.05,5, 0.5, -.05, 10, 0.5, -.05]

ri.AttributeBegin()
ri.Color(c[2])
ri.Surface("texmap",{'string texname':"refl.tex"})
#ri.Surface("shinymetal",{'string texturename':"refl.tex"})
ri.Patch("bilinear",{'P': mirror})
ri.AttributeEnd()


ri.Color(c[0])
for i in range(NWALLS):
ri.Patch("bilinear",{'P': walls[i]})
ri.Color(c[1])

#/* Put a teapot in the room. */
ri.Color(c[3])
ri.TransformBegin()
ri.Translate(5., 1., -2.)
ri.Rotate(90., 0., 1., 0.)
ri.Rotate(-90., 1., 0., 0.)
ri.Geometry("teapot")
ri.TransformEnd()


ri.Begin(ri.RENDER)

SetupCamera()

SetupOptions()

# start our world
ri.WorldBegin()
ri.LightSource("distantlight", {ri.HANDLEID: "1","to":[0,0,1]})
ri.LightSource("ambientlight", {ri.HANDLEID: "2", "intensity":[0.4]})

SetupModel()

ri.WorldEnd()
ri.End()



テクスチャについては、
MakeTexture "refl.tif" "refl.tex" "periodic" "periodic" "gaussian" 1 1
を記述したRIBを使ってtexファイルを出力しました。
Wrong state to call RiMakeTexture.なので、調べます。ありがとうございます。
  • -
  • -

<< PythonからRenderMan その13 戻る jrMan >>