void WriterNodeVisitor::apply( osg::Billboard &node ) { // TODO Does not handle Billboards' points yet pushStateSet(node.getStateSet()); Lib3dsMeshInstanceNode * parent = _cur3dsNode; unsigned int count = node.getNumDrawables(); ListTriangle listTriangles; bool texcoords = false; OSG_NOTICE << "Warning: 3DS writer is incomplete for Billboards (rotation not implemented)." << std::endl; #if DISABLE_3DS_ANIMATION osg::Matrix m( osg::computeLocalToWorld(getNodePath()) ); #endif for ( unsigned int i = 0; i < count; i++ ) { osg::Geometry *g = node.getDrawable( i )->asGeometry(); if ( g != NULL ) { listTriangles.clear(); _cur3dsNode = parent; pushStateSet(g->getStateSet()); createListTriangle(g, listTriangles, texcoords, i); popStateSet(g->getStateSet()); // May set _succeded to false if (!succeeded()) break; osg::Matrix pointLocalMat(osg::Matrix::translate(node.getPosition(i))); // TODO handle rotation #if DISABLE_3DS_ANIMATION osg::Matrix currentBillboardWorldMat(pointLocalMat * m); apply3DSMatrixNode(node, &pointLocalMat, "bil"); // Add a 3DS matrix node (with local matrix) buildFaces(node, currentBillboardWorldMat, listTriangles, texcoords); // May set _succeded to false #else apply3DSMatrixNode(node, &pointLocalMat, "bil"); // Add a 3DS matrix node (with local matrix) buildFaces(node, osg::Matrix(), listTriangles, texcoords); // May set _succeded to false #endif if (!succeeded()) break; } } if (succeeded()) traverse(node); _cur3dsNode = parent; popStateSet(node.getStateSet()); }
static bool readPositionList( osgDB::InputStream& is, osg::Billboard& node ) { unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; for ( unsigned int i=0; i<size; ++i ) { osg::Vec3d pos; is >> pos; node.setPosition( i, pos ); } is >> is.END_BRACKET; return true; }
static bool writePositionList( osgDB::OutputStream& os, const osg::Billboard& node ) { const osg::Billboard::PositionList& posList = node.getPositionList(); os.writeSize(posList.size()); os<< os.BEGIN_BRACKET << std::endl; for ( osg::Billboard::PositionList::const_iterator itr=posList.begin(); itr!=posList.end(); ++itr ) { os << osg::Vec3d(*itr) << std::endl; } os << os.END_BRACKET << std::endl; return true; }
void IntersectionVisitor::apply(osg::Billboard& billboard) { if (!enter(billboard)) return; #if 1 // IntersectVisitor doesn't have getEyeLocal(), can we use NodeVisitor::getEyePoint()? osg::Vec3 eye_local = getEyePoint(); for(unsigned int i = 0; i < billboard.getNumDrawables(); i++ ) { const osg::Vec3& pos = billboard.getPosition(i); osg::ref_ptr<osg::RefMatrix> billboard_matrix = _modelStack.empty() ? new osg::RefMatrix : new osg::RefMatrix(*_modelStack.back()); billboard.computeMatrix(*billboard_matrix,eye_local,pos); pushModelMatrix(billboard_matrix.get()); // now push an new intersector clone transform to the new local coordinates push_clone(); intersect( billboard.getDrawable(i) ); // now push an new intersector clone transform to the new local coordinates pop_clone(); popModelMatrix(); } #else for(unsigned int i=0; i<billboard.getNumDrawables(); ++i) { intersect( billboard.getDrawable(i) ); } #endif leave(); }
static bool checkPositionList( const osg::Billboard& node ) { return node.getPositionList().size()>0; }
void CVRCullVisitor::apply(osg::Billboard& node) { bool status = _cullingStatus; bool firstStatus = _firstCullStatus; if(isCulled(node)) { _firstCullStatus = firstStatus; _cullingStatus = status; return; } // push the node's state. StateSet* node_state = node.getStateSet(); if(node_state) pushStateSet(node_state); // traverse any call callbacks and traverse any children. handle_cull_callbacks_and_traverse(node); const Vec3& eye_local = getEyeLocal(); const RefMatrix& modelview = *getModelViewMatrix(); for(unsigned int i = 0; i < node.getNumDrawables(); ++i) { const Vec3& pos = node.getPosition(i); Drawable* drawable = node.getDrawable(i); // need to modify isCulled to handle the billboard offset. // if (isCulled(drawable->getBound())) continue; if(drawable->getCullCallback()) { if(drawable->getCullCallback()->cull(this,drawable,&_renderInfo) == true) continue; } RefMatrix* billboard_matrix = createOrReuseMatrix(modelview); node.computeMatrix(*billboard_matrix,eye_local,pos); if(_computeNearFar && drawable->getBound().valid()) updateCalculatedNearFar(*billboard_matrix,*drawable,true); float depth = distance(pos,modelview); /* if (_computeNearFar) { if (d<_computed_znear) { if (d<0.0) OSG_NOTIFY(osg::WARN)<<"Alerting billboard handling ="<<d<< std::endl; _computed_znear = d; } if (d>_computed_zfar) _computed_zfar = d; } */ StateSet* stateset = drawable->getStateSet(); if(stateset) pushStateSet(stateset); if(osg::isNaN(depth)) { /*OSG_NOTIFY(osg::NOTICE)<<"CullVisitor::apply(Billboard&) detected NaN,"<<std::endl <<" depth="<<depth<<", pos=("<<pos<<"),"<<std::endl <<" *billboard_matrix="<<*billboard_matrix<<std::endl; OSG_NOTIFY(osg::DEBUG_INFO) << " NodePath:" << std::endl; for (NodePath::const_iterator i = getNodePath().begin(); i != getNodePath().end(); ++i) { OSG_NOTIFY(osg::DEBUG_INFO) << " \"" << (*i)->getName() << "\"" << std::endl; }*/ } else { addDrawableAndDepth(drawable,billboard_matrix,depth); } if(stateset) popStateSet(); } // pop the node's state off the geostate stack. if(node_state) popStateSet(); _firstCullStatus = firstStatus; _cullingStatus = status; }