PanelPtr SceneEditor::createEditorTab(SceneComponentEditorPtr Editor, IconManagerPtr TheIconManager) const { //Editor Icon ImageComponentPtr EditorIcon = TheIconManager->createIconImageComponent(Editor->getPresentationIconName()); if(EditorIcon == NullFC) { EditorIcon = ImageComponent::create(); } beginEditCP(EditorIcon, ImageComponent::ScaleFieldMask | ImageComponent::AlignmentFieldMask); EditorIcon->setAlignment(Vec2f(0.5f,0.5f)); EditorIcon->setScale(ImageComponent::SCALE_MIN_AXIS); endEditCP(EditorIcon, ImageComponent::ScaleFieldMask | ImageComponent::AlignmentFieldMask); //Editor Label LabelPtr TabLabel = Label::create(); beginEditCP(TabLabel, Label::TextFieldMask | Label::BordersFieldMask | Label::BackgroundsFieldMask | Label::AlignmentFieldMask); TabLabel->setBorders(NullFC); TabLabel->setBackgrounds(NullFC); TabLabel->setText(Editor->getPresentationName()); TabLabel->setAlignment(Vec2f(0.5f,0.5f)); endEditCP(TabLabel, Label::TextFieldMask | Label::BordersFieldMask | Label::BackgroundsFieldMask | Label::AlignmentFieldMask); //Tab PanelPtr Tab = Panel::createEmpty(); //Layout SpringLayoutPtr TabLayout = SpringLayout::create(); //Editor Icon TabLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, EditorIcon, 0, SpringLayoutConstraints::WEST_EDGE, Tab); TabLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, EditorIcon, 0, SpringLayoutConstraints::EAST_EDGE, Tab); TabLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, EditorIcon, 0, SpringLayoutConstraints::NORTH_EDGE, Tab); TabLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, EditorIcon, -1, SpringLayoutConstraints::NORTH_EDGE, TabLabel); //Editor Label TabLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, TabLabel, 0, SpringLayoutConstraints::WEST_EDGE, Tab); TabLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, TabLabel, 0, SpringLayoutConstraints::EAST_EDGE, Tab); TabLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, TabLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, Tab); TabLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, TabLabel, LayoutSpring::height(TabLabel)); //Tab Layout //TabLayout->putConstraint(SpringLayoutConstraints::WIDTH_EDGE, Tab, LayoutSpring::max(TabLayout->getConstraint(SpringLayoutConstraints::WIDTH_EDGE,TabLabel),TabLayout->getConstraint(SpringLayoutConstraints::WIDTH_EDGE,EditorIcon))); //TabLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, Tab, LayoutSpring::sum(TabLayout->getConstraint(SpringLayoutConstraints::HEIGHT_EDGE,TabLabel),TabLayout->getConstraint(SpringLayoutConstraints::HEIGHT_EDGE,EditorIcon))); TabLayout->putConstraint(SpringLayoutConstraints::WIDTH_EDGE, Tab, LayoutSpring::width(Tab)); TabLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, Tab, LayoutSpring::height(Tab)); beginEditCP(Tab, Panel::ChildrenFieldMask | Panel::LayoutFieldMask | Panel::PreferredSizeFieldMask); Tab->getChildren().push_back(EditorIcon); Tab->getChildren().push_back(TabLabel); Tab->setLayout(TabLayout); Tab->setPreferredSize(Vec2f(70.0f,50.0f)); endEditCP(Tab, Panel::ChildrenFieldMask | Panel::LayoutFieldMask | Panel::PreferredSizeFieldMask); return Tab; }
ComponentPtr DefaultDialogComponentGenerator::getQuestionComponent(DialogInterfacePtr Parent, const boost::any& Value) { std::string questionString(""); try { questionString = lexical_cast(Value); } catch (boost::bad_lexical_cast &) { std::cout<<"Unable to display question"<<std::endl; } LabelPtr TheQuestionString = Label::Ptr::dcast(getQuestionPrototype()->shallowCopy()); beginEditCP(TheQuestionString, Label::TextFieldMask); TheQuestionString->setText(questionString); endEditCP(TheQuestionString, Label::TextFieldMask); return TheQuestionString; }
/***************************************************************************\ * Instance methods * \***************************************************************************/ ComponentPtr DefaultCaptionComponentGenerator::getCaptionComponent(CaptionPtr Parent, const boost::any& Value) { std::string CaptionSegment(""); try { CaptionSegment = lexical_cast(Value); } catch (boost::bad_lexical_cast &) { std::cout<<"Unable to display segment"<<std::endl; } LabelPtr TheCaptionSegment = Label::Ptr::dcast(getCaptionSegmentPrototype()->shallowCopy()); beginEditCP(TheCaptionSegment, Label::TextFieldMask); TheCaptionSegment->setText(CaptionSegment); endEditCP(TheCaptionSegment, Label::TextFieldMask); return TheCaptionSegment; }
// 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; }