scenepic 1.1.0
3D Visualization Made Easy
canvas3d.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#ifndef _SCENEPIC_CANVAS3D_H_
5#define _SCENEPIC_CANVAS3D_H_
6
7#include "camera.h"
8#include "focus_point.h"
9#include "frame3d.h"
10#include "json_value.h"
11#include "layer_settings.h"
12#include "mesh.h"
13#include "shading.h"
14#include "ui_parameters.h"
15
16#include <limits>
17#include <map>
18#include <memory>
19#include <string>
20
21namespace scenepic
22{
26 {
27 public:
40 std::shared_ptr<Frame3D> create_frame(
41 const std::string& frame_id = "",
43 const std::vector<std::string>& mesh_ids = std::vector<std::string>(),
44 const Camera& camera = Camera::None());
45
59 template<typename MeshType>
60 std::shared_ptr<Frame3D> create_frame_with_meshes(
61 const std::vector<std::shared_ptr<MeshType>>& meshes,
62 const std::string& frame_id = "",
64 const Camera& camera = Camera::None())
65 {
66 std::vector<std::string> mesh_ids;
67 std::transform(
68 meshes.begin(),
69 meshes.end(),
70 std::back_inserter(mesh_ids),
71 [](const std::shared_ptr<MeshType>& mesh) { mesh->mesh_id(); });
72 return this->create_frame(frame_id, focus_point, mesh_ids, camera);
73 }
74
89 const std::map<std::string, LayerSettings> layer_settings);
90
92 const std::string& canvas_id() const;
93
99
101 std::string to_string() const;
102
107
109 const Camera& camera() const;
110
112 Canvas3D& camera(const Camera& value);
113
115 const Shading& shading() const;
116
118 Canvas3D& shading(const Shading& value);
119
121 const FocusPoint& focus_point() const;
122
125
128
131
136 const std::string& media_id() const;
137
138 Canvas3D& media_id(const std::string& audio_id);
139
141 double width() const;
142
144 double height() const;
145
146 private:
147 friend class Scene;
148
157 Canvas3D(
158 const std::string& canvas_id,
159 double height,
160 double width,
161 const Camera& camera = Camera(),
162 const Shading& shading = Shading(),
165
166 std::string m_canvas_id;
167 Camera m_camera;
168 Shading m_shading;
169 FocusPoint m_focus_point;
170 UIParameters m_ui_parameters;
171 std::map<std::string, LayerSettings> m_layer_settings;
172 std::vector<std::shared_ptr<Frame3D>> m_frames;
173 std::string m_media_id;
174 double m_width;
175 double m_height;
176
177 // This will get out of sync with the above after a call to clear_script()
178 // DO NOT REMOVE - it is important
179 std::size_t m_num_frames;
180 };
181} // namespace scenepic
182
183#endif
A camera type.
Definition: camera.h:15
static Camera None()
A value indicating "no camera".
Represents a ScenePic Canvas3D - a 3D viewport that can contain a number of Frame3Ds.
Definition: canvas3d.h:26
const std::string & canvas_id() const
A unique identifier for the canvas.
std::shared_ptr< Frame3D > create_frame(const std::string &frame_id="", const FocusPoint &focus_point=FocusPoint::None(), const std::vector< std::string > &mesh_ids=std::vector< std::string >(), const Camera &camera=Camera::None())
Creates a new Frame3D object and appends to the list of Frame3Ds in the Canvas3D.
Canvas3D & media_id(const std::string &audio_id)
JsonValue to_json() const
Convert this object into ScenePic json.
std::string to_string() const
Return a JSON string representing the object.
double height() const
The width of the canvas.
Canvas3D & ui_parameters(const UIParameters &value)
Set of user interface parameters.
Canvas3D & focus_point(const FocusPoint &value)
The default focus point for the canvas.
Canvas3D & shading(const Shading &value)
Set of Shading parameters for the Canvas.
void clear_script()
Call this if you are dumping a ScenePic script in multiple parts, e.g.
const UIParameters & ui_parameters() const
Set of user interface parameters.
const Shading & shading() const
Set of Shading parameters for the Canvas.
Canvas3D & camera(const Camera &value)
Set of Camera parameters for the Canvas.
const FocusPoint & focus_point() const
The default focus point for the canvas.
double width() const
The width of the canvas.
const Camera & camera() const
Set of Camera parameters for the Canvas.
const std::string & media_id() const
The unique ID of the media file associated with this canvas.
void set_layer_settings(const std::map< std::string, LayerSettings > layer_settings)
Specify the visibilities and opacities of certain mesh layers.
std::shared_ptr< Frame3D > create_frame_with_meshes(const std::vector< std::shared_ptr< MeshType > > &meshes, const std::string &frame_id="", const FocusPoint &focus_point=FocusPoint::None(), const Camera &camera=Camera::None())
Creates a new Frame3D object and appends to the list of Frame3Ds in the Canvas3D.
Definition: canvas3d.h:60
3D focus point for this frame (with optional 3D rotation for orientation lock), used in the ScenePic ...
Definition: focus_point.h:16
static FocusPoint None()
A value indicating "no focus point".
Representation of a JSON value according to the specification at https://www.json....
Definition: json_value.h:30
Top level container representing an entire ScenePic.
Definition: scene.h:58
Parameters of the shaders.
Definition: shading.h:15
Per-Canvas3D parameters of the ScenePic user interface.
Definition: ui_parameters.h:15
Definition: audio_track.h:14