// // Test code // void EnviroFrame::DoTestCode() { SetMode(MM_SLOPE); #if 0 // Shadow tests const int ReceivesShadowTraversalMask = 0x1; const int CastsShadowTraversalMask = 0x2; osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene = new osgShadow::ShadowedScene; shadowedScene->setReceivesShadowTraversalMask(ReceivesShadowTraversalMask); shadowedScene->setCastsShadowTraversalMask(CastsShadowTraversalMask); #if 0 osg::ref_ptr<osgShadow::ShadowMap> sm = new osgShadow::ShadowMap; shadowedScene->setShadowTechnique(sm.get()); int mapres = 1024; sm->setTextureSize(osg::Vec2s(mapres,mapres)); #else osg::ref_ptr<osgShadow::ShadowTexture> sm = new osgShadow::ShadowTexture; shadowedScene->setShadowTechnique(sm.get()); #endif osg::Group* cessna1 = (osg::Group*) osgDB::readNodeFile("cessna.osg"); if (!cessna1) return; cessna1->setNodeMask(CastsShadowTraversalMask); cessna1->getChild(0)->setNodeMask(CastsShadowTraversalMask); osg::Group* cessna2 = (osg::Group*) osgDB::readNodeFile("cessna.osg"); if (!cessna2) return; int flags_off = ~(CastsShadowTraversalMask | ReceivesShadowTraversalMask); cessna2->setNodeMask(flags_off); cessna2->getChild(0)->setNodeMask(flags_off); osg::MatrixTransform* positioned = new osg::MatrixTransform; positioned->setDataVariance(osg::Object::STATIC); positioned->setMatrix(osg::Matrix::rotate(osg::inDegrees(-90.0f),0.0f,1.0f,0.0f) *osg::Matrix::translate(40,40,0)); positioned->addChild(cessna1); //osg::ref_ptr<osg::Group> shadowedScene = new osg::Group; shadowedScene->addChild(positioned); shadowedScene->addChild(cessna2); // osg::ref_ptr<osg::Group> container = new osg::Group; // container->addChild(positioned); // container->addChild(cessna2); vtGroup *vtg = GetCurrentTerrain()->GetTerrainGroup(); vtg->GetOsgGroup()->addChild(shadowedScene.get()); // vtg->GetOsgGroup()->addChild(container.get()); vtLogGraph(shadowedScene.get()); #endif #if 0 if (pTerr && g_App.m_bSelectedStruct) { vtStructureArray3d *sa = pTerr->GetStructureLayer(); int i = 0; while (!sa->GetAt(i)->IsSelected()) i++; vtBuilding3d *bld = sa->GetBuilding(i); // (Do something to the building as a test) sa->ConstructStructure(bld); } #endif #if 0 { // Read points from a text file, create OBJ file with geometry at that locations FILE *fp = fopen("test.txt", "r"); if (!fp) return; char buf[80]; float depth, x, y; // Add the geometry and materials to the shape vtGeode *pGeode = new vtGeode; vtMaterialArray *pMats = new vtMaterialArray; pMats->AddRGBMaterial(RGBf(1.0f, 1.0f, 1.0f), false, false, false); pGeode->SetMaterials(pMats); vtMesh *mesh = new vtMesh(osg::PrimitiveSet::TRIANGLES, VT_Normals | VT_Colors, 4000); int line = 0; fgets(buf, 80, fp); // skip first while (fgets(buf, 80, fp) != NULL) { sscanf(buf, "%f\t%f\t%f", &depth, &x, &y); int idx = mesh->NumVertices(); for (int i = 0; i < 20; i++) { double angle = (double)i / 20.0 * PI2d; FPoint3 vec; vec.x = x/2 * cos(angle); vec.y = 0.0f; vec.z = y/2 * sin(angle); // normal FPoint3 norm = vec; norm.Normalize(); // color RGBAf col(1.0f, 1.0f, 1.0f, 1.0f); if (x > y) { float frac = (x-y)/1.5f; // typical: 0 - 1.2 col.g -= frac; col.b -= frac; } else if (y > x) { float frac = (y-x)/1.5f; // typical: 0 - 1.2 col.r -= frac; col.g -= frac; } int add = mesh->AddVertexN(vec.x, /*650*/-depth, vec.z, norm.x, norm.y, norm.z); mesh->SetVtxColor(add, col); } if (line != 0) { for (int i = 0; i < 20; i++) { int next = (i+1)%20; mesh->AddTri(idx-20 + i, idx + i, idx-20 + next); mesh->AddTri(idx + i, idx + next, idx-20 + next); } } line++; } pGeode->AddMesh(mesh, 0); WriteGeomToOBJ(pGeode, "bore.obj"); vtTransform *model = new vtTransform; model->addChild(pGeode); DPoint3 pos; g_App.m_pTerrainPicker->GetCurrentEarthPos(pos); GetCurrentTerrain()->AddNode(model); GetCurrentTerrain()->PlantModelAtPoint(model, DPoint2(pos.x, pos.y)); } #endif }
/** Diagnostic function to help debugging: Log the scene graph from a given node downwards. */ void vtLogGraph(osg::Node *node, bool bExtents, bool bRefCounts, int indent) { for (int i = 0; i < indent; i++) VTLOG1(" "); if (node) { VTLOG("<%x>", node); if (dynamic_cast<osg::PositionAttitudeTransform*>(node)) VTLOG1(" (PositionAttitudeTransform)"); else if (dynamic_cast<osg::MatrixTransform*>(node)) VTLOG1(" (MatrixTransform)"); else if (dynamic_cast<osg::AutoTransform*>(node)) VTLOG1(" (AutoTransform)"); else if (dynamic_cast<osg::Transform*>(node)) VTLOG1(" (Transform)"); else if (dynamic_cast<osg::TexGenNode*>(node)) VTLOG1(" (TexGenNode)"); else if (dynamic_cast<osg::Switch*>(node)) VTLOG1(" (Switch)"); else if (dynamic_cast<osg::Sequence*>(node)) VTLOG1(" (Sequence)"); else if (dynamic_cast<osg::Projection*>(node)) VTLOG1(" (Projection)"); else if (dynamic_cast<osg::OccluderNode*>(node)) VTLOG1(" (OccluderNode)"); else if (dynamic_cast<osg::LightSource*>(node)) VTLOG1(" (LightSource)"); else if (dynamic_cast<osg::LOD*>(node)) VTLOG1(" (LOD)"); else if (dynamic_cast<osg::CoordinateSystemNode*>(node)) VTLOG1(" (CoordinateSystemNode)"); else if (dynamic_cast<osg::ClipNode*>(node)) VTLOG1(" (ClipNode)"); else if (dynamic_cast<osg::ClearNode*>(node)) VTLOG1(" (ClearNode)"); else if (dynamic_cast<osg::Group*>(node)) VTLOG1(" (Group)"); else if (dynamic_cast<osg::Billboard*>(node)) VTLOG1(" (Billboard)"); else if (dynamic_cast<osg::Geode*>(node)) VTLOG1(" (Geode)"); else if (dynamic_cast<osgParticle::ModularEmitter*>(node)) VTLOG1(" (Geode)"); else if (dynamic_cast<osgParticle::ParticleSystemUpdater*>(node)) VTLOG1(" (Geode)"); else VTLOG1(" (non-node!)"); VTLOG(" '%s'", node->getName().c_str()); if (node->getNodeMask() != 0xffffffff) VTLOG(" mask=%x", node->getNodeMask()); if (node->getStateSet() != NULL) VTLOG(" (has stateset)"); if (bExtents) { const osg::BoundingSphere &bs = node->getBound(); if (bs._radius != -1) VTLOG(" (bs: %.1f %.1f %.1f %1.f)", bs._center[0], bs._center[1], bs._center[2], bs._radius); } if (bRefCounts) { VTLOG(" {rc:%d}", node->referenceCount()); } VTLOG1("\n"); } else VTLOG1("<null>\n"); osg::MatrixTransform *mt = dynamic_cast<osg::MatrixTransform*>(node); if (mt) { for (int i = 0; i < indent+1; i++) VTLOG1(" "); osg::Vec3 v = mt->getMatrix().getTrans(); VTLOG("[Pos %.2f %.2f %.2f]\n", v.x(), v.y(), v.z()); } osg::Group *grp = dynamic_cast<osg::Group*>(node); if (grp) { for (uint i = 0; i < grp->getNumChildren(); i++) vtLogGraph(grp->getChild(i), bExtents, bRefCounts, indent+2); } osg::Geode *geode = dynamic_cast<osg::Geode*>(node); if (geode) { for (uint i = 0; i < geode->getNumDrawables(); i++) { osg::Geometry *geo = dynamic_cast<osg::Geometry *>(geode->getDrawable(i)); if (!geo) continue; osg::StateSet *stateset = geo->getStateSet(); if (!stateset) continue; for (int j = 0; j < indent+3; j++) VTLOG1(" "); VTLOG("drawable %d: geometry %x, stateset %x", i, geo, stateset); osg::StateAttribute *state = stateset->getAttribute(osg::StateAttribute::MATERIAL); if (state) { osg::Material *mat = dynamic_cast<osg::Material *>(state); if (mat) VTLOG(", mat %x", mat); } VTLOG1("\n"); } } }