forked from facebookresearch/habitat-sim
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAttributesBindings.cpp
More file actions
466 lines (443 loc) · 23.5 KB
/
AttributesBindings.cpp
File metadata and controls
466 lines (443 loc) · 23.5 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
// Copyright (c) Facebook, Inc. and its affiliates.
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
#include "esp/bindings/bindings.h"
#include <Magnum/PythonBindings.h>
#include "esp/core/managedContainers/AbstractManagedObject.h"
#include "esp/metadata/attributes/AttributesBase.h"
#include "esp/metadata/attributes/LightLayoutAttributes.h"
#include "esp/metadata/attributes/ObjectAttributes.h"
#include "esp/metadata/attributes/PhysicsManagerAttributes.h"
#include "esp/metadata/attributes/PrimitiveAssetAttributes.h"
#include "esp/metadata/attributes/SceneAttributes.h"
namespace py = pybind11;
using py::literals::operator""_a;
namespace Attrs = esp::metadata::attributes;
using Attrs::AbstractAttributes;
using Attrs::AbstractObjectAttributes;
using Attrs::AbstractPrimitiveAttributes;
using Attrs::CapsulePrimitiveAttributes;
using Attrs::ConePrimitiveAttributes;
using Attrs::CubePrimitiveAttributes;
using Attrs::CylinderPrimitiveAttributes;
using Attrs::IcospherePrimitiveAttributes;
using Attrs::LightInstanceAttributes;
using Attrs::LightLayoutAttributes;
using Attrs::ObjectAttributes;
using Attrs::PhysicsManagerAttributes;
using Attrs::StageAttributes;
using Attrs::UVSpherePrimitiveAttributes;
using esp::core::AbstractFileBasedManagedObject;
using esp::core::AbstractManagedObject;
namespace esp {
namespace metadata {
void initAttributesBindings(py::module& m) {
// ==== AbstractManagedObject ====
// NOLINTNEXTLINE(bugprone-unused-raii)
py::class_<AbstractManagedObject, AbstractManagedObject::ptr>(
m, "AbstractManagedObject");
// ==== AbstractFileBasedManagedObject ====
// NOLINTNEXTLINE(bugprone-unused-raii)
py::class_<AbstractFileBasedManagedObject, esp::core::AbstractManagedObject,
AbstractFileBasedManagedObject::ptr>(
m, "AbstractFileBasedManagedObject");
// ==== AbstractAttributes ====
py::class_<AbstractAttributes, esp::core::AbstractFileBasedManagedObject,
esp::core::config::Configuration, AbstractAttributes::ptr>(
m, "AbstractAttributes")
.def(py::init(
&AbstractAttributes::create<const std::string&, const std::string&>))
.def_property("handle", &AbstractAttributes::getHandle,
&AbstractAttributes::setHandle,
R"(Name of attributes template. )")
.def_property_readonly(
"file_directory", &AbstractAttributes::getFileDirectory,
R"(Directory where file-based templates were loaded from.)")
.def_property_readonly(
"template_id", &AbstractAttributes::getID,
R"(System-generated ID for template. Will be unique among templates
of same type.)")
.def(
"get_user_config", &AbstractAttributes::editUserConfiguration,
py::return_value_policy::reference_internal,
R"(Returns a reference to the User Config object for this attributes, so that it can be
viewed or modified. Any changes to the user_config will require the owning
attributes to be re-registered.)")
.def_property_readonly(
"num_user_configs",
&AbstractAttributes::getNumUserDefinedConfigurations,
R"(The number of currently specified user-defined configuration values.)")
.def_property_readonly("template_class", &AbstractAttributes::getClassKey,
R"(Class name of Attributes template.)")
.def_property_readonly(
"csv_info", &AbstractAttributes::getObjectInfo,
R"(Comma-separated informational string describing this Attributes template)");
// ==== AbstractObjectAttributes ====
py::class_<AbstractObjectAttributes, AbstractAttributes,
AbstractObjectAttributes::ptr>(m, "AbstractObjectAttributes")
.def(py::init(&AbstractObjectAttributes::create<const std::string&,
const std::string&>))
.def_property(
"scale", &AbstractObjectAttributes::getScale,
&AbstractObjectAttributes::setScale,
R"(Scale multiplier for constructions built from this template in x,y,z)")
.def_property(
"collision_asset_size",
&AbstractObjectAttributes::getCollisionAssetSize,
&AbstractObjectAttributes::setCollisionAssetSize,
R"(Size of collsion assets for constructions built from this template in
x,y,z. Default is [1.0,1.0,1.0]. This is used to resize a collision asset
to match a render asset if necessary, such as when using a primitive.)")
.def_property(
"margin", &AbstractObjectAttributes::getMargin,
&AbstractObjectAttributes::setMargin,
R"(Collision margin for constructions built from this template.)")
.def_property(
"orient_up", &AbstractObjectAttributes::getOrientUp,
&AbstractObjectAttributes::setOrientUp,
R"(Up direction for constructions built from this template.)")
.def_property(
"orient_front", &AbstractObjectAttributes::getOrientFront,
&AbstractObjectAttributes::setOrientFront,
R"(Forward direction for constructions built from this template.)")
.def_property("units_to_meters",
&AbstractObjectAttributes::getUnitsToMeters,
&AbstractObjectAttributes::setUnitsToMeters,
R"(Conversion ratio for given units to meters.)")
.def_property(
"friction_coefficient",
&AbstractObjectAttributes::getFrictionCoefficient,
&AbstractObjectAttributes::setFrictionCoefficient,
R"(Friction coefficient for constructions built from this template.)")
.def_property(
"restitution_coefficient",
&AbstractObjectAttributes::getRestitutionCoefficient,
&AbstractObjectAttributes::setRestitutionCoefficient,
R"(Coefficient of restitution for constructions built from this template.)")
.def_property("render_asset_type",
&AbstractObjectAttributes::getRenderAssetType,
&AbstractObjectAttributes::setRenderAssetType,
R"(Type of the mesh asset used to render constructions built
from this template.)")
.def_property(
"collision_asset_type",
&AbstractObjectAttributes::getCollisionAssetType,
&AbstractObjectAttributes::setCollisionAssetType,
R"(Type of the mesh asset used for collision calculations for
constructions built from this template.)")
.def_property(
"render_asset_handle",
&AbstractObjectAttributes::getRenderAssetHandle,
&AbstractObjectAttributes::setRenderAssetHandle,
R"(Handle of the asset used to render constructions built from
this template.)")
.def_property(
"collision_asset_handle",
&AbstractObjectAttributes::getCollisionAssetHandle,
&AbstractObjectAttributes::setCollisionAssetHandle,
R"(Handle of the asset used to calculate collsions for constructions
built from this template.)")
.def_property(
"shader_type", &AbstractObjectAttributes::getShaderType,
&AbstractObjectAttributes::setShaderType,
R"(The shader type [0=material, 1=flat, 2=phong, 3=pbr] to use for this construction)")
.def_property(
"requires_lighting", &AbstractObjectAttributes::getRequiresLighting,
&AbstractObjectAttributes::setRequiresLighting,
R"(If false, this object will be rendered flat, ignoring shader type settings.)")
.def_property_readonly(
"render_asset_is_primitive",
&AbstractObjectAttributes::getRenderAssetIsPrimitive,
R"(Whether constructions built from this template should
be rendered using an internally sourced primitive.)")
.def_property_readonly(
"collision_asset_is_primitive",
&AbstractObjectAttributes::getCollisionAssetIsPrimitive,
R"(Whether collisions involving constructions built from
this template should be solved using an internally sourced
primitive.)")
.def_property_readonly(
"use_mesh_for_collision",
&AbstractObjectAttributes::getUseMeshCollision,
R"(Whether collisions involving constructions built from
this template should be solved using the collision mesh
or a primitive.)")
.def_property(
"is_collidable", &ObjectAttributes::getIsCollidable,
&ObjectAttributes::setIsCollidable,
R"(Whether constructions built from this template are collidable upon initialization.)")
.def_property_readonly(
"is_dirty", &AbstractObjectAttributes::getIsDirty,
R"(Whether values in this attributes have been changed requiring
re-registration before they can be used an object can be created. )");
// ==== ObjectAttributes ====
py::class_<ObjectAttributes, AbstractObjectAttributes, ObjectAttributes::ptr>(
m, "ObjectAttributes")
.def(py::init(&ObjectAttributes::create<>))
.def(py::init(&ObjectAttributes::create<const std::string&>))
.def_property(
"com", &ObjectAttributes::getCOM, &ObjectAttributes::setCOM,
R"(The Center of Mass for objects built from this template.)")
.def_property(
"compute_COM_from_shape", &ObjectAttributes::getComputeCOMFromShape,
&ObjectAttributes::setComputeCOMFromShape,
R"(Whether the COM should be calculated when an object is created
based on its bounding box)")
.def_property("mass", &ObjectAttributes::getMass,
&ObjectAttributes::setMass,
R"(The mass of objects constructed from this template.)")
.def_property(
"inertia", &ObjectAttributes::getInertia,
&ObjectAttributes::setInertia,
R"(The diagonal of the Intertia matrix for objects constructed
from this template.)")
.def_property(
"linear_damping", &ObjectAttributes::getLinearDamping,
&ObjectAttributes::setLinearDamping,
R"(The damping of the linear velocity for objects constructed
from this template.)")
.def_property(
"angular_damping", &ObjectAttributes::getAngularDamping,
&ObjectAttributes::setAngularDamping,
R"(The damping of angular velocity for objects constructed from
this template.)")
.def_property("bounding_box_collisions",
&ObjectAttributes::getBoundingBoxCollisions,
&ObjectAttributes::setBoundingBoxCollisions,
R"(Whether objects constructed from this template should use
bounding box for collisions or designated mesh.)")
.def_property(
"join_collision_meshes", &ObjectAttributes::getJoinCollisionMeshes,
&ObjectAttributes::setJoinCollisionMeshes,
R"(Whether collision meshes for objects constructed from this
template should be joined into a convex hull or kept separate.)")
.def_property(
"is_visibile", &ObjectAttributes::getIsVisible,
&ObjectAttributes::setIsVisible,
R"(Whether objects constructed from this template are visible.)")
.def_property(
"semantic_id", &ObjectAttributes::getSemanticId,
&ObjectAttributes::setSemanticId,
R"(The semantic ID for objects constructed from this template.)");
// ==== StageAttributes ====
py::class_<StageAttributes, AbstractObjectAttributes, StageAttributes::ptr>(
m, "StageAttributes")
.def(py::init(&StageAttributes::create<>))
.def(py::init(&StageAttributes::create<const std::string&>))
.def_property(
"gravity", &StageAttributes::getGravity, &StageAttributes::setGravity,
R"(The 3-vector representation of gravity to use for physically-based
simulations on stages built from this template.)")
.def_property(
"origin", &StageAttributes::getOrigin, &StageAttributes::setOrigin,
R"(The desired location of the origin of stages built from this
template.)")
.def_property(
"semantic_asset_handle", &StageAttributes::getSemanticAssetHandle,
&StageAttributes::setSemanticAssetHandle,
R"(Handle of the asset used for semantic segmentation of stages
built from this template.)")
.def_property(
"semantic_asset_type", &StageAttributes::getSemanticAssetType,
&StageAttributes::setSemanticAssetType,
R"(Type of asset used for collision calculations for constructions
built from this template.)")
.def_property(
"navmesh_asset_handle", &StageAttributes::getNavmeshAssetHandle,
&StageAttributes::setNavmeshAssetHandle,
R"(Handle of the navmesh asset used for constructions built from
this template.)")
.def_property(
"house_filename", &StageAttributes::getHouseFilename,
&StageAttributes::setHouseFilename,
R"(Handle for file containing semantic type maps and hierarchy for
constructions built from this template.)")
.def_property(
"frustum_culling", &StageAttributes::getFrustumCulling,
&StageAttributes::setFrustumCulling,
R"(Whether frustum culling should be enabled for constructions built by this template.)");
// ==== LightInstanceAttributes ====
py::class_<LightInstanceAttributes, AbstractAttributes,
LightInstanceAttributes::ptr>(m, "LightInstanceAttributes")
.def(py::init(&LightInstanceAttributes::create<>))
.def(py::init(&LightInstanceAttributes::create<const std::string&>))
.def_property(
"position", &LightInstanceAttributes::getPosition,
&LightInstanceAttributes::setPosition,
R"(The 3-vector representation of the desired position of the light in the scene.)")
.def_property(
"direction", &LightInstanceAttributes::getDirection,
&LightInstanceAttributes::setDirection,
R"(The 3-vector representation of the desired direction of the light in the scene.)")
.def_property(
"color", &LightInstanceAttributes::getColor,
&LightInstanceAttributes::setColor,
R"(The 3-vector representation of the desired color of the light.)")
.def_property("intensity", &LightInstanceAttributes::getIntensity,
&LightInstanceAttributes::setIntensity,
R"(The intensity to use for the light.)")
.def_property("type", &LightInstanceAttributes::getType,
&LightInstanceAttributes::setType,
R"(The type of the light.)")
.def_property(
"spot_inner_cone_angle", &LightInstanceAttributes::getInnerConeAngle,
&LightInstanceAttributes::setInnerConeAngle,
R"(The inner cone angle to use for the dispersion of spot lights.
Ignored for other types of lights.)")
.def_property(
"spot_outer_cone_angle", &LightInstanceAttributes::getOuterConeAngle,
&LightInstanceAttributes::setOuterConeAngle,
R"(The outter cone angle to use for the dispersion of spot lights.
Ignored for other types of lights.)");
// TODO : LightLayoutAttributes
// ==== PhysicsManagerAttributes ====
py::class_<PhysicsManagerAttributes, AbstractAttributes,
PhysicsManagerAttributes::ptr>(m, "PhysicsManagerAttributes")
.def(py::init(&PhysicsManagerAttributes::create<>))
.def(py::init(&PhysicsManagerAttributes::create<const std::string&>))
.def_property_readonly(
"simulator", &PhysicsManagerAttributes::getSimulator,
R"(The simulator being used for dynamic simulation. If none then only kinematic
support is provided.)")
.def_property("timestep", &PhysicsManagerAttributes::getTimestep,
&PhysicsManagerAttributes::setTimestep,
R"(The timestep to use for forward simulation.)")
.def_property("max_substeps", &PhysicsManagerAttributes::getMaxSubsteps,
&PhysicsManagerAttributes::setMaxSubsteps,
R"(Maximum simulation steps between each rendering step.
(Not currently implemented).)")
.def_property(
"gravity", &PhysicsManagerAttributes::getGravity,
&PhysicsManagerAttributes::setGravity,
R"(The default 3-vector representation of gravity to use for physically-based
simulations. Can be overridden.)")
.def_property(
"friction_coefficient",
&PhysicsManagerAttributes::getFrictionCoefficient,
&PhysicsManagerAttributes::setFrictionCoefficient,
R"(Default friction coefficient for contact modeling. Can be overridden by
stage and object values.)")
.def_property(
"restitution_coefficient",
&PhysicsManagerAttributes::getRestitutionCoefficient,
&PhysicsManagerAttributes::setRestitutionCoefficient,
R"(Default restitution coefficient for contact modeling. Can be overridden by
stage and object values.)");
// ==== AbstractPrimitiveAttributes ====
py::class_<AbstractPrimitiveAttributes, AbstractAttributes,
AbstractPrimitiveAttributes::ptr>(m, "AbstractPrimitiveAttributes")
.def_property_readonly(
"is_wireframe", &AbstractPrimitiveAttributes::getIsWireframe,
R"(Whether primitives built from this template are wireframe or solid.)")
.def_property(
"use_texture_coords",
&AbstractPrimitiveAttributes::getUseTextureCoords,
&AbstractPrimitiveAttributes::setUseTextureCoords,
R"(Whether texture coordinates should be generated for objects
constructed using this template.)")
.def_property(
"use_tangents", &AbstractPrimitiveAttributes::getUseTangents,
&AbstractPrimitiveAttributes::setUseTangents,
R"(Whether 4-component (homogeneous) tangents should be generated for
objects constructed using this template.)")
.def_property(
"num_rings", &AbstractPrimitiveAttributes::getNumRings,
&AbstractPrimitiveAttributes::setNumRings,
R"(Number of line (for wireframe) or face (for solid) rings for
primitives built from this template.
Must be greater than 1 for template to be valid.
For all uvSpheres, must be greater than 2, and for wireframe uvSpheres
must also be multiple of 2.
Used by solid cones, cylinders, uvSpheres, and wireframe cylinders
and uvSpheres)")
.def_property(
"num_segments", &AbstractPrimitiveAttributes::getNumSegments,
&AbstractPrimitiveAttributes::setNumSegments,
R"(Number of line (for wireframe) or face (for solid) segments
for primitives built from this template.
For solid primitives, must be 3 or greater for template to
be valid. For wireframe primitives, must be 4 or greater,
and a multiple of 4 for template to be valid.
Used by solid and wireframe capsules, cones, cylinders,
uvSpheres.)")
.def_property(
"half_length", &AbstractPrimitiveAttributes::getHalfLength,
&AbstractPrimitiveAttributes::setHalfLength,
R"(Half the length of the cylinder (for capsules and cylinders) or the
cone (for cones) primitives built from this template. Primitives is
built with default radius 1.0. In order to get a desired radius r,
length l, and preserve correct normals of the primitive being built,
set half_length to .5 * (l/r) and then scale by r.
Used by solid and wireframe capsules, cones and cylinders.)")
.def_property_readonly(
"prim_obj_class_name",
&AbstractPrimitiveAttributes::getPrimObjClassName,
R"(Name of Magnum primitive class this template uses to construct
primitives)")
.def_property_readonly("prim_obj_type",
&AbstractPrimitiveAttributes::getPrimObjType)
.def("build_handle", &AbstractPrimitiveAttributes::buildHandle)
.def_property_readonly(
"is_valid_template", &AbstractPrimitiveAttributes::isValidTemplate,
R"(Certain attributes properties, such as num_segments, are subject
to restrictions in allowable values. If an illegal value is entered,
the template is considered invalid and no primitive will be built
from it. This property will say whether this template is valid
for creating its designated primitive.)");
// ==== CapsulePrimitiveAttributes ====
py::class_<CapsulePrimitiveAttributes, AbstractPrimitiveAttributes,
CapsulePrimitiveAttributes::ptr>(m, "CapsulePrimitiveAttributes")
.def(py::init(
&CapsulePrimitiveAttributes::create<bool, int, const std::string&>))
.def_property(
"hemisphere_rings", &CapsulePrimitiveAttributes::getHemisphereRings,
&CapsulePrimitiveAttributes::setHemisphereRings,
R"(Number of rings for each hemisphere for capsules built with this
template. Must be larger than 1 for template to be valid.)")
.def_property(
"cylinder_rings", &CapsulePrimitiveAttributes::getCylinderRings,
&CapsulePrimitiveAttributes::setCylinderRings,
R"(Number of rings for cylinder body for capsules built with this
template. Must be larger than 1 for template to be valid.)");
// ==== ConePrimitiveAttributes ====
py::class_<ConePrimitiveAttributes, AbstractPrimitiveAttributes,
ConePrimitiveAttributes::ptr>(m, "ConePrimitiveAttributes")
.def(py::init(
&ConePrimitiveAttributes::create<bool, int, const std::string&>))
.def_property(
"use_cap_end", &ConePrimitiveAttributes::getCapEnd,
&ConePrimitiveAttributes::setCapEnd,
R"(Whether to close cone bottom. Only used for solid cones.)");
// ==== CubePrimitiveAttributes ====
py::class_<CubePrimitiveAttributes, AbstractPrimitiveAttributes,
CubePrimitiveAttributes::ptr>(m, "CubePrimitiveAttributes")
.def(py::init(
&CubePrimitiveAttributes::create<bool, int, const std::string&>));
// ==== CylinderPrimitiveAttributes ====
py::class_<CylinderPrimitiveAttributes, AbstractPrimitiveAttributes,
CylinderPrimitiveAttributes::ptr>(m, "CylinderPrimitiveAttributes")
.def(py::init(
&CylinderPrimitiveAttributes::create<bool, int, const std::string&>))
.def_property(
"use_cap_ends", &CylinderPrimitiveAttributes::getCapEnds,
&CylinderPrimitiveAttributes::setCapEnds,
R"(Whether to close cylinder ends. Only used for solid cylinders.)");
// ==== IcospherePrimitiveAttributes ====
py::class_<IcospherePrimitiveAttributes, AbstractPrimitiveAttributes,
IcospherePrimitiveAttributes::ptr>(m,
"IcospherePrimitiveAttributes")
.def(py::init(
&IcospherePrimitiveAttributes::create<bool, int, const std::string&>))
.def_property(
"subdivisions", &IcospherePrimitiveAttributes::getSubdivisions,
&IcospherePrimitiveAttributes::setSubdivisions,
R"(Number of subdivisions to divide mesh for icospheres made from this
template. Only used with solid icospheres.)");
// ==== UVSpherePrimitiveAttributes ====
py::class_<UVSpherePrimitiveAttributes, AbstractPrimitiveAttributes,
UVSpherePrimitiveAttributes::ptr>(m, "UVSpherePrimitiveAttributes")
.def(py::init(
&UVSpherePrimitiveAttributes::create<bool, int, const std::string&>));
} // initAttributesBindings
} // namespace metadata
} // namespace esp