1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 //    names, trademarks, service marks, or product names of the Licensor
11 //    and its affiliates, except as required to comply with Section 4(c) of
12 //    the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 //     http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #include "pxr/usd/usdPhysics/rigidBodyAPI.h"
25 #include "pxr/usd/usd/schemaRegistry.h"
26 #include "pxr/usd/usd/typed.h"
27 #include "pxr/usd/usd/tokens.h"
28 
29 #include "pxr/usd/sdf/types.h"
30 #include "pxr/usd/sdf/assetPath.h"
31 
32 PXR_NAMESPACE_OPEN_SCOPE
33 
34 // Register the schema with the TfType system.
TF_REGISTRY_FUNCTION(TfType)35 TF_REGISTRY_FUNCTION(TfType)
36 {
37     TfType::Define<UsdPhysicsRigidBodyAPI,
38         TfType::Bases< UsdAPISchemaBase > >();
39 
40 }
41 
42 TF_DEFINE_PRIVATE_TOKENS(
43     _schemaTokens,
44     (PhysicsRigidBodyAPI)
45 );
46 
47 /* virtual */
~UsdPhysicsRigidBodyAPI()48 UsdPhysicsRigidBodyAPI::~UsdPhysicsRigidBodyAPI()
49 {
50 }
51 
52 /* static */
53 UsdPhysicsRigidBodyAPI
Get(const UsdStagePtr & stage,const SdfPath & path)54 UsdPhysicsRigidBodyAPI::Get(const UsdStagePtr &stage, const SdfPath &path)
55 {
56     if (!stage) {
57         TF_CODING_ERROR("Invalid stage");
58         return UsdPhysicsRigidBodyAPI();
59     }
60     return UsdPhysicsRigidBodyAPI(stage->GetPrimAtPath(path));
61 }
62 
63 
64 /* virtual */
_GetSchemaKind() const65 UsdSchemaKind UsdPhysicsRigidBodyAPI::_GetSchemaKind() const
66 {
67     return UsdPhysicsRigidBodyAPI::schemaKind;
68 }
69 
70 /* static */
71 bool
CanApply(const UsdPrim & prim,std::string * whyNot)72 UsdPhysicsRigidBodyAPI::CanApply(
73     const UsdPrim &prim, std::string *whyNot)
74 {
75     return prim.CanApplyAPI<UsdPhysicsRigidBodyAPI>(whyNot);
76 }
77 
78 /* static */
79 UsdPhysicsRigidBodyAPI
Apply(const UsdPrim & prim)80 UsdPhysicsRigidBodyAPI::Apply(const UsdPrim &prim)
81 {
82     if (prim.ApplyAPI<UsdPhysicsRigidBodyAPI>()) {
83         return UsdPhysicsRigidBodyAPI(prim);
84     }
85     return UsdPhysicsRigidBodyAPI();
86 }
87 
88 /* static */
89 const TfType &
_GetStaticTfType()90 UsdPhysicsRigidBodyAPI::_GetStaticTfType()
91 {
92     static TfType tfType = TfType::Find<UsdPhysicsRigidBodyAPI>();
93     return tfType;
94 }
95 
96 /* static */
97 bool
_IsTypedSchema()98 UsdPhysicsRigidBodyAPI::_IsTypedSchema()
99 {
100     static bool isTyped = _GetStaticTfType().IsA<UsdTyped>();
101     return isTyped;
102 }
103 
104 /* virtual */
105 const TfType &
_GetTfType() const106 UsdPhysicsRigidBodyAPI::_GetTfType() const
107 {
108     return _GetStaticTfType();
109 }
110 
111 UsdAttribute
GetRigidBodyEnabledAttr() const112 UsdPhysicsRigidBodyAPI::GetRigidBodyEnabledAttr() const
113 {
114     return GetPrim().GetAttribute(UsdPhysicsTokens->physicsRigidBodyEnabled);
115 }
116 
117 UsdAttribute
CreateRigidBodyEnabledAttr(VtValue const & defaultValue,bool writeSparsely) const118 UsdPhysicsRigidBodyAPI::CreateRigidBodyEnabledAttr(VtValue const &defaultValue, bool writeSparsely) const
119 {
120     return UsdSchemaBase::_CreateAttr(UsdPhysicsTokens->physicsRigidBodyEnabled,
121                        SdfValueTypeNames->Bool,
122                        /* custom = */ false,
123                        SdfVariabilityVarying,
124                        defaultValue,
125                        writeSparsely);
126 }
127 
128 UsdAttribute
GetKinematicEnabledAttr() const129 UsdPhysicsRigidBodyAPI::GetKinematicEnabledAttr() const
130 {
131     return GetPrim().GetAttribute(UsdPhysicsTokens->physicsKinematicEnabled);
132 }
133 
134 UsdAttribute
CreateKinematicEnabledAttr(VtValue const & defaultValue,bool writeSparsely) const135 UsdPhysicsRigidBodyAPI::CreateKinematicEnabledAttr(VtValue const &defaultValue, bool writeSparsely) const
136 {
137     return UsdSchemaBase::_CreateAttr(UsdPhysicsTokens->physicsKinematicEnabled,
138                        SdfValueTypeNames->Bool,
139                        /* custom = */ false,
140                        SdfVariabilityVarying,
141                        defaultValue,
142                        writeSparsely);
143 }
144 
145 UsdAttribute
GetStartsAsleepAttr() const146 UsdPhysicsRigidBodyAPI::GetStartsAsleepAttr() const
147 {
148     return GetPrim().GetAttribute(UsdPhysicsTokens->physicsStartsAsleep);
149 }
150 
151 UsdAttribute
CreateStartsAsleepAttr(VtValue const & defaultValue,bool writeSparsely) const152 UsdPhysicsRigidBodyAPI::CreateStartsAsleepAttr(VtValue const &defaultValue, bool writeSparsely) const
153 {
154     return UsdSchemaBase::_CreateAttr(UsdPhysicsTokens->physicsStartsAsleep,
155                        SdfValueTypeNames->Bool,
156                        /* custom = */ false,
157                        SdfVariabilityUniform,
158                        defaultValue,
159                        writeSparsely);
160 }
161 
162 UsdAttribute
GetVelocityAttr() const163 UsdPhysicsRigidBodyAPI::GetVelocityAttr() const
164 {
165     return GetPrim().GetAttribute(UsdPhysicsTokens->physicsVelocity);
166 }
167 
168 UsdAttribute
CreateVelocityAttr(VtValue const & defaultValue,bool writeSparsely) const169 UsdPhysicsRigidBodyAPI::CreateVelocityAttr(VtValue const &defaultValue, bool writeSparsely) const
170 {
171     return UsdSchemaBase::_CreateAttr(UsdPhysicsTokens->physicsVelocity,
172                        SdfValueTypeNames->Vector3f,
173                        /* custom = */ false,
174                        SdfVariabilityVarying,
175                        defaultValue,
176                        writeSparsely);
177 }
178 
179 UsdAttribute
GetAngularVelocityAttr() const180 UsdPhysicsRigidBodyAPI::GetAngularVelocityAttr() const
181 {
182     return GetPrim().GetAttribute(UsdPhysicsTokens->physicsAngularVelocity);
183 }
184 
185 UsdAttribute
CreateAngularVelocityAttr(VtValue const & defaultValue,bool writeSparsely) const186 UsdPhysicsRigidBodyAPI::CreateAngularVelocityAttr(VtValue const &defaultValue, bool writeSparsely) const
187 {
188     return UsdSchemaBase::_CreateAttr(UsdPhysicsTokens->physicsAngularVelocity,
189                        SdfValueTypeNames->Vector3f,
190                        /* custom = */ false,
191                        SdfVariabilityVarying,
192                        defaultValue,
193                        writeSparsely);
194 }
195 
196 UsdRelationship
GetSimulationOwnerRel() const197 UsdPhysicsRigidBodyAPI::GetSimulationOwnerRel() const
198 {
199     return GetPrim().GetRelationship(UsdPhysicsTokens->physicsSimulationOwner);
200 }
201 
202 UsdRelationship
CreateSimulationOwnerRel() const203 UsdPhysicsRigidBodyAPI::CreateSimulationOwnerRel() const
204 {
205     return GetPrim().CreateRelationship(UsdPhysicsTokens->physicsSimulationOwner,
206                        /* custom = */ false);
207 }
208 
209 namespace {
210 static inline TfTokenVector
_ConcatenateAttributeNames(const TfTokenVector & left,const TfTokenVector & right)211 _ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right)
212 {
213     TfTokenVector result;
214     result.reserve(left.size() + right.size());
215     result.insert(result.end(), left.begin(), left.end());
216     result.insert(result.end(), right.begin(), right.end());
217     return result;
218 }
219 }
220 
221 /*static*/
222 const TfTokenVector&
GetSchemaAttributeNames(bool includeInherited)223 UsdPhysicsRigidBodyAPI::GetSchemaAttributeNames(bool includeInherited)
224 {
225     static TfTokenVector localNames = {
226         UsdPhysicsTokens->physicsRigidBodyEnabled,
227         UsdPhysicsTokens->physicsKinematicEnabled,
228         UsdPhysicsTokens->physicsStartsAsleep,
229         UsdPhysicsTokens->physicsVelocity,
230         UsdPhysicsTokens->physicsAngularVelocity,
231     };
232     static TfTokenVector allNames =
233         _ConcatenateAttributeNames(
234             UsdAPISchemaBase::GetSchemaAttributeNames(true),
235             localNames);
236 
237     if (includeInherited)
238         return allNames;
239     else
240         return localNames;
241 }
242 
243 PXR_NAMESPACE_CLOSE_SCOPE
244 
245 // ===================================================================== //
246 // Feel free to add custom code below this line. It will be preserved by
247 // the code generator.
248 //
249 // Just remember to wrap code in the appropriate delimiters:
250 // 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'.
251 // ===================================================================== //
252 // --(BEGIN CUSTOM CODE)--
253