Rendering学習日記

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

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

「実践CGへの誘い」p.61
Listing 4.1

基本プリミティブの表示をします。いろいろと工夫できますね。
#list41.py
#/* Copyrighted Pixar 1989 */
#/* From the RenderMan Companion p. 61 */
#/* Listing 4.1 Routine generating quadric surfaces shown in Figure 4.1 */
#/*

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

def Go():
ShowQuads()

OFFSET = 1.2

def ShowQuads():
RiRotate(-90.0, 1.0, 0.0, 0.0)

RiTranslate(-OFFSET, 0.0, (OFFSET/2))
RiSphere(0.5, -0.5, 0.5, 360.0, RI_NULL) #/* Declare a sphere */

RiTranslate(OFFSET, 0.0, 0.0)
RiTranslate(0.0, 0.0, -0.5)
RiCone(1.0, 0.5, 360.0, RI_NULL) #/* Declare a cone */

RiTranslate(0.0, 0.0, 0.5)
RiTranslate(OFFSET, 0.0, 0.0)
RiCylinder(0.5, -0.5, 0.5, 360.0, RI_NULL) #/* Declare cylinder */

RiTranslate(-(OFFSET*2), 0.0, -OFFSET)
hyperpt1 =[ 0.4, -0.4, -0.4]
hyperpt2 =[ 0.4, 0.4, 0.4]

#/* Declare hyperboloid */
RiHyperboloid(hyperpt1, hyperpt2, 360.0, RI_NULL)

RiTranslate(OFFSET, 0.0, -0.5)
RiParaboloid(0.5, 0.0, 0.9, 360.0, RI_NULL) #/* Declare paraboloid */

RiTranslate(OFFSET, 0.0, 0.5)
RiTorus(.4, .15, 0.0, 360.0, 360.0, RI_NULL) #/* Declare torus */


RiBegin (RI_NULL) #/* Start Renderer */
RiDisplay("quadsmain.tiff", RI_FILE, "rgb", RI_NULL)
RiFormat( 512, 372, -1.0)
RiProjection (RI_PERSPECTIVE,RI_FOV,45)
RiTranslate (0.0, 0.0, 3.5)
RiWorldBegin ()
RiLightSource ("distantlight", RI_NULL)
RiAttributeBegin()

RiSurface ("plastic", Kd=1.0)
RiColor((0.97,0.64,0.39))
Go()
RiAttributeEnd()
RiWorldEnd()
RiEnd()



quadsmain.jpg
  • -
  • -

「実践CGへの誘い」例題をPythonで・・その10

list42.jpg
「実践CGへの誘い」p.65
Listing 4.2

#list42.py
#/* Copyrighted Pixar 1989 */
#/* From the RenderMan Companion p. 65 */
#/* Listing 4.2 Using hyperboloids to create a surface of revolution */

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

NPOINTS=16

points = [
[1.5000,.0000],
[1.4600,.0900],
[1.3500,.1273],
[1.2625,.1203],
[1.1750,.1047],
[1.0875,.0935],
[1.0000,.0899],
[0.9375,.0982],
[0.8625,.1236],
[0.7250,.1851],
[0.5875,.2281],
[0.4500,.2383],
[0.3375,.2255],
[0.2250,.1953],
[0.0750,.1414],
[0.0000,.1125]
]

color = (1,0.26,0.15)

def Go():
global color
RiColor(color)
RiSurface ("plastic", Kd=1.0)
RiRotate(-90.0, 1.0, 0.0, 0.0)
SurfOR(points, NPOINTS)


#/* Listing 4.2 Using hyperboloids to create a surface of revolution */

def SurfOR(points, npoints):
#/*
# * For each adjacent pair of x,y points in the outline description,
# * draw a hyperboloid by sweeping the line segment defined by
# * those points about the z axis.
# */
pp1 =[ points[0][1], 0, points[0][0]]
for pt in range(1, npoints):
pp2 =[ points[pt][1], 0, points[pt][0]]
RiHyperboloid(pp1, pp2, 360.0, RI_NULL)
tmp = pp1
pp1 = pp2
pp2 = tmp


RiBegin (RI_NULL) #/* Start Renderer */
RiDisplay("list42.tif", RI_FILE, "rgb", RI_NULL)
RiFormat( 512, 372, -1.0)
RiProjection (RI_PERSPECTIVE,RI_FOV,45)
RiTranslate (0.0, -0.75, 2.2)
RiWorldBegin ()
RiLightSource ("distantlight", RI_NULL)
RiAttributeBegin()

Go()
RiAttributeEnd()
RiWorldEnd()
RiEnd()

  • -
  • -

「実践CGへの誘い」例題をPythonで・・その11

「実践CGへの誘い」p.67
Listing 4.3
wavemain.jpg
#list43.py
#/* Copyrighted Pixar 1989 */
#/* From the RenderMan Companion p. 67 */
#/* Listing 4.3 Using RiTorus to create a wavelike pattern */

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

def TorusWave(nwaves, thetamax):
if nwaves < 1:
print "Need a positive number of waves\n"

#/* Divide the net radius 1.0 among the waves and the hemisphere */
innerrad = 2 / (8.0*nwaves + 2)
RiRotate(90.0, 1.0, 0.0, 0.0)
#/* Create the downward-opening hemisphere */
RiSphere(innerrad, -innerrad, 0.0, thetamax, RI_NULL)

outerrad = 0
for wave in range(1,nwaves+1):
#* Each iteration creates a downward-opening half-torus
#* and a larger upward-opening half-torus.
outerrad = outerrad + (innerrad * 2)
RiTorus(outerrad, innerrad, 0.0, 180.0, thetamax, RI_NULL)
outerrad = outerrad + (innerrad * 2)
RiTorus(outerrad, innerrad, 180.0, 360.0, thetamax, RI_NULL)

def Go():
TorusWave(4, 250.0)


RiBegin (RI_NULL) #/* Start Renderer */
RiDisplay("wavemain.tif", RI_FILE, "rgb", RI_NULL)
RiFormat( 512, 372, -1.0)
RiProjection ("perspective", RI_NULL)

RiWorldBegin ()
RiLightSource("ambientlight","intensity",0.4)
RiLightSource ("distantlight", RI_NULL)
RiAttributeBegin()
RiTranslate (-0.1, 0.0, 1.1)
RiRotate (50.0, -1.0, 1.0, 0.0)
RiColor((0.42,0.97,0.45))
RiSurface ("plastic", Kd=1.0)
Go()
RiAttributeEnd()
RiWorldEnd()
RiEnd()


wavemain2.jpg
RiProjection ("perspective", "fov", 45)
と書き換えてみた。
  • -
  • -
<< 12/22 >>