diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..9c30e8d5 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,437 @@ +--- +Checks: > + # The Bifrost USD code base currently passes the uncommented checks + # below!, + clang-diagnostic-*, + # Run the static analyzer, skipping the experimental checks, + clang-analyzer-*, + -clang-analyzer-alpha*, + cert-dcl03-c, + cert-dcl50-cpp, + cert-dcl54-cpp, + cert-dcl59-cpp, + cert-err52-cpp, + # Turn-off: construction of 'g_DefaultString_' with static + # storage duration may throw an exception that cannot be + # caught. This is way too noisy! + # cert-err58-cpp, + cert-err60-cpp, + cert-err61-cpp, + cert-fio38-c, + cert-oop11-cpp, + cppcoreguidelines-c-copy-assignment-signature, + # cppcoreguidelines-pro-bounds-constant-array-index, + # cppcoreguidelines-pro-type-const-cast, + cppcoreguidelines-pro-type-cstyle-cast, + # cppcoreguidelines-pro-type-reinterpret-cast, + cppcoreguidelines-pro-type-union-access, + # cppcoreguidelines-pro-type-vararg, + # Turn-off: Complains about mundane cases all over! + # cppcoreguidelines-pro-bounds-array-to-pointer-decay, + # cppcoreguidelines-pro-bounds-pointer-arithmetic, + # cppcoreguidelines-pro-type-static-cast-downcast, + google-build-explicit-make-pair, + google-build-namespaces, + # google-build-using-namespace, + google-explicit-constructor, + google-global-names-in-headers, + # google-readability-braces-around-statements, + # google-readability-casting, + google-readability-function-size, + # google-readability-namespace-comments, + google-readability-redundant-smartptr-get, + google-readability-todo, + # google-runtime-int, + google-runtime-member-string-references, + google-runtime-memset, + google-runtime-operator, + # Turn-off: maya-bifrostboard doesn't have the same structure as LLVM! + # llvm-header-guard, + # llvm-include-order, + # llvm-namespace-comment, + llvm-twine-local, + misc-argument-comment, + misc-assert-side-effect, + misc-assign-operator-signature, + misc-bool-pointer-implicit-conversion, + misc-definitions-in-headers, + misc-inaccurate-erase, + misc-inefficient-algorithm, + misc-macro-parentheses, + misc-macro-repeated-side-effects, + misc-move-const-arg, + misc-move-constructor-init, + misc-new-delete-overloads, + misc-noexcept-move-constructor, + misc-non-copyable-objects, + misc-sizeof-container, + misc-static-assert, + misc-string-integer-assignment, + misc-swapped-arguments, + misc-throw-by-value-catch-by-reference, + misc-undelegated-constructor, + misc-uniqueptr-reset-release, + misc-unused-alias-decls, + misc-unused-parameters, + misc-unused-raii, + misc-virtual-near-miss, + # modernize-loop-convert, + # C++14! + # modernize-make-unique, + modernize-pass-by-value, + modernize-redundant-void-arg, + modernize-replace-auto-ptr, + # modernize-shrink-to-fit, + # modernize-use-auto, + modernize-use-default, + modernize-use-nullptr, + modernize-use-override, + performance-faster-string-find, + performance-for-range-copy, + performance-implicit-cast-in-loop, + # MAYA-83043: performance-inefficient-string-concatenation is an obsolete + # performance-inefficient-string-concatenation, + performance-type-promotion-in-math-fn, + performance-unnecessary-copy-initialization, + performance-unnecessary-value-param, + # readability-braces-around-statements, + readability-container-size-empty, + # readability-else-after-return, + # readability-function-size, + # readability-identifier-naming, + # readability-implicit-bool-cast, + # readability-inconsistent-declaration-parameter-name, + # readability-named-parameter, + readability-redundant-smartptr-get, + readability-redundant-string-cstr, + # Turn-off: It simplifies assert(false && "...") to + # assert(false). Would be nice to the check... or at least + # submit a fix. + # readability-simplify-boolean-expr, + readability-uniqueptr-delete-release, + bugprone-suspicious-missing-comma + +# By default, all warnings are errors, except #pragma and deprecation warnings +WarningsAsErrors: '*,-clang-diagnostic-#pragma-messages,-clang-diagnostic-deprecated-declarations' +HeaderFilterRegex: '' +AnalyzeTemporaryDtors: false +CheckOptions: + - key: cert-err61-cpp.CheckThrowTemporaries + value: '1' + - key: cert-oop11-cpp.IncludeStyle + value: llvm + - key: cppcoreguidelines-pro-bounds-constant-array-index.GslHeader + value: '' + - key: cppcoreguidelines-pro-bounds-constant-array-index.IncludeStyle + value: '0' + - key: google-readability-braces-around-statements.ShortStatementLines + value: '1' + - key: google-readability-function-size.BranchThreshold + value: '4294967295' + - key: google-readability-function-size.LineThreshold + value: '4294967295' + - key: google-readability-function-size.StatementThreshold + value: '800' + - key: google-readability-namespace-comments.ShortNamespaceLines + value: '10' + - key: google-readability-namespace-comments.SpacesBeforeComments + value: '2' + - key: google-runtime-int.SignedTypePrefix + value: int + - key: google-runtime-int.TypeSuffix + value: '' + - key: google-runtime-int.UnsignedTypePrefix + value: uint + - key: llvm-namespace-comment.ShortNamespaceLines + value: '1' + - key: llvm-namespace-comment.SpacesBeforeComments + value: '1' + - key: misc-assert-side-effect.AssertMacros + value: assert + - key: misc-assert-side-effect.CheckFunctionCalls + value: '0' + - key: misc-definitions-in-headers.UseHeaderFileExtension + value: '1' + - key: misc-move-constructor-init.IncludeStyle + value: llvm + - key: misc-throw-by-value-catch-by-reference.CheckThrowTemporaries + value: '1' + - key: modernize-loop-convert.MaxCopySize + value: '16' + - key: modernize-loop-convert.MinConfidence + value: reasonable + - key: modernize-loop-convert.NamingStyle + value: CamelCase + - key: modernize-pass-by-value.IncludeStyle + value: llvm + - key: modernize-replace-auto-ptr.IncludeStyle + value: llvm + - key: modernize-use-nullptr.NullMacros + value: 'NULL' + - key: readability-braces-around-statements.ShortStatementLines + value: '1' + - key: readability-function-size.BranchThreshold + value: '4294967295' + - key: readability-function-size.LineThreshold + value: '4294967295' + - key: readability-function-size.StatementThreshold + value: '800' + - key: readability-identifier-naming.AbstractClassCase + value: CamelCase + - key: readability-identifier-naming.AbstractClassPrefix + value: '' + - key: readability-identifier-naming.AbstractClassSuffix + value: '' + - key: readability-identifier-naming.ClassCase + value: CamelCase + - key: readability-identifier-naming.ClassConstantCase + value: camelCase + - key: readability-identifier-naming.ClassConstantPrefix + value: '' + - key: readability-identifier-naming.ClassConstantSuffix + value: '' + - key: readability-identifier-naming.ClassMemberCase + value: camelBack + - key: readability-identifier-naming.ClassMemberPrefix + value: 'm_' + - key: readability-identifier-naming.ClassMemberSuffix + value: '' + - key: readability-identifier-naming.ClassMethodCase + value: camelBack + - key: readability-identifier-naming.ClassMethodPrefix + value: '' + - key: readability-identifier-naming.ClassMethodSuffix + value: '' + - key: readability-identifier-naming.ClassPrefix + value: '' + - key: readability-identifier-naming.ClassSuffix + value: '' + - key: readability-identifier-naming.ConstantCase + value: camelCase + - key: readability-identifier-naming.ConstantMemberCase + value: camelCase + - key: readability-identifier-naming.ConstantMemberPrefix + value: 'm_' + - key: readability-identifier-naming.ConstantMemberSuffix + value: '' + - key: readability-identifier-naming.ConstantParameterCase + value: camelCase + - key: readability-identifier-naming.ConstantParameterPrefix + value: '' + - key: readability-identifier-naming.ConstantParameterSuffix + value: '' + - key: readability-identifier-naming.ConstantPrefix + value: '' + - key: readability-identifier-naming.ConstantSuffix + value: '' + - key: readability-identifier-naming.ConstexprFunctionCase + value: camelBack + - key: readability-identifier-naming.ConstexprFunctionPrefix + value: '' + - key: readability-identifier-naming.ConstexprFunctionSuffix + value: '' + - key: readability-identifier-naming.ConstexprMethodCase + value: camelBack + - key: readability-identifier-naming.ConstexprMethodPrefix + value: '' + - key: readability-identifier-naming.ConstexprMethodSuffix + value: '' + - key: readability-identifier-naming.ConstexprVariableCase + value: camelBack + - key: readability-identifier-naming.ConstexprVariablePrefix + value: '' + - key: readability-identifier-naming.ConstexprVariableSuffix + value: '' + - key: readability-identifier-naming.EnumCase + value: CamelCase + - key: readability-identifier-naming.EnumConstantCase + value: camelBack + - key: readability-identifier-naming.EnumConstantPrefix + value: '' + - key: readability-identifier-naming.EnumConstantSuffix + value: '' + - key: readability-identifier-naming.EnumPrefix + value: '' + - key: readability-identifier-naming.EnumSuffix + value: '' + - key: readability-identifier-naming.FunctionCase + value: camelBack + - key: readability-identifier-naming.FunctionPrefix + value: '' + - key: readability-identifier-naming.FunctionSuffix + value: '' + - key: readability-identifier-naming.GlobalConstantCase + value: camelCase + - key: readability-identifier-naming.GlobalConstantPrefix + value: '' + - key: readability-identifier-naming.GlobalConstantSuffix + value: '' + - key: readability-identifier-naming.GlobalFunctionCase + value: camelBack + - key: readability-identifier-naming.GlobalFunctionPrefix + value: '' + - key: readability-identifier-naming.GlobalFunctionSuffix + value: '' + - key: readability-identifier-naming.GlobalVariableCase + value: camelBack + - key: readability-identifier-naming.GlobalVariablePrefix + value: '' + - key: readability-identifier-naming.GlobalVariableSuffix + value: '' + - key: readability-identifier-naming.IgnoreFailedSplit + value: '0' + - key: readability-identifier-naming.InlineNamespaceCase + value: CamelCase + - key: readability-identifier-naming.InlineNamespacePrefix + value: '' + - key: readability-identifier-naming.InlineNamespaceSuffix + value: '' + - key: readability-identifier-naming.LocalConstantCase + value: camelCase + - key: readability-identifier-naming.LocalConstantPrefix + value: '' + - key: readability-identifier-naming.LocalConstantSuffix + value: '' + - key: readability-identifier-naming.LocalVariableCase + value: camelBack + - key: readability-identifier-naming.LocalVariablePrefix + value: '' + - key: readability-identifier-naming.LocalVariableSuffix + value: '' + - key: readability-identifier-naming.MemberCase + value: CamelCase + - key: readability-identifier-naming.MemberPrefix + value: '' + - key: readability-identifier-naming.MemberSuffix + value: '' + - key: readability-identifier-naming.MethodCase + value: CamelCase + - key: readability-identifier-naming.MethodPrefix + value: '' + - key: readability-identifier-naming.MethodSuffix + value: '' + - key: readability-identifier-naming.NamespaceCase + value: CamelCase + - key: readability-identifier-naming.NamespacePrefix + value: '' + - key: readability-identifier-naming.NamespaceSuffix + value: '' + - key: readability-identifier-naming.ParameterCase + value: camelBack + - key: readability-identifier-naming.ParameterPackCase + value: CamelCase + - key: readability-identifier-naming.ParameterPackPrefix + value: '' + - key: readability-identifier-naming.ParameterPackSuffix + value: '' + - key: readability-identifier-naming.ParameterPrefix + value: '' + - key: readability-identifier-naming.ParameterSuffix + value: '' + - key: readability-identifier-naming.PrivateMemberCase + value: camelBack + - key: readability-identifier-naming.PrivateMemberPrefix + value: 'm_' + - key: readability-identifier-naming.PrivateMemberSuffix + value: '' + - key: readability-identifier-naming.PrivateMethodCase + value: camelBack + - key: readability-identifier-naming.PrivateMethodPrefix + value: '' + - key: readability-identifier-naming.PrivateMethodSuffix + value: '' + - key: readability-identifier-naming.ProtectedMemberCase + value: camelBack + - key: readability-identifier-naming.ProtectedMemberPrefix + value: 'm_' + - key: readability-identifier-naming.ProtectedMemberSuffix + value: '' + - key: readability-identifier-naming.ProtectedMethodCase + value: camelBack + - key: readability-identifier-naming.ProtectedMethodPrefix + value: '' + - key: readability-identifier-naming.ProtectedMethodSuffix + value: '' + - key: readability-identifier-naming.PublicMemberCase + value: camelBack + - key: readability-identifier-naming.PublicMemberPrefix + value: 'm_' + - key: readability-identifier-naming.PublicMemberSuffix + value: '' + - key: readability-identifier-naming.PublicMethodCase + value: camelBack + - key: readability-identifier-naming.PublicMethodPrefix + value: '' + - key: readability-identifier-naming.PublicMethodSuffix + value: '' + - key: readability-identifier-naming.StaticConstantCase + value: camelCase + - key: readability-identifier-naming.StaticConstantPrefix + value: '' + - key: readability-identifier-naming.StaticConstantSuffix + value: '' + - key: readability-identifier-naming.StaticVariableCase + value: camelCase + - key: readability-identifier-naming.StaticVariablePrefix + value: '' + - key: readability-identifier-naming.StaticVariableSuffix + value: '' + - key: readability-identifier-naming.StructCase + value: CamelCase + - key: readability-identifier-naming.StructPrefix + value: '' + - key: readability-identifier-naming.StructSuffix + value: '' + - key: readability-identifier-naming.TemplateParameterCase + value: CamelCase + - key: readability-identifier-naming.TemplateParameterPrefix + value: '' + - key: readability-identifier-naming.TemplateParameterSuffix + value: '' + - key: readability-identifier-naming.TemplateTemplateParameterCase + value: CamelCase + - key: readability-identifier-naming.TemplateTemplateParameterPrefix + value: '' + - key: readability-identifier-naming.TemplateTemplateParameterSuffix + value: '' + - key: readability-identifier-naming.TypeTemplateParameterCase + value: CamelCase + - key: readability-identifier-naming.TypeTemplateParameterPrefix + value: '' + - key: readability-identifier-naming.TypeTemplateParameterSuffix + value: '' + - key: readability-identifier-naming.TypedefCase + value: aNy_CasE + - key: readability-identifier-naming.TypedefPrefix + value: '' + - key: readability-identifier-naming.TypedefSuffix + value: '' + - key: readability-identifier-naming.UnionCase + value: CamelCase + - key: readability-identifier-naming.UnionPrefix + value: '' + - key: readability-identifier-naming.UnionSuffix + value: '' + - key: readability-identifier-naming.ValueTemplateParameterCase + value: CamelCase + - key: readability-identifier-naming.ValueTemplateParameterPrefix + value: '' + - key: readability-identifier-naming.ValueTemplateParameterSuffix + value: '' + - key: readability-identifier-naming.VariableCase + value: camelBack + - key: readability-identifier-naming.VariablePrefix + value: '' + - key: readability-identifier-naming.VariableSuffix + value: '' + - key: readability-identifier-naming.VirtualMethodCase + value: camelBack + - key: readability-identifier-naming.VirtualMethodPrefix + value: '' + - key: readability-identifier-naming.VirtualMethodSuffix + value: '' + - key: readability-simplify-boolean-expr.ChainedConditionalAssignment + value: '0' + - key: readability-simplify-boolean-expr.ChainedConditionalReturn + value: '0' +... diff --git a/CHANGELOG.md b/CHANGELOG.md index 40844769..1029d852 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,84 @@ +## [1.2.1] - 2023-11-15 + +### Build + + - BIFROST-9103 - Replace pxr by PXR_NS + - BIFROST-9093 - Uses cpp2json executable instead of the deprecated amino_cpp2json_foreach one. + - BIFROST-8182 - Remove -Wno-unused-macros on Windows targets + - BIFROST-8182 - Clang-tidy support: Add the cmake target "bifrost_usd_clang_tidy" to the build. + +### Feature + + - BIFROST-8077 - Add support for half and matrix attribute types + + - BIFROST-8574 - Add anchor_path parameter on add_reference_prim and add_payload_prim + + By specifying an "anchor_path", the identifier of the referenced layer will not include such anchor path in the reference list. + + - BIFROST-8424 - Add slider and color picker on ops + + - BIFROST-9008 - Add set_layer_permission node + + To be used for the very specific scenario when you need to reference a layer + that needs to be modified by an other runtime than Bifrost. + + For example, if a stage generated by Bifrost references a "file based" layer + storing some USD materials who should be authored in the LookdevX Editor, + it would not work by default. This is because in order to keep the referenced layer + "file based", the "read only" mode would need to be enabled in the open_layer node. + If not in read only mode, the opened layer ("file based" layer) would be automatically + copied into an anonymous layer by Bifrost USD (to avoid side effects) and so would not + be editable in LookdevX in a persistent way (as the layer identifier would change at + every execution of the graph). + + The node graph to open a layer in Bifrost and let it be editable outside should look as following: + open_layer (with read_only "on") -> set_layer_permission (with read_only "off") -> add_reference_prim + + The open_layer node will call the BifrostUsd::Layer constructor that is "opening or finding" the USD layer + using the file path as an identifier (and will not create an anonymous layer, because of the read only mode). + The set_layer_permission will allow the layer to be editable and will not output an anonymous layer. + + - BIFROST-8788 - Use for_each in define_usd_mesh + + - BIFROST-7769 - use getEnv*() functions from public Executor SDK + + - BIFROST-8199 - Use ConfigEnv instead of Object to get config from environment + + - BIFROST-3401 - Use new API for FileUtils::getRelativePath. + +### Bugfix + + - BIFROST-9067 - Fix connection order when creating an add_to_stage node 'on the fly' + + - BIFROST-8826 - fix random test failures on Windows + + - Layer::exportToFile() now uses SdfLayer::New() instead of CreateNew(). + This prevents a temporary and default file to be created on the disk + before the final exported file is actually written. On Windows, when + Pixar USD is writing an initial file and almost immediately attempts + to replace its content by renaming another file to such initial file, + an "access denied" error can occasionally occur; eliminating the + temporary file on the first place by not calling CreateNew() avoids + this error. + - Each unit test file now outputs its exported files into its own unique + folder, avoiding completely the possibility that two concurrent tests + from different test files would attempt to export to the same file. + These unique output folders are deleted as a first phase for each test + file, allowing tests to assume and check that an output file is not + already on disk before it is being exported. + - Some tests were previously just lucky to succeed, as they were + exporting a root layer and sublayer to disk, but the sublayer was + actually exported into the default output folder, not into the expected + folder, and since the sublayer file was already saved to disk by + another test case, the test assumed that everything went fine. Such + test cases are now fixed or were removed (if not fixable). + - Tests do not export initial files first, then replacing these by final + file content, and finally checking the final file for some expected + content. This was also occasionally causing "access denied" errors, as + described above. + - add README.md in test folder + + ## [1.2.0] - 2023-05-12 ### Build @@ -28,9 +109,9 @@ - BIFROST-8426 - Inconsistent UI in define_usd_prim - BIFROST-8273 - fix sublayers not saved if relative_path is on - - Use the layer's save file path (m_filePath) instead of the sdfLayerIdentifier in the recursive call to Layer::exportToFile(). - - Add new more complete unit test for export_layer_to_file() that covers multiple cases for relative and absolute paths to sublayers. - - removed call to changeDir() that has side effect and is not required anymore for unit tests. + - Use the layer's save file path (m_filePath) instead of the sdfLayerIdentifier in the recursive call to Layer::exportToFile(). + - Add new more complete unit test for export_layer_to_file() that covers multiple cases for relative and absolute paths to sublayers. + - removed call to changeDir() that has side effect and is not required anymore for unit tests. ## [1.1.0] - 2023-03-29 @@ -48,15 +129,12 @@ ### Feature - BIFROST-7955 - Add applied schema nodes - - add_applied_schema: This node adds the applied API schema name to the apiSchema metadata of the prim - - remove_applied_schema: This node removes the applied API schema name from the apiSchema metadata of the prim + - add_applied_schema: This node adds the applied API schema name to the apiSchema metadata of the prim + - remove_applied_schema: This node removes the applied API schema name from the apiSchema metadata of the prim ### Bugfix ## [1.0.0] - 2022-12-12 - - Initial release -- 2022-12-12 - - Initial release diff --git a/CMakeLists.txt b/CMakeLists.txt index 53b37fbe..6e06bab5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ #- #***************************************************************************** -# Copyright 2022 Autodesk, Inc. +# Copyright 2023 Autodesk, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -30,6 +30,8 @@ if( NOT BIFUSD_PACKAGE_NAME ) set(BIFUSD_PACKAGE_NAME bifrost_usd_pack) endif() +set(IS_BIFUSD_STANDALONE ON CACHE BOOL "Indicate if this is a standalone build of Bifrost USD") + include(cmake/version.info) # Enable no language yet. @@ -96,7 +98,7 @@ include(cmake/utils.cmake) # Standalone build setup the compiler # Else use the parent environment's compiler -if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) +if(IS_BIFUSD_STANDALONE) #============================================================================== # COMPILER #============================================================================== @@ -181,16 +183,41 @@ add_subdirectory(test) # # Maya if( MAYA_RUNTIME_LOCATION) - find_package( Bifrost REQUIRED Maya) + find_package(Maya REQUIRED) + find_package(Bifrost REQUIRED Maya) add_subdirectory(maya_plugin) endif() +#============================================================================== +# Bifrost Hydra +# NOT PART OF PUBLIC BIFROST SDK YET +# NOT PART OF PUBLIC BIFROST SDK YET +# NOT PART OF PUBLIC BIFROST SDK YET +#============================================================================== +# +if( BIFUSD_BUILD_HYDRA ) + add_subdirectory(bifrost_hydra) +endif() + +#============================================================================== +# Configure "clang_tidy" target +#============================================================================== +# +if( CLAND_TIDY_LOCATION ) + include(${BIFUSD_TOOLS_DIR}/clang-tidy.cmake) + bifrost_usd_clang_tidy() +endif() + #============================================================================== # FINALIZE #============================================================================== -# Publish the findUSD module helper +# Publish the CMake module files install( FILES ${BIFUSD_CMAKE_DIR}/modules/FindUSD.cmake DESTINATION ${BIFUSD_INSTALL_CMAKE_DIR}/modules ) +install( + FILES ${BIFUSD_CMAKE_DIR}/modules/FindMaya.cmake + DESTINATION ${BIFUSD_INSTALL_CMAKE_DIR}/modules ) + include( ${BIFUSD_TOOLS_DIR}/finalize.cmake) diff --git a/README.md b/README.md index b707c162..efa8d5fe 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,11 @@ To build doxygen doc (require doxygen 1.8.14): cmake --build --target usd_pack_apidoc ``` +To run clang-tidy +``` +cmake --build --target bifrost_usd_clang_tidy +``` + ## Testing ``` diff --git a/bifrost_hydra/CMakeLists.txt b/bifrost_hydra/CMakeLists.txt new file mode 100644 index 00000000..4b654c29 --- /dev/null +++ b/bifrost_hydra/CMakeLists.txt @@ -0,0 +1,25 @@ +#- +#***************************************************************************** +# Copyright 2023 Autodesk, Inc. +# +# 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. +#***************************************************************************** +#+ + +if(IS_BIFUSD_STANDALONE) + include(${BIFROST_LOCATION}/sdk_preview/cmake/setup.cmake) +endif() +find_package(BifrostPreview REQUIRED SDK) + +add_subdirectory(src) +add_subdirectory(test) diff --git a/bifrost_hydra/README.md b/bifrost_hydra/README.md new file mode 100644 index 00000000..3e589804 --- /dev/null +++ b/bifrost_hydra/README.md @@ -0,0 +1,48 @@ + +## Bifrost Hydra (Experimental) +Requires a version of the Bifrost SDK that is not released yet. +Register a new Hydra Generative Procedural plugin capable of running a Bifrost Graph that will output +Bifrost geometries to the Hydra Scene Index without using any scene delegate. +In your Hydra based application (usdview for example), the following variables are needed: +``` +export BIFROST_LOCATION= +export BIFROST_LIB_CONFIG_FILES=/bifrost_hydra_translation.json +export HD_ENABLE_SCENE_INDEX_EMULATION=1 +export USDIMAGINGGL_ENGINE_ENABLE_SCENE_INDEX=1 +export HDGP_INCLUDE_DEFAULT_RESOLVER=1 +``` + +Here is a USD file example showing how to setup the Generative Procedural for Bifrost. +``` +#usda 1.0 +( +def Xform "Mia" +{ + def "Head" ( + prepend references = @mia_young.usd@ + ) + { + } + + def GenerativeProcedural "BifrostGraph" ( + prepend apiSchemas = ["HydraGenerativeProceduralAPI"] + ) + { + # The Generative Procedural Plugin name + token primvars:hdGp:proceduralType = "BifrostGraph" + + # The full name of the Bifrost compound or graph to execute in Hydra + token primvars:bifrost:graph = "Groom::create_clumpy_hairs" + + # The inputs parameters must use the same names as the Bifrost + # compound input ports with an additional "primvars:" prefix + prepend rel primvars:mesh = + float primvars:hair_count = 9000000 + float primvars:curl_frequency = 6.5 + + # The output of the Bifrost compound you want to render in Hydra + string primvars:bifrost:output = "hairs" + } +} +``` +There are several USD files in `test/BifrostHydra/resources` following such setup. diff --git a/bifrost_hydra/src/BifrostHdEngine/CMakeLists.txt b/bifrost_hydra/src/BifrostHdEngine/CMakeLists.txt new file mode 100644 index 00000000..fb3799ea --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/CMakeLists.txt @@ -0,0 +1,78 @@ +#- +#***************************************************************************** +# Copyright 2023 Autodesk, Inc. +# +# 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. +#***************************************************************************** +#+ + +set(hd_Engine_headers + Container.h + Engine.h + JobTranslationData.h + Parameters.h + Requirement.h + Runtime.h + ValueTranslationData.h +) + +bifusd_install_headers( + hdEngineHeadersInstall + SOURCE ${CMAKE_CURRENT_SOURCE_DIR} + FILES ${hd_Engine_headers} + DESTINATION "BifrostHydra/Engine" +) + +set(public_libs + Amino::SDK::Preview + BifrostGraph::Executor::Preview + hdEngineHeadersInstall +) + +set(private_libs + Amino::Core + Bifrost::Object + hd + BifrostHdTranslators +) + +set(src_files + Container.cpp + Engine.cpp + JobTranslationData.cpp + Parameters.cpp + Requirement.cpp + Runtime.cpp + ValueTranslationData.cpp +) + +bifusd_set_extra_rpaths(extra_rpaths) + +bifusd_create_shared_lib( + BifrostHdEngine "BIFROST_HD_ENGINE_BUILD_DLL" # TODO: add export file + PUBLIC_INSTALL + PUBLIC_DEFINITIONS $<${BIFUSD_IS_MSC}: BOOST_LIB_TOOLSET="vc141"> + PRIVATE_DEFINITIONS $<${BIFUSD_IS_DEBUG}: TBB_USE_DEBUG BOOST_DEBUG_PYTHON BOOST_LINKING_PYTHON> + + PRIVATE_OPTIONS $<${BIFUSD_IS_MSC}:/wd4251 /wd4273> + $<${BIFUSD_IS_GCC}: -Wno-deprecated -Wno-unused-macros> + $<${BIFUSD_IS_CLANG}: -Wno-deprecated -Wno-unused-macros> + + SRC_FILES ${src_files} + PUBLIC_LINK_LIBS ${public_libs} + PRIVATE_LINK_LIBS ${private_libs} + EXTRA_RPATH ${extra_rpaths} +) + +add_subdirectory(translation) +add_subdirectory(config) diff --git a/bifrost_hydra/src/BifrostHdEngine/Container.cpp b/bifrost_hydra/src/BifrostHdEngine/Container.cpp new file mode 100644 index 00000000..67c93190 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/Container.cpp @@ -0,0 +1,111 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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 + +#include + +namespace BifrostHd { + +Container::Container() : BifrostBoardContainer(&Runtime::Get()), m_job(this) {} + +Container::~Container() = default; + +/* static */ +Runtime& Container::GetRuntime() { return Runtime::Get(); } + +BifrostBoardJob::Requirement* Container::createEvaluationRequirement( + const Amino::String& name, + Amino::PortDescription::PortDirection direction, + const Amino::Type& type, + BifrostGraph::Executor::TypeTranslation::PortClass portClass) const { + Amino::Value defaultVal; + Amino::PortDescription portDesc; + if (getGraph().getPorts().findByName(name, portDesc)) { + defaultVal = portDesc.value(); + } + + return new Requirement(name, direction, type, portClass, defaultVal); +} + +bool Container::initialize() { + // The nullptr pointer used for update() will get passed to portAdded() + // in the translation table, which is only called for each Job Port. + // Job Ports are global state ports, such as for time information. + // For now TypeTranslation::portAdded() does nothing, so the + // pointer can be nullptr. + auto status = + m_job.update(nullptr, BifrostBoardJob::CompileSwitch::kCompile); + + // See BIFROST-3651. + if (status == Amino::SetGraphStatus::Value::kFailure) { + std::cout << "Failed initializing job.\n"; + std::cout + << "This is most likely due to an input or output port being\n"; + std::cout << "set to type 'auto'. In order to run Bifrost compounds\n"; + std::cout + << "outside of Maya, all ports must have a set type such as\n"; + std::cout << "float or Object or double3 etc. If using Bifrost\n"; + std::cout + << "for Maya, you can easily check this by visually inspecting\n"; + std::cout + << "the ports on the compound you are attempting to run here.\n"; + std::cout + << "Any port with a vertical bar indicates an 'auto' port, and\n"; + std::cout + << "you can fix the issue by right-clicking and setting it to \n"; + std::cout << "an explicit type." << std::endl; + + return false; + } + + // populateRequirements() needs the list of exposed Terminals, + // those at root level or those that are wrapped within compounds. + // Update this list of exposed Terminals by retrieving the Terminals + // from the job to execute: +#if 1 + // workaround until BIFROST-6157 gets done: use a temporary + // GraphResolver to retrieve the Terminals: + Amino::GraphResolver resolver; + resolver.setGraph(m_job.aminoJob().getGraph()); + const Amino::GraphResolver::CompoundResolution::Terminals& resolvedTerms = + resolver.getCompoundResolution().getTerminals(); + updateExposedTerminals(&resolvedTerms); +#else + // When BIFROST-6157 will be done, we expect being able to query the + // terminals from the Amino::Job, and it would return the same type + // as GraphResolver::CompoundResolution::getTerminals() returns. + updateExposedTerminals(m_job.aminoJob().getTerminals()); +#endif + + // Fill the EvaluationRequirements structures in the job. This allows us + // to examine the job inputs and outputs. + m_job.populateRequirements(); + + return true; +} + +bool Container::updateJob() { + return m_job.update(nullptr, BifrostBoardJob::CompileSwitch::kCompile) != + BifrostBoardJob::EvaluationStatus::kFailure; +} + +Amino::Job::State Container::executeJob(JobTranslationData& translationData) { + return m_job.execute(&translationData, + BifrostBoardJob::ExecuteFlags::kDefault); +} + +} // namespace BifrostHd diff --git a/bifrost_hydra/src/BifrostHdEngine/Container.h b/bifrost_hydra/src/BifrostHdEngine/Container.h new file mode 100644 index 00000000..b626e366 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/Container.h @@ -0,0 +1,64 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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. +//+ + +#ifndef BIFROST_USD_ENGINE_CONTAINER_H_ +#define BIFROST_USD_ENGINE_CONTAINER_H_ + +#include +#include +#include + +#include + +namespace BifrostHd { + +class Container final : public BifrostBoardContainer { +public: + explicit Container(); + ~Container() override; + + static Runtime& GetRuntime(); + + BifrostBoardJob::Requirement* createEvaluationRequirement( + const Amino::String& name, + Amino::PortDescription::PortDirection direction, + const Amino::Type& type, + BifrostGraph::Executor::TypeTranslation::PortClass portClass) + const override; + + bool initialize(); + + /// \brief Init the evaluation job + /// \return True if initialization was successful, false otherwise + bool updateJob(); + + Amino::Job::State executeJob(JobTranslationData& translationData); + +public: + /// Disabled + /// \{ + Container(const Container&) = delete; + Container(Container&&) = delete; + Container& operator=(const Container&) = delete; + Container& operator=(Container&&) = delete; + /// \} + +private: + BifrostBoardJob m_job; +}; + +} // namespace BifrostHd +#endif // BIFROST_USD_ENGINE_CONTAINER_H_ diff --git a/bifrost_hydra/src/BifrostHdEngine/Engine.cpp b/bifrost_hydra/src/BifrostHdEngine/Engine.cpp new file mode 100644 index 00000000..41301179 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/Engine.cpp @@ -0,0 +1,92 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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 + +#include +#include +#include + +namespace BifrostHd { + +class Engine::Impl { +public: + Impl() = default; + + Amino::Job::State execute(const double frame) { + auto qualifiedName = Amino::String{m_parameters.compoundName().c_str()}; + + // Since for now we can't change the graph at runtime (no Bifrost Graph + // Editor "attached" to our runtime), loading of the graph should happen + // just once. Then, the user can only change input values so we only + // need execution. + if (m_container.graphExecutionCounter() == 0) { + if (!m_container.loadGraph( + qualifiedName, + BifrostBoardContainer::GraphMode::kLoadAsReference)) { + return Amino::Job::State::kErrors; + } + if (!m_container.updateJob()) { + return Amino::Job::State::kErrors; + } + } + + + const double currentTime = frame / m_fps; + const double frameLength = 1.0 / m_fps; + + BifrostHd::JobTranslationData jobTranslationData{ + m_parameters, + /*logVerbose*/ true, + /*Time data*/ {currentTime, frame, frameLength}}; + return m_container.executeJob(jobTranslationData); + } + + void setInputScene(PXR_NS::HdSceneIndexBaseRefPtr inputScene) { + m_parameters.setInputScene(std::move(inputScene)); + } + + void setInputs(PXR_NS::HdSceneIndexPrim const& prim) { + m_parameters.setInputs(prim); + } + + const Output& output() { return m_parameters.output(); } + +private: + double m_fps{24.0}; + Parameters m_parameters; + BifrostHd::Container m_container; +}; + +Engine::Engine() : m_impl(std::make_unique()) {} + +Engine::~Engine() = default; + +void Engine::setInputScene(PXR_NS::HdSceneIndexBaseRefPtr inputScene) { + m_impl->setInputScene(std::move(inputScene)); +} + +void Engine::setInputs(PXR_NS::HdSceneIndexPrim const& prim) { + m_impl->setInputs(prim); +} + +Amino::Job::State Engine::execute(const double frame) { + return m_impl->execute(frame); +} + +const Output& Engine::output() { return m_impl->output(); } + +} // namespace BifrostHd diff --git a/bifrost_hydra/src/BifrostHdEngine/Engine.h b/bifrost_hydra/src/BifrostHdEngine/Engine.h new file mode 100644 index 00000000..1c4ca153 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/Engine.h @@ -0,0 +1,66 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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. +//+ + +#ifndef BIFROST_HD_ENGINE_H +#define BIFROST_HD_ENGINE_H + +#include +#include + +#include + +#include + +namespace BifrostHd { + +/// \class Engine +/// +/// Interface to access the Bifrost Graph and parameters stored +/// in a HdSceneIndexPrim of type hydraGenerativeProcedural +/// + +using Output = + std::pair>>; + +class Engine { +public: + Engine(); + + ~Engine(); + + void setInputScene(PXR_NS::HdSceneIndexBaseRefPtr inputScene); + void setInputs(PXR_NS::HdSceneIndexPrim const& prim); + + Amino::Job::State execute(const double frame = 0); + const Output& output(); + +public: + /// Disabled + /// \{ + Engine(const Engine&) = delete; + Engine(Engine&&) = delete; + Engine& operator=(const Engine&) = delete; + Engine& operator=(Engine&&) = delete; + /// \} + +private: + class Impl; + std::unique_ptr m_impl; +}; + +} // namespace BifrostHd + +#endif // BIFROST_HD_ENGINE_H diff --git a/bifrost_hydra/src/BifrostHdEngine/JobTranslationData.cpp b/bifrost_hydra/src/BifrostHdEngine/JobTranslationData.cpp new file mode 100644 index 00000000..0bd42315 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/JobTranslationData.cpp @@ -0,0 +1,54 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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 + +#include + +namespace BifrostHd { + +class JobTranslationData::Impl { +public: + Impl(bool logVerbose, Time const& time, Parameters& params) + : m_logVerbose(logVerbose), m_time(time), m_params(params) { + (void)m_logVerbose; + } + + JobTranslationData::Time getTime() const { return m_time; } + Parameters& getParameters() { return m_params; } + +private: + bool const m_logVerbose; + Time m_time; + Parameters& m_params; +}; + +JobTranslationData::JobTranslationData(Parameters& params, + bool logVerbose, + Time const& time) + : BifrostBoardJob::JobTranslationData(), + m_impl(std::make_unique(logVerbose, time, params)) {} + +JobTranslationData::~JobTranslationData() = default; + +JobTranslationData::Time JobTranslationData::getTime() const { + return m_impl->getTime(); +} + +Parameters& JobTranslationData::getParameters() { + return m_impl->getParameters(); +} +} // namespace BifrostHd diff --git a/bifrost_hydra/src/BifrostHdEngine/JobTranslationData.h b/bifrost_hydra/src/BifrostHdEngine/JobTranslationData.h new file mode 100644 index 00000000..bbd2bb71 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/JobTranslationData.h @@ -0,0 +1,60 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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. +//+ + +#ifndef BIFROST_HD_ENGINE_JOB_TRANSLATION_DATA_H +#define BIFROST_HD_ENGINE_JOB_TRANSLATION_DATA_H + +#include + +#include + +namespace BifrostHd { + +class Parameters; + +class JobTranslationData final : public BifrostBoardJob::JobTranslationData { +public: + struct Time { + double currentTime; + double currentFrame; + double frameLength; + }; + + JobTranslationData(Parameters& params, bool logVerbose, Time const& time); + + ~JobTranslationData() override; + + Time getTime() const; + + Parameters& getParameters(); + +public: + /// Disabled + /// \{ + JobTranslationData(const JobTranslationData&) = delete; + JobTranslationData(JobTranslationData&&) = delete; + JobTranslationData& operator=(const JobTranslationData&) = delete; + JobTranslationData& operator=(JobTranslationData&&) = delete; + /// \} + +private: + class Impl; + std::unique_ptr m_impl; +}; + +} // namespace BifrostHd + +#endif // BIFROST_HD_ENGINE_JOB_TRANSLATION_DATA_H diff --git a/bifrost_hydra/src/BifrostHdEngine/Parameters.cpp b/bifrost_hydra/src/BifrostHdEngine/Parameters.cpp new file mode 100644 index 00000000..3b20f742 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/Parameters.cpp @@ -0,0 +1,110 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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 + +#include + +namespace BifrostHd { + +class Parameters::Impl { +public: + Impl() = default; + + ~Impl() = default; + + void setInputScene(PXR_NS::HdSceneIndexBaseRefPtr inputScene) { + m_inputScene = std::move(inputScene); + } + + PXR_NS::HdSceneIndexBaseRefPtr inputScene() const { + return m_inputScene; + } + + void setInputs(PXR_NS::HdSceneIndexPrim const& prim) { + auto primvarSchema = + PXR_NS::HdPrimvarsSchema::GetFromParent(prim.dataSource); + + for (const auto& name : primvarSchema.GetPrimvarNames()) { + if (name == "hdGp:proceduralType") { + continue; + } + + if (auto dataSource = + primvarSchema.GetPrimvar(name).GetPrimvarValue()) { + auto value = dataSource->GetValue(0.0f); + if (name == "bifrost:graph") { + if (value.IsHolding()) { + const auto& graphName = value.UncheckedGet(); + m_compound_name = graphName.GetText(); + } + } else if (name == "bifrost:output") { + if (value.GetTypeName() == "string") { + auto output_name = value.UncheckedGet(); + auto objectArray = Amino::Array>(); + m_output = std::make_pair(output_name, objectArray); + } + } else { + m_inputs[name.GetText()] = dataSource->GetValue(0.0f); + } + } + } + } + + const std::string& compoundName() const { return m_compound_name; } + + const Inputs& inputs() const { return m_inputs; } + + Output& output() { return m_output; } + +public: + /// Disabled + /// \{ + Impl(const Impl&) = delete; + Impl(const Impl&&) = delete; + Impl& operator=(const Impl&) = delete; + Impl& operator=(const Impl&&) = delete; + /// \} + +private: + std::string m_compound_name; + PXR_NS::HdSceneIndexBaseRefPtr m_inputScene; + Inputs m_inputs; + Output m_output; +}; + +Parameters::Parameters() : m_impl(std::make_unique()) {} + +Parameters::~Parameters() = default; + +PXR_NS::HdSceneIndexBaseRefPtr Parameters::inputScene() const { + return m_impl->inputScene(); +} +void Parameters::setInputScene(PXR_NS::HdSceneIndexBaseRefPtr inputScene) { + m_impl->setInputScene(std::move(inputScene)); +} + +void Parameters::setInputs(PXR_NS::HdSceneIndexPrim const& prim) { + m_impl->setInputs(prim); +} + +const std::string& Parameters::compoundName() const { return m_impl->compoundName(); } + +const Inputs& Parameters::inputs() const { return m_impl->inputs(); } + +Output& Parameters::output() { return m_impl->output(); } + +} // namespace BifrostHd diff --git a/bifrost_hydra/src/BifrostHdEngine/Parameters.h b/bifrost_hydra/src/BifrostHdEngine/Parameters.h new file mode 100644 index 00000000..129ec2af --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/Parameters.h @@ -0,0 +1,72 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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. +//+ + +#ifndef BIFROST_HD_PARAMETERS_H +#define BIFROST_HD_PARAMETERS_H + +#include + +#include + +#include +#include + +namespace BifrostHd { + +using Inputs = std::unordered_map; +using Output = std::pair>>; + +/// \class Parameters +/// +/// Interface to access the Bifrost Graph and parameters stored +/// in a HdSceneIndexPrim of type hydraGenerativeProcedural +/// + +class Parameters { +public: + Parameters(); + + ~Parameters(); + + void setInputScene(PXR_NS::HdSceneIndexBaseRefPtr inputScene); + + PXR_NS::HdSceneIndexBaseRefPtr inputScene() const; + + void setInputs(PXR_NS::HdSceneIndexPrim const& prim); + + const std::string& compoundName() const; + + const Inputs& inputs() const; + + Output& output(); + +public: + /// Disabled + /// \{ + Parameters(const Parameters&) = delete; + Parameters(Parameters&&) = delete; + Parameters& operator=(const Parameters&) = delete; + Parameters& operator=(Parameters&&) = delete; + /// \} + +private: + class Impl; + std::unique_ptr m_impl; +}; + +} // namespace BifrostHd + +#endif // BIFROST_HD_PARAMETERS_H diff --git a/bifrost_hydra/src/BifrostHdEngine/README.md b/bifrost_hydra/src/BifrostHdEngine/README.md new file mode 100644 index 00000000..7d188c51 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/README.md @@ -0,0 +1,67 @@ +# Bifrost Hydra Engine - Executing Bifrost at Hydra Render time + +The BifrostHdEngine library is responsible for: +1. Loading specific definitions (the jsons files describing nodes, compounds, types, etc.) into the Bifrost runtime +2. Loading a graph (a graph can be a Bifrost compound or a Bifrost graph) +3. Setting the graph inputs using USD primvars matching their names +4. Executing the graph +5. Accessing to the result, that is the output(s) of the graph + +## Engine + +The _BifrostHd::Engine_ is instanciated by the _Bifrost Hydra Generative Procedural_. +Its purpose is to simplify the setup of Bifrost at render time, hidding configuration steps, loading of the graph, setting of the inputs, etc. + +It is providing four methods: +1. _setInputScene(PXR_NS::HdSceneIndexBaseRefPtr inputScene)_ +2. _setInputs(PXR_NS::HdSceneIndexPrim const& prim)_ // the Hydra Generative Procedural prim. +3. _execute(const double frame)_ +4. _output()_ + +## Container + +The _BifrostHd::Container_ is the entry point. It is a specialized version of the _BifrostBoardContainer_. See _\/plug-ins/bifrost/sdk/include/bifrostboard_executor/BifrostBoardContainer.h_ for more info. + + _BifrostHd::Container_ implements a very limited set of functionality at the moment since we only need to load a graph, set its inputs and execute at Hydra render time. +So at the moment it does: + +1. _loadGraph_ : Load a graph into the container +2. _updateJob_ : Create the BifrostBoardJob and attach the loaded graph to it +3. _executeJob_ : Let the BifrostBoardJob execute the loaded graph + +For info, the _BifrostBoardContainer_ got a richer API than that for applications who would like to allow authoring of the graph. + +## Parameters + +The _BifrostHd::Parameters_ stores the _Pixar VtValues_ comming from the Hydra Generative Procedural of type _BifrostGraph_ that are: +1. The name of the Bifrost graph +2. The primvars used to the set the graph inputs +3. The Bifrost output of the graph you want to render in Hydra + +## JobTranslationData + +The _BifrostHd::JobTranslationData_ is an object that is used by the _BifrostHd::Container_ to pass the time and parameters +to Bifrost while executing a graph. + +## Requirement + +The _BifrostHd::Requirement_ describes the name, direction, type and port type for a given input or output of the graph. +It is created by the _BifrostHd::Container_. It is used internally to cache the input value. + +## Runtime + +The _BifrostHd::Runtime_ is responsible for loading the definition files. It is finding so called "json config files" using the +environment variable _BIFROST_LIB_CONFIG_FILES_ that can points to several json files at differents locations. +For example, in our tests, we load the following json config file _${BIFROST_LOCATION}/resources/standalone_config.json_ +and _bifrost-usd/test/BifrostHydra/test_bif_geo_compounds_config.json_ that is loading +the usual Bifrost nodes and compounds plus extra compounds only used by the tests. + +## ValueTranslationData + +The _BifrostHd::ValueTranslationData_ is used by the translation system to convert a Pixar _VtValue_ to an _Amino::Value_ +(a Bifrost graph set its inputs using Amino Values). + +## TypeTranslation + +At graph execution, for each input values, the _BifrostHd::TypeTranslation_ will call _convertValueFromHost_ that will use a _BifrostHd::ValueTranslationData_ to do the conversion. +For each output values, it will call _convertValueToHost_ to set the output of the graph. Note that at the moment, the output is a Bifrost object and the transaltion to an Hydra prim is done in the _Bifrost Hydra Generative Procedural_. Such design could change since it could convert the output value to an Hydra Data Source Container instead. diff --git a/bifrost_hydra/src/BifrostHdEngine/Requirement.cpp b/bifrost_hydra/src/BifrostHdEngine/Requirement.cpp new file mode 100644 index 00000000..f54773a7 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/Requirement.cpp @@ -0,0 +1,48 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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 + +#include +#include + +namespace BifrostHd { + +Requirement::Requirement( + const Amino::String& name, + Amino::PortDescription::PortDirection direction, + const Amino::Type& type, + BifrostGraph::Executor::TypeTranslation::PortClass portClass, + Amino::Value defaultValue) + : BifrostBoardJob::Requirement(name, direction, type, portClass), + m_defaultVal(std::move(defaultValue)) {} + +void Requirement::translate( + BifrostBoardRuntime const* runtime, + Amino::Job const& job, + BifrostBoardJob::JobTranslationData* translationData) const { + // Override so we can create the value translation data on the stack + assert(dynamic_cast(translationData)); + + ValueTranslationData valueTranslationData( + *static_cast(translationData), m_defaultVal, + m_name.c_str()); + + BifrostBoardJob::Requirement::translate(runtime, job, + &valueTranslationData); +} + +} // namespace BifrostHd diff --git a/bifrost_hydra/src/BifrostHdEngine/Requirement.h b/bifrost_hydra/src/BifrostHdEngine/Requirement.h new file mode 100644 index 00000000..84c34bb4 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/Requirement.h @@ -0,0 +1,53 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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. +//+ + +#ifndef BIFROST_HD_ENGINE_REQUIREMENT_H_ +#define BIFROST_HD_ENGINE_REQUIREMENT_H_ + +#include + +namespace BifrostHd { + +class Requirement final : public BifrostBoardJob::Requirement { +public: + Requirement(const Amino::String& name, + Amino::PortDescription::PortDirection direction, + const Amino::Type& type, + BifrostGraph::Executor::TypeTranslation::PortClass portClass, + Amino::Value defaultValue); + + ~Requirement() override = default; + + void translate( + BifrostBoardRuntime const* runtime, + Amino::Job const& job, + BifrostBoardJob::JobTranslationData* translationData) const override; + +public: + /// Disabled + /// \{ + Requirement(Requirement const&) = delete; + Requirement(Requirement&&) = delete; + Requirement& operator=(const Requirement&) = delete; + Requirement& operator=(Requirement&&) = delete; + /// \} + +private: + Amino::Value m_defaultVal; ///< Default value to use if none is set in input +}; + +} // namespace BifrostHd +#endif // BIFROST_HD_ENGINE_REQUIREMENT_H_ diff --git a/bifrost_hydra/src/BifrostHdEngine/Runtime.cpp b/bifrost_hydra/src/BifrostHdEngine/Runtime.cpp new file mode 100644 index 00000000..40be642e --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/Runtime.cpp @@ -0,0 +1,66 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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 + +#include +#include +#include + +namespace { +std::unique_ptr g_runtime; +Amino::StringList g_messages; +} // namespace + +namespace BifrostHd { + +Runtime::Runtime() : BifrostBoardRuntime("BifrostHd") {} + +Runtime::~Runtime() = default; + +/* static */ +bool Runtime::IsValid() { return g_runtime.get(); } + +/* static */ +Runtime& Runtime::Get() { + if (!g_runtime) { + g_runtime = std::make_unique(); + BifrostGraph::Executor::Utility::ConfigEnv config; + if (BifrostGraph::Executor::Utility::getConfigFromEnvironment(config)) { + const auto& configFiles = config.value("bifrost_pack_config_files"); + if (configFiles.size() > 0) { + g_runtime->loadConfigFiles(configFiles); + } + } + } + + return *g_runtime; +} + +void Runtime::reportMessage(Amino::MessageCategory /*category*/, + Amino::String const& message) const { + std::string runtime_msg{"[Runtime] "}; + runtime_msg += message.c_str(); + g_messages.add(runtime_msg.c_str()); +} + +bool Runtime::hasMessages() const { return g_messages.size() > 0u; } + +Amino::StringList const& Runtime::getMessages() const { return g_messages; } + +void Runtime::clearMessages() { g_messages = Amino::StringList(); } + +} // namespace BifrostHd diff --git a/bifrost_hydra/src/BifrostHdEngine/Runtime.h b/bifrost_hydra/src/BifrostHdEngine/Runtime.h new file mode 100644 index 00000000..7686913c --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/Runtime.h @@ -0,0 +1,55 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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. +//+ + +#ifndef BIFROST_HD_ENGINE_RUNTIME_H_ +#define BIFROST_HD_ENGINE_RUNTIME_H_ + +#include + +namespace BifrostHd { + +class Runtime final : public BifrostBoardRuntime { +public: + Runtime(); + ~Runtime() override; + + static bool IsValid(); + + explicit operator bool() const { return IsValid(); } + + static Runtime& Get(); + + void reportMessage(Amino::MessageCategory category, + Amino::String const& message) const override; + + bool hasMessages() const; + + Amino::StringList const& getMessages() const; + + void clearMessages(); + +public: + /// Disabled + /// \{ + Runtime(Runtime const&) = delete; + Runtime(Runtime&&) = delete; + Runtime& operator=(const Runtime&) = delete; + Runtime& operator=(Runtime&&) = delete; + /// \} +}; + +} // namespace BifrostHd +#endif // BIFROST_HD_ENGINE_RUNTIME_H_ diff --git a/bifrost_hydra/src/BifrostHdEngine/ValueTranslationData.cpp b/bifrost_hydra/src/BifrostHdEngine/ValueTranslationData.cpp new file mode 100644 index 00000000..482ba4fe --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/ValueTranslationData.cpp @@ -0,0 +1,124 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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 + +#include +#include +#include + +#include +#include + +#include +#include "pxr/imaging/hd/tokens.h" + +namespace { +bool IsOneDimentionArrayType(Amino::Type const& type) { + if (type.getTypeKind() == Amino::TypeKind::eArray) { + Amino::ArrayType arrayType(type); + return arrayType.getElementType().getTypeKind() != + Amino::TypeKind::eArray; + } + return false; +} + +} // namespace + +namespace BifrostHd { + +ValueTranslationData::ValueTranslationData( + JobTranslationData& jobTranslationData, + Amino::Value defaultVal, + std::string name) + : BifrostBoardJob::ValueTranslationData(Amino::MetadataItem()), + m_defaultVal(std::move(defaultVal)), + m_jobTranslationData(jobTranslationData), + m_name(std::move(name)) {} + +ValueTranslationData::~ValueTranslationData() = default; + +Amino::Value ValueTranslationData::getInput(Amino::Type const& type) const { + const auto& inputs = m_jobTranslationData.getParameters().inputs(); + const auto& inputScene = m_jobTranslationData.getParameters().inputScene(); + + auto search = inputs.find(m_name); + if (search != inputs.end()) { + const auto& vtValue = search->second; + + if (vtValue.IsHolding()) { + return Amino::Value{vtValue.UncheckedGet()}; + } else if (vtValue.IsHolding()) { + return Amino::Value{vtValue.UncheckedGet()}; + } else if (vtValue.IsHolding()) { + return Amino::Value{vtValue.UncheckedGet()}; + } else if (vtValue.IsHolding()) { + return Amino::Value{vtValue.UncheckedGet()}; + } else if (vtValue.IsHolding()) { + auto gf3 = vtValue.UncheckedGet(); + Bifrost::Math::float3 flt3{gf3[0], gf3[1], gf3[2]}; + Amino::StructValue val{type}; + val.read(flt3); + return val; + } else if (vtValue.IsHolding()) { + return Amino::Value{static_cast( + vtValue.UncheckedGet())}; + } else if (vtValue.IsHolding()) { + return Amino::Value{vtValue.UncheckedGet().c_str()}; + } else if (vtValue.IsHolding>()) { + auto paths = vtValue.UncheckedGet>(); + if (paths.size() == 1) { + auto sourceMeshPrim = inputScene->GetPrim(paths[0]); + if (sourceMeshPrim.primType == PXR_NS::HdPrimTypeTokens->mesh) { + auto obj = BifrostHd::CreateBifrostMesh(sourceMeshPrim); + if (obj) { + return Amino::Value{obj, type}; + } + } + } + } + } + return m_defaultVal; +} + +bool ValueTranslationData::setOutput(const Amino::Value& value) { + auto& output = m_jobTranslationData.getParameters().output(); + if (output.first == m_name) { + if (IsOneDimentionArrayType(value.getType())) { + auto objectArray = value.getArray>(); + assert(objectArray != nullptr); + if (objectArray != nullptr && !objectArray->empty()) { + for (auto& object : *objectArray) { + output.second.push_back(object); + } + return true; + } + } else { + auto object = Amino::static_pointer_cast( + value.getAminoClass()); + if (object) { + output.second.push_back(object); + return true; + } + } + } + return false; +} + +const JobTranslationData& ValueTranslationData::jobTranslationData() const { + return m_jobTranslationData; +} +} // namespace BifrostHd diff --git a/bifrost_hydra/src/BifrostHdEngine/ValueTranslationData.h b/bifrost_hydra/src/BifrostHdEngine/ValueTranslationData.h new file mode 100644 index 00000000..a1ac855f --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/ValueTranslationData.h @@ -0,0 +1,56 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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. +//+ + +#ifndef BIFROST_HD_ENGINE_TRANSLATION_DATA_H +#define BIFROST_HD_ENGINE_TRANSLATION_DATA_H + +#include + +namespace BifrostHd { + +class JobTranslationData; + +class ValueTranslationData final + : public BifrostBoardJob::ValueTranslationData { +public: + ValueTranslationData(JobTranslationData& jobTranslationData, + Amino::Value defaultVal, + std::string name); + ~ValueTranslationData() override; + + Amino::Value getInput(Amino::Type const& type) const; + bool setOutput(const Amino::Value& value); + + const JobTranslationData& jobTranslationData() const; + +public: + /// Disabled + /// \{ + ValueTranslationData(const ValueTranslationData&) = delete; + ValueTranslationData(ValueTranslationData&&) = delete; + ValueTranslationData& operator=(const ValueTranslationData&) = delete; + ValueTranslationData& operator=(ValueTranslationData&&) = delete; + /// \} + +private: + Amino::Value m_defaultVal; + JobTranslationData& m_jobTranslationData; + std::string m_name; +}; + +} // namespace BifrostHd + +#endif // BIFROST_HD_ENGINE_TRANSLATION_DATA_H diff --git a/bifrost_hydra/src/BifrostHdEngine/config/CMakeLists.txt b/bifrost_hydra/src/BifrostHdEngine/config/CMakeLists.txt new file mode 100644 index 00000000..9d8dc30a --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/config/CMakeLists.txt @@ -0,0 +1,29 @@ +#- +#***************************************************************************** +# Copyright 2023 Autodesk, Inc. +# +# 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. +#***************************************************************************** +#+ + +set( bifrost_hydra_json_tpl ${BIFUSD_OUTPUT_ROOT_DIR}/bifrost_hydra_translation.json.tpl ) +set( bifrost_hydra_json ${BIFUSD_OUTPUT_ROOT_DIR}/bifrost_hydra_translation.json ) + +# Substitute version information. +# See bifrost_hydra_translation.json.in file +configure_file(bifrost_hydra_translation.json.in ${bifrost_hydra_json_tpl} @ONLY ) + +# Substitute location of libs - only ${xyz} vars remain after the previous step. +# See bifrost_hydra_translation.json.in file +configure_file(${bifrost_hydra_json_tpl} ${bifrost_hydra_json} ) +install(FILES ${bifrost_hydra_json} DESTINATION ${BIFUSD_INSTALL_ROOT_DIR} ) diff --git a/bifrost_hydra/src/BifrostHdEngine/config/bifrost_hydra_translation.json.in b/bifrost_hydra/src/BifrostHdEngine/config/bifrost_hydra_translation.json.in new file mode 100644 index 00000000..ce1a007a --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/config/bifrost_hydra_translation.json.in @@ -0,0 +1,18 @@ +{ + "AminoConfigurations": [ + { + "vendorName": "Autodesk", + "libraryVersion": "", + "libraryDependencies": [ "bif" ], + "libraryName": "bifrostHdTypeTranslation", + "typesTranslationlibs": [ + { + "path": "${BIFROST_USD_CONFIG_SHARED_LIB}", + "files": [ + "BifrostHdTypeTranslation_@BIFUSD_MAJOR_VERSION@_@BIFUSD_MINOR_VERSION@" + ] + } + ] + } + ] +} diff --git a/bifrost_hydra/src/BifrostHdEngine/translation/CMakeLists.txt b/bifrost_hydra/src/BifrostHdEngine/translation/CMakeLists.txt new file mode 100644 index 00000000..bd0f8f04 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/translation/CMakeLists.txt @@ -0,0 +1,46 @@ +#- +#***************************************************************************** +# Copyright 2023 Autodesk, Inc. +# +# 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. +#***************************************************************************** +#+ + +set(private_libs + Amino::Core + BifrostGraph::Executor + Amino::SDK::Preview + BifrostHdEngine +) + +set(src_files + TypeTranslation.cpp +) + +bifusd_set_extra_rpaths(extra_rpaths) + +bifusd_create_shared_lib( + BifrostHdTypeTranslation "HD_MODULE_API_IMPL" + PUBLIC_INSTALL + PUBLIC_DEFINITIONS $<${BIFUSD_IS_MSC}: BOOST_LIB_TOOLSET="vc141"> + PRIVATE_DEFINITIONS $<${BIFUSD_IS_DEBUG}: TBB_USE_DEBUG BOOST_DEBUG_PYTHON BOOST_LINKING_PYTHON> + + PRIVATE_OPTIONS $<${BIFUSD_IS_MSC}:/wd4251 /wd4273> + $<${BIFUSD_IS_GCC}: -Wno-deprecated -Wno-unused-macros> + $<${BIFUSD_IS_CLANG}: -Wno-deprecated -Wno-unused-macros> + + PUBLIC_OPTIONS $<${BIFUSD_IS_MSC}:/wd4251 /wd4273> + SRC_FILES ${src_files} + PRIVATE_LINK_LIBS ${private_libs} + EXTRA_RPATH ${extra_rpaths} +) diff --git a/bifrost_hydra/src/BifrostHdEngine/translation/TypeTranslation.cpp b/bifrost_hydra/src/BifrostHdEngine/translation/TypeTranslation.cpp new file mode 100644 index 00000000..045ad32b --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/translation/TypeTranslation.cpp @@ -0,0 +1,129 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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 "TypeTranslation.h" +#include +#include + +#include + +namespace BifrostHd { + +TypeTranslation::TypeTranslation() + : BifrostGraph::Executor::TypeTranslation("BifrostHd Translation Table") {} + +TypeTranslation::~TypeTranslation() {} + +void TypeTranslation::deleteThis() { delete this; } + +void TypeTranslation::getSupportedTypeNames( + Amino::StringList& out_names) const { + out_names.add("bool"); + out_names.add("float"); + out_names.add("double"); + out_names.add("long"); + out_names.add("ulong"); + out_names.add("int"); + out_names.add("uint"); + out_names.add("short"); + out_names.add("ushort"); + out_names.add("char"); + out_names.add("uchar"); + out_names.add("string"); + out_names.add("Math::float3"); + out_names.add("Object"); + // for graphs using time nodes + out_names.add("Simulation::Time"); +} + +bool TypeTranslation::convertValueFromHost( + Amino::Type const& type, + Amino::Value& value, + BifrostGraph::Executor::TypeTranslation::ValueTranslationData const* + valueTranslationData) const { + assert(dynamic_cast( + valueTranslationData)); + + auto bifrostHdValueTranslationData = + static_cast( + valueTranslationData); + const auto& typeName = type.getFullyQualifiedName(); + + if (typeName == "Simulation::Time") { + auto time = + bifrostHdValueTranslationData->jobTranslationData().getTime(); + Amino::StructValue timeValue(type); + timeValue["ticks"].setLong(static_cast(1)); + timeValue["time"].setDouble(time.currentTime); + timeValue["frame"].setDouble(time.currentFrame); + timeValue["frameLength"].setDouble(time.frameLength); + value = timeValue; + return true; + } + + value = bifrostHdValueTranslationData->getInput(type); + return true; +} + +bool TypeTranslation::convertValueToHost( + Amino::Value const& value, + BifrostGraph::Executor::TypeTranslation::ValueTranslationData* + valueTranslationData) const { + auto elementType = value.getType(); + Amino::String typeName = elementType.getFullyQualifiedName(); + + assert( + dynamic_cast(valueTranslationData)); + + auto bifrostHdValueTranslationData = + static_cast(valueTranslationData); + + return bifrostHdValueTranslationData->setOutput(value); +} + +bool TypeTranslation::portAdded( + Amino::String const& /*name*/, + PortDirection /*direction*/, + Amino::Type const& /*type*/, + Amino::Metadata const& /*metadata*/, + PortClass /*portClass*/, + PortTranslationData* /*valueTranslationData*/) const { + return true; +} + +bool TypeTranslation::registerHostPlugins( + const PluginHostData* /*hostData*/) const { + return true; +} + +bool TypeTranslation::unregisterHostPlugins( + const PluginHostData* /*hostData*/) const { + return false; +} + +bool TypeTranslation::getDataTypeColorHint(Amino::Type const& /*dataType*/, + Amino::String& /*colorHint*/) const { + return false; +} + +} // namespace BifrostHd + +extern "C" { +HD_MODULE_API BifrostGraph::Executor::TypeTranslation* + createBifrostTypeTranslation(void) { + return new BifrostHd::TypeTranslation(); +} +} diff --git a/bifrost_hydra/src/BifrostHdEngine/translation/TypeTranslation.h b/bifrost_hydra/src/BifrostHdEngine/translation/TypeTranslation.h new file mode 100644 index 00000000..ade13a3e --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/translation/TypeTranslation.h @@ -0,0 +1,68 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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. +//+ + +#ifndef BIFROST_HD_ENGINE_TYPE_TRANSLATION_H_ +#define BIFROST_HD_ENGINE_TYPE_TRANSLATION_H_ + +#include "export.h" + +#include + +namespace BifrostHd { + +class TypeTranslation final : public BifrostGraph::Executor::TypeTranslation { +public: + TypeTranslation(); + + ~TypeTranslation() override; + + void deleteThis() override; + + void getSupportedTypeNames(Amino::StringList& out_names) const override; + + bool convertValueFromHost( + Amino::Type const& type, + Amino::Value& value, + BifrostGraph::Executor::TypeTranslation::ValueTranslationData const* + valueTranslationData) const override; + + bool convertValueToHost( + Amino::Value const& value, + BifrostGraph::Executor::TypeTranslation::ValueTranslationData* + valueTranslationData) const override; + + bool portAdded(Amino::String const& name, + PortDirection direction, + Amino::Type const& type, + Amino::Metadata const& metadata, + PortClass portClass, + PortTranslationData* valueTranslationData) const override; + + bool registerHostPlugins(const PluginHostData* hostData) const override; + bool unregisterHostPlugins(const PluginHostData* hostData) const override; + + bool getDataTypeColorHint(Amino::Type const& dataType, + Amino::String& colorHint) const override; +}; + +} // namespace BifrostHd + +extern "C" { +HD_MODULE_API BifrostGraph::Executor::TypeTranslation* + createBifrostTypeTranslation(void); +} + +#endif // BIFROST_HD_ENGINE_TYPE_TRANSLATION_H_ diff --git a/bifrost_hydra/src/BifrostHdEngine/translation/export.h b/bifrost_hydra/src/BifrostHdEngine/translation/export.h new file mode 100644 index 00000000..cb336ab7 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdEngine/translation/export.h @@ -0,0 +1,48 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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. +//+ + +#ifndef HD_MODULE_DECL +#define HD_MODULE_DECL + +#if defined(HD_MODULE_API_NO_API) +#define HD_MODULE_API +#elif defined(_WIN32) || defined(__CYGWIN__) +#ifdef HD_MODULE_API_IMPL +#ifdef __GNUC__ +#define HD_MODULE_API __attribute__((dllexport)) +#else +#define HD_MODULE_API \ + __declspec( \ + dllexport) // Note: actually gcc seems to also supports this syntax. +#endif +#else +#ifdef __GNUC__ +#define HD_MODULE_API __attribute__((dllimport)) +#else +#define HD_MODULE_API \ + __declspec( \ + dllimport) // Note: actually gcc seems to also supports this syntax. +#endif +#endif +#else +#if __GNUC__ >= 4 +#define HD_MODULE_API __attribute__((visibility("default"))) +#else +#define HD_MODULE_API +#endif +#endif + +#endif diff --git a/bifrost_hydra/src/BifrostHdGraph/BifrostGraphGenerativeProcedural.cpp b/bifrost_hydra/src/BifrostHdGraph/BifrostGraphGenerativeProcedural.cpp new file mode 100644 index 00000000..9e064775 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdGraph/BifrostGraphGenerativeProcedural.cpp @@ -0,0 +1,126 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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 "BifrostGraphGenerativeProcedural.h" + +#include +#include +#include +#include + +#include + +PXR_NAMESPACE_USING_DIRECTIVE + +BifrostGraphGenerativeProcedural::BifrostGraphGenerativeProcedural( + const SdfPath& proceduralPrimPath) + : HdGpGenerativeProcedural(proceduralPrimPath) {} + +HdGpGenerativeProcedural::DependencyMap +BifrostGraphGenerativeProcedural::UpdateDependencies( + const HdSceneIndexBaseRefPtr& /*inputScene*/) { + HdGpGenerativeProcedural::DependencyMap result; + + return result; +} + +// Cooks/Recooks and returns the current state of child paths and their +// types. At the moment we create a new Bifrost Graph when any of the parameters +// on the procedural are changed. +HdGpGenerativeProcedural::ChildPrimTypeMap +BifrostGraphGenerativeProcedural::Update( + const HdSceneIndexBaseRefPtr& inputScene, + const ChildPrimTypeMap& /*previousResult*/, + const DependencyMap& /*dirtiedDependencies*/, + HdSceneIndexObserver::DirtiedPrimEntries* outputDirtiedPrims) { + ChildPrimTypeMap result; + auto graphPath = _GetProceduralPrimPath(); + m_engine.setInputScene(inputScene); + m_engine.setInputs(inputScene->GetPrim(graphPath)); + + if (m_engine.execute(/*frame*/ 0.0) == Amino::Job::State::kSuccess) { + const auto& output = m_engine.output(); + const auto& objectArray = output.second; + + for (size_t i = 0; i < objectArray.size(); ++i) { + // We need to cache if the geo is an instance as it is + // costly to re-do it for each path in the sub-loop later on + + std::shared_ptr geo; + const auto& obj = *(objectArray[i]); + + auto geoType = BifrostHd::GetGeoType(obj); + + switch (geoType) { + case BifrostHdGeoTypes::Empty: break; + case BifrostHdGeoTypes::Mesh: + geo = std::make_shared(obj, i); + break; + case BifrostHdGeoTypes::Strands: + geo = std::make_shared(obj, i); + break; + case BifrostHdGeoTypes::PointCloud: break; + case BifrostHdGeoTypes::Instances: + geo = std::make_shared(obj); + break; + } + + if (geo) { + auto path = graphPath; + size_t j = 0; + for (const auto& child : geo->getChildren()) { + // TODO(laforgg): Instances support is not working yet + if (geoType == BifrostHdGeoTypes::Instances && j > 0) { + path = path.AppendChild(TfToken{"prototypes"}); + path = path.AppendChild(TfToken{"mesh"}); + } else { + const auto& childName = child.first; + path = path.AppendChild(childName.GetToken()); + } + + result[path] = geo->getSceneIndexPrimTypeName(); + outputDirtiedPrims->emplace_back(path, + geo->TopologyLocator()); + m_geomTranslators[path] = geo; + j++; + } + } + } + } + + return result; +} + +HdSceneIndexPrim BifrostGraphGenerativeProcedural::GetChildPrim( + const HdSceneIndexBaseRefPtr& /*inputScene*/, + const SdfPath& childPrimPath) { + HdSceneIndexPrim result; + + const auto searchGeo = m_geomTranslators.find(childPrimPath); + if (searchGeo == m_geomTranslators.end()) { + return result; + } + auto geo = searchGeo->second; + if (geo) { + const auto& pathToPrim = geo->getChildren(); + const auto search = + pathToPrim.find(PXR_NS::SdfPath{childPrimPath.GetNameToken()}); + if (search != pathToPrim.end()) { + result = search->second; + } + } + return result; +} diff --git a/bifrost_hydra/src/BifrostHdGraph/BifrostGraphGenerativeProcedural.h b/bifrost_hydra/src/BifrostHdGraph/BifrostGraphGenerativeProcedural.h new file mode 100644 index 00000000..adfd933e --- /dev/null +++ b/bifrost_hydra/src/BifrostHdGraph/BifrostGraphGenerativeProcedural.h @@ -0,0 +1,53 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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. +//+ + +#ifndef BIFROST_HD_GRAPH_PROCEDURAL_H +#define BIFROST_HD_GRAPH_PROCEDURAL_H + +#include + +#include +#include + +PXR_NAMESPACE_OPEN_SCOPE + + +class BifrostGraphGenerativeProcedural : public HdGpGenerativeProcedural { +public: + explicit BifrostGraphGenerativeProcedural(const SdfPath& proceduralPrimPath); + + DependencyMap UpdateDependencies( + const HdSceneIndexBaseRefPtr& /*inputScene*/) override; + + HdGpGenerativeProcedural::ChildPrimTypeMap Update( + const HdSceneIndexBaseRefPtr& inputScene, + const HdGpGenerativeProcedural::ChildPrimTypeMap& previousResult, + const HdGpGenerativeProcedural::DependencyMap& dirtiedDependencies, + HdSceneIndexObserver::DirtiedPrimEntries* outputDirtiedPrims) override; + + HdSceneIndexPrim GetChildPrim(const HdSceneIndexBaseRefPtr& inputScene, + const SdfPath& childPrimPath) override; + +private: + using BifrostTranslatorsMap = std::unordered_map, TfHash>; + + BifrostHd::Engine m_engine; + BifrostTranslatorsMap m_geomTranslators; +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif // BIFROST_HD_GRAPH_PROCEDURAL_H diff --git a/bifrost_hydra/src/BifrostHdGraph/BifrostGraphGenerativeProceduralPlugin.cpp b/bifrost_hydra/src/BifrostHdGraph/BifrostGraphGenerativeProceduralPlugin.cpp new file mode 100644 index 00000000..9274d1eb --- /dev/null +++ b/bifrost_hydra/src/BifrostHdGraph/BifrostGraphGenerativeProceduralPlugin.cpp @@ -0,0 +1,39 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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 "BifrostGraphGenerativeProceduralPlugin.h" + +#include "BifrostGraphGenerativeProcedural.h" + +#include + +PXR_NAMESPACE_USING_DIRECTIVE + +BifrostGraphGenerativeProceduralPlugin:: + BifrostGraphGenerativeProceduralPlugin() = default; + +HdGpGenerativeProcedural* BifrostGraphGenerativeProceduralPlugin::Construct( + const SdfPath& proceduralPrimPath) { + return new BifrostGraphGenerativeProcedural(proceduralPrimPath); +} + +/////////////////////////////////////////////////////////////////////////////// + +TF_REGISTRY_FUNCTION(TfType) { + HdGpGenerativeProceduralPluginRegistry::Define< + BifrostGraphGenerativeProceduralPlugin, + HdGpGenerativeProceduralPlugin>(); +} diff --git a/bifrost_hydra/src/BifrostHdGraph/BifrostGraphGenerativeProceduralPlugin.h b/bifrost_hydra/src/BifrostHdGraph/BifrostGraphGenerativeProceduralPlugin.h new file mode 100644 index 00000000..5193923d --- /dev/null +++ b/bifrost_hydra/src/BifrostHdGraph/BifrostGraphGenerativeProceduralPlugin.h @@ -0,0 +1,35 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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. +//+ + +#ifndef BIFROST_HD_GRAPH_PROCEDURAL_PLUGIN_H +#define BIFROST_HD_GRAPH_PROCEDURAL_PLUGIN_H + +#include + +PXR_NAMESPACE_OPEN_SCOPE + +class BifrostGraphGenerativeProceduralPlugin + : public HdGpGenerativeProceduralPlugin { +public: + BifrostGraphGenerativeProceduralPlugin(); + + HdGpGenerativeProcedural* Construct( + const SdfPath& proceduralPrimPath) override; +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif // BIFROST_HD_GRAPH_PROCEDURAL_PLUGIN_H diff --git a/bifrost_hydra/src/BifrostHdGraph/CMakeLists.txt b/bifrost_hydra/src/BifrostHdGraph/CMakeLists.txt new file mode 100644 index 00000000..9f0304f8 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdGraph/CMakeLists.txt @@ -0,0 +1,64 @@ +#- +#***************************************************************************** +# Copyright 2023 Autodesk, Inc. +# +# 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. +#***************************************************************************** +#+ + +set(private_libs + Amino::Core + BifrostHdEngine + BifrostHdTranslators + hd + hdGp +) + +set(src_files + BifrostGraphGenerativeProcedural.cpp + BifrostGraphGenerativeProceduralPlugin.cpp +) + +bifusd_set_extra_rpaths(extra_rpaths) + +bifusd_create_shared_lib( + BifrostHdGraph "USD_BUILD_DLL" + PUBLIC_INSTALL + PUBLIC_DEFINITIONS $<${BIFUSD_IS_MSC}: BOOST_LIB_TOOLSET="vc141"> + PRIVATE_DEFINITIONS $<${BIFUSD_IS_DEBUG}: TBB_USE_DEBUG BOOST_DEBUG_PYTHON BOOST_LINKING_PYTHON> + + PRIVATE_OPTIONS $<${BIFUSD_IS_MSC}:/wd4251 /wd4273> + $<${BIFUSD_IS_GCC}: -Wno-deprecated -Wno-unused-macros> + $<${BIFUSD_IS_CLANG}: -Wno-deprecated -Wno-unused-macros> + + PUBLIC_OPTIONS $<${BIFUSD_IS_MSC}:/wd4251 /wd4273> + SRC_FILES ${src_files} + PRIVATE_LINK_LIBS ${private_libs} + EXTRA_RPATH ${extra_rpaths} +) + +set(plugin_info_json ${BIFROST_USD_OUTPUT_PROC_DIR}/plugInfo.json) + +# NOTE: To keep on the radar... For some reason, for tests to work, the relative path to add in the plugInfo.json needs +# to be computed from the directory that contains the directory that contains plugInfo.json. +if( BIFUSD_IS_WINDOWS) + file( RELATIVE_PATH BIFROST_HYDRA_REL_SHARED_LIB_DIR ${BIFROST_USD_OUTPUT_PROC_DIR}/.. ${BIFUSD_OUTPUT_BIN_DIR} ) +else() + file( RELATIVE_PATH BIFROST_HYDRA_REL_SHARED_LIB_DIR ${BIFROST_USD_OUTPUT_PROC_DIR}/.. ${BIFUSD_OUTPUT_LIB_DIR} ) +endif() + +configure_file(plugInfo.json.in ${plugin_info_json} @ONLY) + +install( + FILES ${plugin_info_json} + DESTINATION "${BIFROST_USD_PACK_INSTALL_RES_PROC_DIR}") diff --git a/bifrost_hydra/src/BifrostHdGraph/plugInfo.json.in b/bifrost_hydra/src/BifrostHdGraph/plugInfo.json.in new file mode 100644 index 00000000..407f8596 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdGraph/plugInfo.json.in @@ -0,0 +1,22 @@ +{ + "Plugins": [ + { + "LibraryPath": "@BIFROST_HYDRA_REL_SHARED_LIB_DIR@/@CMAKE_SHARED_LIBRARY_PREFIX@BifrostHdGraph_@BIFUSD_MAJOR_VERSION@_@BIFUSD_MINOR_VERSION@@CMAKE_SHARED_LIBRARY_SUFFIX@", + "Name": "bifrostGraph", + "ResourcePath": ".", + "Root": "..", + "Type": "library", + "Info": { + "Types": { + "BifrostGraphGenerativeProceduralPlugin": { + "bases": [ + "HdGpGenerativeProceduralPlugin" + ], + "displayName": "BifrostGraph", + "priority" : 0 + } + } + } + } + ] +} diff --git a/bifrost_hydra/src/BifrostHdTranslators/CMakeLists.txt b/bifrost_hydra/src/BifrostHdTranslators/CMakeLists.txt new file mode 100644 index 00000000..dc4fab4f --- /dev/null +++ b/bifrost_hydra/src/BifrostHdTranslators/CMakeLists.txt @@ -0,0 +1,75 @@ +#- +#***************************************************************************** +# Copyright 2023 Autodesk, Inc. +# +# 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. +#***************************************************************************** +#+ + +set(hd_GraphTranslator_headers + Geometry.h + GeometryFn.h + Mesh.h + Instances.h + Strands.h +) + +bifusd_install_headers( + hdGraphTranslatorsHeadersInstall + SOURCE ${CMAKE_CURRENT_SOURCE_DIR} + FILES ${hd_GraphTranslator_headers} + DESTINATION "BifrostHydra/Translators" +) + +set(private_libs + Amino::Core + Bifrost::Object::Preview + Amino::SDK::Preview + Bifrost::Geometry::Preview + Bifrost::VTT::Preview + hd + hdGraphTranslatorsHeadersInstall +) + +set(src_files + Geometry.cpp + GeometryFn.cpp + Mesh.cpp + Instances.cpp + Strands.cpp +) + +bifusd_set_extra_rpaths(extra_rpaths) + +bifusd_create_shared_lib( + BifrostHdTranslators "USD_BUILD_DLL" + PUBLIC_INSTALL + PUBLIC_DEFINITIONS $<${BIFUSD_IS_MSC}: BOOST_LIB_TOOLSET="vc141"> + PRIVATE_DEFINITIONS $<${BIFUSD_IS_DEBUG}: TBB_USE_DEBUG BOOST_DEBUG_PYTHON BOOST_LINKING_PYTHON> + + PRIVATE_OPTIONS $<${BIFUSD_IS_MSC}:/wd4251 /wd4273> + $<${BIFUSD_IS_GCC}: -Wno-deprecated -Wno-unused-macros> + $<${BIFUSD_IS_CLANG}: + # 'GetValue' overrides a member function but is not marked 'override' + # in pxr/imaging/hd/dataSource.h:176:21 + -Wno-suggest-override -Wno-inconsistent-missing-override + # There are some unused member function in pxr/imaging/hd/dataSource.h:65:5 + -Wno-unused-member-function + -Wno-unused-macros + > + + SRC_FILES ${src_files} + PRIVATE_LINK_LIBS ${private_libs} + EXTRA_RPATH ${extra_rpaths} +) + diff --git a/bifrost_hydra/src/BifrostHdTranslators/Geometry.cpp b/bifrost_hydra/src/BifrostHdTranslators/Geometry.cpp new file mode 100644 index 00000000..fa028f58 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdTranslators/Geometry.cpp @@ -0,0 +1,25 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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 + +namespace BifrostHd { + +Geometry::Geometry() = default; + +Geometry::~Geometry() = default; + +} // namespace BifrostHd diff --git a/bifrost_hydra/src/BifrostHdTranslators/Geometry.h b/bifrost_hydra/src/BifrostHdTranslators/Geometry.h new file mode 100644 index 00000000..62a911d1 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdTranslators/Geometry.h @@ -0,0 +1,55 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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. +//+ + +#ifndef BIFROST_HD_GRAPH_GEOMETRY_H +#define BIFROST_HD_GRAPH_GEOMETRY_H + +#include +#include +#include + +namespace BifrostHd { + +using ChildPrimMap = PXR_NS::TfDenseHashMap; + +class Geometry { +public: + explicit Geometry(); + + virtual ~Geometry(); + + virtual const PXR_NS::TfToken& getSceneIndexPrimTypeName() const = 0; + + virtual const PXR_NS::HdDataSourceLocator& TopologyLocator() const = 0; + + virtual const ChildPrimMap& getChildren() const = 0; + +public: + /// Disabled + /// \{ + Geometry(Geometry const&) = delete; + Geometry(Geometry&&) = delete; + Geometry& operator=(const Geometry&) = delete; + Geometry& operator=(Geometry&&) = delete; + /// \} + +protected: + ChildPrimMap m_children_map; +}; + +} // namespace BifrostHd + +#endif // BIFROST_HD_GRAPH_GEOMETRY_H diff --git a/bifrost_hydra/src/BifrostHdTranslators/GeometryFn.cpp b/bifrost_hydra/src/BifrostHdTranslators/GeometryFn.cpp new file mode 100644 index 00000000..4b342cc4 --- /dev/null +++ b/bifrost_hydra/src/BifrostHdTranslators/GeometryFn.cpp @@ -0,0 +1,700 @@ +//- +// Copyright 2023 Autodesk, Inc. +// +// 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +PXR_NAMESPACE_USING_DIRECTIVE + +using BifrostGeoIndices = Amino::Array; +using BifrostFloat3Array = Amino::Array; + +namespace { + +VtVec3fArray GetVec3fArray(const Bifrost::Object& object, + const Amino::String& name) { + VtVec3fArray result; + const auto data = + Bifrost::Geometry::getDataGeoPropValues(object, name); + if (data) { + result.reserve(data->size()); + + for (size_t i = 0; i < data->size(); ++i) { + result.emplace_back((*data)[i].x, (*data)[i].y, (*data)[i].z); + } + } + return result; +} + +VtIntArray GetIntArray(const Bifrost::Object& object, + const Amino::String& name) { + VtIntArray result; + auto data = Bifrost::Geometry::getDataGeoPropValues( + object, name); + + if (data) { + result = VtIntArray{data->begin(), data->end()}; + } + return result; +} + +VtIntArray BifrostOffsetsToUsdVertexCount( + Amino::Ptr& offsets) { + using SizeType = decltype(offsets->size()); + const SizeType face_vertex_indices_count = offsets->size() - 1; + BifrostGeoIndices face_vertex_count; + face_vertex_count.resize(face_vertex_indices_count); + VtIntArray vt_face_vertex_count(face_vertex_indices_count); + // Cumulative substract on array + for (SizeType i = 0; i < face_vertex_indices_count; ++i) { + vt_face_vertex_count[i] = (*offsets)[i + 1] - (*offsets)[i]; + } + + return vt_face_vertex_count; +} + +class Matrix4dFromObjectDataSource : public HdMatrixDataSource { +public: + HD_DECLARE_DATASOURCE(Matrix4dFromObjectDataSource) + + bool GetContributingSampleTimesForInterval( + Time /*startTime*/, + Time /*endTime*/, + std::vector