<< Lightflowブーリアン演算その2 戻る Lightflowで立方体生成関数をつくる その2 >>

Lightflowで立方体生成関数をつくる その1

plasticマテリアルを以下のようにリスト化した
col=[plastic,plastic2,plastic3,plastic4,plastic5,plastic6]
これで、col[0]からcol[5]まで6つのマテリアルが呼び出せる。

Pythonで関数は、def hoge:で書いていく。
Lightflow内のboxの位置とリスト化したマテリアルを引数として渡して、立方体を生成するように以下のように定義した。

#関数定義 ボックスの位置とリストcolのインデックス番号0から5まで
def boxpos(x0,y0,z0,c):
s.materialBegin( col[c] )
s.transformBegin( transform().translation( vector3(x0,y0,z0)))
s.addObject( s.newObject( "box", [ "position",vector3( -1.0, -1.0, -1.0 ),vector3( 1.0, 1.0, 1.0 )] ) )
s.transformEnd()
s.materialEnd()


よって、一行
boxpos(0,0,0,0)
boxpos(-3.0,0,0,1)
boxpos(-3,-3,0,3)
boxpos(0,-3,0,4)
のように記述してあげると良い。
box_def.jpg

以下はサンプルファイルである。

#! /usr/bin/env python
#box_def.py

from lightflowPM import *
from math import *
import colorinc

s = scene()

s.lightOn( s.newLight( "point", [ "position", vector3( 5.0, -5.0, 4.0 ), "color", vector3( 300.0, 300.0, 300.0 ) ] ) )

s.lightOn( s.newLight( "ambient", [ "color", vector3( 0.3, 0.3, 0.3 ) ] ) ) #環境光を加える。

plastic = s.newMaterial( "standard",[ "kc", colorinc.Brown,"kd",0.66 ] ) #

plastic2 = s.newMaterial( "standard",[ "kc", colorinc.CadetBlue,"kd",0.66 ] ) #

plastic3 = s.newMaterial( "standard",[ "kc", colorinc.Coral,"kd",0.66 ] ) #

plastic4 = s.newMaterial( "standard",[ "kc", colorinc.VLightGray,"kd",0.66 ] ) #

plastic5 = s.newMaterial( "standard",[ "kc", colorinc.Aquamarine,"kd",0.66 ] ) #

plastic6 = s.newMaterial( "standard",[ "kc", colorinc.BlueViolet,"kd",0.66 ] ) #

#plasticをリスト化した
col=[plastic,plastic2,plastic3,plastic4,plastic5,plastic6]

check_ground=s.newPattern("check",["color",vector3( 0.2, 0.4, 0.6 ),"scale",0.025])

ground=s.newMaterial( "standard",[ "kc", check_ground,"kc",vector3( 1.0, 1.0, 1.0 ),"ka",check_ground ] ) #チェック青と白

#関数定義 ボックスの位置とリストcolのインデックス番号0から5まで
def boxpos(x0,y0,z0,c):
s.materialBegin( col[c] )
s.transformBegin( transform().translation( vector3(x0,y0,z0)))
s.addObject( s.newObject( "box", [ "position",vector3( -1.0, -1.0, -1.0 ),vector3( 1.0, 1.0, 1.0 )] ) )
s.transformEnd()
s.materialEnd()



#Brown box
boxpos(0,0,0,0)

#CadetBlue box
boxpos(-3.0,0,0,1)

#Coral box z軸中心に45度回転
s.materialBegin( col[2] )
s.transformBegin( transform().translation( vector3(3.0,0,0)))
s.transformBegin( transform().rotationAroundZ( pi*45.0/180 ))

s.addObject( s.newObject( "box", [ "position",vector3( -1.0, -1.0, -1.0 ),vector3( 1.0, 1.0, 1.0 )] ) )

s.transformEnd()
s.transformEnd()
s.materialEnd()


#VLightGray box
boxpos(-3,-3,0,3)


#Aquamarine box
boxpos(0,-3,0,4)


#BlueViolet box
boxpos(3,-3,0,5)


#check模様の地面groundをpatchで作成しています。高さ(z軸)を-1.0にしてぴったり立方体とあわせています。
s.materialBegin( ground )
s.addObject( s.newObject( "patch", [ "points",vector3( -50, -50, -1.0 ),vector3( -50, 50, -1.0 ),vector3( 50, -50, -1.0 ),vector3( 50, 50, -1.0 )] ) )
s.materialEnd()


saver = s.newImager( "tga-saver", [ "file", "box_def.tga" ] )

s.imagerBegin( saver )
camera = s.newCamera( "pinhole", [ "eye", vector3( 0, -10, 5 ), "aim", vector3( 0, 0, 0 ) ] )
s.imagerEnd()

s.render( camera, 512, 300 )
  • -
  • -

<< Lightflowブーリアン演算その2 戻る Lightflowで立方体生成関数をつくる その2 >>