# Path: src/simulator/panda3d/panda_pedestrian.py
# class PandaPedestrian:
# 
# 
#     def __init__(self, actor, texture, taskMgr, joint):
#         self.taskMgr = taskMgr
#         self.actor = actor
#         self.texture = texture
#         self.joint = self.actor.exposeJoint(None, 'modelRoot', joint)
#         
#         self.animations = {}
#         self.actions = {}
#         self.command_queue = []
#         self.cur_action = 'stand'
#         
#         self.type = "male"
#         self.id = -1
#         self.pos = np.array([0,0,0])
#         self.loop = False
#         self.sequence = Parallel()
#         
#         self.live_controller = False
#         self.print_action = False
#         self.start_time = 0.0
# 
#     
#     def getActor(self):
#         return self.actor
#         
#       
#     def getTexture(self):
#         return self.texture
#         
#         
#     def setColor(self, color):
#         pass
#         
#         
#     def setId(self, id):
#         self.id = id
#         
#         
#     def getId(self):
#         return self.id
#     
#     
#     def setType(self, type):
#         self.type = type
#     
#     
#     def getType(self):
#         return self.type
# 
# 
#     def getBounds(self):
#         return self.actor.getTightBounds()
# 
# 
#     def addAnimation(self, name, path):
#         self.animations[name] = path
#         self.actor.loadAnims({name:path})
# 
# 
#     def addAction(self, name, angle, diff):
#         self.actions[name] = Action(name, angle, VBase3(*diff))
# 
# 
#     def addCommand(self, command):
#         if command in self.actions:
#             self.command_queue.append(command)
#         else:
#             print "Error: invalid command"
# 
# 
#     def addCommands(self, commands):
#         for command in commands:
#             self.addCommand(command)
# 
# 
#     def setStartTime(self, time):
#         self.start_time = time
# 
# 
#     def update(self, time):
#         if self.cur_action:
#             name = self.cur_action
#             anim_controller = self.actor.getAnimControl(name)
#             next_frame = anim_controller.getNextFrame()
#             cur_frame = anim_controller.getFullFframe()
#             num_frames = anim_controller.getNumFrames()
# 
#             if not self.sequence.isPlaying():
# #            if not anim_controller.isPlaying():
#                 if self.command_queue:
#                     next_action = self.command_queue.pop(0)
#                     self.startAction(next_action)
#                 else:
#                     if self.live_controller:
#                         if self.cur_action == 'run':
#                             next_action = 'run'
#                         elif self.cur_action == 'stand':
#                             next_action = 'stand'
#                         else:
#                             next_action = 'walk'
#                     
#                         self.startAction(next_action)
# 
#     
#     def isActive(self, time):
#         if time >= self.start_time and self.command_queue or \
#            time >= self.start_time and self.live_controller:
#             if self.actor.isHidden():
#                 self.actor.show()
#             return True
#         else:
#             if not self.actor.isHidden():
#                 self.actor.hide()
#             return False
# 
# 
#     def reposition(self, diff, rotation):
#         x,y,z = diff
#         self.actor.setX(x)
#         self.actor.setY(y)
#         self.actor.setH(self.actor.getH() + rotation)
# #        name = self.cur_action
# #        anim_controller = self.actor.getAnimControl(name)
# #        cur_frame = anim_controller.getFullFframe()
# #        print cur_frame
# 
# 
#     def liveController(self):
#             self.print_action = True
#             self.live_controller = True
# 
# 
#     def startAction(self, action):
#         cur_action = self.cur_action
#         rotation = self.actions[cur_action].rotation
#         self.cur_action = action
#         paction = self.actions[action]
#         if cur_action != "stand":
#             diff = self.joint.getPos(render) - paction.diff
#         else:
#             diff = self.actor.getPos()
#             
#         if self.print_action:
#             print paction.name,
#             
#         interval = self.actor.actorInterval(paction.name)
#         func = Func(self.reposition, diff, rotation)
#         self.sequence = Parallel(Sequence(Wait(0.001),func), interval)
#         self.sequence.start()


import os
import logging
import sys
from pandac.PandaModules import Spotlight
from direct.actor.Actor import Actor
from pandac.PandaModules import VBase3
from ..panda3d_helper import *
from ..panda_pedestrian import PandaPedestrian
        self.pedestrian_count = 0
        self.characters = {}


    def buildPedestrian(self, character_name, texture, scale, hpr, pos):
        """Builds a Panda3D actor by using the specified model and texture"""
        if not character_name in self.characters:
            return
        character = self.characters[character_name]
        model_path = os.path.normpath("%s/%s" 
                                      % (self.config_path, character['model']))
        if not os.path.exists(model_path):
            logging.error("The path '%s' does not exist" % model_path)
            sys.exit()
        
        actor = Actor(model_path)
        tex_dir = character['texture_dir']
        tex_path = os.path.normpath("%s/%s/%s" 
                                    %(self.config_path, tex_dir, texture))
        if not os.path.exists(tex_path):
            logging.error("The path '%s' does not exist" % tex_path)
            sys.exit()
        tex = loader.loadTexture(tex_path)
        actor.setTexture(tex,1)
        actor.reparentTo(self.parent.render)
        actor.setScale(scale)
        actor.setHpr(VBase3(*hpr))
        actor.setPos(*ToPandaCoordinates(VBase3(*pos)))
        
        joint = character['joint']

# Path: src/simulator/panda3d/panda_pedestrian.py
# class PandaPedestrian:
# 
# 
#     def __init__(self, actor, texture, taskMgr, joint):
#         self.taskMgr = taskMgr
#         self.actor = actor
#         self.texture = texture
#         self.joint = self.actor.exposeJoint(None, 'modelRoot', joint)
#         
#         self.animations = {}
#         self.actions = {}
#         self.command_queue = []
#         self.cur_action = 'stand'
#         
#         self.type = "male"
#         self.id = -1
#         self.pos = np.array([0,0,0])
#         self.loop = False
#         self.sequence = Parallel()
#         
#         self.live_controller = False
#         self.print_action = False
#         self.start_time = 0.0
# 
#     
#     def getActor(self):
#         return self.actor
#         
#       
#     def getTexture(self):
#         return self.texture
#         
#         
#     def setColor(self, color):
#         pass
#         
#         
#     def setId(self, id):
#         self.id = id
#         
#         
#     def getId(self):
#         return self.id
#     
#     
#     def setType(self, type):
#         self.type = type
#     
#     
#     def getType(self):
#         return self.type
# 
# 
#     def getBounds(self):
#         return self.actor.getTightBounds()
# 
# 
#     def addAnimation(self, name, path):
#         self.animations[name] = path
#         self.actor.loadAnims({name:path})
# 
# 
#     def addAction(self, name, angle, diff):
#         self.actions[name] = Action(name, angle, VBase3(*diff))
# 
# 
#     def addCommand(self, command):
#         if command in self.actions:
#             self.command_queue.append(command)
#         else:
#             print "Error: invalid command"
# 
# 
#     def addCommands(self, commands):
#         for command in commands:
#             self.addCommand(command)
# 
# 
#     def setStartTime(self, time):
#         self.start_time = time
# 
# 
#     def update(self, time):
#         if self.cur_action:
#             name = self.cur_action
#             anim_controller = self.actor.getAnimControl(name)
#             next_frame = anim_controller.getNextFrame()
#             cur_frame = anim_controller.getFullFframe()
#             num_frames = anim_controller.getNumFrames()
# 
#             if not self.sequence.isPlaying():
# #            if not anim_controller.isPlaying():
#                 if self.command_queue:
#                     next_action = self.command_queue.pop(0)
#                     self.startAction(next_action)
#                 else:
#                     if self.live_controller:
#                         if self.cur_action == 'run':
#                             next_action = 'run'
#                         elif self.cur_action == 'stand':
#                             next_action = 'stand'
#                         else:
#                             next_action = 'walk'
#                     
#                         self.startAction(next_action)
# 
#     
#     def isActive(self, time):
#         if time >= self.start_time and self.command_queue or \
#            time >= self.start_time and self.live_controller:
#             if self.actor.isHidden():
#                 self.actor.show()
#             return True
#         else:
#             if not self.actor.isHidden():
#                 self.actor.hide()
#             return False
# 
# 
#     def reposition(self, diff, rotation):
#         x,y,z = diff
#         self.actor.setX(x)
#         self.actor.setY(y)
#         self.actor.setH(self.actor.getH() + rotation)
# #        name = self.cur_action
# #        anim_controller = self.actor.getAnimControl(name)
# #        cur_frame = anim_controller.getFullFframe()
# #        print cur_frame
# 
# 
#     def liveController(self):
#             self.print_action = True
#             self.live_controller = True
# 
# 
#     def startAction(self, action):
#         cur_action = self.cur_action
#         rotation = self.actions[cur_action].rotation
#         self.cur_action = action
#         paction = self.actions[action]
#         if cur_action != "stand":
#             diff = self.joint.getPos(render) - paction.diff
#         else:
#             diff = self.actor.getPos()
#             
#         if self.print_action:
#             print paction.name,
#             
#         interval = self.actor.actorInterval(paction.name)
#         func = Func(self.reposition, diff, rotation)
#         self.sequence = Parallel(Sequence(Wait(0.001),func), interval)
#         self.sequence.start()


# Path: src/simulator/panda3d/builders/pedestrian_builder.py
import os
import logging
import sys
from pandac.PandaModules import Spotlight
from direct.actor.Actor import Actor
from pandac.PandaModules import VBase3
from ..panda3d_helper import *
from ..panda_pedestrian import PandaPedestrian

        self.pedestrian_count = 0
        self.characters = {}


    def buildPedestrian(self, character_name, texture, scale, hpr, pos):
        """Builds a Panda3D actor by using the specified model and texture"""
        if not character_name in self.characters:
            return
        character = self.characters[character_name]
        model_path = os.path.normpath("%s/%s" 
                                      % (self.config_path, character['model']))
        if not os.path.exists(model_path):
            logging.error("The path '%s' does not exist" % model_path)
            sys.exit()
        
        actor = Actor(model_path)
        tex_dir = character['texture_dir']
        tex_path = os.path.normpath("%s/%s/%s" 
                                    %(self.config_path, tex_dir, texture))
        if not os.path.exists(tex_path):
            logging.error("The path '%s' does not exist" % tex_path)
            sys.exit()
        tex = loader.loadTexture(tex_path)
        actor.setTexture(tex,1)
        actor.reparentTo(self.parent.render)
        actor.setScale(scale)
        actor.setHpr(VBase3(*hpr))
        actor.setPos(*ToPandaCoordinates(VBase3(*pos)))
        
        joint = character['joint']

        panda_pedestrian = PandaPedestrian(actor, texture, self.parent.taskMgr, joint)