Dandelion 1.1.2
A light-weight 3D builder for educational usage
载入中...
搜索中...
未找到
group.h
浏览该文件的文档.
1#ifndef DANDELION_SCENE_GROUP_H
2#define DANDELION_SCENE_GROUP_H
3
4#include <cstddef>
5#include <string>
6
7#include <spdlog/spdlog.h>
8#include <nlohmann/json.hpp>
9
10#include "object.h"
11
12/*!
13 * \ingroup rendering
14 * \ingroup simulation
15 * \file scene/group.h
16 * \~chinese
17 * \brief 包含物体组的类。
18 */
19
20/*!
21 * \ingroup rendering
22 * \ingroup simulation
23 * \~chinese
24 * \brief 表示物体组的类。
25 *
26 * 一个模型文件(例如一个 obj 文件)中可以包含多个物体,
27 * 因此加载一个模型文件的结果是一个组而不是一个物体。加载完成后,组名即文件名、
28 * 各物体名即文件中各 mesh 的名称。在删除组中所有的物体后该组为空但不会被删除,
29 * 未来将实现组间转移物体和向组中添加物体的功能。
30 */
31class Group
32{
33public:
34
35 /*!
36 * \~chinese
37 * 创建一个组只需要指定组名,加载模型数据要显式调用 `load` 方法。
38 * \param group_name 要创建组的组名
39 */
40 Group(const std::string& group_name);
41 ///@{
42 /*! \~chinese 禁止复制组。 */
43 Group(Group& other) = delete;
44 Group(const Group& other) = delete;
45 ///@}
46 ~Group() = default;
47 /*!
48 * \~chinese
49 * 被 `Scene::load` 调用,真正加载模型数据的函数。
50 * 这个函数只加载模型 mesh 数据,不包括变换、物理属性等 `Object` 层面的信息
51 * \param file_path 要加载模型的文件路径
52 * \returns 是否加载成功
53 */
54 bool load_models(const std::string& file_path);
55 /*!
56 * \~chinese
57 * 将 `Group` 保存为单个 obj 文件,包括 mesh、材质等信息
58 * \param file_path 保存的文件路径
59 * \returns 是否保存成功
60 */
61 bool save_models(const std::string& file_path);
62 /*!
63 * \~chinese
64 * 加载以 JSON 格式保存的除 mesh 和材质以外的数据,如变换、物理属性
65 * \param metadata 包含所有额外信息的 JSON 对象
66 */
67 void load_metadata(const nlohmann::json& metadata);
68 /*!
69 * \~chinese
70 * 将模型以外的额外信息序列化为 JSON 对象,用 `load_metadata` 可以读取
71 * \returns 表示该组中所有物体信息的 JSON 对象
72 */
73 nlohmann::json dump_metadata();
74 /*! \~chinese 组中所有的物体。 */
75 std::vector<std::unique_ptr<Object>> objects;
76 /*! \~chinese 组的唯一 ID。 */
77 std::size_t id;
78 /*! \~chinese 组名,来自加载时的文件名。 */
79 std::string name;
80
81private:
82
83 /*! \~chinese 下一个可用的组 ID。 */
84 static std::size_t next_available_id;
85 std::shared_ptr<spdlog::logger> logger;
86};
87
88#endif // DANDELION_SCENE_GROUP_H
Group(const std::string &group_name)
Group(Group &other)=delete
std::vector< std::unique_ptr< Object > > objects
定义 group.h:75
nlohmann::json dump_metadata()
定义 group.cpp:261
static std::size_t next_available_id
定义 group.h:84
bool load_models(const std::string &file_path)
定义 group.cpp:36
std::string name
定义 group.h:79
void load_metadata(const nlohmann::json &metadata)
定义 group.cpp:241
Group(const Group &other)=delete
std::size_t id
定义 group.h:77
bool save_models(const std::string &file_path)
定义 group.cpp:137
包含物体的类。