feat: intelligently determine necessary views for thin objects and update SparkPlug UI to support dynamic number of views
Build and Deploy / build-and-push (push) Successful in 32s

This commit is contained in:
AI Bot
2026-09-02 14:33:16 +05:30
parent 857648292f
commit 0865b02d17
2 changed files with 27 additions and 8 deletions
+23 -3
View File
@@ -382,10 +382,30 @@ app.post('/api/sparkplug/generate-images', authenticate, async (req, res) => {
// Use the Gemini 3.1 Flash Image API
const baseUrl = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash-image:generateContent';
const views = ['Front view', 'Back view', 'Left side view', 'Right side view'];
// Run parallel generation for all 4 views
// Intelligently determine needed views using a text model
const genAI = new GoogleGenerativeAI(apiKey);
const textModel = genAI.getGenerativeModel({ model: "gemini-3.5-flash-lite" });
const viewPrompt = `You are a 3D modeling assistant. The user wants to generate orthographic views for a product based on this description: "${prompt}".
If the product is extremely thin and flat (like a sachet, pouch, packet, paper, or card), we only need the front and back views.
Otherwise, for a standard 3D volume (bottle, box, can, etc), we need front, back, left, and right.
Return ONLY a valid JSON array of strings representing the views needed.
Example 1: ["Front view", "Back view"]
Example 2: ["Front view", "Back view", "Left side view", "Right side view"]`;
let views = ['Front view', 'Back view', 'Left side view', 'Right side view'];
try {
const viewResult = await textModel.generateContent(viewPrompt);
const textResponse = viewResult.response.text().trim();
const match = textResponse.match(/\[.*\]/s);
if (match) {
views = JSON.parse(match[0]);
}
} catch (e) {
console.error("Failed to intelligently determine views, falling back to 4 views", e);
}
// Run parallel generation for determined views
const promises = views.map(async (view, index) => {
const fullPrompt = `A clean, isolated 3D render concept art of: ${prompt}.
Focus ONLY on the object itself.