00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include "OSGConfig.h"
00047 #include <OSGGL.h>
00048
00049 #include <OSGAction.h>
00050 #include <OSGDrawAction.h>
00051 #include <OSGRenderAction.h>
00052 #include <OSGIntersectAction.h>
00053 #include <OSGRenderAction.h>
00054 #include <OSGMaterial.h>
00055 #include <OSGChunkMaterial.h>
00056 #include <OSGSimpleMaterial.h>
00057 #include <OSGSimpleTexturedMaterial.h>
00058 #include "OSGDrawable.h"
00059 #include "OSGGeometry.h"
00060 #include "OSGGeoFunctions.h"
00061 #include "OSGGeoPumpFactory.h"
00062
00063 #include <OSGIntersectActor.h>
00064
00065 #include "OSGPrimitiveIterator.h"
00066 #include "OSGTriangleIterator.h"
00067 #include "OSGFaceIterator.h"
00068 #include "OSGLineIterator.h"
00069 #include "OSGEdgeIterator.h"
00070
00071 #include "OSGGeoPropPtrs.h"
00072 OSG_USING_NAMESPACE
00073
00074
00075
00076
00077
00078
00087
00088
00089
00090
00091 const UInt16 Geometry::MapPosition = 1;
00092 const UInt16 Geometry::MapNormal = Geometry::MapPosition << 1;
00093 const UInt16 Geometry::MapColor = Geometry::MapNormal << 1;
00094 const UInt16 Geometry::MapSecondaryColor = Geometry::MapColor << 1;
00095 const UInt16 Geometry::MapTexCoords = Geometry::MapSecondaryColor << 1;
00096 const UInt16 Geometry::MapTexCoords1 = Geometry::MapTexCoords << 1;
00097 const UInt16 Geometry::MapTexCoords2 = Geometry::MapTexCoords1 << 1;
00098 const UInt16 Geometry::MapTexCoords3 = Geometry::MapTexCoords2 << 1;
00099 const UInt16 Geometry::MapTexCoords4 = Geometry::MapTexCoords3 << 1;
00100 const UInt16 Geometry::MapTexCoords5 = Geometry::MapTexCoords4 << 1;
00101 const UInt16 Geometry::MapTexCoords6 = Geometry::MapTexCoords5 << 1;
00102 const UInt16 Geometry::MapTexCoords7 = Geometry::MapTexCoords6 << 1;
00103 const UInt16 Geometry::MapEmpty = Geometry::MapTexCoords7 << 1;
00104
00105 std::vector<GeoVBO *> Geometry::_vbos;
00106
00107
00108
00109
00110
00111
00112
00113
00114
00117 const char *Geometry::mapType(UInt8 type)
00118 {
00119 switch(type)
00120 {
00121 case GL_POINTS: return "Points";
00122 case GL_LINES: return "Lines";
00123 case GL_LINE_LOOP: return "LineLoop";
00124 case GL_LINE_STRIP: return "LineStrip";
00125 case GL_TRIANGLES: return "Triangles";
00126 case GL_TRIANGLE_STRIP: return "TriangleStrip";
00127 case GL_TRIANGLE_FAN: return "TriangleFan";
00128 case GL_QUADS: return "Quads";
00129 case GL_QUAD_STRIP: return "QuadStrip";
00130 case GL_POLYGON: return "Polygon";
00131 }
00132
00133 return "Unknown Primitive";
00134 }
00135
00136
00137
00138
00139
00140 void Geometry::initMethod(void)
00141 {
00142 DrawAction::registerEnterDefault(getClassType(),
00143 osgTypedMethodFunctor2BaseCPtrRef<Action::ResultE, MaterialDrawablePtr,
00144 CNodePtr, Action *>(&MaterialDrawable::drawActionHandler));
00145
00146 IntersectAction::registerEnterDefault(getClassType(),
00147 osgTypedMethodFunctor2BaseCPtrRef<Action::ResultE, GeometryPtr,
00148 CNodePtr, Action *>(&Geometry::intersect));
00149
00150 IntersectActor::regClassEnter(
00151 osgTypedMethodFunctor2BaseCPtr<
00152 NewActionTypes::ResultE,
00153 GeometryPtr,
00154 NodeCorePtr,
00155 ActorBase::FunctorArgumentType &>(&Geometry::intersectActor),
00156 getClassType());
00157
00158 RenderAction::registerEnterDefault(getClassType(),
00159 osgTypedMethodFunctor2BaseCPtrRef<Action::ResultE, MaterialDrawablePtr,
00160 CNodePtr, Action *>(&MaterialDrawable::renderActionHandler));
00161 }
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 Geometry::Geometry(void) :
00176 Inherited(),
00177 _numBytesOnGfxCard(0)
00178 {
00179 }
00180
00181 Geometry::Geometry(const Geometry &source) :
00182 Inherited(source),
00183 _numBytesOnGfxCard(source._numBytesOnGfxCard)
00184 {
00185 }
00186
00190 Geometry::~Geometry(void)
00191 {
00192 }
00193
00194 void Geometry::onCreate(const Geometry *)
00195 {
00196
00197 if(GlobalSystemState == Startup)
00198 return;
00199
00200
00201
00202
00203
00204 if(Thread::getAspect() != _sfIgnoreGLForAspect.getValue())
00205 {
00206 GeometryPtr tmpPtr(*this);
00207
00208 beginEditCP(tmpPtr, Geometry::GLIdFieldMask);
00209
00210 setGLId(
00211 Window::registerGLObject(
00212 osgTypedMethodVoidFunctor2ObjCPtrPtr<GeometryPtr,
00213 Window ,
00214 UInt32>(tmpPtr,
00215 &Geometry::handleGL),
00216 2));
00217
00218 endEditCP(tmpPtr, Geometry::GLIdFieldMask);
00219 }
00220 }
00221
00222 void Geometry::onDestroy(void)
00223 {
00224 Inherited::onDestroy();
00225
00226 GeometryPtr thisP = getPtr();
00227
00228 if(_sfTypes.getValue() != NullFC)
00229 {
00230 beginEditCP(_sfTypes.getValue(), Attachment::ParentsFieldMask);
00231 {
00232 _sfTypes.getValue()->subParent(thisP);
00233 }
00234 endEditCP(_sfTypes.getValue(), Attachment::ParentsFieldMask);
00235
00236 subRefCP(_sfTypes.getValue());
00237 }
00238
00239 if(_sfLengths.getValue() != NullFC)
00240 {
00241 beginEditCP(_sfLengths.getValue(), Attachment::ParentsFieldMask);
00242 {
00243 _sfLengths.getValue()->subParent(thisP);
00244 }
00245 endEditCP(_sfLengths.getValue(), Attachment::ParentsFieldMask);
00246
00247 subRefCP(_sfLengths.getValue());
00248 }
00249
00250 if(_sfPositions.getValue() != NullFC)
00251 {
00252 beginEditCP(_sfPositions.getValue(), Attachment::ParentsFieldMask);
00253 {
00254 _sfPositions.getValue()->subParent(thisP);
00255 }
00256 endEditCP(_sfPositions.getValue(), Attachment::ParentsFieldMask);
00257
00258 subRefCP(_sfPositions.getValue());
00259 }
00260
00261 if(_sfNormals.getValue() != NullFC)
00262 {
00263 beginEditCP(_sfNormals.getValue(), Attachment::ParentsFieldMask);
00264 {
00265 _sfNormals.getValue()->subParent(thisP);
00266 }
00267 endEditCP(_sfNormals.getValue(), Attachment::ParentsFieldMask);
00268
00269 subRefCP(_sfNormals.getValue());
00270 }
00271
00272 if(_sfColors.getValue() != NullFC)
00273 {
00274 beginEditCP(_sfColors.getValue(), Attachment::ParentsFieldMask);
00275 {
00276 _sfColors.getValue()->subParent(thisP);
00277 }
00278 endEditCP(_sfColors.getValue(), Attachment::ParentsFieldMask);
00279
00280 subRefCP(_sfColors.getValue());
00281 }
00282
00283 if(_sfSecondaryColors.getValue() != NullFC)
00284 {
00285 beginEditCP(_sfSecondaryColors.getValue(),
00286 Attachment::ParentsFieldMask);
00287 {
00288 _sfSecondaryColors.getValue()->subParent(thisP);
00289 }
00290 endEditCP(_sfSecondaryColors.getValue(),
00291 Attachment::ParentsFieldMask);
00292
00293 subRefCP(_sfSecondaryColors.getValue());
00294 }
00295
00296 if(_sfTexCoords.getValue() != NullFC)
00297 {
00298 beginEditCP(_sfTexCoords.getValue(), Attachment::ParentsFieldMask);
00299 {
00300 _sfTexCoords.getValue()->subParent(thisP);
00301 }
00302 endEditCP(_sfTexCoords.getValue(), Attachment::ParentsFieldMask);
00303
00304 subRefCP(_sfTexCoords.getValue());
00305 }
00306
00307 if(_sfTexCoords1.getValue() != NullFC)
00308 {
00309 beginEditCP(_sfTexCoords1.getValue(), Attachment::ParentsFieldMask);
00310 {
00311 _sfTexCoords1.getValue()->subParent(thisP);
00312 }
00313 endEditCP(_sfTexCoords1.getValue(), Attachment::ParentsFieldMask);
00314
00315 subRefCP(_sfTexCoords1.getValue());
00316 }
00317
00318 if(_sfTexCoords2.getValue() != NullFC)
00319 {
00320 beginEditCP(_sfTexCoords2.getValue(), Attachment::ParentsFieldMask);
00321 {
00322 _sfTexCoords2.getValue()->subParent(thisP);
00323 }
00324 endEditCP(_sfTexCoords2.getValue(), Attachment::ParentsFieldMask);
00325
00326 subRefCP(_sfTexCoords2.getValue());
00327 }
00328
00329 if(_sfTexCoords3.getValue() != NullFC)
00330 {
00331 beginEditCP(_sfTexCoords3.getValue(), Attachment::ParentsFieldMask);
00332 {
00333 _sfTexCoords3.getValue()->subParent(thisP);
00334 }
00335 endEditCP(_sfTexCoords3.getValue(), Attachment::ParentsFieldMask);
00336
00337 subRefCP(_sfTexCoords3.getValue());
00338 }
00339
00340 if(_sfTexCoords4.getValue() != NullFC)
00341 {
00342 beginEditCP(_sfTexCoords4.getValue(), Attachment::ParentsFieldMask);
00343 {
00344 _sfTexCoords4.getValue()->subParent(thisP);
00345 }
00346 endEditCP(_sfTexCoords4.getValue(), Attachment::ParentsFieldMask);
00347
00348 subRefCP(_sfTexCoords4.getValue());
00349 }
00350
00351 if(_sfTexCoords5.getValue() != NullFC)
00352 {
00353 beginEditCP(_sfTexCoords5.getValue(), Attachment::ParentsFieldMask);
00354 {
00355 _sfTexCoords5.getValue()->subParent(thisP);
00356 }
00357 endEditCP(_sfTexCoords5.getValue(), Attachment::ParentsFieldMask);
00358
00359 subRefCP(_sfTexCoords5.getValue());
00360 }
00361
00362 if(_sfTexCoords6.getValue() != NullFC)
00363 {
00364 beginEditCP(_sfTexCoords6.getValue(), Attachment::ParentsFieldMask);
00365 {
00366 _sfTexCoords6.getValue()->subParent(thisP);
00367 }
00368 endEditCP(_sfTexCoords6.getValue(), Attachment::ParentsFieldMask);
00369
00370 subRefCP(_sfTexCoords6.getValue());
00371 }
00372
00373 if(_sfTexCoords7.getValue() != NullFC)
00374 {
00375 beginEditCP(_sfTexCoords7.getValue(), Attachment::ParentsFieldMask);
00376 {
00377 _sfTexCoords7.getValue()->subParent(thisP);
00378 }
00379 endEditCP(_sfTexCoords7.getValue(), Attachment::ParentsFieldMask);
00380
00381 subRefCP(_sfTexCoords7.getValue());
00382 }
00383
00384 if(_sfIndices.getValue() != NullFC)
00385 {
00386 beginEditCP(_sfIndices.getValue(), Attachment::ParentsFieldMask);
00387 {
00388 _sfIndices.getValue()->subParent(thisP);
00389 }
00390 endEditCP(_sfIndices.getValue(), Attachment::ParentsFieldMask);
00391
00392 subRefCP(_sfIndices.getValue());
00393 }
00394
00395 subRefCP(_sfMaterial.getValue());
00396
00397 if(getGLId() > 0)
00398 {
00399 Window::destroyGLObject(getGLId(), 2);
00400 }
00401 }
00402
00403
00404
00405 void Geometry::adjustVolume(Volume & volume)
00406 {
00407 GeoPositionsPtr pos = getPositions();
00408
00409 volume.setValid();
00410 volume.setEmpty();
00411
00412 if(pos == NullFC)
00413 return;
00414
00415 PrimitiveIterator it;
00416
00417 for(it = this->beginPrimitives(); it != this->endPrimitives(); ++it)
00418 {
00419 for(UInt32 v=0; v < it.getLength(); ++v)
00420 {
00421 volume.extendBy(it.getPosition(v));
00422 }
00423 }
00424 }
00425
00426
00427
00428 GeometryPtr Geometry::getPtr(void) const
00429 {
00430 return GeometryPtr(*this);
00431 }
00432
00433
00436 void Geometry::handleGL(Window* win, UInt32 idstatus)
00437 {
00438 Window::GLObjectStatusE mode;
00439 UInt32 id;
00440 UInt32 glid = 0;
00441
00442 Window::unpackIdStatus(idstatus, id, mode);
00443
00444 if(mode == Window::initialize || mode == Window::needrefresh ||
00445 mode == Window::reinitialize)
00446 {
00447 _numBytesOnGfxCard = getCachedGfxMemoryUsage();
00448
00449 GeoPumpFactory::Index ind = GeoPumpFactory::the()->getIndex(this);
00450
00451 bool vbo_supported = getVbo() && (ind == 129) && win->hasExtension(GeoPumpFactory::_arbVBO);
00452 bool created_vbo = false;
00453 if(mode == Window::initialize)
00454 {
00455 if(vbo_supported)
00456 {
00457
00458 win->setGLObjectId(id, 0);
00459
00460 createVBO(win, id);
00461 created_vbo = true;
00462 }
00463 else
00464 {
00465
00466 glid = glGenLists(1);
00467 win->setGLObjectId(id, glid);
00468
00469 win->setGLObjectId(id + 1, 0);
00470 }
00471 }
00472
00473 glid = win->getGLObjectId(id);
00474
00475 if(!vbo_supported)
00476 {
00477
00478
00479 destroyVBO(win, id);
00480
00481 if(glid == 0)
00482 {
00483
00484
00485 glid = glGenLists(1);
00486 win->setGLObjectId(id, glid);
00487 }
00488
00489 glNewList(glid, GL_COMPILE);
00490
00491 GeoPumpFactory::GeoPump p =
00492 GeoPumpFactory::the()->getGeoPump(win, ind);
00493
00494
00495
00496 if(p)
00497 p(win, this);
00498 else
00499 {
00500 SWARNING << "Geometry::handleGL: no Pump found for geometry "
00501 << this
00502 << std::endl;
00503 }
00504
00505 glEndList();
00506
00507 if(glGetError() == GL_OUT_OF_MEMORY)
00508 {
00509 SFATAL << "Geometry::handleGL: couldn't create display list (out of memory) skipping geometry "
00510 << this
00511 << std::endl;
00512
00513
00514 glDeleteLists(glid, 1);
00515 win->setGLObjectId(id, 0);
00516 }
00517 }
00518 else
00519 {
00520
00521
00522 if(glid != 0)
00523 {
00524 glDeleteLists(glid, 1);
00525
00526 win->setGLObjectId(id, 0);
00527 }
00528 if(!created_vbo)
00529 {
00530 updateVBO(win, id);
00531 }
00532 }
00533 }
00534 else if(mode == Window::destroy)
00535 {
00536
00537 destroyVBO(win, id);
00538
00539 glid = win->getGLObjectId(id);
00540 if(glid != 0)
00541 {
00542 glDeleteLists(glid, 1);
00543
00544 win->setGLObjectId(id, 0);
00545 }
00546 }
00547 else if(mode == Window::finaldestroy)
00548 {
00549
00550 }
00551 else
00552 {
00553 SWARNING << "Geometry(" << this << "::handleGL: Illegal mode: "
00554 << mode << " for id " << id << std::endl;
00555 }
00556
00557 }
00558
00559
00560
00561 void Geometry::dump( UInt32 uiIndent,
00562 const BitVector bvFlags) const
00563 {
00564 UInt32 i;
00565
00566 GeometryPtr thisP = getPtr();
00567
00568 indentLog(uiIndent, PLOG);
00569
00570 PLOG << "GeoCore"
00571 << "("
00572 << thisP.getFieldContainerId()
00573 << ") : "
00574 << getType().getName()
00575 << " "
00576 << _attachmentMap.getValue().size()
00577 << " attachments | "
00578 << this
00579 << std::endl;
00580
00581 indentLog(uiIndent, PLOG);
00582 PLOG << "[" << std::endl;
00583
00584 indentLog(uiIndent + 4, PLOG);
00585 PLOG << "Parents : " << std::endl;
00586
00587 for(i = 0; i < _parents.size(); i++)
00588 {
00589 indentLog(uiIndent + 4, PLOG);
00590 PLOG << " " << i << ") " << &(*(_parents[i])) << std::endl;
00591 }
00592
00593 indentLog(uiIndent, PLOG);
00594 PLOG << "]" << std::endl;
00595
00596 indentLog(uiIndent, PLOG);
00597 PLOG << "{" << std::endl;
00598
00599 uiIndent += 4;
00600
00601 if(getPositions() != NullFC)
00602 {
00603 getPositions()->dump(uiIndent, bvFlags);
00604 }
00605
00606 if(getIndices() != NullFC)
00607 {
00608 getIndices()->dump(uiIndent, bvFlags);
00609 }
00610
00611 if(getMaterial() != NullFC)
00612 {
00613 getMaterial()->dump(uiIndent, bvFlags);
00614 }
00615
00616 if(getTypes() != NullFC)
00617 {
00618 getTypes()->dump(uiIndent, bvFlags);
00619 }
00620
00621 if(getLengths() != NullFC)
00622 {
00623 getLengths()->dump(uiIndent, bvFlags);
00624 }
00625
00626 if(getNormals() != NullFC)
00627 {
00628 getNormals()->dump(uiIndent, bvFlags);
00629 }
00630
00631 if(getColors() != NullFC)
00632 {
00633 getColors()->dump(uiIndent, bvFlags);
00634 }
00635
00636 if(getTexCoords() != NullFC)
00637 {
00638 getTexCoords()->dump(uiIndent, bvFlags);
00639 }
00640
00641 if(getTexCoords1() != NullFC)
00642 {
00643 getTexCoords1()->dump(uiIndent, bvFlags);
00644 }
00645
00646 if(getTexCoords2() != NullFC)
00647 {
00648 getTexCoords2()->dump(uiIndent, bvFlags);
00649 }
00650
00651 if(getTexCoords3() != NullFC)
00652 {
00653 getTexCoords3()->dump(uiIndent, bvFlags);
00654 }
00655
00656 if(getTexCoords4() != NullFC)
00657 {
00658 getTexCoords4()->dump(uiIndent, bvFlags);
00659 }
00660
00661 if(getTexCoords5() != NullFC)
00662 {
00663 getTexCoords5()->dump(uiIndent, bvFlags);
00664 }
00665
00666 if(getTexCoords6() != NullFC)
00667 {
00668 getTexCoords6()->dump(uiIndent, bvFlags);
00669 }
00670
00671 if(getTexCoords7() != NullFC)
00672 {
00673 getTexCoords7()->dump(uiIndent, bvFlags);
00674 }
00675
00676 uiIndent -= 4;
00677
00678 AttachmentContainer::dump(uiIndent, bvFlags);
00679
00680 indentLog(uiIndent, PLOG);
00681 PLOG << "}" << std::endl;
00682 }
00683
00684 #ifndef OSG_SUPPORT_NO_GEO_INTERFACE
00685
00689 GeoPropertyArrayInterface *Geometry::getProperty(Int32 mapID)
00690 {
00691 GeoPropertyArrayInterface *pP = 0;
00692
00693 switch(mapID)
00694 {
00695 case 0:
00696 pP = 0;
00697 break;
00698 case MapPosition:
00699 pP =(getPositions() == NullFC) ? 0 : &(*getPositions());
00700 break;
00701 case MapNormal:
00702 pP =(getNormals() == NullFC) ? 0 : &(*getNormals());
00703 break;
00704 case MapColor:
00705 pP =(getColors() == NullFC) ? 0 : &(*getColors());
00706 break;
00707 case MapSecondaryColor:
00708 pP =(getSecondaryColors() == NullFC) ? 0 : &(*getSecondaryColors());
00709 break;
00710 case MapTexCoords:
00711 pP =(getTexCoords() == NullFC) ? 0 : &(*getTexCoords());
00712 break;
00713 case MapTexCoords1:
00714 pP =(getTexCoords1() == NullFC) ? 0 : &(*getTexCoords1());
00715 break;
00716 case MapTexCoords2:
00717 pP =(getTexCoords2() == NullFC) ? 0 : &(*getTexCoords2());
00718 break;
00719 case MapTexCoords3:
00720 pP =(getTexCoords3() == NullFC) ? 0 : &(*getTexCoords3());
00721 break;
00722 case MapTexCoords4:
00723 pP =(getTexCoords4() == NullFC) ? 0 : &(*getTexCoords4());
00724 break;
00725 case MapTexCoords5:
00726 pP =(getTexCoords5() == NullFC) ? 0 : &(*getTexCoords5());
00727 break;
00728 case MapTexCoords6:
00729 pP =(getTexCoords6() == NullFC) ? 0 : &(*getTexCoords6());
00730 break;
00731 case MapTexCoords7:
00732 pP =(getTexCoords7() == NullFC) ? 0 : &(*getTexCoords7());
00733 break;
00734 default:
00735 FFATAL(("Invalid mapID(%d) in Geometry::getProperty()\n",
00736 mapID));
00737 break;
00738 }
00739
00740 return pP;
00741 }
00742
00743 #endif
00744
00751 Int16 Geometry::calcMappingIndex(UInt16 attrib) const
00752 {
00753 UInt16 nmappings = getIndexMapping().size();
00754 Int16 i;
00755
00756 for(i = nmappings - 1; i >= 0; i--)
00757 {
00758 if(getIndexMapping()[i] & attrib )
00759 break;
00760 }
00761
00762 return i;
00763 }
00764
00765
00766
00771 bool Geometry::isMergeable( const GeometryPtr other )
00772 {
00773 if (MergeIndex(other)!=-1 || getPositions()==NullFC) return true;
00774 else return false;
00775 }
00776
00779 bool Geometry::merge( const GeometryPtr other )
00780 {
00781 if (other == NullFC)
00782 {
00783 FDEBUG(("Geometry::merge: other = NullFC!!!\n"));
00784 return false;
00785 }
00786
00787
00788 if (getPositions()==NullFC)
00789 {
00790 if (other->getPositions()!=NullFC)
00791 setPositions(other->getPositions()->clone());
00792
00793 if (other->getTypes()!=NullFC)
00794 setTypes(other->getTypes()->clone());
00795
00796 if (other->getLengths()!=NullFC)
00797 setLengths(other->getLengths()->clone());
00798
00799 if (other->getNormals()!=NullFC)
00800 setNormals(other->getNormals()->clone());
00801
00802 if (other->getColors()!=NullFC)
00803 setColors(other->getColors()->clone());
00804
00805 if (other->getSecondaryColors()!=NullFC)
00806 setSecondaryColors(other->getSecondaryColors()->clone());
00807
00808 if (other->getTexCoords()!=NullFC)
00809 setTexCoords(other->getTexCoords()->clone());
00810
00811 if (other->getTexCoords1()!=NullFC)
00812 setTexCoords1(other->getTexCoords1()->clone());
00813
00814 if (other->getTexCoords2()!=NullFC)
00815 setTexCoords2(other->getTexCoords2()->clone());
00816
00817 if (other->getTexCoords3()!=NullFC)
00818 setTexCoords3(other->getTexCoords3()->clone());
00819
00820 if (other->getTexCoords4()!=NullFC)
00821 setTexCoords4(other->getTexCoords4()->clone());
00822
00823 if (other->getTexCoords5()!=NullFC)
00824 setTexCoords5(other->getTexCoords5()->clone());
00825
00826 if (other->getTexCoords6()!=NullFC)
00827 setTexCoords6(other->getTexCoords6()->clone());
00828
00829 if (other->getTexCoords7()!=NullFC)
00830 setTexCoords7(other->getTexCoords7()->clone());
00831
00832 if(other->getIndices()!=NullFC)
00833 setIndices(other->getIndices()->clone());
00834
00835 if(other->getMFIndexMapping()!=NULL)
00836 getMFIndexMapping()->setValues(*(other->getMFIndexMapping()));
00837
00838 setMaterial(other->getMaterial());
00839 setDlistCache(other->getDlistCache());
00840
00841 return true;
00842 }
00843
00844
00845
00846 Int16 mergetype = MergeIndex( other );
00847
00848 if(mergetype >= 0 && mergetype <= 6)
00849 {
00850
00851 if(GeoIndicesUI16Ptr::dcast(getIndices()) != NullFC)
00852 {
00853 GeoIndicesPtr indices = getIndices();
00854 UInt32 indices_size = indices->getSize();
00855 GeoIndicesUI32Ptr indicesUI32 = GeoIndicesUI32::create();
00856 MFUInt32 &dst = indicesUI32->getField();
00857 dst.reserve(indices_size);
00858 beginEditCP(indicesUI32);
00859 for (UInt32 i = 0; i < indices_size; ++i)
00860 dst.push_back(indices->getValue(i));
00861 endEditCP(indicesUI32);
00862
00863 beginEditCP((GeometryPtr)this, Geometry::IndicesFieldMask);
00864 setIndices(indicesUI32);
00865 endEditCP((GeometryPtr)this, Geometry::IndicesFieldMask);
00866 }
00867 }
00868
00869 switch ( mergetype )
00870 {
00871 case 0: merge0( other ); break;
00872 case 1: merge1( other ); break;
00873 case 2: merge2( other ); break;
00874 case 3: merge3( other ); break;
00875 case 4: merge4( other ); break;
00876 case 5: merge5( other ); break;
00877 case 6: merge6( other ); break;
00878 default: return false;
00879 }
00880 return true;
00881 }
00882
00883
00884
00885
00886
00887 Action::ResultE Geometry::drawPrimitives(DrawActionBase * action)
00888 {
00889
00890 Color4f color;
00891 if(getColors() != NullFC)
00892 glPushAttrib(GL_CURRENT_BIT);
00893
00894 bool vbo_supported = false;
00895 if(getVbo())
00896 {
00897 vbo_supported = drawVBO(action->getWindow(), getGLId());
00898 }
00899
00900 if(!vbo_supported)
00901 {
00902 if(getDlistCache() == true)
00903 {
00904 action->getWindow()->validateGLObject(getGLId());
00905 UInt32 glid = action->getWindow()->getGLObjectId(getGLId());
00906 if(glid != 0)
00907 glCallList(glid);
00908 }
00909 else
00910 {
00911 GeoPumpFactory::Index ind = GeoPumpFactory::the()->getIndex(this);
00912 GeoPumpFactory::GeoPump p =
00913 GeoPumpFactory::the()->getGeoPump(action->getWindow(), ind);
00914
00915
00916
00917 if(p)
00918 p(action->getWindow(), this);
00919 else
00920 {
00921 SWARNING << "draw: no Pump found for geometry "
00922 << this
00923 << std::endl;
00924 }
00925 }
00926 }
00927
00928
00929 if(getColors() != NullFC)
00930 glPopAttrib();
00931
00932 StatCollector *coll = action->getStatistics();
00933
00934 if(coll != NULL)
00935 {
00936 StatIntElem *el = coll->getElem(Drawable::statNTriangles,false);
00937 if(el)
00938 {
00939 GeometryPtr geo(this);
00940 UInt32 ntri,nl,np,is;
00941
00942 calcPrimitiveCount(geo, ntri, nl, np);
00943 el->add(ntri);
00944 coll->getElem(Drawable::statNLines)->add(nl);
00945 coll->getElem(Drawable::statNLines)->add(np);
00946
00947 if(getIndices() == NullFC)
00948 {
00949 if(getPositions() != NullFC)
00950 {
00951 is = getPositions()->getSize();
00952 }
00953 else
00954 {
00955 is = 0;
00956 }
00957 }
00958 else
00959 {
00960 is = getIndexMapping().size();
00961 is = getIndices()->getSize() /(is ? is : 1);
00962 }
00963 coll->getElem(Drawable::statNVertices)->add(is);
00964
00965 UInt32 primitiveCount = 0;
00966 if (getTypes() != NullFC) {
00967 primitiveCount = getTypes()->getSize();
00968 }
00969 coll->getElem(Drawable::statNPrimitives)->add(primitiveCount);
00970 }
00971
00972
00973
00974 if (vbo_supported || getDlistCache())
00975 {
00976 StatIntOnceElem *el = coll->getElem(Drawable::statNGeoBytes, false);
00977 if (el)
00978 coll->getElem(Drawable::statNGeoBytes)->add(getGLId(), _numBytesOnGfxCard);
00979 }
00980 }
00981
00982 return Action::Continue;
00983 }
00984
00985 UInt32 Geometry::getCachedGfxMemoryUsage(void)
00986 {
00987 int nBytes = 0;
00988
00989
00990 if (getLengths() != NullFC)
00991 {
00992 if (GeoPLengthsUI32Ptr::dcast(getLengths()) != NullFC)
00993 nBytes += getLengths()->getSize()*4;
00994 else
00995 nBytes += getLengths()->getSize()*2;
00996 }
00997
00998
00999 if (getIndices() != NullFC)
01000 {
01001 if (GeoIndicesUI32Ptr::dcast(getIndices()) != NullFC)
01002 nBytes += getIndices()->getSize()*4;
01003 else
01004 nBytes += getIndices()->getSize()*2;
01005 }
01006
01007
01008 if (getPositions() != NullFC)
01009 nBytes += getPositions()->getSize()*12;
01010
01011
01012 if (getNormals() != NullFC)
01013 {
01014 if (GeoNormals3fPtr::dcast(getNormals()) != NullFC)
01015 nBytes += getNormals()->getSize()*12;
01016 else
01017 nBytes += getNormals()->getSize()*3;
01018 }
01019
01020
01021 if (getColors() != NullFC)
01022 nBytes += getColors()->getSize()*16;
01023
01024
01025 if (getSecondaryColors() != NullFC)
01026 nBytes += getSecondaryColors()->getSize()*16;
01027
01028
01029 if (getTexCoords() != NullFC)
01030 {
01031 if (GeoTexCoords4fPtr::dcast(getTexCoords()) != NullFC)
01032 nBytes += getTexCoords()->getSize()*16;
01033 else if (GeoTexCoords3fPtr::dcast(getTexCoords()) != NullFC)
01034 nBytes += getTexCoords()->getSize()*12;
01035 else if (GeoTexCoords2fPtr::dcast(getTexCoords()) != NullFC)
01036 nBytes += getTexCoords()->getSize()*8;
01037 }
01038
01039
01040 if (getTexCoords1() != NullFC)
01041 {
01042 if (GeoTexCoords4fPtr::dcast(getTexCoords1()) != NullFC)
01043 nBytes += getTexCoords1()->getSize()*16;
01044 else if (GeoTexCoords3fPtr::dcast(getTexCoords1()) != NullFC)
01045 nBytes += getTexCoords1()->getSize()*12;
01046 else if (GeoTexCoords2fPtr::dcast(getTexCoords1()) != NullFC)
01047 nBytes += getTexCoords1()->getSize()*8;
01048 }
01049
01050
01051 if (getTexCoords2() != NullFC)
01052 {
01053 if (GeoTexCoords4fPtr::dcast(getTexCoords2()) != NullFC)
01054 nBytes += getTexCoords2()->getSize()*16;
01055 else if (GeoTexCoords3fPtr::dcast(getTexCoords2()) != NullFC)
01056 nBytes += getTexCoords2()->getSize()*12;
01057 else if (GeoTexCoords2fPtr::dcast(getTexCoords2()) != NullFC)
01058 nBytes += getTexCoords2()->getSize()*8;
01059 }
01060
01061
01062 if (getTexCoords3() != NullFC)
01063 {
01064 if (GeoTexCoords4fPtr::dcast(getTexCoords3()) != NullFC)
01065 nBytes += getTexCoords3()->getSize()*16;
01066 else if (GeoTexCoords3fPtr::dcast(getTexCoords3()) != NullFC)
01067 nBytes += getTexCoords3()->getSize()*12;
01068 else if (GeoTexCoords2fPtr::dcast(getTexCoords3()) != NullFC)
01069 nBytes += getTexCoords3()->getSize()*8;
01070 }
01071
01072
01073 if (getTexCoords4() != NullFC)
01074 {
01075 if (GeoTexCoords4fPtr::dcast(getTexCoords4()) != NullFC)
01076 nBytes += getTexCoords4()->getSize()*16;
01077 else if (GeoTexCoords3fPtr::dcast(getTexCoords4()) != NullFC)
01078 nBytes += getTexCoords4()->getSize()*12;
01079 else if (GeoTexCoords2fPtr::dcast(getTexCoords4()) != NullFC)
01080 nBytes += getTexCoords4()->getSize()*8;
01081 }
01082
01083
01084 if (getTexCoords5() != NullFC)
01085 {
01086 if (GeoTexCoords4fPtr::dcast(getTexCoords5()) != NullFC)
01087 nBytes += getTexCoords5()->getSize()*16;
01088 else if (GeoTexCoords3fPtr::dcast(getTexCoords5()) != NullFC)
01089 nBytes += getTexCoords5()->getSize()*12;
01090 else if (GeoTexCoords2fPtr::dcast(getTexCoords5()) != NullFC)
01091 nBytes += getTexCoords5()->getSize()*8;
01092 }
01093
01094
01095 if (getTexCoords6() != NullFC)
01096 {
01097 if (GeoTexCoords4fPtr::dcast(getTexCoords6()) != NullFC)
01098 nBytes += getTexCoords6()->getSize()*16;
01099 else if (GeoTexCoords3fPtr::dcast(getTexCoords6()) != NullFC)
01100 nBytes += getTexCoords6()->getSize()*12;
01101 else if (GeoTexCoords2fPtr::dcast(getTexCoords6()) != NullFC)
01102 nBytes += getTexCoords6()->getSize()*8;
01103 }
01104
01105
01106 if (getTexCoords7() != NullFC)
01107 {
01108 if (GeoTexCoords4fPtr::dcast(getTexCoords7()) != NullFC)
01109 nBytes += getTexCoords7()->getSize()*16;
01110 else if (GeoTexCoords3fPtr::dcast(getTexCoords7()) != NullFC)
01111 nBytes += getTexCoords7()->getSize()*12;
01112 else if (GeoTexCoords2fPtr::dcast(getTexCoords7()) != NullFC)
01113 nBytes += getTexCoords7()->getSize()*8;
01114 }
01115
01116 return nBytes;
01117 }
01118
01119 Action::ResultE Geometry::intersect(Action * action)
01120 {
01121 IntersectAction * ia = dynamic_cast<IntersectAction*>(action);
01122 const DynamicVolume &dv = ia->getActNode()->getVolume(true);
01123
01124 if(dv.isValid() && !dv.intersect(ia->getLine()))
01125 {
01126 return Action::Skip;
01127 }
01128
01129 TriangleIterator it = this->beginTriangles();
01130 TriangleIterator end = this->endTriangles ();
01131 Real32 t;
01132 Vec3f norm;
01133
01134 for(; it != end; ++it)
01135 {
01136 if(ia->getLine().intersect(it.getPosition(0),
01137 it.getPosition(1),
01138 it.getPosition(2), t, &norm))
01139 {
01140 ia->setHit(t, ia->getActNode(), it.getIndex(), norm);
01141 }
01142 }
01143
01144 return Action::Continue;
01145 }
01146
01147 NewActionTypes::ResultE
01148 Geometry::intersectActor(ActorBase::FunctorArgumentType &funcArg)
01149 {
01150 IntersectActor *pIA = dynamic_cast<IntersectActor *>(funcArg.getActor());
01151 Real32 scaleFactor = pIA->getScaleFactor();
01152
01153 TriangleIterator itTris = this->beginTriangles();
01154 TriangleIterator endTris = this->endTriangles ();
01155
01156 Real32 hitDist;
01157 Vec3f hitNormal;
01158
01159 for(; itTris != endTris; ++itTris)
01160 {
01161 if(pIA->getRay().intersect(itTris.getPosition(0),
01162 itTris.getPosition(1),
01163 itTris.getPosition(2),
01164 hitDist, &hitNormal) == true)
01165 {
01166 pIA->setHit(hitDist * scaleFactor, funcArg.getNode(),
01167 itTris.getIndex(), hitNormal );
01168 }
01169 }
01170
01171 pIA->setupChildrenPriorities();
01172
01173 return NewActionTypes::Continue;
01174 }
01175
01179 void Geometry::changed(BitVector whichField,
01180 UInt32 origin )
01181 {
01182 if(whichField & TypesFieldMask)
01183 {
01184 if(origin & ChangedOrigin::Abstract)
01185 {
01186 if(origin & ChangedOrigin::AbstrCheckValid)
01187 {
01188 GeometryPtr thisP = getPtr();
01189
01190 if(_sfTypes.getValue() != NullFC &&
01191 _sfTypes.getValue()->findParent(thisP) == -1 )
01192 {
01193 GeoPTypesPtr pType = _sfTypes.getValue();
01194
01195 _sfTypes.setValue(NullFC);
01196
01197 setTypes(pType);
01198 }
01199 }
01200 else if(origin & ChangedOrigin::AbstrIncRefCount)
01201 {
01202 addRefCP(_sfTypes.getValue());
01203 }
01204 else
01205 {
01206 GeoPTypesPtr pType = _sfTypes.getValue();
01207
01208 _sfTypes.setValue(NullFC);
01209
01210 setTypes(pType);
01211 }
01212 }
01213 }
01214
01215 if(whichField & LengthsFieldMask)
01216 {
01217 if(origin & ChangedOrigin::Abstract)
01218 {
01219 if(origin & ChangedOrigin::AbstrCheckValid)
01220 {
01221 GeometryPtr thisP = getPtr();
01222
01223 if(_sfLengths.getValue() != NullFC &&
01224 _sfLengths.getValue()->findParent(thisP) == -1 )
01225 {
01226 GeoPLengthsPtr pLength = _sfLengths.getValue();
01227
01228 _sfLengths.setValue(NullFC);
01229
01230 setLengths(pLength);
01231 }
01232 }
01233 else if(origin & ChangedOrigin::AbstrIncRefCount)
01234 {
01235 addRefCP(_sfLengths.getValue());
01236 }
01237 else
01238 {
01239 GeoPLengthsPtr pLength = _sfLengths.getValue();
01240
01241 _sfLengths.setValue(NullFC);
01242
01243 setLengths(pLength);
01244 }
01245 }
01246 }
01247
01248 if(whichField & PositionsFieldMask)
01249 {
01250 for(UInt32 i = 0; i < _parents.size(); i++)
01251 {
01252 _parents[i]->invalidateVolume();
01253 }
01254
01255 if(origin & ChangedOrigin::Abstract)
01256 {
01257 if(origin & ChangedOrigin::AbstrCheckValid)
01258 {
01259 GeometryPtr thisP = getPtr();
01260
01261 if(_sfPositions.getValue() != NullFC &&
01262 _sfPositions.getValue()->findParent(thisP) == -1 )
01263 {
01264 GeoPositionsPtr pPos = _sfPositions.getValue();
01265
01266 _sfPositions.setValue(NullFC);
01267
01268 setPositions(pPos);
01269 }
01270 }
01271 else if(origin & ChangedOrigin::AbstrIncRefCount)
01272 {
01273 addRefCP(_sfPositions.getValue());
01274 }
01275 else
01276 {
01277 GeoPositionsPtr pPos = _sfPositions.getValue();
01278
01279 _sfPositions.setValue(NullFC);
01280
01281 setPositions(pPos);
01282 }
01283 }
01284 else
01285 {
01286 }
01287 }
01288
01289 if(whichField & NormalsFieldMask)
01290 {
01291 if(origin & ChangedOrigin::Abstract)
01292 {
01293 if(origin & ChangedOrigin::AbstrCheckValid)
01294 {
01295 GeometryPtr thisP = getPtr();
01296
01297 if(_sfNormals.getValue() != NullFC &&
01298 _sfNormals.getValue()->findParent(thisP) == -1 )
01299 {
01300 GeoNormalsPtr pNorm = _sfNormals.getValue();
01301
01302 _sfNormals.setValue(NullFC);
01303
01304 setNormals(pNorm);
01305 }
01306 }
01307 else if(origin & ChangedOrigin::AbstrIncRefCount)
01308 {
01309 addRefCP(_sfNormals.getValue());
01310 }
01311 else
01312 {
01313 GeoNormalsPtr pNorm = _sfNormals.getValue();
01314
01315 _sfNormals.setValue(NullFC);
01316
01317 setNormals(pNorm);
01318 }
01319 }
01320 }
01321
01322 if(whichField & ColorsFieldMask)
01323 {
01324 if(origin & ChangedOrigin::Abstract)
01325 {
01326 if(origin & ChangedOrigin::AbstrCheckValid)
01327 {
01328 GeometryPtr thisP = getPtr();
01329
01330 if(_sfColors.getValue() != NullFC &&
01331 _sfColors.getValue()->findParent(thisP) == -1 )
01332 {
01333 GeoColorsPtr pColor = _sfColors.getValue();
01334
01335 _sfColors.setValue(NullFC);
01336
01337 setColors(pColor);
01338 }
01339 }
01340 else if(origin & ChangedOrigin::AbstrIncRefCount)
01341 {
01342 addRefCP(_sfColors.getValue());
01343 }
01344 else
01345 {
01346 GeoColorsPtr pColor = _sfColors.getValue();
01347
01348 _sfColors.setValue(NullFC);
01349
01350 setColors(pColor);
01351 }
01352 }
01353 }
01354
01355 if(whichField & SecondaryColorsFieldMask)
01356 {
01357 if(origin & ChangedOrigin::Abstract)
01358 {
01359 if(origin & ChangedOrigin::AbstrCheckValid)
01360 {
01361 GeometryPtr thisP = getPtr();
01362
01363 if(_sfSecondaryColors.getValue() != NullFC &&
01364 _sfSecondaryColors.getValue()->findParent(thisP)== -1 )
01365 {
01366 GeoColorsPtr pColor = _sfSecondaryColors.getValue();
01367
01368 _sfSecondaryColors.setValue(NullFC);
01369
01370 setSecondaryColors(pColor);
01371 }
01372 }
01373 else if(origin & ChangedOrigin::AbstrIncRefCount)
01374 {
01375 addRefCP(_sfSecondaryColors.getValue());
01376 }
01377 else
01378 {
01379 GeoColorsPtr pColor = _sfSecondaryColors.getValue();
01380
01381 _sfSecondaryColors.setValue(NullFC);
01382
01383 setSecondaryColors(pColor);
01384 }
01385 }
01386 }
01387
01388 if(whichField & TexCoordsFieldMask)
01389 {
01390 if(origin & ChangedOrigin::Abstract)
01391 {
01392 if(origin & ChangedOrigin::AbstrCheckValid)
01393 {
01394 GeometryPtr thisP = getPtr();
01395
01396 if(_sfTexCoords.getValue() != NullFC &&
01397 _sfTexCoords.getValue()->findParent(thisP) == -1 )
01398 {
01399 GeoTexCoordsPtr pTexCoord = _sfTexCoords.getValue();
01400
01401 _sfTexCoords.setValue(NullFC);
01402
01403 setTexCoords(pTexCoord);
01404 }
01405 }
01406 else if(origin & ChangedOrigin::AbstrIncRefCount)
01407 {
01408 addRefCP(_sfTexCoords.getValue());
01409 }
01410 else
01411 {
01412 GeoTexCoordsPtr pTexCoord = _sfTexCoords.getValue();
01413
01414 _sfTexCoords.setValue(NullFC);
01415
01416 setTexCoords(pTexCoord);
01417 }
01418 }
01419 }
01420
01421 if(whichField & TexCoords1FieldMask)
01422 {
01423 if(origin & ChangedOrigin::Abstract)
01424 {
01425 if(origin & ChangedOrigin::AbstrCheckValid)
01426 {
01427 GeometryPtr thisP = getPtr();
01428
01429 if(_sfTexCoords1.getValue() != NullFC &&
01430 _sfTexCoords1.getValue()->findParent(thisP) == -1 )
01431 {
01432 GeoTexCoordsPtr pTexCoord = _sfTexCoords1.getValue();
01433
01434 _sfTexCoords1.setValue(NullFC);
01435
01436 setTexCoords1(pTexCoord);
01437 }
01438 }
01439 else if(origin & ChangedOrigin::AbstrIncRefCount)
01440 {
01441 addRefCP(_sfTexCoords1.getValue());
01442 }
01443 else
01444 {
01445 GeoTexCoordsPtr pTexCoord = _sfTexCoords1.getValue();
01446
01447 _sfTexCoords1.setValue(NullFC);
01448
01449 setTexCoords1(pTexCoord);
01450 }
01451 }
01452 }
01453
01454 if(whichField & TexCoords2FieldMask)
01455 {
01456 if(origin & ChangedOrigin::Abstract)
01457 {
01458 if(origin & ChangedOrigin::AbstrCheckValid)
01459 {
01460 GeometryPtr thisP = getPtr();
01461
01462 if(_sfTexCoords2.getValue() != NullFC &&
01463 _sfTexCoords2.getValue()->findParent(thisP) == -1 )
01464 {
01465 GeoTexCoordsPtr pTexCoord = _sfTexCoords2.getValue();
01466
01467 _sfTexCoords2.setValue(NullFC);
01468
01469 setTexCoords2(pTexCoord);
01470 }
01471 }
01472 else if(origin & ChangedOrigin::AbstrIncRefCount)
01473 {
01474 addRefCP(_sfTexCoords2.getValue());
01475 }
01476 else
01477 {
01478 GeoTexCoordsPtr pTexCoord = _sfTexCoords2.getValue();
01479
01480 _sfTexCoords2.setValue(NullFC);
01481
01482 setTexCoords2(pTexCoord);
01483 }
01484 }
01485 }
01486
01487 if(whichField & TexCoords3FieldMask)
01488 {
01489 if(origin & ChangedOrigin::Abstract)
01490 {
01491 if(origin & ChangedOrigin::AbstrCheckValid)
01492 {
01493 GeometryPtr thisP = getPtr();
01494
01495 if(_sfTexCoords3.getValue() != NullFC &&
01496 _sfTexCoords3.getValue()->findParent(thisP) == -1 )
01497 {
01498 GeoTexCoordsPtr pTexCoord = _sfTexCoords3.getValue();
01499
01500 _sfTexCoords3.setValue(NullFC);
01501
01502 setTexCoords3(pTexCoord);
01503 }
01504 }
01505 else if(origin & ChangedOrigin::AbstrIncRefCount)
01506 {
01507 addRefCP(_sfTexCoords3.getValue());
01508 }
01509 else
01510 {
01511 GeoTexCoordsPtr pTexCoord = _sfTexCoords3.getValue();
01512
01513 _sfTexCoords3.setValue(NullFC);
01514
01515 setTexCoords3(pTexCoord);
01516 }
01517 }
01518 }
01519
01520 if(whichField & TexCoords4FieldMask)
01521 {
01522 if(origin & ChangedOrigin::Abstract)
01523 {
01524 if(origin & ChangedOrigin::AbstrCheckValid)
01525 {
01526 GeometryPtr thisP = getPtr();
01527
01528 if(_sfTexCoords4.getValue() != NullFC &&
01529 _sfTexCoords4.getValue()->findParent(thisP) == -1 )
01530 {
01531 GeoTexCoordsPtr pTexCoord = _sfTexCoords4.getValue();
01532
01533 _sfTexCoords4.setValue(NullFC);
01534
01535 setTexCoords4(pTexCoord);
01536 }
01537 }
01538 else if(origin & ChangedOrigin::AbstrIncRefCount)
01539 {
01540 addRefCP(_sfTexCoords4.getValue());
01541 }
01542 else
01543 {
01544 GeoTexCoordsPtr pTexCoord = _sfTexCoords4.getValue();
01545
01546 _sfTexCoords4.setValue(NullFC);
01547
01548 setTexCoords4(pTexCoord);
01549 }
01550 }
01551 }
01552
01553 if(whichField & TexCoords5FieldMask)
01554 {
01555 if(origin & ChangedOrigin::Abstract)
01556 {
01557 if(origin & ChangedOrigin::AbstrCheckValid)
01558 {
01559 GeometryPtr thisP = getPtr();
01560
01561 if(_sfTexCoords5.getValue() != NullFC &&
01562 _sfTexCoords5.getValue()->findParent(thisP) == -1 )
01563 {
01564 GeoTexCoordsPtr pTexCoord = _sfTexCoords5.getValue();
01565
01566 _sfTexCoords5.setValue(NullFC);
01567
01568 setTexCoords5(pTexCoord);
01569 }
01570 }
01571 else if(origin & ChangedOrigin::AbstrIncRefCount)
01572 {
01573 addRefCP(_sfTexCoords5.getValue());
01574 }
01575 else
01576 {
01577 GeoTexCoordsPtr pTexCoord = _sfTexCoords5.getValue();
01578
01579 _sfTexCoords5.setValue(NullFC);
01580
01581 setTexCoords5(pTexCoord);
01582 }
01583 }
01584 }
01585
01586 if(whichField & TexCoords6FieldMask)
01587 {
01588 if(origin & ChangedOrigin::Abstract)
01589 {
01590 if(origin & ChangedOrigin::AbstrCheckValid)
01591 {
01592 GeometryPtr thisP = getPtr();
01593
01594 if(_sfTexCoords6.getValue() != NullFC &&
01595 _sfTexCoords6.getValue()->findParent(thisP) == -1 )
01596 {
01597 GeoTexCoordsPtr pTexCoord = _sfTexCoords6.getValue();
01598
01599 _sfTexCoords6.setValue(NullFC);
01600
01601 setTexCoords6(pTexCoord);
01602 }
01603 }
01604 else if(origin & ChangedOrigin::AbstrIncRefCount)
01605 {
01606 addRefCP(_sfTexCoords6.getValue());
01607 }
01608 else
01609 {
01610 GeoTexCoordsPtr pTexCoord = _sfTexCoords6.getValue();
01611
01612 _sfTexCoords6.setValue(NullFC);
01613
01614 setTexCoords6(pTexCoord);
01615 }
01616 }
01617 }
01618
01619 if(whichField & TexCoords7FieldMask)
01620 {
01621 if(origin & ChangedOrigin::Abstract)
01622 {
01623 if(origin & ChangedOrigin::AbstrCheckValid)
01624 {
01625 GeometryPtr thisP = getPtr();
01626
01627 if(_sfTexCoords7.getValue() != NullFC &&
01628 _sfTexCoords7.getValue()->findParent(thisP) == -1 )
01629 {
01630 GeoTexCoordsPtr pTexCoord = _sfTexCoords7.getValue();
01631
01632 _sfTexCoords7.setValue(NullFC);
01633
01634 setTexCoords7(pTexCoord);
01635 }
01636 }
01637 else if(origin & ChangedOrigin::AbstrIncRefCount)
01638 {
01639 addRefCP(_sfTexCoords7.getValue());
01640 }
01641 else
01642 {
01643 GeoTexCoordsPtr pTexCoord = _sfTexCoords7.getValue();
01644
01645 _sfTexCoords7.setValue(NullFC);
01646
01647 setTexCoords7(pTexCoord);
01648 }
01649 }
01650 }
01651
01652 if(whichField & IndicesFieldMask)
01653 {
01654 if(origin & ChangedOrigin::Abstract)
01655 {
01656 if(origin & ChangedOrigin::AbstrCheckValid)
01657 {
01658 GeometryPtr thisP = getPtr();
01659
01660 if(_sfIndices.getValue() != NullFC &&
01661 _sfIndices.getValue()->findParent(thisP) == -1 )
01662 {
01663 GeoIndicesPtr pIndex = _sfIndices.getValue();
01664
01665 _sfIndices.setValue(NullFC);
01666
01667 setIndices(pIndex);
01668 }
01669 }
01670 else if(origin & ChangedOrigin::AbstrIncRefCount)
01671 {
01672 addRefCP(_sfIndices.getValue());
01673 }
01674 else
01675 {
01676 GeoIndicesPtr pIndex = _sfIndices.getValue();
01677
01678 _sfIndices.setValue(NullFC);
01679
01680 setIndices(pIndex);
01681 }
01682 }
01683 }
01684
01685 if(whichField & MaterialFieldMask)
01686 {
01687 if(origin & ChangedOrigin::Abstract)
01688 {
01689 if(origin & ChangedOrigin::AbstrIncRefCount)
01690 {
01691 addRefCP(_sfMaterial.getValue());
01692 }
01693 else
01694 {
01695 MaterialPtr pMat = _sfMaterial.getValue();
01696
01697 _sfMaterial.setValue(NullFC);
01698
01699 setMaterial(pMat);
01700 }
01701 }
01702 }
01703
01704 if(whichField & (IndicesFieldMask | LengthsFieldMask |
01705 TypesFieldMask | IndexMappingFieldMask)
01706 )
01707 {
01708 updateLowHighIndices();
01709 }
01710
01711 #if 1
01712
01713 if(Thread::getAspect() != _sfIgnoreGLForAspect.getValue())
01714 {
01715
01716 if(getDlistCache() || getVbo())
01717 {
01718 if(getGLId() == 0)
01719 {
01720 GeometryPtr tmpPtr(*this);
01721
01722 beginEditCP(tmpPtr, Geometry::GLIdFieldMask);
01723
01724 setGLId(
01725 Window::registerGLObject(
01726 osgTypedMethodVoidFunctor2ObjCPtrPtr<
01727 GeometryPtr,
01728 Window ,
01729 UInt32>(tmpPtr,
01730 &Geometry::handleGL),
01731 2));
01732
01733 endEditCP(tmpPtr, Geometry::GLIdFieldMask);
01734 }
01735
01736
01737
01738 if(whichField != MaterialFieldMask)
01739 Window::refreshGLObject(getGLId());
01740 }
01741 else
01742 {
01743 if(getGLId() != 0)
01744 Window::destroyGLObject(getGLId(), 2);
01745
01746 setGLId(0);
01747 }
01748 }
01749 #endif
01750
01751 Inherited::changed(whichField, origin);
01752 }
01753
01754
01755
01758 TriangleIterator Geometry::beginTriangles(void) const
01759 {
01760 TriangleIterator it(this->getPtr());
01761
01762 it.setToBegin();
01763
01764 return it;
01765 }
01766
01769 TriangleIterator Geometry::endTriangles(void) const
01770 {
01771 TriangleIterator it(this->getPtr());
01772
01773 it.setToEnd();
01774
01775 return it;
01776 }
01777
01778
01779
01782 PrimitiveIterator Geometry::beginPrimitives(void) const
01783 {
01784 PrimitiveIterator it(this->getPtr());
01785
01786 it.setToBegin();
01787
01788 return it;
01789 }
01790
01793 PrimitiveIterator Geometry::endPrimitives(void) const
01794 {
01795 PrimitiveIterator it(this->getPtr());
01796
01797 it.setToEnd();
01798
01799 return it;
01800 }
01801
01802
01803
01806 FaceIterator Geometry::beginFaces(void) const
01807 {
01808 FaceIterator it(this->getPtr());
01809
01810 it.setToBegin();
01811
01812 return it;
01813 }
01814
01817 FaceIterator Geometry::endFaces(void) const
01818 {
01819 FaceIterator it(this->getPtr());
01820
01821 it.setToEnd();
01822
01823 return it;
01824 }
01825
01826
01827
01830 LineIterator Geometry::beginLines(void) const
01831 {
01832 LineIterator it(this->getPtr());
01833
01834 it.setToBegin();
01835
01836 return it;
01837 }
01838
01841 LineIterator Geometry::endLines(void) const
01842 {
01843 LineIterator it(this->getPtr());
01844
01845 it.setToEnd();
01846
01847 return it;
01848 }
01849
01850
01851
01854 EdgeIterator Geometry::beginEdges(void) const
01855 {
01856 EdgeIterator it(this->getPtr());
01857
01858 it.setToBegin();
01859
01860 return it;
01861 }
01862
01865 EdgeIterator Geometry::endEdges(void) const
01866 {
01867 EdgeIterator it(this->getPtr());
01868
01869 it.setToEnd();
01870
01871 return it;
01872 }
01873
01874
01879 GeometryPtr Geometry::clone(void)
01880 {
01881 GeometryPtr geo = Geometry::create();
01882
01883
01884
01885
01886 beginEditCP(geo);
01887 {
01888 if(getTypes() != NullFC)
01889 {
01890 geo->setTypes(getTypes()->clone());
01891 }
01892
01893 if(getLengths() != NullFC)
01894 {
01895 geo->setLengths(getLengths()->clone());
01896 }
01897
01898 if(getPositions() != NullFC)
01899 {
01900 geo->setPositions(getPositions()->clone());
01901 }
01902
01903 if(getNormals() != NullFC)
01904 {
01905 geo->setNormals(getNormals()->clone());
01906 }
01907
01908 if(getColors() != NullFC)
01909 {
01910 geo->setColors(getColors()->clone());
01911 }
01912
01913 if(getSecondaryColors() != NullFC)
01914 {
01915 geo->setSecondaryColors(getSecondaryColors()->clone());
01916 }
01917
01918 if(getTexCoords() != NullFC)
01919 {
01920 geo->setTexCoords(getTexCoords()->clone());
01921 }
01922
01923 if(getTexCoords1() != NullFC)
01924 {
01925 geo->setTexCoords1(getTexCoords1()->clone());
01926 }
01927
01928 if(getTexCoords2() != NullFC)
01929 {
01930 geo->setTexCoords2(getTexCoords2()->clone());
01931 }
01932
01933 if(getTexCoords3() != NullFC)
01934 {
01935 geo->setTexCoords3(getTexCoords3()->clone());
01936 }
01937
01938 if(getTexCoords4() != NullFC)
01939 {
01940 geo->setTexCoords4(getTexCoords4()->clone());
01941 }
01942
01943 if(getTexCoords5() != NullFC)
01944 {
01945 geo->setTexCoords5(getTexCoords5()->clone());
01946 }
01947
01948 if(getTexCoords6() != NullFC)
01949 {
01950 geo->setTexCoords6(getTexCoords6()->clone());
01951 }
01952
01953 if(getTexCoords7() != NullFC)
01954 {
01955 geo->setTexCoords7(getTexCoords7()->clone());
01956 }
01957
01958 if(getIndices() != NullFC)
01959 {
01960 geo->setIndices(getIndices()->clone());
01961 }
01962
01963 if(getMFIndexMapping() != NULL)
01964 {
01965 geo->getMFIndexMapping()->setValues(*getMFIndexMapping());
01966 }
01967
01968 geo->setMaterial(getMaterial());
01969 geo->setDlistCache(getDlistCache());
01970 }
01971 endEditCP(geo);
01972
01973 return geo;
01974 }
01975
01976 bool Geometry::CompareMaterials(MaterialPtr m1, MaterialPtr m2)
01977 {
01978 if(m1 == m2)
01979 return true;
01980
01981 ChunkMaterialPtr cm1=ChunkMaterialPtr::dcast(m1);
01982 ChunkMaterialPtr cm2=ChunkMaterialPtr::dcast(m2);
01983
01984 if (cm1==NullFC || cm2==NullFC) return false;
01985
01986 MFStateChunkPtr &chunks1=cm1->getChunks();
01987 MFStateChunkPtr &chunks2=cm2->getChunks();
01988
01989 if (chunks1.size()!=chunks2.size()) return false;
01990
01991 MFStateChunkPtr::iterator matIt = chunks1.begin();
01992 MFStateChunkPtr::iterator matEnd = chunks1.end ();
01993
01994 MFStateChunkPtr::iterator i;
01995
01996 while (matIt!=matEnd)
01997 {
01998 i = chunks2.find(*matIt);
01999
02000 if (i == chunks2.end()) return false;
02001
02002 ++matIt;
02003 }
02004
02005 if(cm1->getState() == NullFC)
02006 cm1->rebuildState();
02007 if(cm2->getState() == NullFC)
02008 cm2->rebuildState();
02009
02010 MFStateChunkPtr &statechunks1=cm1->getState()->getChunks();
02011 MFStateChunkPtr &statechunks2=cm2->getState()->getChunks();
02012
02013 if (statechunks1.size()!=statechunks2.size()) return false;
02014
02015 matIt = statechunks1.begin();
02016 matEnd = statechunks1.end ();
02017
02018 while (matIt!=matEnd)
02019 {
02020 i = statechunks2.find(*matIt);
02021
02022 if (i == statechunks2.end()) return false;
02023
02024 ++matIt;
02025 }
02026
02027 return true;
02028 }
02029
02041 Int16 Geometry::MergeIndex( const GeometryPtr other )
02042 {
02043
02044 if (!CompareMaterials(getMaterial(),other->getMaterial())) return -1;
02045
02046
02047
02048 if ( ( ( getNormals() != NullFC ) ^
02049 ( other->getNormals() != NullFC )
02050 ) ||
02051 ( ( getColors() != NullFC ) ^
02052 ( other->getColors() != NullFC )
02053 ) ||
02054 ( ( getSecondaryColors() != NullFC ) ^
02055 ( other->getSecondaryColors() != NullFC )
02056 ) ||
02057 ( ( getTexCoords() != NullFC ) ^
02058 ( other->getTexCoords() != NullFC )
02059 ) ||
02060 ( ( getTexCoords1() != NullFC ) ^
02061 ( other->getTexCoords1() != NullFC )
02062 ) ||
02063 ( ( getTexCoords2() != NullFC ) ^
02064 ( other->getTexCoords2() != NullFC )
02065 ) ||
02066 ( ( getTexCoords3() != NullFC ) ^
02067 ( other->getTexCoords3() != NullFC )
02068 ) ||
02069 ( ( getTexCoords4() != NullFC ) ^
02070 ( other->getTexCoords4() != NullFC )
02071 ) ||
02072 ( ( getTexCoords5() != NullFC ) ^
02073 ( other->getTexCoords5() != NullFC )
02074 ) ||
02075 ( ( getTexCoords6() != NullFC ) ^
02076 ( other->getTexCoords6() != NullFC )
02077 ) ||
02078 ( ( getTexCoords7() != NullFC ) ^
02079 ( other->getTexCoords7() != NullFC )
02080 ) )
02081 return -1;
02082
02083
02084
02085
02086
02087
02088 UInt16 nmap = getIndexMapping().size();
02089 UInt16 onmap = other->getIndexMapping().size();
02090
02091 if ( nmap == onmap ) return 0;
02092 else
02093 {
02094
02095 if ( nmap == 1 && onmap == 0 ) return 1;
02096
02097 if ( nmap == 0 && onmap == 1 ) return 2;
02098
02099
02100 if ( nmap > 1 && onmap == 0 ) return 3;
02101
02102 if ( nmap == 0 && onmap > 1 ) return 4;
02103
02104
02105 if ( nmap > 1 && onmap == 1 ) return 5;
02106
02107 if ( nmap == 1 && onmap > 1 ) return 6;
02108 }
02109
02110
02111 return -1;
02112 }
02113
02114 #define copyAttrib(Name, TypeT, Type) \
02115 { \
02116 Geo ## TypeT ## Ptr prop1 = Geo ## TypeT ## Ptr::dcast(get ## Type ()); \
02117 Geo ## TypeT ## Ptr prop2 = Geo ## TypeT ## Ptr::dcast(other->get ## Type ()); \
02118 if(prop1 != NullFC && prop2 != NullFC) \
02119 { \
02120 beginEditCP(prop1); \
02121 Name##Base = prop1->getSize(); \
02122 prop1->resize(Name##Base + prop2->getSize()); \
02123 for(i = 0; i < prop2->getSize(); ++i) \
02124 prop1->getField()[Name##Base + i] = prop2->getField()[i]; \
02125 endEditCP(prop1); \
02126 } \
02127 }
02128
02129 #define copyAllAttrib \
02130 { \
02131 copyAttrib(pos, Positions2f, Positions) \
02132 copyAttrib(pos, Positions3f, Positions) \
02133 copyAttrib(pos, Positions4f, Positions) \
02134 copyAttrib(pos, Positions2d, Positions) \
02135 copyAttrib(pos, Positions3d, Positions) \
02136 copyAttrib(pos, Positions4d, Positions) \
02137 copyAttrib(pos, Positions2s, Positions) \
02138 copyAttrib(pos, Positions3s, Positions) \
02139 copyAttrib(pos, Positions4s, Positions) \
02140 copyAttrib(type, PTypesUI8, Types) \
02141 copyAttrib(length, PLengthsUI8, Lengths) \
02142 copyAttrib(length, PLengthsUI16, Lengths) \
02143 copyAttrib(length, PLengthsUI32, Lengths) \
02144 copyAttrib(normal, Normals3f, Normals) \
02145 copyAttrib(normal, Normals3s, Normals) \
02146 copyAttrib(normal, Normals3b, Normals) \
02147 copyAttrib(color, Colors3f, Colors) \
02148 copyAttrib(color, Colors4f, Colors) \
02149 copyAttrib(color, Colors3ub, Colors) \
02150 copyAttrib(color, Colors4ub, Colors) \
02151 copyAttrib(seccolor, Colors3f, SecondaryColors) \
02152 copyAttrib(seccolor, Colors4f, SecondaryColors) \
02153 copyAttrib(seccolor, Colors3ub, SecondaryColors) \
02154 copyAttrib(seccolor, Colors4ub, SecondaryColors) \
02155 copyAttrib(texcoord, TexCoords1f, TexCoords) \
02156 copyAttrib(texcoord, TexCoords2f, TexCoords) \
02157 copyAttrib(texcoord, TexCoords3f, TexCoords) \
02158 copyAttrib(texcoord, TexCoords4f, TexCoords) \
02159 copyAttrib(texcoord1, TexCoords1f, TexCoords1) \
02160 copyAttrib(texcoord1, TexCoords2f, TexCoords1) \
02161 copyAttrib(texcoord1, TexCoords3f, TexCoords1) \
02162 copyAttrib(texcoord1, TexCoords4f, TexCoords1) \
02163 copyAttrib(texcoord2, TexCoords1f, TexCoords2) \
02164 copyAttrib(texcoord2, TexCoords2f, TexCoords2) \
02165 copyAttrib(texcoord2, TexCoords3f, TexCoords2) \
02166 copyAttrib(texcoord2, TexCoords4f, TexCoords2) \
02167 copyAttrib(texcoord3, TexCoords1f, TexCoords3) \
02168 copyAttrib(texcoord3, TexCoords2f, TexCoords3) \
02169 copyAttrib(texcoord3, TexCoords3f, TexCoords3) \
02170 copyAttrib(texcoord3, TexCoords4f, TexCoords3) \
02171 copyAttrib(texcoord4, TexCoords1f, TexCoords4) \
02172 copyAttrib(texcoord4, TexCoords2f, TexCoords4) \
02173 copyAttrib(texcoord4, TexCoords3f, TexCoords4) \
02174 copyAttrib(texcoord4, TexCoords4f, TexCoords4) \
02175 copyAttrib(texcoord5, TexCoords1f, TexCoords5) \
02176 copyAttrib(texcoord5, TexCoords2f, TexCoords5) \
02177 copyAttrib(texcoord5, TexCoords3f, TexCoords5) \
02178 copyAttrib(texcoord5, TexCoords4f, TexCoords5) \
02179 copyAttrib(texcoord6, TexCoords1f, TexCoords6) \
02180 copyAttrib(texcoord6, TexCoords2f, TexCoords6) \
02181 copyAttrib(texcoord6, TexCoords3f, TexCoords6) \
02182 copyAttrib(texcoord6, TexCoords4f, TexCoords6) \
02183 copyAttrib(texcoord7, TexCoords1f, TexCoords7) \
02184 copyAttrib(texcoord7, TexCoords2f, TexCoords7) \
02185 copyAttrib(texcoord7, TexCoords3f, TexCoords7) \
02186 copyAttrib(texcoord7, TexCoords4f, TexCoords7) \
02187 beginEditCP((GeometryPtr)this); \
02188 setDlistCache(other->getDlistCache()); \
02189 setVbo(other->getVbo()); \
02190 endEditCP((GeometryPtr)this); \
02191 }
02192
02193
02194 void Geometry::merge0( const GeometryPtr other )
02195 {
02196 UInt32 posBase = 0,typeBase = 0,lengthBase = 0,normalBase = 0,colorBase = 0,
02197 seccolorBase = 0,texcoordBase = 0,texcoord1Base = 0,texcoord2Base = 0,
02198 texcoord3Base = 0, texcoord4Base = 0, texcoord5Base = 0, texcoord6Base = 0,
02199 texcoord7Base = 0;
02200
02201
02202 UInt32 i;
02203
02204 copyAllAttrib;
02205
02206 if ( getIndices() != NullFC )
02207 {
02208
02209
02210 GeoIndicesPtr ind = getIndices();
02211 GeoIndicesPtr oind = other->getIndices();
02212
02213 beginEditCP( ind );
02214
02215 UInt32 indBase = ind->getSize();
02216 ind->resize( indBase + oind->getSize() );
02217
02218
02219 if ( getIndexMapping().size() < 2 )
02220 {
02221 for ( i = 0; i < oind->getSize(); i++ )
02222 ind->setValue( oind->getValue(i) + posBase, indBase + i );
02223 }
02224 else
02225 {
02226 UInt32 * offsets = new UInt32 [ getIndexMapping().size() ];
02227 Int16 mind;
02228 UInt16 nmap = getIndexMapping().size();
02229 UInt16 j;
02230
02231 if ( ( mind = calcMappingIndex( MapPosition ) ) >= 0 )
02232 offsets[ mind ] = posBase;
02233
02234 if ( ( mind = calcMappingIndex( MapNormal ) ) >= 0 )
02235 offsets[ mind ] = normalBase;
02236
02237 if ( ( mind = calcMappingIndex( MapColor ) ) >= 0 )
02238 offsets[ mind ] = colorBase;
02239
02240 if ( ( mind = calcMappingIndex( MapSecondaryColor ) ) >= 0 )
02241 offsets[ mind ] = seccolorBase;
02242
02243 if ( ( mind = calcMappingIndex( MapTexCoords ) ) >= 0 )
02244 offsets[ mind ] = texcoordBase;
02245
02246 if ( ( mind = calcMappingIndex( MapTexCoords1 ) ) >= 0 )
02247 offsets[ mind ] = texcoord1Base;
02248
02249 if ( ( mind = calcMappingIndex( MapTexCoords2 ) ) >= 0 )
02250 offsets[ mind ] = texcoord2Base;
02251
02252 if ( ( mind = calcMappingIndex( MapTexCoords3 ) ) >= 0 )
02253 offsets[ mind ] = texcoord3Base;
02254
02255 if ( ( mind = calcMappingIndex( MapTexCoords4 ) ) >= 0 )
02256 offsets[ mind ] = texcoord4Base;
02257
02258 if ( ( mind = calcMappingIndex( MapTexCoords5 ) ) >= 0 )
02259 offsets[ mind ] = texcoord5Base;
02260
02261 if ( ( mind = calcMappingIndex( MapTexCoords6 ) ) >= 0 )
02262 offsets[ mind ] = texcoord6Base;
02263
02264 if ( ( mind = calcMappingIndex( MapTexCoords7 ) ) >= 0 )
02265 offsets[ mind ] = texcoord7Base;
02266
02267
02268 for ( i = 0, j = 0; i < oind->getSize();
02269 i++, j = ( j + 1 ) % nmap )
02270 {
02271 ind->setValue(oind->getValue(i) + offsets[j],
02272 indBase + i );
02273 }
02274
02275 delete [] offsets;
02276 }
02277
02278 endEditCP( ind );
02279 }
02280 }
02281
02282
02283
02284 void Geometry::merge1( const GeometryPtr other )
02285 {
02286 UInt32 posBase,typeBase,lengthBase,normalBase,colorBase,
02287 seccolorBase,texcoordBase,texcoord1Base,texcoord2Base,
02288 texcoord3Base, texcoord4Base, texcoord5Base, texcoord6Base,
02289 texcoord7Base;
02290
02291 UInt32 i;
02292
02293 copyAllAttrib;
02294
02295 GeoIndicesPtr ind = getIndices();
02296
02297 UInt32 indBase = ind->getSize();
02298 ind->resize(indBase + other->getPositions()->getSize());
02299
02300 beginEditCP(ind);
02301
02302 for (i = 0; i < other->getPositions()->getSize(); i++ )
02303 ind->setValue( i + posBase, indBase + i );
02304
02305 endEditCP( ind );
02306 }
02307
02308
02309
02310 void Geometry::merge2( const GeometryPtr other )
02311 {
02312 UInt32 posBase,typeBase,lengthBase,normalBase,colorBase,
02313 seccolorBase,texcoordBase,texcoord1Base,texcoord2Base,
02314 texcoord3Base, texcoord4Base, texcoord5Base, texcoord6Base,
02315 texcoord7Base;
02316
02317 UInt32 i;
02318
02319 copyAllAttrib;
02320
02321 GeoIndicesUI32Ptr indices = GeoIndicesUI32::create();
02322 beginEditCP(indices, GeoIndicesUI32::GeoPropDataFieldMask);
02323
02324 indices->resize(posBase + other->getIndices()->getSize());
02325
02326 for (i = 0; i < posBase; i++)
02327 indices->setValue(i, i);
02328
02329 for (i = 0; i < other->getIndices()->getSize(); i++)
02330 indices->setValue(posBase + other->getIndices()->getValue(i), posBase + i);
02331
02332 endEditCP (indices, GeoIndicesUI32::GeoPropDataFieldMask);
02333
02334 beginEditCP((GeometryPtr)this, Geometry::IndicesFieldMask);
02335
02336 setIndices(indices);
02337
02338 endEditCP((GeometryPtr)this, Geometry::IndicesFieldMask);
02339 }
02340
02341
02342 void Geometry::merge3( const GeometryPtr other )
02343 {
02344 UInt32 posBase,typeBase,lengthBase,normalBase,colorBase,
02345 seccolorBase,texcoordBase,texcoord1Base,texcoord2Base,
02346 texcoord3Base, texcoord4Base, texcoord5Base, texcoord6Base,
02347 texcoord7Base;
02348
02349 UInt32 i;
02350
02351 copyAllAttrib;
02352
02353
02354 GeoIndicesPtr ind = getIndices();
02355 UInt16 nmap = getIndexMapping().size();
02356 Int16 mind;
02357 UInt32 indBase = ind->getSize();
02358 ind->resize( indBase + other->getPositions()->getSize()*nmap );
02359
02360 beginEditCP( ind );
02361
02362 for (i = 0; i < other->getPositions()->getSize(); i++)
02363 {
02364 if ( ( mind = calcMappingIndex( MapPosition ) ) >= 0 )
02365 ind->setValue(posBase + i, indBase + i*nmap + mind);
02366
02367 if ( ( mind = calcMappingIndex( MapNormal ) ) >= 0 )
02368 ind->setValue(normalBase + i, indBase + i*nmap + mind);
02369
02370 if ( ( mind = calcMappingIndex( MapColor ) ) >= 0 )
02371 ind->setValue(colorBase + i, indBase + i*nmap + mind);
02372
02373 if ( ( mind = calcMappingIndex( MapSecondaryColor ) ) >= 0 )
02374 ind->setValue(seccolorBase + i, indBase + i*nmap + mind);
02375
02376 if ( ( mind = calcMappingIndex( MapTexCoords ) ) >= 0 )
02377 ind->setValue(texcoordBase + i, indBase + i*nmap + mind);
02378
02379 if ( ( mind = calcMappingIndex( MapTexCoords1 ) ) >= 0 )
02380 ind->setValue(texcoord1Base + i, indBase + i*nmap + mind);
02381
02382 if ( ( mind = calcMappingIndex( MapTexCoords2 ) ) >= 0 )
02383 ind->setValue(texcoord2Base + i, indBase + i*nmap + mind);
02384
02385 if ( ( mind = calcMappingIndex( MapTexCoords3 ) ) >= 0 )
02386 ind->setValue(texcoord3Base + i, indBase + i*nmap + mind);
02387
02388 if ( ( mind = calcMappingIndex( MapTexCoords4 ) ) >= 0 )
02389 ind->setValue(texcoord4Base + i, indBase + i*nmap + mind);
02390
02391 if ( ( mind = calcMappingIndex( MapTexCoords5 ) ) >= 0 )
02392 ind->setValue(texcoord5Base + i, indBase + i*nmap + mind);
02393
02394 if ( ( mind = calcMappingIndex( MapTexCoords6 ) ) >= 0 )
02395 ind->setValue(texcoord6Base + i, indBase + i*nmap + mind);
02396
02397 if ( ( mind = calcMappingIndex( MapTexCoords7 ) ) >= 0 )
02398 ind->setValue(texcoord7Base + i, indBase + i*nmap + mind);
02399 }
02400
02401 endEditCP( ind );
02402 }
02403
02404
02405
02406 void Geometry::merge4( const GeometryPtr other )
02407 {
02408 UInt32 posBase = 0,typeBase = 0,lengthBase = 0,normalBase = 0,colorBase = 0,
02409 seccolorBase = 0,texcoordBase = 0,texcoord1Base = 0,texcoord2Base = 0,
02410 texcoord3Base = 0, texcoord4Base = 0, texcoord5Base = 0, texcoord6Base = 0,
02411 texcoord7Base = 0;
02412
02413 UInt32 i;
02414
02415 copyAllAttrib;
02416
02417 GeoIndicesPtr oind = other->getIndices();
02418 UInt16 nmap = other->getIndexMapping().size();
02419 Int16 mind;
02420 GeoIndicesUI32Ptr indices = GeoIndicesUI32::create();
02421 beginEditCP(indices, GeoIndicesUI32::GeoPropDataFieldMask);
02422
02423 indices->resize( posBase*nmap + oind->getSize() );
02424
02425 for (i = 0; i < posBase; i++)
02426 {
02427 if ( ( mind = calcMappingIndex( MapPosition ) ) >= 0 )
02428 indices->setValue(i, i*nmap + mind);
02429
02430 if ( ( mind = calcMappingIndex( MapNormal ) ) >= 0 )
02431 indices->setValue(i, i*nmap + mind);
02432
02433 if ( ( mind = calcMappingIndex( MapColor ) ) >= 0 )
02434 indices->setValue(i, i*nmap + mind);
02435
02436 if ( ( mind = calcMappingIndex( MapSecondaryColor ) ) >= 0 )
02437 indices->setValue(i, i*nmap + mind);
02438
02439 if ( ( mind = calcMappingIndex( MapTexCoords ) ) >= 0 )
02440 indices->setValue(i, i*nmap + mind);
02441
02442 if ( ( mind = calcMappingIndex( MapTexCoords1 ) ) >= 0 )
02443 indices->setValue(i, i*nmap + mind);
02444
02445 if ( ( mind = calcMappingIndex( MapTexCoords2 ) ) >= 0 )
02446 indices->setValue(i, i*nmap + mind);
02447
02448 if ( ( mind = calcMappingIndex( MapTexCoords3 ) ) >= 0 )
02449 indices->setValue(i, i*nmap + mind);
02450
02451 if ( ( mind = calcMappingIndex( MapTexCoords4 ) ) >= 0 )
02452 indices->setValue(i, i*nmap + mind);
02453
02454 if ( ( mind = calcMappingIndex( MapTexCoords5 ) ) >= 0 )
02455 indices->setValue(i, i*nmap + mind);
02456
02457 if ( ( mind = calcMappingIndex( MapTexCoords6 ) ) >= 0 )
02458 indices->setValue(i, i*nmap + mind);
02459
02460 if ( ( mind = calcMappingIndex( MapTexCoords7 ) ) >= 0 )
02461 indices->setValue(i, i*nmap + mind);
02462 }
02463
02464 for (i = 0; i < other->getIndices()->getSize(); i++)
02465 indices->setValue(posBase*nmap + other->getIndices()->getValue(i), posBase*nmap + i);
02466
02467 endEditCP (indices, GeoIndicesUI32::GeoPropDataFieldMask);
02468
02469 beginEditCP((GeometryPtr)this, Geometry::IndicesFieldMask);
02470
02471 setIndices(indices);
02472
02473 endEditCP((GeometryPtr)this, Geometry::IndicesFieldMask);
02474 }
02475
02476
02477 void Geometry::merge5( const GeometryPtr other )
02478 {
02479 UInt32 posBase,typeBase,lengthBase,normalBase,colorBase,
02480 seccolorBase,texcoordBase,texcoord1Base,texcoord2Base,
02481 texcoord3Base, texcoord4Base, texcoord5Base, texcoord6Base,
02482 texcoord7Base;
02483
02484 UInt32 i;
02485
02486 copyAllAttrib;
02487
02488
02489 GeoIndicesPtr ind = getIndices();
02490 GeoIndicesPtr oind = other->getIndices();
02491 UInt16 nmap = getIndexMapping().size();
02492 Int16 mind;
02493 UInt32 indBase = ind->getSize();
02494 ind->resize( indBase + oind->getSize()*nmap );
02495
02496 beginEditCP( ind );
02497
02498 for (i = 0; i < oind->getSize(); i++)
02499 {
02500 if ( ( mind = calcMappingIndex( MapPosition ) ) >= 0 )
02501 ind->setValue(posBase + oind->getValue(i), indBase + i*nmap + mind);
02502
02503 if ( ( mind = calcMappingIndex( MapNormal ) ) >= 0 )
02504 ind->setValue(normalBase + oind->getValue(i), indBase + i*nmap + mind);
02505
02506 if ( ( mind = calcMappingIndex( MapColor ) ) >= 0 )
02507 ind->setValue(colorBase + oind->getValue(i), indBase + i*nmap + mind);
02508
02509 if ( ( mind = calcMappingIndex( MapSecondaryColor ) ) >= 0 )
02510 ind->setValue(seccolorBase + oind->getValue(i), indBase + i*nmap + mind);
02511
02512 if ( ( mind = calcMappingIndex( MapTexCoords ) ) >= 0 )
02513 ind->setValue(texcoordBase + oind->getValue(i), indBase + i*nmap + mind);
02514
02515 if ( ( mind = calcMappingIndex( MapTexCoords1 ) ) >= 0 )
02516 ind->setValue(texcoord1Base + oind->getValue(i), indBase + i*nmap + mind);
02517
02518 if ( ( mind = calcMappingIndex( MapTexCoords2 ) ) >= 0 )
02519 ind->setValue(texcoord2Base + oind->getValue(i), indBase + i*nmap + mind);
02520
02521 if ( ( mind = calcMappingIndex( MapTexCoords3 ) ) >= 0 )
02522 ind->setValue(texcoord3Base + oind->getValue(i), indBase + i*nmap + mind);
02523
02524 if ( ( mind = calcMappingIndex( MapTexCoords4 ) ) >= 0 )
02525 ind->setValue(texcoord4Base + oind->getValue(i), indBase + i*nmap + mind);
02526
02527 if ( ( mind = calcMappingIndex( MapTexCoords5 ) ) >= 0 )
02528 ind->setValue(texcoord5Base + oind->getValue(i), indBase + i*nmap + mind);
02529
02530 if ( ( mind = calcMappingIndex( MapTexCoords6 ) ) >= 0 )
02531 ind->setValue(texcoord6Base + oind->getValue(i), indBase + i*nmap + mind);
02532
02533 if ( ( mind = calcMappingIndex( MapTexCoords7 ) ) >= 0 )
02534 ind->setValue(texcoord7Base + oind->getValue(i), indBase + i*nmap + mind);
02535 }
02536
02537 endEditCP( ind );
02538 }
02539
02540
02541
02542 void Geometry::merge6( const GeometryPtr other )
02543 {
02544 UInt32 posBase,typeBase,lengthBase,normalBase,colorBase,
02545 seccolorBase,texcoordBase,texcoord1Base,texcoord2Base,
02546 texcoord3Base, texcoord4Base, texcoord5Base, texcoord6Base,
02547 texcoord7Base;
02548
02549 UInt32 i;
02550
02551 copyAllAttrib;
02552
02553
02554 GeoIndicesPtr ind = getIndices();
02555 GeoIndicesPtr indclone = getIndices()->clone();
02556 GeoIndicesPtr oind = other->getIndices();
02557 UInt16 nmap = other->getIndexMapping().size();
02558 Int16 mind;
02559 UInt32 indBase = ind->getSize();
02560 ind->resize( indBase*nmap + oind->getSize() );
02561
02562 beginEditCP( ind );
02563
02564 for (i = 0; i < indclone->getSize(); i++)
02565 {
02566 if ( ( mind = calcMappingIndex( MapPosition ) ) >= 0 )
02567 ind->setValue(indclone->getValue(i), i*nmap + mind);
02568
02569 if ( ( mind = calcMappingIndex( MapNormal ) ) >= 0 )
02570 ind->setValue(indclone->getValue(i), i*nmap + mind);
02571
02572 if ( ( mind = calcMappingIndex( MapColor ) ) >= 0 )
02573 ind->setValue(indclone->getValue(i), i*nmap + mind);
02574
02575 if ( ( mind = calcMappingIndex( MapSecondaryColor ) ) >= 0 )
02576 ind->setValue(indclone->getValue(i), i*nmap + mind);
02577
02578 if ( ( mind = calcMappingIndex( MapTexCoords ) ) >= 0 )
02579 ind->setValue(indclone->getValue(i), i*nmap + mind);
02580
02581 if ( ( mind = calcMappingIndex( MapTexCoords1 ) ) >= 0 )
02582 ind->setValue(indclone->getValue(i), i*nmap + mind);
02583
02584 if ( ( mind = calcMappingIndex( MapTexCoords2 ) ) >= 0 )
02585 ind->setValue(indclone->getValue(i), i*nmap + mind);
02586
02587 if ( ( mind = calcMappingIndex( MapTexCoords3 ) ) >= 0 )
02588 ind->setValue(indclone->getValue(i), i*nmap + mind);
02589
02590 if ( ( mind = calcMappingIndex( MapTexCoords4 ) ) >= 0 )
02591 ind->setValue(indclone->getValue(i), i*nmap + mind);
02592
02593 if ( ( mind = calcMappingIndex( MapTexCoords5 ) ) >= 0 )
02594 ind->setValue(indclone->getValue(i), i*nmap + mind);
02595
02596 if ( ( mind = calcMappingIndex( MapTexCoords6 ) ) >= 0 )
02597 ind->setValue(indclone->getValue(i), i*nmap + mind);
02598
02599 if ( ( mind = calcMappingIndex( MapTexCoords7 ) ) >= 0 )
02600 ind->setValue(indclone->getValue(i), i*nmap + mind);
02601 }
02602
02603 for (i = 0; i < oind->getSize(); i++)
02604 ind->setValue(oind->getValue(i), indBase*nmap + i);
02605
02606 endEditCP( ind );
02607 }
02608
02609
02610 bool Geometry::updateLowHighIndices( void )
02611 {
02612
02613 if(getTypes () == NullFC || getTypes ()->size() == 0)
02614 return true;
02615
02616 UInt32 primcount = getTypes()->size();
02617
02618 if(getLengths() == NullFC || getLengths()->size() < primcount ||
02619 getIndices() == NullFC || getIndices()->size() == 0 ||
02620 getIndexMapping().size() > 1
02621 )
02622 return true;
02623
02624 GeoIndicesPtr indP = getIndices();
02625
02626 UInt32 low, high, mini, maxi, cur;
02627
02628 GeometryPtr self(this);
02629 beginEditCP(self, LowindicesFieldMask |
02630 HighindicesFieldMask |
02631 MinindexFieldMask |
02632 MaxindexFieldMask);
02633
02634
02635 getLowindices().resize(primcount);
02636 getHighindices().resize(primcount);
02637 mini = 0xffffffffU;
02638 maxi = 0;
02639
02640 for (UInt32 i = 0, cur = 0; i < primcount; i++)
02641 {
02642 UInt32 l;
02643 getLengths()->getValue(l, i);
02644
02645 low = 0xffffffffU;
02646 high = 0;
02647
02648 for (UInt32 j = 0; j < l; ++j, ++cur)
02649 {
02650 if(cur >= indP->size())
02651 break;
02652
02653 UInt32 ind;
02654 indP->getValue(ind, cur);
02655
02656 if(ind < low ) low = ind;
02657 if(ind > high) high = ind;
02658 if(ind < mini) mini = ind;
02659 if(ind > maxi) maxi = ind;
02660 }
02661
02662 getLowindices()[i] = low;
02663 getHighindices()[i] = high;
02664 }
02665
02666 setMinindex(mini);
02667 setMaxindex(maxi);
02668
02669 endEditCP(self, LowindicesFieldMask |
02670 HighindicesFieldMask |
02671 MinindexFieldMask |
02672 MaxindexFieldMask);
02673
02674 return false;
02675 }
02676
02677 void Geometry::createVBO(Window *win, UInt32 id)
02678 {
02679
02680
02681 if(_vbos.capacity() > _vbos.size())
02682 {
02683 _vbos.push_back(new GeoVBO(win, this));
02684 win->setGLObjectId(id + 1, _vbos.size());
02685 return;
02686 }
02687
02688
02689 for(UInt32 i=0;i<_vbos.size();++i)
02690 {
02691 if(_vbos[i] == NULL)
02692 {
02693 _vbos[i] = new GeoVBO(win, this);
02694 win->setGLObjectId(id + 1, i + 1);
02695 return;
02696 }
02697 }
02698
02699 _vbos.push_back(new GeoVBO(win, this));
02700 win->setGLObjectId(id + 1, _vbos.size());
02701 }
02702
02703 void Geometry::destroyVBO(Window *win, UInt32 id)
02704 {
02705 UInt32 i = win->getGLObjectId(id + 1);
02706
02707 if(i == 0)
02708 return;
02709
02710 --i;
02711
02712 if(i < _vbos.size())
02713 {
02714 delete _vbos[i];
02715 _vbos[i] = NULL;
02716 }
02717 win->setGLObjectId(id + 1, 0);
02718 }
02719
02720 void Geometry::updateVBO(Window *win, UInt32 id)
02721 {
02722 UInt32 i = win->getGLObjectId(id + 1);
02723
02724 if(i == 0)
02725 {
02726
02727 createVBO(win, id);
02728 return;
02729 }
02730
02731 --i;
02732
02733 if(i < _vbos.size())
02734 {
02735 GeoVBO *vbo = _vbos[i];
02736 if(vbo != NULL)
02737 {
02738 vbo->update();
02739 }
02740 }
02741 }
02742
02743 bool Geometry::drawVBO(Window *win, UInt32 id)
02744 {
02745 win->validateGLObject(id);
02746 UInt32 i = win->getGLObjectId(id + 1);
02747 if(i == 0)
02748 {
02749
02750 return false;
02751 }
02752
02753 --i;
02754
02755 if(i < _vbos.size())
02756 {
02757 GeoVBO *vbo = _vbos[i];
02758 if(vbo != NULL)
02759 vbo->draw();
02760 }
02761 return true;
02762 }
02763
02764
02765
02766
02767
02768
02769
02770
02771 #ifdef OSG_SGI_CC
02772 #pragma set woff 1174
02773 #endif
02774
02775 #ifdef OSG_LINUX_ICC
02776 #pragma warning(disable : 177)
02777 #endif
02778
02779 namespace
02780 {
02781 static Char8 cvsid_cpp [] = "@(#)$Id: $";
02782 static Char8 cvsid_hpp [] = OSGGEOMETRY_HEADER_CVSID;
02783 static Char8 cvsid_inl [] = OSGGEOMETRY_INLINE_CVSID;
02784 }
02785