Обновить furniture.js

This commit is contained in:
svoboda200786 2025-08-16 09:09:46 +00:00
parent 90bab56b42
commit 4fcf268789

View File

@ -1,73 +1,73 @@
// server.js // server.js 2
const express = require('express'); const express = require('express');
const path = require('path'); const path = require('path');
const app = express(); const app = express();
// --- ИЗМЕНЕНИЕ: Используйте порт 3201, как в вашем конфиге прокси --- // --- ИЗМЕНЕНИЕ: Используйте порт 3201, как в вашем конфиге прокси ---
const PORT = 3201; const PORT = 3201;
app.use(express.json()); app.use(express.json());
// Раздаем ТОЛЬКО нашу папку 'public' // Раздаем ТОЛЬКО нашу папку 'public'
app.use(express.static(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, 'public')));
// --- УДАЛЕНО: Раздача папок build и jsm больше не нужна --- // --- УДАЛЕНО: Раздача папок build и jsm больше не нужна ---
// app.use('/build', express.static(path.join(__dirname, 'node_modules/three/build'))); // app.use('/build', express.static(path.join(__dirname, 'node_modules/three/build')));
// app.use('/jsm', express.static(path.join(__dirname, 'node_modules/three/examples/jsm'))); // app.use('/jsm', express.static(path.join(__dirname, 'node_modules/three/examples/jsm')));
// API эндпоинт для расчета цены (без изменений) // API эндпоинт для расчета цены (без изменений)
const PRICE_CONFIG = { const PRICE_CONFIG = {
edgeBandingPerMeter: 50, edgeBandingPerMeter: 50,
baseWorkCost: 3000, baseWorkCost: 3000,
}; };
const MATERIALS_PRICES = { const MATERIALS_PRICES = {
'Белый': 1500, 'Белый': 1500,
'Серый': 1650, 'Серый': 1650,
'Черный': 1800, 'Черный': 1800,
'Образец1': 2200, 'Образец1': 2200,
'Образец2': 2500, 'Образец2': 2500,
}; };
const PANEL_THICKNESS = 16; const PANEL_THICKNESS = 16;
app.post('/api/calculate-price', (req, res) => { app.post('/api/calculate-price', (req, res) => {
const params = req.body; const params = req.body;
const pricePerM2 = MATERIALS_PRICES[params.materialName]; const pricePerM2 = MATERIALS_PRICES[params.materialName];
if (!pricePerM2) { if (!pricePerM2) {
return res.status(400).json({ error: 'Invalid material name' }); return res.status(400).json({ error: 'Invalid material name' });
} }
const { width, height, depth, columns, rows } = params; const { width, height, depth, columns, rows } = params;
const M_IN_MM = 1000; const M_IN_MM = 1000;
let totalAreaM2 = 0; let totalAreaM2 = 0;
let totalEdgeLengthM = 0; let totalEdgeLengthM = 0;
const innerWidth = width - 2 * PANEL_THICKNESS; const innerWidth = width - 2 * PANEL_THICKNESS;
const innerHeight = height - 2 * PANEL_THICKNESS; const innerHeight = height - 2 * PANEL_THICKNESS;
const shelfDepth = depth - PANEL_THICKNESS; const shelfDepth = depth - PANEL_THICKNESS;
totalAreaM2 += (2 * height * depth) / (M_IN_MM * M_IN_MM); totalAreaM2 += (2 * height * depth) / (M_IN_MM * M_IN_MM);
totalAreaM2 += (2 * width * depth) / (M_IN_MM * M_IN_MM); totalAreaM2 += (2 * width * depth) / (M_IN_MM * M_IN_MM);
totalEdgeLengthM += (2 * height + 2 * width) / M_IN_MM; totalEdgeLengthM += (2 * height + 2 * width) / M_IN_MM;
totalAreaM2 += (innerWidth * innerHeight) / (M_IN_MM * M_IN_MM); totalAreaM2 += (innerWidth * innerHeight) / (M_IN_MM * M_IN_MM);
const numDividers = columns - 1; const numDividers = columns - 1;
if (numDividers > 0) { if (numDividers > 0) {
totalAreaM2 += (numDividers * innerHeight * shelfDepth) / (M_IN_MM * M_IN_MM); totalAreaM2 += (numDividers * innerHeight * shelfDepth) / (M_IN_MM * M_IN_MM);
totalEdgeLengthM += (numDividers * innerHeight) / M_IN_MM; totalEdgeLengthM += (numDividers * innerHeight) / M_IN_MM;
} }
const numShelves = rows - 1; const numShelves = rows - 1;
if (numShelves > 0) { if (numShelves > 0) {
const sectionWidth = (innerWidth - (numDividers * PANEL_THICKNESS)) / columns; const sectionWidth = (innerWidth - (numDividers * PANEL_THICKNESS)) / columns;
const totalShelfArea = (columns * numShelves * sectionWidth * shelfDepth) / (M_IN_MM * M_IN_MM); const totalShelfArea = (columns * numShelves * sectionWidth * shelfDepth) / (M_IN_MM * M_IN_MM);
totalAreaM2 += totalShelfArea; totalAreaM2 += totalShelfArea;
const totalShelfEdgeLength = (columns * numShelves * sectionWidth) / M_IN_MM; const totalShelfEdgeLength = (columns * numShelves * sectionWidth) / M_IN_MM;
totalEdgeLengthM += totalShelfEdgeLength; totalEdgeLengthM += totalShelfEdgeLength;
} }
const materialCost = totalAreaM2 * pricePerM2; const materialCost = totalAreaM2 * pricePerM2;
const edgeBandingCost = totalEdgeLengthM * PRICE_CONFIG.edgeBandingPerMeter; const edgeBandingCost = totalEdgeLengthM * PRICE_CONFIG.edgeBandingPerMeter;
const finalPrice = PRICE_CONFIG.baseWorkCost + materialCost + edgeBandingCost; const finalPrice = PRICE_CONFIG.baseWorkCost + materialCost + edgeBandingCost;
res.json({ price: Math.round(finalPrice) }); res.json({ price: Math.round(finalPrice) });
}); });
app.listen(PORT, () => { app.listen(PORT, () => {
console.log(`Сервер конструктора мебели запущен на порту: ${PORT}`); console.log(`Сервер конструктора мебели запущен на порту: ${PORT}`);
}); });