Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / sceneMaterials Not Updated Right After FBX Import
  RSS 2.0 ATOM  

sceneMaterials Not Updated Right After FBX Import
Rate this thread
 
31482
 
Permlink of this thread  
avatar
  • Total Posts: 50
  • Joined: 02 September 2006 01:02 PM

Hi all,

I noticed the sceneMaterials global variable is empty after importing an FBX file with objects that have materials applied, but it is empty for only about 4 minutes!  After about 4 minutes, the sceneMaterials contains the materials that are listed in the Material Editor under the “scene” under “Browse From:”.  I am using Vista Ultimate (32-bit, SP2) and 3ds Max 2010 (32-bit).  See attachment below for the file “twoballs.zip”.

Here are the steps that I do to reproduce the problem:
01) Open 3ds Max 2010.
02) Reset 3ds Max 2010.
03) Open the MAXScript Listener.
04) Import “twoballs.fbx”.
05) Start my stop watch.
06) Evaluate:
for mat in sceneMaterials do print mat.name
07) In my case, it just said OK, and printed nothing.
08) Open the Material Editor.
09) Click the “Get Material” icon.
10) Select “scene” from the “Browse From:” group.
11) Confirm that there are two Standard materials listed.
12) In my case, the following Standard materials were listed as expected:
“01 - Default ( Standard ) [Sphere01]”
“02 - Default ( Standard ) [Sphere02]”
13) Close the Material/Map Browser.
14) Close the Material Editor.
15) At each remaining 15 second interval, evaluate:
for mat in sceneMaterials do print mat.name
16) In my case, at around 4 minutes, the expression printed:
“01 - Default”
“02 - Default”
17) Repeat steps 2 to 16 to confirm consistent behavior.
18) In my case, it takes around 3 to 4.5 minutes to see the materials in sceneMaterials.

This same behavior happens with other FBX files as well, including files that have Standard as well as mental ray ProMaterials.

If anyone is able to confirm these results, or has any ideas as to what the problem might be, I would be greatfully delighted!

Thanks a ton!

Robert Graf



Robert G Graf
http://www.goofers.org

Attachment Attachment
Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

Max 8, 9, 2008 - Show the materials as “active” immediately (in the Editor), otherwise the same delay as 2010.
Max 2009 - same as 2010.

This suggests that it is an FBX problem which has been around for a long time and is therefore not, specifically, a Max 2010 problem.



Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.

Replies: 0
avatar

Hey there Steve,

Thanks a lot for taking the time to confirm this!  This is a great help.

I noticed something fishy in addition to what I noticed in my first post in this thread.
I will include details in the post below (as I will be submitting this information in a defect report to Autodesk).

Thanks again for the help!

Robert



Robert G Graf
http://www.goofers.org

Replies: 0
avatar

In addition to the observations in the first post of this thread, the delayed update behavior for the sceneMaterials global MAXScript variable also occurs when importing scenes from Wavefront (OBJ), and 3D Studio (3DS) files.  As indicated in the first post, this is also occurring with FBX files as well.  This seems to suggest that there is an issue involving the generic import plugin interface, which all importers are derived from.  I have attached a ZIP file containing the FBX, 3DS, and OBJ files.

Observation:
There appears to be an internal timer in 3ds Max whose timeout setting is at exactly 5 minutes, or 300 seconds.  When the timer expires, it triggers an event that causes the global sceneMaterials variable to be updated to reflect the actual scene materials (as indicated in the Material Editor/Get Material/Browse From:/scene).  After the timer expires, it resets back to 5 minutes, and the cycle continues.  Also, it appears that the sceneMaterial variable is being updated immediately after assigning a new material to an object via the Material Editor, regardless whether or not the timer has expired, which is great.

Potential Solution:
When importing scenes into 3ds Max, the generic 3ds Max import plugin class should issue an update for the sceneMaterials global variable after the specific import plugin (FBX, OBJ, 3DS, etc) has finished completely.

How to Reproduce the Observation:

NOTE—Use a stop watch or timer (with second accuracy) as indicated below (iPhone does a great job at this :) It may be helpful to read all of the steps first to get an idea of the procedure because some of the steps are time sensitive (need to be completed as quickly as possible).

01) Open 3ds Max 2010.

02) Open the MAXScript Listener.

03) Reset 3ds Max.

04) Import the file sphere.obj.
--> Make sure to import materials.
--> For the FBX, use the default Autodesk M&E preset.
--> For the 3DS, use the default import settings.

05) In the MAXScript Listener, evaluate the following statement once per second:
--> Use the stop watch or timer to do this.
--> It may be helpful to copy the statement to the clipboard (CTRL+C),
--> and then simply paste (CTRL+V) the statement and press ENTER,
--> so that the statement evaluates about once every second.
--> NOTE: I tried using the sleep statement and while loop, but that
--> appears to have an effect on the 3ds Max internal timer, so
--> I had to copy and paste once every second instead.

--> MAXScript STATEMENT:
--> for mat in sceneMaterials do print mat.name

--> The statement will most likely print an “OK” in the beginning.
--> When the sceneMaterials variable has been updated,
--> the statement will print the names of any materials.

06) IMPORTANT: As soon as the statement prints the name of any materials, immediately reset the stop watch or timer back to zero, and let it continue to count from zero.  Then, immediately Reset 3ds Max and reimport the sphere.obj file again (try to do all of this as quickly as possible).  The purpose of this step is to synchronize our procedures to zero with the internal 3ds Max timer.

07) Repeat step 05 for the newly imported scene.

08) The statement should print the name of any materials at 5 minutes or 300 seconds, but will print “OK” until then.

09) IMPORTANT: When the statement prints the names of any materials, immediately reset the stop watch or timer back to zero, and let it continue to count from zero.

10) Let the timer count to 2 minutes, or 120 seconds.

11) Once the timer reaches 2 minutes, Reset 3ds Max and reimport the sphere.obj scene.

12) Evaluate the statement to confirm that no materials are printed.  Just an “OK” should be printed.

13) Let the timer count to 4 minutes, or 240 seconds.

14) Once the timer reaches 4 minutes, Reset 3ds Max and reimport the sphere.obj scene.

15) Evaluate the statement to confirm that no materials are printed.  Just an “OK” should be printed.

16) Let the timer count to 4.5 minutes or 270 seconds.

17) Once the timer reaches 4.5 minutes, repeat step 05 (evaluating the statement once every second).

18) The statement should print the names of any materials when the timer reaches 5 minutes or 300 seconds.

19) Repeat steps 03 to 18 for the file sphere.3DS.

20) Repeat steps 03 to 18 for the file sphere.FBX.

Thanks a bunch for any confirmation of these steps!

Robert



Robert G Graf
http://www.goofers.org

Attachment Attachment
Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

I don’t have time to go through all that right now, but if you save the scene the materials show up immediately afterwards. Do you have Autosave set to 5 mins?



Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.

Replies: 0
avatar

Hi Steve,

Thanks a ton!  You got it!  My autosave was set to 5 minutes.  I changed it to 1 minute, and then the update for sceneMaterials changed accordingly, but as you stated, it looks like saving the Max scene causes the sceneMaterials variable to be updated.

So, for now, I’ll use a MAXScript command to save the scene, before using the sceneMaterials, as a temporary solution until a fix is in place.

Thanks again Steve!!
Robert



Robert G Graf
http://www.goofers.org

Replies: 0
avatar

Hehe, sorry I got here so late, but yes, the SceneMaterials variable does not update correctly. Like you found out the best way to force an update is to save the scene. For very heavy scenes it’s better to save a new empty scene, as that will force the update too.

Something like:

theFile (GetDir #Scene + "\\_temp.max") --define the file name
saveNodes #() theFile --save no objects in the file
deleteFile theFile --delete it again


Replies: 0
avatar

Thanks a lot for the script!  This is a great help.

Cheers!
Robert Graf



Robert G Graf
http://www.goofers.org

Replies: 0