GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
property_table.h
Go to the documentation of this file.
1// Copyright 2022 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_METADATA_PROPERTY_TABLE_H_
16#define DRACO_METADATA_PROPERTY_TABLE_H_
17
19
20#ifdef DRACO_TRANSCODER_SUPPORTED
21
22#include <memory>
23#include <string>
24#include <vector>
25
26namespace draco {
27
28// Describes a property table as defined in the EXT_structural_metadata glTF
29// extension, including property table schema and table properties (columns).
30class PropertyTable {
31 public:
32 // Describes property table schema in the form of a JSON object.
33 struct Schema {
34 // JSON object of the schema.
35 // TODO(vytyaz): Consider using a third_party/json library. Currently there
36 // is a conflict between Filament's assert_invariant() macro and JSON
37 // library's assert_invariant() method that causes compile errors in Draco
38 // visualization library.
39 class Object {
40 public:
41 enum Type { OBJECT, ARRAY, STRING, INTEGER, BOOLEAN };
42
43 // Constructors.
44 Object() : Object("") {}
45 explicit Object(const std::string& name)
46 : name_(name), type_(OBJECT), integer_(0), boolean_(false) {}
47 Object(const std::string& name, const std::string& value) : Object(name) {
48 SetString(value);
49 }
50 Object(const std::string& name, const char* value) : Object(name) {
51 SetString(value);
52 }
53 Object(const std::string& name, int value) : Object(name) {
54 SetInteger(value);
55 }
56 Object(const std::string& name, bool value) : Object(name) {
57 SetBoolean(value);
58 }
59
60 // Methods for comparing two objects.
61 bool operator==(const Object& other) const;
62 bool operator!=(const Object& other) const { return !(*this == other); }
63
64 // Method for copying the object.
65 void Copy(const Object& src);
66
67 // Methods for getting object name and type.
68 const std::string& GetName() const { return name_; }
69 Type GetType() const { return type_; }
70
71 // Methods for getting object value.
72 const std::vector<Object>& GetObjects() const { return objects_; }
73 const std::vector<Object>& GetArray() const { return array_; }
74 const std::string& GetString() const { return string_; }
75 int GetInteger() const { return integer_; }
76 bool GetBoolean() const { return boolean_; }
77
78 // Methods for setting object value.
79 std::vector<Object>& SetObjects() {
80 type_ = OBJECT;
81 return objects_;
82 }
83 std::vector<Object>& SetArray() {
84 type_ = ARRAY;
85 return array_;
86 }
87 void SetString(const std::string& value) {
88 type_ = STRING;
89 string_ = value;
90 }
91 void SetInteger(int value) {
92 type_ = INTEGER;
93 integer_ = value;
94 }
95 void SetBoolean(bool value) {
96 type_ = BOOLEAN;
97 boolean_ = value;
98 }
99
100 private:
101 std::string name_;
102 Type type_;
103 std::vector<Object> objects_;
104 std::vector<Object> array_;
105 std::string string_;
106 int integer_;
107 bool boolean_;
108 };
109
110 // Valid schema top-level JSON object name is "schema".
111 Schema() : json("schema") {}
112
113 // Methods for comparing two schemas.
114 bool operator==(const Schema& other) const { return json == other.json; }
115 bool operator!=(const Schema& other) const { return !(*this == other); }
116
117 // Valid schema top-level JSON object is required to have child objects.
118 bool Empty() const { return json.GetObjects().empty(); }
119
120 // Top-level JSON object of the schema.
121 Object json;
122 };
123
124 // Describes a property (column) of a property table.
125 class Property {
126 public:
127 // Describes glTF buffer view data.
128 struct Data {
129 // Methods for comparing two data objects.
130 bool operator==(const Data& other) const;
131 bool operator!=(const Data& other) const { return !(*this == other); }
132
133 // Buffer view data.
134 std::vector<uint8_t> data;
135
136 // Data target corresponds to the target property of the glTF bufferView
137 // object and classifies the type or nature of the data.
138 int target = 0;
139 };
140
141 // Describes offsets of the entries in property data when the data
142 // represents an array of strings or an array of variable-length number
143 // arrays.
144 struct Offsets {
145 // Methods for comparing two offsets.
146 bool operator==(const Offsets& other) const;
147 bool operator!=(const Offsets& other) const { return !(*this == other); }
148
149 // Data containing the offset entries.
150 Data data;
151
152 // Data type of the offset entries.
153 std::string type;
154 };
155
156 // Creates an empty property.
157 Property();
158
159 // Methods for comparing two properties.
160 bool operator==(const Property& other) const;
161 bool operator!=(const Property& other) const { return !(*this == other); }
162
163 // Copies all data from |src| property.
164 void Copy(const Property& src);
165
166 // Name of this property.
167 void SetName(const std::string& name);
168 const std::string& GetName() const;
169
170 // Property data stores one table column worth of data. For example, when
171 // the data of type UINT8 is [11, 22] then the property values are 11 and 22
172 // for the first and second table rows. See EXT_structural_metadata glTF
173 // extension documentation for more details.
174 Data& GetData();
175 const Data& GetData() const;
176
177 // Array offsets are used when property data contains a variable-length
178 // number arrays. For example, when the data is [0, 1, 2, 3, 4] and the
179 // array offsets are [0, 2, 5] for a two-row table, then the property value
180 // arrays are [0, 1] and [2, 3, 4] for the first and second table rows,
181 // respectively. See EXT_structural_metadata glTF extension documentation
182 // for more details.
183 const Offsets& GetArrayOffsets() const;
184 Offsets& GetArrayOffsets();
185
186 // String offsets are used when property data contains strings. For example,
187 // when the data is "SeaLand" and the array offsets are [0, 3, 7] for a
188 // two-row table, then the property strings are "Sea" and "Land" for the
189 // first and second table rows, respectively. See EXT_structural_metadata
190 // glTF extension documentation for more details.
191 const Offsets& GetStringOffsets() const;
192 Offsets& GetStringOffsets();
193
194 private:
195 std::string name_;
196 Data data_;
197 Offsets array_offsets_;
198 Offsets string_offsets_;
199 // TODO(vytyaz): Support property value modifiers min, max, offset, scale.
200 };
201
202 // Creates an empty property table.
203 PropertyTable();
204
205 // Methods for comparing two property tables.
206 bool operator==(const PropertyTable& other) const;
207 bool operator!=(const PropertyTable& other) const {
208 return !(*this == other);
209 }
210
211 // Copies all data from |src| property table.
212 void Copy(const PropertyTable& src);
213
214 // Name of this property table.
215 void SetName(const std::string& value);
216 const std::string& GetName() const;
217
218 // Class of this property table.
219 void SetClass(const std::string& value);
220 const std::string& GetClass() const;
221
222 // Number of rows in this property table.
223 void SetCount(int count);
224 int GetCount() const;
225
226 // Table properties (columns).
227 int AddProperty(std::unique_ptr<Property> property);
228 int NumProperties() const;
229 const Property& GetProperty(int index) const;
230 Property& GetProperty(int index);
231 void RemoveProperty(int index);
232
233 private:
234 std::string name_;
235 std::string class_;
236 int count_;
237 std::vector<std::unique_ptr<Property>> properties_;
238};
239
240} // namespace draco
241
242#endif // DRACO_TRANSCODER_SUPPORTED
243#endif // DRACO_METADATA_PROPERTY_TABLE_H_
Type
Definition Database.hh:9
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
lazy data
Definition meshpage.php:1583
tag src
Definition meshpage.php:1786
Definition attribute_octahedron_transform.cc:21
basic_json<> json
default JSON class
Definition json.hpp:111
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