初步了解Panda3D音频和高级交互组件

Posted bcbobo21cn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了初步了解Panda3D音频和高级交互组件相关的知识,希望对你有一定的参考价值。

运行panda3d Tut-Music-Box.py示例;

如下图,点击按钮有一个打开关闭盒子的效果,还会播放不同音乐;

Panda将音频系统分为两类:声音效果,音乐;

Panda提供三种音频库:openAL,FMOD,Miles;

self.musicBoxSound = base.loadMusic('music/musicbox.mp3'),载入音频文件;

self.lidSfx = base.loadSfx('music/openclose.mp3'),载入音效;

用pview查看一下模型,如下图;

 

单独把界面部分的代码看一下;

import direct.directbase.DirectStart
from panda3d.core import NodePath,TextNode
from panda3d.core import Vec3,Vec4
from direct.gui.OnscreenText import OnscreenText
from direct.showbase.DirectObject import DirectObject
from direct.interval.SoundInterval import SoundInterval
from direct.gui.DirectSlider import DirectSlider
from direct.gui.DirectButton import DirectButton
from direct.interval.MetaInterval import Sequence,Parallel
from direct.interval.LerpInterval import LerpFunc
import sys

class World(DirectObject):
  def __init__(self):

    self.slider = DirectSlider(pos = Vec3(0,0,.7), value = .50,
                    command = None)

    self.button = DirectButton(pos = Vec3(.7,0,.7), text = "Open Box",
                   scale = .1, pad = (.5, .5),
                   rolloverSound = None, clickSound = None,
                   command = None)

w = World()
run()

运行如下;按钮和滑动条是用DirectXXX类做的;这是系统提供的高级交互组件的一部分; 

 

单独看一下模型相关的代码,

import direct.directbase.DirectStart
from panda3d.core import NodePath,TextNode
from panda3d.core import Vec3,Vec4
from direct.gui.OnscreenText import OnscreenText
from direct.showbase.DirectObject import DirectObject
from direct.interval.SoundInterval import SoundInterval
from direct.gui.DirectSlider import DirectSlider
from direct.gui.DirectButton import DirectButton
from direct.interval.MetaInterval import Sequence,Parallel
from direct.interval.LerpInterval import LerpFunc
import sys

class World(DirectObject):
  def __init__(self):

    self.musicBox=loader.loadModel('models/MusicBox')
    self.musicBox.setPos(0, 60, -10)
    self.musicBox.reparentTo(render)

    #Finding pieces of the model
    self.Lid   = self.musicBox.find('**/lid')
    self.Panda = self.musicBox.find('**/turningthing')  

    self.HingeNode = self.musicBox.find('**/box').attachNewNode('nHingeNode')
    self.HingeNode.setPos(.8659,6.5,5.4)
    #WRT - ie with respect to. Reparents the object without changing
    #its position, size, or orientation
    self.Lid.wrtReparentTo(self.HingeNode)
    self.HingeNode.setHpr(0,90,0)

w = World()
run()

运行如下,只看到一个盒子; 

 

     从代码来看;就是加载模型,然后找模型的不同部分,设置为这几个节点,self.Lid,self.Panda,self.HingeNode ;

    还不知道盒子打开关闭的效果是如何做的,下回继续;

以上是关于初步了解Panda3D音频和高级交互组件的主要内容,如果未能解决你的问题,请参考以下文章

初步了解panda3d阴影效果的实现

初步了解panda3d灯光

初步了解Panda3D场景管理

初步了解Panda3d粒子系统

初步了解Panda3d粒子系统

初步了解Panda3D 雾(Fog)