|
| 1 | +// Filename: accumulatedAttribs.cxx |
| 2 | +// Created by: drose (30Jan03) |
| 3 | +// |
| 4 | +//////////////////////////////////////////////////////////////////// |
| 5 | +// |
| 6 | +// PANDA 3D SOFTWARE |
| 7 | +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved |
| 8 | +// |
| 9 | +// All use of this software is subject to the terms of the Panda 3d |
| 10 | +// Software license. You should have received a copy of this license |
| 11 | +// along with this source code; you will also find a current copy of |
| 12 | +// the license at http://www.panda3d.org/license.txt . |
| 13 | +// |
| 14 | +// To contact the maintainers of this program write to |
| 15 | +// panda3d@yahoogroups.com . |
| 16 | +// |
| 17 | +//////////////////////////////////////////////////////////////////// |
| 18 | + |
| 19 | +#include "accumulatedAttribs.h" |
| 20 | +#include "sceneGraphReducer.h" |
| 21 | +#include "geomTransformer.h" |
| 22 | +#include "pandaNode.h" |
| 23 | +#include "colorAttrib.h" |
| 24 | +#include "colorScaleAttrib.h" |
| 25 | +#include "texMatrixAttrib.h" |
| 26 | +#include "config_pgraph.h" |
| 27 | + |
| 28 | + |
| 29 | +//////////////////////////////////////////////////////////////////// |
| 30 | +// Function: AccumulatedAttribs::write |
| 31 | +// Access: Public |
| 32 | +// Description: |
| 33 | +//////////////////////////////////////////////////////////////////// |
| 34 | +void AccumulatedAttribs:: |
| 35 | +write(ostream &out, int attrib_types, int indent_level) const { |
| 36 | + if ((attrib_types & SceneGraphReducer::TT_transform) != 0) { |
| 37 | + _transform->write(out, indent_level); |
| 38 | + } |
| 39 | + if ((attrib_types & SceneGraphReducer::TT_color) != 0) { |
| 40 | + if (_color == (const RenderAttrib *)NULL) { |
| 41 | + indent(out, indent_level) << "no color\n"; |
| 42 | + } else { |
| 43 | + _color->write(out, indent_level); |
| 44 | + } |
| 45 | + } |
| 46 | + if ((attrib_types & SceneGraphReducer::TT_color_scale) != 0) { |
| 47 | + if (_color_scale == (const RenderAttrib *)NULL) { |
| 48 | + indent(out, indent_level) << "no color scale\n"; |
| 49 | + } else { |
| 50 | + _color_scale->write(out, indent_level); |
| 51 | + } |
| 52 | + } |
| 53 | + if ((attrib_types & SceneGraphReducer::TT_tex_matrix) != 0) { |
| 54 | + if (_tex_matrix == (const RenderAttrib *)NULL) { |
| 55 | + indent(out, indent_level) << "no tex matrix\n"; |
| 56 | + } else { |
| 57 | + _tex_matrix->write(out, indent_level); |
| 58 | + } |
| 59 | + } |
| 60 | + if ((attrib_types & SceneGraphReducer::TT_other) != 0) { |
| 61 | + _other->write(out, indent_level); |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +//////////////////////////////////////////////////////////////////// |
| 66 | +// Function: AccumulatedAttribs::collect |
| 67 | +// Access: Public |
| 68 | +// Description: Collects the state and transform from the indicated |
| 69 | +// node and adds it to the accumulator, removing it from |
| 70 | +// the node. |
| 71 | +//////////////////////////////////////////////////////////////////// |
| 72 | +void AccumulatedAttribs:: |
| 73 | +collect(PandaNode *node, int attrib_types) { |
| 74 | + if ((attrib_types & SceneGraphReducer::TT_transform) != 0) { |
| 75 | + // Collect the node's transform. |
| 76 | + nassertv(_transform != (TransformState *)NULL); |
| 77 | + _transform = _transform->compose(node->get_transform()); |
| 78 | + node->set_transform(TransformState::make_identity()); |
| 79 | + } |
| 80 | + |
| 81 | + if ((attrib_types & SceneGraphReducer::TT_color) != 0) { |
| 82 | + const RenderAttrib *node_attrib = |
| 83 | + node->get_attrib(ColorAttrib::get_class_type()); |
| 84 | + if (node_attrib != (const RenderAttrib *)NULL) { |
| 85 | + // The node has a color attribute; apply it. |
| 86 | + if (_color == (const RenderAttrib *)NULL) { |
| 87 | + _color = node_attrib; |
| 88 | + } else { |
| 89 | + _color = _color->compose(node_attrib); |
| 90 | + } |
| 91 | + node->clear_attrib(ColorAttrib::get_class_type()); |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + if ((attrib_types & SceneGraphReducer::TT_color_scale) != 0) { |
| 96 | + const RenderAttrib *node_attrib = |
| 97 | + node->get_attrib(ColorScaleAttrib::get_class_type()); |
| 98 | + if (node_attrib != (const RenderAttrib *)NULL) { |
| 99 | + // The node has a color scale attribute; apply it. |
| 100 | + if (_color_scale == (const RenderAttrib *)NULL) { |
| 101 | + _color_scale = node_attrib; |
| 102 | + } else { |
| 103 | + _color_scale = _color_scale->compose(node_attrib); |
| 104 | + } |
| 105 | + node->clear_attrib(ColorScaleAttrib::get_class_type()); |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + if ((attrib_types & SceneGraphReducer::TT_tex_matrix) != 0) { |
| 110 | + const RenderAttrib *node_attrib = |
| 111 | + node->get_attrib(TexMatrixAttrib::get_class_type()); |
| 112 | + if (node_attrib != (const RenderAttrib *)NULL) { |
| 113 | + // The node has a tex matrix attribute; apply it. |
| 114 | + if (_tex_matrix == (const RenderAttrib *)NULL) { |
| 115 | + _tex_matrix = node_attrib; |
| 116 | + } else { |
| 117 | + _tex_matrix = _tex_matrix->compose(node_attrib); |
| 118 | + } |
| 119 | + node->clear_attrib(TexMatrixAttrib::get_class_type()); |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + if ((attrib_types & SceneGraphReducer::TT_transform) != 0) { |
| 124 | + // Collect everything else. |
| 125 | + nassertv(_other != (RenderState *)NULL); |
| 126 | + _other = _other->compose(node->get_state()); |
| 127 | + node->set_state(RenderState::make_empty()); |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +//////////////////////////////////////////////////////////////////// |
| 132 | +// Function: AccumulatedAttribs::apply_to_node |
| 133 | +// Access: Public |
| 134 | +// Description: Stores the indicated attributes in the node's |
| 135 | +// transform and state information; does not attempt to |
| 136 | +// apply the properties to the vertices. Clears the |
| 137 | +// attributes from the accumulator for future |
| 138 | +// traversals. |
| 139 | +//////////////////////////////////////////////////////////////////// |
| 140 | +void AccumulatedAttribs:: |
| 141 | +apply_to_node(PandaNode *node, int attrib_types) { |
| 142 | + if ((attrib_types & SceneGraphReducer::TT_transform) != 0) { |
| 143 | + node->set_transform(_transform->compose(node->get_transform())); |
| 144 | + _transform = TransformState::make_identity(); |
| 145 | + } |
| 146 | + |
| 147 | + if ((attrib_types & SceneGraphReducer::TT_color) != 0) { |
| 148 | + if (_color != (RenderAttrib *)NULL) { |
| 149 | + const RenderAttrib *node_attrib = |
| 150 | + node->get_attrib(ColorAttrib::get_class_type()); |
| 151 | + if (node_attrib != (RenderAttrib *)NULL) { |
| 152 | + node->set_attrib(_color->compose(node_attrib)); |
| 153 | + } else { |
| 154 | + node->set_attrib(_color); |
| 155 | + } |
| 156 | + _color = (RenderAttrib *)NULL; |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + if ((attrib_types & SceneGraphReducer::TT_color_scale) != 0) { |
| 161 | + if (_color_scale != (RenderAttrib *)NULL) { |
| 162 | + const RenderAttrib *node_attrib = |
| 163 | + node->get_attrib(ColorScaleAttrib::get_class_type()); |
| 164 | + if (node_attrib != (RenderAttrib *)NULL) { |
| 165 | + node->set_attrib(_color_scale->compose(node_attrib)); |
| 166 | + } else { |
| 167 | + node->set_attrib(_color_scale); |
| 168 | + } |
| 169 | + _color_scale = (RenderAttrib *)NULL; |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + if ((attrib_types & SceneGraphReducer::TT_tex_matrix) != 0) { |
| 174 | + if (_tex_matrix != (RenderAttrib *)NULL) { |
| 175 | + const RenderAttrib *node_attrib = |
| 176 | + node->get_attrib(TexMatrixAttrib::get_class_type()); |
| 177 | + if (node_attrib != (RenderAttrib *)NULL) { |
| 178 | + node->set_attrib(_tex_matrix->compose(node_attrib)); |
| 179 | + } else { |
| 180 | + node->set_attrib(_tex_matrix); |
| 181 | + } |
| 182 | + _tex_matrix = (RenderAttrib *)NULL; |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 186 | + if ((attrib_types & SceneGraphReducer::TT_other) != 0) { |
| 187 | + node->set_state(_other->compose(node->get_state())); |
| 188 | + _other = RenderState::make_empty(); |
| 189 | + } |
| 190 | +} |
0 commit comments