| 257 | | MDGModifier dgMod; |
|---|
| 258 | | |
|---|
| 259 | | MFnLambertShader fnShader; |
|---|
| 260 | | |
|---|
| 261 | | fnShader.create( true, &stat ); |
|---|
| 262 | | check_status( stat ); |
|---|
| 263 | | |
|---|
| 264 | | fnShader.setName( MString( buf ), &stat ); |
|---|
| 265 | | check_status( stat ); |
|---|
| 266 | | |
|---|
| 267 | | { |
|---|
| 268 | | MFnTypedAttribute attr; |
|---|
| 269 | | MObject attrObj = attr.create( "originalShaderName", |
|---|
| 270 | | "osn", MFnData::kString, MObject::kNullObj, &stat ); |
|---|
| 271 | | check_status( stat ); |
|---|
| 272 | | |
|---|
| 273 | | stat = fnShader.addAttribute( attrObj ); |
|---|
| 274 | | check_status( stat ); |
|---|
| 275 | | |
|---|
| 276 | | MPlug attrPlug = fnShader.findPlug( attrObj, &stat ); |
|---|
| 277 | | check_status( stat ); |
|---|
| 278 | | |
|---|
| 279 | | stat = attrPlug.setString( MString( shader.shader ) ); |
|---|
| 280 | | check_status( stat ); |
|---|
| 281 | | } |
|---|
| 282 | | |
|---|
| 283 | | MPlug outColorPlug = fnShader.findPlug( MString( "outColor" ), &stat ); |
|---|
| 284 | | check_status( stat ); |
|---|
| 285 | | |
|---|
| 286 | | MObject shaderObj = fnShader.object( &stat ); |
|---|
| 287 | | check_status( stat ); |
|---|
| 288 | | |
|---|
| 289 | | MObject texObj = ImportTexture( shader.shader ); |
|---|
| 290 | | if( texObj != MObject::kNullObj ) |
|---|
| 291 | | { |
|---|
| 292 | | MFnDependencyNode fnTex( texObj, &stat ); |
|---|
| 293 | | check_status( stat ); |
|---|
| 294 | | |
|---|
| 295 | | MPlug texColorPlug = fnTex.findPlug( MString( "outColor" ), &stat ); |
|---|
| 296 | | check_status( stat ); |
|---|
| 297 | | //MPlug texTransPlug = fnTex.findPlug( MString( "outTransparency" ), &stat ); |
|---|
| 298 | | //check_status( stat ); |
|---|
| 299 | | |
|---|
| 300 | | MPlug shaderColorPlug = fnShader.findPlug( MString( "color" ), &stat ); |
|---|
| 301 | | check_status( stat ); |
|---|
| 302 | | //MPlug shaderTransPlug = fnShader.findPlug( MString( "transparency" ), &stat ); |
|---|
| 303 | | //check_status( stat ); |
|---|
| 304 | | |
|---|
| 305 | | |
|---|
| 306 | | stat = dgMod.connect( texColorPlug, shaderColorPlug ); |
|---|
| 307 | | check_status( stat ); |
|---|
| 308 | | //stat = dgMod.connect( texTransPlug, shaderTransPlug ); |
|---|
| 309 | | //check_status( stat ); |
|---|
| 310 | | } |
|---|
| 311 | | |
|---|
| 312 | | MFnSet fnGroup; |
|---|
| 313 | | MSelectionList empty; |
|---|
| 314 | | fnGroup.create( empty, MFnSet::kRenderableOnly, false, &stat ); |
|---|
| 315 | | check_status( stat ); |
|---|
| 316 | | |
|---|
| 317 | | buf.Append( "SG" ); |
|---|
| 318 | | fnGroup.setName( MString( buf ), &stat ); |
|---|
| 319 | | check_status( stat ); |
|---|
| 320 | | |
|---|
| 321 | | MPlug surfaceShaderPlug = fnGroup.findPlug( MString( "surfaceShader" ), &stat ); |
|---|
| 322 | | check_status( stat ); |
|---|
| 323 | | |
|---|
| 324 | | MObject groupObj = fnGroup.object( &stat ); |
|---|
| 325 | | check_status( stat ); |
|---|
| 326 | | |
|---|
| 327 | | MPlugArray connections; |
|---|
| 328 | | surfaceShaderPlug.connectedTo( connections, true, false, &stat ); |
|---|
| 329 | | check_status( stat ); |
|---|
| 330 | | |
|---|
| 331 | | for( uint i = 0; i < connections.length(); i++ ) |
|---|
| 332 | | { |
|---|
| 333 | | stat = dgMod.disconnect( connections[i], surfaceShaderPlug ); |
|---|
| 334 | | check_status( stat ); |
|---|
| 335 | | } |
|---|
| 336 | | |
|---|
| 337 | | stat = dgMod.connect( outColorPlug, surfaceShaderPlug ); |
|---|
| 338 | | check_status( stat ); |
|---|
| 339 | | |
|---|
| 340 | | stat = dgMod.doIt(); |
|---|
| 341 | | check_status( stat ); |
|---|
| 342 | | |
|---|
| 343 | | m_shaders.append( groupObj ); |
|---|
| | 260 | MObject sgObj; |
|---|
| | 261 | |
|---|
| | 262 | MItDependencyNodes nodeIter( MFn::kShadingEngine, &stat ); |
|---|
| | 263 | check_status( stat ); |
|---|
| | 264 | |
|---|
| | 265 | for( ; ; ) |
|---|
| | 266 | { |
|---|
| | 267 | bool isDone = nodeIter.isDone( &stat ); |
|---|
| | 268 | check_status( stat ); |
|---|
| | 269 | |
|---|
| | 270 | if( isDone ) |
|---|
| | 271 | break; |
|---|
| | 272 | |
|---|
| | 273 | MObject obj = nodeIter.thisNode( &stat ); |
|---|
| | 274 | check_status( stat ); |
|---|
| | 275 | |
|---|
| | 276 | stat = nodeIter.next(); |
|---|
| | 277 | check_status( stat ); |
|---|
| | 278 | |
|---|
| | 279 | MFnDependencyNode depNode( obj, &stat ); |
|---|
| | 280 | check_status( stat ); |
|---|
| | 281 | |
|---|
| | 282 | MString depName = depNode.name( &stat ); |
|---|
| | 283 | check_status( stat ); |
|---|
| | 284 | |
|---|
| | 285 | if( depName != sgName ) |
|---|
| | 286 | continue; |
|---|
| | 287 | |
|---|
| | 288 | sgObj = obj; |
|---|
| | 289 | break; |
|---|
| | 290 | } |
|---|
| | 291 | |
|---|
| | 292 | if( sgObj.isNull() ) |
|---|
| | 293 | { |
|---|
| | 294 | MDGModifier dgMod; |
|---|
| | 295 | |
|---|
| | 296 | MFnLambertShader fnShader; |
|---|
| | 297 | |
|---|
| | 298 | fnShader.create( true, &stat ); |
|---|
| | 299 | check_status( stat ); |
|---|
| | 300 | |
|---|
| | 301 | fnShader.setName( shaderName, &stat ); |
|---|
| | 302 | check_status( stat ); |
|---|
| | 303 | |
|---|
| | 304 | { |
|---|
| | 305 | MFnTypedAttribute attr; |
|---|
| | 306 | MObject attrObj = attr.create( "originalShaderName", |
|---|
| | 307 | "osn", MFnData::kString, MObject::kNullObj, &stat ); |
|---|
| | 308 | check_status( stat ); |
|---|
| | 309 | |
|---|
| | 310 | stat = fnShader.addAttribute( attrObj ); |
|---|
| | 311 | check_status( stat ); |
|---|
| | 312 | |
|---|
| | 313 | MPlug attrPlug = fnShader.findPlug( attrObj, &stat ); |
|---|
| | 314 | check_status( stat ); |
|---|
| | 315 | |
|---|
| | 316 | stat = attrPlug.setString( MString( shader.shader ) ); |
|---|
| | 317 | check_status( stat ); |
|---|
| | 318 | } |
|---|
| | 319 | |
|---|
| | 320 | MPlug outColorPlug = fnShader.findPlug( MString( "outColor" ), &stat ); |
|---|
| | 321 | check_status( stat ); |
|---|
| | 322 | |
|---|
| | 323 | MObject shaderObj = fnShader.object( &stat ); |
|---|
| | 324 | check_status( stat ); |
|---|
| | 325 | |
|---|
| | 326 | MObject texObj = ImportTexture( shader.shader ); |
|---|
| | 327 | if( texObj != MObject::kNullObj ) |
|---|
| | 328 | { |
|---|
| | 329 | MFnDependencyNode fnTex( texObj, &stat ); |
|---|
| | 330 | check_status( stat ); |
|---|
| | 331 | |
|---|
| | 332 | MPlug texColorPlug = fnTex.findPlug( MString( "outColor" ), &stat ); |
|---|
| | 333 | check_status( stat ); |
|---|
| | 334 | //MPlug texTransPlug = fnTex.findPlug( MString( "outTransparency" ), &stat ); |
|---|
| | 335 | //check_status( stat ); |
|---|
| | 336 | |
|---|
| | 337 | MPlug shaderColorPlug = fnShader.findPlug( MString( "color" ), &stat ); |
|---|
| | 338 | check_status( stat ); |
|---|
| | 339 | //MPlug shaderTransPlug = fnShader.findPlug( MString( "transparency" ), &stat ); |
|---|
| | 340 | //check_status( stat ); |
|---|
| | 341 | |
|---|
| | 342 | |
|---|
| | 343 | stat = dgMod.connect( texColorPlug, shaderColorPlug ); |
|---|
| | 344 | check_status( stat ); |
|---|
| | 345 | //stat = dgMod.connect( texTransPlug, shaderTransPlug ); |
|---|
| | 346 | //check_status( stat ); |
|---|
| | 347 | } |
|---|
| | 348 | |
|---|
| | 349 | MFnSet fnGroup; |
|---|
| | 350 | MSelectionList empty; |
|---|
| | 351 | fnGroup.create( empty, MFnSet::kRenderableOnly, false, &stat ); |
|---|
| | 352 | check_status( stat ); |
|---|
| | 353 | |
|---|
| | 354 | fnGroup.setName( sgName, &stat ); |
|---|
| | 355 | check_status( stat ); |
|---|
| | 356 | |
|---|
| | 357 | MPlug surfaceShaderPlug = fnGroup.findPlug( MString( "surfaceShader" ), &stat ); |
|---|
| | 358 | check_status( stat ); |
|---|
| | 359 | |
|---|
| | 360 | sgObj = fnGroup.object( &stat ); |
|---|
| | 361 | check_status( stat ); |
|---|
| | 362 | |
|---|
| | 363 | MPlugArray connections; |
|---|
| | 364 | surfaceShaderPlug.connectedTo( connections, true, false, &stat ); |
|---|
| | 365 | check_status( stat ); |
|---|
| | 366 | |
|---|
| | 367 | for( uint i = 0; i < connections.length(); i++ ) |
|---|
| | 368 | { |
|---|
| | 369 | stat = dgMod.disconnect( connections[i], surfaceShaderPlug ); |
|---|
| | 370 | check_status( stat ); |
|---|
| | 371 | } |
|---|
| | 372 | |
|---|
| | 373 | stat = dgMod.connect( outColorPlug, surfaceShaderPlug ); |
|---|
| | 374 | check_status( stat ); |
|---|
| | 375 | |
|---|
| | 376 | stat = dgMod.doIt(); |
|---|
| | 377 | check_status( stat ); |
|---|
| | 378 | } |
|---|
| | 379 | |
|---|
| | 380 | m_shaders.append( sgObj ); |
|---|