Vec3Array *Object3D::getVertexList(Node *node, unsigned int index) { Vec3Array *vertices = NULL; Drawable *drawable = getDrawable(node, index); Geometry *geom = drawable->asGeometry(); if(geom) vertices = dynamic_cast<Vec3Array*>(geom->getVertexArray()); return vertices; }
void Object3D::dirty() { GeodeFindVisitor visitor; _originalNode->accept(visitor); std::vector<Geode*> geodeList = visitor.getGeodeList(); std::vector<Geode*>::iterator it; for(it=geodeList.begin(); it!=geodeList.end(); ++it) { Geode *geode = *it; if(geode) { for(unsigned int i=0; i<geode->getNumDrawables(); i++) { Drawable *drawable = geode->getDrawable(i); drawable->dirtyBound(); Geometry* geom(drawable->asGeometry()); osgUtil::SmoothingVisitor sv; sv.smooth(*geom); geom->getNormalArray()->dirty(); } } } }
bool IntersectVisitor::intersect(Drawable& drawable) { bool hitFlag = false; IntersectState* cis = _intersectStateStack.back().get(); const BoundingBox& bb = drawable.getBoundingBox(); for(IntersectState::LineSegmentList::iterator sitr=cis->_segList.begin(); sitr!=cis->_segList.end(); ++sitr) { if (sitr->second->intersect(bb)) { TriangleFunctor<TriangleIntersect> ti; ti.set(*sitr->second); drawable.accept(ti); if (ti._hit) { osg::Geometry* geometry = drawable.asGeometry(); for(TriangleIntersect::TriangleHitList::iterator thitr=ti._thl.begin(); thitr!=ti._thl.end(); ++thitr) { Hit hit; hit._nodePath = _nodePath; hit._matrix = cis->_model_matrix; hit._inverse = cis->_model_inverse; hit._drawable = &drawable; if (_nodePath.empty()) hit._geode = NULL; else hit._geode = dynamic_cast<Geode*>(_nodePath.back()); TriangleHit& triHit = thitr->second; hit._ratio = thitr->first; hit._primitiveIndex = triHit._index; hit._originalLineSegment = sitr->first; hit._localLineSegment = sitr->second; hit._intersectPoint = sitr->second->start()*(1.0f-hit._ratio)+ sitr->second->end()*hit._ratio; hit._intersectNormal = triHit._normal; if (geometry) { osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geometry->getVertexArray()); if (vertices) { osg::Vec3* first = &(vertices->front()); if (triHit._v1) hit._vecIndexList.push_back(triHit._v1-first); if (triHit._v2) hit._vecIndexList.push_back(triHit._v2-first); if (triHit._v3) hit._vecIndexList.push_back(triHit._v3-first); } } _segHitList[sitr->first.get()].push_back(hit); std::sort(_segHitList[sitr->first.get()].begin(),_segHitList[sitr->first.get()].end()); hitFlag = true; } } } } return hitFlag; }