// 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; }
virtual void actionPerformed(const ActionEventPtr e) { TheAnimationAdvancer->pauseToggle(); }
// 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); TutorialUpdateListener TheTutorialUpdateListener; TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindowEventProducer->getWindow()); //////////////// // Create the Graphics GraphicsPtr TutorialGraphics = osg::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create an Button Component and a simple Font. See 17Label_Font for more information about Fonts. ******************************************************/ ButtonPtr ExampleButton = osg::Button::create(); UIFontPtr ExampleFont = osg::UIFont::create(); beginEditCP(ExampleButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); ExampleButton->setMinSize(Vec2f(50, 25)); ExampleButton->setMaxSize(Vec2f(200, 100)); ExampleButton->setPreferredSize(Vec2f(100, 50)); ExampleButton->setToolTipText("Click to start/pause"); ExampleButton->setText("start/pause"); ExampleButton->setFont(ExampleFont); ExampleButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0)); ExampleButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setAlignment(Vec2f(.5,0.5)); endEditCP(ExampleButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); // Create an ActionListener and assign it to ExampleButton // This Class is defined above, and will cause the output // window to display "Button 1 Action" when pressed ExampleButtonActionListener TheExampleButtonActionListener; ExampleButton->addActionListener(&TheExampleButtonActionListener); ////////////////// //Torus Material TheTorusMaterial = SimpleMaterial::create(); beginEditCP(TheTorusMaterial); SimpleMaterialPtr::dcast(TheTorusMaterial)->setAmbient(Color3f(0.3,0.3,0.3)); SimpleMaterialPtr::dcast(TheTorusMaterial)->setDiffuse(Color3f(0.7,0.7,0.7)); SimpleMaterialPtr::dcast(TheTorusMaterial)->setSpecular(Color3f(1.0,1.0,1.0)); endEditCP(TheTorusMaterial); //Torus Geometry GeometryPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32); beginEditCP(TorusGeometry); TorusGeometry->setMaterial(TheTorusMaterial); endEditCP (TorusGeometry); NodePtr TorusGeometryNode = Node::create(); beginEditCP(TorusGeometryNode, Node::CoreFieldMask); TorusGeometryNode->setCore(TorusGeometry); endEditCP (TorusGeometryNode, Node::CoreFieldMask); //Make Torus Node NodePtr TorusNode = Node::create(); TransformPtr TorusNodeTrans; TorusNodeTrans = Transform::create(); setName(TorusNodeTrans, std::string("TorusNodeTransformationCore")); beginEditCP(TorusNode, Node::CoreFieldMask | Node::ChildrenFieldMask); TorusNode->setCore(TorusNodeTrans); TorusNode->addChild(TorusGeometryNode); endEditCP (TorusNode, Node::CoreFieldMask | Node::ChildrenFieldMask); //Make Main Scene Node NodePtr scene = Node::create(); ComponentTransformPtr Trans; Trans = ComponentTransform::create(); setName(Trans, std::string("MainTransformationCore")); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); { scene->setCore(Trans); // add the torus as a child scene->addChild(TorusNode); } endEditCP (scene, Node::CoreFieldMask | Node::ChildrenFieldMask); setupAnimation(); // 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); InternalWindowPtr MainInternalWindow = osg::InternalWindow::create(); LayoutPtr MainInternalWindowLayout = osg::FlowLayout::create(); beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); MainInternalWindow->getChildren().push_back(ExampleButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); 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); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); TutorialViewport->getForegrounds().push_back(TutorialUIForeground); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); // show the whole scene mgr->showAll(); TheAnimationAdvancer->start(); Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "24AnimationAction"); //Enter main Loop TutorialWindowEventProducer->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; }