lwoLayer.cxx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file lwoLayer.cxx
  10. * @author drose
  11. * @date 2001-04-24
  12. */
  13. #include "lwoLayer.h"
  14. #include "lwoInputFile.h"
  15. #include "dcast.h"
  16. #include "indent.h"
  17. TypeHandle LwoLayer::_type_handle;
  18. /**
  19. * Resets the layer's parameters to initial defaults for a generic layer
  20. * created implicitly.
  21. */
  22. void LwoLayer::
  23. make_generic() {
  24. _number = -1;
  25. _flags = 0;
  26. _pivot.set(0.0, 0.0, 0.0);
  27. _name = "Generic";
  28. _parent = -1;
  29. }
  30. /**
  31. * Reads the data of the chunk in from the given input file, if possible. The
  32. * ID and length of the chunk have already been read. stop_at is the byte
  33. * position of the file to stop at (based on the current position at
  34. * in->get_bytes_read()). Returns true on success, false otherwise.
  35. */
  36. bool LwoLayer::
  37. read_iff(IffInputFile *in, size_t stop_at) {
  38. LwoInputFile *lin = DCAST(LwoInputFile, in);
  39. _number = lin->get_be_uint16();
  40. _flags = lin->get_be_uint16();
  41. _pivot = lin->get_vec3();
  42. _name = lin->get_string();
  43. if (lin->get_bytes_read() >= stop_at) {
  44. _parent = -1;
  45. } else {
  46. _parent = lin->get_be_uint16();
  47. if (_parent == 0xffff) {
  48. _parent = -1;
  49. }
  50. }
  51. return true;
  52. }
  53. /**
  54. *
  55. */
  56. void LwoLayer::
  57. write(std::ostream &out, int indent_level) const {
  58. indent(out, indent_level)
  59. << get_id() << " { number = " << _number << ", flags = 0x"
  60. << std::hex << _flags << std::dec << ", pivot = " << _pivot
  61. << ", _name = \"" << _name << "\", _parent = " << _parent << " }\n";
  62. }