@@ -40,6 +40,28 @@ PXR_NAMESPACE_USING_DIRECTIVE
40
40
41
41
namespace {
42
42
43
+ bool writeArnoldLightShader (const AtNode* node, UsdPrim& prim,
44
+ UsdArnoldPrimWriter &primWriter, UsdArnoldWriter &writer, const TfToken& lightShaderAttr)
45
+ {
46
+ AtNode *linkedColor = AiNodeGetLink (node, str::color);
47
+ if (!linkedColor)
48
+ return false ;
49
+ std::string nodeGraphName = prim.GetPath ().GetString () + " /light_shader" ;
50
+ SdfPath nodeGraphPath (nodeGraphName);
51
+ UsdStageRefPtr stage = writer.GetUsdStage ();
52
+ UsdPrim nodeGraphPrim = stage->DefinePrim (nodeGraphPath, str::t_ArnoldNodeGraph);
53
+
54
+ UsdAttribute arnoldShaderAttr =
55
+ prim.CreateAttribute (lightShaderAttr,
56
+ SdfValueTypeNames->String , false );
57
+ arnoldShaderAttr.Set (nodeGraphPrim.GetPath ().GetString ());
58
+
59
+ primWriter.WriteAttribute (node, " color" , nodeGraphPrim,
60
+ nodeGraphPrim.CreateAttribute (str::t_outputs_color,
61
+ SdfValueTypeNames->Token , false ), writer);
62
+ return true ;
63
+ }
64
+
43
65
void writeLightCommon (const AtNode *node, UsdPrim &prim, UsdArnoldPrimWriter &primWriter, UsdArnoldWriter &writer)
44
66
{
45
67
#if PXR_VERSION >= 2111
@@ -88,17 +110,20 @@ void UsdArnoldWriteDomeLight::Write(const AtNode *node, UsdArnoldWriter &writer)
88
110
writeLightCommon (node, prim, *this , writer);
89
111
_WriteMatrix (light, node, writer);
90
112
91
- AtNode *linkedTexture = AiNodeGetLink (node, " color" );
92
- static AtString imageStr (" image" );
93
- if (linkedTexture && AiNodeIs (linkedTexture, imageStr)) {
94
- // a texture is connected to the color attribute, so we want to export it to
95
- // the Dome's TextureFile attribute
96
- AtString filename = AiNodeGetStr (linkedTexture, AtString (" filename" ));
97
- SdfAssetPath assetPath (filename.c_str ());
98
- writer.SetAttribute (light.GetTextureFileAttr (), assetPath);
99
- light.GetColorAttr ().ClearConnections ();
100
- writer.SetAttribute (light.GetColorAttr (), GfVec3f (1 .f , 1 .f , 1 .f ));
113
+ if (writeArnoldLightShader (node, prim, *this , writer, str::t_primvars_arnold_shaders)) {
101
114
_exportedAttrs.insert (" color" );
115
+
116
+ AtNode *linkedTexture = AiNodeGetLink (node, " color" );
117
+ static AtString imageStr (" image" );
118
+ if (linkedTexture && AiNodeIs (linkedTexture, imageStr)) {
119
+ // a texture is connected to the color attribute, so we want to export it to
120
+ // the Dome's TextureFile attribute
121
+ AtString filename = AiNodeGetStr (linkedTexture, AtString (" filename" ));
122
+ SdfAssetPath assetPath (filename.c_str ());
123
+ writer.SetAttribute (light.GetTextureFileAttr (), assetPath);
124
+ light.GetColorAttr ().ClearConnections ();
125
+ writer.SetAttribute (light.GetColorAttr (), GfVec3f (1 .f , 1 .f , 1 .f ));
126
+ }
102
127
}
103
128
AtString textureFormat = AiNodeGetStr (node, AtString (" format" ));
104
129
static AtString latlongStr (" latlong" );
@@ -174,17 +199,20 @@ void UsdArnoldWriteRectLight::Write(const AtNode *node, UsdArnoldWriter &writer)
174
199
_WriteMatrix (light, node, writer);
175
200
WriteAttribute (node, " normalize" , prim, light.GetNormalizeAttr (), writer);
176
201
177
- AtNode *linkedTexture = AiNodeGetLink (node, AtString (" color" ));
178
- static AtString imageStr (" image" );
179
- if (linkedTexture && AiNodeIs (linkedTexture, imageStr)) {
180
- // a texture is connected to the color attribute, so we want to export it to
181
- // the Dome's TextureFile attribute
182
- AtString filename = AiNodeGetStr (linkedTexture, AtString (" filename" ));
183
- SdfAssetPath assetPath (filename.c_str ());
184
- writer.SetAttribute (light.GetTextureFileAttr (), assetPath);
185
- light.GetColorAttr ().ClearConnections ();
186
- writer.SetAttribute (light.GetColorAttr (), GfVec3f (1 .f , 1 .f , 1 .f ));
202
+ if (writeArnoldLightShader (node, prim, *this , writer, str::t_primvars_arnold_shaders)) {
187
203
_exportedAttrs.insert (" color" );
204
+
205
+ AtNode *linkedTexture = AiNodeGetLink (node, AtString (" color" ));
206
+ static AtString imageStr (" image" );
207
+ if (linkedTexture && AiNodeIs (linkedTexture, imageStr)) {
208
+ // a texture is connected to the color attribute, so we want to export it to
209
+ // the Dome's TextureFile attribute
210
+ AtString filename = AiNodeGetStr (linkedTexture, AtString (" filename" ));
211
+ SdfAssetPath assetPath (filename.c_str ());
212
+ writer.SetAttribute (light.GetTextureFileAttr (), assetPath);
213
+ light.GetColorAttr ().ClearConnections ();
214
+ writer.SetAttribute (light.GetColorAttr (), GfVec3f (1 .f , 1 .f , 1 .f ));
215
+ }
188
216
}
189
217
190
218
float width = 1 .f ;
@@ -240,21 +268,26 @@ void UsdArnoldWriteGeometryLight::Write(const AtNode *node, UsdArnoldWriter &wri
240
268
{
241
269
std::string nodeName = GetArnoldNodeName (node, writer);
242
270
UsdStageRefPtr stage = writer.GetUsdStage (); // Get the USD stage defined in the writer
243
- SdfPath objPath (nodeName);
244
- writer.CreateHierarchy (objPath);
245
- UsdLuxGeometryLight light = UsdLuxGeometryLight::Define (stage, objPath);
246
- UsdPrim prim = light.GetPrim ();
247
271
248
- writeLightCommon (node, prim, *this , writer);
249
- WriteAttribute (node, " normalize" , prim, light.GetNormalizeAttr (), writer);
272
+ AtNode *meshNode = (AtNode *)AiNodeGetPtr (node, AtString (" mesh" ));
273
+ if (!meshNode)
274
+ return ;
275
+
276
+ writer.WritePrimitive (meshNode);
277
+ std::string meshName = GetArnoldNodeName (meshNode, writer);
278
+ SdfPath meshPath (meshName);
279
+ UsdPrim mesh = stage->GetPrimAtPath (meshPath);
280
+
281
+ UsdAttribute lightAttr = mesh.CreateAttribute (str::t_primvars_arnold_light,
282
+ SdfValueTypeNames->Bool , false );
283
+ lightAttr.Set (true );
284
+
285
+ _exportedAttrs.insert (" mesh" );
250
286
// We're not authoring the light matrix, so that it's consistent with the mesh
251
287
_exportedAttrs.insert (" matrix" );
252
- AtNode *mesh = (AtNode *)AiNodeGetPtr (node, AtString (" mesh" ));
253
- if (mesh) {
254
- writer.WritePrimitive (mesh);
255
- std::string meshName = GetArnoldNodeName (mesh, writer);
256
- light.CreateGeometryRel ().AddTarget (SdfPath (meshName));
257
- }
258
- _exportedAttrs.insert (" mesh" );
259
- _WriteArnoldParameters (node, writer, prim, " primvars:arnold" );
288
+
289
+ if (writeArnoldLightShader (node, mesh, *this , writer, str::t_primvars_arnold_light_shaders))
290
+ _exportedAttrs.insert (" color" );
291
+
292
+ _WriteArnoldParameters (node, writer, mesh, " primvars:arnold:light" );
260
293
}
0 commit comments