Katana Plug-in APIs 0.1

ExampleSceneLayer.h

00001 // Copyright (c) 2016 The Foundry Visionmongers Ltd. All Rights Reserved.
00002 
00003 #ifndef SCENELAYER_H_
00004 #define SCENELAYER_H_
00005 
00006 #include "DrawableMesh.h"
00007 #include "SceneNode.h"
00008 
00009 #include <FnViewer/plugin/FnViewportLayer.h>
00010 #include <FnViewer/plugin/FnEventWrapper.h>
00011 #include <FnViewer/utils/FnGLShaderProgram.h>
00012 
00013 #include <FnAttribute/FnAttribute.h>
00014 #include <string>
00015 #include <map>
00016 #include <vector>
00017 
00018 using Foundry::Katana::ViewerAPI::FnEventWrapper;
00019 using Foundry::Katana::ViewerAPI::ViewportLayer;
00020 using Foundry::Katana::ViewerAPI::ViewportWrapperPtr;
00021 
00029 class ExampleSceneLayer : public ViewportLayer
00030 {
00031     using OptID = Foundry::Katana::ViewerAPI::OptionIdGenerator;
00032 
00033 public:
00034     typedef std::map<std::string, DrawableMesh*> MeshMap;
00035     typedef std::map<std::string, FnAttribute::GroupAttribute> MeshQueue;
00036 
00037     ExampleSceneLayer();
00038     virtual ~ExampleSceneLayer();
00039 
00041     static ViewportLayer* create()
00042     {
00043         return new ExampleSceneLayer();
00044     }
00045 
00047     virtual void setup();
00048 
00050     virtual void cleanup();
00051 
00053     virtual void draw();
00054 
00056     void pickerDraw(unsigned int x, unsigned int y,
00057                     unsigned int w, unsigned int h,
00058                     const PickedAttrsMap& ignoreAttrs);
00059 
00060     // Returns true if the event has been handled. Otherwise false, and the
00061     // event will be passed to the next layer
00062     virtual bool event(const FnEventWrapper& eventData);
00063 
00065     virtual void resize(unsigned int width, unsigned int height);
00066 
00068     void freeze() {}
00069 
00071     void thaw() {}
00072 
00073     void setOption(OptID::value_type optionId,
00074                    FnAttribute::Attribute attr) override;
00075 
00076 protected:
00077 
00078     /*
00079      * Returns an attribute containing a list of scene graph locations that can
00080      * be selected at the passed window coordinates.
00081      *
00082      * Note that the OpenGL context must be current before this method is
00083      * called.
00084      */
00085     void getSelectableItems(int x, int y, int w, int h,
00086         std::vector<std::string>& selectedItems);
00087 
00088     void getLocationsFromPickedAttrsMap(
00089         const PickedAttrsMap& pickedMap,
00090         std::set<std::string>& locations);
00091 
00092 private:
00093     // A pointer to the scene root node, typically owned by the viewer delegate
00094     SceneNode* m_sceneRoot;
00095 
00097     GLShaderProgram m_pickingShader;
00098 
00100     std::vector<std::string> m_excludedLocationsPicking;
00101 };
00102 #endif /* SCENELAYER_H_ */
 All Classes Functions Variables Typedefs Enumerations Enumerator