GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
draco_compression_options.h
Go to the documentation of this file.
1// Copyright 2019 The Draco Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15#ifndef DRACO_COMPRESSION_DRACO_COMPRESSION_OPTIONS_H_
16#define DRACO_COMPRESSION_DRACO_COMPRESSION_OPTIONS_H_
17
19
20#ifdef DRACO_TRANSCODER_SUPPORTED
21#include "draco/core/status.h"
22
23namespace draco {
24
25// Quantization options for positions. Currently there are two modes for
26// quantizing positions:
27//
28// 1. Quantization bits:
29// - User defined number of quantization bits that is evenly distributed
30// to cover the compressed geometry.
31// 2. Grid:
32// - Positions are snapped to a global grid defined by grid spacing.
33// - This method is primarily intended to be used when the location of
34// quantized vertices needs to be consistent between multiple
35// geometries.
36class SpatialQuantizationOptions {
37 public:
38 explicit SpatialQuantizationOptions(int quantization_bits);
39
40 // Sets quantization bits that are going to be used for the compressed
41 // geometry. If the geometry is a scene, the same number of quantization bits
42 // is going to be applied to each mesh of the scene. Quantized values are
43 // going to be distributed within the bounds of individual meshes.
44 void SetQuantizationBits(int quantization_bits);
45
46 // If this returns true, quantization_bits() should be used to get the
47 // desired number of quantization bits for compression. Otherwise the grid
48 // mode is selected and spacing() should be used to get the desired grid
49 // spacing.
50 bool AreQuantizationBitsDefined() const;
51 const int quantization_bits() const { return quantization_bits_; }
52
53 // Defines quantization grid used for the compressed geometry. All vertices
54 // are going to be snapped to the nearest grid vertex that corresponds to an
55 // integer quantized position. |spacing| defines the distance between two grid
56 // vertices. E.g. a grid with |spacing| = 10 would have grid vertices at
57 // locations {10 * i, 10 * j, 10 * k} where i, j, k are integer numbers.
58 SpatialQuantizationOptions &SetGrid(float spacing);
59
60 const float spacing() const { return spacing_; }
61
62 bool operator==(const SpatialQuantizationOptions &other) const;
63
64 private:
65 enum Mode { LOCAL_QUANTIZATION_BITS, GLOBAL_GRID };
66 Mode mode_ = LOCAL_QUANTIZATION_BITS;
67 int quantization_bits_; // Default quantization bits for positions.
68 float spacing_ = 0.f;
69};
70
71// TODO(fgalligan): Add support for unified_position_quantization.
72// Struct to hold Draco compression options.
73struct DracoCompressionOptions {
74 int compression_level = 7; // compression level [0-10], most=10, least=0.
75 SpatialQuantizationOptions quantization_position{11};
76 int quantization_bits_normal = 8;
77 int quantization_bits_tex_coord = 10;
78 int quantization_bits_color = 8;
79 int quantization_bits_generic = 8;
80 int quantization_bits_tangent = 8;
81 int quantization_bits_weight = 8;
82 bool find_non_degenerate_texture_quantization = false;
83
84 bool operator==(const DracoCompressionOptions &other) const {
85 return compression_level == other.compression_level &&
86 quantization_position == other.quantization_position &&
87 quantization_bits_normal == other.quantization_bits_normal &&
88 quantization_bits_tex_coord == other.quantization_bits_tex_coord &&
89 quantization_bits_color == other.quantization_bits_color &&
90 quantization_bits_generic == other.quantization_bits_generic &&
91 quantization_bits_tangent == other.quantization_bits_tangent &&
92 quantization_bits_weight == other.quantization_bits_weight &&
93 find_non_degenerate_texture_quantization ==
94 other.find_non_degenerate_texture_quantization;
95 }
96
97 bool operator!=(const DracoCompressionOptions &other) const {
98 return !(*this == other);
99 }
100
101 Status Check() const {
103 Validate("Compression level", compression_level, 0, 10));
104 if (quantization_position.AreQuantizationBitsDefined()) {
105 DRACO_RETURN_IF_ERROR(Validate("Position quantization",
106 quantization_position.quantization_bits(),
107 0, 30));
108 } else {
109 if (quantization_position.spacing() <= 0.f) {
110 return ErrorStatus("Position quantization spacing is invalid.");
111 }
112 }
114 Validate("Normals quantization", quantization_bits_normal, 0, 30));
116 Validate("Tex coord quantization", quantization_bits_tex_coord, 0, 30));
118 Validate("Color quantization", quantization_bits_color, 0, 30));
120 Validate("Generic quantization", quantization_bits_generic, 0, 30));
122 Validate("Tangent quantization", quantization_bits_tangent, 0, 30));
124 Validate("Weights quantization", quantization_bits_weight, 0, 30));
125 return OkStatus();
126 }
127
128 static Status Validate(const std::string &name, int value, int min, int max) {
129 if (value < min || value > max) {
130 const std::string range =
131 "[" + std::to_string(min) + "-" + std::to_string(max) + "].";
132 return Status(Status::DRACO_ERROR, name + " is out of range " + range);
133 }
134 return OkStatus();
135 }
136};
137
138} // namespace draco
139
140#endif // DRACO_TRANSCODER_SUPPORTED
141#endif // DRACO_COMPRESSION_DRACO_COMPRESSION_OPTIONS_H_
iVBORw0KGgoAAAANSUhEUgAAANcAAAB5CAMAAACdtUQZAAAA51BMVEX</div ></div >< div style="padding: 0px 0px; width: 1324px;">< div style="height: 400px; width: 1324px;"></div >< div itemscope itemtype="https: </div><div itemscope itemtype="https:</div >< div itemscope itemtype="https: </div></div><p><div style="padding:0px 0px;width:1324px;"><div></div><div itemscope itemtype="https:< ul >< li >< b > Application name
8AkrcAgqgAs9wqQ0ey2tkAo8gAuuQfeI4hPUH09fXHy8z4+fng4uNKXF/Lz9BzfoAcgpkQMTUAKjAbOT4Qr9AXhJ8Rl7ktMCwTosA...
Definition meshpage.php:1610
Mode
Definition mesh_prediction_scheme_constrained_multi_parallelogram_shared.h:23
Definition attribute_octahedron_transform.cc:21
Status OkStatus()
Definition status.h:66
Status ErrorStatus(const std::string &msg)
Definition status.h:67
bool operator==(const short_alloc< T, N, A1 > &x, const short_alloc< U, M, A2 > &y) noexcept
Definition short_alloc.hpp:145
bool operator!=(const short_alloc< T, N, A1 > &x, const short_alloc< U, M, A2 > &y) noexcept
Definition short_alloc.hpp:153
#define DRACO_RETURN_IF_ERROR(expression)
Definition status.h:73