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/usdLux/domeLight.h"
25 #include "pxr/usd/usd/schemaRegistry.h"
26 #include "pxr/usd/usd/typed.h"
27 
28 #include "pxr/usd/sdf/types.h"
29 #include "pxr/usd/sdf/assetPath.h"
30 
31 PXR_NAMESPACE_OPEN_SCOPE
32 
33 // Register the schema with the TfType system.
TF_REGISTRY_FUNCTION(TfType)34 TF_REGISTRY_FUNCTION(TfType)
35 {
36     TfType::Define<UsdLuxDomeLight,
37         TfType::Bases< UsdLuxNonboundableLightBase > >();
38 
39     // Register the usd prim typename as an alias under UsdSchemaBase. This
40     // enables one to call
41     // TfType::Find<UsdSchemaBase>().FindDerivedByName("DomeLight")
42     // to find TfType<UsdLuxDomeLight>, which is how IsA queries are
43     // answered.
44     TfType::AddAlias<UsdSchemaBase, UsdLuxDomeLight>("DomeLight");
45 }
46 
47 /* virtual */
~UsdLuxDomeLight()48 UsdLuxDomeLight::~UsdLuxDomeLight()
49 {
50 }
51 
52 /* static */
53 UsdLuxDomeLight
Get(const UsdStagePtr & stage,const SdfPath & path)54 UsdLuxDomeLight::Get(const UsdStagePtr &stage, const SdfPath &path)
55 {
56     if (!stage) {
57         TF_CODING_ERROR("Invalid stage");
58         return UsdLuxDomeLight();
59     }
60     return UsdLuxDomeLight(stage->GetPrimAtPath(path));
61 }
62 
63 /* static */
64 UsdLuxDomeLight
Define(const UsdStagePtr & stage,const SdfPath & path)65 UsdLuxDomeLight::Define(
66     const UsdStagePtr &stage, const SdfPath &path)
67 {
68     static TfToken usdPrimTypeName("DomeLight");
69     if (!stage) {
70         TF_CODING_ERROR("Invalid stage");
71         return UsdLuxDomeLight();
72     }
73     return UsdLuxDomeLight(
74         stage->DefinePrim(path, usdPrimTypeName));
75 }
76 
77 /* virtual */
_GetSchemaKind() const78 UsdSchemaKind UsdLuxDomeLight::_GetSchemaKind() const
79 {
80     return UsdLuxDomeLight::schemaKind;
81 }
82 
83 /* static */
84 const TfType &
_GetStaticTfType()85 UsdLuxDomeLight::_GetStaticTfType()
86 {
87     static TfType tfType = TfType::Find<UsdLuxDomeLight>();
88     return tfType;
89 }
90 
91 /* static */
92 bool
_IsTypedSchema()93 UsdLuxDomeLight::_IsTypedSchema()
94 {
95     static bool isTyped = _GetStaticTfType().IsA<UsdTyped>();
96     return isTyped;
97 }
98 
99 /* virtual */
100 const TfType &
_GetTfType() const101 UsdLuxDomeLight::_GetTfType() const
102 {
103     return _GetStaticTfType();
104 }
105 
106 UsdAttribute
GetTextureFileAttr() const107 UsdLuxDomeLight::GetTextureFileAttr() const
108 {
109     return GetPrim().GetAttribute(UsdLuxTokens->inputsTextureFile);
110 }
111 
112 UsdAttribute
CreateTextureFileAttr(VtValue const & defaultValue,bool writeSparsely) const113 UsdLuxDomeLight::CreateTextureFileAttr(VtValue const &defaultValue, bool writeSparsely) const
114 {
115     return UsdSchemaBase::_CreateAttr(UsdLuxTokens->inputsTextureFile,
116                        SdfValueTypeNames->Asset,
117                        /* custom = */ false,
118                        SdfVariabilityVarying,
119                        defaultValue,
120                        writeSparsely);
121 }
122 
123 UsdAttribute
GetTextureFormatAttr() const124 UsdLuxDomeLight::GetTextureFormatAttr() const
125 {
126     return GetPrim().GetAttribute(UsdLuxTokens->inputsTextureFormat);
127 }
128 
129 UsdAttribute
CreateTextureFormatAttr(VtValue const & defaultValue,bool writeSparsely) const130 UsdLuxDomeLight::CreateTextureFormatAttr(VtValue const &defaultValue, bool writeSparsely) const
131 {
132     return UsdSchemaBase::_CreateAttr(UsdLuxTokens->inputsTextureFormat,
133                        SdfValueTypeNames->Token,
134                        /* custom = */ false,
135                        SdfVariabilityVarying,
136                        defaultValue,
137                        writeSparsely);
138 }
139 
140 UsdRelationship
GetPortalsRel() const141 UsdLuxDomeLight::GetPortalsRel() const
142 {
143     return GetPrim().GetRelationship(UsdLuxTokens->portals);
144 }
145 
146 UsdRelationship
CreatePortalsRel() const147 UsdLuxDomeLight::CreatePortalsRel() const
148 {
149     return GetPrim().CreateRelationship(UsdLuxTokens->portals,
150                        /* custom = */ false);
151 }
152 
153 namespace {
154 static inline TfTokenVector
_ConcatenateAttributeNames(const TfTokenVector & left,const TfTokenVector & right)155 _ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right)
156 {
157     TfTokenVector result;
158     result.reserve(left.size() + right.size());
159     result.insert(result.end(), left.begin(), left.end());
160     result.insert(result.end(), right.begin(), right.end());
161     return result;
162 }
163 }
164 
165 /*static*/
166 const TfTokenVector&
GetSchemaAttributeNames(bool includeInherited)167 UsdLuxDomeLight::GetSchemaAttributeNames(bool includeInherited)
168 {
169     static TfTokenVector localNames = {
170         UsdLuxTokens->lightShaderId,
171         UsdLuxTokens->inputsTextureFile,
172         UsdLuxTokens->inputsTextureFormat,
173     };
174     static TfTokenVector allNames =
175         _ConcatenateAttributeNames(
176             UsdLuxNonboundableLightBase::GetSchemaAttributeNames(true),
177             localNames);
178 
179     if (includeInherited)
180         return allNames;
181     else
182         return localNames;
183 }
184 
185 PXR_NAMESPACE_CLOSE_SCOPE
186 
187 // ===================================================================== //
188 // Feel free to add custom code below this line. It will be preserved by
189 // the code generator.
190 //
191 // Just remember to wrap code in the appropriate delimiters:
192 // 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'.
193 // ===================================================================== //
194 // --(BEGIN CUSTOM CODE)--
195 
196 #include "pxr/usd/usdGeom/metrics.h"
197 #include "pxr/usd/usdGeom/tokens.h"
198 
199 PXR_NAMESPACE_OPEN_SCOPE
200 
201 void
OrientToStageUpAxis() const202 UsdLuxDomeLight::OrientToStageUpAxis() const
203 {
204     if (UsdGeomGetStageUpAxis(GetPrim().GetStage()) == UsdGeomTokens->z) {
205         UsdGeomXformOp::Type const opType = UsdGeomXformOp::TypeRotateX;
206         TfToken const& opSuffix = UsdLuxTokens->orientToStageUpAxis;
207         TfToken const opName = UsdGeomXformOp::GetOpName(opType, opSuffix);
208         bool resetsXformStack;
209         for (UsdGeomXformOp const& op: GetOrderedXformOps(&resetsXformStack)) {
210             if (op.GetName() == opName) {
211                 // Op already exists.
212                 return;
213             }
214         }
215         AddXformOp(opType, UsdGeomXformOp::PrecisionFloat, opSuffix)
216             .Set(90.0f);
217     }
218 }
219 
220 PXR_NAMESPACE_CLOSE_SCOPE
221