diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..7f5e31c --- /dev/null +++ b/.clang-format @@ -0,0 +1,68 @@ +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: false +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortCaseLabelsOnASingleLine : false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: false +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: false +BreakBeforeBinaryOperators: false +BreakBeforeBraces: Allman +BreakBeforeTernaryOperators: false +BreakConstructorInitializersBeforeComma: false +BreakStringLiterals: false +ColumnLimit: 120 +CommentPragmas: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerBinding: false +FixNamespaceComments: false +IndentCaseLabels: false +IndentPPDirectives: AfterHash +IndentFunctionDeclarationAfterType: false +IndentWidth: 4 +SortIncludes: true +IncludeCategories: + - Regex: '' + Priority: 2 + - Regex: '<[[:alnum:]_.]+>' + Priority: 4 + - Regex: '<[[:alnum:]_.\/]+>' + Priority: 3 + - Regex: '".*"' + Priority: 1 +IncludeBlocks: Regroup +Language: Cpp +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 0 +PenaltyBreakComment: 1 +PenaltyBreakFirstLessLess: 0 +PenaltyBreakString: 1 +PenaltyExcessCharacter: 10 +PenaltyReturnTypeOnItsOwnLine: 1000 +PointerAlignment: Left +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +Standard: Cpp11 +ReflowComments: true +TabWidth: 4 +UseTab: Never diff --git a/.gitignore b/.gitignore index 43a989c..218dc45 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,9 @@ _*/ # Generated license file. PACKAGE-DEPS.yaml + +.nvidia-omniverse + +# Internal CI/CD files. +/.teamcity +/tools/ci diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..8ea140a --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,167 @@ +include: +# external + - project: 'omniverse/devplat/gitlab/templates/common/kit-extension' + file: 'modules/complete-pipeline.yml' + ref: v1_latest + + + +# ============================================================================================================== +# More variables can be found in common.yml - here we put the ones controlling the jobs workflow +variables: + OSEC_NSPECT_ID: "NSPECT-96O5-S11L" + OSEC_CHECKMARX_ENABLED: 'false' + OSEC_GITLAB_SAST_ENABLED: 'false' + OSEC_PULSE_TRUFFLEHOG_ENABLED: 'false' + OSEC_OMNI_PULSE_ENABLED: 'false' + OSEC_README_ENABLED: 'false' # WARNING: Also have the init() function get_nspectid_from_repo_toml() in there... + ALLOW_PUBLISH_DOCS: + value: "true" + description: "Set to true to publish docs" + ALLOW_PUBLISH_TO_LAUNCHER: + value: "false" + description: "Set to true to for Kit apps that are published to the Launcher. That adds jobs for that." + ALLOW_PUBLISH_EXTENSIONS: + value: "true" + description: "Set to true to publish extension updates." + ALLOW_PUBLISH_CONTAINERS: + value: "false" + description: "Set to true to publish containers to NGC." + ALLOW_SECURITY_SCAN: + value: "false" + description: "Set to true to trigger a security scan as a child pipeline (non blocking)" + ALLOW_SCHEDULE_PIPELINE: + value: "true" + description: "Set to 'false' to disable schedule pipeline on a all jobs, useful to set it back on only some jobs." + ALLOW_TAG_PIPELINE: + value: "true" + description: "Set to 'false' to disable tag pipeline on a all push jobs." + RUN_EXTENSION_BENCHMARKS: + value: "false" + description: "Set to true to run benchmarks for kit extensions." + OMNI_CI_ENABLE_CXX_COVERAGE: + value: "false" + description: "Set to 'true' to enable C++ code coverage testing." + OMNI_CI_ENABLE_SANITIZERS: + value: "false" + description: "Set to 'true' to enable C++ sanitizer builds." + RUN_BUMP_VERSION: + value: "false" + description: "Set to true to run bump version. Only happens on schedule." + RUN_NIGHTLY_TESTS: + value: "false" + description: "Set to true to run nightly tests. Only happens on schedule." + RUN_DOCS_BUILD: + value: "true" + description: "Set to true to build omni docs. Only happens on schedule." + + +# ============================================================================================================== +.check-common: + stage: check + timeout: 20 minutes + interruptible: true + rules: + - if: $RUN_BUMP_VERSION == "true" + when: never + - !reference [.rules-workflow, rules] + +.repo-artifacts: + artifacts: + when: always + expire_in: 2 weeks + paths: + - _repo/repo.log + - _repo/repolog*.txt + + +# ============================================================================================================== +# By default, all platforms (windows-x86_64, linux-x86_64) are published, +# but this can be changed in repo.toml config if necessary: +# [repo_publish_exts] +# platforms = ["linux-x86_64"] +verify-publish-extensions: + extends: + - .deploy-common + - .omni_nvks_runner_with_docker + script: + - ./repo.sh build --fetch-only -rd + - ./repo.sh publish_exts -a --from-package -c release --verify + - ./repo.sh publish_exts -a --from-package -c debug --verify + # - ./repo.sh ci publish_extensions + needs: + # We set all dependencies as optional just in case a platform is not needed, + # then the yml file can override both build/test on one platform and deploy will still work. + - job: build-windows-x86_64 + artifacts: true + optional: false + - job: build-linux-x86_64 + artifacts: true + optional: false + rules: + - if: $ALLOW_PUBLISH_EXTENSIONS != "true" + when: never + - if: $RUN_BUMP_VERSION == "true" + when: never + - !reference [.rules-push, rules] + # - !reference [.rules-version-changed, rules] + + +# ============================================================================================================== +# By default, all platforms (windows-x86_64, linux-x86_64) are published, +# but this can be changed in repo.toml config if necessary: +# [repo_publish_exts] +# platforms = ["linux-x86_64"] +publish-extensions: + extends: + - .deploy-common + - .omni_nvks_runner_with_docker + script: + - ./repo.sh build --fetch-only -rd + - ./repo.sh publish_exts -a --from-package -c release + - ./repo.sh publish_exts -a --from-package -c debug + # - ./repo.sh ci publish_extensions + needs: + # We set all dependencies as optional just in case a platform is not needed, + # then the yml file can override both build/test on one platform and deploy will still work. + - job: build-windows-x86_64 + artifacts: true + optional: false + - job: build-linux-x86_64 + artifacts: true + optional: false + + rules: + - if: $ALLOW_PUBLISH_EXTENSIONS != "true" + when: never + - if: $RUN_BUMP_VERSION == "true" + when: never + - !reference [.rules-version-changed, rules] + - !reference [.rules-push-manual, rules] + + +# ============================================================================================================== +publish-docs: + rules: + - when: never + needs: + + +# ============================================================================================================== +publish-to-launcher: + rules: + - when: never + needs: + +# ============================================================================================================== +release-new-version: + rules: + - when: never + + +# ============================================================================================================== +# update Kit SDK and extensions, merge master, typically done in daily branch +# set AUTOUPDATE_KIT=true for scheduled pipeline to run +autoupdate-kit: + rules: + - when: never diff --git a/.lastformat b/.lastformat new file mode 100644 index 0000000..1a34b40 --- /dev/null +++ b/.lastformat @@ -0,0 +1 @@ +1714061207.6556504 \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..b94274b --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,35 @@ +# Contributing to the MJCF Importer Extension + +## Did you find a bug? + +* Check in the GitHub [Issues](https://github.com/NVIDIA-Omniverse/mjcf-importer-extension/issues) if a report for your bug already exists. +* If the bug has not been reported yet, open a new Issue. +* Use a short and descriptive title which contains relevant keywords. +* Write a clear description of the bug. +* Document the environment including your operating system, compiler version, and hardware specifications. +* Add code samples and executable test cases with instructions for reproducing the bug. + +## Did you find an issue in the documentation? + +* Please create an [Issue](https://github.com/NVIDIA-Omniverse/mjcf-importer-extension/issues/) if you find a documentation issue. + +## Did you write a bug fix? + +* Open a new [Pull Request](https://github.com/NVIDIA-Omniverse/mjcf-importer-extension/pulls) with your bug fix. +* Write a description of the bug which is fixed by your patch or link to related Issues. +* If your patch fixes for example Issue #33, write `Fixes #33`. +* Explain your solution with a few words. + +## Did you write a cosmetic patch? + +* Patches that are purely cosmetic will not be considered and associated Pull Requests will be closed. +* Cosmetic are patches which do not improve stability, performance, functionality, etc. +* Examples for cosmetic patches: code formatting, fixing whitespaces. + +## Do you have a question? + +* Search the GitHub [Discussions](https://github.com/NVIDIA-Omniverse/mjcf-importer-extension/discussions/) for your question. +* If nobody asked your question before, feel free to open a new discussion. +* Once somebody shares a satisfying answer to your question, click "Mark as answer". +* GitHub Issues should only be used for bug reports. +* If you open an Issue with a question, we may convert it into a discussion. \ No newline at end of file diff --git a/LICENSE b/LICENSE index 29cf1a3..af58e37 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/ + https://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION @@ -193,7 +193,7 @@ you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/VERSION.md b/VERSION.md index ad88a8c..1cc5f65 100644 --- a/VERSION.md +++ b/VERSION.md @@ -1 +1 @@ -105.1 \ No newline at end of file +1.1.0 \ No newline at end of file diff --git a/deps/ext-deps.packman.xml b/deps/ext-deps.packman.xml index 8e28a5d..ce50162 100644 --- a/deps/ext-deps.packman.xml +++ b/deps/ext-deps.packman.xml @@ -1,19 +1,21 @@ - + + + - - - + + + diff --git a/deps/host-deps.packman.xml b/deps/host-deps.packman.xml index 7144e9a..64ac797 100644 --- a/deps/host-deps.packman.xml +++ b/deps/host-deps.packman.xml @@ -1,13 +1,11 @@ - + - + - - + - - + diff --git a/deps/kit-sdk-deps.packman.xml b/deps/kit-sdk-deps.packman.xml index 0bf24be..7e9e30d 100644 --- a/deps/kit-sdk-deps.packman.xml +++ b/deps/kit-sdk-deps.packman.xml @@ -1,4 +1,4 @@ - + @@ -7,6 +7,7 @@ + @@ -14,12 +15,15 @@ + + + - + @@ -29,4 +33,8 @@ + + + + diff --git a/deps/kit-sdk.packman.xml b/deps/kit-sdk.packman.xml index 3bf5b4e..3b54e7b 100644 --- a/deps/kit-sdk.packman.xml +++ b/deps/kit-sdk.packman.xml @@ -1,5 +1,5 @@ - + - + diff --git a/deps/omni-physics.packman.xml b/deps/omni-physics.packman.xml index 6d4cb5e..9f73b19 100644 --- a/deps/omni-physics.packman.xml +++ b/deps/omni-physics.packman.xml @@ -1,5 +1,4 @@ - - + - + diff --git a/deps/omni-usd-resolver.packman.xml b/deps/omni-usd-resolver.packman.xml index 80e3397..c8c6d1d 100644 --- a/deps/omni-usd-resolver.packman.xml +++ b/deps/omni-usd-resolver.packman.xml @@ -1,7 +1,8 @@ - + + - \ No newline at end of file + diff --git a/deps/repo-deps.packman.xml b/deps/repo-deps.packman.xml index 4e1d631..967c68e 100644 --- a/deps/repo-deps.packman.xml +++ b/deps/repo-deps.packman.xml @@ -1,41 +1,38 @@ - - - - + - + - - + + - - + + - - + + - - + + - - + + - - + + + + + - + - + - - + + - - - - - + + diff --git a/deps/rtx-plugins.packman.xml b/deps/rtx-plugins.packman.xml deleted file mode 100644 index 7435c3d..0000000 --- a/deps/rtx-plugins.packman.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/index.rst b/index.rst index f1132b5..3331970 100644 --- a/index.rst +++ b/index.rst @@ -12,3 +12,4 @@ Extension Documentation source/extensions/omni.importer.mjcf/docs/index source/extensions/omni.importer.mjcf/docs/Overview source/extensions/omni.importer.mjcf/docs/CHANGELOG + CONTRIBUTING \ No newline at end of file diff --git a/premake5.lua b/premake5.lua index 7806f8e..4008aa6 100644 --- a/premake5.lua +++ b/premake5.lua @@ -5,10 +5,11 @@ repo_build = require("omni/repo/build") root = repo_build.get_abs_path(".") -- Set the desired MSVC, WINSDK, and MSBUILD versions before executing the kit template premake configuration. -MSVC_VERSION = "14.27.29110" -WINSDK_VERSION = "10.0.18362.0" -MSBUILD_VERSION = "Current" +MSVC_VERSION = "14.29.30133" +WINSDK_VERSION = "10.0.19608.0" +MSBUILD_VERSION = "15" +cppdialect "C++17" -- Execute the kit template premake configuration, which creates the solution, finds extensions, etc. dofile("_repo/deps/repo_kit_tools/kit-template/premake5.lua") diff --git a/repo.bat b/repo.bat index c760407..6e713c6 100644 --- a/repo.bat +++ b/repo.bat @@ -1,6 +1,6 @@ @echo off -call "%~dp0tools\packman\python.bat" %~dp0tools\repoman\repoman.py %* +call "%~dp0tools\packman\python.bat" "%~dp0tools\repoman\repoman.py" %* if %errorlevel% neq 0 ( goto Error ) :Success diff --git a/repo.sh b/repo.sh index 2297585..a5649e4 100755 --- a/repo.sh +++ b/repo.sh @@ -5,4 +5,4 @@ set -e SCRIPT_DIR=$(dirname ${BASH_SOURCE}) cd "$SCRIPT_DIR" -exec "tools/packman/python.sh" tools/repoman/repoman.py $@ +exec "tools/packman/python.sh" tools/repoman/repoman.py "$@" diff --git a/repo.toml b/repo.toml index 5f19b4a..881944e 100644 --- a/repo.toml +++ b/repo.toml @@ -13,6 +13,29 @@ name = "omniverse-mjcf-importer" [repo_build.msbuild] vs_version = "vs2019" +[repo_format] +command = "format" +entry_point = "omni.repo.format:setup_repo_tool" + +license_preamble = ''' +SPDX-FileCopyrightText: Copyright (c) {years}, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +SPDX-License-Identifier: Apache-2.0 +''' + +# license_text will always be after the spdx_license_text or copyright line, separated by a single newline +license_text = ''' +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +''' [repo_build] # List of packman projects to pull (in order) @@ -34,6 +57,19 @@ post_build.commands = [ # ["${root}/repo${shell_ext}", "stubgen", "-c", "${config}"] ] +######################################################################################################################## +# Packaging +######################################################################################################################## +[repo_changelog] +[repo_changelog.packages.urdf_importer] +enabled = false + +[repo_publish] +enabled = false +######################################################################################################################## +# Testing +######################################################################################################################## + [repo_docs] name = "Omniverse MJCF Importer" @@ -53,14 +89,20 @@ sphinx_conf_py_extra = """ """ -[repo_package.packages."platform:windows-x86_64".docs] -windows_max_path_length = 0 - - [repo_publish_exts] enabled = true use_packman_to_upload_archive = false +kit_path = "${root}/_build/$platform/$config/kit/kit${exe_ext}" + +publish_root = "${root}/_build/$platform/$config" + +# disable signing as it's not common practice for extension publishing atm +signing.enabled = false + +ext_folders = [ + "${publish_root}/exts" +] exts.include = [ "omni.importer.mjcf", ] diff --git a/source/extensions/omni.importer.mjcf/bindings/BindingsMjcfPython.cpp b/source/extensions/omni.importer.mjcf/bindings/BindingsMjcfPython.cpp index 88cb496..8710ec3 100644 --- a/source/extensions/omni.importer.mjcf/bindings/BindingsMjcfPython.cpp +++ b/source/extensions/omni.importer.mjcf/bindings/BindingsMjcfPython.cpp @@ -1,15 +1,21 @@ -// Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -#include - +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "../plugins/Mjcf.h" +#include + CARB_BINDINGS("omni.importer.mjcf.python") namespace omni @@ -18,10 +24,9 @@ namespace importer { namespace mjcf { - -} -} } +} // namespace importer +} // namespace omni namespace { @@ -53,7 +58,6 @@ PYBIND11_MODULE(_mjcf, m) Refer to the sample documentation for more examples and usage )pbdoc"; - py::class_(m, "ImportConfig") .def(py::init<>()) .def_readwrite("merge_fixed_joints", &ImportConfig::mergeFixedJoints, @@ -61,29 +65,33 @@ PYBIND11_MODULE(_mjcf, m) .def_readwrite("convex_decomp", &ImportConfig::convexDecomp, "Decompose a convex mesh into smaller pieces for a closer fit") .def_readwrite("import_inertia_tensor", &ImportConfig::importInertiaTensor, - "Import inertia tensor from mjcf, if not specified in mjcf it will import as identity") + "Import inertia tensor from mjcf, if not specified in " + "mjcf it will import as identity") .def_readwrite("fix_base", &ImportConfig::fixBase, "Create fix joint for base link") .def_readwrite("self_collision", &ImportConfig::selfCollision, "Self collisions between links in the articulation") .def_readwrite("density", &ImportConfig::density, "default density used for links") - //.def_readwrite("default_drive_type", &ImportConfig::defaultDriveType, "default drive type used for joints") + //.def_readwrite("default_drive_type", &ImportConfig::defaultDriveType, + //"default drive type used for joints") .def_readwrite( "default_drive_strength", &ImportConfig::defaultDriveStrength, "default drive stiffness used for joints") .def_readwrite("distance_scale", &ImportConfig::distanceScale, "Set the unit scaling factor, 1.0 means meters, 100.0 means cm") - //.def_readwrite("up_vector", &ImportConfig::upVector, "Up vector used for import") + //.def_readwrite("up_vector", &ImportConfig::upVector, "Up vector used for + // import") .def_readwrite( "create_physics_scene", &ImportConfig::createPhysicsScene, "add a physics scene to the stage on import") .def_readwrite("make_default_prim", &ImportConfig::makeDefaultPrim, "set imported robot as default prim") .def_readwrite( "create_body_for_fixed_joint", &ImportConfig::createBodyForFixedJoint, "creates body for fixed joint") - .def_readwrite( - "override_com", &ImportConfig::overrideCoM, - "whether to compute the center of mass from geometry and override values given in the original asset") - .def_readwrite( - "override_inertia_tensor", &ImportConfig::overrideInertia, - "Whether to compute the inertia tensor from geometry and override values given in the original asset") + .def_readwrite("override_com", &ImportConfig::overrideCoM, + "whether to compute the center of mass from geometry and " + "override values given in the original asset") + .def_readwrite("override_inertia_tensor", &ImportConfig::overrideInertia, + "Whether to compute the inertia tensor from geometry and " + "override values given in the original asset") .def_readwrite("make_instanceable", &ImportConfig::makeInstanceable, - "Creates an instanceable version of the asset. All meshes will be placed in a separate USD file") + "Creates an instanceable version of the asset. All meshes " + "will be placed in a separate USD file") .def_readwrite( "instanceable_usd_path", &ImportConfig::instanceableMeshUsdPath, "USD file to store instanceable mehses in") @@ -97,14 +105,15 @@ PYBIND11_MODULE(_mjcf, m) .def("set_density", [](ImportConfig& config, const float value) { config.density = value; }) /* .def("set_default_drive_type", [](ImportConfig& config, const int value) { - config.defaultDriveType = static_cast(value); + config.defaultDriveType = + static_cast(value); })*/ .def("set_default_drive_strength", [](ImportConfig& config, const float value) { config.defaultDriveStrength = value; }) .def("set_distance_scale", [](ImportConfig& config, const float value) { config.distanceScale = value; }) /* .def("set_up_vector", - [](ImportConfig& config, const float x, const float y, const float z) { - config.upVector = { x, y, z }; + [](ImportConfig& config, const float x, const float y, const + float z) { config.upVector = { x, y, z }; })*/ .def("set_create_physics_scene", [](ImportConfig& config, const bool value) { config.createPhysicsScene = value; }) @@ -137,4 +146,4 @@ PYBIND11_MODULE(_mjcf, m) )pbdoc"); } -} +} // namespace diff --git a/source/extensions/omni.importer.mjcf/plugins/MeshImporter.h b/source/extensions/omni.importer.mjcf/plugins/MeshImporter.h index 6e565c5..82361a3 100644 --- a/source/extensions/omni.importer.mjcf/plugins/MeshImporter.h +++ b/source/extensions/omni.importer.mjcf/plugins/MeshImporter.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,9 +25,10 @@ namespace mesh class MeshImporter { private: - // std::map> gymGraphicsMeshCache; - // std::map, carb::gym::TriangleMeshHandle> cylinderCache; - // std::map simulationMeshCache; + // std::map> + // gymGraphicsMeshCache; std::map, + // carb::gym::TriangleMeshHandle> cylinderCache; std::map + // simulationMeshCache; public: MeshImporter() diff --git a/source/extensions/omni.importer.mjcf/plugins/Mjcf.cpp b/source/extensions/omni.importer.mjcf/plugins/Mjcf.cpp index 5c17226..1235913 100644 --- a/source/extensions/omni.importer.mjcf/plugins/Mjcf.cpp +++ b/source/extensions/omni.importer.mjcf/plugins/Mjcf.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,9 +13,14 @@ // See the License for the specific language governing permissions and // limitations under the License. - #define CARB_EXPORTS +// clang-format off +#include "UsdPCH.h" +// clang-format on + +#include "Mjcf.h" + #include "MjcfImporter.h" #include "stdio.h" @@ -23,14 +28,8 @@ #include #include -#include "Mjcf.h" - #include #include -// clang-format off -#include -#include -// clang-format on #define EXTENSION_NAME "omni.importer.mjcf.plugin" @@ -81,7 +80,18 @@ void createAssetFromMJCF(const char* fileName, if (!_stage) // If all else fails, import on current stage { CARB_LOG_INFO("Importing URDF to Current Stage"); - _stage = omni::usd::UsdContext::getContext()->getStage(); + // Get the 'active' USD stage from the USD stage cache. + const std::vector allStages = pxr::UsdUtilsStageCache::Get().GetAllStages(); + if (allStages.size() != 1) + { + CARB_LOG_ERROR( + "Cannot determine the 'active' USD stage (%zu stages " + "present in the USD stage cache).", + allStages.size()); + return; + } + + _stage = allStages[0]; save_stage = false; } std::string result = ""; @@ -95,25 +105,24 @@ void createAssetFromMJCF(const char* fileName, // CARB_LOG_WARN("Import Done, saving"); if (save_stage) { - // CARB_LOG_WARN("Saving Stage %s", _stage->GetRootLayer()->GetIdentifier().c_str()); + // CARB_LOG_WARN("Saving Stage %s", + // _stage->GetRootLayer()->GetIdentifier().c_str()); _stage->Save(); } } } -} +} // namespace CARB_EXPORT void carbOnPluginStartup() { CARB_LOG_INFO("Startup MJCF Extension"); } - CARB_EXPORT void carbOnPluginShutdown() { } - void fillInterface(omni::importer::mjcf::Mjcf& iface) { using namespace omni::importer::mjcf; diff --git a/source/extensions/omni.importer.mjcf/plugins/Mjcf.h b/source/extensions/omni.importer.mjcf/plugins/Mjcf.h index e6e4082..1d27db2 100644 --- a/source/extensions/omni.importer.mjcf/plugins/Mjcf.h +++ b/source/extensions/omni.importer.mjcf/plugins/Mjcf.h @@ -1,11 +1,17 @@ -// Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once #include @@ -56,6 +62,6 @@ struct Mjcf const std::string& stage_identifier); }; -} -} -} +} // namespace mjcf +} // namespace importer +} // namespace omni diff --git a/source/extensions/omni.importer.mjcf/plugins/MjcfImporter.cpp b/source/extensions/omni.importer.mjcf/plugins/MjcfImporter.cpp index 740c29f..f0cbad3 100644 --- a/source/extensions/omni.importer.mjcf/plugins/MjcfImporter.cpp +++ b/source/extensions/omni.importer.mjcf/plugins/MjcfImporter.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "MjcfImporter.h" #include @@ -41,8 +40,8 @@ MJCFImporter::MJCFImporter(const std::string fullPath, ImportConfig& config) return; } - - // if the mjcf file contains , load the included file as well + // if the mjcf file contains , load the included file as + // well { tinyxml2::XMLDocument includeDoc; tinyxml2::XMLElement* includeElement = root->FirstChildElement("include"); @@ -60,7 +59,6 @@ MJCFImporter::MJCFImporter(const std::string fullPath, ImportConfig& config) LoadGlobals(root, defaultClassName, baseDirPath, worldBody, bodies, actuators, tendons, contacts, simulationMeshCache, meshes, materials, textures, compiler, classes, jointToActuatorIdx, config); - for (int i = 0; i < int(bodies.size()); ++i) { populateBodyLookup(bodies[i]); @@ -71,7 +69,8 @@ MJCFImporter::MJCFImporter(const std::string fullPath, ImportConfig& config) if (!createContactGraph()) { CARB_LOG_ERROR( - "*** Could not create contact graph to compute collision groups! Are contacts specified properly?\n"); + "*** Could not create contact graph to compute collision " + "groups! Are contacts specified properly?\n"); } // loading is complete if it reaches here @@ -383,7 +382,8 @@ void MJCFImporter::addWorldGeomsAndSites(pxr::UsdStageWeakPtr stage, const std::string instanceableUsdPath) { - // we have to create a dummy link to place the sites/geoms defined in the world body + // we have to create a dummy link to place the sites/geoms defined in the + // world body std::string dummyPath = rootPath + "/worldBody"; pxr::UsdPrim dummyLink = pxr::UsdGeomXform::Define(stage, pxr::SdfPath(dummyPath)).GetPrim(); @@ -402,7 +402,8 @@ void MJCFImporter::addWorldGeomsAndSites(pxr::UsdStageWeakPtr stage, pxr::UsdPhysicsRigidBodyAPI physicsAPI = pxr::UsdPhysicsRigidBodyAPI::Apply(bodyLink); pxr::PhysxSchemaPhysxRigidBodyAPI::Apply(bodyLink); - // createFixedRoot(stage, dummyPath + "/joints/rootJoint_" + uniqueName, dummyPath + "/" + uniqueName); + // createFixedRoot(stage, dummyPath + "/joints/rootJoint_" + uniqueName, + // dummyPath + "/" + uniqueName); physicsAPI.GetKinematicEnabledAttr().Set(true); bool hasCollisionGeoms = false; @@ -481,7 +482,6 @@ void MJCFImporter::addWorldGeomsAndSites(pxr::UsdStageWeakPtr stage, pxr::UsdPrim prim = createPrimitiveGeom( stage, geomPath, worldBody.geoms[i], simulationMeshCache, config, true, rootPath, false); - if (!config.visualizeCollisionGeoms && worldBody.hasVisual && !isVisual) { // turn off visibility for collision prim @@ -489,7 +489,6 @@ void MJCFImporter::addWorldGeomsAndSites(pxr::UsdStageWeakPtr stage, imageable.MakeInvisible(); } - // parse material and texture if (worldBody.geoms[i]->material != "") { @@ -543,7 +542,6 @@ void MJCFImporter::addWorldGeomsAndSites(pxr::UsdStageWeakPtr stage, addVisualSites(stage, dummyLink, &worldBody, dummyPath, config); } - void MJCFImporter::AddContactFilters(pxr::UsdStageWeakPtr stage) { // adding collision filtering pairs @@ -572,7 +570,8 @@ void MJCFImporter::AddTendons(pxr::UsdStageWeakPtr stage, std::string rootPath) { if (t->type == MJCFTendon::FIXED) { - // setting the joint with the lowest kinematic hierarchy number as the TendonAxisRoot + // setting the joint with the lowest kinematic hierarchy number as the + // TendonAxisRoot if (t->fixedJoints.size() != 0) { MJCFTendon::FixedJoint* rootJoint = t->fixedJoints[0]; @@ -747,7 +746,9 @@ void MJCFImporter::AddTendons(pxr::UsdStageWeakPtr stage, std::string rootPath) { // we shouldn't be here... CARB_LOG_ERROR( - "Error adding attachment %s. Failed to find attached link.\n", name.c_str()); + "Error adding attachment %s. Failed to find " + "attached link.\n", + name.c_str()); } } @@ -813,13 +814,16 @@ void MJCFImporter::AddTendons(pxr::UsdStageWeakPtr stage, std::string rootPath) else { CARB_LOG_ERROR( - "Spatial tendon %s cannot be added since it has no attachments specified.", t->name.c_str()); + "Spatial tendon %s cannot be added since it has no " + "attachments specified.", + t->name.c_str()); } } else { CARB_LOG_ERROR( - "Tendon %s is not a fixed or spatial tendon. Only fixed and spatial tendons are currently supported.", + "Tendon %s is not a fixed or spatial tendon. Only fixed " + "and spatial tendons are currently supported.", t->name.c_str()); } } @@ -870,7 +874,9 @@ void MJCFImporter::CreateInstanceableMeshes(pxr::UsdStageRefPtr stage, if ((!createBodyForFixedJoint) && ((body->joints.size() == 0) && (!isRoot))) { - CARB_LOG_WARN("RigidBodySpec with no joint will have no geometry for now, to avoid instability of fixed joint!"); + CARB_LOG_WARN( + "RigidBodySpec with no joint will have no geometry for now, " + "to avoid instability of fixed joint!"); } else { @@ -920,7 +926,6 @@ void MJCFImporter::CreateInstanceableMeshes(pxr::UsdStageRefPtr stage, } } - void MJCFImporter::CreatePhysicsBodyAndJoint(pxr::UsdStageWeakPtr stage, MJCFBody* body, std::string rootPrimPath, @@ -936,7 +941,9 @@ void MJCFImporter::CreatePhysicsBodyAndJoint(pxr::UsdStageWeakPtr stage, if ((!createBodyForFixedJoint) && ((body->joints.size() == 0) && (!isRoot))) { - CARB_LOG_WARN("RigidBodySpec with no joint will have no geometry for now, to avoid instability of fixed joint!"); + CARB_LOG_WARN( + "RigidBodySpec with no joint will have no geometry for now, " + "to avoid instability of fixed joint!"); } else { @@ -1100,7 +1107,8 @@ void MJCFImporter::CreatePhysicsBodyAndJoint(pxr::UsdStageWeakPtr stage, config.distanceScale); applyPhysxJoint(jointPrim, joint); - // joint was aligned such that its hinge axis is aligned with local x-axis. + // joint was aligned such that its hinge axis is aligned with local + // x-axis. jointPrim.CreateAxisAttr().Set(pxr::UsdPhysicsTokens->x); if (joint->limited) @@ -1126,7 +1134,8 @@ void MJCFImporter::CreatePhysicsBodyAndJoint(pxr::UsdStageWeakPtr stage, config.distanceScale); applyPhysxJoint(jointPrim, joint); - // joint was aligned such that its hinge axis is aligned with local x-axis. + // joint was aligned such that its hinge axis is aligned with local + // x-axis. jointPrim.CreateAxisAttr().Set(pxr::UsdPhysicsTokens->x); if (joint->limited) @@ -1167,7 +1176,9 @@ void MJCFImporter::CreatePhysicsBodyAndJoint(pxr::UsdStageWeakPtr stage, } else { - CARB_LOG_WARN("*** Only hinge, slide, ball, and free joints are supported by MJCF importer"); + CARB_LOG_WARN( + "*** Only hinge, slide, ball, and free joints are " + "supported by MJCF importer"); } } else @@ -1178,8 +1189,8 @@ void MJCFImporter::CreatePhysicsBodyAndJoint(pxr::UsdStageWeakPtr stage, stage, jointPath, poseJointToParentBody, poseJointToChildBody, parentBodyPath, bodyPath, config); applyPhysxJoint(jointPrim, body->joints[0]); - // TODO: this needs to be updated to support all joint types and combinations - // set joint limits + // TODO: this needs to be updated to support all joint types and + // combinations set joint limits for (int jid = 0; jid < (int)body->joints.size(); jid++) { // all locked @@ -1190,7 +1201,9 @@ void MJCFImporter::CreatePhysicsBodyAndJoint(pxr::UsdStageWeakPtr stage, if (body->joints[jid]->type != MJCFJoint::HINGE && body->joints[jid]->type != MJCFJoint::SLIDE) { - CARB_LOG_WARN("*** Only hinge and slide joints are supported by MJCF importer"); + CARB_LOG_WARN( + "*** Only hinge and slide joints are supported by " + "MJCF importer"); continue; } @@ -1414,7 +1427,7 @@ void MJCFImporter::computeKinematicHierarchy() while (bodyQueue.size() != 0) { - num_bodies_at_level = bodyQueue.size(); + num_bodies_at_level = (int)bodyQueue.size(); for (int i = 0; i < num_bodies_at_level; i++) { @@ -1435,6 +1448,6 @@ void MJCFImporter::computeKinematicHierarchy() } } -} -} -} +} // namespace mjcf +} // namespace importer +} // namespace omni diff --git a/source/extensions/omni.importer.mjcf/plugins/MjcfImporter.h b/source/extensions/omni.importer.mjcf/plugins/MjcfImporter.h index 6629afe..3670720 100644 --- a/source/extensions/omni.importer.mjcf/plugins/MjcfImporter.h +++ b/source/extensions/omni.importer.mjcf/plugins/MjcfImporter.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,22 +13,21 @@ // See the License for the specific language governing permissions and // limitations under the License. - #pragma once // clang-format off #include "UsdPCH.h" // clang-format on +#include "Mjcf.h" #include "MjcfParser.h" #include "MjcfTypes.h" #include "MjcfUsd.h" #include "MjcfUtils.h" #include "core/mesh.h" +#include "math/core/maths.h" #include -#include "math/core/maths.h" -#include "Mjcf.h" #include #include @@ -145,6 +144,6 @@ class MJCFImporter pxr::GfVec3f GetLocalPos(MJCFTendon::SpatialAttachment attachment); }; -} -} -} +} // namespace mjcf +} // namespace importer +} // namespace omni diff --git a/source/extensions/omni.importer.mjcf/plugins/MjcfParser.cpp b/source/extensions/omni.importer.mjcf/plugins/MjcfParser.cpp index 475bbc3..5f24539 100644 --- a/source/extensions/omni.importer.mjcf/plugins/MjcfParser.cpp +++ b/source/extensions/omni.importer.mjcf/plugins/MjcfParser.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "MjcfParser.h" #include "MeshImporter.h" @@ -58,12 +57,14 @@ void LoadCompiler(tinyxml2::XMLElement* c, MJCFCompiler& compiler) if ((s = GetAttr(c, "eulerseq")) != "") { - for (int i = s.length() - 1; i >= 0; i--) + for (int i = (int)s.length() - 1; i >= 0; i--) { char axis = s[i]; if (axis == 'X' || axis == 'Y' || axis == 'Z') { - CARB_LOG_ERROR("The MJCF importer currently only supports intrinsic euler rotations!"); + CARB_LOG_ERROR( + "The MJCF importer currently only supports intrinsic " + "euler rotations!"); } } compiler.eulerseq = s; @@ -94,7 +95,6 @@ void LoadCompiler(tinyxml2::XMLElement* c, MJCFCompiler& compiler) } } - void LoadInertial(tinyxml2::XMLElement* i, MJCFInertial& inertial) { if (!i) @@ -124,7 +124,6 @@ void LoadInertial(tinyxml2::XMLElement* i, MJCFInertial& inertial) } } - void LoadGeom(tinyxml2::XMLElement* g, MJCFGeom& geom, std::string className, @@ -394,7 +393,9 @@ void LoadTendon(tinyxml2::XMLElement* t, getIfExist(t, "springlength", tendon.springlength); if (tendon.springlength < 0.0f) { - CARB_LOG_WARN("*** Automatic tendon springlength calculation is not supported (negative springlengths)."); + CARB_LOG_WARN( + "*** Automatic tendon springlength calculation is not " + "supported (negative springlengths)."); } getIfExist(t, "stiffness", tendon.stiffness); getIfExist(t, "damping", tendon.damping); @@ -488,7 +489,6 @@ void LoadTendon(tinyxml2::XMLElement* t, } } - void LoadJoint(tinyxml2::XMLElement* g, MJCFJoint& joint, std::string className, @@ -541,7 +541,8 @@ void LoadJoint(tinyxml2::XMLElement* g, sscanf(st, "%f %f", &joint.range.x, &joint.range.y); if (compiler.autolimits) { - // set limited to true if a range is specified and autolimits is set to true + // set limited to true if a range is specified and autolimits is set to + // true joint.limited = true; } } @@ -562,7 +563,6 @@ void LoadJoint(tinyxml2::XMLElement* g, } } - void LoadFreeJoint(tinyxml2::XMLElement* g, MJCFJoint& joint, std::string className, @@ -588,7 +588,6 @@ void LoadFreeJoint(tinyxml2::XMLElement* g, } } - void LoadDefault(tinyxml2::XMLElement* e, const std::string className, MJCFClass& cl, @@ -601,7 +600,8 @@ void LoadDefault(tinyxml2::XMLElement* e, LoadTendon(e->FirstChildElement("tendon"), cl.dtendon, className, MJCFTendon::DEFAULT, classes); LoadMesh(e->FirstChildElement("mesh"), cl.dmesh, className, compiler, classes); - // a defaults class should have one general actuator element, so only one of these should be sucessful + // a defaults class should have one general actuator element, so only one of + // these should be sucessful LoadActuator(e->FirstChildElement("motor"), cl.dactuator, className, MJCFActuator::MOTOR, classes); LoadActuator(e->FirstChildElement("position"), cl.dactuator, className, MJCFActuator::POSITION, classes); LoadActuator(e->FirstChildElement("velocity"), cl.dactuator, className, MJCFActuator::VELOCITY, classes); @@ -619,7 +619,8 @@ void LoadDefault(tinyxml2::XMLElement* e, std::string name = d->Attribute("class"); classes[name] = cl; // Copy from this class - LoadDefault(d, name, classes[name], compiler, classes); // Recursively load it + LoadDefault(d, name, classes[name], compiler, + classes); // Recursively load it d = d->NextSiblingElement("default"); } } @@ -872,7 +873,6 @@ void LoadAssets(tinyxml2::XMLElement* a, } } - void LoadGlobals(tinyxml2::XMLElement* root, std::string& defaultClassName, std::string baseDirPath, @@ -904,8 +904,9 @@ void LoadGlobals(tinyxml2::XMLElement* root, tinyxml2::XMLElement* d = root->FirstChildElement("default"); if (!d) { - // if no default, set the defaultClassName to default if it does not exist yet. - // added this condition to avoid overwriting default class parameters parsed in a prior call + // if no default, set the defaultClassName to default if it does not exist + // yet. added this condition to avoid overwriting default class parameters + // parsed in a prior call if (classes.find(defaultClassName) == classes.end()) { classes[defaultClassName] = MJCFClass(); @@ -942,7 +943,8 @@ void LoadGlobals(tinyxml2::XMLElement* root, classes, config); } - // finds the origin of the world frame within which the rest of the kinematic tree is defined + // finds the origin of the world frame within which the rest of the kinematic + // tree is defined tinyxml2::XMLElement* wb = root->FirstChildElement("worldbody"); if (wb) { @@ -1090,6 +1092,6 @@ void LoadGlobals(tinyxml2::XMLElement* root, } } -} -} -} +} // namespace mjcf +} // namespace importer +} // namespace omni diff --git a/source/extensions/omni.importer.mjcf/plugins/MjcfParser.h b/source/extensions/omni.importer.mjcf/plugins/MjcfParser.h index 93d3bdb..17ebee4 100644 --- a/source/extensions/omni.importer.mjcf/plugins/MjcfParser.h +++ b/source/extensions/omni.importer.mjcf/plugins/MjcfParser.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,14 +15,13 @@ #pragma once -#include "MjcfTypes.h" #include "Mjcf.h" +#include "MjcfTypes.h" #include "math/core/maths.h" #include #include - namespace omni { namespace importer @@ -116,6 +115,6 @@ void LoadGlobals(tinyxml2::XMLElement* root, std::map& jointToActuatorIdx, ImportConfig& config); -} -} -} +} // namespace mjcf +} // namespace importer +} // namespace omni diff --git a/source/extensions/omni.importer.mjcf/plugins/MjcfTypes.h b/source/extensions/omni.importer.mjcf/plugins/MjcfTypes.h index 2ca938d..16678a2 100644 --- a/source/extensions/omni.importer.mjcf/plugins/MjcfTypes.h +++ b/source/extensions/omni.importer.mjcf/plugins/MjcfTypes.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -229,7 +229,6 @@ class MJCFInertial Quat principalAxes; bool hasFullInertia; - MJCFInertial() { mass = -1.0f; @@ -250,7 +249,6 @@ enum JointAxis eJointAxisSwing2, //!< Corresponds to rotation around the body0 z-axis }; - class MJCFBody { public: @@ -306,7 +304,6 @@ class MJCFBody } }; - class MJCFCompiler { public: @@ -568,7 +565,6 @@ class MJCFMaterial } }; - class MJCFClass { public: @@ -583,7 +579,6 @@ class MJCFClass std::string name; }; - } // namespace mjcf -} -} +} // namespace importer +} // namespace omni diff --git a/source/extensions/omni.importer.mjcf/plugins/MjcfUsd.cpp b/source/extensions/omni.importer.mjcf/plugins/MjcfUsd.cpp index 2e43dae..08da2e0 100644 --- a/source/extensions/omni.importer.mjcf/plugins/MjcfUsd.cpp +++ b/source/extensions/omni.importer.mjcf/plugins/MjcfUsd.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,10 +13,12 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "MjcfUsd.h" + #include "utils/Path.h" +#include + namespace omni { namespace importer @@ -41,7 +43,6 @@ pxr::SdfPath getNextFreePath(pxr::UsdStageWeakPtr stage, const pxr::SdfPath& pri return uniquePath; } - std::string makeValidUSDIdentifier(const std::string& name) { auto validName = pxr::TfMakeValidIdentifier(name); @@ -122,7 +123,8 @@ std::string ReplaceBackwardSlash(std::string in) std::string copyTexture(std::string usdStageIdentifier, std::string texturePath) { - // switch any windows-style path into linux backwards slash (omniclient handles windows paths) + // switch any windows-style path into linux backwards slash (omniclient + // handles windows paths) usdStageIdentifier = ReplaceBackwardSlash(usdStageIdentifier); texturePath = ReplaceBackwardSlash(texturePath); @@ -208,7 +210,9 @@ void createMaterial(pxr::UsdStageWeakPtr usdStage, else { CARB_LOG_WARN( - "Material %s has an image texture, but it won't be imported since the asset is being loaded on memory. Please import it into a destination folder to get all textures.", + "Material %s has an image texture, but it won't be imported " + "since the asset is being loaded on memory. Please import it " + "into a destination folder to get all textures.", material.name.c_str()); } } @@ -359,7 +363,6 @@ pxr::UsdGeomMesh createMesh(pxr::UsdStageWeakPtr stage, mesh.SetNormalsInterpolation(pxr::UsdGeomTokens->faceVarying); } - return mesh; } @@ -496,7 +499,9 @@ void createAndBindMaterial(pxr::UsdStageWeakPtr stage, else { CARB_LOG_WARN( - "Material %s has an image texture, but it won't be imported since the asset is being loaded on memory. Please import it into a destination folder to get all textures.", + "Material %s has an image texture, but it won't be imported " + "since the asset is being loaded on memory. Please import it " + "into a destination folder to get all textures.", material->name.c_str()); } } @@ -518,7 +523,9 @@ void createAndBindMaterial(pxr::UsdStageWeakPtr stage, else { CARB_LOG_WARN( - "Material %s has an image texture, but it won't be imported since the asset is being loaded on memory. Please import it into a destination folder to get all textures.", + "Material %s has an image texture, but it won't be imported " + "since the asset is being loaded on memory. Please import it " + "into a destination folder to get all textures.", material->name.c_str()); } } @@ -538,11 +545,10 @@ void createAndBindMaterial(pxr::UsdStageWeakPtr stage, } } - pxr::GfVec3f evalSphereCoord(float u, float v) { - float theta = u * 2.0 * kPi; - float phi = (v - 0.5) * kPi; + float theta = u * 2.0f * kPi; + float phi = (v - 0.5f) * kPi; float cos_phi = cos(phi); float x = cos_phi * cos(theta); @@ -552,7 +558,6 @@ pxr::GfVec3f evalSphereCoord(float u, float v) return pxr::GfVec3f(x, y, z); } - int calcSphereIndex(int i, int j, int num_v_verts, int num_u_verts, std::vector& points) { if (j == 0) @@ -561,7 +566,7 @@ int calcSphereIndex(int i, int j, int num_v_verts, int num_u_verts, std::vector< } else if (j == num_v_verts - 1) { - return points.size() - 1; + return (int)points.size() - 1; } else { @@ -570,7 +575,6 @@ int calcSphereIndex(int i, int j, int num_v_verts, int num_u_verts, std::vector< } } - pxr::UsdGeomMesh createSphereMesh(pxr::UsdStageWeakPtr stage, const pxr::SdfPath path, float scale) { int u_patches = 32; @@ -584,8 +588,8 @@ pxr::UsdGeomMesh createSphereMesh(pxr::UsdStageWeakPtr stage, const pxr::SdfPath u_patches = (u_patches > 3) ? u_patches : 3; v_patches = (v_patches > 3) ? v_patches : 2; - float u_delta = 1.0 / (float)u_patches; - float v_delta = 1.0 / (float)v_patches; + float u_delta = 1.0f / (float)u_patches; + float v_delta = 1.0f / (float)v_patches; int num_u_verts = u_patches; int num_v_verts = v_patches + 1; @@ -667,7 +671,6 @@ pxr::UsdGeomMesh createSphereMesh(pxr::UsdStageWeakPtr stage, const pxr::SdfPath return usdMesh; } - pxr::UsdPrim createPrimitiveGeom(pxr::UsdStageWeakPtr stage, const std::string geomPath, const MJCFGeom* geom, @@ -679,7 +682,6 @@ pxr::UsdPrim createPrimitiveGeom(pxr::UsdStageWeakPtr stage, { pxr::SdfPath path = pxr::SdfPath(geomPath); - if (geom->type == MJCFGeom::PLANE) { // add visual plane @@ -1112,7 +1114,6 @@ void applyCollisionGeom(pxr::UsdStageWeakPtr stage, pxr::UsdPrim prim, const MJC } } - pxr::UsdPhysicsJoint createFixedJoint(pxr::UsdStageWeakPtr stage, const std::string jointPath, const Transform& poseJointToParentBody, @@ -1168,7 +1169,6 @@ pxr::UsdPhysicsJoint createD6Joint(pxr::UsdStageWeakPtr stage, pxr::GfQuatf localRot1 = pxr::GfQuatf( poseJointToChildBody.q.w, poseJointToChildBody.q.x, poseJointToChildBody.q.y, poseJointToChildBody.q.z); - pxr::SdfPathVector val0{ pxr::SdfPath(parentBodyPath) }; pxr::SdfPathVector val1{ pxr::SdfPath(bodyPath) }; @@ -1352,6 +1352,6 @@ void createJointDrives(pxr::UsdPhysicsJoint jointPrim, driveAPI.CreateMaxForceAttr().Set(maxForce); } } -} -} -} +} // namespace mjcf +} // namespace importer +} // namespace omni diff --git a/source/extensions/omni.importer.mjcf/plugins/MjcfUsd.h b/source/extensions/omni.importer.mjcf/plugins/MjcfUsd.h index 75e6912..a2ccaa7 100644 --- a/source/extensions/omni.importer.mjcf/plugins/MjcfUsd.h +++ b/source/extensions/omni.importer.mjcf/plugins/MjcfUsd.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,22 +13,15 @@ // See the License for the specific language governing permissions and // limitations under the License. - #pragma once // clang-format off #include "UsdPCH.h" // clang-format on -// clang-format off -#include -#include -// clang-format on - +#include "Mjcf.h" #include "MjcfTypes.h" #include "MjcfUtils.h" - #include "math/core/maths.h" -#include "Mjcf.h" #include #include @@ -142,6 +135,6 @@ void createJointDrives(pxr::UsdPhysicsJoint jointPrim, const std::string axis, const ImportConfig& config); -} -} -} +} // namespace mjcf +} // namespace importer +} // namespace omni diff --git a/source/extensions/omni.importer.mjcf/plugins/MjcfUtils.cpp b/source/extensions/omni.importer.mjcf/plugins/MjcfUtils.cpp index ce91d63..5962483 100644 --- a/source/extensions/omni.importer.mjcf/plugins/MjcfUtils.cpp +++ b/source/extensions/omni.importer.mjcf/plugins/MjcfUtils.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,8 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "MjcfUtils.h" + #include "math/core/maths.h" namespace omni @@ -176,7 +176,7 @@ void getEulerIfExist(tinyxml2::XMLElement* e, const char* aname, Quat& q, std::s float angles[3] = { a, b, c }; q = Quat(); - for (int i = eulerseq.length() - 1; i >= 0; i--) + for (int i = (int)eulerseq.length() - 1; i >= 0; i--) { char axis = eulerseq[i]; Quat new_quat = Quat(); @@ -197,7 +197,8 @@ void getEulerIfExist(tinyxml2::XMLElement* e, const char* aname, Quat& q, std::s } else { - std::cout << "The MJCF importer currently only supports euler sequences consisting of {x, y, z}" + std::cout << "The MJCF importer currently only supports euler " + "sequences consisting of {x, y, z}" << std::endl; } @@ -224,7 +225,6 @@ void getAngleAxisIfExist(tinyxml2::XMLElement* e, const char* aname, Quat& q, bo } } - void getZAxisIfExist(tinyxml2::XMLElement* e, const char* aname, Quat& q) { const char* st = e->Attribute(aname); @@ -245,14 +245,13 @@ void getZAxisIfExist(tinyxml2::XMLElement* e, const char* aname, Quat& q) rotVec = Normalize(rotVec); } - // essentially doing dot product between (0, 0, 1) and the vector and taking arccos to - // obtain the angle between the two vectors + // essentially doing dot product between (0, 0, 1) and the vector and taking + // arccos to obtain the angle between the two vectors float angle = acos(new_zaxis.z); q = QuatFromAxisAngle(rotVec, angle); } } - void QuatFromZAxis(Vec3 zaxis, Quat& q) { Vec3 new_zaxis = zaxis; @@ -267,13 +266,12 @@ void QuatFromZAxis(Vec3 zaxis, Quat& q) rotVec = Normalize(rotVec); } - // essentially doing dot product between (0, 0, 1) and the vector and taking arccos to - // obtain the angle between the two vectors + // essentially doing dot product between (0, 0, 1) and the vector and taking + // arccos to obtain the angle between the two vectors float angle = acos(new_zaxis.z); q = QuatFromAxisAngle(rotVec, angle); } - Quat indexedRotation(int axis, float s, float c) { float v[3] = { 0, 0, 0 }; @@ -317,7 +315,8 @@ Vec3 Diagonalize(const Matrix33& m, Quat& massFrame) float t = 1 / (absw + Sqrt(w * w + 1)); // absolute value of tan phi float h = 1 / Sqrt(t * t + 1); // absolute value of cos phi - assert(h != 1); // |w|<1000 guarantees this with typical IEEE754 machine eps (approx 6e-8) + assert(h != 1); // |w|<1000 guarantees this with typical IEEE754 machine + // eps (approx 6e-8) r = indexedRotation(a, Sqrt((1 - h) / 2) * Sign(w), Sqrt((1 + h) / 2)); } @@ -327,7 +326,6 @@ Vec3 Diagonalize(const Matrix33& m, Quat& massFrame) return Vec3(d.cols[0].x, d.cols[1].y, d.cols[2].z); } - -} -} -} +} // namespace mjcf +} // namespace importer +} // namespace omni diff --git a/source/extensions/omni.importer.mjcf/plugins/MjcfUtils.h b/source/extensions/omni.importer.mjcf/plugins/MjcfUtils.h index f626cf4..3cbd450 100644 --- a/source/extensions/omni.importer.mjcf/plugins/MjcfUtils.h +++ b/source/extensions/omni.importer.mjcf/plugins/MjcfUtils.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +16,7 @@ #pragma once #include "math/core/maths.h" + #include namespace omni @@ -42,7 +43,6 @@ void getAngleAxisIfExist(tinyxml2::XMLElement* e, const char* aname, Quat& q, bo Quat indexedRotation(int axis, float s, float c); Vec3 Diagonalize(const Matrix33& m, Quat& massFrame); - -} -} -} +} // namespace mjcf +} // namespace importer +} // namespace omni diff --git a/source/extensions/omni.importer.mjcf/plugins/UsdPCH.h b/source/extensions/omni.importer.mjcf/plugins/UsdPCH.h index 80fa3e0..f0090a8 100644 --- a/source/extensions/omni.importer.mjcf/plugins/UsdPCH.h +++ b/source/extensions/omni.importer.mjcf/plugins/UsdPCH.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +16,8 @@ #pragma once // !!! DO NOT INCLUDE THIS FILE IN A HEADER !!! -// When you include this file in a cpp file, add the file name to premake5.lua's pchFiles list! +// When you include this file in a cpp file, add the file name to premake5.lua's +// pchFiles list! // The usd headers drag in heavy dependencies and are very slow to build. // Make it PCH to speed up building time. @@ -27,7 +28,8 @@ # pragma warning(disable : 4267) // conversion from size_t to int # pragma warning(disable : 4305) // argument truncation from double to float # pragma warning(disable : 4800) // int to bool -# pragma warning(disable : 4996) // call to std::copy with parameters that may be unsafe +# pragma warning(disable : 4996) // call to std::copy with parameters that may be + // unsafe # define NOMINMAX // Make sure nobody #defines min or max # include // Include this here so we can curate # undef small // defined in rpcndr.h @@ -37,7 +39,8 @@ # pragma GCC diagnostic ignored "-Wunused-local-typedefs" # pragma GCC diagnostic ignored "-Wunused-function" // This suppresses deprecated header warnings, which is impossible with pragmas. -// Alternative is to specify -Wno-deprecated build option, but that disables other useful warnings too. +// Alternative is to specify -Wno-deprecated build option, but that disables +// other useful warnings too. # ifdef __DEPRECATED # define OMNI_USD_SUPPRESS_DEPRECATION_WARNINGS # undef __DEPRECATED @@ -46,9 +49,11 @@ #define BOOST_PYTHON_STATIC_LIB -// Include cstdio here so that vsnprintf is properly declared. This is necessary because pyerrors.h has -// #define vsnprintf _vsnprintf which later causes to declare std::_vsnprintf instead of the correct and proper -// std::vsnprintf. By doing it here before everything else, we avoid this nonsense. +// Include cstdio here so that vsnprintf is properly declared. This is necessary +// because pyerrors.h has #define vsnprintf _vsnprintf which later causes +// to declare std::_vsnprintf instead of the correct and proper +// std::vsnprintf. By doing it here before everything else, we avoid this +// nonsense. #include // Python must be included first because it monkeys with macros that cause @@ -152,7 +157,6 @@ #include #include - // -- Hydra #include @@ -166,7 +170,7 @@ #include // -- nv extensions -//#include +// #include // -- omni.usd #include diff --git a/source/extensions/omni.importer.mjcf/plugins/core/mesh.cpp b/source/extensions/omni.importer.mjcf/plugins/core/mesh.cpp index 883449c..02e8bf5 100644 --- a/source/extensions/omni.importer.mjcf/plugins/core/mesh.cpp +++ b/source/extensions/omni.importer.mjcf/plugins/core/mesh.cpp @@ -1,11 +1,17 @@ -// Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "mesh.h" @@ -154,8 +160,7 @@ T PlyRead(ifstream& s, PlyFormat format) return data; } -} // namespace anonymous - +} // namespace static pxr::GfVec3f AiVector3dToGfVector3f(const aiVector3D& vector) { @@ -172,7 +177,6 @@ pxr::GfVec3f AiColor4DToGfVector3f(const aiColor4D& color) return pxr::GfVec3f(color.r, color.g, color.b); } - void addAssimpNodeToMesh(const aiScene* scene, const aiNode* node, aiMatrix4x4 xform, UVInfo& uvInfo, Mesh* mesh) { unsigned int triOffset = static_cast(mesh->m_indices.size() / 3); @@ -279,7 +283,8 @@ void addAssimpNodeToMesh(const aiScene* scene, const aiNode* node, aiMatrix4x4 x usdmesh.faceVertexIndices.push_back(f.mIndices[k]); } } - // assert(f.mNumIndices > 0 && f.mNumIndices <= 3); // importer should triangluate mesh + // assert(f.mNumIndices > 0 && f.mNumIndices <= 3); // importer should + // triangluate mesh if (f.mNumIndices == 1) { mesh->m_indices.push_back(f.mIndices[0] + indexOffset); @@ -322,7 +327,6 @@ void addAssimpNodeToMesh(const aiScene* scene, const aiNode* node, aiMatrix4x4 x } } - Mesh* ImportMeshAssimp(const char* path) { Assimp::Importer importer; @@ -438,7 +442,6 @@ Mesh* ImportMeshAssimp(const char* path) return mesh; } - Mesh* ImportMesh(const char* path) { std::string ext = GetExtension(path); @@ -452,7 +455,6 @@ Mesh* ImportMesh(const char* path) else if (ext == "stl") mesh = ImportMeshFromStl(path); - return mesh; } @@ -597,8 +599,10 @@ Mesh* ImportMeshFromPly(const char* path) // debug #if ENABLE_VERBOSE_OUTPUT - printf("Loaded mesh: %s numFaces: %d numVertices: %d format: %d numProperties: %d\n", path, numFaces, numVertices, - format, numProperties); + printf( + "Loaded mesh: %s numFaces: %d numVertices: %d format: %d " + "numProperties: %d\n", + path, numFaces, numVertices, format, numProperties); #endif Mesh* mesh = new Mesh; @@ -672,7 +676,8 @@ Mesh* ImportMeshFromPly(const char* path) mesh->m_normals[i] = SafeNormalize(mesh->m_normals[i], Vector3(0.0f, 1.0f, 0.0f)); } - // cout << "Imported mesh " << path << " in " << (GetSeconds()-startTime)*1000.f << "ms" << endl; + // cout << "Imported mesh " << path << " in " << + // (GetSeconds()-startTime)*1000.f << "ms" << endl; return mesh; } @@ -702,7 +707,6 @@ struct VertexKey } }; - void ImportFromMtlLib(const char* path, std::vector& materials) { FILE* f = fopen(path, "r"); @@ -754,7 +758,6 @@ void ImportFromMtlLib(const char* path, std::vector& materials) } } - Mesh* ImportMeshFromObj(const char* meshPath) { ifstream file(meshPath); @@ -770,7 +773,8 @@ Mesh* ImportMeshFromObj(const char* meshPath) vector colors; vector& indices = m->m_indices; - // typedef unordered_map > VertexMap; + // typedef unordered_map > + // VertexMap; typedef map VertexMap; VertexMap vertexLookup; @@ -997,7 +1001,8 @@ Mesh* ImportMeshFromObj(const char* meshPath) if (m->m_materialAssignments.size()) m->m_materialAssignments.back().endTri = int(indices.size()) / 3; - // cout << "Imported mesh " << meshPath << " in " << (GetSeconds()-startTime)*1000.f << "ms" << endl; + // cout << "Imported mesh " << meshPath << " in " << + // (GetSeconds()-startTime)*1000.f << "ms" << endl; return m; } @@ -1039,7 +1044,8 @@ void ExportToObj(const char* path, const Mesh& m) { // uint32_t j = i+1; - // no sharing, assumes there is a unique position, texcoord and normal for each vertex + // no sharing, assumes there is a unique position, texcoord and normal for + // each vertex file << "f " << m.m_indices[i * 3] + 1 << " " << m.m_indices[i * 3 + 1] + 1 << " " << m.m_indices[i * 3 + 2] + 1 << endl; } @@ -1317,7 +1323,6 @@ Mesh* CreateCylinder(int slices, float radius, float halfHeight, bool cap) mesh->m_texcoords.push_back(Vec2(2.0f * float(i) / slices, 0.0f)); mesh->m_texcoords.push_back(Vec2(2.0f * float(i) / slices, 1.0f)); - if (i > 0) { int a = (i - 1) * 2 + 0; diff --git a/source/extensions/omni.importer.mjcf/plugins/core/mesh.h b/source/extensions/omni.importer.mjcf/plugins/core/mesh.h index e8c6b1b..d41976e 100644 --- a/source/extensions/omni.importer.mjcf/plugins/core/mesh.h +++ b/source/extensions/omni.importer.mjcf/plugins/core/mesh.h @@ -1,35 +1,36 @@ -// Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once // clang-format off #include "../UsdPCH.h" // clang-format on -// clang-format off -#include -#include -// clang-format on - -#include "assimp/scene.h" - #include "../math/core/core.h" #include "../math/core/maths.h" +#include "assimp/scene.h" #include #include struct TextureData { - int width; // width of texture - if height == 0, then width will be the same as buffer.size() - int height; // height of textur - if height == 0, then the buffer represents a compressed image with file type - // corresponding to format + int width; // width of texture - if height == 0, then width will be the same + // as buffer.size() + int height; // height of textur - if height == 0, then the buffer represents a + // compressed image with file type corresponding to format std::vector buffer; // r8g8b8a8 if not compressed std::string format; // format of the data in buffer if compressed (i.e. png, jpg, bmp) }; @@ -85,7 +86,6 @@ enum GymMeshNormalMode eComputePerFace, // compute per-face normals }; - struct USDMesh { std::string name; @@ -112,10 +112,12 @@ struct Mesh void DuplicateVertex(uint32_t i); - void CalculateFaceNormals(); // splits mesh at vertices to calculate faceted normals (changes topology) + void CalculateFaceNormals(); // splits mesh at vertices to calculate faceted + // normals (changes topology) void CalculateNormals(); void Transform(const Matrix44& m); - void Normalize(float s = 1.0f); // scale so bounds in any dimension equals s and lower bound = (0,0,0) + void Normalize(float s = 1.0f); // scale so bounds in any dimension equals s + // and lower bound = (0,0,0) void Flip(); @@ -156,7 +158,8 @@ Mesh* CreateTriMesh(float size, float y = 0.0f); Mesh* CreateCubeMesh(); Mesh* CreateQuadMesh(float sizex, float sizez, int gridx, int gridz); Mesh* CreateDiscMesh(float radius, uint32_t segments); -Mesh* CreateTetrahedron(float ground = 0.0f, float height = 1.0f); // fixed but not used +Mesh* CreateTetrahedron(float ground = 0.0f, + float height = 1.0f); // fixed but not used Mesh* CreateSphere(int slices, int segments, float radius = 1.0f); Mesh* CreateEllipsoid(int slices, int segments, Vec3 radiis); Mesh* CreateCapsule(int slices, int segments, float radius = 1.0f, float halfHeight = 1.0f); diff --git a/source/extensions/omni.importer.mjcf/plugins/core/platform.cpp b/source/extensions/omni.importer.mjcf/plugins/core/platform.cpp index 4da5938..dadd107 100644 --- a/source/extensions/omni.importer.mjcf/plugins/core/platform.cpp +++ b/source/extensions/omni.importer.mjcf/plugins/core/platform.cpp @@ -1,11 +1,17 @@ -// Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "platform.h" @@ -64,7 +70,6 @@ void Sleep(double seconds) ::Sleep(DWORD(seconds * 1000)); } - //// helper function to get exe path // string GetExePath() //{ @@ -95,8 +100,8 @@ void Sleep(double seconds) // ofn.lpstrFilter = filter; // ofn.lpstrFile = fileName; // ofn.nMaxFile = MAX_PATH; -// ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR; -// ofn.lpstrDefExt = ""; +// ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | +// OFN_NOCHANGEDIR; ofn.lpstrDefExt = ""; // // string fileNameStr; // @@ -124,7 +129,8 @@ void Sleep(double seconds) // { // do // { -// if (!(strcmp(info.cFileName, ".") == 0 || strcmp(info.cFileName, "..") == 0)) +// if (!(strcmp(info.cFileName, ".") == 0 || +// strcmp(info.cFileName, "..") == 0)) // { // files.push_back(info.cFileName); // } @@ -146,7 +152,6 @@ void Sleep(double seconds) // return true; //} - #else // linux, mac platforms @@ -174,7 +179,6 @@ double GetSeconds() #endif - uint8_t* LoadFileToBuffer(const char* filename, uint32_t* sizeRead) { FILE* file = fopen(filename, "rb"); @@ -206,7 +210,8 @@ uint8_t* LoadFileToBuffer(const char* filename, uint32_t* sizeRead) string LoadFileToString(const char* filename) { // std::ifstream file(filename); - // return string((std::istreambuf_iterator(file)), std::istreambuf_iterator()); + // return string((std::istreambuf_iterator(file)), + // std::istreambuf_iterator()); uint32_t size; uint8_t* buf = LoadFileToBuffer(filename, &size); @@ -240,7 +245,6 @@ bool SaveStringToFile(const char* filename, const char* s) } } - string StripFilename(const char* path) { // simply find the last diff --git a/source/extensions/omni.importer.mjcf/plugins/core/platform.h b/source/extensions/omni.importer.mjcf/plugins/core/platform.h index aa2c26f..2d81749 100644 --- a/source/extensions/omni.importer.mjcf/plugins/core/platform.h +++ b/source/extensions/omni.importer.mjcf/plugins/core/platform.h @@ -1,11 +1,17 @@ -// Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once #include "../math/core/types.h" @@ -65,7 +71,6 @@ inline std::string GetFilePathByPlatform(const char* path) } #endif - // shows a file open dialog // std::string FileOpenDialog(const char *filter = "All Files (*.*)\0*.*\0"); diff --git a/source/extensions/omni.importer.mjcf/plugins/math/core/common_math.h b/source/extensions/omni.importer.mjcf/plugins/math/core/common_math.h index af82ba9..1724092 100644 --- a/source/extensions/omni.importer.mjcf/plugins/math/core/common_math.h +++ b/source/extensions/omni.importer.mjcf/plugins/math/core/common_math.h @@ -1,11 +1,17 @@ -// Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once diff --git a/source/extensions/omni.importer.mjcf/plugins/math/core/core.h b/source/extensions/omni.importer.mjcf/plugins/math/core/core.h index 034f428..5326135 100644 --- a/source/extensions/omni.importer.mjcf/plugins/math/core/core.h +++ b/source/extensions/omni.importer.mjcf/plugins/math/core/core.h @@ -1,11 +1,17 @@ -// Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once @@ -19,7 +25,7 @@ # define VERBOSE(a) #endif -//#define Super __super +// #define Super __super // basically just a collection of macros and types #ifndef UNUSED @@ -44,7 +50,6 @@ #include - // disable some warnings #if _WIN32 # pragma warning(disable : 4996) // secure io @@ -135,9 +140,9 @@ T ByteSwap(const T& val) # define ToLittleEndian(x) x #endif -//#include "platform.h" +// #include "platform.h" -//#define sizeof_array(x) (sizeof(x)/sizeof(*x)) +// #define sizeof_array(x) (sizeof(x)/sizeof(*x)) template size_t sizeof_array(const T (&)[N]) { @@ -156,8 +161,8 @@ size_t sizeof_array(const T (&)[N]) // } //}; - -// given the path of one file it strips the filename and appends the relative path onto it +// given the path of one file it strips the filename and appends the relative +// path onto it inline void MakeRelativePath(const char* filePath, const char* fileRelativePath, char* fullPath) { // get base path of file diff --git a/source/extensions/omni.importer.mjcf/plugins/math/core/mat22.h b/source/extensions/omni.importer.mjcf/plugins/math/core/mat22.h index f2db7e7..130fb79 100644 --- a/source/extensions/omni.importer.mjcf/plugins/math/core/mat22.h +++ b/source/extensions/omni.importer.mjcf/plugins/math/core/mat22.h @@ -1,11 +1,17 @@ -// Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once diff --git a/source/extensions/omni.importer.mjcf/plugins/math/core/mat33.h b/source/extensions/omni.importer.mjcf/plugins/math/core/mat33.h index 3e073e0..02de602 100644 --- a/source/extensions/omni.importer.mjcf/plugins/math/core/mat33.h +++ b/source/extensions/omni.importer.mjcf/plugins/math/core/mat33.h @@ -1,11 +1,17 @@ -// Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once @@ -161,7 +167,6 @@ CUDA_CALLABLE inline Matrix33 InverseDouble(const Matrix33& a, bool& success) for (int j = 0; j < 3; ++j) m[i][j] = a(i, j); - double det = m[0][0] * (m[2][2] * m[1][1] - m[2][1] * m[1][2]) - m[1][0] * (m[2][2] * m[0][1] - m[2][1] * m[0][2]) + m[2][0] * (m[1][2] * m[0][1] - m[1][1] * m[0][2]); @@ -205,7 +210,6 @@ CUDA_CALLABLE inline Matrix33 InverseDouble(const Matrix33& a, bool& success) } } - CUDA_CALLABLE inline Matrix33 operator*(float s, const Matrix33& a) { return Multiply(s, a); @@ -308,7 +312,6 @@ CUDA_CALLABLE inline XQuat::XQuat(const Matrix33& m) *this = Normalize(*this); } - CUDA_CALLABLE inline void quat2Mat(const XQuat& q, Matrix33& m) { float sqx = q.x * q.x; diff --git a/source/extensions/omni.importer.mjcf/plugins/math/core/mat44.h b/source/extensions/omni.importer.mjcf/plugins/math/core/mat44.h index c1167d1..b9840ce 100644 --- a/source/extensions/omni.importer.mjcf/plugins/math/core/mat44.h +++ b/source/extensions/omni.importer.mjcf/plugins/math/core/mat44.h @@ -1,11 +1,17 @@ -// Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once diff --git a/source/extensions/omni.importer.mjcf/plugins/math/core/maths.h b/source/extensions/omni.importer.mjcf/plugins/math/core/maths.h index 3e51c69..6a4a5ca 100644 --- a/source/extensions/omni.importer.mjcf/plugins/math/core/maths.h +++ b/source/extensions/omni.importer.mjcf/plugins/math/core/maths.h @@ -1,11 +1,17 @@ -// Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once @@ -28,7 +34,6 @@ #include #include - struct Transform { // transform @@ -208,7 +213,8 @@ inline float Randf(float max) return Randf() * max; } -// returns a random unit vector (also can add an offset to generate around an off axis vector) +// returns a random unit vector (also can add an offset to generate around an +// off axis vector) inline Vec3 RandomUnitVector() { float phi = Randf(kPi * 2.0f); @@ -281,7 +287,6 @@ inline void UniformSampleTriangle(float& u, float& v) v = Randf() * r; } - inline Vec3 CosineSampleHemisphere() { Vec2 s = UniformSampleDisc(); @@ -348,7 +353,6 @@ inline Mat44 ViewMatrix(const Point3& pos) return Mat44(&view[0][0]); } - inline Mat44 LookAtMatrix(const Point3& viewer, const Point3& target) { // create a basis from viewer to target (OpenGL convention looking down -z) @@ -430,7 +434,6 @@ inline Mat44 OrthographicMatrix(float left, float right, float bottom, float top { 0.0f, 0.0f, -2.0f / (f - n), 0.0f }, { -(right + left) / (right - left), -(top + bottom) / (top - bottom), -(f + n) / (f - n), 1.0f } }; - return Mat44(&m[0][0]); } @@ -518,7 +521,8 @@ inline Mat44 TransformMatrix(const Rotation& r, const Point3& p) const float s3 = Sin(yaw); const float c3 = Cos(yaw); - // interprets the angles as yaw around world-y, pitch around new z, roll around new x + // interprets the angles as yaw around world-y, pitch around new z, roll + // around new x float mr[4][4] = { { c2 * c3, s2, -c2 * s3, 0.0f }, { s1 * s3 - c1 * c3 * s2, c1 * c2, c3 * s1 + c1 * s2 * s3, 0.0f }, { c3 * s1 * s2 + c1 * s3, -c2 * s1, c1 * c3 - s1 * s2 * s3, 0.0f }, @@ -529,7 +533,6 @@ inline Mat44 TransformMatrix(const Rotation& r, const Point3& p) return m1; // m2 * m1; } - // aligns the z axis along the vector inline Rotation AlignToVector(const Vec3& vector) { @@ -596,7 +599,8 @@ T HermiteSecondDerivative(const T& a, const T& b, const T& t1, const T& t2, floa inline float Log(float base, float x) { - // calculate the log of a value for an arbitary base, only use if you can't use the standard bases (10, e) + // calculate the log of a value for an arbitary base, only use if you can't + // use the standard bases (10, e) return logf(x) / logf(base); } @@ -766,7 +770,8 @@ inline bool operator!=(const Colour& lhs, const Colour& rhs) inline Colour ToneMap(const Colour& s) { - // return Colour(s.r / (s.r+1.0f), s.g / (s.g+1.0f), s.b / (s.b+1.0f), 1.0f); + // return Colour(s.r / (s.r+1.0f), s.g / (s.g+1.0f), s.b / + // (s.b+1.0f), 1.0f); float Y = 0.3333f * (s.r + s.g + s.b); return s / (1.0f + Y); } @@ -897,7 +902,6 @@ inline float SpecularExponentToRoughness(float exponent, float maxExponent = 204 return 1.0f - logf(exponent) / logf(maxExponent); } - inline Colour JetColorMap(float low, float high, float x) { float t = (x - low) / (high - low); @@ -1003,7 +1007,8 @@ CUDA_CALLABLE inline bool SolveQuadratic(T a, T b, T c, T& minT, T& maxT) return false; } - // numerical receipes 5.6 (this method ensures numerical accuracy is preserved) + // numerical receipes 5.6 (this method ensures numerical accuracy is + // preserved) T t = T(-0.5) * (b + Sign(b) * Sqrt(discriminant)); minT = t / a; maxT = c / t; @@ -1094,7 +1099,8 @@ CUDA_CALLABLE inline bool IntersectRayTriTwoSided(const Vec3& p, Vector3 n = Cross(ab, ac); float d = Dot(-dir, n); - float ood = 1.0f / d; // No need to check for division by zero here as infinity aritmetic will save us... + float ood = 1.0f / d; // No need to check for division by zero here as + // infinity aritmetic will save us... Vector3 ap = p - a; t = Dot(ap, n) * ood; @@ -1118,7 +1124,6 @@ CUDA_CALLABLE inline bool IntersectRayTriTwoSided(const Vec3& p, return true; } - // mostly taken from Real Time Collision Detection - p192 inline bool IntersectRayTri(const Point3& p, const Vec3& dir, @@ -1167,14 +1172,14 @@ inline bool IntersectRayTri(const Point3& p, w *= ood; u = 1.0f - v - w; - // optionally write out normal (todo: this branch is a performance concern, should probably remove) + // optionally write out normal (todo: this branch is a performance concern, + // should probably remove) if (normal) *normal = n; return true; } - // mostly taken from Real Time Collision Detection - p192 CUDA_CALLABLE inline bool IntersectSegmentTri(const Vec3& p, const Vec3& q, @@ -1228,7 +1233,8 @@ CUDA_CALLABLE inline bool IntersectSegmentTri(const Vec3& p, w *= ood; u = 1.0f - v - w; - // optionally write out normal (todo: this branch is a performance concern, should probably remove) + // optionally write out normal (todo: this branch is a performance concern, + // should probably remove) if (normal) *normal = n; @@ -1240,11 +1246,14 @@ CUDA_CALLABLE inline float ScalarTriple(const Vec3& a, const Vec3& b, const Vec3 return Dot(Cross(a, b), c); } -// intersects a line (through points p and q, against a triangle a, b, c - mostly taken from Real Time Collision -// Detection - p186 -CUDA_CALLABLE inline bool IntersectLineTri( - const Vec3& p, const Vec3& q, const Vec3& a, const Vec3& b, const Vec3& c) //, float& t, float& u, float& v, float& - // w, Vec3* normal, float expand) +// intersects a line (through points p and q, against a triangle a, b, c - +// mostly taken from Real Time Collision Detection - p186 +CUDA_CALLABLE inline bool IntersectLineTri(const Vec3& p, + const Vec3& q, + const Vec3& a, + const Vec3& b, + const Vec3& c) //, float& t, float& u, float& v, float& + // w, Vec3* normal, float expand) { const Vec3 pq = q - p; const Vec3 pa = a - p; @@ -1284,7 +1293,6 @@ CUDA_CALLABLE inline Vec3 ClosestPointToAABB(const Vec3& p, const Vec3& lower, c return c; } - // RTCD 5.1.5, page 142 CUDA_CALLABLE inline Vec3 ClosestPointOnTriangle( const Vec3& a, const Vec3& b, const Vec3& c, const Vec3& p, float& v, float& w) @@ -1363,8 +1371,9 @@ CUDA_CALLABLE inline Vec3 ClosestPointOnFatTriangle( return x + d * thickness; } -// computes intersection between a ray and a triangle expanded by a constant thickness, also works for ray-sphere and -// ray-capsule this is an iterative method similar to sphere tracing but for convex objects, see +// computes intersection between a ray and a triangle expanded by a constant +// thickness, also works for ray-sphere and ray-capsule this is an iterative +// method similar to sphere tracing but for convex objects, see // http://dtecta.com/papers/jgt04raycast.pdf CUDA_CALLABLE inline bool IntersectRayFatTriangle(const Vec3& p, const Vec3& dir, @@ -1427,7 +1436,6 @@ CUDA_CALLABLE inline bool IntersectRayFatTriangle(const Vec3& p, return true; } - CUDA_CALLABLE inline float SqDistPointSegment(Vec3 a, Vec3 b, Vec3 c) { Vec3 ab = b - a, ac = c - a, bc = c - b; @@ -1515,7 +1523,6 @@ CUDA_CALLABLE inline void ClosestPointBetweenLineSegments( } } - CUDA_CALLABLE inline float ClosestPointBetweenLineSegmentAndTri( const Vec3& p, const Vec3& q, const Vec3& a, const Vec3& b, const Vec3& c, float& outT, float& outV, float& outW) { @@ -1617,7 +1624,6 @@ CUDA_CALLABLE inline float ClosestPointBetweenLineSegmentAndTri( return sqrtf(minDsq); } - CUDA_CALLABLE inline float minf(const float a, const float b) { return a < b ? a : b; @@ -1651,7 +1657,6 @@ CUDA_CALLABLE inline bool IntersectRayAABBFast( return hit; } - CUDA_CALLABLE inline bool IntersectRayAABB( const Vec3& start, const Vector3& dir, const Vector3& min, const Vector3& max, float& t, Vector3* normal) { @@ -1830,8 +1835,8 @@ class Rect uint32_t m_bottom; }; -// doesn't really belong here but efficient (and I believe correct) in place random shuffle based on the Fisher-Yates / -// Knuth algorithm +// doesn't really belong here but efficient (and I believe correct) in place +// random shuffle based on the Fisher-Yates / Knuth algorithm template void RandomShuffle(T begin, T end) { @@ -1848,7 +1853,6 @@ void RandomShuffle(T begin, T end) } } - CUDA_CALLABLE inline Quat QuatFromAxisAngle(const Vec3& axis, float angle) { Vec3 v = Normalize(axis); @@ -1862,7 +1866,6 @@ CUDA_CALLABLE inline Quat QuatFromAxisAngle(const Vec3& axis, float angle) return Quat(v.x, v.y, v.z, w); } - // rotate by quaternion (q, w) CUDA_CALLABLE inline Vec3 rotate(const Vec3& q, float w, const Vec3& x) { @@ -1908,7 +1911,6 @@ CUDA_CALLABLE inline Quat GetRotationQuat(const Vec3& _u, const Vec3& _v) } } - CUDA_CALLABLE inline void TransformBounds(const Quat& q, Vec3 extents, Vec3& newExtents) { Matrix33 transform(q); @@ -2033,7 +2035,8 @@ inline int PoissonSampleBox3D(Vec3 lower, Vec3 upper, float separation, Vec3* po return c; } -// Generates an optimally dense sphere packing at the origin (implicit sphere at the origin) +// Generates an optimally dense sphere packing at the origin (implicit sphere at +// the origin) inline int TightPack3D(float radius, float separation, Vec3* points, int maxPoints) { int dim = int(ceilf(radius / separation)); @@ -2068,7 +2071,6 @@ inline int TightPack3D(float radius, float separation, Vec3* points, int maxPoin return c; } - struct Bounds { CUDA_CALLABLE inline Bounds() : lower(FLT_MAX), upper(-FLT_MAX) @@ -2157,8 +2159,8 @@ CUDA_CALLABLE inline float SurfaceArea(const Bounds& b) inline void ExtractFrustumPlanes(const Matrix44& m, Plane* planes) { - // Based on Fast Extraction of Viewing Frustum Planes from the WorldView-Projection Matrix, Gill Grib, Klaus - // Hartmann + // Based on Fast Extraction of Viewing Frustum Planes from the + // WorldView-Projection Matrix, Gill Grib, Klaus Hartmann // Left clipping plane planes[0].x = m(3, 0) + m(0, 0); diff --git a/source/extensions/omni.importer.mjcf/plugins/math/core/matnn.h b/source/extensions/omni.importer.mjcf/plugins/math/core/matnn.h index 156c901..2973392 100644 --- a/source/extensions/omni.importer.mjcf/plugins/math/core/matnn.h +++ b/source/extensions/omni.importer.mjcf/plugins/math/core/matnn.h @@ -1,11 +1,17 @@ -// Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once @@ -60,7 +66,6 @@ class XMatrix return data[col][row]; } - void SetIdentity() { for (int i = 0; i < m; ++i) @@ -88,7 +93,6 @@ XMatrix operator-(const XMatrix& lhs, const XMatrix& for (int j = 0; j < n; ++j) d(i, j) = lhs(i, j) - rhs(i, j); - return d; } @@ -101,11 +105,9 @@ XMatrix operator+(const XMatrix& lhs, const XMatrix& for (int j = 0; j < n; ++j) d(i, j) = lhs(i, j) + rhs(i, j); - return d; } - template XMatrix Multiply(const XMatrix& lhs, const XMatrix& rhs) { @@ -129,7 +131,6 @@ XMatrix Multiply(const XMatrix& lhs, const XMatrix& rhs) return ret; } - template XMatrix Transpose(const XMatrix& a) { @@ -146,7 +147,6 @@ XMatrix Transpose(const XMatrix& a) return ret; } - // matrix to swap row i and j when multiplied on the right template XMatrix Permutation(int i, int j) @@ -267,7 +267,8 @@ T Determinant(const XMatrix& A, XMatrix& L, XMatrix& { U = LU(A, L); - // determinant is the product of diagonal entries of U (assume L has 1s on diagonal) + // determinant is the product of diagonal entries of U (assume L has 1s on + // diagonal) T det = 1.0; for (int i = 0; i < n; ++i) det *= U(i, i); diff --git a/source/extensions/omni.importer.mjcf/plugins/math/core/point3.h b/source/extensions/omni.importer.mjcf/plugins/math/core/point3.h index 052f3f9..af19b2f 100644 --- a/source/extensions/omni.importer.mjcf/plugins/math/core/point3.h +++ b/source/extensions/omni.importer.mjcf/plugins/math/core/point3.h @@ -1,11 +1,17 @@ -// Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once diff --git a/source/extensions/omni.importer.mjcf/plugins/math/core/quat.h b/source/extensions/omni.importer.mjcf/plugins/math/core/quat.h index 725ec35..606013b 100644 --- a/source/extensions/omni.importer.mjcf/plugins/math/core/quat.h +++ b/source/extensions/omni.importer.mjcf/plugins/math/core/quat.h @@ -1,11 +1,17 @@ -// Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once @@ -222,9 +228,10 @@ CUDA_CALLABLE inline void EulerFromQuatZYX(const Quat& q, float& rotx, float& ro } } -// converts Euler angles to quaternion performing an intrinsic rotation in yaw then pitch then roll order -// i.e. first rotate by yaw around z, then rotate by pitch around the rotated y axis, then rotate around -// roll around the twice (by yaw and pitch) rotated x axis +// converts Euler angles to quaternion performing an intrinsic rotation in yaw +// then pitch then roll order i.e. first rotate by yaw around z, then rotate by +// pitch around the rotated y axis, then rotate around roll around the twice (by +// yaw and pitch) rotated x axis CUDA_CALLABLE inline Quat rpy2quat(const float roll, const float pitch, const float yaw) { Quat q; @@ -244,9 +251,10 @@ CUDA_CALLABLE inline Quat rpy2quat(const float roll, const float pitch, const fl return q; } -// converts Euler angles to quaternion performing an intrinsic rotation in x then y then z order -// i.e. first rotate by x_rot around x, then rotate by y_rot around the rotated y axis, then rotate by -// z_rot around the twice (by roll and pitch) rotated z axis +// converts Euler angles to quaternion performing an intrinsic rotation in x +// then y then z order i.e. first rotate by x_rot around x, then rotate by y_rot +// around the rotated y axis, then rotate by z_rot around the twice (by roll and +// pitch) rotated z axis CUDA_CALLABLE inline Quat euler_xyz2quat(const float x_rot, const float y_rot, const float z_rot) { Quat q; @@ -267,8 +275,9 @@ CUDA_CALLABLE inline Quat euler_xyz2quat(const float x_rot, const float y_rot, c } // !!! preist@ This function produces euler angles according to this convention: -// https://www.euclideanspace.com/maths/standards/index.htm Heading = rotation about y axis Attitude = rotation about z -// axis Bank = rotation about x axis Order: Heading (y) -> Attitude (z) -> Bank (x), and applied intrinsically +// https://www.euclideanspace.com/maths/standards/index.htm Heading = rotation +// about y axis Attitude = rotation about z axis Bank = rotation about x axis +// Order: Heading (y) -> Attitude (z) -> Bank (x), and applied intrinsically CUDA_CALLABLE inline void quat2rpy(const Quat& q1, float& bank, float& attitude, float& heading) { float sqw = q1.w * q1.w; @@ -300,8 +309,8 @@ CUDA_CALLABLE inline void quat2rpy(const Quat& q1, float& bank, float& attitude, } // preist@: -// The Euler angles correspond to an extrinsic x-y-z i.e. intrinsic z-y-x rotation -// and this function does not guard against gimbal lock +// The Euler angles correspond to an extrinsic x-y-z i.e. intrinsic z-y-x +// rotation and this function does not guard against gimbal lock CUDA_CALLABLE inline void zUpQuat2rpy(const Quat& q1, float& roll, float& pitch, float& yaw) { // roll (x-axis rotation) @@ -340,7 +349,6 @@ CUDA_CALLABLE inline void getEulerZYX(const Quat& q, float& yawZ, float& pitchY, yawZ = atan2(2 * (q.x * q.y + q.w * q.z), squ + sqx - sqy - sqz); } - // rotate vector by quaternion (q, w) CUDA_CALLABLE inline Vec3 Rotate(const Quat& q, const Vec3& x) { @@ -391,7 +399,8 @@ CUDA_CALLABLE inline Quat Normalize(const Quat& q) } // -// given two quaternions and a time-step returns the corresponding angular velocity vector +// given two quaternions and a time-step returns the corresponding angular +// velocity vector // CUDA_CALLABLE inline Vec3 DifferentiateQuat(const Quat& q1, const Quat& q0, float invdt) { @@ -416,7 +425,6 @@ CUDA_CALLABLE inline Vec3 DifferentiateQuat(const Quat& q1, const Quat& q0, floa } } - CUDA_CALLABLE inline Quat IntegrateQuat(const Vec3& omega, const Quat& q0, float dt) { Vec3 axis; diff --git a/source/extensions/omni.importer.mjcf/plugins/math/core/types.h b/source/extensions/omni.importer.mjcf/plugins/math/core/types.h index 264e25f..0e5f780 100644 --- a/source/extensions/omni.importer.mjcf/plugins/math/core/types.h +++ b/source/extensions/omni.importer.mjcf/plugins/math/core/types.h @@ -1,11 +1,17 @@ -// Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once diff --git a/source/extensions/omni.importer.mjcf/plugins/math/core/vec2.h b/source/extensions/omni.importer.mjcf/plugins/math/core/vec2.h index c54d984..a9bdf83 100644 --- a/source/extensions/omni.importer.mjcf/plugins/math/core/vec2.h +++ b/source/extensions/omni.importer.mjcf/plugins/math/core/vec2.h @@ -1,11 +1,17 @@ -// Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once @@ -46,7 +52,6 @@ # define FLOAT_VALIDATE(f) #endif - // vec2 template class XVector2 @@ -195,7 +200,6 @@ CUDA_CALLABLE bool operator==(const XVector2& lhs, const XVector2& rhs) return (lhs.x == rhs.x && lhs.y == rhs.y); } - template CUDA_CALLABLE T Dot(const XVector2& v1, const XVector2& v2) { @@ -228,7 +232,8 @@ CUDA_CALLABLE XVector2 Min(const XVector2& a, const XVector2& b) return XVector2(Min(a.x, b.x), Min(a.y, b.y)); } -// 2d cross product, treat as if a and b are in the xy plane and return magnitude of z +// 2d cross product, treat as if a and b are in the xy plane and return +// magnitude of z template CUDA_CALLABLE T Cross(const XVector2& a, const XVector2& b) { diff --git a/source/extensions/omni.importer.mjcf/plugins/math/core/vec3.h b/source/extensions/omni.importer.mjcf/plugins/math/core/vec3.h index 290b353..d9652d5 100644 --- a/source/extensions/omni.importer.mjcf/plugins/math/core/vec3.h +++ b/source/extensions/omni.importer.mjcf/plugins/math/core/vec3.h @@ -1,11 +1,17 @@ -// Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once @@ -206,7 +212,6 @@ CUDA_CALLABLE inline float Dot3(const float* v1, const float* v2) return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; } - template CUDA_CALLABLE inline T Dot(const XVector3& v1, const XVector3& v2) { diff --git a/source/extensions/omni.importer.mjcf/plugins/math/core/vec4.h b/source/extensions/omni.importer.mjcf/plugins/math/core/vec4.h index 505be97..5cef174 100644 --- a/source/extensions/omni.importer.mjcf/plugins/math/core/vec4.h +++ b/source/extensions/omni.importer.mjcf/plugins/math/core/vec4.h @@ -1,11 +1,17 @@ -// Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 // -// NVIDIA CORPORATION and its licensors retain all intellectual property -// and proprietary rights in and to this software, related documentation -// and any modifications thereto. Any use, reproduction, disclosure or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA CORPORATION is strictly prohibited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once @@ -14,7 +20,6 @@ #include - #if 0 // defined(_DEBUG) && defined(_WIN32) # define VEC4_VALIDATE() \ { \ diff --git a/source/extensions/omni.importer.mjcf/plugins/utils/Path.h b/source/extensions/omni.importer.mjcf/plugins/utils/Path.h index 8cb39bc..de8fac3 100644 --- a/source/extensions/omni.importer.mjcf/plugins/utils/Path.h +++ b/source/extensions/omni.importer.mjcf/plugins/utils/Path.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,8 +19,10 @@ #include "../UsdPCH.h" // clang-format on -#include +#include +#include +#include namespace omni { @@ -60,7 +62,6 @@ inline std::string normalizeUrl(const char* url) return ret; } - std::string resolve_absolute(std::string parent, std::string relative) { size_t bufferSize = parent.size() + relative.size(); @@ -69,7 +70,7 @@ std::string resolve_absolute(std::string parent, std::string relative) return combined_url; } -} -} -} -} +} // namespace path +} // namespace utils +} // namespace isaac +} // namespace omni diff --git a/source/extensions/omni.importer.mjcf/premake5.lua b/source/extensions/omni.importer.mjcf/premake5.lua index 9940855..3979124 100644 --- a/source/extensions/omni.importer.mjcf/premake5.lua +++ b/source/extensions/omni.importer.mjcf/premake5.lua @@ -65,7 +65,6 @@ project_ext_plugin(ext, "omni.importer.mjcf.plugin") "%{root}/_build/target-deps/pybind11/include", "%{root}/_build/target-deps/nv_usd/%{cfg.buildcfg}/include", "%{root}/_build/target-deps/usd_ext_physics/%{cfg.buildcfg}/include", - "%{root}/_build/target-deps/rtx_plugins/include", "%{root}/_build/target-deps/assimp/include", "%{root}/_build/target-deps/python/include", "%{root}/_build/target-deps/tinyxml2/include", diff --git a/tools/packman/bootstrap/configure.bat b/tools/packman/bootstrap/configure.bat index bb8253d..13fa6ca 100644 --- a/tools/packman/bootstrap/configure.bat +++ b/tools/packman/bootstrap/configure.bat @@ -4,7 +4,7 @@ :: you may not use this file except in compliance with the License. :: You may obtain a copy of the License at :: -:: http://www.apache.org/licenses/LICENSE-2.0 +:: https://www.apache.org/licenses/LICENSE-2.0 :: :: Unless required by applicable law or agreed to in writing, software :: distributed under the License is distributed on an "AS IS" BASIS, @@ -12,7 +12,7 @@ :: See the License for the specific language governing permissions and :: limitations under the License. -set PM_PACKMAN_VERSION=7.2.3 +set PM_PACKMAN_VERSION=7.6 :: Specify where packman command is rooted set PM_INSTALL_PATH=%~dp0.. @@ -48,15 +48,15 @@ echo. :: that may be needed in the path :ENSURE_DIR if not exist "%PM_PACKAGES_ROOT%" ( - echo Creating packman packages cache at %PM_PACKAGES_ROOT% - mkdir "%PM_PACKAGES_ROOT%" + echo Creating packman packages cache at %PM_PACKAGES_ROOT% + mkdir "%PM_PACKAGES_ROOT%" ) if %errorlevel% neq 0 ( goto ERROR_MKDIR_PACKAGES_ROOT ) :: The Python interpreter may already be externally configured if defined PM_PYTHON_EXT ( - set PM_PYTHON=%PM_PYTHON_EXT% - goto PACKMAN + set PM_PYTHON=%PM_PYTHON_EXT% + goto PACKMAN ) set PM_PYTHON_VERSION=3.10.5-1-windows-x86_64 @@ -95,11 +95,16 @@ if exist "%PM_PYTHON%" ( if exist "%PM_PYTHON_DIR%" ( rd /s /q "%PM_PYTHON_DIR%" > nul ) ) -:: Perform atomic rename -rename "%TEMP_FOLDER_NAME%" "%PM_PYTHON_VERSION%" 1> nul -:: Failure during move, need to clean up and abort +:: Perform atomic move (allowing ovewrite, /y) +move /y "%TEMP_FOLDER_NAME%" "%PM_PYTHON_DIR%" 1> nul +:: Verify that python.exe is now where we expect +if exist "%PM_PYTHON%" goto PACKMAN + +:: Wait a second and try again (can help with access denied weirdness) +timeout /t 1 /nobreak 1> nul +move /y "%TEMP_FOLDER_NAME%" "%PM_PYTHON_DIR%" 1> nul if %errorlevel% neq 0 ( - echo !!! Error renaming python !!! + echo !!! Error moving python %TEMP_FOLDER_NAME% -> %PM_PYTHON_DIR% !!! call :CLEAN_UP_TEMP_FOLDER goto ERROR ) @@ -107,7 +112,7 @@ if %errorlevel% neq 0 ( :PACKMAN :: The packman module may already be externally configured if defined PM_MODULE_DIR_EXT ( - set PM_MODULE_DIR=%PM_MODULE_DIR_EXT% + set PM_MODULE_DIR=%PM_MODULE_DIR_EXT% ) else ( set PM_MODULE_DIR=%PM_PACKAGES_ROOT%\packman-common\%PM_PACKMAN_VERSION% ) diff --git a/tools/packman/bootstrap/download_file_from_url.ps1 b/tools/packman/bootstrap/download_file_from_url.ps1 index df55745..ba245e5 100644 --- a/tools/packman/bootstrap/download_file_from_url.ps1 +++ b/tools/packman/bootstrap/download_file_from_url.ps1 @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/tools/packman/bootstrap/fetch_file_from_packman_bootstrap.cmd b/tools/packman/bootstrap/fetch_file_from_packman_bootstrap.cmd index bf3a88d..a650859 100644 --- a/tools/packman/bootstrap/fetch_file_from_packman_bootstrap.cmd +++ b/tools/packman/bootstrap/fetch_file_from_packman_bootstrap.cmd @@ -4,7 +4,7 @@ :: you may not use this file except in compliance with the License. :: You may obtain a copy of the License at :: -:: http://www.apache.org/licenses/LICENSE-2.0 +:: https://www.apache.org/licenses/LICENSE-2.0 :: :: Unless required by applicable law or agreed to in writing, software :: distributed under the License is distributed on an "AS IS" BASIS, @@ -20,7 +20,7 @@ @echo Fetching %PACKAGE_NAME% ... @powershell -ExecutionPolicy ByPass -NoLogo -NoProfile -File "%~dp0download_file_from_url.ps1" ^ - -source "http://bootstrap.packman.nvidia.com/%PACKAGE_NAME%" -output %TARGET_PATH% + -source "https://bootstrap.packman.nvidia.com/%PACKAGE_NAME%" -output %TARGET_PATH% :: A bug in powershell prevents the errorlevel code from being set when using the -File execution option :: We must therefore do our own failure analysis, basically make sure the file exists: @if not exist %TARGET_PATH% goto ERROR_DOWNLOAD_FAILED diff --git a/tools/packman/bootstrap/generate_temp_folder.ps1 b/tools/packman/bootstrap/generate_temp_folder.ps1 index d34fc9c..0e628db 100644 --- a/tools/packman/bootstrap/generate_temp_folder.ps1 +++ b/tools/packman/bootstrap/generate_temp_folder.ps1 @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/tools/packman/bootstrap/install_package.py b/tools/packman/bootstrap/install_package.py index b8ae7f6..38bbc12 100644 --- a/tools/packman/bootstrap/install_package.py +++ b/tools/packman/bootstrap/install_package.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/tools/packman/config.packman.xml b/tools/packman/config.packman.xml index 7402744..3223a33 100644 --- a/tools/packman/config.packman.xml +++ b/tools/packman/config.packman.xml @@ -6,4 +6,4 @@ - + \ No newline at end of file diff --git a/tools/packman/packman b/tools/packman/packman index 32adace..08c3897 100755 --- a/tools/packman/packman +++ b/tools/packman/packman @@ -6,7 +6,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,7 @@ else PM_CURL_SILENT="-s -S" PM_WGET_QUIET="--quiet" fi -PM_PACKMAN_VERSION=7.2.3 +PM_PACKMAN_VERSION=7.6 # This is necessary for newer macOS if [ `uname` == 'Darwin' ]; then @@ -61,7 +61,7 @@ fi fetch_file_from_s3() { SOURCE=$1 - SOURCE_URL=http://bootstrap.packman.nvidia.com/$SOURCE + SOURCE_URL=https://bootstrap.packman.nvidia.com/$SOURCE TARGET=$2 echo "Fetching $SOURCE from bootstrap.packman.nvidia.com ..." if command -v wget >/dev/null 2>&1; then diff --git a/tools/packman/packman.cmd b/tools/packman/packman.cmd index 5a91fd2..e55b2f0 100644 --- a/tools/packman/packman.cmd +++ b/tools/packman/packman.cmd @@ -47,6 +47,7 @@ exit /b 1 @echo Error while processing and setting environment variables! exit /b 1 +:: pad [xxxx] :ECHO_AND_RESET_ERROR @echo off if /I "%PM_VERBOSITY%"=="debug" ( @@ -62,10 +63,27 @@ goto :RUN_PM_MODULE :CONFIGURE :: Must capture and set code page to work around issue #279, powershell invocation mutates console font -for /f "tokens=2 delims=:" %%a in ('chcp') do (set OLD_CODE_PAGE=%%a) -chcp 437 > nul +:: This issue only happens in Windows CMD shell when using 65001 code page. Some Git Bash implementations +:: don't support chcp so this workaround is a bit convoluted. +:: Test for chcp: +chcp > nul 2>&1 +if %errorlevel% equ 0 ( + for /f "tokens=2 delims=:" %%a in ('chcp') do (set PM_OLD_CODE_PAGE=%%a) +) else ( + call :ECHO_AND_RESET_ERROR +) +:: trim leading space (this is safe even when PM_OLD_CODE_PAGE has not been set) +set PM_OLD_CODE_PAGE=%PM_OLD_CODE_PAGE:~1% +if "%PM_OLD_CODE_PAGE%" equ "65001" ( + chcp 437 > nul + set PM_RESTORE_CODE_PAGE=1 +) call "%~dp0\bootstrap\configure.bat" -set CONFIG_ERRORLEVEL=%errorlevel% -:: Restore code page -chcp %OLD_CODE_PAGE% > nul -exit /b %CONFIG_ERRORLEVEL% +set PM_CONFIG_ERRORLEVEL=%errorlevel% +if defined PM_RESTORE_CODE_PAGE ( + :: Restore code page + chcp %PM_OLD_CODE_PAGE% > nul +) +set PM_OLD_CODE_PAGE= +set PM_RESTORE_CODE_PAGE= +exit /b %PM_CONFIG_ERRORLEVEL% diff --git a/tools/packman/packmanconf.py b/tools/packman/packmanconf.py index 612dae3..3dac03e 100644 --- a/tools/packman/packmanconf.py +++ b/tools/packman/packmanconf.py @@ -79,7 +79,7 @@ def get_module_dir(conf_dir, packages_root: str, version: str) -> str: tf = tempfile.NamedTemporaryFile(delete=False) target_name = tf.name tf.close() - url = f"http://bootstrap.packman.nvidia.com/packman-common@{version}.zip" + url = f"https://bootstrap.packman.nvidia.com/packman-common@{version}.zip" print(f"Downloading '{url}' ...") import urllib.request diff --git a/tools/packman/python.bat b/tools/packman/python.bat index ef37691..e4e6cc6 100644 --- a/tools/packman/python.bat +++ b/tools/packman/python.bat @@ -4,7 +4,7 @@ :: you may not use this file except in compliance with the License. :: You may obtain a copy of the License at :: -:: http://www.apache.org/licenses/LICENSE-2.0 +:: https://www.apache.org/licenses/LICENSE-2.0 :: :: Unless required by applicable law or agreed to in writing, software :: distributed under the License is distributed on an "AS IS" BASIS, @@ -13,9 +13,20 @@ :: limitations under the License. @echo off -setlocal +setlocal enableextensions call "%~dp0\packman" init set "PYTHONPATH=%PM_MODULE_DIR%;%PYTHONPATH%" -set PYTHONNOUSERSITE=1 -"%PM_PYTHON%" -u %* + +if not defined PYTHONNOUSERSITE ( + set PYTHONNOUSERSITE=1 +) + +REM For performance, default to unbuffered; however, allow overriding via +REM PYTHONUNBUFFERED=0 since PYTHONUNBUFFERED on windows can truncate output +REM when printing long strings +if not defined PYTHONUNBUFFERED ( + set PYTHONUNBUFFERED=1 +) + +"%PM_PYTHON%" %* \ No newline at end of file diff --git a/tools/packman/python.sh b/tools/packman/python.sh index 37c9f1b..00ab46e 100755 --- a/tools/packman/python.sh +++ b/tools/packman/python.sh @@ -6,7 +6,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -22,11 +22,21 @@ if [ ! -f "$PACKMAN_CMD" ]; then fi source "$PACKMAN_CMD" init export PYTHONPATH="${PM_MODULE_DIR}:${PYTHONPATH}" -export PYTHONNOUSERSITE=1 + +if [ -z "${PYTHONNOUSERSITE:-}" ]; then + export PYTHONNOUSERSITE=1 +fi + +# For performance, default to unbuffered; however, allow overriding via +# PYTHONUNBUFFERED=0 since PYTHONUNBUFFERED on windows can truncate output +# when printing long strings +if [ -z "${PYTHONUNBUFFERED:-}" ]; then + export PYTHONUNBUFFERED=1 +fi # workaround for our python not shipping with certs if [[ -z ${SSL_CERT_DIR:-} ]]; then export SSL_CERT_DIR=/etc/ssl/certs/ fi -"${PM_PYTHON}" -u "$@" +"${PM_PYTHON}" "$@"