Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Scene opened callback and dx11Shader

1 REPLY 1
SOLVED
Reply
Message 1 of 2
rflannery
896 Views, 1 Reply

Scene opened callback and dx11Shader

We have a script that runs in Maya whenever a file is opened to redirect shader paths to the correct location.  Originally this was set up as a script job on the "SceneOpened" event, and it worked.  But then we found out that it was not running in Maya standalone mode.  So we converted the script job to a callback that runs on the "MSceneMessage.kAfterOpen" event.  That made the script run in both Maya GUI and standalone mode.

 

The problem now is that the shaders don't seem to load correctly (when the scene is opened).  The light binding "Automatic Bind" all show "none" as a value, and the lighting is broken on the model.  Clicking the "reload fx file" icon in the Attribute Editor or running the following command fixes the problem:

cmds.dx11Shader('myTestMaterial', reload=True)

But the user should not have to click the "reload fx file" icon every time they open a scene.

 

I tried adding that dx11Shader reload command to the callback function, but it didn't change anything.  As far as I can tell, when a scene is opened, Maya runs my callback.  Then it runs a "scene opened" callback that is internal to the dx11Shader plugin.  It seems that if my function is run *after* that internal callback (like when it was using a script job instead of a callback), then it works.  But if it is run before the dx11Shader internal callback, then this weird broken state happens.

 

Questions:

(Answers to any or all would be appreciated.)

* Why doesn't running cmds.dx11Shader('myTestMaterial', reload=True) in my callback function fix the problem?

* Is there any way I can force my callback to run after the dx11Shader callback?

* Am I going about this the wrong way completely?  Like there is some other way I am overlooking?

 

 

1 REPLY 1
Message 2 of 2
rflannery
in reply to: rflannery

Okay, I think I have finally figured this out.

Short version:  Fix the problem by triggering the callback off of MEventMessage "PostSceneRead" (instead of MSceneMessage.kAfterOpen).

Long version:
I set up some callbacks for various triggers, and had them print out, so that I could see when each callback was run.  When opening a file, the order was like this:

  • MSceneMessage.kSceneUpdate
  • MSceneMessage.kAfterFileRead
  • MSceneMessage.kAfterFileRead
  • MEventMessage 'PostSceneRead'
  • MSceneMessage.kSceneUpdate
  • MSceneMessage.kAfterOpen


Then I tried running my callback from different triggers.  The results were as follows:

  • MSceneMessage.kAfterFileRead - worked
  • MEventMessage 'PostSceneRead' - worked
  • MSceneMessage.kSceneUpdate - worked/failed intermettently, with no discernable pattern
  • MSceneMessage.kAfterOpen  - failed


Based on this information, what I think is happening is that the "dx11Shader" plugin has an internal callback that does something with the lighting.  If my callback is run after the dx11Shader's callback, then my lighting is broken; if my callback is run first, then my lighting works.  I believe the dx11Shader's callback is triggered off of MSceneMessage.kSceneUpdate.  This would explain why trying to trigger my own callback off of MSceneMessage.kSceneUpdate worked or failed randomly.  As far as I know, when two callbacks are connected to the same trigger, there is no way to enforce the order in which they will be executed.

So triggering off of 'PostSceneRead' works because it happens before that kSceneUpdate.  Triggering off of kAfterFileRead works, too.  But I decided not to do that, because it could be triggered multiple times when a file is opened (i.e. when opening a scene that has referenced files.)

Oh, and cmds.dx11Shader(shaderNode, reload=True) is no longer needed in my callback script.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report