Lagrange
Loading...
Searching...
No Matches
scene_utils.h
1/*
2 * Copyright 2023 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/SurfaceMesh.h>
15#include <lagrange/scene/Scene.h>
16#include <lagrange/scene/api.h>
17
18namespace lagrange::scene::utils {
19
20// add child to the node. Assumes the child was already added to the scene.
21[[deprecated("Use Scene::add_child instead")]] inline void add_child(
22 Node& node,
23 ElementId child_index)
24{
25 node.children.push_back(child_index);
26}
27
28// add child to the node and the scene. Assumes the child was not already added to the scene.
29template <typename Scalar, typename Index>
30[[deprecated("Use Scene::add_child instead")]] ElementId
31add_child(Scene<Scalar, Index>& scene, Node& node, Node child)
32{
33 ElementId child_idx = scene.nodes.size();
34 scene.nodes.push_back(child);
35 node.children.push_back(child_idx);
36 return child_idx;
37}
38
39// add mesh to the scene (but not to the node graph!) and return its index.
40template <typename Scalar, typename Index>
41[[deprecated("Use Scene::add(mesh) instead")]] ElementId add_mesh(
42 Scene<Scalar, Index>& scene,
43 SurfaceMesh<Scalar, Index> mesh)
44{
45 scene.meshes.emplace_back(std::move(mesh));
46 return scene.meshes.size() - 1;
47}
48
49// Returns the global transform of a node.
50// Note that this has to traverse the node hierarchy up to the root.
51// Considering saving the global transforms if you need them often.
52template <typename Scalar, typename Index>
53Eigen::Affine3f compute_global_node_transform(const Scene<Scalar, Index>& scene, ElementId node_idx)
54{
55 if (node_idx == lagrange::invalid<size_t>()) return Eigen::Affine3f::Identity();
56 const Node& n = scene.nodes[node_idx];
57 return compute_global_node_transform<Scalar, Index>(scene, n.parent) * n.transform;
58}
59
69LA_SCENE_API Eigen::Affine3f camera_view_transform(
70 const Camera& camera,
71 const Eigen::Affine3f& world_from_local = Eigen::Affine3f::Identity());
72
80LA_SCENE_API Eigen::Projective3f camera_projection_transform(const Camera& camera);
81
97template <typename Scalar, typename Index>
98void convert_texcoord_uv_st(
99 SurfaceMesh<Scalar, Index>& mesh,
100 AttributeId attribute_id = invalid<AttributeId>());
101
102} // namespace lagrange::scene::utils
uint32_t AttributeId
Identified to be used to access an attribute.
Definition AttributeFwd.h:73
constexpr T invalid()
You can use invalid<T>() to get a value that can represent "invalid" values, such as invalid indices ...
Definition invalid.h:40