How to edit more complex 3D options through API?


#21

Can you post your full script for me (minus your real token)?


(Solsnare) #22

console.log("Trying to get all data for model at https://api.sketchfab.com/i/models/{UID}");
var internalModelEndpoint = "https://api.sketchfab.com/i/models/";
var testModel = "b664fc7cae49475185ce42b9bb5371e8";
restler.get(internalModelEndpoint + testModel)
    .on("complete", function(results) {
        console.log("Got what i wanted from this");
        console.log(util.inspect(results));
        console.log("------------UPDATING MATERIAL INFO------------");
        UpdateMaterialInfo(results);
        var v2ModelPatchEndPoint = "https://api.sketchfab.com/i/models/";
        console.log("PATCHING THE MODEL WITH NEW UPDATED DATA");
        for (var x in results.options.materials) {
            var mat = results.options.materials[x];
            if (mat.name == undefined) continue;
            console.log(util.inspect(mat.channels.AlbedoPBR));
        }
        var fullUrl = v2ModelPatchEndPoint + testModel + "?token=" + APIToken;
        console.log("Sending patch request to this url: " + fullUrl);
        restler.patch(v2ModelPatchEndPoint + testModel + "?token=" + APIToken, {
            headers: header,
            data: {
                results
            }
        }).on("complete", function(result2) {
            console.log("Finished patching the data: " + util.inspect(result2));
        });
    });

It's Node.JS, using Restler to send the REST requests.

Sorry for the crappy formatting, i cant seem to get it to maintain it... It doesnt look this way when i post, actually is tabbed.


#23

I fixed the formatting.

Do you have a raw PATCH request with the data payload hard-coded?


(Solsnare) #24

Sorry? Not sure what you mean by Raw data hard coded.

All that's happening here is i get the data with the get request on "i/models/{uid}"

grab the data, modify value i wanted,

then send the data back to "i/models/{uid}".

BTW, Thanks for fixing the formatting!


#25

Yes, can you send me an example PATCH data object?


(Solsnare) #26

-----------START OF PATCH DATA----------
{ status: { code: 0, processing: 'SUCCEEDED', warning: {}, error: {} },
  uid: 'b664fc7cae49475185ce42b9bb5371e8',
  publishedAt: '2017-07-10T03:11:28.369898',
  likeCount: 0,
  commentCount: 0,
  archiveSize: 49986,
  isDownloadAllowed: true,
  isDeleted: false,
  viewCount: 1,
  processingStatus: 2,
  staffpickedAt: null,
  isDownloadable: false,
  isRestricted: false,
  isPrivate: false,
  embedUrl: 'https://sketchfab.com/models/b664fc7cae49475185ce42b9bb5371e8/embed',
  files:
   [ { wireframeSize: 13900,
       uid: '0e3767117b874587bfa36e287150526c',
       osgjsUrl: 'https://dg5bepmjyhz9h.cloudfront.net/urls/b664fc7cae49475185ce42b9bb5371e8/dist/models/0e3767117b874587bfa36e287150526c/file.osgjs.gz',
       flag: 0,
       modelSize: 41752,
       osgjsSize: 9304 } ],
  description: 'Created by: WordHomie in JuicyVoxels',
  tags: [],
  viewerUrl: 'https://sketchfab.com/models/b664fc7cae49475185ce42b9bb5371e8',
  isProtected: false,
  categories: [],
  vertexCount: 898,
  user:
   { username: 'solsnare',
     account: 'free',
     displayName: 'solsnare',
     uid: '6689b156e06544309227656862eaf7ae',
     avatars: { images: [Object], uid: 'b1d05a8e761f43fd861eccc50e92a30e' },
     profileUrl: 'https://sketchfab.com/solsnare' },
  originalFileName: 'CHAR2',
  thumbnails:
   { images: [ [Object], [Object], [Object], [Object] ],
     uid: '54aa6a3020004f27b4a9564899d7d5eb' },
  animationCount: 0,
  name: 'Wordsicles',
  license: null,
  editorUrl: 'https://sketchfab.com/models/b664fc7cae49475185ce42b9bb5371e8/edit',
  isPublished: true,
  createdAt: '2017-07-10T03:11:20.578235',
  faceCount: 1422,
  ext: 'obj',
  downloadCount: 0,
  options:
   { sound: { soundtracks: [] },
     version: 4,
     orientation: { matrix: [Object] },
     wireframe: { color: '000000FF', enable: false },
     scene: { fov: 45, nearFarRatio: 0.005, postProcess: [Object] },
     hotspot: { hotspots: [] },
     materials:
      { '832e3031-146e-4742-aafa-68ce96028a26': [Object],
        updatedAt: 14998088430 },
     environment:
      { backgroundExposure: 1,
        enable: true,
        uid: 'd348dfd2a8104ab0b8528f885d645eb3',
        shadowEnable: true,
        shadowBias: 0.005,
        blur: 0.1,
        lightIntensity: 1,
        rotation: 0,
        exposure: 2.1402 },
     vr:
      { floorHeight: -22,
        scale: 18.7232955419,
        initialCamera: [Object] },
     camera:
      { right: 3.1415926536,
        useCameraConstraints: false,
        target: [Object],
        zoomOut: 748,
        up: 1.5550883635,
        down: -1.5550883635,
        usePitchConstraints: false,
        useYawConstraints: false,
        position: [Object],
        useZoomConstraints: false,
        zoomIn: 0,
        left: -3.1415926536 },
     lighting: { lights: [Object], enable: false },
     background:
      { color: [Object],
        enableVR: false,
        enable: 'color',
        uid: '51af6a870cce449eb75b0345feebaebb' },
     updatedAt: '2017-07-11T21:59:19.515739',
     shading:
      { vertexColor: [Object],
        type: 'lit',
        pointSize: 2,
        renderer: 'pbr' },
     animation: { speed: 1, order: [], cycleMode: 'one', autoplay: false },
     createdAt: '2017-07-10T03:11:20.599901' } }
------------END OF PATCH DATA------------

#27

Ok, you should get rid of everything outside options and only include the settings you're actually need to change inside options.


(Solsnare) #28

I don't see how this is going to stop this request from giving me the authentication error. The endpoint doesn't even let me go far enough to do anything.

Should i be using the V2 endpoint you're describing? I explained above the last time i used it all it did was return what seemed to be the result of a V3 models/{uid} get request.

Doing what you said above.. Will report back soon.

BTW:

this conflicts with what you said prior:

unless i misunderstood?


(Solsnare) #29

OK. Did what you said

this code

console.log("Trying to get all data for model at https://api.sketchfab.com/i/models/{UID}");
    var internalModelEndpoint = "https://api.sketchfab.com/i/models/";
    var testModel = "b664fc7cae49475185ce42b9bb5371e8";
    restler.get(internalModelEndpoint + testModel)
        .on("complete", function (results) {
            console.log("------------UPDATING MATERIAL INFO------------");
            UpdateMaterialInfo(results, function (modifiedResults) {
                var v2ModelPatchEndPoint = "https://api.sketchfab.com/i/models/";
                console.log("PATCHING THE MODEL WITH NEW UPDATED DATA");
                for (var x in results.options.materials) {
                    var mat = results.options.materials[x];
                    if (mat.name == undefined) continue;
                    console.log(util.inspect(mat.channels.AlbedoPBR));
                }
                var fullUrl = v2ModelPatchEndPoint + testModel + "?token=" + APIToken;
                console.log("Sending patch request to this url: " + fullUrl);

                console.log("-----MODIFIED RESULTS-----\n"+util.inspect(modifiedResults));

                restler.patch(v2ModelPatchEndPoint + testModel + "?token=" + APIToken, {
                    headers: header,
                    data: {
                        modifiedResults
                    }
                }).on("complete", function (result2) {
                    console.log("Finished patching the data: " + util.inspect(result2));
                });
            });
        });

generated this

Sending patch request to this url: https://api.sketchfab.com/i/models/API_TOKEN
-----MODIFIED RESULTS-----
{ options:
   { materials:
      { channels: [Object],
        name: 'Default1',
        shadeless: false,
        stateSetID: 1,
        version: 3,
        cullFace: 'DISABLE',
        id: '832e3031-146e-4742-aafa-68ce96028a26',
        reflection: 0.1 } } }
Finished patching the data: { detail: 'Authentication credentials were not provided.' }

Here i'm sending the patch request to v2 instead of i

var v2ModelPatchEndPoint = "https://api.sketchfab.com/v2/models/";

this is the result:

Sending patch request to this url: https://api.sketchfab.com/v2/models/b664fc7cae49475185ce42b9bb5371e8
-----MODIFIED RESULTS-----
{ options:
   { materials:
      { stateSetID: 1,
        name: 'Default1',
        shadeless: false,
        channels: [Object],
        version: 3,
        cullFace: 'DISABLE',
        id: '832e3031-146e-4742-aafa-68ce96028a26',
        reflection: 0.1 } } }
Finished patching the data:
{ uid: 'b664fc7cae49475185ce42b9bb5371e8',
  publishedAt: '2017-07-10T03:11:28.369898',
  likeCount: 0,
  commentCount: 0,
  isDownloadAllowed: true,
  isDownloadable: false,
  processingStatus: 2,
  staffpickedAt: null,
  isPrivate: false,
  embedUrl: 'https://sketchfab.com/models/b664fc7cae49475185ce42b9bb5371e8/embed',
  description: 'Created by: WordHomie in JuicyVoxels',
  tags: [],
  viewerUrl: 'https://sketchfab.com/models/b664fc7cae49475185ce42b9bb5371e8',
  isProtected: false,
  vertexCount: 898,
  user:
   { username: 'solsnare',
     account: 'free',
     displayName: 'solsnare',
     uid: '6689b156e06544309227656862eaf7ae',
     avatars: { images: [Object], uid: 'b1d05a8e761f43fd861eccc50e92a30e' },
     profileUrl: 'https://sketchfab.com/solsnare' },
  date: '2017-07-10T03:11:20.578235',
  urlid: 'b664fc7cae49475185ce42b9bb5371e8',
  categories: [],
  thumbnails:
   { images: [ [Object], [Object], [Object], [Object] ],
     uid: '54aa6a3020004f27b4a9564899d7d5eb' },
  viewCount: 1,
  name: 'Wordsicles',
  license: null,
  editorUrl: 'https://sketchfab.com/models/b664fc7cae49475185ce42b9bb5371e8/edit',
  faceCount: 1422,
  downloadCount: 0 }

At least theres no authentication error, but still appears to be doing nothing..

This is getting really annoying... can you please provide a solution on how you're supposed to accomplish something like this? How is the 3d options web tool doing it? What sort of authentication is it looking for?


#30

Sorry for the confusion. I meant, for example, you must include every post-processing filter, even if you are only setting one of them.

I'm looking into this for you further.


(Solsnare) #31

Ah alright, thanks for clearing that up.

That'd be wonderful, i'll be waiting and messing around with the viewer API till then.

Thanks a lot in advance for taking this time to help me.


(Solsnare) #32

Any developments so far?

I'm just working on other infrastructure till then but this is definitely an annoyance.

There is one more solution, if it even exists, is it possible to include some sort of specific "Sketchfab Settings" file that sketch can read from to further configure the rest of whats needed?


#33

We have a prototype "Presets" feature that allows you to copy settings from one model to another:

https://docs.google.com/document/u/1/d/1YK8LITNqAMXwPtIe8Rvx37N0M3BMgaI63qbl3UGZP1c/pub


(Solsnare) #34

This looks to be a wonderful up and coming feature,
However this would not be solving my problem as i don't believe there is any way to set a preset to be used every time a model is uploaded through our account (or another users account).

Just to clarify what exactly my logistical problem is:
My models are being uploaded from our app, into our marketplace and we are using sketchfab to display the models.
The problem comes in how sketchfab chooses to display the model, it uses trilinear filtering, rather than point (or nearest). for the textures, making them look disgusting.

The problem is created because OUR models use very low quality textures that are meant to be used within games and rendered very quickly, so they look pixelly by design, which is something sketchfab is not very friendly towards when it comes to the API.

I've gotten as far as getting the material ID's, and changing the specific data within that. But the FINAL problem is that i can't seem to send this into sketchfabs api in anyway that causes the change to occur on the material.. no matter what i do.

Sorry for reiterating if you understood all of this, but i really can't progress without your side providing me on how i need to communicate to your API.


(Stephomi) #35

Just tried it and got the same issue as you.

It looks like the "options" keys has been stripped off from the v2 data api (being a deprecated/unsupporteed API end point, that's not really surprising though).

I'll see with our backend developers to see if it can/should be fixed and we'll ping you back.


(Solsnare) #36

Ok, that'd be fantastic!

I'll be sitting here twiddling my thumbs in anticipation till then :smiley:


(Stephomi) #37

var xhrGet = new XMLHttpRequest();
var uid = 'yolo';

xhrGet.open('GET', 'https://api.sketchfab.com/i/models/' + uid, true);
xhrGet.onload = function() {
    var xhrPatch = new XMLHttpRequest();

    xhrPatch.open('PATCH', 'https://api.sketchfab.com/v2/models/' + uid + '?token=' + token, true);

    xhrPatch.onload = function() {
        console.log(xhrPatch.responseText);
    };

    var result = JSON.parse(xhrGet.responseText);
    var opt = {
        options: result.options
    };

    opt.options.shading.type = 'shadeless';

    var str = JSON.stringify(opt);

    xhrPatch.setRequestHeader("Content-type","application/json");
    xhrPatch.send(str);
};

xhrGet.send();

^ Here is the "valid" way to use the v2 api to patch every options.
However it won't work because there's another issue (but at least you'll get an error).

We'll keep you up to date when we'll fix it.


(Solsnare) #38

Hmmm

What code am i supposed to be getting? Cause this url
https://api.sketchfab.com/v2/models/b664fc7cae49475185ce42b9bb5371e8?token=API_TOKEN

keeps giving me back a response that looks like a v2 get request..

Additionally this code looks identical (Though done with another plugin or something) except that i didnt set the request header, but i tried that too and it seems to echo the get.

this is what im talking about btw:

Finished patching the data:
{ uid: 'b664fc7cae49475185ce42b9bb5371e8',
  publishedAt: '2017-07-10T03:11:28.369898',
  likeCount: 0,
  commentCount: 0,
  isDownloadAllowed: true,
  isDownloadable: false,
  processingStatus: 2,
  staffpickedAt: null,
  isPrivate: false,
  embedUrl: 'https://sketchfab.com/models/b664fc7cae49475185ce42b9bb5371e8/embed',
  description: 'Created by: WordHomie in JuicyVoxels',
  tags: [],
  viewerUrl: 'https://sketchfab.com/models/b664fc7cae49475185ce42b9bb5371e8',
  isProtected: false,
  vertexCount: 898,
  user:
   { username: 'solsnare',
     account: 'free',
     displayName: 'solsnare',
     uid: '6689b156e06544309227656862eaf7ae',
     avatars: { images: [Object], uid: 'b1d05a8e761f43fd861eccc50e92a30e' },
     profileUrl: 'https://sketchfab.com/solsnare' },
  date: '2017-07-10T03:11:20.578235',
  urlid: 'b664fc7cae49475185ce42b9bb5371e8',
  categories: [],
  thumbnails:
   { images: [ [Object], [Object], [Object], [Object] ],
     uid: '54aa6a3020004f27b4a9564899d7d5eb' },
  viewCount: 1,
  name: 'Wordsicles',
  license: null,
  editorUrl: 'https://sketchfab.com/models/b664fc7cae49475185ce42b9bb5371e8/edit',
  faceCount: 1422,
  downloadCount: 0 }

(Stephomi) #39

If you try to patch a recent model you should get the error (until we fix the issue) :

{"detail":{"materials":["Texture(s) with uid 35c4d334eded44d8a657f390954a32dd doesn't exist."]}}

I just tried to paste my code snippet in a new tab (in chrome console) and I did receive this error.

The request header is important, also my code isn't using any plugins, XMLHttpRequest is native js.


(Solsnare) #40

Ah ok, i'm using Restler (plugin for communicating with REST apis) and it's not giving me this.

I'll try with your native code and see what happens.

As for the fix for this error, any ETA on the issue being fixed?

I'll continue doing the viewer API for this issue on my website if this will take more than a week.

If not, i'll wait around till i can apply the more useful fix.

Thank you @stephomi