1 /**************************************************************************\
2 * Copyright (c) Kongsberg Oil & Gas Technologies AS
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32
33 /*!
34 \class SoNormalBinding SoNormalBinding.h Inventor/nodes/SoNormalBinding.h
35 \brief The SoNormalBinding class is a node for specifying normal vector bindings.
36
37 \ingroup nodes
38
39 Use nodes of this type to specify how to map normal vectors from
40 SoNormal nodes in the scene graph to shape nodes.
41
42 <b>FILE FORMAT/DEFAULTS:</b>
43 \code
44 NormalBinding {
45 value PER_VERTEX_INDEXED
46 }
47 \endcode
48
49 */
50
51 // *************************************************************************
52
53 #include <Inventor/actions/SoCallbackAction.h>
54
55 #include <Inventor/actions/SoGLRenderAction.h>
56 #include <Inventor/actions/SoGetPrimitiveCountAction.h>
57 #include <Inventor/actions/SoPickAction.h>
58 #include <Inventor/elements/SoNormalBindingElement.h>
59 #include <Inventor/elements/SoOverrideElement.h>
60
61 #include "nodes/SoSubNodeP.h"
62
63 // *************************************************************************
64
65 /*!
66 \enum SoNormalBinding::Binding
67
68 Enumeration of available types of mappings. See documentation of
69 SoMaterialBinding node for explanation of the different values.
70
71 Note that SoNormalBinding::DEFAULT and SoNormalBinding::NONE has
72 been obsoleted and are both mapped to
73 SoNormalBinding::PER_VERTEX_INDEXED.
74 */
75
76 /*!
77 \var SoSFEnum SoNormalBinding::value
78
79 The normal binding to use for subsequent shape nodes in the scene
80 graph.
81 */
82
83 // *************************************************************************
84
85 SO_NODE_SOURCE(SoNormalBinding);
86
87 /*!
88 Constructor.
89 */
SoNormalBinding(void)90 SoNormalBinding::SoNormalBinding(void)
91 {
92 SO_NODE_INTERNAL_CONSTRUCTOR(SoNormalBinding);
93
94 SO_NODE_ADD_FIELD(value, (DEFAULT));
95
96 SO_NODE_DEFINE_ENUM_VALUE(Binding, OVERALL);
97 SO_NODE_DEFINE_ENUM_VALUE(Binding, PER_PART);
98 SO_NODE_DEFINE_ENUM_VALUE(Binding, PER_PART_INDEXED);
99 SO_NODE_DEFINE_ENUM_VALUE(Binding, PER_FACE);
100 SO_NODE_DEFINE_ENUM_VALUE(Binding, PER_FACE_INDEXED);
101 SO_NODE_DEFINE_ENUM_VALUE(Binding, PER_VERTEX);
102 SO_NODE_DEFINE_ENUM_VALUE(Binding, PER_VERTEX_INDEXED);
103 SO_NODE_DEFINE_ENUM_VALUE(Binding, DEFAULT);
104 SO_NODE_DEFINE_ENUM_VALUE(Binding, NONE);
105
106 SO_NODE_SET_SF_ENUM_TYPE(value, Binding);
107 }
108
109 /*!
110 Destructor.
111 */
~SoNormalBinding()112 SoNormalBinding::~SoNormalBinding()
113 {
114 }
115
116 // Doc from superclass.
117 void
initClass(void)118 SoNormalBinding::initClass(void)
119 {
120 SO_NODE_INTERNAL_INIT_CLASS(SoNormalBinding, SO_FROM_INVENTOR_1|SoNode::VRML1);
121
122 SO_ENABLE(SoGLRenderAction, SoNormalBindingElement);
123 SO_ENABLE(SoPickAction, SoNormalBindingElement);
124 SO_ENABLE(SoCallbackAction, SoNormalBindingElement);
125 SO_ENABLE(SoGetPrimitiveCountAction, SoNormalBindingElement);
126 }
127
128 // Doc from superclass.
129 void
GLRender(SoGLRenderAction * action)130 SoNormalBinding::GLRender(SoGLRenderAction * action)
131 {
132 SoNormalBinding::doAction(action);
133 }
134
135 // Doc from superclass.
136 void
doAction(SoAction * action)137 SoNormalBinding::doAction(SoAction * action)
138 {
139 SoState * state = action->getState();
140 if (!this->value.isIgnored() && !SoOverrideElement::getNormalBindingOverride(state)) {
141 SoNormalBindingElement::set(state, this,
142 (SoNormalBindingElement::Binding)
143 this->value.getValue());
144 if (this->isOverride()) {
145 SoOverrideElement::setNormalBindingOverride(state, this, TRUE);
146 }
147 }
148 }
149
150 // Doc from superclass.
151 void
callback(SoCallbackAction * action)152 SoNormalBinding::callback(SoCallbackAction * action)
153 {
154 SoNormalBinding::doAction(action);
155 }
156
157 // Doc from superclass.
158 void
pick(SoPickAction * action)159 SoNormalBinding::pick(SoPickAction * action)
160 {
161 SoNormalBinding::doAction(action);
162 }
163
164 // Doc from superclass.
165 void
getPrimitiveCount(SoGetPrimitiveCountAction * action)166 SoNormalBinding::getPrimitiveCount(SoGetPrimitiveCountAction * action)
167 {
168 SoNormalBinding::doAction(action);
169 }
170
171 SbBool
readInstance(SoInput * in,unsigned short flags)172 SoNormalBinding::readInstance(SoInput * in, unsigned short flags)
173 {
174 SbBool ret = inherited::readInstance(in, flags);
175
176 if (this->value.getValue() < 2) {
177 // old OIV files might use obsolete bindings. Change to
178 // PER_VERTEX_INDEXED
179 this->value = PER_VERTEX_INDEXED;
180 }
181
182 return ret;
183 }
184