Debian Codegraph @

apps/converters/ivdowngrade/SoIndexedTriangleMeshV1.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) 1990-93 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 | $Revision: 1.1.1.1 $
44 |
45 | Classes:
46 | SoIndexedTriangleMeshV1
47 |
48 | Author(s) : Gavin Bell, David Mott
49 |
50 ______________ S I L I C O N G R A P H I C S I N C . ____________
51 _______________________________________________________________________
52 */
53
54 #include <Inventor/nodes/SoIndexedTriangleStripSet.h>
55 #include <Inventor/nodes/SoSeparator.h>
56 #include <Inventor/nodes/SoVertexProperty.h>
57 #include "SoIndexedTriangleMeshV1.h"
58 #include "SoVertexPropertyV2.h"
59
60 SO_NODE_SOURCE(SoIndexedTriangleMeshV1);
61
62 ////////////////////////////////////////////////////////////////////////
63 //
64 // Description:
65 // Default constructor
66 //
67 // Use: public
68
69 SoIndexedTriangleMeshV1::SoIndexedTriangleMeshV1()
70 //
71 ////////////////////////////////////////////////////////////////////////
72 {
73 SO_NODE_CONSTRUCTOR(SoIndexedTriangleMeshV1);
74
75 SO_NODE_ADD_FIELD(coordIndex, (-1));
76 SO_NODE_ADD_FIELD(materialIndex, (-1));
77 SO_NODE_ADD_FIELD(normalIndex, (-1));
78 SO_NODE_ADD_FIELD(textureCoordIndex, (-1));
79
80 isBuiltIn = TRUE;
81 }
82
83 ////////////////////////////////////////////////////////////////////////
84 //
85 // Description:
86 // This initializes the SoIndexedTriangleMeshV1 class.
87 //
88 // Use: internal
89
90 void
91 SoIndexedTriangleMeshV1::initClass()
92 //
93 ////////////////////////////////////////////////////////////////////////
94 {
95 SO__NODE_INIT_CLASS(SoIndexedTriangleMeshV1, "IndexedTriangleMesh", SoNode);
96 }
97
98 ////////////////////////////////////////////////////////////////////////
99 //
100 // Description:
101 // Convert the 2.0 tri strip set to a 1.0 tmesh.
102 //
103 SoNode *
104 SoIndexedTriangleMeshV1::downgrade(SoIndexedTriangleStripSet *tstrip)
105 //
106 ////////////////////////////////////////////////////////////////////////
107 {
108 SoIndexedTriangleMeshV1 *tmesh = new SoIndexedTriangleMeshV1;
109
110 // just copy all the fields (only the name of this class needs
111 // to change. But there is no mechanism to change a class name,
112 // so we copy all the data to this class which has the name we want.)
113 int num;
114
115 #define COPY_MFINT32(toNode, fromNode, field) \
116 if (! fromNode->field.isDefault()) { \
117 if ((num = fromNode->field.getNum()) > 0) \
118 toNode->field.setValues(0, num, fromNode->field.getValues(0)); \
119 } \
120 if (fromNode->field.isIgnored()) \
121 toNode->field.setIgnored(TRUE) \
122
123
124 COPY_MFINT32(tmesh, tstrip, coordIndex);
125 COPY_MFINT32(tmesh, tstrip, materialIndex);
126 COPY_MFINT32(tmesh, tstrip, normalIndex);
127 COPY_MFINT32(tmesh, tstrip, textureCoordIndex);
128
129 // If the vertexProperty field is set, then we need to do more work
130 SoNode *node;
131 if (! tstrip->vertexProperty.isDefault()) {
132 SoSeparator *sep = new SoSeparator;
133 SoVertexProperty *vp = (SoVertexProperty *) tstrip->vertexProperty.getValue();
134
135 SoGroup *vpgroup = SoVertexPropertyV2::convert(vp);
136 sep->addChild(vpgroup);
137 sep->addChild(tmesh);
138
139 node = sep;
140 }
141 else node = tmesh;
142
143 return node;
144 }