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/usdRi/materialAPI.h"
25 #include "pxr/usd/usd/schemaBase.h"
26
27 #include "pxr/usd/sdf/primSpec.h"
28
29 #include "pxr/usd/usd/pyConversions.h"
30 #include "pxr/base/tf/pyAnnotatedBoolResult.h"
31 #include "pxr/base/tf/pyContainerConversions.h"
32 #include "pxr/base/tf/pyResultConversions.h"
33 #include "pxr/base/tf/pyUtils.h"
34 #include "pxr/base/tf/wrapTypeHelpers.h"
35
36 #include <boost/python.hpp>
37
38 #include <string>
39
40 using namespace boost::python;
41
42 PXR_NAMESPACE_USING_DIRECTIVE
43
44 namespace {
45
46 #define WRAP_CUSTOM \
47 template <class Cls> static void _CustomWrapCode(Cls &_class)
48
49 // fwd decl.
50 WRAP_CUSTOM;
51
52
53 static UsdAttribute
_CreateSurfaceAttr(UsdRiMaterialAPI & self,object defaultVal,bool writeSparsely)54 _CreateSurfaceAttr(UsdRiMaterialAPI &self,
55 object defaultVal, bool writeSparsely) {
56 return self.CreateSurfaceAttr(
57 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely);
58 }
59
60 static UsdAttribute
_CreateDisplacementAttr(UsdRiMaterialAPI & self,object defaultVal,bool writeSparsely)61 _CreateDisplacementAttr(UsdRiMaterialAPI &self,
62 object defaultVal, bool writeSparsely) {
63 return self.CreateDisplacementAttr(
64 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely);
65 }
66
67 static UsdAttribute
_CreateVolumeAttr(UsdRiMaterialAPI & self,object defaultVal,bool writeSparsely)68 _CreateVolumeAttr(UsdRiMaterialAPI &self,
69 object defaultVal, bool writeSparsely) {
70 return self.CreateVolumeAttr(
71 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely);
72 }
73
74 static std::string
_Repr(const UsdRiMaterialAPI & self)75 _Repr(const UsdRiMaterialAPI &self)
76 {
77 std::string primRepr = TfPyRepr(self.GetPrim());
78 return TfStringPrintf(
79 "UsdRi.MaterialAPI(%s)",
80 primRepr.c_str());
81 }
82
83 struct UsdRiMaterialAPI_CanApplyResult :
84 public TfPyAnnotatedBoolResult<std::string>
85 {
UsdRiMaterialAPI_CanApplyResult__anone91741490111::UsdRiMaterialAPI_CanApplyResult86 UsdRiMaterialAPI_CanApplyResult(bool val, std::string const &msg) :
87 TfPyAnnotatedBoolResult<std::string>(val, msg) {}
88 };
89
90 static UsdRiMaterialAPI_CanApplyResult
_WrapCanApply(const UsdPrim & prim)91 _WrapCanApply(const UsdPrim& prim)
92 {
93 std::string whyNot;
94 bool result = UsdRiMaterialAPI::CanApply(prim, &whyNot);
95 return UsdRiMaterialAPI_CanApplyResult(result, whyNot);
96 }
97
98 } // anonymous namespace
99
wrapUsdRiMaterialAPI()100 void wrapUsdRiMaterialAPI()
101 {
102 typedef UsdRiMaterialAPI This;
103
104 UsdRiMaterialAPI_CanApplyResult::Wrap<UsdRiMaterialAPI_CanApplyResult>(
105 "_CanApplyResult", "whyNot");
106
107 class_<This, bases<UsdAPISchemaBase> >
108 cls("MaterialAPI");
109
110 cls
111 .def(init<UsdPrim>(arg("prim")))
112 .def(init<UsdSchemaBase const&>(arg("schemaObj")))
113 .def(TfTypePythonClass())
114
115 .def("Get", &This::Get, (arg("stage"), arg("path")))
116 .staticmethod("Get")
117
118 .def("CanApply", &_WrapCanApply, (arg("prim")))
119 .staticmethod("CanApply")
120
121 .def("Apply", &This::Apply, (arg("prim")))
122 .staticmethod("Apply")
123
124 .def("GetSchemaAttributeNames",
125 &This::GetSchemaAttributeNames,
126 arg("includeInherited")=true,
127 return_value_policy<TfPySequenceToList>())
128 .staticmethod("GetSchemaAttributeNames")
129
130 .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find<This>,
131 return_value_policy<return_by_value>())
132 .staticmethod("_GetStaticTfType")
133
134 .def(!self)
135
136
137 .def("GetSurfaceAttr",
138 &This::GetSurfaceAttr)
139 .def("CreateSurfaceAttr",
140 &_CreateSurfaceAttr,
141 (arg("defaultValue")=object(),
142 arg("writeSparsely")=false))
143
144 .def("GetDisplacementAttr",
145 &This::GetDisplacementAttr)
146 .def("CreateDisplacementAttr",
147 &_CreateDisplacementAttr,
148 (arg("defaultValue")=object(),
149 arg("writeSparsely")=false))
150
151 .def("GetVolumeAttr",
152 &This::GetVolumeAttr)
153 .def("CreateVolumeAttr",
154 &_CreateVolumeAttr,
155 (arg("defaultValue")=object(),
156 arg("writeSparsely")=false))
157
158 .def("__repr__", ::_Repr)
159 ;
160
161 _CustomWrapCode(cls);
162 }
163
164 // ===================================================================== //
165 // Feel free to add custom code below this line, it will be preserved by
166 // the code generator. The entry point for your custom code should look
167 // minimally like the following:
168 //
169 // WRAP_CUSTOM {
170 // _class
171 // .def("MyCustomMethod", ...)
172 // ;
173 // }
174 //
175 // Of course any other ancillary or support code may be provided.
176 //
177 // Just remember to wrap code in the appropriate delimiters:
178 // 'namespace {', '}'.
179 //
180 // ===================================================================== //
181 // --(BEGIN CUSTOM CODE)--
182
183 namespace {
184
185 WRAP_CUSTOM {
186 typedef UsdRiMaterialAPI This;
187 _class
188 .def(init<UsdShadeMaterial>(arg("material")))
189
190 .def("GetSurface", &This::GetSurface, (arg("ignoreBaseMaterial")=false))
191 .def("GetDisplacement", &This::GetDisplacement,
192 (arg("ignoreBaseMaterial")=false))
193 .def("GetVolume", &This::GetVolume, (arg("ignoreBaseMaterial")=false))
194
195 .def("GetSurfaceOutput", &This::GetSurfaceOutput)
196 .def("GetDisplacementOutput", &This::GetDisplacementOutput)
197 .def("GetVolumeOutput", &This::GetVolumeOutput)
198
199 .def("SetSurfaceSource", &This::SetSurfaceSource)
200 .def("SetDisplacementSource", &This::SetDisplacementSource)
201 .def("SetVolumeSource", &This::SetVolumeSource)
202
203 .def("ComputeInterfaceInputConsumersMap",
204 &This::ComputeInterfaceInputConsumersMap,
205 (arg("computeTransitiveConsumers")=false),
206 return_value_policy<TfPyMapToDictionary>())
207 ;
208 }
209
210 } // anonymous namespace
211