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