// select all visible nodes UInt32 RenderAction::selectVisibles(void) { if(getFrustumCulling() == false) return getNNodes(); useNodeList(); Color3f col; UInt32 count = 0; for(UInt32 i = 0; i < getNNodes(); i++) { if(isVisible(getNode(i))) { col.setValuesRGB(0,1,0); addNode(getNode(i)); ++count; } else { col.setValuesRGB(1,0,0); } if(getVolumeDrawing()) { dropVolume(this, getNode(i), col); } } return count; }
void MergeGraphOp::processTransformations(Node * const node) { MFUnrecChildNodePtr::const_iterator mfit = node->getMFChildren()->begin(); MFUnrecChildNodePtr::const_iterator mfen = node->getMFChildren()->end (); std::vector<Node *> toAdd; std::vector<Node *> toSub; for ( ; mfit != mfen; ++mfit ) { bool special=isInExcludeList(*mfit); bool leaf=isLeaf(*mfit); bool empty=true; //if a transformation: if ((*mfit)->getCore()->getType().isDerivedFrom( Transform::getClassType())) { if (!leaf && !special) { //try to apply it to children geometries //move all "moveable" children one level up //if empty after that, delete it MFUnrecChildNodePtr::const_iterator it2 = (*mfit)->getMFChildren()->begin(); MFUnrecChildNodePtr::const_iterator en2 = (*mfit)->getMFChildren()->end (); for ( ; it2 != en2; ++it2 ) { if (!isInExcludeList(*it2)) { //check if geometry if ((*it2)->getCore()->getType().isDerivedFrom( Geometry::getClassType())) { if(!isLeaf(*it2)) { //hmm...bad tree... empty=false; } else { //it is a leaf geometry, so apply the transformation Geometry *geo_old = dynamic_cast<Geometry *>( (*it2)->getCore()); //GeometryPtr geo = geo_old->clone(); GeometryUnrecPtr geo = dynamic_pointer_cast<Geometry>( OSG::deepClone(geo_old, "Material")); Transform *t = dynamic_cast<Transform *>( (*mfit)->getCore()); GeoPnt3fProperty *pos = dynamic_cast<GeoPnt3fProperty *>(geo->getPositions()); GeoVec3fProperty *norm = dynamic_cast<GeoVec3fProperty *>(geo->getNormals()); GeoColor3fProperty *color = dynamic_cast<GeoColor3fProperty *>(geo->getColors()); GeoColor3fProperty *scolor = dynamic_cast<GeoColor3fProperty *>(geo->getSecondaryColors()); GeoVec3fProperty *texcoord0 = dynamic_cast<GeoVec3fProperty *>(geo->getTexCoords()); GeoVec3fProperty *texcoord1 = dynamic_cast<GeoVec3fProperty *>(geo->getTexCoords1()); GeoVec3fProperty *texcoord2 = dynamic_cast<GeoVec3fProperty *>(geo->getTexCoords2()); GeoVec3fProperty * texcoord3 = dynamic_cast<GeoVec3fProperty *>(geo->getTexCoords3()); Matrix m=t->getMatrix(); if(pos!=NULL) { for(UInt32 i = 0; i < pos->size(); ++i) { Pnt3f p=pos->getValue(i); m.multFull(p, p); pos->setValue(p,i); } } if(norm!=NULL) { for(UInt32 i = 0; i < norm->size(); ++i) { Vec3f n=norm->getValue(i); m.mult(n, n); n.normalize(); norm->setValue(n,i); } } if(color != NULL && _color_is_vector) { for(UInt32 i = 0; i < color->size(); ++i) { Color3f c = color->getValue(i); Vec3f v; v.setValue(c.getValuesRGB()); m.mult(v, v); v.normalize(); c.setValuesRGB(v[0], v[1], v[2]); color->setValue(c,i); } } if(scolor != NULL && _secondary_color_is_vector) { for(UInt32 i = 0; i < scolor->size(); ++i) { Color3f c = scolor->getValue(i); Vec3f v; v.setValue(c.getValuesRGB()); m.mult(v, v); v.normalize(); c.setValuesRGB(v[0], v[1], v[2]); scolor->setValue(c,i); } } if(texcoord0 != NULL && _texcoord0_is_vector) { for(UInt32 i = 0; i < texcoord0->size(); ++i) { Vec3f v = texcoord0->getValue(i); m.mult(v, v); v.normalize(); texcoord0->setValue(v,i); } } if(texcoord1 != NULL && _texcoord1_is_vector) { for(UInt32 i = 0; i < texcoord1->size(); ++i) { Vec3f v = texcoord1->getValue(i); m.mult(v, v); v.normalize(); texcoord1->setValue(v,i); } } if(texcoord2 != NULL && _texcoord2_is_vector) { for(UInt32 i = 0; i < texcoord2->size(); ++i) { Vec3f v = texcoord2->getValue(i); m.mult(v, v); v.normalize(); texcoord2->setValue(v,i); } } if (texcoord3 != NULL && _texcoord3_is_vector) { for(UInt32 i = 0; i < texcoord3->size(); i++) { Vec3f v = texcoord3->getValue(i); m.mult(v, v); v.normalize(); texcoord3->setValue(v,i); } } (*it2)->setCore(geo); toAdd.push_back(*it2); } } else empty=false; } else empty=false; } } //now check whether we have to remove it if ((empty||leaf) && !special) { toSub.push_back(*mfit); continue; } if (leaf && special) { //what to do? } if (!leaf && special) { //what to do? } continue; } } std::vector<Node *>::const_iterator vit = toAdd.begin(); std::vector<Node *>::const_iterator ven = toAdd.end (); for ( ; vit != ven; ++vit ) { node->addChild(*vit); } vit = toSub.begin(); ven = toSub.end (); for ( ; vit != ven; ++vit ) { node->subChild(*vit); } }
Action::ResultE ProxyGroup::render(Action *action) { DrawActionBase *da = dynamic_cast<DrawActionBase *>(action); if(getEnabled() == false) return Action::Continue; if(getState() == NOT_LOADED) startLoading(); if(getState() == LOAD_THREAD_FINISHED) { if(_loadedRoot != NULL) { _loadThread = NULL; setRoot(_loadedRoot); getRoot()->invalidateVolume(); getRoot()->updateVolume(); setState(LOADED); da->getActNode()->invalidateVolume(); da->getActNode()->updateVolume (); } else { SWARNING << "failed to load " << getAbsoluteUrl() << std::endl; setState(LOAD_ERROR); } } if(getState() == LOADED) { da->useNodeList(); if(da->isVisible(getCPtr(getRoot()))) da->addNode(getRoot()); } else { if(da->getActNode()->getNChildren() == 0) { Color3f col; col.setValuesRGB(.5,.3,0); dropVolume(da, da->getActNode(), col); } } // thread cleanup if(_loadThread && _loadQueue.empty()) { printf("join\n"); BaseThread::join(_loadThread); _loadThread = NULL; } return Action::Continue; }
// visibility levels bool RenderPartition::pushVisibility(Node * const pNode) { if(getFrustumCulling() == false) return true; FrustumVolume::PlaneSet inplanes = _visibilityStack.back(); if(inplanes == FrustumVolume::P_ALL) { _visibilityStack.push_back(inplanes); return true; } Color3f col; bool result = true; FrustumVolume frustum = _oFrustum; BoxVolume vol = pNode->getVolume(); // don't mess with infinite volumes if(vol.isInfinite() == false) { pNode->updateVolume(); vol = pNode->getVolume(); #if 1 vol.transform(topMatrix()); #else // not quite working Matrix m = topMatrix(); m.invert(); frustum.transform(m); #endif } if(_oDrawEnv.getStatCollector() != NULL) { _oDrawEnv.getStatCollector()->getElem(statCullTestedNodes)->inc(); } if(intersect(frustum, vol, inplanes) == false) { result = false; col.setValuesRGB(1,0,0); if(_oDrawEnv.getStatCollector() != NULL) { _oDrawEnv.getStatCollector()->getElem(statCulledNodes)->inc(); } } else { if(inplanes == FrustumVolume::P_ALL) { col.setValuesRGB(0,1,0); } else { col.setValuesRGB(0,0,1); } } if(getVolumeDrawing()) { dropVolume(this, pNode, col); } _visibilityStack.push_back(inplanes); return result; }