Home >> Python >> Panda3D GUI Components


■モデルのGUIコンポーネント

☆ボタン

from direct.showbase.ShowBase import ShowBase
from direct.showbase.Loader import Loader
from direct.gui.DirectGui import *
from panda3d.core import *

# ショーベースとモデルの設定
base = ShowBase( )
loader = Loader( base )
model = loader.loadModel( "cube.dae" )
model.reparentTo( render )
model.setPos( 0, 5, 0 )  #y: depth # z: upper
model.setR( rotation )

# 平行光源の設定
dlight = DirectionalLight('dlight')
dlight.setColor(VBase4(0.8, 0.8, 1.0, 1))
dlight.setDirection(Vec3( -1, 1, -1 ) )
dlnp = render.attachNewNode(dlight)
dlnp.setPos(0, 5, 3)
render.setLight(dlnp)

# HPRの各方向に回転する関数とボタン(DirectButton)の設定
def setRotateR( ):
    global rotation
    model.setR( model.getR( ) + 10 )

b = DirectButton(text = ("Rotate R", "clicked", "Rot R", "disabled"), \
                 scale=0.1, command=setRotateR, pos=(-0.5, 0, 0.6) )

def setRotateH( ):
    global model
    model.setH( model.getH( ) + 10 )
    
c = DirectButton(text=("Rotate H", "clicked", "Rot H", "disabled"),\
                scale = 0.1, command=setRotateH, pos=(-0.5, 0, 0.4 ) )

def setRotateP( ):
    global model
    model.setP( model.getP( ) + 10 )

d =  DirectButton(text=("Rotate P", "clicked", "Rot P", "disabled"),\
                scale = 0.1, command=setRotateP, pos=(-0.5, 0, 0.2 ) )

base.run( )
		

Panda 3d Subview Python Python 3d Collision Detect