Debian Codegraph @

apps/converters/ivdowngrade/SoVertexPropertyV2.c++

raw
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*
38 * Copyright (C) 1995-96 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | Classes:
44 | SoVertexPropertyV2
45 |
46 | Authors: David Mott
47 |
48 ______________ S I L I C O N G R A P H I C S I N C . ____________
49 _______________________________________________________________________
50 */
51
52 #include <Inventor/nodes/SoGroup.h>
53 #include <Inventor/nodes/SoCoordinate3.h>
54 #include <Inventor/nodes/SoNormal.h>
55 #include <Inventor/nodes/SoPackedColor.h>
56 #include <Inventor/nodes/SoTextureCoordinate2.h>
57 #include <Inventor/nodes/SoNormalBinding.h>
58 #include <Inventor/nodes/SoMaterialBinding.h>
59 #include <Inventor/actions/SoWriteAction.h>
60 #include "SoVertexPropertyV2.h"
61 #include "SoPackedColorV2.h"
62
63 SO_NODE_SOURCE(SoVertexPropertyV2);
64
65 ////////////////////////////////////////////////////////////////////////
66 //
67 // Description:
68 // init that class!
69 //
70 void
71 SoVertexPropertyV2::initClass()
72 //
73 ////////////////////////////////////////////////////////////////////////
74 {
75 SO__NODE_INIT_CLASS(SoVertexPropertyV2, "VertexProperty", SoVertexProperty);
76
77 // Tell the type system whenever it wants to create something
78 // of type SoVertexProperty to create a SoVertexPropertyV2
79 SoType::overrideType(
80 SoVertexProperty::getClassTypeId(), &SoVertexPropertyV2::createInstance);
81 }
82
83 ////////////////////////////////////////////////////////////////////////
84 //
85 // Description:
86 // Constructor
87 //
88 SoVertexPropertyV2::SoVertexPropertyV2()
89 //
90 ////////////////////////////////////////////////////////////////////////
91 {
92 SO_NODE_CONSTRUCTOR(SoVertexPropertyV2);
93 SO_NODE_ADD_FIELD(alternateRep, (NULL));
94 }
95
96 ////////////////////////////////////////////////////////////////////////
97 //
98 // Description:
99 // Destructor
100 //
101 SoVertexPropertyV2::~SoVertexPropertyV2()
102 //
103 ////////////////////////////////////////////////////////////////////////
104 {
105
106 }
107
108 ////////////////////////////////////////////////////////////////////////
109 //
110 // Description:
111 // write the alternate rep for this node
112 //
113 void
114 SoVertexPropertyV2::write(SoWriteAction *action)
115 //
116 ////////////////////////////////////////////////////////////////////////
117 {
118 SoOutput *out = action->getOutput();
119
120 // In write-reference counting phase
121 if (out->getStage() == SoOutput::COUNT_REFS) {
122 // Only do this once!
123 if (alternateRep.isDefault()) {
124 // Set up the alternate representation
125 SoGroup *group = convert(this);
126 alternateRep = group;
127
128 // Data from the fields has been copied under the alternateRep.
129 // No need to write it out again, so set fields to default.
130 vertex.setDefault(TRUE);
131 normal.setDefault(TRUE);
132 orderedRGBA.setDefault(TRUE);
133 texCoord.setDefault(TRUE);
134 normalBinding.setDefault(TRUE);
135 materialBinding.setDefault(TRUE);
136 }
137 }
138
139 SoVertexProperty::write(action);
140 }
141
142 ////////////////////////////////////////////////////////////////////////
143 //
144 // Description:
145 // write the alternate rep for this node
146 //
147 SoGroup *
148 SoVertexPropertyV2::convert(SoVertexProperty *vp)
149 //
150 ////////////////////////////////////////////////////////////////////////
151 {
152 SoGroup *group = new SoGroup;
153
154 // For any non default field, create a node to contain its info
155 // and put that node in the group (alternateRep). We can set the
156 // field to default since its info will be written in the alternateRep
157 // (no need to write it twice).
158 if ( vp->vertex.getNum()>0 ) {
159 SoCoordinate3 *coord = new SoCoordinate3;
160 coord->point.copyFrom(vp->vertex);
161 group->addChild(coord);
162 }
163 if (vp->normal.getNum()>0 ) {
164 SoNormal *norm = new SoNormal;
165 norm->vector.copyFrom(vp->normal);
166 group->addChild(norm);
167 }
168 if ( vp->orderedRGBA.getNum()>0 ) {
169 SoPackedColor *packedColor = new SoPackedColorV2;
170 packedColor->orderedRGBA.copyFrom(vp->orderedRGBA);
171 group->addChild(packedColor);
172 }
173 if ( vp->texCoord.getNum()>0 ) {
174 SoTextureCoordinate2 *tex = new SoTextureCoordinate2;
175 tex->point.copyFrom(vp->texCoord);
176 group->addChild(tex);
177 }
178 if (! vp->normalBinding.isDefault()) {
179 SoNormalBinding *normBind = new SoNormalBinding;
180 normBind->value.copyFrom(vp->normalBinding);
181 group->addChild(normBind);
182 }
183 if (! vp->materialBinding.isDefault()) {
184 SoMaterialBinding *mtlBind = new SoMaterialBinding;
185 mtlBind->value.copyFrom(vp->materialBinding);
186 group->addChild(mtlBind);
187 }
188
189 return group;
190 }
191