Rendering学習日記

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

RiCurves その3

Essential RenderManのサンプルを参照して、Python cgkitで試してみました。RiCurvesの表記の仕方がわからなくて、最初エラーが出てしまいました。
RiCurves("linear",COUNT,"nonperiodic","P",points,"constantwidth",curveWidth
RI_NULL)
・・・
TypeError: 'int' object is not iterable

原因はCOUNTはいらないということでしょうか。スクリプト書き直したら、できました。ありがとうございます。
curves2.jpg
#/* curves2.py - create a set of curves */
import random, math
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())

COUNT = 1000

def jitter(scale):
val=random.random()*1000
return (val/500-1)*scale

points=[]
pappend=points.append
nverts=[]
red=(1,0,0)
curveWidth=0.3
fov=30

#/*Generate Curve Postions*/
for i in range(COUNT):
tx=(math.sin(i*0.3)*i*50)/COUNT+jitter(5)
ty=(math.cos(i*0.3)*i*50)/COUNT+jitter(5)

pappend(0)
pappend(0)
pappend(50)

pappend(0.1*tx)
pappend(0.1*ty)
pappend(25)

pappend(0.4*tx)
pappend(0.4*ty)
pappend(0)

pappend(tx)
pappend(ty)
pappend(-25)

nverts.append(4)


RiBegin(RI_NULL)
RiDisplay ("curves2.tiff","framebuffer","rgb",RI_NULL)
RiProjection ("perspective","fov",fov,RI_NULL)
RiWorldBegin()
RiTranslate(0,0,200)
RiColor(red)
RiRotate(45,1,0,0)

RiCurves("linear",nverts,"nonperiodic","P",points,"constantwidth",curveWidth,RI_NULL)

RiWorldEnd()
RiEnd()
  • -
  • -

RiCurves その4

cubicに書き換えてみました。
RiCurves("cubic",nverts,"nonperiodic","P",points,"constantwidth",curveWidth,RI_NULL)
勉強ですね。ありがとうございます。
curves2_cubic.jpg
  • -
  • -

PythonからRenderMan その3

イギリスのbournemouth universityを参考にしました。ありがとうございます。Thank you.
RenderManProServer-14からついているimport prmanを利用してます。
cubeを作成しました。
cube_pr.jpg
#cube_pr.py
#set PYTHONPATH=C:\Python25;C:\Python\Scripts;%RMANTREE%\bin
import getpass
import time
# import the python renderman library
import prman

def Cube(width,height,depth) :
w=width/2.0
h=height/2.0
d=depth/2.0
ri.ArchiveRecord(ri.COMMENT, 'Cube Generated by Cube Function')
#rear
face=[-w,-h,d,-w,h,d,w,-h,d,w,h,d]
ri.Patch("bilinear",{'P':face})
#front
face=[-w,-h,-d,-w,h,-d,w,-h,-d,w,h,-d]
ri.Patch("bilinear",{'P':face})
#left
face=[-w,-h,-d,-w,h,-d,-w,-h,d,-w,h,d]
ri.Patch("bilinear",{'P':face})
#right
face=[w,-h,-d,w,h,-d,w,-h,d,w,h,d]
ri.Patch("bilinear",{'P':face})
#bottom
face=[w,-h,d,w,-h,-d,-w,-h,d,-w,-h,-d]
ri.Patch("bilinear",{'P':face})
#top
face=[w,h,d,w,h,-d,-w,h,d,-w,h,-d]
ri.Patch("bilinear",{'P':face})
ri.ArchiveRecord(ri.COMMENT, '--End of Cube Function--')


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

filename = "Cube.rib"
# this is the begining of the rib archive generation we can only
# make RI calls after this function else we get a core dump
ri.Begin("__render") #filename)
# 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("cube_pr.png", "file", "rgb")
ri.Format(512, 384, -1.0)
ri.PixelSamples( 4, 4)
ri.ShadingRate(1)
# now set the projection to perspective
ri.Projection(ri.PERSPECTIVE,{ri.FOV:50})

# now we 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.Surface("plastic")
ri.Translate(0,0,5)

ri.TransformBegin()
ri.Translate(-2,0,0)
ri.Rotate(25,0,1,0)
ri.Color([0,0,1])
Cube(1,1,1)
ri.TransformEnd()

ri.TransformBegin()
ri.Translate( 0,0,0)
ri.Rotate( 25,1,1,0)
ri.Color([1,0,0])
Cube(1,1,1)
ri.TransformEnd()

ri.TransformBegin()
ri.Translate(2,0,0)
ri.Rotate(-25,1,1,1)
ri.Color([0,1,0])
Cube(0.2,2,0.2);
ri.TransformEnd()

ri.WorldEnd()
ri.End()
  • -
  • -
<< 9/14 >>