Rendering学習日記

日々、3DCGの世界は進歩しています。勉強して理解したことをまとめていきます。RenderMan互換レンダラーやグローバル・イルミネーション。いろんなことに好奇心を持って、面白くなる。目指せShader書き!!
ありがとうございます。

「実践CGへの誘い」例題をPythonで行う その3

「実践CGへの誘い」p.25
Listing 2.3
list23.jpg
#list23.py
# Copyrighted Pixar 1989
# From the RenderMan Companion p. 25
# Listing 2.3 Control over viewer and color

import cgkit.cri
from cgkit.cgtypes import *

# Load the RenderMan API.
# Replace the library name with whatever renderer you want to use.
ri = cgkit.cri.loadRI("3delight")
cgkit.cri.importRINames(ri, globals())

L= -.5 #* For x: left side */
R= .5 # /* For x: right side */
D= -.5 # /* For y: down side */
U= .5 # /* For y: upper side */
F= .5 # /* For z: far side */
N= -.5 # /* For z: near side */

#/* UnitCube(): define a cube in the graphics environment */
def UnitCube():
Cube=[
[ [L,D,F], [L,D,N], [R,D,N], [R,D,F] ], #/* Bottom face */
[ [L,D,F], [L,U,F], [L,U,N], [L,D,N] ], #/* Left face */
[ [R,U,N], [L,U,N], [L,U,F], [R,U,F] ], #/* Top face */
[ [R,U,N], [R,U,F], [R,D,F], [R,D,N] ], #/* Right face */
[ [R,D,F], [R,U,F], [L,U,F], [L,D,F] ], #/* Far face */
[ [L,U,N], [R,U,N], [R,D,N], [L,D,N] ] #/* Near face */
];
for i in range(6):
RiPolygon(P=Cube[i])


#square=[.5,.5,.5,.5,-.5,.5,-.5,-.5,.5,-.5,.5,.5]

color=(.2,.4,.6)

RiBegin(RI_NULL)
RiDisplay("list23.tif", RI_FRAMEBUFFER, RI_RGB)
RiFormat(640,480, -1.0)
RiShadingRate(1.0)
RiLightSource("distantlight", RI_NULL)
RiProjection(RI_PERSPECTIVE)
RiWorldBegin()
RiTranslate(0.0, 0.0, 1.5)
RiRotate(40.0, -1.0, 1.0, 0.0)
RiSurface("matte",RI_NULL)
RiColor(color)
UnitCube()
#RiPolygon(P=square)
RiWorldEnd()
RiEnd()
  • -
  • -

PythonからRenderManを使う その2

Pixar RenderManのPython APIとcgkitでの記述を並べてみた。
import prmanでは、パラメータを辞書形式で記述。後はほとんど同じ感じてす。
以下は、ティーポットの表示
■import prman
#test2.py
# set PYTHONPATH=C:\Python25;C:\Python\Scripts;%RMANTREE%\bin
import prman
ri=prman.Ri()
rendertarget="test2.rib"
ri.Begin(ri.RENDER)
ri.Imager("background", {"color color":(.2,.4,.6)})
ri.Display("teapot2.png", "file", "rgb")
ri.Format(640,480,1)
ri.Projection(ri.PERSPECTIVE, {ri.FOV: 45})
ri.Translate(0,0,10)
ri.WorldBegin()
ri.LightSource("pointlight", {ri.HANDLEID: "1", "from": [-10,10,-10],"intensity":[300]})
ri.LightSource("pointlight", {ri.HANDLEID: "2", "from": [10,10,-10],"intensity":[300]})
ri.LightSource("pointlight", {ri.HANDLEID: "3", "from": [-10,-10,-10],"intensity":[300]})
ri.Color((0.9,0,0.1))
ri.Surface("plastic")
ri.Translate(0,-1,0)
ri.Rotate(-90,1,0,0)
ri.Geometry("teapot")
ri.WorldEnd()
ri.End()


teapot2.jpg

■cgkit
3Delightを利用した。
#min2.py
import cgkit.cri

ri = cgkit.cri.loadRI("3Delight")
cgkit.cri.importRINames(ri, globals())

RiBegin(RI_NULL)
RiImager("background", "color background",(.2,.4,.6))
RiDisplay("min2.png", RI_FILE, RI_RGB)
RiProjection(RI_PERSPECTIVE,RI_FOV,45)
RiTranslate(0,0,10)
RiWorldBegin()
#RiLightSource("ambientlight","intensity",0.4)
#RiLightSource("distantlight")
RiLightSource("pointlight", RI_HANDLEID, "1", "from",[-10,10,-10],"intensity",[300])
RiLightSource("pointlight", RI_HANDLEID, "2", "from",[10,10,-10],"intensity",[300])
RiLightSource("pointlight", RI_HANDLEID, "3", "from",[-10,-10,-10],"intensity",[300])
RiSurface("plastic")
RiColor((1,0.2,0.2))
RiTranslate(0,-1,0)
RiRotate(-90,1,0,0)
RiReadArchive("teapot.rib")
RiWorldEnd()
RiEnd()



min2.jpg
  • -
  • -

「実践CGへの誘い」例題をPythonで行う その4

「実践CGへの誘い」p.28
Listing 2.5
TransformBegin()〜TransformEnd()を使ったサンプル
ありがたいです。

#list25.py
#/* Copyrighted Pixar 1989 */
#/* From the RenderMan Companion p. 28 */
#/* Listing 2.5 Another cube definition */

import cgkit.cri
from cgkit.cgtypes import *

# Load the RenderMan API.
# Replace the library name with whatever renderer you want to use.
ri = cgkit.cri.loadRI("3delight")
cgkit.cri.importRINames(ri, globals())

#/* UnitCube(): Enter a unit cube into the scene */

def UnitCube():
square = [ [.5,.5,.5], [-.5,.5,.5], [-.5,-.5,.5], [.5,-.5,.5] ]
RiTransformBegin()
#/* far square */
RiPolygon( RI_P, square, RI_NULL)
#/* right face */
RiRotate(90.0, 0.0, 1.0, 0.0)
RiPolygon( RI_P, square, RI_NULL)
#/* near face */
RiRotate(90.0, 0.0, 1.0, 0.0)
RiPolygon( RI_P, square, RI_NULL)
#/* left face */
RiRotate(90.0, 0.0, 1.0, 0.0)
RiPolygon( RI_P, square, RI_NULL)
RiTransformEnd()

RiTransformBegin()
#/* bottom face */
RiRotate(90.0, 1.0, 0.0, 0.0)
RiPolygon( RI_P, square, RI_NULL)
RiTransformEnd()

RiTransformBegin()
#/* top face */
RiRotate(-90.0, 1.0, 0.0, 0.0)
RiPolygon( RI_P, square, RI_NULL)
RiTransformEnd()

color=(.9,.1,.2)

RiBegin(RI_NULL)
RiDisplay("list25.tif", RI_FRAMEBUFFER, RI_RGB)
RiFormat(640,480, -1.0)
RiShadingRate(1.0)
RiLightSource("distantlight", RI_NULL)
RiProjection(RI_PERSPECTIVE)
RiWorldBegin()
RiTranslate(0.0, 0.0, 1.5)
RiRotate(40.0, -1.0, 1.0, 0.0)
RiSurface("matte",RI_NULL)
RiColor(color)
UnitCube()
RiWorldEnd()
RiEnd()

  • -
  • -
<< 2/14 >>