|
2 | 2 |
|
3 | 3 | __all__ = ['Audio3DManager'] |
4 | 4 |
|
5 | | -from panda3d.core import Vec3, VBase3, WeakNodePath |
| 5 | +from panda3d.core import Vec3, VBase3, WeakNodePath, ClockObject |
6 | 6 | from direct.task.TaskManagerGlobal import Task, taskMgr |
7 | 7 | # |
8 | 8 | class Audio3DManager: |
@@ -141,14 +141,22 @@ def getSoundVelocity(self, sound): |
141 | 141 | """ |
142 | 142 | Get the velocity of the sound. |
143 | 143 | """ |
144 | | - if (sound in self.vel_dict): |
| 144 | + if sound in self.vel_dict: |
145 | 145 | vel = self.vel_dict[sound] |
146 | | - if (vel!=None): |
| 146 | + if vel is not None: |
147 | 147 | return vel |
148 | | - else: |
149 | | - for known_object in list(self.sound_dict.keys()): |
150 | | - if self.sound_dict[known_object].count(sound): |
151 | | - return known_object.getPosDelta(self.root)/globalClock.getDt() |
| 148 | + |
| 149 | + for known_object in list(self.sound_dict.keys()): |
| 150 | + if self.sound_dict[known_object].count(sound): |
| 151 | + node_path = known_object.getNodePath() |
| 152 | + if not node_path: |
| 153 | + # The node has been deleted. |
| 154 | + del self.sound_dict[known_object] |
| 155 | + continue |
| 156 | + |
| 157 | + clock = ClockObject.getGlobalClock() |
| 158 | + return node_path.getPosDelta(self.root) / clock.getDt() |
| 159 | + |
152 | 160 | return VBase3(0, 0, 0) |
153 | 161 |
|
154 | 162 | def setListenerVelocity(self, velocity): |
@@ -176,10 +184,11 @@ def getListenerVelocity(self): |
176 | 184 | """ |
177 | 185 | Get the velocity of the listener. |
178 | 186 | """ |
179 | | - if (self.listener_vel!=None): |
| 187 | + if self.listener_vel is not None: |
180 | 188 | return self.listener_vel |
181 | | - elif (self.listener_target!=None): |
182 | | - return self.listener_target.getPosDelta(self.root)/globalClock.getDt() |
| 189 | + elif self.listener_target is not None: |
| 190 | + clock = ClockObject.getGlobalClock() |
| 191 | + return self.listener_target.getPosDelta(self.root) / clock.getDt() |
183 | 192 | else: |
184 | 193 | return VBase3(0, 0, 0) |
185 | 194 |
|
|
0 commit comments