<< はじめてのFujiyama Renderer その7 戻る はじめてのFujiyama Renderer その9 >>

はじめてのFujiyama Renderer その8 視野変換

とりあえず、カメラ位置と注視点位置から視野変換するPythonスクリプトをRenderMan資料placecam.cを参考に求めてみました。ありがとうございます。
まちがっているところもあるかもしれませんが、それっぽくカメラ位置が求められています。
Fujiyama Rendere0.1.1では、変換の順序は、プロパティを設定する順序に
影響しません。記述の順番は関係しません。
順序を設定するためのプロパティは'transform_order'、
'rotate_order'になり、デフォルトではそれぞれ、ORDER_SRTと
ORDER_XYZになっています。
変換はスケール、回転、移動の順に行われています。
回転はx,y,z軸回転の順に行われています。

以下のfujicam.py、Pythonスクリプトを実行し、出力された変換をコピペでシーンに張り付けてください。なおroll、coneangleは未対応です。

#!/usr/bin/env python
#fujicam.py
import sys
import os
from math import *

PI=3.1415926535897932


def usage():
print "usage: placecam pos_x pos_y pos_z aim_x aim_y aim_z"
print " [coneangle] [roll_angle]"
print " Calculate Fujiyama Renderer transforms needed for camera transform"
print " from light position to aim point with the given roll angle."
sys.exit(1)



def RiRotate(xangle, yangle, zangle):
if (fabs(xangle) > 0.001 or fabs(yangle) > 0.001 or fabs(zangle) > 0.001):
print "rotate %0.2f %0.2f %0.2f" % (xangle, yangle, zangle)



def RiTranslate(dx, dy, dz):
print "translate %0.2f %0.2f %0.2f" % (dx, dy, dz)


"""
/*
* AimZ(): rotate the world so the direction vector points in
* positive z by rotating about the y axis, then x. The cosine
* of each rotation is given by components of the normalized
* direction vector. Before the y rotation the direction vector
* might be in negative z, but not afterward.
*/
"""

def AimZ(direction):
global PI
if (direction[0]==0 and direction[1]==0 and direction[2]==0):
return
#/*
# * The initial rotation about the y axis is given by the projection of
# * the direction vector onto the x,z plane: the x and z components
# * of the direction.
# */
xzlen = sqrt(direction[0]*direction[0]+direction[2]*direction[2])
if (xzlen == 0):
if (direction[1] < 0):
yrot = 180
else:
yrot=0

else:
yrot = 180-180*acos(direction[2]/xzlen)/PI

# /*
# * The second rotation, about the x axis, is given by the projection on
# * the y,z plane of the y-rotated direction vector: the original y
# * component, and the rotated x,z vector from above.
# */
yzlen = sqrt(direction[1]*direction[1]+xzlen*xzlen)
xrot = 180*acos(xzlen/yzlen)/PI; #/* yzlen should never be 0 */

if (direction[1] > 0):
RiRotate(xrot, 0.0, 0.0)
else:
RiRotate(-xrot, 0.0, 0.0)

# /* The last rotation declared gets performed first */
if (direction[0] > 0):
RiRotate( 0.0, -yrot, 0.0)
else:
RiRotate( 0.0, yrot, 0.0)



def PlaceCamera(position, direction, roll):
RiRotate(0.0, 0.0, -roll)
AimZ(direction)
RiTranslate(position[0], position[1], position[2])


def main():
global PI
if len(sys.argv) < 7:
usage()
pos=[0,0,0]
aim=[0,0,0]
dir=[0,0,0]

pos[0] = float(sys.argv[1])
pos[1] = float(sys.argv[2])
pos[2] = float(sys.argv[3])
aim[0] = float(sys.argv[4])
aim[1] = float(sys.argv[5])
aim[2] = float(sys.argv[6])

if len(sys.argv) > 7:
coneangle = float(sys.argv[7])
else:
coneangle = 0.0

if len(sys.argv) > 8:
roll = float(sys.argv[8])
else:
roll = 0.0

print "position: %0.2f, %0.2f, %0.2f"% (pos[0], pos[1], pos[2])
print "aim: %0.2f, %0.2f, %0.2f"% (aim[0], aim[1], aim[2])
print "coneangle: %0.4f"% coneangle
print "roll: %0.2f\n" % roll

if (coneangle != 0.0):
fov = coneangle * 360.0 / PI
print "Projection \"perspective\" \"fov\" [%0.2f]" % fov


dir[0] = aim[0] - pos[0]
dir[1] = aim[1] - pos[1]
dir[2] = aim[2] - pos[2]

PlaceCamera(pos, dir, roll)


if __name__ == "__main__":
main()


いろいろと試したくなります。ありがとうございます。

2013/8/24 : coneangle箇所修正
  • -
  • -

<< はじめてのFujiyama Renderer その7 戻る はじめてのFujiyama Renderer その9 >>