OCCT-Light 0.1
C ABI and C++ veneer for multi-language CAD workflows
Loading...
Searching...
No Matches
io_gltf.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 Capgemini Engineering Research and Development.
2//
3// This file is part of OCCT-Light software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Affero General Public License version 3 as published
7// by the Free Software Foundation, with an option to use any later version.
8// Consult the file LICENSE_AGPL_30.txt included in OCCT-Light distribution
9// for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of a commercial
12// license or contractual agreement.
13//
14// SPDX-License-Identifier: AGPL-3.0-or-later
15
21#ifndef OCCTL_HPP_IO_GLTF_HPP
22#define OCCTL_HPP_IO_GLTF_HPP
23
24#include <occtl/occtl_io_gltf.h>
25
26#include <occtl-hpp/core.hpp>
27#include <occtl-hpp/topo.hpp>
28
29#include <string>
30#include <utility>
31#include <vector>
32
33namespace occtl::io_gltf
34{
35
43
46{
47 bool load_all_scenes = false;
48 bool skip_empty_nodes = true;
49 bool use_mesh_name_as_fallback = true;
50 bool apply_scale = true;
51 bool parallel = false;
52 bool single_precision = true;
53 bool fill_incomplete = true;
54 int memory_limit_mib = -1;
55
56 [[nodiscard]] ::occtl_io_gltf_read_options_t to_c() const noexcept
57 {
58 ::occtl_io_gltf_read_options_t aOpts = OCCTL_IO_GLTF_READ_OPTIONS_INIT;
59 aOpts.load_all_scenes = load_all_scenes ? 1 : 0;
60 aOpts.skip_empty_nodes = skip_empty_nodes ? 1 : 0;
61 aOpts.use_mesh_name_as_fallback = use_mesh_name_as_fallback ? 1 : 0;
62 aOpts.apply_scale = apply_scale ? 1 : 0;
63 aOpts.parallel = parallel ? 1 : 0;
64 aOpts.single_precision = single_precision ? 1 : 0;
65 aOpts.fill_incomplete = fill_incomplete ? 1 : 0;
66 aOpts.memory_limit_mib = memory_limit_mib;
67 return aOpts;
68 }
69};
70
73{
74 TransformFormat transform_format = TransformFormat::Compact;
75 bool force_uv_export = false;
76 bool embed_textures_in_glb = true;
77 bool merge_faces = false;
78 bool split_indices_16 = false;
79
80 [[nodiscard]] ::occtl_io_gltf_write_options_t to_c() const noexcept
81 {
82 ::occtl_io_gltf_write_options_t aOpts = OCCTL_IO_GLTF_WRITE_OPTIONS_INIT;
83 aOpts.transform_format = static_cast<::occtl_io_gltf_transform_format_t>(transform_format);
84 aOpts.force_uv_export = force_uv_export ? 1 : 0;
85 aOpts.embed_textures_in_glb = embed_textures_in_glb ? 1 : 0;
86 aOpts.merge_faces = merge_faces ? 1 : 0;
87 aOpts.split_indices_16 = split_indices_16 ? 1 : 0;
88 return aOpts;
89 }
90};
91
94inline std::pair<Graph, NodeId> read(const std::string& thePath,
95 const ReadOptions& theOptions = ReadOptions{})
96{
97 ::occtl_graph_t* aRaw = nullptr;
98 ::occtl_node_id_t aRoot{};
99 const ::occtl_io_gltf_read_options_t aOpts = theOptions.to_c();
100 check(::occtl_io_gltf_read(thePath.c_str(), &aRaw, &aRoot, &aOpts));
101 return {Graph(aRaw), NodeId(aRoot)};
102}
103
106inline void write(const Graph& theGraph,
107 const NodeId theRoot,
108 const std::string& thePath,
109 const WriteOptions& theOptions = WriteOptions{})
110{
111 const ::occtl_io_gltf_write_options_t aOpts = theOptions.to_c();
112 check(::occtl_io_gltf_write(theGraph.get(), theRoot.get(), thePath.c_str(), &aOpts));
113}
114
115} // namespace occtl::io_gltf
116
117#endif // OCCTL_HPP_IO_GLTF_HPP
RAII handle for a topology graph. Mirrors occtl_graph_t.
Definition topo.hpp:1444
::occtl_graph_t * get() const noexcept
Borrows-it pointer to the underlying C handle, for direct ABI calls.
Definition topo.hpp:1494
Session-local identity of a graph node. Mirrors occtl_node_id_t.
Definition topo.hpp:52
::occtl_node_id_t get() const noexcept
Borrows-it view of the underlying C value type, for direct ABI calls.
Definition topo.hpp:64
C++ veneer for the core module.
void check(const ::occtl_status_t theStatus)
Throw on non-OK; otherwise a no-op.
Definition core.hpp:85
TransformFormat
Transform encoding used when writing glTF node transforms.
Definition io_gltf.hpp:38
OCCT-Light: glTF 2.0 / GLB file I/O.
@ OCCTL_IO_GLTF_TRANSFORM_TRS
Definition occtl_io_gltf.h:53
@ OCCTL_IO_GLTF_TRANSFORM_COMPACT
Definition occtl_io_gltf.h:51
@ OCCTL_IO_GLTF_TRANSFORM_MAT4
Definition occtl_io_gltf.h:52
occtl_status_t occtl_io_gltf_write(const occtl_graph_t *graph, occtl_node_id_t root, const char *path, const occtl_io_gltf_write_options_t *options)
enum occtl_io_gltf_transform_format occtl_io_gltf_transform_format_t
occtl_status_t occtl_io_gltf_read(const char *path, occtl_graph_t **out_graph, occtl_node_id_t *out_root, const occtl_io_gltf_read_options_t *options)
struct occtl_graph occtl_graph_t
Definition occtl_topo_types.h:152
Options for read. PascalCase mirror of occtl_io_gltf_read_options_t.
Definition io_gltf.hpp:46
Options for write. PascalCase mirror of occtl_io_gltf_write_options_t.
Definition io_gltf.hpp:73
Definition occtl_io_gltf.h:64
int32_t single_precision
Definition occtl_io_gltf.h:72
int32_t fill_incomplete
Definition occtl_io_gltf.h:73
int32_t memory_limit_mib
Definition occtl_io_gltf.h:74
int32_t load_all_scenes
Definition occtl_io_gltf.h:67
int32_t apply_scale
Definition occtl_io_gltf.h:70
int32_t parallel
Definition occtl_io_gltf.h:71
int32_t use_mesh_name_as_fallback
Definition occtl_io_gltf.h:69
int32_t skip_empty_nodes
Definition occtl_io_gltf.h:68
Definition occtl_io_gltf.h:84
int32_t force_uv_export
Definition occtl_io_gltf.h:88
occtl_io_gltf_transform_format_t transform_format
Definition occtl_io_gltf.h:87
int32_t embed_textures_in_glb
Definition occtl_io_gltf.h:89
int32_t split_indices_16
Definition occtl_io_gltf.h:91
int32_t merge_faces
Definition occtl_io_gltf.h:90
Definition occtl_topo_types.h:50
C++ veneer for the topo module.