| 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 |
| $Revision: 1.1.1.1 $ |
| 44 |
| |
| 45 |
| Classes: |
| 46 |
| SoV2VertexProperty |
| 47 |
| |
| 48 |
| Author(s) : 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 "SoV2VertexProperty.h" |
| 55 |
#include <Inventor/nodes/SoVertexProperty.h> |
| 56 |
#include <Inventor/nodes/SoGroup.h> |
| 57 |
#include <Inventor/nodes/SoCoordinate3.h> |
| 58 |
#include <Inventor/nodes/SoNormal.h> |
| 59 |
#include <Inventor/nodes/SoPackedColor.h> |
| 60 |
#include <Inventor/nodes/SoTextureCoordinate2.h> |
| 61 |
#include <Inventor/nodes/SoNormalBinding.h> |
| 62 |
#include <Inventor/nodes/SoMaterialBinding.h> |
| 63 |
#include <Inventor/errors/SoReadError.h> |
| 64 |
|
| 65 |
SO_NODE_SOURCE(SoV2VertexProperty); |
| 66 |
|
| 67 |
//////////////////////////////////////////////////////////////////////// |
| 68 |
// |
| 69 |
// Description: |
| 70 |
// Default constructor |
| 71 |
// |
| 72 |
// Use: public |
| 73 |
|
| 74 |
SoV2VertexProperty::SoV2VertexProperty() |
| 75 |
// |
| 76 |
//////////////////////////////////////////////////////////////////////// |
| 77 |
{ |
| 78 |
SO_NODE_CONSTRUCTOR(SoV2VertexProperty); |
| 79 |
|
| 80 |
// Initialize with dummy values using standard macro, then delete |
| 81 |
// all values: |
| 82 |
SO_NODE_ADD_FIELD(vertex, (SbVec3f(0,0,0))); |
| 83 |
vertex.deleteValues(0); |
| 84 |
SO_NODE_ADD_FIELD(normal, (SbVec3f(0,0,0))); |
| 85 |
normal.deleteValues(0); |
| 86 |
SO_NODE_ADD_FIELD(texCoord, (SbVec2f(0,0))); |
| 87 |
texCoord.deleteValues(0); |
| 88 |
SO_NODE_ADD_FIELD(orderedRGBA, (0)); |
| 89 |
orderedRGBA.deleteValues(0); |
| 90 |
|
| 91 |
// Initialize these with default values. They'll be ignored if |
| 92 |
// the corresponding fields have no values: |
| 93 |
SO_NODE_ADD_FIELD(materialBinding, (SoVertexProperty::OVERALL)); |
| 94 |
SO_NODE_ADD_FIELD(normalBinding, (SoVertexProperty::PER_VERTEX_INDEXED)); |
| 95 |
|
| 96 |
SO_NODE_ADD_FIELD(alternateRep, (NULL)); |
| 97 |
|
| 98 |
// Set up static info for enumerated type field |
| 99 |
SO_NODE_DEFINE_ENUM_VALUE(Binding, OVERALL); |
| 100 |
SO_NODE_DEFINE_ENUM_VALUE(Binding, PER_VERTEX); |
| 101 |
SO_NODE_DEFINE_ENUM_VALUE(Binding, PER_VERTEX_INDEXED); |
| 102 |
SO_NODE_DEFINE_ENUM_VALUE(Binding, PER_FACE); |
| 103 |
SO_NODE_DEFINE_ENUM_VALUE(Binding, PER_FACE_INDEXED); |
| 104 |
SO_NODE_DEFINE_ENUM_VALUE(Binding, PER_PART); |
| 105 |
SO_NODE_DEFINE_ENUM_VALUE(Binding, PER_PART_INDEXED); |
| 106 |
|
| 107 |
// Set up info in enumerated type field |
| 108 |
SO_NODE_SET_SF_ENUM_TYPE(materialBinding, Binding); |
| 109 |
SO_NODE_SET_SF_ENUM_TYPE(normalBinding, Binding); |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
//////////////////////////////////////////////////////////////////////// |
| 114 |
// |
| 115 |
// Description: |
| 116 |
// Destructor. |
| 117 |
// |
| 118 |
// Use: private |
| 119 |
|
| 120 |
SoV2VertexProperty::~SoV2VertexProperty() |
| 121 |
// |
| 122 |
//////////////////////////////////////////////////////////////////////// |
| 123 |
{ |
| 124 |
} |
| 125 |
|
| 126 |
//////////////////////////////////////////////////////////////////////// |
| 127 |
// |
| 128 |
// Description: |
| 129 |
// Create a version 2.1 VertexProperty. |
| 130 |
// |
| 131 |
// Use: private |
| 132 |
|
| 133 |
SoNode * |
| 134 |
SoV2VertexProperty::createNewNode() |
| 135 |
// |
| 136 |
//////////////////////////////////////////////////////////////////////// |
| 137 |
{ |
| 138 |
SoVertexProperty *result = SO_UPGRADER_CREATE_NEW(SoVertexProperty); |
| 139 |
|
| 140 |
// |
| 141 |
// Inventor 2.0 did not have VertexProperty. When we convert 2.1 to 2.0 files, |
| 142 |
// the VertexProperty puts all its field info into an alternateRep, then |
| 143 |
// sets its fields to default values. |
| 144 |
// We simply run through the nodes in the alternateRep and recreate the fields. |
| 145 |
// |
| 146 |
|
| 147 |
if (! alternateRep.isDefault()) { |
| 148 |
SoGroup *group = (SoGroup *) alternateRep.getValue(); |
| 149 |
if (group->isOfType(SoGroup::getClassTypeId())) { |
| 150 |
for (int i = 0; i < group->getNumChildren(); i++) { |
| 151 |
SoNode *node = group->getChild(i); |
| 152 |
|
| 153 |
// Set the fields in our node |
| 154 |
if (node->isOfType(SoCoordinate3::getClassTypeId())) |
| 155 |
result->vertex.copyFrom(((SoCoordinate3 *)node)->point); |
| 156 |
|
| 157 |
else if (node->isOfType(SoNormal::getClassTypeId())) |
| 158 |
result->normal.copyFrom(((SoNormal *)node)->vector); |
| 159 |
|
| 160 |
else if (node->isOfType(SoPackedColor::getClassTypeId())) |
| 161 |
result->orderedRGBA.copyFrom(((SoPackedColor *)node)->orderedRGBA); |
| 162 |
|
| 163 |
else if (node->isOfType(SoTextureCoordinate2::getClassTypeId())) |
| 164 |
result->texCoord.copyFrom(((SoTextureCoordinate2 *)node)->point); |
| 165 |
|
| 166 |
else if (node->isOfType(SoNormalBinding::getClassTypeId())) |
| 167 |
result->normalBinding.copyFrom(((SoNormalBinding *)node)->value); |
| 168 |
|
| 169 |
else if (node->isOfType(SoMaterialBinding::getClassTypeId())) |
| 170 |
result->materialBinding.copyFrom(((SoMaterialBinding *)node)->value); |
| 171 |
} |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
return result; |
| 176 |
} |
| 177 |
//////////////////////////////////////////////////////////////////////// |
| 178 |
// |
| 179 |
// Description: |
| 180 |
// special upgrade method to read field description |
| 181 |
// |
| 182 |
// Use: public, internal, virtual |
| 183 |
SbBool |
| 184 |
SoV2VertexProperty::upgrade(SoInput *in, const SbName &refName, SoBase *&result) |
| 185 |
// |
| 186 |
//////////////////////////////////////////////////////////////////////// |
| 187 |
{ |
| 188 |
SbBool isBinary = in->isBinary(); |
| 189 |
if (in->isBinary()){ |
| 190 |
SbString unknownString; |
| 191 |
SbBool readOK = in->read(unknownString); |
| 192 |
if (!readOK || (unknownString != "fields" )) { |
| 193 |
SoReadError::post(in, "Problem upgrading vertex property ") ; |
| 194 |
return FALSE; |
| 195 |
} |
| 196 |
} |
| 197 |
SbBool ret = SoUpgrader::upgrade(in, refName, result); |
| 198 |
|
| 199 |
if (in->isBinary()){ |
| 200 |
// Read a zero, which represents the number of children here |
| 201 |
int dummy; |
| 202 |
in->read(dummy); |
| 203 |
} |
| 204 |
|
| 205 |
return ret; |
| 206 |
} |