Geode *ClipPlanePlugin::loadPlane() { // *5---*6---*7 // | | | // *3--------*4 // | | | // *0---*1---*2 float w = cover->getSceneSize() * 0.1; // width of plane Vec3Array *lineCoords = new Vec3Array(12); (*lineCoords)[0].set(-w, -0.01, -w); (*lineCoords)[1].set(w, -0.01, -w); (*lineCoords)[2].set(-w, -0.01, 0.0f); (*lineCoords)[3].set(w, -0.01, 0.0f); (*lineCoords)[4].set(-w, -0.01, w); (*lineCoords)[5].set(w, -0.01, w); (*lineCoords)[6].set(-w, -0.01, -w); (*lineCoords)[7].set(-w, -0.01, w); (*lineCoords)[8].set(0.0f, -0.01, -w); (*lineCoords)[9].set(0.0f, -0.01, w); (*lineCoords)[10].set(w, -0.01, -w); (*lineCoords)[11].set(w, -0.01, w); DrawArrayLengths *primitives = new DrawArrayLengths(PrimitiveSet::LINE_STRIP); for (int i = 0; i < 6; i++) { primitives->push_back(2); } Vec3Array *lineColors = new Vec3Array(12); for (int i = 0; i < 12; i++) { (*lineColors)[i].set(Vec3(1.0f, 1.0f, 1.0f)); } Geometry *geoset = new Geometry(); geoset->setVertexArray(lineCoords); geoset->addPrimitiveSet(primitives); geoset->setColorArray(lineColors); Material *mtl = new Material; mtl->setColorMode(Material::AMBIENT_AND_DIFFUSE); mtl->setAmbient(Material::FRONT_AND_BACK, Vec4(0.2f, 0.2f, 0.2f, 1.0f)); mtl->setDiffuse(Material::FRONT_AND_BACK, Vec4(0.9f, 0.9f, 0.9f, 1.0f)); mtl->setSpecular(Material::FRONT_AND_BACK, Vec4(0.9f, 0.9f, 0.9f, 1.0f)); mtl->setEmission(Material::FRONT_AND_BACK, Vec4(0.0f, 0.0f, 0.0f, 1.0f)); mtl->setShininess(Material::FRONT_AND_BACK, 16.0f); Geode *geode = new Geode; geode->setName("ClipPlane"); geode->addDrawable(geoset); StateSet *geostate = geode->getOrCreateStateSet(); geostate->setAttributeAndModes(mtl, StateAttribute::ON); geostate->setMode(GL_LIGHTING, StateAttribute::OFF); LineWidth *lineWidth = new LineWidth(3.0); geostate->setAttributeAndModes(lineWidth, StateAttribute::ON); geode->setStateSet(geostate); return geode; }
osg::Node *JTOpenPlugin::createShape(JtkShape *partShape, const char *objName) { //cout << "JtkSHAPE\n"; Geode *geode = new Geode(); ref_ptr<Geometry> geom = new Geometry(); StateSet *geoState = geode->getOrCreateStateSet(); Vec3Array *vert = new Vec3Array; Vec3Array *normalArray = new Vec3Array(); Vec3Array *colorArray = new Vec3Array(); Vec2Array *tcArray = new Vec2Array(); DrawArrayLengths *primitives = NULL; if (partShape->typeID() == JtkEntity::JtkPOLYGONSET) { primitives = new DrawArrayLengths(PrimitiveSet::POLYGON); } else if (partShape->typeID() == JtkEntity::JtkLINESTRIPSET) { primitives = new DrawArrayLengths(PrimitiveSet::LINE_STRIP); } else if (partShape->typeID() == JtkEntity::JtkTRISTRIPSET) { primitives = new DrawArrayLengths(PrimitiveSet::TRIANGLE_STRIP); } else { cerr << "unknown partShape->typeID " << partShape->typeID() << endl; } geode->setName(objName); if (primitives) { for (int set = 0; set < partShape->numOfSets(); set++) { float *vertex = NULL, *normal = NULL, *color = NULL, *texture = NULL; int vertexCount = -1, normCount = -1, colorCount = -1, textCount = -1; partShape->getInternal(vertex, vertexCount, normal, normCount, color, colorCount, texture, textCount, set); primitives->push_back(vertexCount); // backFaceCulling nur dann, wenn es im CoviseConfig enabled ist /*if(backFaceCulling && (mask & Viewer::MASK_SOLID)) { CullFace *cullFace = new CullFace(); // da viele Modelle backface Culling nicht vertragen (nicht richtig modelliert sind) cullFace->setMode(CullFace::BACK); geoState->setAttributeAndModes(cullFace, StateAttribute::ON); } // already done in updateMaterial() #if 0 if(Blended) { BlendFunc *blendFunc = new BlendFunc(); blendFunc->setFunction(BlendFunc::SRC_ALPHA, BlendFunc::ONE_MINUS_SRC_ALPHA); geoState->setAttributeAndModes(blendFunc, StateAttribute::ON); #if 1 AlphaFunc *alphaFunc = new AlphaFunc(); alphaFunc->setFunction(AlphaFunc::ALWAYS,1.0); geoState->setAttributeAndModes(alphaFunc, StateAttribute::OFF); #endif } #endif #ifdef HAVE_OSGNV if((strncmp(d_currentObject->node->name(),"combineTextures",15)==0)||(strncmp(objName,"combineTextures",15)==0)) { geoState->setAttributeAndModes(combineTextures.get(), StateAttribute::ON); } if((strncmp(d_currentObject->node->name(),"combineEnvTextures",15)==0)||(strncmp(objName,"combineEnvTextures",15)==0)) { geoState->setAttributeAndModes(combineEnvTextures.get(), StateAttribute::ON); } #endif*/ if (vertex && (vertexCount > 0)) { for (int elems = 0; elems < vertexCount; elems++) { vert->push_back(Vec3(vertex[elems * 3 + 0], vertex[elems * 3 + 1], vertex[elems * 3 + 2])); } JtkEntityFactory::deleteMemory(vertex); } if (normal && (normCount > 0)) { for (int elems = 0; elems < normCount; elems++) { normalArray->push_back(Vec3(normal[elems * 3 + 0], normal[elems * 3 + 1], normal[elems * 3 + 2])); } if (normCount == vertexCount) { } else { //geom->setNormalBinding(Geometry::BIND_PER_PRIMITIVE); std::cerr << "JTOpen: normals per primitive not supported" << std::endl; } JtkEntityFactory::deleteMemory(normal); } else // generate normals { } if (color && (colorCount > 0)) { for (int elems = 0; elems < colorCount; elems++) { colorArray->push_back(Vec3(color[elems * 3 + 0], color[elems * 3 + 1], color[elems * 3 + 2])); } if (colorCount == vertexCount) { } else { //geom->setColorBinding(Geometry::BIND_PER_PRIMITIVE); std::cerr << "JTOpen: colors per primitive not supported" << std::endl; } JtkEntityFactory::deleteMemory(color); } if (texture && (textCount > 0)) { for (int elems = 0; elems < textCount; elems++) { tcArray->push_back(Vec2(texture[elems * 2 + 0], texture[elems * 2 + 1])); } JtkEntityFactory::deleteMemory(texture); } /* if(!(mask & Viewer::MASK_CONVEX)) { osgUtil::Tesselator *tess = new osgUtil::Tesselator; tess->retesselatePolygons(*geom); //delete[] tess; }*/ // if enabled, generate tri strips, but not for animated objects // if(genStrips && strncmp(objName, "Animated", 8)) { // d_stripper->stripify(*geom); } } geom->setVertexArray(vert); geom->addPrimitiveSet(primitives); if (normalArray->size() > 0) { geom->setNormalArray(normalArray); geom->setNormalBinding(Geometry::BIND_PER_VERTEX); } if (colorArray->size() > 0) { geom->setColorArray(colorArray); geom->setColorBinding(Geometry::BIND_PER_VERTEX); } if (tcArray->size() > 0) geom->setTexCoordArray(0, tcArray); if (normalArray->size() == 0) { osgUtil::SmoothingVisitor::smooth(*(geom.get()), 40.0 / 180.0 * M_PI); } geode->addDrawable(geom.get()); geode->setStateSet(geoState); return geode; } return NULL; }
Node *makeSky( void ) { int i, j; float lev[] = { -5, -1.0, 1.0, 15.0, 30.0, 60.0, 90.0 }; float cc[][4] = { { 0.0, 0.0, 0.15 }, { 0.0, 0.0, 0.15 }, { 0.4, 0.4, 0.7 }, { 0.2, 0.2, 0.6 }, { 0.1, 0.1, 0.6 }, { 0.1, 0.1, 0.6 }, { 0.1, 0.1, 0.6 }, }; float x, y, z; float alpha, theta; float radius = 20.0f; int nlev = sizeof( lev )/sizeof(float); Geometry *geom = new Geometry; Vec3Array& coords = *(new Vec3Array(19*nlev)); Vec4Array& colors = *(new Vec4Array(19*nlev)); Vec2Array& tcoords = *(new Vec2Array(19*nlev)); int ci = 0; for( i = 0; i < nlev; i++ ) { for( j = 0; j <= 18; j++ ) { alpha = osg::DegreesToRadians(lev[i]); theta = osg::DegreesToRadians((float)(j*20)); x = radius * cosf( alpha ) * cosf( theta ); y = radius * cosf( alpha ) * -sinf( theta ); z = radius * sinf( alpha ); coords[ci][0] = x; coords[ci][1] = y; coords[ci][2] = z; colors[ci][0] = cc[i][0]; colors[ci][1] = cc[i][1]; colors[ci][2] = cc[i][2]; colors[ci][3] = 1.0; tcoords[ci][0] = (float)j/18.0; tcoords[ci][1] = (float)i/(float)(nlev-1); ci++; } } for( i = 0; i < nlev-1; i++ ) { DrawElementsUShort* drawElements = new DrawElementsUShort(PrimitiveSet::TRIANGLE_STRIP); drawElements->reserve(38); for( j = 0; j <= 18; j++ ) { drawElements->push_back((i+1)*19+j); drawElements->push_back((i+0)*19+j); } geom->addPrimitiveSet(drawElements); } geom->setVertexArray( &coords ); geom->setTexCoordArray( 0, &tcoords ); geom->setColorArray( &colors ); geom->setColorBinding( Geometry::BIND_PER_VERTEX ); Texture2D *tex = new Texture2D; tex->setImage(osgDB::readImageFile("Images/white.rgb")); StateSet *dstate = new StateSet; dstate->setTextureAttributeAndModes(0, tex, StateAttribute::OFF ); dstate->setTextureAttribute(0, new TexEnv ); dstate->setMode( GL_LIGHTING, StateAttribute::OFF ); dstate->setMode( GL_CULL_FACE, StateAttribute::ON ); // clear the depth to the far plane. osg::Depth* depth = new osg::Depth; depth->setFunction(osg::Depth::ALWAYS); depth->setRange(1.0,1.0); dstate->setAttributeAndModes(depth,StateAttribute::ON ); dstate->setRenderBinDetails(-2,"RenderBin"); geom->setStateSet( dstate ); Geode *geode = new Geode; geode->addDrawable( geom ); geode->setName( "Sky" ); return geode; }