SF Editor shows materials but getMaterialsList returns empty array


(Fedemart) #1

Hello all!

I sent the following problem description to support but they haven't responded yet. I wonder if anybody else have had this issue as well?

  • I upload a .obj + .mtl + textures in a zip file through the Data Api
    • mtl file defines the following materials:
      Material6892
      Material152759
      Material152777
      Material152771
  • Model uploads successfully. I can see it both in Sketchfab website and in my local viewer

  • In Sketchfab I can see the Materials list in the editor, as expected.

    • Materials listed:
      Material6892
      Material152759
      Material152777
      Material152771
  • PROBLEM: Locally, running api.getMaterialList returns an empty array

CODE:

 api.getMaterialList( function( err, materials ) {
   console.log(err + " " + materials.length + " materials: " + materials );
 } );

 api.getTextureList( function( err, textures ) {
   console.log(textures.length +  " textures: " +  textures );
 } );

CONSOLE:
null 0 materials:
null 7 textures: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]


#2

Hi,

Sorry I didn't get to your email yet. I cannot reproduce this:

What browser are you using?


(Fedemart) #3

Hi James,

I responded with more detail by e-mail.

I'm using Chrome Version 47.0.2526.106 m and "Web Server for Chrome" extension.
I'm using dev tools with Workspaces enabled.


(Fedemart) #4

Well I realized that the problem is IgetMaterialList doesn't work until the viewer is "ready". getTextures does work so that confused me, but now its solved.

api.addEventListener( 'viewerready', function() {

            // API is ready to use
            // Insert your code here
            console.log( 'Viewer is ready' );

            api.getMaterialList( function( err, materials ) {
            materiales = materials;
            console.log(err + " " + materials.length + " materials: " + materials );
        } );

output:
null 4 materials: [object Object],[object Object],[object Object],[object Object]


#5

Ah yep, I should have caught that!