Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add variant support #4

Open
wants to merge 9 commits into
base: needle/feature/wasm-improvements
Choose a base branch
from
1 change: 1 addition & 0 deletions pxr/usd/sdf/wrapLayerJs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ EMSCRIPTEN_BINDINGS(SdfLayer) {
.function("ExportToString", &ExportToString)
.function("GetDisplayName", &pxr::SdfLayer::GetDisplayName)
.function("GetPrimAtPath", &pxr::SdfLayer::GetPrimAtPath)
.function("GetDefaultPrim", &pxr::SdfLayer::GetDefaultPrim)
.function("GetPropertyAtPath", /*&pxr::SdfLayer::GetPropertyAtPath*/ &_GetPropertyAtPath, allow_raw_pointer<ret_val>())
.function("SetTimeSample", &_SetTimeSample)
.function("Traverse", &traverse)
Expand Down
34 changes: 34 additions & 0 deletions pxr/usd/usd/wrapPrimJs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "pxr/usd/usd/attribute.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/references.h"
#include "pxr/usd/usd/variantSets.h"

#include <emscripten/bind.h>
using namespace emscripten;
Expand All @@ -36,12 +37,45 @@ GetPropertyNames(pxr::UsdPrim& self)
return self.GetPropertyNames();
};


std::vector<std::string>
GetVariantSets(pxr::UsdPrim& self)
{
pxr::UsdVariantSets variantSets = self.GetVariantSets();
return variantSets.GetNames();
};

bool
SetVariant(pxr::UsdPrim& self, const std::string& variantSetName, const std::string& variantName){
pxr::UsdVariantSets variantSets = self.GetVariantSets();
return variantSets.SetSelection(variantSetName, variantName);
}

std::vector<std::string>
GetVariantSetOptions(pxr::UsdPrim& self, const std::string& variantSetName){
pxr::UsdVariantSets variantSets = self.GetVariantSets();
pxr::UsdVariantSet variantSet = variantSets.GetVariantSet(variantSetName);
return variantSet.GetVariantNames();
}

std::string
GetVariantSelection(pxr::UsdPrim& self, const std::string& variantSetName){
pxr::UsdVariantSets variantSets = self.GetVariantSets();
pxr::UsdVariantSet variantSet = variantSets.GetVariantSet(variantSetName);
return variantSet.GetVariantSelection();
}

EMSCRIPTEN_BINDINGS(UsdPrim) {
emscripten::register_vector<std::string>("VectorString");
class_<pxr::UsdPrim>("UsdPrim")
.function("GetAttribute", &pxr::UsdPrim::GetAttribute)
.function("GetTypeName", &pxr::UsdPrim::GetTypeName)
.function("GetAttributes", &pxr::UsdPrim::GetAttributes)
.function("GetPropertyNames", &GetPropertyNames)
.function("GetReferences", &pxr::UsdPrim::GetReferences)
.function("GetVariantSets", &GetVariantSets)
.function("SetVariant", &SetVariant)
.function("GetVariantSetOptions", &GetVariantSetOptions)
.function("GetVariantSelection", &GetVariantSelection)
;
}
17 changes: 16 additions & 1 deletion pxr/usd/usd/wrapStageJs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "pxr/usd/sdf/wrapPathJs.h"
#include "pxr/base/tf/wrapTokenJs.h"
#include "pxr/usd/usd/emscriptenPtrRegistrationHelper.h"
#include "pxr/usd/usdGeom/metrics.h"
#include "pxr/usd/usdGeom/tokens.h"
#include <functional>

#include <iostream>
Expand Down Expand Up @@ -86,6 +88,19 @@ void Export(pxr::UsdStage& self, const std::string &fileName, bool addFileFormat
self.Export(fileName, addFileFormatComments, arguments);
}

char GetUpAxis(pxr::UsdStage& self)
{
// Convert the UsdStage& to a UsdStageRefPtr
pxr::UsdStageRefPtr stageRefPtr(&self);

// Convert the UsdStageRefPtr to a UsdStageWeakPtr
pxr::UsdStageWeakPtr stageWeakPtr(stageRefPtr);

// Use the weak pointer to get the stage up axis
auto upAxisToken = pxr::UsdGeomGetStageUpAxis(stageWeakPtr);
return upAxisToken == pxr::UsdGeomTokens->y ? 'y' : upAxisToken == pxr::UsdGeomTokens->z ? 'z' : 'x';
}

void MyExit()
{
emscripten_force_exit(0);
Expand All @@ -109,12 +124,12 @@ EMSCRIPTEN_BINDINGS(UsdStage) {

.class_function("Open", &Open)
.class_function("Open", select_overload<pxr::UsdStageRefPtr(const pxr::SdfLayerHandle &layer, pxr::UsdStage::InitialLoadSet)>(&pxr::UsdStage::Open))

.class_function("Exit", &MyExit)
.function("ExportToString", &exportToString<pxr::UsdStage>)
.function("DefinePrim", &pxr::UsdStage::DefinePrim)
.function("Download", &download)
.function("Export", &Export)
.function("GetUpAxis", &GetUpAxis)
.function("GetPrimAtPath", &pxr::UsdStage::GetPrimAtPath)
.function("SetDefaultPrim", &pxr::UsdStage::SetDefaultPrim)
.function("OverridePrim", &pxr::UsdStage::OverridePrim)
Expand Down
2 changes: 1 addition & 1 deletion pxr/usdImaging/hdEmscripten/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ set_target_properties(${BINDINGS_NAME}
target_link_options(${BINDINGS_NAME} PRIVATE "SHELL: -Oz -s EXPORT_NAME='getUsdModule' \
-s MODULARIZE=1 -lembind -s PTHREAD_POOL_SIZE=10 -s ASYNCIFY -s ASYNCIFY_ADVISE \
-sIMPORTED_MEMORY=1 --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/js/MemoryConfiguration.js \
-s ASYNCIFY_REMOVE=['__vfprintf_internal','__fseeko_unlocked','*::itanium_demangle::*','*VtArray*','*_Clear*','*dlfree*','*TfType*','*Tf_Registry*','*Tf_Post*','*tao::PXR_INTERNAL_NS_pegtl*','*UsdObject*','*TfSmallVector*','*TfMallocTag*','*__cxa_guard_acquire*,'*UsdSchema*','*Usd_CrateFile*','*TfEnum*','*TfErrorMark*','*VtStreamOutArray*','*SdfSpec*']")
")

install(
FILES
Expand Down