Uploading, setting camera position, creating a preview/thumbnail

api

(Mr Inka) #1

Edit: Ouch, I played around with the JSON encoding a bit and it seems to work now. I don’t really know what I did to make it work, was my fault, sorry!

  • Only question that is left: Can I somehow create thumbnails for my uploaded models with the API? They appear without any thumbnail until i set one manually.

Here is my working code for the patch by the way:

var headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
    'content-type': 'application/json',
    'accept': 'application/json, text/javascript, */*; q=0.01'
};

var options = {
	url: "https://api.sketchfab.com/v2/models/" + URI + "?token=f13e0a_________00ebfc",
    method: 'PATCH',
    headers: headers,
    body: JSON.stringify(data) //this just takes the whole object from the editor inspect PATCH request
};

function callback(error, response, body) {
	if(!error){
		console.log(" > Patched!")
	}
}
request(options, callback);	


This is solved. You may ignore below



Well, a bit of a complicated post.

So I tried uploading models via the v3 API, which worked fine. To make it easier, I used this NodeJS module: https://github.com/sketchfab/node-sketchfab

Here is the exact code:

function uploadModel(modelName, modelDesc){
    skClient.upload(
        {
            file: path.resolve('./current/itemFile.zip'),
            name: modelName,
            private: false,
            isPublished: true,
            description: modelDesc,
            tags: [],
            categories: [],
            options: {
                shading: 'lit',
                background: {"environment": "4eda3e78ed214dc8852c439dc64b9c9d"},
                orientation: {matrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]}
            }
        },
        function(err, task) {
            if (err) {
                console.log(err);
                return;
            }
            task.on('progress', function(value) {
            	console.log("Progress: " + value.toFixed(1) + "%");
            });
            task.on('success', function(url) {
                console.log("Finished - URL: " + url);
            });
            task.on('error', function(error) {
                console.log(error)
            });
        }
    );  
}

This works fine (except that “orientation” doesn’t seem to change anything).

What I am trying to achieve is the following:

  • Upload a model

  • Set the environment (works)

  • Set the environment rotation (does not work)

  • Set the standard camera position including a zoom level (does not work)

  • Create a thumbnail / preview from the standard camera position (does not work)

I know that some settings can be changed by sending a PATCH via the V3 API. According to the V3 documentation, most settings are missing though. I found this “old” post and I was wondering, if any new options have been added to the V3 API by now: How to edit more complex 3D options through API?

Patching through the V3 API works (only for the same options I can patch from the upload module, so this doesn’t help much).

After reading through everything I could find, I tried patching with the V2. Basically, I copied the request that is being sent by the Sketchfab editor after I edited a model. I removed the materials but kept the property in the object. All models I am planning to upload share the same camera position, environment, lighting etc.The only difference would be the materials.

Here is my approach on patching with V2.

patch("3b2b6ac732c34189aa781e7bab292b74")

function patch(modelUID){
  var data = {"options":{"version":7,"background":{"enable":"environment","uid":"f77703e1f27f4bd384957f9a5b6fc129","color":[0.2,0.2,0.2]},"environment":{"enable":true,"backgroundExposure":1,"exposure":1.2,"rotation":3.5903916041026203,"uid":"4eda3e78ed214dc8852c439dc64b9c9d","blur":0.1,"shadowEnable":true,"lightIntensity":5,"shadowBias":0.005},"lighting":{"enable":false,"lights":[{"type":"SPOT","enable":true,"color":[0.7806122449,0.7985214494,1],"intensity":0,"ground":[0.3,0.2,0.2],"intensityGround":1,"matrix":[0.8611127508405398,-0.50839260113826,-0.0046683273,0,-0.36626156345453464,-0.6266879823417485,0.6878332937,0,-0.352614942088929,-0.5905921909013454,-0.7258536814,0,-6.837625328013586,-11.341198621979638,-8.9242123084,1],"falloff":0.0065037164,"attachedToCamera":false,"angle":45,"hardness":0.5,"castShadows":false,"shadowBias":0.005},{"type":"DIRECTION","enable":true,"color":[1,0.878331945,0.7091836735],"intensity":1,"ground":[0.3,0.2,0.2],"intensityGround":1,"matrix":[-0.708526136295518,0.32228459662484177,0.6277924442,0,-0.5661936339065705,-0.7906158117533882,-0.2331338825,0,0.4212071734777199,-0.5206335341753777,0.7426474533,0,8.333938337088355,-9.969588543938965,19.8672347292,1],"falloff":0.0065037164,"attachedToCamera":false,"angle":45,"hardness":0.5,"castShadows":false,"shadowBias":0.005},{"type":"DIRECTION","enable":true,"color":[0.4234693878,0.7352665556,1],"intensity":0.12,"ground":[0.9642857143,0.6484128637,0.2607507289],"intensityGround":0.06,"matrix":[-0.41379321196563246,0.8978194664620465,-0.1506498699,0,-0.055744463827167856,-0.19015967492043043,-0.980169298,0,-0.9086626064608961,-0.3971895060736386,0.1287352474,0,-17.739501059430353,-7.549343767109912,7.8308662542,1],"falloff":0.0065037164,"attachedToCamera":false,"angle":45,"hardness":0.5,"castShadows":false,"shadowBias":0.005}]},"materials":{},"orientation":{"matrix":[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]},"camera":{"position":[-32.31701315867941,-44.96663362596114,10.2509626094425],"target":[0.5133940119868285,7.465606898640619,5.080569260786353],"fov":45,"nearFarRatio":0.005,"useCameraConstraints":false,"usePanConstraints":true,"useZoomConstraints":false,"usePitchConstraints":false,"useYawConstraints":false,"zoomIn":0,"zoomOut":3308,"left":-3.141593,"right":3.141593,"up":1.555089,"down":-1.555089},"animation":{"order":[],"speed":1,"cycleMode":"one","initializeWithRestPose":false},"hotspot":{"hotspots":[],"visible":true},"vr":{"worldFactor":12.2537558693,"floorHeight":-0.5462219715,"displayFloor":true,"initialCamera":{"position":[0.0757465363,-29.1710566684,-0.5462219715],"rotation":[0,0,0,1]}},"scene":{"postProcess":{"enable":true,"grain":{"enable":false,"animated":false,"factor":0.15},"sharpen":{"enable":false,"factor":0.2},"chromaticAberration":{"enable":false,"factor":0.05},"vignette":{"enable":true,"amount":0.475,"hardness":0.725},"bloom":{"enable":false,"factor":0,"threshold":0.5,"radius":0.7},"toneMapping":{"enable":false,"method":"default","exposure":1,"brightness":0,"contrast":0,"saturation":1},"colorBalance":{"enable":false,"low":[0,0,0],"mid":[1,-1,-1],"high":[0,0,0]},"dof":{"enable":false,"blurNear":0.5,"blurFar":0.5,"focusPoint":[-0.9425225075,-1.5143804848,7.9159166613]},"ssr":{"enable":false,"factor":1},"ssao":{"enable":false,"radius":0.6126877935,"intensity":0.5,"bias":0.1225375587},"taa":{"enable":true,"transparent":true}},"sssProfiles":[{"falloff":[1,0.37,0.3],"strength":[0.48,0.41,0.28]},{"falloff":[0.5,0.67,0.6],"strength":[0.38,0.61,0.68]},{"falloff":[0.7,0.77,0.3],"strength":[0.88,0.61,0.28]}]},"sound":{"soundtracks":[]},"shading":{"renderer":"pbr","type":"lit","vertexColor":{"enable":false,"useAlpha":false,"colorSpace":"srgb"},"pointSize":0},"wireframe":{"enable":false,"color":"000000FF"}}}
  request.patch({
    url:'https://api.sketchfab.com/v2/models/' + modelUID + '?token=f13e_______________ebfc',
    body: JSON.stringify(data),
    json: true,
  },function(error, response, body){ 
  	console.log(body)
  }); 
}

The response I am getting says:

{ detail: 'Parse error - no dict found' }

So … how do I go on?

  • All I would want is to copy camera, environment settings etc. from an existing model that I edited by hand.

  • Can I even generate a preview / thumbnail when uploading / patching headlessly with the api?

Thanks in advance! :slight_smile:


#2

We plan to add more features to the V3 Data API in the future. Setting environment orientation/brightness and camera position would definitely be good additions. A new thumbnail should be generated every time you update settings (if the model is published) or when you publish it.

While the V2 API works with all options, it’s not officially supported and is subject to change without warning.


#3

We are also working on a Presets feature that will allow you to save and copy settings from one model to another.