Panda3D
cLwoSurfaceBlock.cxx
Go to the documentation of this file.
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 cLwoSurfaceBlock.cxx
10  * @author drose
11  * @date 2001-04-26
12  */
13 
14 #include "cLwoSurfaceBlock.h"
15 #include "cLwoSurfaceBlockTMap.h"
16 #include "lwoToEggConverter.h"
17 
18 #include "lwoSurfaceBlockChannel.h"
19 #include "lwoSurfaceBlockEnabled.h"
20 #include "lwoSurfaceBlockImage.h"
21 #include "lwoSurfaceBlockRepeat.h"
23 #include "dcast.h"
24 
25 
26 /**
27  *
28  */
29 CLwoSurfaceBlock::
30 CLwoSurfaceBlock(LwoToEggConverter *converter, const LwoSurfaceBlock *block) :
31  _converter(converter),
32  _block(block)
33 {
34  _block_type = _block->_header->get_id();
35  _ordinal = _block->_header->_ordinal;
36  _enabled = true;
37  _opacity_type = LwoSurfaceBlockOpacity::T_additive;
38  _opacity = 1.0;
39  _transform = LMatrix4d::ident_mat();
40  _inv_transform = LMatrix4d::ident_mat();
41  _projection_mode = LwoSurfaceBlockProjection::M_uv;
42  _axis = LwoSurfaceBlockAxis::A_y;
43  _clip_index = -1;
44  _w_wrap = LwoSurfaceBlockWrap::M_repeat;
45  _h_wrap = LwoSurfaceBlockWrap::M_repeat;
46  _w_repeat = 1.0;
47  _h_repeat = 1.0;
48  _tmap = nullptr;
49 
50  // Scan the chunks in the header.
51  int num_hchunks = _block->_header->get_num_chunks();
52  for (int hi = 0; hi < num_hchunks; hi++) {
53  const IffChunk *hchunk = _block->_header->get_chunk(hi);
54 
55  if (hchunk->is_of_type(LwoSurfaceBlockChannel::get_class_type())) {
56  const LwoSurfaceBlockChannel *bc =
57  DCAST(LwoSurfaceBlockChannel, hchunk);
58  _channel_id = bc->_channel_id;
59 
60  } else if (hchunk->is_of_type(LwoSurfaceBlockEnabled::get_class_type())) {
61  const LwoSurfaceBlockEnabled *ec =
62  DCAST(LwoSurfaceBlockEnabled, hchunk);
63  _enabled = ec->_enabled;
64  }
65  }
66 
67  // Scan the chunks in the body.
68  int num_chunks = _block->get_num_chunks();
69  for (int i = 0; i < num_chunks; i++) {
70  const IffChunk *chunk = _block->get_chunk(i);
71 
72  if (chunk->is_of_type(LwoSurfaceBlockTMap::get_class_type())) {
73  const LwoSurfaceBlockTMap *lwo_tmap = DCAST(LwoSurfaceBlockTMap, chunk);
74  if (_tmap != nullptr) {
75  nout << "Two TMAP chunks encountered within surface block.\n";
76  delete _tmap;
77  }
78  _tmap = new CLwoSurfaceBlockTMap(_converter, lwo_tmap);
79 
80  } else if (chunk->is_of_type(LwoSurfaceBlockProjection::get_class_type())) {
81  const LwoSurfaceBlockProjection *proj = DCAST(LwoSurfaceBlockProjection, chunk);
82  _projection_mode = proj->_mode;
83 
84  } else if (chunk->is_of_type(LwoSurfaceBlockAxis::get_class_type())) {
85  const LwoSurfaceBlockAxis *axis = DCAST(LwoSurfaceBlockAxis, chunk);
86  _axis = axis->_axis;
87 
88  } else if (chunk->is_of_type(LwoSurfaceBlockImage::get_class_type())) {
89  const LwoSurfaceBlockImage *image = DCAST(LwoSurfaceBlockImage, chunk);
90  _clip_index = image->_index;
91 
92  } else if (chunk->is_of_type(LwoSurfaceBlockWrap::get_class_type())) {
93  const LwoSurfaceBlockWrap *wrap = DCAST(LwoSurfaceBlockWrap, chunk);
94  _w_wrap = wrap->_width;
95  _h_wrap = wrap->_height;
96 
97  } else if (chunk->is_of_type(LwoSurfaceBlockWrap::get_class_type())) {
98  const LwoSurfaceBlockWrap *wrap = DCAST(LwoSurfaceBlockWrap, chunk);
99  _w_wrap = wrap->_width;
100  _h_wrap = wrap->_height;
101 
102  } else if (chunk->is_of_type(LwoSurfaceBlockVMapName::get_class_type())) {
103  const LwoSurfaceBlockVMapName *vmap = DCAST(LwoSurfaceBlockVMapName, chunk);
104  _uv_name = vmap->_name;
105 
106  } else if (chunk->is_of_type(LwoSurfaceBlockRepeat::get_class_type())) {
107  const LwoSurfaceBlockRepeat *repeat = DCAST(LwoSurfaceBlockRepeat, chunk);
108  if (repeat->get_id() == IffId("WRPW")) {
109  _w_repeat = repeat->_cycles;
110  } else if (repeat->get_id() == IffId("WRPH")) {
111  _h_repeat = repeat->_cycles;
112  }
113  }
114  }
115 
116  if (_tmap != nullptr) {
117  _tmap->get_transform(_transform);
118  }
119 
120  // Also rotate the transform if we specify some axis other than Y. (All the
121  // map_* uv mapping functions are written to assume Y is the dominant axis.)
122  switch (_axis) {
123  case LwoSurfaceBlockAxis::A_x:
124  _transform = LMatrix4d::rotate_mat(90.0,
125  LVecBase3d::unit_z(),
126  CS_yup_left) * _transform;
127  break;
128 
129  case LwoSurfaceBlockAxis::A_y:
130  break;
131 
132  case LwoSurfaceBlockAxis::A_z:
133  _transform = LMatrix4d::rotate_mat(-90.0,
134  LVecBase3d::unit_x(),
135  CS_yup_left) * _transform;
136  break;
137  }
138 
139  _inv_transform.invert_from(_transform);
140 }
141 
142 /**
143  *
144  */
145 CLwoSurfaceBlock::
146 ~CLwoSurfaceBlock() {
147  if (_tmap != nullptr) {
148  delete _tmap;
149  }
150 }
Indicates which channel the texture in this LwoSurfaceBlock is applied to.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
For cylindrical and spherical projections, this parameter controls how many times the image repeats o...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A texture layer or shader, part of a LwoSurface chunk.
The tMap chunk within a LwoSurfaceBlock chunk.
Specifies how the texture image appears for areas outside the image.
Specifies the name of a set of UV's defined on the polygons that use this model.
The basic kind of record in an EA "IFF" file, which the LightWave object file is based on.
Definition: iffChunk.h:30
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Indicates the projection mode for this particular shader.
Indicates the axis for this particular shader's projection.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class supervises the construction of an EggData structure from the data represented by the LwoHe...
Indicates whether this particular layer or shader should be rendered or not.
Specifies the particular image that is being applied as a texture.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition: typedObject.I:28
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class is a wrapper around LwoSurfaceBlockTMap and stores additional information useful during th...
A four-byte chunk ID appearing in an "IFF" file.
Definition: iffId.h:26
IffId get_id() const
Returns the ID associated with this chunk.
Definition: iffChunk.I:25
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.