lwoSurface.cxx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 lwoSurface.cxx
  10. * @author drose
  11. * @date 2001-04-24
  12. */
  13. #include "lwoSurface.h"
  14. #include "iffInputFile.h"
  15. #include "lwoSurfaceBlock.h"
  16. #include "lwoSurfaceColor.h"
  17. #include "lwoSurfaceParameter.h"
  18. #include "lwoSurfaceSidedness.h"
  19. #include "lwoSurfaceSmoothingAngle.h"
  20. #include "indent.h"
  21. TypeHandle LwoSurface::_type_handle;
  22. /**
  23. * Reads the data of the chunk in from the given input file, if possible. The
  24. * ID and length of the chunk have already been read. stop_at is the byte
  25. * position of the file to stop at (based on the current position at
  26. * in->get_bytes_read()). Returns true on success, false otherwise.
  27. */
  28. bool LwoSurface::
  29. read_iff(IffInputFile *in, size_t stop_at) {
  30. _name = in->get_string();
  31. _source = in->get_string();
  32. read_subchunks_iff(in, stop_at);
  33. return true;
  34. }
  35. /**
  36. *
  37. */
  38. void LwoSurface::
  39. write(std::ostream &out, int indent_level) const {
  40. indent(out, indent_level)
  41. << get_id() << " {\n";
  42. indent(out, indent_level + 2)
  43. << "name = \"" << _name << "\", source = \"" << _source << "\"\n";
  44. write_chunks(out, indent_level + 2);
  45. indent(out, indent_level)
  46. << "}\n";
  47. }
  48. /**
  49. * Allocates and returns a new chunk of the appropriate type based on the
  50. * given ID, according to the context given by this chunk itself.
  51. */
  52. IffChunk *LwoSurface::
  53. make_new_chunk(IffInputFile *in, IffId id) {
  54. if (id == IffId("COLR")) {
  55. return new LwoSurfaceColor;
  56. } else if (id == IffId("DIFF") ||
  57. id == IffId("LUMI") ||
  58. id == IffId("SPEC") ||
  59. id == IffId("REFL") ||
  60. id == IffId("TRAN") ||
  61. id == IffId("TRNL") ||
  62. id == IffId("GLOS") ||
  63. id == IffId("SHRP") ||
  64. id == IffId("BUMP") ||
  65. id == IffId("RSAN") ||
  66. id == IffId("RIND")) {
  67. return new LwoSurfaceParameter;
  68. } else if (id == IffId("SIDE")) {
  69. return new LwoSurfaceSidedness;
  70. } else if (id == IffId("SMAN")) {
  71. return new LwoSurfaceSmoothingAngle;
  72. } else if (id == IffId("BLOK")) {
  73. return new LwoSurfaceBlock;
  74. } else {
  75. return IffChunk::make_new_chunk(in, id);
  76. }
  77. }