1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
17 * This library is free software; you can redistribute it and/or modify it *
18 * under the terms of the GNU Library General Public License as published *
19 * by the Free Software Foundation, version 2. *
21 * This library is distributed in the hope that it will be useful, but *
22 * WITHOUT ANY WARRANTY; without even the implied warranty of *
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
24 * Library General Public License for more details. *
26 * You should have received a copy of the GNU Library General Public *
27 * License along with this library; if not, write to the Free Software *
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
31 \*---------------------------------------------------------------------------*/
32 /*---------------------------------------------------------------------------*\
40 \*---------------------------------------------------------------------------*/
42 //---------------------------------------------------------------------------
44 //---------------------------------------------------------------------------
49 #include "OSGConfig.h"
51 #include "OSGPrimeMaterial.h"
52 #include "OSGGeoBuilder.h"
57 /***************************************************************************\
59 \***************************************************************************/
61 // Default Typenames for the given attribute
62 const char* GeoBuilder::_defaultPropTypes
[Geometry::MaxAttribs
] =
64 "GeoPnt3fProperty", // Positions = 0
65 "GeoVec3fProperty", // 1 unused
66 "GeoVec3fProperty", // NormalsIndex = 2
67 "GeoColor4fProperty",// ColorsIndex = 3
68 "GeoColor4fProperty",// SecondaryColorsIndex = 4
69 "GeoVec3fProperty", // 5 unused
70 "GeoVec3fProperty", // 6 unused
71 "GeoVec3fProperty", // 7 unused
72 "GeoVec2fProperty", // TexCoordsIndex = 8
73 "GeoVec2fProperty", // TexCoords1Index = 9
74 "GeoVec2fProperty", // TexCoords2Index = 10
75 "GeoVec2fProperty", // TexCoords3Index = 11
76 "GeoVec2fProperty", // TexCoords4Index = 12
77 "GeoVec2fProperty", // TexCoords5Index = 13
78 "GeoVec2fProperty", // TexCoords6Index = 14
79 "GeoVec2fProperty", // TexCoords7Index = 15
82 GeoBuilder::GeoBuilder(void) :
90 GeoBuilder::~GeoBuilder()
94 void GeoBuilder::reset(void)
98 _geo
= Geometry::create();
100 PrimeMaterial
*mat
= getDefaultMaterial();
102 _geo
->setMaterial(mat
);
109 GeoVectorProperty
*GeoBuilder::getProperty(UInt32 propIndex
)
111 GeoVectorPropertyUnrecPtr att
;
113 if(propIndex
>= _geo
->getMFProperties()->size() ||
114 _geo
->getProperty(propIndex
) == NULL
)
116 att
= dynamic_pointer_cast
<GeoVectorProperty
>(
117 FieldContainerFactory::the()->createContainer(
118 _defaultPropTypes
[propIndex
]));
120 _geo
->setProperty(att
, propIndex
);
124 att
= _geo
->getProperty(propIndex
);
130 // Finish the vertex. Make sure all Properties have the same number of
131 // attributes and adjust the index, if necessary
132 UInt32
GeoBuilder::finishVertex(void)
134 UInt32 possize
= _geo
->getProperty(Geometry::PositionsIndex
)->size32();
136 for(UInt16 i
= 1; i
< _geo
->getMFProperties()->size(); ++i
)
138 if(_geo
->getProperty(i
) != NULL
)
140 GeoVectorProperty::MaxTypeT val
;
142 _geo
->getProperty(i
)->getValue(val
,
143 _geo
->getProperty(i
)->size() - 1);
145 for(UInt32 propsize
= _geo
->getProperty(i
)->size32();
149 _geo
->getProperty(i
)->addValue(val
);
154 // Are we in a begin/end loop? Then add current vertex to index
163 void GeoBuilder::addType(Int32 type
)
165 if(_geo
->getTypes() == NULL
)
167 GeoIntegralPropertyUnrecPtr t
= GeoUInt8Property::create();
171 _geo
->getTypes()->addValue(type
);
174 void GeoBuilder::addLength(UInt32 length
)
176 if(_geo
->getLengths() == NULL
)
178 GeoIntegralPropertyUnrecPtr l
= GeoUInt32Property::create();
181 _geo
->getLengths()->addValue(length
);
184 void GeoBuilder::index(UInt32 newIndex
)
188 FWARNING(("GeoBuilder::index: called outside begin/end block!\n"));
192 if(_geo
->getIndices() == NULL
)
194 GeoIntegralPropertyUnrecPtr i
= GeoUInt32Property::create();
198 _geo
->getIndices()->push_back(newIndex
);
204 void GeoBuilder::begin(UInt32 type
)
212 void GeoBuilder::end(void)
220 void GeoBuilder::line(UInt32 start
)
232 void GeoBuilder::line(UInt32 i1
, UInt32 i2
)
244 void GeoBuilder::tri(UInt32 start
)
257 void GeoBuilder::tri(UInt32 i1
, UInt32 i2
, UInt32 i3
)
270 void GeoBuilder::quad(UInt32 start
)
284 void GeoBuilder::quad(UInt32 i1
, UInt32 i2
, UInt32 i3
, UInt32 i4
)
299 Geometry
*GeoBuilder::getGeometry(void)