<< 「実践CGへの誘い」例題をPythonで行う その6 戻る 「実践CGへの誘い」例題をPythonで行う その8 >>

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

できました。よく読まないといけません。
UnitCube()を最初に使った定義のものに戻しています。

「実践CGへの誘い」p.32
Listing 2.7

オブジェクトインスタンスを利用したサンプルです。
ありがとうございます。


#list27.py
#/* Copyrighted Pixar 1989 */
#/* From the RenderMan Companion p. 32 */
#/* Listing 27c A more efficient color cube */
#/*
# * ColorCube(): create a unit color cube from smaller cubes
# * Parameters:
# * n: the number of minicubes on a side
# * s: a scale factor for each minicube
# */

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])

def ColorCube(n, s):
if n<=0:
return

cube = RiObjectBegin()
UnitCube()
RiObjectEnd()

RiAttributeBegin()
RiTranslate(-.5, -.5, -.5 )
RiScale(1.0/n, 1.0/n, 1.0/n)
color=[0,0,0]
for x in range(n):
for y in range(n):
for z in range(n):
color[0] = (x+1)/float(n)
color[1] = (y+1)/float(n)
color[2] = (z+1)/float(n)
RiColor(color)
RiTransformBegin()
RiTranslate (x+.5, y+.5, z+.5)
RiScale(s, s, s)
RiObjectInstance(cube)
RiTransformEnd()

RiAttributeEnd()


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

RiBegin(RI_NULL); #/* Start the renderer */
RiDisplay("colormain2.tiff", RI_FILE, "rgb", RI_NULL)
RiFormat(512, 384, -1.0)
RiShadingRate(1.0)
RiLightSource("distantlight", RI_NULL)
RiProjection(RI_PERSPECTIVE,RI_FOV,65)
RiWorldBegin()
RiSides(1) # /* N E W */
RiTranslate(0.0, 0.0, 1.5)
RiRotate(30.0, -1.0, 0.0, 0.0)
RiRotate(30.0, 0.0, -1.0, 0.0)
RiColor(color) # /* Declare the color */
ColorCube(4, .8) #/* Define the cube */
RiWorldEnd()
RiEnd() #/* Clean up after the renderer */


  • -
  • -

<< 「実践CGへの誘い」例題をPythonで行う その6 戻る 「実践CGへの誘い」例題をPythonで行う その8 >>