2D to 3D
The Youzu 3D Lens Component Transforms 2D product images into interactive 3D models.
API
The 2D to 3D API allows you to convert 2D product images into interactive 3D models. This is an asynchronous process that requires polling for job completion.
Authentication
You can authenticate using either:
Option 1: Authorization: Bearer YOUR_TOKEN header (obtain from /api/v1/token)
Option 2: x-client-secret: YOUR_CLIENT_SECRET header
Create 2D to 3D Conversion
Endpoint: POST /api/v1/2d-to-3d
Convert 2D images to 3D models. Supports uploading multiple images of the same product from different angles for better results.
curl -X POST "https://platform.youzu.ai/api/v1/2d-to-3d" \
-H "Authorization: Bearer YOUR_TOKEN" \
-F "images=@product-front.jpg" \
-F "images=@product-side.jpg" \
-F "images=@product-back.jpg"
curl -X POST "https://platform.youzu.ai/api/v1/2d-to-3d" \
-H "x-client-secret: YOUR_CLIENT_SECRET" \
-F "images=@product-front.jpg" \
-F "images=@product-side.jpg" \
-F "images=@product-back.jpg"
// Convert 2D images to 3D model using token
const formData = new FormData();
formData.append('images', document.getElementById('image1').files[0]);
formData.append('images', document.getElementById('image2').files[0]);
fetch('https://platform.youzu.ai/api/v1/2d-to-3d', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
},
body: formData
})
.then(response => response.json())
.then(data => {
console.log('Conversion started:', data);
// Poll for completion using data.id
})
.catch(error => {
console.error('Error:', error);
});
// Convert 2D images to 3D model using client secret
const formData = new FormData();
formData.append('images', document.getElementById('image1').files[0]);
formData.append('images', document.getElementById('image2').files[0]);
fetch('https://platform.youzu.ai/api/v1/2d-to-3d', {
method: 'POST',
headers: {
'x-client-secret': 'YOUR_CLIENT_SECRET'
},
body: formData
})
.then(response => response.json())
.then(data => {
console.log('Conversion started:', data);
// Poll for completion using data.id
})
.catch(error => {
console.error('Error:', error);
});
import requests
# Convert 2D images to 3D model using token
url = 'https://platform.youzu.ai/api/v1/2d-to-3d'
headers = {
'Authorization': 'Bearer YOUR_TOKEN'
}
files = [
('images', open('product-front.jpg', 'rb')),
('images', open('product-side.jpg', 'rb'))
]
response = requests.post(url, headers=headers, files=files)
if response.status_code == 200:
job = response.json()
print('Conversion started:', job)
# Poll for completion using job['id']
else:
print('Error:', response.status_code, response.text)
import requests
# Convert 2D images to 3D model using client secret
url = 'https://platform.youzu.ai/api/v1/2d-to-3d'
headers = {
'x-client-secret': 'YOUR_CLIENT_SECRET'
}
files = [
('images', open('product-front.jpg', 'rb')),
('images', open('product-side.jpg', 'rb'))
]
response = requests.post(url, headers=headers, files=files)
if response.status_code == 200:
job = response.json()
print('Conversion started:', job)
# Poll for completion using job['id']
else:
print('Error:', response.status_code, response.text)
Get Conversion Status
Endpoint: GET /api/v1/2d-to-3d/{id}
Check the status of a 2D to 3D conversion job.
curl -X GET "https://platform.youzu.ai/api/v1/2d-to-3d/YOUR_JOB_ID" \
-H "Authorization: Bearer YOUR_TOKEN"
curl -X GET "https://platform.youzu.ai/api/v1/2d-to-3d/YOUR_JOB_ID" \
-H "x-client-secret: YOUR_CLIENT_SECRET"
// Check conversion status using token
fetch('https://platform.youzu.ai/api/v1/2d-to-3d/YOUR_JOB_ID', {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
}
})
.then(response => response.json())
.then(data => {
console.log('Job status:', data.status);
if (data.status === 'COMPLETED') {
console.log('3D model URL:', data.outputUrls[0]);
}
})
.catch(error => {
console.error('Error:', error);
});
// Check conversion status using client secret
fetch('https://platform.youzu.ai/api/v1/2d-to-3d/YOUR_JOB_ID', {
method: 'GET',
headers: {
'x-client-secret': 'YOUR_CLIENT_SECRET'
}
})
.then(response => response.json())
.then(data => {
console.log('Job status:', data.status);
if (data.status === 'COMPLETED') {
console.log('3D model URL:', data.outputUrls[0]);
}
})
.catch(error => {
console.error('Error:', error);
});
import requests
# Check conversion status using token
url = 'https://platform.youzu.ai/api/v1/2d-to-3d/YOUR_JOB_ID'
headers = {
'Authorization': 'Bearer YOUR_TOKEN'
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
job = response.json()
print('Job status:', job['status'])
if job['status'] == 'COMPLETED':
print('3D model URL:', job['outputUrls'][0])
else:
print('Error:', response.status_code, response.text)
import requests
# Check conversion status using client secret
url = 'https://platform.youzu.ai/api/v1/2d-to-3d/YOUR_JOB_ID'
headers = {
'x-client-secret': 'YOUR_CLIENT_SECRET'
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
job = response.json()
print('Job status:', job['status'])
if job['status'] == 'COMPLETED':
print('3D model URL:', job['outputUrls'][0])
else:
print('Error:', response.status_code, response.text)
SDK
Props
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
alt |
alt |
The alt text for the image | string | '' |
height |
height |
The height of the component | string | undefined |
modelSrc |
model-src |
The 3D model URL (.gib file) | string | undefined |
showLoader |
show-loader |
Manually control the loading state (for demo purposes) | boolean | false |
src |
src |
The source URL of the image | string | undefined |
width |
width |
The width of the component | string | undefined |
Events
| Event | Description | Type |
|---|---|---|
viewChange |
Event emitted when view mode changes (2D to 3D or vice versa) | CustomEvent<ViewChangeEventData> |
Methods
| Method | Parameters | Return Type | Description |
|---|---|---|---|
switchTo3D |
options?: LensOptions |
Promise<void> |
Switch to 3D view |
toggleView |
Promise<void> |
Toggle between 2D and 3D views |