14#include <lagrange/SurfaceMesh.h>
15#include <lagrange/common.h>
16#include <lagrange/fs/filesystem.h>
17#include <lagrange/scene/SceneExtension.h>
18#include <lagrange/scene/api.h>
19#include <lagrange/utils/invalid.h>
21#include <Eigen/Geometry>
36namespace lagrange::scene {
38using ElementId = size_t;
39constexpr ElementId invalid_element = lagrange::invalid<ElementId>();
45 ElementId mesh = invalid_element;
50 std::vector<ElementId> materials;
60 Eigen::Affine3f transform = Eigen::Affine3f::Identity();
63 ElementId parent = invalid_element;
66 std::vector<ElementId> children;
72 std::vector<SceneMeshInstance> meshes;
75 std::vector<ElementId> cameras;
78 std::vector<ElementId> lights;
95 size_t num_channels = 4;
101 std::vector<unsigned char>
data;
106 size_t get_bits_per_element()
const;
134 ElementId index = invalid_element;
148 Eigen::Vector4f base_color_value = Eigen::Vector4f::Ones();
151 Eigen::Vector3f emissive_value = Eigen::Vector3f::Zero();
157 float metallic_value = 1.f;
158 float roughness_value = 1.f;
161 enum class AlphaMode {
167 AlphaMode alpha_mode = AlphaMode::Opaque;
168 float alpha_cutoff = 0.5f;
172 float normal_scale = 1.f;
176 float occlusion_strength = 1.f;
179 bool double_sided =
false;
187 ElementId image = invalid<ElementId>();
189 enum TextureFilter :
int {
193 NearestMimpapNearest = 9984,
194 LinearMipmapNearest = 9985,
195 NearestMipmapLinear = 9986,
196 LinearMipmapLinear = 9987
200 TextureFilter mag_filter = TextureFilter::Undefined;
205 TextureFilter min_filter = TextureFilter::Undefined;
207 enum class WrapMode {
214 WrapMode wrap_u = WrapMode::Wrap;
215 WrapMode wrap_v = WrapMode::Wrap;
217 Eigen::Vector2f scale = Eigen::Vector2f::Ones();
218 Eigen::Vector2f offset = Eigen::Vector2f::Zero();
219 float rotation = 0.0f;
228 enum class Type { Undefined, Directional, Point, Spot, Ambient, Area };
229 Type type = Type::Undefined;
234 Eigen::Vector3f position = Eigen::Vector3f::Zero();
235 Eigen::Vector3f direction = Eigen::Vector3f(0, 1, 0);
236 Eigen::Vector3f up = Eigen::Vector3f(0, 0, 1);
243 float intensity = 1.f;
244 float attenuation_constant = 1.f;
245 float attenuation_linear = 0.f;
246 float attenuation_quadratic = 0.f;
247 float attenuation_cubic = 0.f;
255 Eigen::Vector3f color_diffuse = Eigen::Vector3f::Zero();
256 Eigen::Vector3f color_specular = Eigen::Vector3f::Zero();
257 Eigen::Vector3f color_ambient = Eigen::Vector3f::Zero();
261 float angle_inner_cone;
262 float angle_outer_cone;
265 Eigen::Vector2f size = Eigen::Vector2f::Zero();
276 Eigen::Vector3f position = Eigen::Vector3f::Zero();
277 Eigen::Vector3f up = Eigen::Vector3f(0, 1, 0);
278 Eigen::Vector3f look_at = Eigen::Vector3f(0, 0, 1);
281 float near_plane = 0.1f;
284 float far_plane = 1000.f;
286 enum class Type { Perspective, Orthographic };
287 Type type = Type::Perspective;
292 float orthographic_width = 0.f;
300 float aspect_ratio = 1.f;
308 float horizontal_fov = (float)M_PI_2;
312 float get_vertical_fov()
const
314 return 2.f * std::atan(std::tan(horizontal_fov * 0.5f) / aspect_ratio);
316 void set_horizontal_fov_from_vertical_fov(
float vfov)
318 horizontal_fov = 2.f * std::atan(std::tan(vfov * 0.5f) * aspect_ratio);
320 void set_aspect_ratio_from_fov(
float vfov,
float hfov)
322 aspect_ratio = std::tan(hfov * 0.5f) / std::tan(vfov * 0.5f);
341 std::vector<ElementId> meshes;
347template <
typename Scalar,
typename Index>
357 std::vector<Node> nodes;
360 std::vector<ElementId> root_nodes;
363 std::vector<MeshType> meshes;
366 std::vector<ImageExperimental> images;
369 std::vector<Texture> textures;
372 std::vector<MaterialExperimental> materials;
375 std::vector<Light> lights;
378 std::vector<Camera> cameras;
381 std::vector<Skeleton> skeletons;
384 std::vector<Animation> animations;
398 template <
typename T>
399 ElementId
add(T&& value);
408 void add_child(ElementId parent_id, ElementId child_id);
411template <
typename Scalar,
typename Index>
415 using ElementType = std::decay_t<T>;
416 if constexpr (std::is_same_v<ElementType, Node>) {
417 nodes.emplace_back(std::forward<T>(value));
418 return nodes.size() - 1;
419 }
else if constexpr (std::is_same_v<ElementType, MeshType>) {
420 meshes.emplace_back(std::forward<T>(value));
421 return meshes.size() - 1;
422 }
else if constexpr (std::is_same_v<ElementType, ImageExperimental>) {
423 images.emplace_back(std::forward<T>(value));
424 return images.size() - 1;
425 }
else if constexpr (std::is_same_v<ElementType, Texture>) {
426 textures.emplace_back(std::forward<T>(value));
427 return textures.size() - 1;
428 }
else if constexpr (std::is_same_v<ElementType, MaterialExperimental>) {
429 materials.emplace_back(std::forward<T>(value));
430 return materials.size() - 1;
431 }
else if constexpr (std::is_same_v<ElementType, Light>) {
432 lights.emplace_back(std::forward<T>(value));
433 return lights.size() - 1;
434 }
else if constexpr (std::is_same_v<ElementType, Camera>) {
435 cameras.emplace_back(std::forward<T>(value));
436 return cameras.size() - 1;
437 }
else if constexpr (std::is_same_v<ElementType, Skeleton>) {
438 skeletons.emplace_back(std::forward<T>(value));
439 return skeletons.size() - 1;
440 }
else if constexpr (std::is_same_v<ElementType, Animation>) {
441 animations.emplace_back(std::forward<T>(value));
442 return animations.size() - 1;
AttributeValueType
Enum describing at runtime the value type of an attribute.
Definition: AttributeValueType.h:25
internal::Range< Index > range(Index end)
Returns an iterable object representing the range [0, end).
Definition: range.h:176
Main namespace for Lagrange.
Definition: AABBIGL.h:30
Compilers might complain about static_assert(false, "").
Definition: common.h:96
Definition: SceneExtension.h:192
Minimalistic image data structure that stores the raw image data.
Definition: Scene.h:87
AttributeValueType element_type
The scalar type of the elements in the buffer.
Definition: Scene.h:98
std::vector< unsigned char > data
Raw buffer of size (width * height * num_channels * num_bits_per_element / 8) bytes containing image ...
Definition: Scene.h:101
Image structure that can store either image data or reference to an image file.
Definition: Scene.h:113
Extensions extensions
Image extensions.
Definition: Scene.h:125
ImageBufferExperimental image
Image data.
Definition: Scene.h:118
std::string name
Image name. Not guaranteed to be unique and can be empty.
Definition: Scene.h:115
fs::path uri
Image file path.
Definition: Scene.h:122
void add_child(ElementId parent_id, ElementId child_id)
Add a child node to a given parent node.
Definition: Scene.cpp:19
ElementId add(T &&value)
Add an element to the scene.
Definition: Scene.h:413