Lagrange
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
17namespace lagrange::scene::utils {
18
19// add child to the node. Assumes the child was already added to the scene.
20[[deprecated("Use Scene::add_child instead")]] inline void add_child(
21 Node& node,
22 ElementId child_index)
23{
24 node.children.push_back(child_index);
25}
26
27// add child to the node and the scene. Assumes the child was not already added to the scene.
28template <typename Scalar, typename Index>
29[[deprecated("Use Scene::add_child instead")]] ElementId
30add_child(Scene<Scalar, Index>& scene, Node& node, Node child)
31{
32 ElementId child_idx = scene.nodes.size();
33 scene.nodes.push_back(child);
34 node.children.push_back(child_idx);
35 return child_idx;
36}
37
38// add mesh to the scene (but not to the node graph!) and return its index.
39template <typename Scalar, typename Index>
40[[deprecated("Use Scene::add(mesh) instead")]] ElementId add_mesh(
41 Scene<Scalar, Index>& scene,
42 SurfaceMesh<Scalar, Index> mesh)
43{
44 scene.meshes.emplace_back(std::move(mesh));
45 return scene.meshes.size() - 1;
46}
47
48// Returns the global transform of a node.
49// Note that this has to traverse the node hierarchy up to the root.
50// Considering saving the global transforms if you need them often.
51template <typename Scalar, typename Index>
52Eigen::Affine3f compute_global_node_transform(const Scene<Scalar, Index>& scene, ElementId node_idx)
53{
54 if (node_idx == lagrange::invalid<size_t>()) return Eigen::Affine3f::Identity();
55 const Node& n = scene.nodes[node_idx];
56 return compute_global_node_transform<Scalar, Index>(scene, n.parent) * n.transform;
57}
58
74template <typename Scalar, typename Index>
75void convert_texcoord_uv_st(
76 SurfaceMesh<Scalar, Index>& mesh,
77 AttributeId attribute_id = invalid<AttributeId>());
78
79} // namespace lagrange::scene::utils
uint32_t AttributeId
Identified to be used to access an attribute.
Definition: AttributeFwd.h:73