|
| 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 | +#include "USD.hh" |
| 18 | + |
| 19 | +#include "sdf/usd/usd_parser/USDData.hh" |
| 20 | +#include "sdf/usd/usd_parser/USDStage.hh" |
| 21 | +#include "Physics.hh" |
| 22 | + |
| 23 | +#pragma push_macro ("__DEPRECATED") |
| 24 | +#undef __DEPRECATED |
| 25 | +#include <pxr/usd/usdPhysics/scene.h> |
| 26 | +#pragma pop_macro ("__DEPRECATED") |
| 27 | + |
| 28 | +#include <string> |
| 29 | + |
| 30 | +namespace sdf |
| 31 | +{ |
| 32 | +inline namespace SDF_VERSION_NAMESPACE { |
| 33 | +namespace usd |
| 34 | +{ |
| 35 | + UsdErrors parseUSDWorld( |
| 36 | + const std::string &_inputFilename, |
| 37 | + std::shared_ptr<WorldInterface> &_world) |
| 38 | + { |
| 39 | + UsdErrors errors; |
| 40 | + USDData usdData(_inputFilename); |
| 41 | + usdData.Init(); |
| 42 | + usdData.ParseMaterials(); |
| 43 | + |
| 44 | + auto referencee = pxr::UsdStage::Open(_inputFilename); |
| 45 | + if (!referencee) |
| 46 | + { |
| 47 | + errors.emplace_back(UsdError( |
| 48 | + UsdErrorCode::INVALID_USD_FILE, |
| 49 | + "Unable to open [" + _inputFilename + "]")); |
| 50 | + return errors; |
| 51 | + } |
| 52 | + auto range = pxr::UsdPrimRange::Stage(referencee); |
| 53 | + |
| 54 | + _world->_worldName = referencee->GetDefaultPrim().GetName().GetText(); |
| 55 | + |
| 56 | + for (auto const &prim : range) |
| 57 | + { |
| 58 | + if (prim.IsA<pxr::UsdPhysicsScene>()) |
| 59 | + { |
| 60 | + std::pair<std::string, std::shared_ptr<USDStage>> data = |
| 61 | + usdData.FindStage(prim.GetPath().GetName()); |
| 62 | + |
| 63 | + ParsePhysicsScene(prim, _world, data.second->MetersPerUnit()); |
| 64 | + continue; |
| 65 | + } |
| 66 | + } |
| 67 | + return errors; |
| 68 | + } |
| 69 | +} |
| 70 | +} |
| 71 | +} |
0 commit comments