void setupAnimation(void) { //Read animation data from XML file FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(BoostPath("./Data/15TestAnimations.xml")); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { if( (*Itor)->getType().isDerivedFrom(Animation::getClassType())) { //Set the animation to the one we just read in TheAnimation = (dynamic_pointer_cast<Animation>(*Itor)); } else if( (*Itor)->getType() == (SimpleMaterial::getClassType())) { //Set torus material TheTorusMaterial = (dynamic_pointer_cast<SimpleMaterial>(*Itor)); //Attach torus material to torus geometry TorusGeometry->setMaterial(TheTorusMaterial); } } TheAnimation->attachUpdateProducer(TutorialWindow->editEventProducer()); TheAnimation->start(); }
void handleTreeNodeExport(ActionEventDetails* const details, Tree* const editorTree) { boost::any SelectedComp(editorTree->getLastSelectedPathComponent()); //Get the tree selection try { FieldContainerTreeModel::ContainerFieldIdPair ThePair(boost::any_cast<FieldContainerTreeModel::ContainerFieldIdPair>(SelectedComp)); if(ThePair._FieldID == 0 && ThePair._Container != NULL) { std::vector<WindowEventProducer::FileDialogFilter> ExportFileFilters; ExportFileFilters.push_back(WindowEventProducer::FileDialogFilter("Field Container File","xml")); ExportFileFilters.push_back(WindowEventProducer::FileDialogFilter("All Files","*")); //Export File BoostPath InitialFilePath("./Export.xml"); WindowEventProducer* MainWindow(editorTree->getParentWindow()->getParentDrawingSurface()->getEventProducer()); BoostPath ExportFilePath; ExportFilePath =MainWindow->saveFileDialog("Save Field Container", ExportFileFilters, InitialFilePath.filename(), InitialFilePath.parent_path(), true); if(!ExportFilePath.empty()) { if(ExportFilePath.extension().empty()) { ExportFilePath = ExportFilePath.string() + ".xml"; } FCFileType::FCPtrStore Containers; Containers.insert(ThePair._Container); FCFileType::FCTypeVector IgnoreTypes; FCFileHandler::the()->write(Containers,ExportFilePath,IgnoreTypes); } } } catch(boost::bad_any_cast &ex) { SWARNING << ex.what() << std::endl; } }
DialogWindowTransitPtr loadCreditsWindow(const BoostPath& WindowDefinitionFile) { FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(WindowDefinitionFile); for(FCFileType::FCPtrStore::iterator Itor(NewContainers.begin()) ; Itor!= NewContainers.end() ; ++Itor) { if((*Itor)->getType() == DialogWindow::getClassType()) { return DialogWindowTransitPtr(dynamic_pointer_cast<DialogWindow>(*Itor)); } } SFATAL << "Failed to load Builder Credits Window definition from file: " << WindowDefinitionFile.string() << std::endl; return DialogWindowTransitPtr(NULL); }
XMLLookAndFeelUnrecPtr XMLLookAndFeel::create(const BoostPath& LoadFile) { XMLLookAndFeelUnrecPtr Result = NULL; if(boost::filesystem::exists(LoadFile)) { FCFileType::FCPtrStore Containers; Containers = FCFileHandler::the()->read(LoadFile); FCFileType::FCPtrStore::iterator ContainerItor; for(ContainerItor = Containers.begin(); ContainerItor != Containers.end(); ++ContainerItor) { if((*ContainerItor)->getType() == XMLLookAndFeel::getClassType()) { Result = dynamic_pointer_cast<XMLLookAndFeel>(*ContainerItor); break; } } } return Result; }
void LoadXML(std::string FilePath, std::vector<NodePtr>& RootNodes, std::vector<CameraPtr>& Cameras) { RootNodes.clear(); Cameras.clear(); std::cout << "Loading xml File: " << FilePath << std::endl; FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(Path(FilePath)); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { if( (*Itor)->getType() == Node::getClassType() && Node::Ptr::dcast(*Itor)->getParent() == NullFC) { RootNodes.push_back(Node::Ptr::dcast(*Itor)); } else if( (*Itor)->getType().isDerivedFrom( Camera::getClassType() )) { Cameras.push_back(Camera::Ptr::dcast(*Itor)); } } }
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; }
// Initialize WIN32 & OpenSG and set up the scene int main(int argc, char **argv) { std::cout << "\n\nKEY COMMANDS:" << std::endl << "1-9 Play Sounds 1-9" << std::endl << "p Pause Sounds" << std::endl << "u Unpause Sounds" << std::endl << "- Decrease Sound Group Volume" << std::endl << "= Increase Sound Group Volume" << std::endl << "CTRL-Q Exit\n\n" << std::endl; // OSG init osgInit(argc,argv); TheWindowEventProducer = createNativeWindow(); TheWindowEventProducer->initWindow(); TheWindowEventProducer->setDisplayCallback(display); TheWindowEventProducer->setReshapeCallback(reshape); //Attach Mouse Listener TutorialMouseListener TheTutorialMouseListener; MouseEventConnection = TheWindowEventProducer->addMouseListener(&TheTutorialMouseListener); //Attach Key Listener TutorialKeyListener TheTutorialKeyListener; TheWindowEventProducer->addKeyListener(&TheTutorialKeyListener); //Attach MouseMotion Listener TutorialMouseMotionListener TheTutorialMouseMotionListener; TheWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener); // create the scene NodeUnrecPtr scene = makeTorus(1.0, 2.0, 16, 16); // create the SimpleSceneManager helper mgr = new SimpleSceneManager; // tell the manager what to manage mgr->setWindow(TheWindowEventProducer ); mgr->setRoot (scene); // show the whole scene mgr->showAll(); //Load Sound Definitions FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(BoostPath("Data/04SoundData.xml")); FCFileType::FCPtrStore::iterator Itor; TutorialSoundListener TheSoundListerner; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { //Get Sounds if( (*Itor)->getType().isDerivedFrom(Sound::getClassType())) { Sounds.push_back(dynamic_pointer_cast<Sound>(*Itor)); dynamic_pointer_cast<Sound>(*Itor)->addSoundListener(&TheSoundListerner); } //Get Sound Groups if( (*Itor)->getType().isDerivedFrom(SoundGroup::getClassType())) { SoundGroups.push_back(dynamic_pointer_cast<SoundGroup>(*Itor)); } } //Initialize the Sound Manager SoundManager::the()->attachUpdateProducer(TheWindowEventProducer); SoundManager::the()->setCamera(mgr->getCamera()); Vec2f WinSize(TheWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TheWindowEventProducer->getDesktopSize() - WinSize) *0.5); TheWindowEventProducer->openWindow(WinPos, WinSize, "04 XML Sound Loading Window"); //Enter main loop TheWindowEventProducer->mainLoop(); osgExit(); return 0; }
// Initialize GLUT & 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); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindowEventProducer->getWindow()); Path FBOFilePath; if(argc < 2) { FWARNING(("No FBO file given!\n")); FBOFilePath = Path("./Data/01LoadFBO.xml"); } else { FBOFilePath = Path(std::string(argv[1])); } std::cout << "Loading xml File: " << FBOFilePath << std::endl; FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(FBOFilePath); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { if( (*Itor)->getType() == FBOViewport::getClassType()) { TheFBOViewport = FBOViewport::Ptr::dcast(*Itor); } } ChunkMaterialPtr BoxMaterial = ChunkMaterial::create(); GeometryPtr BoxGeoCore = makeBoxGeo(1.0,1.0,1.0,2,2,2); beginEditCP(BoxGeoCore, Geometry::MaterialFieldMask); BoxGeoCore->setMaterial(BoxMaterial); endEditCP(BoxGeoCore, Geometry::MaterialFieldMask); NodePtr BoxGeoNode = Node::create(); beginEditCP(BoxGeoNode, Node::CoreFieldMask); BoxGeoNode->setCore(BoxGeoCore); endEditCP(BoxGeoNode, Node::CoreFieldMask); NodePtr SceneNode = Node::create(); beginEditCP(SceneNode, Node::CoreFieldMask | Node::ChildrenFieldMask); SceneNode->setCore(Group::create()); SceneNode->addChild(BoxGeoNode); endEditCP(SceneNode, Node::CoreFieldMask | Node::ChildrenFieldMask); // tell the manager what to manage mgr->setRoot (SceneNode); // show the whole scene mgr->showAll(); if(TheFBOViewport != NullFC) { //Add the texture chunk of the FBO to the Material for the box beginEditCP(BoxMaterial, ChunkMaterial::ChunksFieldMask); BoxMaterial->addChunk(TheFBOViewport->editTextures(0)); endEditCP(BoxMaterial, ChunkMaterial::ChunksFieldMask); //Add The FBO Viewport the the Window beginEditCP(TheFBOViewport, FBOViewport::ParentFieldMask); TheFBOViewport->setParent(TutorialWindowEventProducer->getWindow()); endEditCP(TheFBOViewport, FBOViewport::ParentFieldMask); beginEditCP(TutorialWindowEventProducer->getWindow()); ViewportPtr vp = TutorialWindowEventProducer->getWindow()->getPort(0); addRefCP(vp); TutorialWindowEventProducer->getWindow()->subPort(0); //Put the FBO Vieport in front, so it is rendered first TutorialWindowEventProducer->getWindow()->addPort(TheFBOViewport); TutorialWindowEventProducer->getWindow()->addPort(vp ); endEditCP (TutorialWindowEventProducer->getWindow()); } Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "07LoadFBO"); //Main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); NodeRecPtr Root(NULL); if(argc == 2) { Root = SceneFileHandler::the()->read(argv[1]); } if(Root == NULL) { // Make Torus Node (creates Torus in background of Root) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); NodeRecPtr TorusNode = Node::create(); TorusNode->setCore(Transform::create()); TorusNode->addChild(TorusGeometryNode); NodeRecPtr SphereGeometryNode = makeSphere(2,1.0f); NodeRecPtr BoxGeometryNode = makeBox(1.0,1.0,1.0,1,1,1); // Make Main Scene Node and add the Torus Root = Node::create(); Root->setCore(Group::create()); Root->addChild(TorusNode); Root->addChild(SphereGeometryNode); Root->addChild(BoxGeometryNode); } // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); //Import InternalWindow(s) from XML file std::vector<InternalWindowRecPtr> StoreWindows; FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(BoostPath("./Data/55ComponentTree.xml")); //Store each window found in the XML in the vector FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin(); Itor != NewContainers.end(); ++Itor) { if( (*Itor)->getType() == (InternalWindow::getClassType())) { StoreWindows.push_back(dynamic_pointer_cast<InternalWindow>(*Itor)); } } //Tree Model FieldContainerTreeModelRecPtr TheTreeModel = FieldContainerTreeModel::create(); TheTreeModel->setRoot(StoreWindows.front()); //TheTreeModel->setShowPtrFields(false); //TheTreeModel->setShowDataFields(false); //TheTreeModel->setShowParentPtrFields(false); //TheTreeModel->setShowChildPtrFields(false); TheTreeModel->setShowAttachments(false); //TheTreeModel->setShowCallbackFunctors(false); //Tree Component Generator FieldContainerFieldPathComponentGeneratorRecPtr TheTreeComponentGenerator = FieldContainerFieldPathComponentGenerator::create(); //Create the Tree TreeRecPtr TheTree = Tree::create(); TheTree->setPreferredSize(Vec2f(100, 500)); TheTree->setRootVisible(true); TheTree->setModel(TheTreeModel); TheTree->setCellGenerator(TheTreeComponentGenerator); setName(TheTree, std::string("TheTree")); // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel) ScrollPanelRecPtr ExampleScrollPanel = ScrollPanel::create(); ExampleScrollPanel->setPreferredSize(Vec2f(350,500)); //ExampleScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); //ExampleScrollPanel->setVerticalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); ExampleScrollPanel->setViewComponent(TheTree); setName(ExampleScrollPanel, std::string("ExampleScrollPanel")); //Show Buttons CheckboxButtonRecPtr ShowMultiFieldsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowSingleFieldsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowPtrFieldsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowDataFieldsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowParentPtrFieldsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowChildPtrFieldsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowAttachmentsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowCallbackFunctorsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowInternalFieldsButton = CheckboxButton::create(); ShowMultiFieldsButton->setText("Multi Fields"); ShowMultiFieldsButton->setPreferredSize(Vec2f(120.0f,ShowMultiFieldsButton->getPreferredSize().y())); ShowMultiFieldsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowSingleFieldsButton->setText("Single Fields"); ShowSingleFieldsButton->setPreferredSize(Vec2f(120.0f,ShowSingleFieldsButton->getPreferredSize().y())); ShowSingleFieldsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowPtrFieldsButton->setText("Ptr Fields"); ShowPtrFieldsButton->setPreferredSize(Vec2f(120.0f,ShowPtrFieldsButton->getPreferredSize().y())); ShowPtrFieldsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowDataFieldsButton->setText("Data Fields"); ShowDataFieldsButton->setPreferredSize(Vec2f(120.0f,ShowDataFieldsButton->getPreferredSize().y())); ShowDataFieldsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowParentPtrFieldsButton->setText("ParentPtr Fields"); ShowParentPtrFieldsButton->setPreferredSize(Vec2f(120.0f,ShowParentPtrFieldsButton->getPreferredSize().y())); ShowParentPtrFieldsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowChildPtrFieldsButton->setText("ChildPtr Fields"); ShowChildPtrFieldsButton->setPreferredSize(Vec2f(120.0f,ShowChildPtrFieldsButton->getPreferredSize().y())); ShowChildPtrFieldsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowAttachmentsButton->setText("Attachments"); ShowAttachmentsButton->setPreferredSize(Vec2f(120.0f,ShowAttachmentsButton->getPreferredSize().y())); ShowAttachmentsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowCallbackFunctorsButton->setText("Callback Functors"); ShowCallbackFunctorsButton->setPreferredSize(Vec2f(120.0f,ShowCallbackFunctorsButton->getPreferredSize().y())); ShowCallbackFunctorsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowInternalFieldsButton->setText("Internal Fields"); ShowInternalFieldsButton->setPreferredSize(Vec2f(120.0f,ShowInternalFieldsButton->getPreferredSize().y())); ShowInternalFieldsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowCheckboxesController CheckboxesController(TheTreeModel, ShowMultiFieldsButton, ShowSingleFieldsButton, ShowPtrFieldsButton, ShowDataFieldsButton, ShowParentPtrFieldsButton, ShowChildPtrFieldsButton, ShowAttachmentsButton, ShowCallbackFunctorsButton, ShowInternalFieldsButton); PanelRecPtr OptionsPanel = Panel::create(); FlowLayoutRecPtr OptionsPanelLayout = FlowLayout::create(); OptionsPanel->setLayout(OptionsPanelLayout); OptionsPanel->setPreferredSize(Vec2f(250.0f, 300.0f)); OptionsPanel->pushToChildren(ShowMultiFieldsButton); OptionsPanel->pushToChildren(ShowSingleFieldsButton); OptionsPanel->pushToChildren(ShowPtrFieldsButton); OptionsPanel->pushToChildren(ShowDataFieldsButton); OptionsPanel->pushToChildren(ShowInternalFieldsButton); OptionsPanel->pushToChildren(ShowParentPtrFieldsButton); OptionsPanel->pushToChildren(ShowChildPtrFieldsButton); OptionsPanel->pushToChildren(ShowAttachmentsButton); OptionsPanel->pushToChildren(ShowCallbackFunctorsButton); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleScrollPanel); MainInternalWindow->pushToChildren(OptionsPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.85f,0.85f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); setName(MainInternalWindow, std::string("MainInternalWindow")); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); TutorialDrawingSurface->openWindow(StoreWindows.back()); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(Root); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "56FieldContainerTree"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); //Print key command info std::cout << "\n\nKEY COMMANDS:" << std::endl; std::cout << "CTRL-Q Exit\n\n" << std::endl; //SkeletonDrawer System Material LineChunkUnrecPtr ExampleLineChunk = LineChunk::create(); ExampleLineChunk->setWidth(2.0f); ExampleLineChunk->setSmooth(true); BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create(); ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA); ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create(); ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f)); ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f)); ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f)); ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create(); ExampleMaterial->addChunk(ExampleLineChunk); ExampleMaterial->addChunk(ExampleMaterialChunk); ExampleMaterial->addChunk(ExampleBlendChunk); //Joint Node Hierarchy NodeRecPtr ExampleJointNode; //Create a new skeleton SkeletonBlendedGeometryRecPtr ExampleSkeleton; //Load skeleton from an XML file FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(BoostPath("./Data/14Skeleton.xml")); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { //We only want the skeleton; ignore anything else saved in the XML file if( (*Itor)->getType() == (SkeletonBlendedGeometry::getClassType())) { ExampleSkeleton = (dynamic_pointer_cast<SkeletonBlendedGeometry>(*Itor)); } if( (*Itor)->getType() == (Node::getClassType()) && (dynamic_pointer_cast<Node>(*Itor)->getParent() == NULL)) { ExampleJointNode = (dynamic_pointer_cast<Node>(*Itor)); } } //SkeletonDrawer SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create(); ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton); ExampleSkeletonDrawable->setMaterial(ExampleMaterial); //Skeleton Node NodeUnrecPtr SkeletonNode = Node::create(); SkeletonNode->setCore(ExampleSkeletonDrawable); // Make Main Scene Node and add the Torus NodeUnrecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(SkeletonNode); mgr->setRoot(scene); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "14SkeletonLoader"); //Main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); //Add Key Listener TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); //Add Mouse Listeners TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); // open window /* Set up complete, now performing XML import */ BoostPath ExecutableDirectory(argv[0]); ExecutableDirectory.remove_leaf(); BoostPath FilePath; if(argc > 1) { FilePath = BoostPath(argv[1]); } else { FilePath = BoostPath("./Data/mayaExport1.xml"); } if(!boost::filesystem::exists(FilePath)) { std::cerr << "Could not find file by path: " << FilePath.string() << std::endl; osgExit(); return -1; } // parse XML file to get field container data FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(FilePath); // find root node from container, attach update listeners to particle systems std::vector<NodeRefPtr> RootNodes; for(FCFileType::FCPtrStore::iterator Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { // get root node if( (*Itor)->getType() == Node::getClassType() && dynamic_pointer_cast<Node>(*Itor)->getParent() == NULL) { RootNodes.push_back(dynamic_pointer_cast<Node>(*Itor)); } else if( (*Itor)->getType() == ParticleSystem::getClassType()) //attach update listeners to particle systems present { ParticleSystemRefPtr ExampleParticleSystems = dynamic_pointer_cast<ParticleSystem>(*Itor); ExampleParticleSystems->attachUpdateListener(TutorialWindow); } } // get root node that was extracted from XML file if(RootNodes.size() > 0) { NodeRefPtr scene = RootNodes[0]; // set root node mgr->setRoot(scene); } // Show the whole Scene mgr->showAll(); mgr->setHeadlight(true); mgr->getCamera()->setFar(10000); // main loop //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "15FCFileTypeIO"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); //Attach to events TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); //Particle System Material PointChunkRefPtr PSPointChunk = PointChunk::create(); PSPointChunk->setSize(20.0f); PSPointChunk->setSmooth(true); BlendChunkRefPtr PSBlendChunk = BlendChunk::create(); PSBlendChunk->setSrcFactor(GL_SRC_ALPHA); PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create(); PSMaterialChunkChunk->setAmbient(Color4f(0.2f,0.6f,0.5f,0.3f)); PSMaterialChunkChunk->setDiffuse(Color4f(0.2f,0.9f,0.1f,0.3f)); PSMaterialChunkChunk->setSpecular(Color4f(0.5f,0.4f,0.2f,0.6f)); PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE); //enable depth test DepthChunkRefPtr PSDepthChunk = DepthChunk::create(); ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(PSPointChunk); PSMaterial->addChunk(PSMaterialChunkChunk); PSMaterial->addChunk(PSBlendChunk); PSMaterial->addChunk(PSDepthChunk); LineChunkRefPtr PSLineChunk = LineChunk::create(); ChunkMaterialRefPtr TestMaterial = ChunkMaterial::create(); //TestMaterial->addChunk(PointChunk::create()); //TestMaterial->addChunk(LineChunk::create()); TestMaterial->addChunk(PSMaterialChunkChunk); PolygonChunkRefPtr ThePolygonChunk = PolygonChunk::create(); BlendChunkRefPtr TheBlendChunk = BlendChunk::create(); DepthChunkRefPtr TheDepthChunk = DepthChunk::create(); TestMaterial->addChunk(ThePolygonChunk); TestMaterial->addChunk(TheBlendChunk); TestMaterial->addChunk(TheDepthChunk); //Particle System ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create(); ExampleParticleSystem->attachUpdateProducer(TutorialWindow); ExampleParticleSystem->addParticle(Pnt3f(-40.0,0.0,0.0), Vec3f(0.0,1.0,0.0), Color4f(1.0,1.0,1.0,1.0), Vec3f(1.0,1.0,1.0), -1, Vec3f(0.0,0.0,0.0), Vec3f(0.0,0.0,0.0)); ExampleParticleSystem->addParticle(Pnt3f(40.0,0.0,0.0), Vec3f(0.0,1.0,0.0), Color4f(1.0,1.0,1.0,1.0), Vec3f(1.0,1.0,1.0), -1, Vec3f(0.0,0.0,0.0), Vec3f(0.0,0.0,0.0)); PointParticleSystemDrawerRecPtr ExamplePointParticleSystemDrawer = PointParticleSystemDrawer::create(); ExamplePointParticleSystemDrawer->setForcePerParticleSizing(false); Matrix ExampleMatrix; ExampleMatrix.setTransform(Vec3f(10.0,10.0,10.0)); TransformRefPtr ExampleXform = Transform::create(); ExampleXform->setMatrix(ExampleMatrix); NodeRefPtr ExampleNode = Node::create(); ExampleNode->setCore(ExampleXform); RateParticleGeneratorRecPtr ExampleGenerator = RateParticleGenerator::create(); // ExampleGenerator->setEmitInWorldSpace(true); ExampleGenerator->setBeacon(ExampleNode); ExampleGenerator->setGenerationRate(5.0); ExampleGenerator->setPositionDistribution(createPositionDistribution()); ExampleGenerator->setLifespanDistribution(createLifespanDistribution()); NewtonParticleAffectorRefPtr ExampleAffector = NewtonParticleAffector::create(); ExampleAffector->setBeacon(ExampleNode); ExampleAffector->setMaxDistance(-1.0); ConditionalParticleAffectorRecPtr ExampleConditionalAffector = ConditionalParticleAffector::create(); ExampleConditionalAffector->setConditionalAttribute("active"); ExampleConditionalAffector->setConditionalOperator(4); //greater than ExampleConditionalAffector->setConditionalValue(0); // testing if the value associated with "test" = 1 ExampleConditionalAffector->pushToAffectors(ExampleAffector); DistanceAttractRepelParticleAffectorRefPtr ExampleAttractRepelAffector = DistanceAttractRepelParticleAffector::create(); ExampleAttractRepelAffector->setDistanceFromSource(DistanceParticleAffector::DISTANCE_FROM_NODE); //Attach the Generators and affectors to the Particle System ExampleParticleSystem->setBeacon(ExampleNode); //ExampleParticleSystem->pushToGenerators(ExampleGenerator); ExampleParticleSystem->pushToAffectors(ExampleConditionalAffector); // ExampleParticleSystem->pushToAffectors(ExampleAttractRepelAffector); ExampleParticleSystem->setMaxParticles(1000); ExampleParticleSystem->setDynamic(true); //Particle System Core ParticleSystemCoreRecPtr ParticleNodeCore = ParticleSystemCore::create(); ParticleNodeCore->setSystem(ExampleParticleSystem); ParticleNodeCore->setDrawer(ExamplePointParticleSystemDrawer); ParticleNodeCore->setMaterial(PSMaterial); ParticleNodeCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT); NodeRefPtr PSNode = Node::create(); PSNode->setCore(ParticleNodeCore); // Make Main Scene Node and add the Torus NodeRefPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(PSNode); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager, ParticleNodeCore.get(), ExamplePointParticleSystemDrawer.get(), ExampleParticleSystem.get(), ExampleConditionalAffector.get())); sceneManager.setRoot(scene); // Show the whole Scene sceneManager.showAll(); sceneManager.getCamera()->setFar(1000.0); sceneManager.getCamera()->setNear(0.10); FCFileType::FCPtrStore Containers; Containers.insert(scene); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "16FullTest"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); //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 << "CTRL-Q Exit\n\n" << std::endl; //SkeletonDrawer System Material LineChunkUnrecPtr ExampleLineChunk = LineChunk::create(); ExampleLineChunk->setWidth(2.0f); ExampleLineChunk->setSmooth(true); BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create(); ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA); ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create(); ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f)); ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f)); ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f)); ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create(); ExampleMaterial->addChunk(ExampleLineChunk); ExampleMaterial->addChunk(ExampleMaterialChunk); ExampleMaterial->addChunk(ExampleBlendChunk); //Skeleton ExampleSkeleton = SkeletonBlendedGeometry::create(); //===========================================Joints================================================================== Matrix TempMat; Matrix InvBind; /*================================================================================================*/ /* Pelvis */ Pelvis = Joint::create(); //create a joint called Pelvis TempMat.setTranslate(0.0,7.0,0.0); Pelvis->setJointTransformation(TempMat); NodeRecPtr PelvisNode = makeNodeFor(Pelvis); InvBind = PelvisNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(Pelvis, InvBind); setName(Pelvis, "Pelvis Joint"); setName(PelvisNode, "Pelvis Node"); /*================================================================================================*/ /* Clavicle */ Clavicle = Joint::create(); //create a joint called Clavicle TempMat.setTranslate(0.0,5.0,0.0); Clavicle->setJointTransformation(TempMat); NodeRecPtr ClavicleNode = makeNodeFor(Clavicle); PelvisNode->addChild(ClavicleNode); InvBind = ClavicleNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(Clavicle, InvBind); setName(Clavicle, "Clavicle Joint"); setName(ClavicleNode, "Clavicle Node"); /*================================================================================================*/ /* Left Shoulder */ LeftShoulder = Joint::create(); //create a joint called LeftShoulder TempMat.setTranslate(1.0,-0.5,0.0); LeftShoulder->setJointTransformation(TempMat); NodeRecPtr LeftShoulderNode = makeNodeFor(LeftShoulder); ClavicleNode->addChild(LeftShoulderNode); InvBind = LeftShoulderNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(LeftShoulder, InvBind); setName(LeftShoulder, "Left Shoulder Joint"); setName(LeftShoulderNode, "Left Shoulder Node"); /*================================================================================================*/ /* Left Elbow */ LeftElbow = Joint::create(); //create a joint called LeftElbow TempMat.setTranslate(2.0,0.0,0.0); LeftElbow->setJointTransformation(TempMat); NodeRecPtr LeftElbowNode = makeNodeFor(LeftElbow); LeftShoulderNode->addChild(LeftElbowNode); InvBind = LeftElbowNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(LeftElbow, InvBind); setName(LeftElbow, "Left Elbow Joint"); setName(LeftElbowNode, "Left Elbow Node"); /*================================================================================================*/ /* Left Hand */ LeftHand = Joint::create(); //create a joint called LeftHand TempMat.setTranslate(2.0,0.0,0.0); LeftHand->setJointTransformation(TempMat); NodeRecPtr LeftHandNode = makeNodeFor(LeftHand); LeftElbowNode->addChild(LeftHandNode); InvBind = LeftHandNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(LeftHand, InvBind); setName(LeftHand, "Left Hand Joint"); setName(LeftHandNode, "Left Hand Node"); /*================================================================================================*/ /* Left Fingers */ LeftFingers = Joint::create(); //create a joint called LeftFingers TempMat.setTranslate(1.0,0.0,0.0); LeftFingers->setJointTransformation(TempMat); NodeRecPtr LeftFingersNode = makeNodeFor(LeftFingers); LeftHandNode->addChild(LeftFingersNode); InvBind = LeftFingersNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(LeftFingers, InvBind); setName(LeftFingers, "Left Fingers Joint"); setName(LeftFingersNode, "Left Fingers Node"); /*================================================================================================*/ /* Right Shoulder */ RightShoulder = Joint::create(); //create a joint called RightShoulder TempMat.setTranslate(-1.0,-0.5,0.0); RightShoulder->setJointTransformation(TempMat); NodeRecPtr RightShoulderNode = makeNodeFor(RightShoulder); ClavicleNode->addChild(RightShoulderNode); InvBind = RightShoulderNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(RightShoulder, InvBind); setName(RightShoulder, "Right Shoulder Joint"); setName(RightShoulderNode, "Right Shoulder Node"); /*================================================================================================*/ /* Right Elbow */ RightElbow = Joint::create(); //create a joint called RightElbow TempMat.setTranslate(-2.0,0.0,0.0); RightElbow->setJointTransformation(TempMat); NodeRecPtr RightElbowNode = makeNodeFor(RightElbow); RightShoulderNode->addChild(RightElbowNode); InvBind = RightElbowNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(RightElbow, InvBind); setName(RightElbow, "Right Elbow Joint"); setName(RightElbowNode, "Right Elbow Node"); /*================================================================================================*/ /* Right Hand */ RightHand = Joint::create(); //create a joint called RightHand TempMat.setTranslate(-2.0,0.0,0.0); RightHand->setJointTransformation(TempMat); NodeRecPtr RightHandNode = makeNodeFor(RightHand); RightElbowNode->addChild(RightHandNode); InvBind = RightHandNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(RightHand, InvBind); setName(RightHand, "Right Hand Joint"); setName(RightHandNode, "Right Hand Node"); /*================================================================================================*/ /* Right Fingers */ RightFingers = Joint::create(); //create a joint called RightFingers TempMat.setTranslate(-1.0,0.0,0.0); RightFingers->setJointTransformation(TempMat); NodeRecPtr RightFingersNode = makeNodeFor(RightFingers); RightHandNode->addChild(RightFingersNode); InvBind = RightFingersNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(RightFingers, InvBind); setName(RightFingers, "Right Fingers Joint"); setName(RightFingersNode, "Right Fingers Node"); /*================================================================================================*/ /* Head */ Head = Joint::create(); //create a joint called Head TempMat.setTranslate(0.0,1.0,0.0); Head->setJointTransformation(TempMat); NodeRecPtr HeadNode = makeNodeFor(Head); ClavicleNode->addChild(HeadNode); InvBind = HeadNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(Head, InvBind); setName(Head, "Head Joint"); setName(HeadNode, "Head Node"); /*================================================================================================*/ /* Left Hip */ LeftHip = Joint::create(); //create a joint called LeftHip TempMat.setTranslate(1.0,-1.0,0.0); LeftHip->setJointTransformation(TempMat); NodeRecPtr LeftHipNode = makeNodeFor(LeftHip); PelvisNode->addChild(LeftHipNode); InvBind = LeftHipNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(LeftHip, InvBind); setName(LeftHip, "Left Hip Joint"); setName(LeftHipNode, "Left Hip Node"); /*================================================================================================*/ /* Left Knee */ LeftKnee = Joint::create(); //create a joint called LeftKnee TempMat.setTranslate(0.0,-3.0,0.0); LeftKnee->setJointTransformation(TempMat); NodeRecPtr LeftKneeNode = makeNodeFor(LeftKnee); LeftHipNode->addChild(LeftKneeNode); InvBind = LeftKneeNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(LeftKnee, InvBind); setName(LeftKnee, "Left Knee Joint"); setName(LeftKneeNode, "Left Knee Node"); /*================================================================================================*/ /* Left Foot */ LeftFoot = Joint::create(); //create a joint called LeftFoot TempMat.setTranslate(0.0,-3.0,0.0); LeftFoot->setJointTransformation(TempMat); NodeRecPtr LeftFootNode = makeNodeFor(LeftFoot); LeftKneeNode->addChild(LeftFootNode); InvBind = LeftFootNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(LeftFoot, InvBind); setName(LeftFoot, "Left Foot Joint"); setName(LeftFootNode, "Left Foot Node"); /*================================================================================================*/ /* Left Toes */ LeftToes = Joint::create(); //create a bone called ExampleChildbone TempMat.setTranslate(0.0,0.0,1.0); LeftToes->setJointTransformation(TempMat); NodeRecPtr LeftToesNode = makeNodeFor(LeftToes); LeftFootNode->addChild(LeftToesNode); InvBind = LeftToesNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(LeftToes, InvBind); setName(LeftToes, "Left Toes Joint"); setName(LeftToesNode, "Left Toes Node"); /*================================================================================================*/ /* Right Hip */ RightHip = Joint::create(); //create a joint called RightHip TempMat.setTranslate(-1.0,-1.0,0.0); RightHip->setJointTransformation(TempMat); NodeRecPtr RightHipNode = makeNodeFor(RightHip); PelvisNode->addChild(RightHipNode); InvBind = RightHipNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(RightHip, InvBind); setName(RightHip, "Right Hip Joint"); setName(RightHipNode, "Right Hip Node"); /*================================================================================================*/ /* Right Knee */ RightKnee = Joint::create(); //create a joint called RightKnee TempMat.setTranslate(0.0,-3.0,0.0); RightKnee->setJointTransformation(TempMat); NodeRecPtr RightKneeNode = makeNodeFor(RightKnee); RightHipNode->addChild(RightKneeNode); InvBind = RightKneeNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(RightKnee, InvBind); setName(RightKnee, "Right Knee Joint"); setName(RightKneeNode, "Right Knee Node"); /*================================================================================================*/ /* Right Foot */ RightFoot = Joint::create(); //create a joint called RightFoot TempMat.setTranslate(0.0,-3.0,0.0); RightFoot->setJointTransformation(TempMat); NodeRecPtr RightFootNode = makeNodeFor(RightFoot); RightKneeNode->addChild(RightFootNode); InvBind = RightFootNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(RightFoot, InvBind); setName(RightFoot, "Right Foot Joint"); setName(RightFootNode, "Right Foot Node"); /*================================================================================================*/ /* Right Toes */ RightToes = Joint::create(); //create a joint called RightToes TempMat.setTranslate(0.0,0.0,1.0); RightToes->setJointTransformation(TempMat); NodeRecPtr RightToesNode = makeNodeFor(RightToes); RightFootNode->addChild(RightToesNode); InvBind = RightToesNode->getToWorld(); InvBind.invert(); ExampleSkeleton->pushToJoints(RightToes, InvBind); setName(RightToes, "Right Toes Joint"); setName(RightToesNode, "Right Toes Node"); //Create a geometry to attach to the skeleton (i.e-> skin) GeoUInt8PropertyUnrecPtr type = GeoUInt8Property::create(); type->push_back(GL_QUADS); GeoUInt32PropertyUnrecPtr lens = GeoUInt32Property::create(); lens->push_back(72); GeoPnt3fPropertyUnrecPtr pnts = GeoPnt3fProperty ::create(); // the points of the Quads //Back pnts->push_back(Pnt3f(-0.5, 6.0, 0)); pnts->push_back(Pnt3f( 0.5, 6.0, 0)); pnts->push_back(Pnt3f( 0.5, 12.0, 0)); pnts->push_back(Pnt3f(-0.5, 12.0, 0)); //Head pnts->push_back(Pnt3f(-0.5, 12, 0)); pnts->push_back(Pnt3f( 0.5, 12, 0)); pnts->push_back(Pnt3f( 0.5, 13, 0)); pnts->push_back(Pnt3f(-0.5, 13, 0)); //Left Shoulder pnts->push_back(Pnt3f(0.0, 11.5, 0)); pnts->push_back(Pnt3f(0.0, 12.5, 0)); pnts->push_back(Pnt3f(1.0, 12.0, 0)); pnts->push_back(Pnt3f(1.0, 11.0, 0)); //Left Humerus pnts->push_back(Pnt3f(1.0, 11.0, 0)); pnts->push_back(Pnt3f(1.0, 12.0, 0)); pnts->push_back(Pnt3f(3.0, 12.0, 0)); pnts->push_back(Pnt3f(3.0, 11.0, 0)); //Left Radius pnts->push_back(Pnt3f(3.0, 11.0, 0)); pnts->push_back(Pnt3f(3.0, 12.0, 0)); pnts->push_back(Pnt3f(5.0, 12.0, 0)); pnts->push_back(Pnt3f(5.0, 11.0, 0)); //Left Hand pnts->push_back(Pnt3f(5.0, 11.0, 0)); pnts->push_back(Pnt3f(5.0, 12.0, 0)); pnts->push_back(Pnt3f(6.0, 12.0, 0)); pnts->push_back(Pnt3f(6.0, 11.0, 0)); //Right Shoulder pnts->push_back(Pnt3f(0.0, 11.5, 0)); pnts->push_back(Pnt3f(0.0, 12.5, 0)); pnts->push_back(Pnt3f(-1.0, 12.0, 0)); pnts->push_back(Pnt3f(-1.0, 11.0, 0)); //Right Humerus pnts->push_back(Pnt3f(-1.0, 11.0, 0)); pnts->push_back(Pnt3f(-1.0, 12.0, 0)); pnts->push_back(Pnt3f(-3.0, 12.0, 0)); pnts->push_back(Pnt3f(-3.0, 11.0, 0)); //Right Radius pnts->push_back(Pnt3f(-3.0, 11.0, 0)); pnts->push_back(Pnt3f(-3.0, 12.0, 0)); pnts->push_back(Pnt3f(-5.0, 12.0, 0)); pnts->push_back(Pnt3f(-5.0, 11.0, 0)); //Right Hand pnts->push_back(Pnt3f(-5.0, 11.0, 0)); pnts->push_back(Pnt3f(-5.0, 12.0, 0)); pnts->push_back(Pnt3f(-6.0, 12.0, 0)); pnts->push_back(Pnt3f(-6.0, 11.0, 0)); //Left Hip pnts->push_back(Pnt3f(0.0, 6.5, 0)); pnts->push_back(Pnt3f(0.5, 7.5, 0)); pnts->push_back(Pnt3f( 1.5, 6.0, 0)); pnts->push_back(Pnt3f(0.5, 6.0, 0)); //Left Femur pnts->push_back(Pnt3f(0.5, 6.0, 0)); pnts->push_back(Pnt3f( 1.5, 6.0, 0)); pnts->push_back(Pnt3f( 1.5, 3.0, 0)); pnts->push_back(Pnt3f(0.5, 3.0, 0)); //Left Tibia pnts->push_back(Pnt3f(0.5, 3.0, 0)); pnts->push_back(Pnt3f( 1.5, 3.0, 0)); pnts->push_back(Pnt3f( 1.5, 0.0, 0)); pnts->push_back(Pnt3f(0.5, 0.0, 0)); //Left Foot pnts->push_back(Pnt3f(0.5, 0.0, 0)); pnts->push_back(Pnt3f( 1.5, 0.0, 0)); pnts->push_back(Pnt3f( 1.5, 0.0, 1.0)); pnts->push_back(Pnt3f(0.5, 0.0, 1.0)); //Right Hip pnts->push_back(Pnt3f(0.0, 6.5, 0)); pnts->push_back(Pnt3f(-0.5, 7.5, 0)); pnts->push_back(Pnt3f( -1.5, 6.0, 0)); pnts->push_back(Pnt3f(-0.5, 6.0, 0)); //Right Femur pnts->push_back(Pnt3f(-0.5, 6.0, 0)); pnts->push_back(Pnt3f( -1.5, 6.0, 0)); pnts->push_back(Pnt3f( -1.5, 3.0, 0)); pnts->push_back(Pnt3f(-0.5, 3.0, 0)); //Right Tibia pnts->push_back(Pnt3f(-0.5, 3.0, 0)); pnts->push_back(Pnt3f( -1.5, 3.0, 0)); pnts->push_back(Pnt3f( -1.5, 0.0, 0)); pnts->push_back(Pnt3f(-0.5, 0.0, 0)); //Right Foot pnts->push_back(Pnt3f(-0.5, 0.0, 0)); pnts->push_back(Pnt3f( -1.5, 0.0, 0)); pnts->push_back(Pnt3f( -1.5, 0.0, 1.0)); pnts->push_back(Pnt3f(-0.5, 0.0, 1.0)); //Normals GeoVec3fPropertyUnrecPtr norms = GeoVec3fProperty ::create(); geo=Geometry::create(); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); //Left Hip norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); //Left Femur norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); //Left Tibia norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); //Left Foot norms->push_back(Vec3f( 0.0,1.0,0.0)); norms->push_back(Vec3f( 0.0,1.0,0.0)); norms->push_back(Vec3f( 0.0,1.0,0.0)); norms->push_back(Vec3f( 0.0,1.0,0.0)); //Right Hip norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); //Right Femur norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); //Right Tibia norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); norms->push_back(Vec3f( 0.0,0.0,1.0)); //Right Foot norms->push_back(Vec3f( 0.0,1.0,0.0)); norms->push_back(Vec3f( 0.0,1.0,0.0)); norms->push_back(Vec3f( 0.0,1.0,0.0)); norms->push_back(Vec3f( 0.0,1.0,0.0)); //Tell the geometry (geo) to use the points and normals we just defined geo->setTypes (type); geo->setLengths (lens); geo->setPositions(pnts); geo->setNormals(norms); // assign a material to the geometry to make it visible. The details // of materials are defined later. geo->setMaterial(getDefaultMaterial()); //Create unbound geometry node (for displaying mesh in its bind pose) UnboundGeometry = Node::create(); UnboundGeometry->setCore(geo); UnboundGeometry->setTravMask(0); //By default, we won't show the mesh's bind pose //SkeletonDrawer SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create(); ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton); ExampleSkeletonDrawable->setMaterial(ExampleMaterial); ExampleSkeletonDrawable->setDrawBindPose(false); //By default, we don't draw the skeleton's bind pose ExampleSkeletonDrawable->setBindPoseColor(Color4f(0.0, 1.0, 0.0, 1.0)); //When drawn, the skeleton's bind pose renders green ExampleSkeletonDrawable->setDrawPose(true); //By default, we do draw the skeleton's current pose ExampleSkeletonDrawable->setPoseColor(Color4f(0.0, 0.0, 1.0, 1.0)); //The skeleton's current pose renders blue //Skeleton Node SkeletonNode = Node::create(); SkeletonNode->setCore(ExampleSkeletonDrawable); // Skeleton Blended Geometry // Here we are attaching the "skin" to the skeleton so that when the skeleton is animated, the skin moves with it ExampleSkeleton->setBaseGeometry(geo); //Back ExampleSkeleton->addJointBlending(0,Pelvis,1.0f); ExampleSkeleton->addJointBlending(1,Pelvis,1.0f); ExampleSkeleton->addJointBlending(2,Clavicle,1.0f); ExampleSkeleton->addJointBlending(3,Clavicle,1.0f); //Head ExampleSkeleton->addJointBlending(4,Clavicle,1.0f); ExampleSkeleton->addJointBlending(5,Clavicle,1.0f); ExampleSkeleton->addJointBlending(6,Head,1.0f); ExampleSkeleton->addJointBlending(7,Head,1.0f); //Left Shoulder ExampleSkeleton->addJointBlending(8,Clavicle,1.0f); ExampleSkeleton->addJointBlending(9,Clavicle,1.0f); ExampleSkeleton->addJointBlending(10,LeftShoulder,1.0f); ExampleSkeleton->addJointBlending(11,LeftShoulder,1.0f); //Left Humerus ExampleSkeleton->addJointBlending(12,LeftShoulder,1.0f); ExampleSkeleton->addJointBlending(13,LeftShoulder,1.0f); ExampleSkeleton->addJointBlending(14,LeftElbow,0.8f); ExampleSkeleton->addJointBlending(15,LeftElbow,0.8f); ExampleSkeleton->addJointBlending(14,LeftHand,0.2f); ExampleSkeleton->addJointBlending(15,LeftHand,0.2f); //Left Radius ExampleSkeleton->addJointBlending(16,LeftElbow,1.0f); ExampleSkeleton->addJointBlending(17,LeftElbow,1.0f); ExampleSkeleton->addJointBlending(18,LeftHand,1.0f); ExampleSkeleton->addJointBlending(19,LeftHand,1.0f); //Left Hand ExampleSkeleton->addJointBlending(20,LeftHand,1.0f); ExampleSkeleton->addJointBlending(21,LeftHand,1.0f); ExampleSkeleton->addJointBlending(22,LeftFingers,1.0f); ExampleSkeleton->addJointBlending(23,LeftFingers,1.0f); //Right Shoulder ExampleSkeleton->addJointBlending(24,Clavicle,1.0f); ExampleSkeleton->addJointBlending(25,Clavicle,1.0f); ExampleSkeleton->addJointBlending(26,RightShoulder,1.0f); ExampleSkeleton->addJointBlending(27,RightShoulder,1.0f); //Right Humerus ExampleSkeleton->addJointBlending(28,RightShoulder,1.0f); ExampleSkeleton->addJointBlending(29,RightShoulder,1.0f); ExampleSkeleton->addJointBlending(30,RightElbow,1.0f); ExampleSkeleton->addJointBlending(31,RightElbow,1.0f); //Right Radius ExampleSkeleton->addJointBlending(32,RightElbow,1.0f); ExampleSkeleton->addJointBlending(33,RightElbow,1.0f); ExampleSkeleton->addJointBlending(34,RightHand,1.0f); ExampleSkeleton->addJointBlending(35,RightHand,1.0f); //Right Hand ExampleSkeleton->addJointBlending(36,RightHand,1.0f); ExampleSkeleton->addJointBlending(37,RightHand,1.0f); ExampleSkeleton->addJointBlending(38,RightFingers,1.0f); ExampleSkeleton->addJointBlending(39,RightFingers,1.0f); //Left Hip ExampleSkeleton->addJointBlending(40,Pelvis,1.0f); ExampleSkeleton->addJointBlending(41,Pelvis,1.0f); ExampleSkeleton->addJointBlending(42,LeftHip,1.0f); ExampleSkeleton->addJointBlending(43,LeftHip,1.0f); //Left Femur ExampleSkeleton->addJointBlending(44,LeftHip,1.0f); ExampleSkeleton->addJointBlending(45,LeftHip,1.0f); ExampleSkeleton->addJointBlending(46,LeftKnee,1.0f); ExampleSkeleton->addJointBlending(47,LeftKnee,1.0f); //Left Tibia ExampleSkeleton->addJointBlending(48,LeftKnee,1.0f); ExampleSkeleton->addJointBlending(49,LeftKnee,1.0f); ExampleSkeleton->addJointBlending(50,LeftFoot,1.0f); ExampleSkeleton->addJointBlending(51,LeftFoot,1.0f); //Left Foot ExampleSkeleton->addJointBlending(52,LeftFoot,1.0f); ExampleSkeleton->addJointBlending(53,LeftFoot,1.0f); ExampleSkeleton->addJointBlending(54,LeftToes,1.0f); ExampleSkeleton->addJointBlending(55,LeftToes,1.0f); //Right Hip ExampleSkeleton->addJointBlending(56,Pelvis,1.0f); ExampleSkeleton->addJointBlending(57,Pelvis,1.0f); ExampleSkeleton->addJointBlending(58,RightHip,1.0f); ExampleSkeleton->addJointBlending(59,RightHip,1.0f); //Right Femur ExampleSkeleton->addJointBlending(60,RightHip,1.0f); ExampleSkeleton->addJointBlending(61,RightHip,1.0f); ExampleSkeleton->addJointBlending(62,RightKnee,1.0f); ExampleSkeleton->addJointBlending(63,RightKnee,1.0f); //Right Tibia ExampleSkeleton->addJointBlending(64,RightKnee,1.0f); ExampleSkeleton->addJointBlending(65,RightKnee,1.0f); ExampleSkeleton->addJointBlending(66,RightFoot,1.0f); ExampleSkeleton->addJointBlending(67,RightFoot,1.0f); //Right Foot ExampleSkeleton->addJointBlending(68,RightFoot,1.0f); ExampleSkeleton->addJointBlending(69,RightFoot,1.0f); ExampleSkeleton->addJointBlending(70,RightToes,1.0f); ExampleSkeleton->addJointBlending(71,RightToes,1.0f); MeshNode = Node::create(); MeshNode->setCore(ExampleSkeleton); //Create scene node NodeUnrecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(UnboundGeometry); scene->addChild(SkeletonNode); scene->addChild(MeshNode); mgr->setRoot(scene); //Setup the Animation setupAnimation(); //Save to an xml file FCFileType::FCPtrStore Containers; Containers.insert(ExampleSkeleton); Containers.insert(PelvisNode); Containers.insert(TheSkeletonAnimation); //Use an empty Ignore types vector FCFileType::FCTypeVector IgnoreTypes; //IgnoreTypes.push_back(Node::getClassType().getId()); //Write the Field Containers to a xml file FCFileHandler::the()->write(Containers,BoostPath("./13Output.xml"),IgnoreTypes); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "13MeshBlending"); //Main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
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 << "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; //Import scene from XML ChunkMaterialPtr ExampleMaterial; SkeletonPtr ExampleSkeleton; SkeletonBlendedGeometryPtr TheNewSkeletonGeometry; GeometryPtr ExampleGeometry; FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(Path("./Data/20BlendedGeometry.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())) { //Set ExampleSkeleton to the Skeleton we just read in ExampleSkeleton = (Skeleton::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (Geometry::getClassType())) { //Set ExampleGeometry to the geometry we just read in ExampleGeometry = (Geometry::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (SkeletonBlendedGeometry::getClassType())) { //Set TheNewSkeletonGeometry to the SkeletonBlendedGeometry we just read in TheNewSkeletonGeometry = (SkeletonBlendedGeometry::Ptr::dcast(*Itor)); } if( (*Itor)->getType().isDerivedFrom(Animation::getClassType())) { //Set TheSkeletonAnimation to the Animation we just read in TheSkeletonAnimation = (Animation::Ptr::dcast(*Itor)); } } //UnboundGeometry UnboundGeometry = Node::create(); beginEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask); UnboundGeometry->setCore(ExampleGeometry); UnboundGeometry->setTravMask(0); endEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask); //SkeletonDrawer SkeletonDrawablePtr ExampleSkeletonDrawable = osg::SkeletonDrawable::create(); beginEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask); ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton); ExampleSkeletonDrawable->setMaterial(ExampleMaterial); ExampleSkeletonDrawable->setDrawBindPose(false); //By default, we don't draw the skeleton's bind pose ExampleSkeletonDrawable->setBindPoseColor(Color4f(0.0, 1.0, 0.0, 1.0)); //When drawn, the skeleton's bind pose renders in green ExampleSkeletonDrawable->setDrawPose(true); //By default, we do draw the skeleton's current pose ExampleSkeletonDrawable->setPoseColor(Color4f(0.0, 0.0, 1.0, 1.0)); //The skeleton's current pose renders in blue endEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask); //Skeleton Node SkeletonNode = osg::Node::create(); beginEditCP(SkeletonNode, Node::CoreFieldMask); SkeletonNode->setCore(ExampleSkeletonDrawable); endEditCP(SkeletonNode, Node::CoreFieldMask); //Skeleton Blended Geometry Node MeshNode = osg::Node::create(); beginEditCP(MeshNode, Node::CoreFieldMask); MeshNode->setCore(TheNewSkeletonGeometry); endEditCP(MeshNode, Node::CoreFieldMask); //Animation Advancer TheAnimationAdvancer = osg::ElapsedTimeAnimationAdvancer::create(); osg::beginEditCP(TheAnimationAdvancer); osg::ElapsedTimeAnimationAdvancer::Ptr::dcast(TheAnimationAdvancer)->setStartTime( 0.0 ); osg::beginEditCP(TheAnimationAdvancer); //Create scene NodePtr scene = osg::Node::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(osg::Group::create()); scene->addChild(UnboundGeometry); scene->addChild(SkeletonNode); scene->addChild(MeshNode); endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); mgr->setRoot(scene); // 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, "20LoadXMLBlendedGeometry"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { if(argc != 2) { std::cout << "Usage: 04Xml2Osb.exe [Filename]" << std::endl; return -1; } Path FilePath(argv[1]); if(!boost::filesystem::exists(FilePath)) { std::cout << "No file by name: "<< FilePath.string() << " exists." << std::endl; return -1; } // OSG init osgInit(argc,argv); NodePtr TheScene(NullFC); //Load the Scene FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(FilePath); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { if( (*Itor)->getType() == Node::getClassType() && Node::Ptr::dcast(*Itor)->getParent() == NullFC) { TheScene = Node::Ptr::dcast(*Itor); } } //Check if the scene was loaded if(TheScene == NullFC) { std::cout << "Failed to load a scene from: "<< FilePath.string() << "." << std::endl; return -1; } //Run Graph optimizations GraphOpSeq *graphop = new GraphOpSeq; graphop->addGraphOp(new VerifyGeoGraphOp); graphop->addGraphOp(new StripeGraphOp); //graphop->addGraphOp(new MaterialMergeGraphOp); //graphop->addGraphOp(new SharePtrGraphOp); if(graphop != NULL) { graphop->run(TheScene); } //Export the Scene to an osb file std::string ExportFileName(FilePath.string().substr(0,FilePath.string().size()-3) + "osb"); SceneFileHandler::the().write(TheScene, ExportFileName.c_str()); // OSG exit osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); //Initialize Window TutorialWindow->initWindow(); SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); //Attach to events TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); BoostPath FilePath("../Animation/Data/Nanobot.dae"); if(argc >= 2) { FilePath = BoostPath(argv[1]); if(!boost::filesystem::exists(FilePath)) { std::cerr << "Could not load file: "<< FilePath.string() << ", because no such files exists."<< std::endl; FilePath = BoostPath("../Animation/Data/Nanobot.dae"); } } NodeRefPtr LoadedRoot; std::vector<AnimationRecPtr> LoadedAnimations; FCFileType::FCPtrStore ObjStore; try { ObjStore = FCFileHandler::the()->read(FilePath); } catch(std::exception &ex) { std::cerr << "Failed to load file: " << FilePath.string() << ", error:" << ex.what() << std::endl; return -1; } for(FCFileType::FCPtrStore::iterator StorItor(ObjStore.begin()); StorItor != ObjStore.end(); ++StorItor) { //Animations if((*StorItor)->getType().isDerivedFrom(Animation::getClassType())) { LoadedAnimations.push_back(dynamic_pointer_cast<Animation>(*StorItor)); LoadedAnimations.back()->attachUpdateProducer(TutorialWindow); LoadedAnimations.back()->start(); } //Root Node if((*StorItor)->getType() == Node::getClassType() && dynamic_pointer_cast<Node>(*StorItor)->getParent() == NULL) { LoadedRoot = dynamic_pointer_cast<Node>(*StorItor); } } if(LoadedRoot == NULL) { LoadedRoot = SceneFileHandler::the()->read(FilePath.string().c_str()); } if(LoadedRoot == NULL) { LoadedRoot= makeTorus(.5, 2, 32, 32); } //Make the fog node PostShaderStageRecPtr PostShaderStageCore = PostShaderStage::create(); PostShaderStageCore->clearPasses(); PostShaderStageCore->addPass("", generateNoEffectProg()); DirectionalLightRecPtr SceneLightCore = DirectionalLight::create(); SceneLightCore->setAmbient(Color4f(0.2f, 0.2f, 0.2f, 1.0f)); SceneLightCore->setDiffuse(Color4f(0.8f, 0.8f, 0.8f, 1.0f)); SceneLightCore->setSpecular(Color4f(1.0f, 1.0f, 1.0f, 1.0f)); NodeRefPtr SceneLight = makeNodeFor(SceneLightCore); SceneLight->addChild(LoadedRoot); NodeRefPtr PostShaderStageNode = makeNodeFor(PostShaderStageCore); PostShaderStageNode->addChild(SceneLight); //Make Main Scene Node NodeRefPtr scene = makeCoredNode<Group>(); scene->addChild(PostShaderStageNode); // tell the manager what to manage sceneManager.setRoot (scene); SceneLightCore->setBeacon(sceneManager.getCamera()->getBeacon()); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // show the whole scene sceneManager.showAll(); sceneManager.getWindow()->getPort(0)->setTravMask(1); RenderOptionsRecPtr ViewportRenderOptions = RenderOptions::create(); ViewportRenderOptions->setRenderProperties(0x0); ViewportRenderOptions->setRenderProperties(RenderPropertiesPool::the()->getFrom1("Default")); ViewportRenderOptions->setRenderProperties(0x01); sceneManager.getWindow()->getPort(0)->setRenderOptions(ViewportRenderOptions); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "Collada Loader"); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get(), PostShaderStageCore.get())); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// 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; }
// Initialize WIN32 & OpenSG and set up the scene int main(int argc, char **argv) { preloadSharedObject("OSGTBFileIO"); // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); //Attach to events TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1)); // create the scene NodeUnrecPtr scene = makeTorus(1.0, 2.0, 16, 16); sceneManager.setRoot (scene); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // show the whole scene sceneManager.showAll(); //Load Sound Definitions FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(BoostPath("Data/04SoundData.xml")); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { //Get Sounds if( (*Itor)->getType().isDerivedFrom(Sound::getClassType())) { Sounds.push_back(dynamic_pointer_cast<Sound>(*Itor)); Sounds.back()->connectSoundPlayed (boost::bind(handleSoundPlayed, _1)); Sounds.back()->connectSoundStopped (boost::bind(handleSoundStopped, _1)); Sounds.back()->connectSoundPaused (boost::bind(handleSoundPaused, _1)); Sounds.back()->connectSoundUnpaused(boost::bind(handleSoundUnpaused, _1)); Sounds.back()->connectSoundLooped (boost::bind(handleSoundLooped, _1)); } //Get Sound Groups if( (*Itor)->getType().isDerivedFrom(SoundGroup::getClassType())) { SoundGroups.push_back(dynamic_pointer_cast<SoundGroup>(*Itor)); } } //Initialize the Sound Manager SoundManager::the()->attachUpdateProducer(TutorialWindow); SoundManager::the()->setCamera(sceneManager.getCamera()); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "04 XML Sound Loading Window"); //Enter main loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); //SkeletonDrawer System Material LineChunkUnrecPtr ExampleLineChunk = LineChunk::create(); ExampleLineChunk->setWidth(2.0f); ExampleLineChunk->setSmooth(true); BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create(); ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA); ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create(); ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f)); ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f)); ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f)); ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create(); ExampleMaterial->addChunk(ExampleLineChunk); //Read skeleton from XML file FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(BoostPath("./Data/16Skeleton.xml")); SkeletonUnrecPtr ExampleSkeleton; FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { //Only import skeleton data; we ignore anything else saved in the XML file if( (*Itor)->getType() == (Skeleton::getClassType())) { //Set the Skeleton to the one we just read in ExampleSkeleton = (dynamic_pointer_cast<Skeleton>(*Itor)); } } //SkeletonDrawer SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create(); ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton); ExampleSkeletonDrawable->setMaterial(ExampleMaterial); //Skeleton Particle System Node NodeUnrecPtr SkeletonNode = Node::create(); SkeletonNode->setCore(ExampleSkeletonDrawable); //Torus Node NodeUnrecPtr TorusNode = makeTorus(.5, 2, 32, 32); // Make Main Scene Node and add the Torus NodeUnrecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(SkeletonNode); //scene->addChild(TorusNode); scene->addChild(makeCoordAxis(10.0)); mgr->setRoot(scene); mgr->turnHeadlightOff(); // Show the whole Scene mgr->showAll(); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "16LoadXMLSkeleton"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }