/*! Create LineChunk from fetched data. * The DXF line pattern description is mapped to a 16 bit stipple pattern * suitable for OpenGL line stippling. This mapping only approximately * resembles the DXF line pattern. * * \todo * Currently it's not checked, whether the fetched data is consistent! */ DXFResult DXFLtype::endEntity(void) { if(_linetypeMapP->find(_name) != _linetypeMapP->end()) { FWARNING(("DXF Loader: before line %d: " "LTYPE entity '%s' already exists. " "Overwriting with new one!\n", DXFRecord::getLineNumber(), _name.c_str() )); } // Do consistency checks Real32 checkedPatternLen = 0.0; for(std::vector<Real64>::iterator itr = _elementLen.begin(); itr != _elementLen.end(); ++ itr) { checkedPatternLen += osgabs(*itr); } if(osgabs(checkedPatternLen - _patternLen) > Eps) { FWARNING(("DXF Loader: before line %d: " "LTYPE entity defines inconsistent pattern lenght!\n", DXFRecord::getLineNumber() )); // we go on, but will use consistent data: checkedPatternLen } if(_nElements != _elementLen.size()) { FWARNING(("DXF Loader: before line %d: " "LTYPE entity declares %d pattern elements but provides %d!\n", DXFRecord::getLineNumber(), _nElements, _elementLen.size() )); // we go on, but will use consistent data: _elementLen.size() } UInt16 pattern = 0; LineChunkPtr linetype = LineChunk::create(); beginEditCP(linetype); { // linetype->setWidth(1); if(_elementLen.size() != 0) { // Build OpenGL 16 bit stipple pattern: for each bit calculate, which // pattern element it belongs to and set it if the pattern element is // positive, otherwise leave it unset. Real32 s = checkedPatternLen/16.0; UInt8 j = 0; Real32 elementLenSum = osgabs(_elementLen[j]); for(UInt8 i = 0; i < 16; ++ i) { if(elementLenSum < (0.5 + i) * s && j < _elementLen.size()) { ++ j; elementLenSum += osgabs( _elementLen[j] ); } if( _elementLen[j] > 0.0) pattern |= 1<<i; } linetype->setStippleRepeat(1); linetype->setStipplePattern(pattern); } linetype->setSmooth(true); //TODO: make this configurable by an option? } endEditCP(linetype); #if 1 // DEBUG TODO: raus?!?! std::string pstr(""); for(UInt8 i=0; i<16; ++i) pstr += (pattern & (1<<i)) ? "1" : "0"; FDEBUG(("DXFLtype::endEntity(): pattern '%s' = %s\n", _name.c_str(), pstr.c_str())); #endif // DEBUG (*_linetypeMapP)[_name] = linetype; return DXFStateContinue; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); TutorialUpdateListener TheTutorialUpdateListener; TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener); TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(MainWindow); //Print key command info std::cout << "\n\nKEY COMMANDS:" << std::endl; std::cout << "space Play/Pause the animation" << std::endl; std::cout << "G Show/Hide the grid" << std::endl; std::cout << "A Show/Hide the axes" << std::endl; std::cout << "B Show/Hide the bind pose skeleton" << std::endl; std::cout << "SHIFT-B Show/Hide the bind pose mesh" << std::endl; std::cout << "P Show/Hide the current pose skeleton" << std::endl; std::cout << "SHIFT-P Show/Hide the current pose mesh" << std::endl; std::cout << "CTRL-Q Exit\n\n" << std::endl; //Setup axes LineChunkPtr AxesLineChunk = LineChunk::create(); beginEditCP(AxesLineChunk); AxesLineChunk->setWidth(0.0f); AxesLineChunk->setSmooth(true); endEditCP(AxesLineChunk); //Axes material ChunkMaterialPtr AxesMaterial = ChunkMaterial::create(); beginEditCP(AxesMaterial, ChunkMaterial::ChunksFieldMask); AxesMaterial->addChunk(AxesLineChunk); endEditCP(AxesMaterial, ChunkMaterial::ChunksFieldMask); //Grid material ChunkMaterialPtr gridMaterial = ChunkMaterial::create(); beginEditCP(gridMaterial, ChunkMaterial::ChunksFieldMask); gridMaterial->addChunk(AxesLineChunk); endEditCP(gridMaterial, ChunkMaterial::ChunksFieldMask); //Axes should render as lines GeoPTypesPtr axesType = GeoPTypesUI8::create(); beginEditCP(axesType, GeoPTypesUI8::GeoPropDataFieldMask); { axesType->addValue(GL_LINES); } endEditCP (axesType, GeoPTypesUI8::GeoPropDataFieldMask); //Grid type GeoPTypesPtr gridType = GeoPTypesUI8::create(); beginEditCP(gridType, GeoPTypesUI8::GeoPropDataFieldMask); { gridType->addValue(GL_LINES); } endEditCP (gridType, GeoPTypesUI8::GeoPropDataFieldMask); //Axes lens GeoPLengthsPtr axesLens = GeoPLengthsUI32::create(); beginEditCP(axesLens, GeoPLengthsUI32::GeoPropDataFieldMask); { axesLens->addValue(6); } endEditCP (axesLens, GeoPLengthsUI32::GeoPropDataFieldMask); //Grid lens GeoPLengthsPtr gridLens = GeoPLengthsUI32::create(); beginEditCP(gridLens, GeoPLengthsUI32::GeoPropDataFieldMask); { gridLens->addValue(84); } endEditCP (gridLens, GeoPLengthsUI32::GeoPropDataFieldMask); //Axes points GeoPositions3fPtr axesPnts = GeoPositions3f::create(); beginEditCP(axesPnts, GeoPositions3f::GeoPropDataFieldMask); { // X-Axis axesPnts->addValue(Pnt3f(0, 0, 0)); axesPnts->addValue(Pnt3f(15, 0, 0)); // Y-Axis axesPnts->addValue(Pnt3f(0, 0, 0)); axesPnts->addValue(Pnt3f(0, 15, 0)); // Z-Axis axesPnts->addValue(Pnt3f(0, 0, 0)); axesPnts->addValue(Pnt3f(0, 0, 15)); } endEditCP (axesPnts, GeoPositions3f::GeoPropDataFieldMask); //Grid points GeoPositions3fPtr gridPnts = GeoPositions3f::create(); beginEditCP(gridPnts, GeoPositions3f::GeoPropDataFieldMask); { float height = 0; gridPnts->addValue(Pnt3f(-10, height, 0)); if(height == 0) gridPnts->addValue(Pnt3f(0, height, 0)); else gridPnts->addValue(Pnt3f(10, height, 0)); gridPnts->addValue(Pnt3f(-10, height, 1)); gridPnts->addValue(Pnt3f(10, height, 1)); gridPnts->addValue(Pnt3f(-10, height, 2)); gridPnts->addValue(Pnt3f(10, height, 2)); gridPnts->addValue(Pnt3f(-10, height, 3)); gridPnts->addValue(Pnt3f(10, height, 3)); gridPnts->addValue(Pnt3f(-10, height, 4)); gridPnts->addValue(Pnt3f(10, height, 4)); gridPnts->addValue(Pnt3f(-10, height, 5)); gridPnts->addValue(Pnt3f(10, height, 5)); gridPnts->addValue(Pnt3f(-10, height, 6)); gridPnts->addValue(Pnt3f(10, height, 6)); gridPnts->addValue(Pnt3f(-10, height, 7)); gridPnts->addValue(Pnt3f(10, height, 7)); gridPnts->addValue(Pnt3f(-10, height, 8)); gridPnts->addValue(Pnt3f(10, height, 8)); gridPnts->addValue(Pnt3f(-10, height, 9)); gridPnts->addValue(Pnt3f(10, height, 9)); gridPnts->addValue(Pnt3f(-10, height, 10)); gridPnts->addValue(Pnt3f(10, height, 10)); gridPnts->addValue(Pnt3f(-10, height, -1)); gridPnts->addValue(Pnt3f(10, height, -1)); gridPnts->addValue(Pnt3f(-10, height, -2)); gridPnts->addValue(Pnt3f(10, height, -2)); gridPnts->addValue(Pnt3f(-10, height, -3)); gridPnts->addValue(Pnt3f(10, height, -3)); gridPnts->addValue(Pnt3f(-10, height, -4)); gridPnts->addValue(Pnt3f(10, height, -4)); gridPnts->addValue(Pnt3f(-10, height, -5)); gridPnts->addValue(Pnt3f(10, height, -5)); gridPnts->addValue(Pnt3f(-10, height, -6)); gridPnts->addValue(Pnt3f(10, height, -6)); gridPnts->addValue(Pnt3f(-10, height, -7)); gridPnts->addValue(Pnt3f(10, height, -7)); gridPnts->addValue(Pnt3f(-10, height, -8)); gridPnts->addValue(Pnt3f(10, height, -8)); gridPnts->addValue(Pnt3f(-10, height, -9)); gridPnts->addValue(Pnt3f(10, height, -9)); gridPnts->addValue(Pnt3f(-10, height, -10)); gridPnts->addValue(Pnt3f(10, height, -10)); gridPnts->addValue(Pnt3f(0, height, -10)); if(height == 0) gridPnts->addValue(Pnt3f(0, height, 0)); else gridPnts->addValue(Pnt3f(0, height, 10)); gridPnts->addValue(Pnt3f(1, height, -10)); gridPnts->addValue(Pnt3f(1, height, 10)); gridPnts->addValue(Pnt3f(2, height, -10)); gridPnts->addValue(Pnt3f(2, height, 10)); gridPnts->addValue(Pnt3f(3, height, -10)); gridPnts->addValue(Pnt3f(3, height, 10)); gridPnts->addValue(Pnt3f(4, height, -10)); gridPnts->addValue(Pnt3f(4, height, 10)); gridPnts->addValue(Pnt3f(5, height, -10)); gridPnts->addValue(Pnt3f(5, height, 10)); gridPnts->addValue(Pnt3f(6, height, -10)); gridPnts->addValue(Pnt3f(6, height, 10)); gridPnts->addValue(Pnt3f(7, height, -10)); gridPnts->addValue(Pnt3f(7, height, 10)); gridPnts->addValue(Pnt3f(8, height, -10)); gridPnts->addValue(Pnt3f(8, height, 10)); gridPnts->addValue(Pnt3f(9, height, -10)); gridPnts->addValue(Pnt3f(9, height, 10)); gridPnts->addValue(Pnt3f(10, height, -10)); gridPnts->addValue(Pnt3f(10, height, 10)); gridPnts->addValue(Pnt3f(-1, height, -10)); gridPnts->addValue(Pnt3f(-1, height, 10)); gridPnts->addValue(Pnt3f(-2, height, -10)); gridPnts->addValue(Pnt3f(-2, height, 10)); gridPnts->addValue(Pnt3f(-3, height, -10)); gridPnts->addValue(Pnt3f(-3, height, 10)); gridPnts->addValue(Pnt3f(-4, height, -10)); gridPnts->addValue(Pnt3f(-4, height, 10)); gridPnts->addValue(Pnt3f(-5, height, -10)); gridPnts->addValue(Pnt3f(-5, height, 10)); gridPnts->addValue(Pnt3f(-6, height, -10)); gridPnts->addValue(Pnt3f(-6, height, 10)); gridPnts->addValue(Pnt3f(-7, height, -10)); gridPnts->addValue(Pnt3f(-7, height, 10)); gridPnts->addValue(Pnt3f(-8, height, -10)); gridPnts->addValue(Pnt3f(-8, height, 10)); gridPnts->addValue(Pnt3f(-9, height, -10)); gridPnts->addValue(Pnt3f(-9, height, 10)); gridPnts->addValue(Pnt3f(-10, height, -10)); gridPnts->addValue(Pnt3f(-10, height, 10)); } endEditCP (gridPnts, GeoPositions3f::GeoPropDataFieldMask); //Axes normals GeoNormals3fPtr axesNorms = GeoNormals3f::create(); beginEditCP(axesNorms, GeoNormals3f::GeoPropDataFieldMask); axesNorms->addValue(Vec3f( 0.0,0.0,1.0)); axesNorms->addValue(Vec3f( 0.0,0.0,1.0)); axesNorms->addValue(Vec3f( 0.0,0.0,1.0)); axesNorms->addValue(Vec3f( 0.0,0.0,1.0)); axesNorms->addValue(Vec3f( 1.0,0.0,0.0)); axesNorms->addValue(Vec3f( 1.0,0.0,0.0)); endEditCP(axesNorms, GeoNormals3f::GeoPropDataFieldMask); //Grid normals GeoNormals3fPtr gridNorms = GeoNormals3f::create(); beginEditCP(gridNorms, GeoNormals3f::GeoPropDataFieldMask); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); endEditCP(gridNorms, GeoNormals3f::GeoPropDataFieldMask); //Axes colors GeoColors3fPtr axesColors = GeoColors3f::create(); beginEditCP(axesColors, GeoColors3f::GeoPropDataFieldMask); //X-Axis = Red axesColors->addValue(Color3f( 1.0,0.0,0.0)); axesColors->addValue(Color3f( 1.0,0.0,0.0)); //Y-Axis = Green axesColors->addValue(Color3f( 0.0,1.0,0.0)); axesColors->addValue(Color3f( 0.0,1.0,0.0)); //Z-Axis = Blue axesColors->addValue(Color3f( 0.0,0.0,1.0)); axesColors->addValue(Color3f( 0.0,0.0,1.0)); endEditCP(axesColors, GeoColors3f::GeoPropDataFieldMask); //Grid gridColors GeoColors3fPtr gridColors = GeoColors3f::create(); beginEditCP(gridColors, GeoColors3f::GeoPropDataFieldMask); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); endEditCP(gridColors, GeoColors3f::GeoPropDataFieldMask); //Create axes geometry GeometryPtr axesGeo = Geometry::create(); beginEditCP(axesGeo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask); { axesGeo->setTypes (axesType); axesGeo->setLengths (axesLens); axesGeo->setPositions(axesPnts); axesGeo->setNormals(axesNorms); axesGeo->setColors(axesColors); // assign a material to the geometry to make it visible. The details // of materials are defined later. axesGeo->setMaterial(AxesMaterial); } endEditCP (axesGeo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask ); //Create grid geometry GeometryPtr gridGeo = Geometry::create(); beginEditCP(gridGeo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask); { gridGeo->setTypes (gridType); gridGeo->setLengths (gridLens); gridGeo->setPositions(gridPnts); gridGeo->setNormals(gridNorms); gridGeo->setColors(gridColors); // assign a material to the geometry to make it visible. The details // of materials are defined later. gridGeo->setMaterial(AxesMaterial); } endEditCP (gridGeo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask ); //Create unbound geometry Node Axes = osg::Node::create(); beginEditCP(Axes, Node::CoreFieldMask); Axes->setCore(axesGeo); endEditCP(Axes, Node::CoreFieldMask); //Create unbound geometry Node Grid = osg::Node::create(); beginEditCP(Grid, Node::CoreFieldMask); Grid->setCore(gridGeo); endEditCP(Grid, Node::CoreFieldMask); //Import scene from an XML file ChunkMaterialPtr ExampleMaterial; std::vector<SkeletonPtr> SkeletonPtrs; std::vector<SkeletonBlendedGeometryPtr> SkeletonBlendedGeometryPtrs; std::vector<GeometryPtr> GeometryPtrs; FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(Path("./Data/21SceneFromMaya.xml")); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { if( (*Itor)->getType() == (ChunkMaterial::getClassType())) { //Set ExampleMaterial to the ChunkMaterial we just read in ExampleMaterial = (ChunkMaterial::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (Skeleton::getClassType())) { //Add the skeleton we just read in to SkeletonPtrs SkeletonPtrs.push_back(Skeleton::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (SkeletonBlendedGeometry::getClassType())) { //Add the SkeletonBlendedGeometry we just read in to SkeletonBlendedGeometryPtrs SkeletonBlendedGeometryPtrs.push_back(SkeletonBlendedGeometry::Ptr::dcast(*Itor)); } if( (*Itor)->getType().isDerivedFrom(SkeletonAnimation::getClassType())) { //Set TheSkeletonAnimation to the Animation we just read in TheSkeletonAnimation = (Animation::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (Geometry::getClassType())) { //Add the Geometry we just read in to GeometryPtrs GeometryPtrs.push_back(Geometry::Ptr::dcast(*Itor)); } } //Create unbound geometry Node (to show the mesh in its bind pose) for (int i(0); i < GeometryPtrs.size(); ++i) { NodePtr UnboundGeometry = Node::create(); beginEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask); UnboundGeometry->setCore(GeometryPtrs[i]); UnboundGeometry->setTravMask(0); endEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask); UnboundGeometries.push_back(UnboundGeometry); } //Create skeleton nodes for (int i(0); i < SkeletonPtrs.size(); ++i) { //SkeletonDrawer SkeletonDrawablePtr ExampleSkeletonDrawable = osg::SkeletonDrawable::create(); beginEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask); ExampleSkeletonDrawable->setSkeleton(SkeletonPtrs[i]); ExampleSkeletonDrawable->setMaterial(AxesMaterial); ExampleSkeletonDrawable->setDrawPose(true); //By default we draw the current skeleton ExampleSkeletonDrawable->setPoseColor(Color4f(1.0, 0.0, 1.0, 1.0)); //Set color of current skeleton ExampleSkeletonDrawable->setDrawBindPose(false); //By default we don't draw the bind pose skeleton ExampleSkeletonDrawable->setBindPoseColor(Color4f(1.0, 1.0, 0.0, 1.0)); //Set color of bind pose skeleton endEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask); //Skeleton Node NodePtr SkeletonNode = osg::Node::create(); beginEditCP(SkeletonNode, Node::CoreFieldMask); SkeletonNode->setCore(ExampleSkeletonDrawable); endEditCP(SkeletonNode, Node::CoreFieldMask); SkeletonNodes.push_back(SkeletonNode); } //Create skeleton blended geometry nodes for (int i(0); i < SkeletonBlendedGeometryPtrs.size(); ++i) { NodePtr MeshNode = osg::Node::create(); beginEditCP(MeshNode, Node::CoreFieldMask); MeshNode->setCore(SkeletonBlendedGeometryPtrs[i]); endEditCP(MeshNode, Node::CoreFieldMask); MeshNodes.push_back(MeshNode); } //Create Animation Advancer TheAnimationAdvancer = osg::ElapsedTimeAnimationAdvancer::create(); osg::beginEditCP(TheAnimationAdvancer); osg::ElapsedTimeAnimationAdvancer::Ptr::dcast(TheAnimationAdvancer)->setStartTime( 0.0 ); osg::beginEditCP(TheAnimationAdvancer); //Add nodes to scene NodePtr scene = osg::Node::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(osg::Group::create()); scene->addChild(Axes); scene->addChild(Grid); //Add all imported skeletons to scene for (int i(0); i < SkeletonNodes.size(); ++i) { scene->addChild(SkeletonNodes[i]); } //Add all imported geometries to scene for (int i(0); i < UnboundGeometries.size(); ++i) { scene->addChild(UnboundGeometries[i]); } //Add all imported SkeletonBlendedGeometries to scene for (int i(0); i < MeshNodes.size(); ++i) { scene->addChild(MeshNodes[i]); } endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); mgr->setRoot(scene); //By default the animation is not paused animationPaused = false; // Show the whole Scene mgr->showAll(); TheAnimationAdvancer->start(); //Show window Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "21LoadXMLSceneFromMaya"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
ChunkMaterialPtr vtkOsgConverter::CreateMaterial(bool lit, bool hasTexCoords) { if (_verbose) std::cout << "Start CreateMaterial()" << std::endl; vtkProperty* prop = _actor->GetProperty(); double* diffuseColor = prop->GetDiffuseColor(); double* ambientColor = prop->GetAmbientColor(); double* specularColor = prop->GetSpecularColor(); double specularPower = prop->GetSpecularPower(); double diffuse = prop->GetDiffuse(); double ambient = prop->GetAmbient(); double specular = prop->GetSpecular(); double opacity = prop->GetOpacity(); float pointSize = prop->GetPointSize(); float lineWidth = prop->GetLineWidth(); // int lineStipplePattern = prop->GetLineStipplePattern(); int representation = prop->GetRepresentation(); if (_verbose) { std::cout << " Colors:" << std::endl; std::cout << " diffuse " << diffuse << " * " << diffuseColor[0] << " " << diffuseColor[1] << " " << diffuseColor[2] << std::endl; std::cout << " ambient " << ambient << " * " << ambientColor[0] << " " << ambientColor[1] << " " << ambientColor[2] << std::endl; std::cout << " specular " << specular << " * " << specularColor[0] << " " << specularColor[1] << " " << specularColor[2] << std::endl; } PolygonChunkPtr polygonChunk = PolygonChunk::create(); beginEditCP(polygonChunk); { if (representation == VTK_SURFACE) { polygonChunk->setFrontMode(GL_FILL); polygonChunk->setBackMode(GL_FILL); } else if (representation == VTK_WIREFRAME) { polygonChunk->setFrontMode(GL_LINE); polygonChunk->setBackMode(GL_LINE); } else { polygonChunk->setFrontMode(GL_POINT); polygonChunk->setBackMode(GL_POINT); } } endEditCP(polygonChunk); MaterialChunkPtr osgMaterialChunk = MaterialChunk::create(); beginEditCP(osgMaterialChunk); { osgMaterialChunk->setDiffuse(Color4f(diffuseColor[0] * diffuse, diffuseColor[1] * diffuse, diffuseColor[2] * diffuse, opacity)); osgMaterialChunk->setSpecular(Color4f(specularColor[0] * specular, specularColor[1] * specular, specularColor[2] * specular, 1.0)); osgMaterialChunk->setAmbient(Color4f(ambientColor[0] * ambient, ambientColor[1] * ambient, ambientColor[2] * ambient, opacity)); osgMaterialChunk->setShininess(specularPower); //if(opacity < 1.0) //{ // osgMaterialChunk->setColorMaterial(GL_AMBIENT); // HACK: Opacity does not work with GL_AMBIENT_AND_DIFFUSE //osgMaterialChunk->setTransparency(1.0f - opacity); //} //else osgMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE); // On objects consisting only of points or lines, dont lit if(!lit) osgMaterialChunk->setLit(false); } endEditCP(osgMaterialChunk); ChunkMaterialPtr osgChunkMaterial = ChunkMaterial::create(); beginEditCP(osgChunkMaterial); { osgChunkMaterial->addChunk(osgMaterialChunk); osgChunkMaterial->addChunk(TwoSidedLightingChunk::create()); osgChunkMaterial->addChunk(polygonChunk); if(pointSize > 1.0f) { PointChunkPtr pointChunk = PointChunk::create(); pointChunk->setSize(pointSize); osgChunkMaterial->addChunk(pointChunk); } if(lineWidth > 1.0f) { LineChunkPtr lineChunk = LineChunk::create(); lineChunk->setWidth(lineWidth); osgChunkMaterial->addChunk(lineChunk); } // TEXTURE if (hasTexCoords) { vtkTexture* vtkTexture = _actor->GetTexture(); if (vtkTexture) { TextureChunkPtr osgTextureChunk = NullFC; osgTextureChunk = CreateTexture(vtkTexture); if(osgTextureChunk != NullFC) { if (_verbose) std::cout << " Add TextureChunk" << std::endl; osgChunkMaterial->addChunk(osgTextureChunk); } // Per default EnvMode is set to GL_REPLACE which does not lit the surface beginEditCP(osgTextureChunk); osgTextureChunk->setEnvMode(GL_MODULATE); endEditCP(osgTextureChunk); } } } endEditCP(osgChunkMaterial); if (_verbose) std::cout << "End CreateMaterial()" << std::endl; return osgChunkMaterial; }
// Initialize OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener); TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener); TutorialUpdateListener TheTutorialUpdateListener; TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(MainWindow); //Print key command info std::cout << "\n\nKEY COMMANDS:" << std::endl; std::cout << "space Play/Pause the animation" << std::endl; std::cout << "B Show/Hide the bind pose skeleton" << std::endl; std::cout << "SHIFT-B Show/Hide the bind pose mesh" << std::endl; std::cout << "P Show/Hide the current pose skeleton" << std::endl; std::cout << "SHIFT-P Show/Hide the current pose mesh" << std::endl; std::cout << "O Toggle override status of TheSecondAnimation" << std::endl; std::cout << "CTRL-Q Exit\n\n" << std::endl; //Import scene from XML ChunkMaterialPtr ExampleMaterial; std::vector<SkeletonPtr> SkeletonPtrs; std::vector<SkeletonBlendedGeometryPtr> SkeletonBlendedGeometryPtrs; std::vector<GeometryPtr> GeometryPtrs; //Skeleton materaial LineChunkPtr SkelLineChunk = LineChunk::create(); beginEditCP(SkelLineChunk); SkelLineChunk->setWidth(0.0f); SkelLineChunk->setSmooth(true); endEditCP(SkelLineChunk); ChunkMaterialPtr SkelMaterial = ChunkMaterial::create(); beginEditCP(SkelMaterial, ChunkMaterial::ChunksFieldMask); SkelMaterial->addChunk(SkelLineChunk); endEditCP(SkelMaterial, ChunkMaterial::ChunksFieldMask); //LOAD FIRST ANIMATION FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(BoostPath("./Data/23WalkingAnimation.xml")); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { if( (*Itor)->getType() == (ChunkMaterial::getClassType())) { //Set ExampleMaterial to the ChunkMaterial we just read in ExampleMaterial = (ChunkMaterial::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (Skeleton::getClassType())) { //Add the Skeleton we just read in to SkeletonPtrs SkeletonPtrs.push_back(Skeleton::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (SkeletonBlendedGeometry::getClassType())) { //Add the SkeletonBlendedGeometry we just read in to SkeletonBlendedGeometryPtrs SkeletonBlendedGeometryPtrs.push_back(SkeletonBlendedGeometry::Ptr::dcast(*Itor)); } if( (*Itor)->getType().isDerivedFrom(SkeletonAnimation::getClassType())) { //Set TheWalkingAnimation to the SkeletonAnimation we just read in TheWalkingAnimation = (SkeletonAnimation::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (Geometry::getClassType())) { //Add the Geometry we just read in to GeometryPtrs GeometryPtrs.push_back(Geometry::Ptr::dcast(*Itor)); } } //LOAD SECOND ANIMATION NewContainers = FCFileHandler::the()->read(BoostPath("./Data/23SamAnimation.xml")); for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { //Import only the skeletonAnimation from the second XML file; we've already imported the skeleton and the geometry if( (*Itor)->getType().isDerivedFrom(SkeletonAnimation::getClassType())) { TheSecondAnimation = (SkeletonAnimation::Ptr::dcast(*Itor)); } } //Blend the two animations TheSkeletonBlendedAnimation = SkeletonBlendedAnimation::create(); beginEditCP(TheSkeletonBlendedAnimation); TheSkeletonBlendedAnimation->addAnimationBlending(TheWalkingAnimation, BlendWalking, false); TheSkeletonBlendedAnimation->addAnimationBlending(TheSecondAnimation, BlendTouchScreen, false); endEditCP(TheSkeletonBlendedAnimation); //Create unbound geometry Node (to show the mesh in its bind pose) for (int i(0); i < GeometryPtrs.size(); ++i) { NodePtr UnboundGeometry = Node::create(); beginEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask); UnboundGeometry->setCore(GeometryPtrs[i]); UnboundGeometry->setTravMask(0); //By default, we don't show the mesh in its bind pose. endEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask); UnboundGeometries.push_back(UnboundGeometry); } //Create skeleton nodes for (int i(0); i < SkeletonPtrs.size(); ++i) { //SkeletonDrawer SkeletonDrawablePtr ExampleSkeletonDrawable = osg::SkeletonDrawable::create(); beginEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask); ExampleSkeletonDrawable->setSkeleton(SkeletonPtrs[i]); ExampleSkeletonDrawable->setMaterial(SkelMaterial); ExampleSkeletonDrawable->setDrawPose(true); //By default we draw the current skeleton ExampleSkeletonDrawable->setPoseColor(Color4f(1.0, 0.0, 1.0, 1.0)); //Set color of current skeleton ExampleSkeletonDrawable->setDrawBindPose(false); //By default we don't draw the bind pose skeleton ExampleSkeletonDrawable->setBindPoseColor(Color4f(1.0, 1.0, 0.0, 1.0)); //Set color of bind pose skeleton endEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask); //Skeleton Node NodePtr SkeletonNode = osg::Node::create(); beginEditCP(SkeletonNode, Node::CoreFieldMask); SkeletonNode->setCore(ExampleSkeletonDrawable); endEditCP(SkeletonNode, Node::CoreFieldMask); SkeletonNodes.push_back(SkeletonNode); } //Create skeleton blended geometry nodes for (int i(0); i < SkeletonBlendedGeometryPtrs.size(); ++i) { NodePtr MeshNode = osg::Node::create(); beginEditCP(MeshNode, Node::CoreFieldMask); MeshNode->setCore(SkeletonBlendedGeometryPtrs[i]); endEditCP(MeshNode, Node::CoreFieldMask); MeshNodes.push_back(MeshNode); } //Setup scene NodePtr EmptyScene = osg::Node::create(); beginEditCP(EmptyScene, Node::CoreFieldMask); EmptyScene->setCore(Group::create()); endEditCP (EmptyScene, Node::CoreFieldMask); mgr->setRoot(EmptyScene); //User Interface // Create the Graphics GraphicsPtr TutorialGraphics = osg::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); // Create the DefaultBoundedRangeModelPtr and // set its values DefaultBoundedRangeModelPtr UpperAnimationSliderRangeModel = DefaultBoundedRangeModel::create(); UpperAnimationSliderRangeModel->setMinimum(0); UpperAnimationSliderRangeModel->setMaximum(100); UpperAnimationSliderRangeModel->setValue(BlendWalking * 100); UpperAnimationSliderRangeModel->setExtent(0); //Create the upper animation blend amount slider LabelPtr TempLabel; SliderPtr UpperAnimationSlider = Slider::create(); beginEditCP(UpperAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask); //Label the slider TempLabel = Label::Ptr::dcast(UpperAnimationSlider->getLabelPrototype()->shallowCopy()); beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("0.0"); endEditCP(TempLabel, Label::TextFieldMask); UpperAnimationSlider->getLabelMap()[0] = TempLabel; TempLabel = Label::Ptr::dcast(UpperAnimationSlider->getLabelPrototype()->shallowCopy()); beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("1.0"); endEditCP(TempLabel, Label::TextFieldMask); UpperAnimationSlider->getLabelMap()[100] = TempLabel; //Customize the slider UpperAnimationSlider->setPreferredSize(Vec2f(100, 300)); UpperAnimationSlider->setSnapToTicks(false); UpperAnimationSlider->setMajorTickSpacing(10); UpperAnimationSlider->setMinorTickSpacing(5); UpperAnimationSlider->setOrientation(Slider::VERTICAL_ORIENTATION); UpperAnimationSlider->setInverted(true); UpperAnimationSlider->setDrawLabels(true); UpperAnimationSlider->setRangeModel(UpperAnimationSliderRangeModel); endEditCP(UpperAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask); DefaultBoundedRangeModelPtr LowerAnimationSliderRangeModel = DefaultBoundedRangeModel::create(); LowerAnimationSliderRangeModel->setMinimum(0); LowerAnimationSliderRangeModel->setMaximum(100); LowerAnimationSliderRangeModel->setValue(BlendTouchScreen * 100); LowerAnimationSliderRangeModel->setExtent(0); //Create the lower animation blend amount slider SliderPtr LowerAnimationSlider = Slider::create(); beginEditCP(LowerAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask); //Label the slider TempLabel = Label::Ptr::dcast(LowerAnimationSlider->getLabelPrototype()->shallowCopy()); beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("0.0"); endEditCP(TempLabel, Label::TextFieldMask); LowerAnimationSlider->getLabelMap()[0] = TempLabel; TempLabel = Label::Ptr::dcast(LowerAnimationSlider->getLabelPrototype()->shallowCopy()); beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("1.0"); endEditCP(TempLabel, Label::TextFieldMask); LowerAnimationSlider->getLabelMap()[100] = TempLabel; //Customize the slider LowerAnimationSlider->setPreferredSize(Vec2f(100, 300)); LowerAnimationSlider->setSnapToTicks(false); LowerAnimationSlider->setMajorTickSpacing(10); LowerAnimationSlider->setMinorTickSpacing(5); LowerAnimationSlider->setOrientation(Slider::VERTICAL_ORIENTATION); LowerAnimationSlider->setInverted(true); LowerAnimationSlider->setDrawLabels(true); LowerAnimationSlider->setRangeModel(LowerAnimationSliderRangeModel); endEditCP(LowerAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask); // Create Background to be used with the MainFrame ColorLayerPtr MainFrameBackground = osg::ColorLayer::create(); beginEditCP(MainFrameBackground, ColorLayer::ColorFieldMask); MainFrameBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); endEditCP(MainFrameBackground, ColorLayer::ColorFieldMask); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerPtr MainInternalWindowBackground = osg::ColorLayer::create(); beginEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); endEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); LayoutPtr MainInternalWindowLayout = osg::FlowLayout::create(); //GL Viewport ComponentPtr TheGLViewport = createGLPanel(); InternalWindowPtr MainInternalWindow = osg::InternalWindow::create(); beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); MainInternalWindow->getChildren().push_back(UpperAnimationSlider); MainInternalWindow->getChildren().push_back(LowerAnimationSlider); MainInternalWindow->getChildren().push_back(TheGLViewport); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(1.0f,1.0f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); endEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); // Create the Drawing Surface UIDrawingSurfacePtr TutorialDrawingSurface = UIDrawingSurface::create(); beginEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindowEventProducer); endEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundPtr TutorialUIForeground = osg::UIForeground::create(); beginEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); endEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); TutorialViewport->getForegrounds().push_back(TutorialUIForeground); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); //Attach the Slider Listeners BlendAmountSliderChangeListener UpperAnimationSliderListener(TheSkeletonBlendedAnimation, 0, UpperAnimationSlider); UpperAnimationSlider->addChangeListener(&UpperAnimationSliderListener); BlendAmountSliderChangeListener LowerAnimationSliderListener(TheSkeletonBlendedAnimation, 1, LowerAnimationSlider); LowerAnimationSlider->addChangeListener(&LowerAnimationSliderListener); //Animation Advancer TheAnimationAdvancer = ElapsedTimeAnimationAdvancer::create(); beginEditCP(TheAnimationAdvancer); ElapsedTimeAnimationAdvancer::Ptr::dcast(TheAnimationAdvancer)->setStartTime( 0.0 ); beginEditCP(TheAnimationAdvancer); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene mgr->showAll(); TheAnimationAdvancer->start(); //Show window Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "23BlendXMLAnimations"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
void display(void) { float t = glutGet( GLUT_ELAPSED_TIME ); win->frameInit(); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); Matrix m; Quaternion q; q.setValueAsAxisDeg( 0,1,0, -t/20 ); m.setRotate( q ); tchunk1->setMatrix( m ); tchunk1->activate( dact ); mchunk1->activate( dact ); pchunk1->activate( dact ); lichunk1->activate( dact ); glCallList( dlid ); m.setIdentity(); m.setTranslate( cos(t/1000), 0, sin(t/1000) ); tchunk2->setMatrix( m ); pchunk2->changeFrom( dact, get_pointer(pchunk1) ); tchunk2->changeFrom( dact, get_pointer(tchunk1) ); mchunk2->changeFrom( dact, get_pointer(mchunk1) ); lichunk2->changeFrom( dact, get_pointer(lichunk1) ); blchunk->activate( dact ); glCallList( dlid ); tchunk2->deactivate( dact ); mchunk2->deactivate( dact ); pchunk2->deactivate( dact ); lichunk2->deactivate( dact ); blchunk->deactivate( dact ); xchunk1->activate( dact ); txchunk->activate( dact ); #if 0 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_PASS_THROUGH_NV); glTexEnvi(GL_TEXTURE_SHADER_NV, GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV,34102 ); glTexEnvf(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_SCALE_NV, 0.0000 ); glTexEnvf(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_BIAS_NV, 0.0000 ); glEnable(GL_TEXTURE_SHADER_NV); GLint consistent; glGetTexEnviv(GL_TEXTURE_SHADER_NV, GL_SHADER_CONSISTENT_NV, &consistent); if(!consistent) { FWARNING(("Texture shaders not consistent!\n")); } #endif glCallList( dlid2 ); // glDisable(GL_TEXTURE_SHADER_NV); xchunk1->deactivate( dact ); txchunk->deactivate( dact ); win->frameExit(); glutSwapBuffers(); }
int main( int argc, char *argv[] ) { osgInit(argc, argv); glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutCreateWindow("OpenSG"); glutKeyboardFunc(key); // glutReshapeFunc(resize); glutDisplayFunc(display); // glutMouseFunc(mouse); // glutMotionFunc(motion); glutIdleFunc(display); pImage = Image::create(); // create the dummy structures // the window is needed for the chunks that access GLObjects win = GLUTWindow::create(); win->frameInit(); // test for preliminary calls not messing up GLexts win->init(); dact = DrawAction::create(); dact->setWindow(get_pointer(win)); win->init(); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 60, 1, 0.1, 10 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); gluLookAt( 3, 3, 3, 0, 0, 0, 0, 1, 0 ); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); dlid = glGenLists( 1 ); glNewList( dlid, GL_COMPILE ); glutSolidSphere( .8, 8, 8 ); glEndList(); dlid2 = glGenLists( 1 ); glNewList( dlid2, GL_COMPILE ); glBegin( GL_POLYGON ); glNormal3f( 0, 1, 0 ); glColor3f( 1, 1, 1 ); glTexCoord2f( 0, 0 ); glVertex3f( -1.5, -1, -1.5 ); glTexCoord2f( 2, 0 ); glVertex3f( 1.5, -1, -1.5 ); glTexCoord2f( 2, 2 ); glVertex3f( 1.5, -1, 1.5 ); glTexCoord2f( 0, 2 ); glVertex3f( -1.5, -1, 1.5 ); glEnd(); glEndList(); Matrix m; tchunk1 = TransformChunk::create(); m.setTranslate( 0, 1, 0 ); tchunk1->setMatrix( m ); tchunk2 = TransformChunk::create(); tchunk2->setMatrix( Matrix::identity() ); mchunk1 = MaterialChunk::create(); mchunk1->setDiffuse( Color4f( 1,0,0,0 ) ); mchunk1->setAmbient( Color4f( 1,0,0,0 ) ); mchunk1->setShininess( 20 ); mchunk2 = MaterialChunk::create(); mchunk2->setDiffuse( Color4f( 0,1,0,0 ) ); mchunk2->setAmbient( Color4f( 0,1,0,0 ) ); mchunk2->setShininess( 50 ); // Texture chunk // UChar8 imgdata[] = // { 255,0,0,0, 0,255,0,0, 0,0,255,255, 255,255,255,255 }; UChar8 imgdata[] = { 255,0,0, 255,0,0, 255,0,255, 255,0,0, 255,0,0, 255,0,255, 255,255,0, 255,255,0, 255,255,255, 255,255,0, 255,255,0, 255,255,255, }; // UChar8 limgdata[] = // { 0, 128, 64, 255 }; pImage->set( Image::OSG_RGB_PF, 2, 2, 1, 1, 1, 0, imgdata ); if ( argc > 1 ) pImage->read( argv[1] ); xchunk1 = TextureChunk::create(); beginEditCP(xchunk1); xchunk1->setImage( pImage ); // NOTE: the image is NOT copied, the variable // needs to be kept around as long as the // texture is used xchunk1->setMinFilter( GL_LINEAR ); xchunk1->setMagFilter( GL_NEAREST ); xchunk1->setWrapS( GL_REPEAT ); xchunk1->setWrapT( GL_REPEAT ); xchunk1->setEnvMode( GL_REPLACE ); xchunk1->setEnvColor( Color4f(.5,.5,.5,0) ); xchunk1->setScale( false ); // xchunk1->setShaderOperation(GL_PASS_THROUGH_NV); endEditCP(xchunk1); xchunk1->imageContentChanged(); beginEditCP(xchunk1); xchunk1->setImage( pImage ); endEditCP(xchunk1); // blend chunk blchunk = BlendChunk::create(); #ifdef GL_EXT_blend_color blchunk->setSrcFactor( GL_CONSTANT_ALPHA ); blchunk->setDestFactor( GL_ONE_MINUS_CONSTANT_ALPHA ); #endif blchunk->setColor( Color4f( .5,.5,.5,0.1 ) ); blchunk->setEquation(GL_FUNC_SUBTRACT); std::cout << "BlendChunk is trans:" << blchunk->isTransparent() << std::endl; // texture transform chunk txchunk = TextureTransformChunk::create(); beginEditCP(txchunk); txchunk->setMatrix( Matrix(4,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1) ); endEditCP(txchunk); // polygon chunk pchunk1 = PolygonChunk::create(); { UInt32 stipple[32] = { 0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff }; pchunk1->editMFStipple()->clear(); for ( int i = 0; i < 32; i++ ) pchunk1->editMFStipple()->push_back( stipple[i] ); } pchunk1->setFrontMode(GL_LINE); pchunk1->setBackMode(GL_FILL); pchunk2 = PolygonChunk::create(); { UInt32 stipple[32] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }; pchunk2->editMFStipple()->clear(); for ( int i = 0; i < 32; i++ ) pchunk2->editMFStipple()->push_back( stipple[i] ); } lichunk1 = LineChunk::create(); lichunk1->setSmooth(true); lichunk1->setStipplePattern(0xf0f0); lichunk2 = LineChunk::create(); lichunk2->setStippleRepeat(5); lichunk2->setStipplePattern(0xaaaa); glutMainLoop(); return 0; }