-
Notifications
You must be signed in to change notification settings - Fork 8
/
UsdInstance.cpp
97 lines (76 loc) · 2.46 KB
/
UsdInstance.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2020 The Khronos Group
// SPDX-License-Identifier: Apache-2.0
#include "UsdInstance.h"
#include "UsdAnari.h"
#include "UsdDevice.h"
#include "UsdGroup.h"
#define GroupType ANARI_GROUP
using GroupUsdType = AnariToUsdBridgedObject<GroupType>::Type;
DEFINE_PARAMETER_MAP(UsdInstance,
REGISTER_PARAMETER_MACRO("name", ANARI_STRING, name)
REGISTER_PARAMETER_MACRO("usd::name", ANARI_STRING, usdName)
REGISTER_PARAMETER_MACRO("usd::timeVarying", ANARI_INT32, timeVarying)
REGISTER_PARAMETER_MACRO("group", GroupType, group)
REGISTER_PARAMETER_MACRO("transform", ANARI_FLOAT32_MAT4, transform)
)
constexpr UsdInstance::ComponentPair UsdInstance::componentParamNames[]; // Workaround for C++14's lack of inlining constexpr arrays
UsdInstance::UsdInstance(const char* name,
UsdDevice* device)
: BridgedBaseObjectType(ANARI_INSTANCE, name, device)
{
}
UsdInstance::~UsdInstance()
{
#ifdef OBJECT_LIFETIME_EQUALS_USD_LIFETIME
if(cachedBridge)
cachedBridge->DeleteInstance(usdHandle);
#endif
}
void UsdInstance::remove(UsdDevice* device)
{
applyRemoveFunc(device, &UsdBridge::DeleteInstance);
}
bool UsdInstance::isInstanceable() const
{
return false;
}
bool UsdInstance::deferCommit(UsdDevice* device)
{
const UsdInstanceData& paramData = getReadParams();
if(UsdObjectNotInitialized<GroupUsdType>(paramData.group))
{
return true;
}
return false;
}
bool UsdInstance::doCommitData(UsdDevice* device)
{
UsdBridge* usdBridge = device->getUsdBridge();
const char* instanceName = getName();
bool isNew = false;
if (!usdHandle.value)
isNew = usdBridge->CreateInstance(instanceName, usdHandle);
if (paramChanged || isNew)
{
doCommitRefs(device); // Perform immediate commit of refs - no params from children required
paramChanged = false;
}
return false;
}
void UsdInstance::doCommitRefs(UsdDevice* device)
{
UsdBridge* usdBridge = device->getUsdBridge();
const UsdInstanceData& paramData = getReadParams();
double timeStep = device->getReadParams().timeStep;
bool groupTimeVarying = isTimeVarying(UsdInstanceComponents::GROUP);
bool transformTimeVarying = isTimeVarying(UsdInstanceComponents::TRANSFORM);
if (paramData.group)
{
usdBridge->SetGroupRef(usdHandle, paramData.group->getUsdHandle(), groupTimeVarying, timeStep);
}
else
{
usdBridge->DeleteGroupRef(usdHandle, groupTimeVarying, timeStep);
}
usdBridge->SetInstanceTransform(usdHandle, paramData.transform.Data, transformTimeVarying, timeStep);
}