shubhamgoyal

object_builder.py [flattenStrong() version]

Jul 18th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.99 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #
  3. # Copyright (c) 2011-2012 Wiktor Starzyk, Faisal Z. Qureshi
  4. #
  5. # This file is part of the Virtual Vision Simulator.
  6. #
  7. # The Virtual Vision Simulator is free software: you can
  8. # redistribute it and/or modify it under the terms
  9. # of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License,
  11. # or (at your option) any later version.
  12. #
  13. # The Virtual Vision Simulator is distributed in the hope
  14. # that it will be useful, but WITHOUT ANY WARRANTY;
  15. # without even the implied warranty of MERCHANTABILITY or
  16. # FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with the Virtual Vision Simulator.  
  21. # If not, see <http://www.gnu.org/licenses/>.
  22. #
  23.  
  24.  
  25. import os
  26. import logging
  27. import sys
  28.  
  29. from pandac.PandaModules import Filename
  30. from pandac.PandaModules import Spotlight
  31. from pandac.PandaModules import NodePath
  32. from direct.actor.Actor import Actor
  33. from simulator.panda3d.panda_object import PandaObject
  34.  
  35. class ObjectBuilder:
  36.  
  37.     def __init__(self, parent, config_path):
  38.         self.parent = parent
  39.         self.config_path = config_path
  40.  
  41.  
  42.     def buildObject(self, model, scale, pos, hpr, has_lighting=True):
  43.         """Builds a static object using the Panda3D loadModel function"""
  44.         path = os.path.normpath("%s/%s" % (self.config_path, model))
  45.         if not os.path.exists(path):
  46.             logging.error("The path '%s' does not exist" % path)
  47.             sys.exit()
  48.         path = Filename.fromOsSpecific(path)
  49.         modelRoot = self.parent.loader.loadModel(path)
  50.         object = NodePath('static_model')
  51.     modelRoot.getChildren().reparentTo(object)
  52.         object.setPos(*pos)
  53.         object.setHpr(*hpr)
  54.         object.setScale(scale)
  55.         object.reparentTo(self.parent.static_model)
  56.         static_object = PandaObject(object, has_lighting)
  57.         return static_object
Advertisement
Add Comment
Please, Sign In to add comment