Image-to-3d
0.1 Quick Start Script Hd Nodejs
// Install axios with npm install axios
import axios from 'axios';
const baseUrl = "http://api.csm.ai:5566/";

function sleep(seconds) {
    const ms = seconds * 1000;
    return new Promise(resolve => setTimeout(resolve, ms));
}

const headers = {
    'Content-Type': 'application/json',
    'x-api-key': '6bCfF4467bXXXXXX4E6B271BeC5'
};

// Upload Stage
const uploadObj = {
    "image_url": "https://via.placeholder.com/300/09f/fff.png",
    "preview_mesh": "hd",
    "pixel_alignment": "highest",
    "model_resolution": "high",
    "resolution": "high_poly",
    "diffusion_time_steps": 75,
    "auto_gen_3d": true,
    "topology": "quads",
    "texture_resolution": 2048
}

// Create the session, this will automatically upload the image and start the spin generation process.
const response = await axios.post(`${baseUrl}image-to-3d-sessions`, uploadObj, { headers: headers });

let imageTo3dSession = response.data.data;

const session_code = imageTo3dSession.session_code;

// console.log(imageTo3dSession);
// {
//     error: '',
//     message: 'Created',
//     statusCode: 201,
//     data: {
//       user_id: 'XXXXXXX',
//       session_code: 'SESSION_1713430448_7229295',
//       image_url: 'https://via.placeholder.com/300/09f/fff.png',
//       status: 'training_preview',
//       topology: 'quads',
//       resolution: 'high_poly',
//       source: 'external',
//       diffusion_time_steps: 75,
//       auto_gen_3d: true,
//       preview_mesh: 'hd',
//       model_resolution: 'high',
//       texture_resolution: 2048,
//       pixel_alignment: 'highest',
//       created_at: '2024-04-18T08:54:08.575Z',
//       updated_at: '2024-04-18T08:54:09.095Z'
//     }
//   }


// Sleep for 15 minutes before making the call to check preview status
await sleep(15*60);

// Check the status of the session
do{
    await sleep(5*60);
    const response = await axios.get(`${baseUrl}image-to-3d-sessions/${session_code}`, { headers: headers });
    imageTo3dSession = response.data.data;
}while (imageTo3dSession.status !== 'preview_done') ;

console.log("preview_done", imageTo3dSession);

// Make the refine job call
const refineResponse = await axios.post(`${baseUrl}image-to-3d-sessions/get-3d/refine/${session_code}`, {}, { headers: headers });

imageTo3dSession = refineResponse.data.data;

// Sleep for a 40 minutes before making the call to check preview status
await sleep(40*60);

// Check the status of the session
do{
    await sleep(5*60);
    const response = await axios.get(`${baseUrl}image-to-3d-sessions/${session_code}`, { headers: headers });
    imageTo3dSession = response.data.data;
    console.log(imageTo3dSession);
}while (imageTo3dSession.status !== 'refine_done') ;




// console.log(imageTo3dSession);
// {
//     _id: 'XXXXXXX',
//     user_id: 'XXXXXXX',
//     session_code: 'SESSION_1713441503_6143414',
//     image_url: 'https://via.placeholder.com/300/09f/fff.png',
//     preview_mesh_url: 'XXXXXXXX',
//     preview_mesh_url_zip: 'XXXXXXXX',
//     preview_mesh_url_glb: 'XXXXXXXXXX',
//     preview_mesh_url_usdz: 'XXXXXXXXXX',
//     preview_mesh_url_fbx: '',
//     status: 'training_refine',
//     topology: 'quads',
//     resolution: 'high_poly',
//     source: 'external',
//     auto_gen_3d: true,
//     model_version: '2.0-turbo',
//     selected_spin: 'XXXXXXXX',
//     is_deleted: false,
//     manual_segmentation: false,
//     preview_mesh: 'hd',
//     pixel_alignment: 'highest',
//     model_resolution: 'high',
//     diffusion_time_steps: 75,
//     selected_spin_index: 0,
//     spins: [
     
//     ],
//     created_at: '2024-04-18T11:58:25.287Z',
//     updated_at: '2024-04-18T12:01:03.539Z',
//   }