<< PythonからRenderMan その12 戻る PythonからRenderManシーン記述 >>

PythonからRenderMan その13

ドーナツ作り。以前の記事を書き換えたものです。ありがとうございます。



#proc_torus2_pr.py
#set PYTHONPATH=C:\Python25;C:\Python\Scripts;%RMANTREE%\bin
import getpass
import time
# import the python renderman library
import prman

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

filename = "proc_geom.rib"

ri.Begin(ri.RENDER)

def TorusWave(ri,nwaves,thetamax) :
if(nwaves < 1) :
print "need positive number of waves"
return
innerrad = 2.0/(8.0 * nwaves +2)
ri.Rotate(90.0,1.0,0.0,0.0)
ri.Sphere(innerrad,-innerrad,0,thetamax)
outerrad =0.0
for wave in range(1,nwaves) :
outerrad=outerrad+(innerrad*2)
ri.Torus(outerrad,innerrad,0.0,180.0,thetamax)
outerrad=outerrad+(innerrad*2)
ri.Torus(outerrad,innerrad,180.0,360.0,thetamax)


#ArchiveRecord is used to add elements to the rib stream in this case comments
# note the function is overloaded so we can concatinate output
ri.ArchiveRecord(ri.COMMENT, 'File ' +filename)
ri.ArchiveRecord(ri.COMMENT, "Created by " + getpass.getuser())
ri.ArchiveRecord(ri.COMMENT, "Creation Date: " +time.ctime(time.time()))

# now we add the display element using the usual elements
# FILENAME DISPLAY Type Output format
ri.Display("proc_torus2.png", "file", "rgb")
ri.Format(512, 384, -1.0)
ri.Projection(ri.PERSPECTIVE,{ri.FOV:30})

# now we start our world
colours ={
"red":[1,0,0],
"white":[1,1,1],
"green":[0,1,0],
"blue":[0,0,1],
"black":[0,0,0],
"yellow":[1,1,0]
}

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

ri.Translate(0,0,9) #move the global view position
ri.Surface("plastic")

ri.TransformBegin()
ri.Rotate(40,1,0,0)
ri.Color(colours["red"])
ri.Attribute ("identifier",{"name": "Wave1"})
TorusWave(ri,8,360.0)
ri.TransformEnd()

ri.TransformBegin()
ri.Rotate(55,1,0,0)
ri.Color(colours["green"])
ri.Translate(2.2,0,0)
ri.Attribute( "identifier",{ "name" :"Wave2"})
TorusWave(ri,8,360.0)
ri.TransformEnd()

ri.TransformBegin()
ri.Rotate(35,1,0,0)
ri.Color(colours["blue"])
ri.Translate(-2.2,0,0)
ri.Attribute("identifier",{ "name" : "Wave3"})
TorusWave(ri,8,360.0)
ri.TransformEnd()
#end our world

ri.WorldEnd()
ri.End()


  • -
  • -

<< PythonからRenderMan その12 戻る PythonからRenderManシーン記述 >>