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

Lightflowブーリアン演算その2

ブーリアン演算を使って、お互いの物体の重なっている部分を表示するには、"intersection"を使う。Lightflowの設定では3つの物体でもまとめて計算できるようだ。便利かも。
csg1 = s.newObject( "solid",
[ "type", "intersection",
"solids", box1, hole ] )
bool04in.jpg
以下はサンプルファイル参考にしてみてください。


#! /usr/bin/env python
from lightflowPM import *
from math import *

s = scene()

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

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

s.lightOn( s.newLight( "point", [ "position", vector3( 3.0, 3.0, 3.0 ), "color", vector3( 300.0, 300.0, 300.0 ) ] ) )

plastic = s.newMaterial( "standard", [ "kc", vector3( 0.096, 0.252, 0.504 ), "kd", 0.5, "km", 0.1 ] )

#cylinder
s.materialBegin( plastic )
s.transformBegin( transform().rotationAroundX( pi*5.0/180 ) )
s.transformBegin( transform().translation( vector3( 0, 0, 2.4 ) ) )
cap1=s.newObject( "disc", [ "radius", 1.0 ] )
s.transformEnd()

s.transformBegin( transform().translation( vector3( 0, 0, 0 ) ) )
cap2=s.newObject( "disc", [ "radius", 1.0 ] )
s.transformEnd()

cyl=s.newObject( "cylinder", [ "radius", 1.0 ,"height",2.4] )
s.transformEnd()
s.materialEnd()

#cylinder with double caps
hole = s.newObject( "boundary", [ "surfaces", cyl, cap1, cap2 ] )



plastic2 = s.newMaterial( "standard", [ "kc", vector3(0.556863,0.137255,0.137255), "kd", 0.5, "km", 0.1 ] )

#box1
s.materialBegin( plastic2 )
s.transformBegin( transform().translation( vector3( 0, 0, 1.2 ) ) )
s.transformBegin( transform().rotationAroundY( pi*45.0/180 ) )
box1=s.newObject( "box", [ "position",vector3( -1.0, -1.0, -1.0 ),vector3( 1.0, 1.0, 1.0 )] )
s.transformEnd()
s.transformEnd()
s.materialEnd()


csg1 = s.newObject( "solid",
[ "type", "intersection",
"solids", box1, hole ] )

s.addObject(csg1)


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

s.imagerBegin( saver )

camera = s.newCamera( "pinhole", [ "eye", vector3( -1.5, -4, 3 ),
"aim", vector3( 0, 0, 1 ),
"aa-samples", 2,5
] )

s.imagerEnd()

s.render( camera, 400, 400 )
  • -
  • -

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