Welcome to mirror list, hosted at ThFree Co, Russian Federation.

draco-compressor.h « src « draco « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fb6168a61af3549ea8e690b8ee3bbdf821bda9d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * C++ library for the Draco compression feature inside the glTF-Blender-IO project.
 *
 * The python side uses the CTypes library to open the DLL, load function
 * pointers add pass the data to the compressor as raw bytes.
 *
 * The compressor intercepts the regular glTF exporter after data has been
 * gathered and right before the data is converted to a JSON representation,
 * which is going to be written out.
 *
 * The original uncompressed data is removed and replaces an extension,
 * pointing to the newly created buffer containing the compressed data.
 *
 * @author Jim Eckerlein <eckerlein@ux3d.io>
 * @date   2019-11-29
 */

#include <cstdint>

#if defined(_MSC_VER)
#define DLL_EXPORT(retType) extern "C" __declspec(dllexport) retType __cdecl
#else
#define DLL_EXPORT(retType) extern "C" retType
#endif

/**
 * This tuple is opaquely exposed to Python through a pointer.
 * It encapsulates the complete current compressor state.
 *
 * A single instance is only intended to compress a single primitive.
 */
struct DracoCompressor;

DLL_EXPORT(DracoCompressor *)
create_compressor ();

DLL_EXPORT(void)
set_compression_level (
    DracoCompressor *compressor,
    uint32_t compressionLevel
);

DLL_EXPORT(void)
set_position_quantization (
    DracoCompressor *compressor,
    uint32_t quantizationBitsPosition
);

DLL_EXPORT(void)
set_normal_quantization (
    DracoCompressor *compressor,
    uint32_t quantizationBitsNormal
);

DLL_EXPORT(void)
set_uv_quantization (
    DracoCompressor *compressor,
    uint32_t quantizationBitsTexCoord
);

DLL_EXPORT(void)
set_generic_quantization (
    DracoCompressor *compressor,
    uint32_t bits
);

/// Compresses a mesh.
/// Use `compress_morphed` when compressing primitives which have morph targets.
DLL_EXPORT(bool)
compress (
    DracoCompressor *compressor
);

/// Compresses the mesh.
/// Use this instead of `compress`, because this procedure takes into account that mesh triangles must not be reordered.
DLL_EXPORT(bool)
compress_morphed (
    DracoCompressor *compressor
);

/**
 * Returns the size of the compressed data in bytes.
 */
DLL_EXPORT(uint64_t)
get_compressed_size (
    DracoCompressor const *compressor
);

/**
 * Copies the compressed mesh into the given byte buffer.
 *
 * @param[o_data] A Python `bytes` object.
 */
DLL_EXPORT(void)
copy_to_bytes (
    DracoCompressor const *compressor,
    uint8_t *o_data
);

/**
 * Releases all memory allocated by the compressor.
 */
DLL_EXPORT(void)
destroy_compressor (
    DracoCompressor *compressor
);

DLL_EXPORT(void)
set_faces (
    DracoCompressor *compressor,
    uint32_t index_count,
    uint32_t index_byte_length,
    uint8_t const *indices
);

/// Adds a `float` position attribute to the current mesh.
/// Returns the id Draco has assigned to this attribute.
DLL_EXPORT(uint32_t)
add_positions_f32 (
    DracoCompressor *compressor,
    uint32_t count,
    uint8_t const *data
);

/// Adds a `float` normal attribute to the current mesh.
/// Returns the id Draco has assigned to this attribute.
DLL_EXPORT(uint32_t)
add_normals_f32 (
    DracoCompressor *compressor,
    uint32_t count,
    uint8_t const *data
);

/// Adds a `float` texture coordinate attribute to the current mesh.
/// Returns the id Draco has assigned to this attribute.
DLL_EXPORT(uint32_t)
add_uvs_f32 (
    DracoCompressor *compressor,
    uint32_t count,
    uint8_t const *data
);

/// Adds a `unsigned short` joint attribute to the current mesh.
/// Returns the id Draco has assigned to this attribute.
DLL_EXPORT(uint32_t)
add_joints_u16 (
    DracoCompressor *compressor,
    uint32_t count,
    uint8_t const *data
);

/// Adds a `float` weight attribute to the current mesh.
/// Returns the id Draco has assigned to this attribute.
DLL_EXPORT(uint32_t)
add_weights_f32 (
    DracoCompressor *compressor,
    uint32_t count,
    uint8_t const *data
);