|
| 1 | +/* |
| 2 | + * Copyright (C) 2022 Open Source Robotics Foundation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | +*/ |
| 17 | + |
| 18 | +#include "USDPhysics.hh" |
| 19 | + |
| 20 | +#pragma push_macro ("__DEPRECATED") |
| 21 | +#undef __DEPRECATED |
| 22 | +#include <pxr/base/gf/vec3d.h> |
| 23 | +#include <pxr/usd/usdPhysics/scene.h> |
| 24 | +#pragma pop_macro ("__DEPRECATED") |
| 25 | + |
| 26 | +#include "sdf/World.hh" |
| 27 | + |
| 28 | +namespace sdf |
| 29 | +{ |
| 30 | +inline namespace SDF_VERSION_NAMESPACE { |
| 31 | +namespace usd |
| 32 | +{ |
| 33 | + void ParseUSDPhysicsScene( |
| 34 | + const pxr::UsdPhysicsScene &_scene, |
| 35 | + sdf::World &_world, |
| 36 | + double _metersPerUnit) |
| 37 | + { |
| 38 | + ignition::math::Vector3d worldGravity{0, 0, -1}; |
| 39 | + float magnitude {9.8f}; |
| 40 | + const auto gravityAttr = _scene.GetGravityDirectionAttr(); |
| 41 | + if (gravityAttr) |
| 42 | + { |
| 43 | + pxr::GfVec3f gravity; |
| 44 | + gravityAttr.Get(&gravity); |
| 45 | + if (!ignition::math::equal(0.0f, gravity[0]) && |
| 46 | + !ignition::math::equal(0.0f, gravity[1]) && |
| 47 | + !ignition::math::equal(0.0f, gravity[2])) |
| 48 | + { |
| 49 | + worldGravity[0] = gravity[0]; |
| 50 | + worldGravity[1] = gravity[1]; |
| 51 | + worldGravity[2] = gravity[2]; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + const auto magnitudeAttr = _scene.GetGravityMagnitudeAttr(); |
| 56 | + if (magnitudeAttr) |
| 57 | + { |
| 58 | + magnitudeAttr.Get(&magnitude); |
| 59 | + if (!std::isnan(magnitude) && !std::isinf(magnitude)) |
| 60 | + { |
| 61 | + magnitude = magnitude * _metersPerUnit; |
| 62 | + } |
| 63 | + } |
| 64 | + _world.SetGravity(worldGravity * magnitude); |
| 65 | + } |
| 66 | +} |
| 67 | +} |
| 68 | +} |
0 commit comments