NDEVR
API Documentation
CameraManager.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Design
28File: CameraManager
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/Camera.h>
35#include <NDEVR/MouseController.h>
36#include <NDEVR/ViewportLayout.h>
37#include <NDEVR/KeyController.h>
38#include <NDEVR/UUID.h>
39#include <NDEVR/Pointer.h>
40#include <NDEVR/Buffer.h>
41#include <NDEVR/Dictionary.h>
42#if NDEVR_VIEWPORT
43namespace std
44{
45
55 template<>
56 struct hash<std::pair<UUID, UUID>>
57 {
70
71 size_t operator()(const std::pair<UUID, UUID>& value) const
72 {
73 hash<UUID> hasher;
74 return hasher(value.first) ^ hasher(value.second);
75 }
76 };
77
87 template <>
88 struct equal_to<std::pair<UUID, UUID>>
89 {
103
104 bool operator()(const std::pair<UUID, UUID>& x, const std::pair<UUID, UUID>& y) const
105 {
106 return x == y;
107 }
108 };
109};
110namespace NDEVR
111{
112 class KeyControllerBase;
113 class MouseControllerBase;
114 class MouseController;
115 class KeyController;
116 class SnapsManager;
117 class Skybox;
121 class NDEVR_DESIGN_API CameraManager
122 {
123 private:
124 class CameraOrientationSync;
125 class CameraOffsetSync;
126 public:
145 {
146 return m_snap_manager;
147 }
148
153 {
154 return m_snap_manager;
155 }
156
161 void update(const Time& time, DesignObjectLookup* lookup);
168 {
169 return m_mouse_controllers.get(id);
170 }
171
177 {
178 return m_key_controllers.get(id);
179 }
180
192 void updateCamera(const ViewportFormat& format);
198 bool hasCamera(UUID id) const;
205 {
206 const auto& camera = m_cameras.find(id);
207 if (camera != m_cameras.end())
208 return camera.value();
209 return DynamicPointer<Camera>();
210 }
211
216 {
217 return m_cameras.size();
218 }
219
226 void clearAll();
257 void setSkybox(UUID camera, Skybox* skybox);
263 void addCameraModel(const UUID& camera, const Model& object);
269 Skybox* getSkybox(UUID camera_id) const;
276 {
277 return m_index_cameras[id];
278 }
279
285 {
286 return m_index_cameras[id];
287 }
288
293 void deleteCamera(UUID id, bool delete_model = true);
304 void selectCamera(UUID camera);
317 void addKeyController(UUID camera, UUID id, KeyControllerBase* actions);
323 void removeKeyController(UUID camera, UUID id);
372 void setCameraShowGrid(bool show_grid);
377 void setCameraShowEnvironment(bool show_grid);
383 void addMouseCursor(UUID id, const StringView& cursor);
408 void removeViewportLayout(const UUID& id);
417 private:
418 Buffer<ViewportLayout> m_viewport_layout_stack;
419 DynamicPointer<SnapsManager> m_snap_manager;
420 Dictionary<UUID, Skybox*> m_skyboxes;
421 Set<std::pair<UUID, UUID>> m_default_hidden_items;
422 Dictionary<std::pair<UUID, UUID>, CameraOrientationSync*> m_camera_orientation_syncs;
423 Dictionary<std::pair<UUID, UUID>, CameraOffsetSync*> m_camera_offset_syncs;
424 Buffer<DynamicPointer<Camera>> m_index_cameras;
428 Buffer<UUID> m_global_mouse_actions;
429 Dictionary<UUID, MouseControllerBase*> m_global_mouse_action_lookup;
430 Buffer<UUID> m_global_key_actions;
431 Dictionary<UUID, KeyControllerBase*> m_global_key_action_lookup;
432 RGBColor m_theme_camera_background_color;
433 Buffer<std::pair<UUID, String>> m_global_mouse_cursors;
434 Dictionary<UUID, String> m_global_mouse_cursor_lookup;
435 UUID m_active_camera;
436 BasicResourceListener* m_color_theme_listener;
437 };
438}
439#endif
Simple version of ResourceListener which allows for a simple function callback that will be executed ...
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
void addCameraModel(const UUID &camera, const Model &object)
Associates a model with a camera for visibility or rendering purposes.
void delinkCameraOrientation(UUID a, UUID b)
Removes the orientation link between two cameras.
void clearAll()
Removes all cameras, controllers, skyboxes, and layouts from the manager.
~CameraManager()
Destroys the CameraManager and releases all managed resources.
Buffer< UUID > userCameraIDs() const
Returns the UUIDs of all user-created cameras.
DynamicPointer< Camera > getCamera(UUID id) const
Retrieves a camera by its UUID.
Buffer< DynamicPointer< Camera > > userCameras() const
Returns all user-created cameras.
RGBColor defaultCameraBackgroundColor() const
Returns the default camera background color based on the current theme.
void addMouseController(UUID camera, UUID id, MouseControllerBase *actions)
Adds a mouse controller to a specific camera.
void removeKeyController(UUID id)
Removes a global key controller.
void addMouseController(UUID id, MouseControllerBase *actions)
Adds a global mouse controller that applies to all cameras.
DynamicPointer< Camera > createCamera(Model &parent, ViewportFormat format, DesignObjectLookup *lookup)
Creates a new camera under the given parent model with the specified viewport format.
const ConstPointer< SnapsManager > & snapsManager() const
Returns a const pointer to the snap manager.
const DynamicPointer< SnapsManager > & snapsManager()
Returns a mutable pointer to the snap manager.
void updateCamera(const ViewportFormat &format)
Updates an existing camera to match the given viewport format.
void setCameraShowGrid(bool show_grid)
Enables or disables grid display for all managed cameras.
void linkCameraOrientation(UUID a, UUID b)
Links the orientation of two cameras so they rotate together.
Resource< bool > camera_show_grid
Whether the grid is displayed in camera viewports.
void setDefaultLayoutTheme(ViewportLayoutTheme theme)
Sets the default viewport layout theme used when creating new layouts.
DynamicPointer< Camera > selectedCamera() const
Returns the currently selected (active) camera.
void updateViewportLayout(const ViewportLayout &layout)
Updates an existing viewport layout with new settings.
void removeKeyController(UUID camera, UUID id)
Removes a key controller from a specific camera.
void setThemeCameraBackgroundColor(const RGBColor &color)
Sets the fallback background color used when a camera has no explicitly assigned color.
void setSkybox(UUID camera, Skybox *skybox)
Sets the skybox for a specific camera.
Resource< bool > camera_show_environment
Whether the environment (skybox) is displayed in camera viewports.
void selectCamera(UUID camera)
Sets the specified camera as the currently active (selected) camera.
void removeMouseCursor(UUID id)
Removes a mouse cursor style from the global cursor stack.
void update(const Time &time, DesignObjectLookup *lookup)
Updates all managed cameras and controllers for the current frame.
void deleteCamera(UUID id, bool delete_model=true)
Deletes a camera by UUID and optionally removes its associated model.
Skybox * getSkybox(UUID camera_id) const
Retrieves the skybox assigned to a camera.
void setCameraShowEnvironment(bool show_grid)
Enables or disables environment (skybox/background) display for all managed cameras.
void removeMouseController(UUID id)
Removes a global mouse controller.
void addCamera(DynamicPointer< Camera > camera)
Adds an existing camera to this manager.
void saveLayout()
Saves the current viewport layout configuration.
uint04 userCameraCount() const
Returns the number of user-created cameras (excludes internal cameras).
Buffer< UUID > cameraIDs() const
Returns the UUIDs of all managed cameras.
void addKeyController(UUID id, KeyControllerBase *actions)
Adds a global key controller that applies to all cameras.
const ConstPointer< Camera > & getCameraFromIndex(uint04 id) const
Retrieves a camera by its sequential index (const overload).
void addKeyController(UUID camera, UUID id, KeyControllerBase *actions)
Adds a key controller to a specific camera.
const DynamicPointer< KeyController > & keyController(UUID id)
Retrieves the key controller associated with the given ID.
void removeMouseController(UUID camera, UUID id)
Removes a mouse controller from a specific camera.
void addMouseCursor(UUID id, const StringView &cursor)
Adds a mouse cursor style to the global cursor stack.
void updateCameraBackgrounds()
Refreshes the background color of all managed cameras based on current settings.
const DynamicPointer< Camera > & getCameraFromIndex(uint04 id)
Retrieves a camera by its sequential index.
void removeViewportLayout(const UUID &id)
Removes a viewport layout from the stack by its UUID.
uint04 cameraCount() const
Returns the total number of managed cameras.
CameraManager()
Synchronizes positional offset between linked cameras.
const DynamicPointer< MouseController > & mouseController(UUID id)
Retrieves the mouse controller associated with the given ID.
Resource< ViewportLayout > current_layout
The currently active viewport layout.
void addViewportLayout(const ViewportLayout &layout)
Pushes a viewport layout onto the layout stack and activates it.
bool hasCamera(UUID id) const
Checks whether a camera with the given ID is managed by this manager.
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition Pointer.hpp:276
A core class where all Design Objects including models, materials, and geometries are stored.
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
Forward declaration for the camera class.
A top-level controller that dispatches key events to registered sub-controllers.
A core class that represents a node on model hierarchy.
Definition Model.h:292
A base class for adding functionality to the user mouse inputs.
Contains logic for executing actions based on user mouse inputs.
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:57
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Resource.h:42
Container that stores unique elements in no particular order, and which allow for fast retrieval or i...
Definition Set.h:59
Contains a 3D box used to render complicated backgrounds for a CameraBackground object.
Definition Skybox.h:42
Forward declaration for the NDEVR string type.
The core String View class for the NDEVR API.
Definition StringView.h:58
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
Stores information for how to construct a viewport, including camera identity, field of view,...
Stores information for how to construct a group of viewports such as those in the center 3D panel.
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
ViewportLayoutTheme
The potential layouts of multiple viewports within the NDEVR engine.
STL namespace.