/
counterbugtech
/
KontrBugCAD
Обзор
Документация
Войти
/
counterbugtech
/
KontrBugCAD
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
js/core/parametric/executors/CreatePrimitiveExecutor.js
1 строка
3 KB
counterbugtech
версия 0.9.37
17 май 2026, 13:43
Верифицирован
17 май 2026, 13:43
31de57b
Код
Авторство
О чём код?
import*as THREE from"three";import{ParametricExecutor}from"./ParametricExecutor.js";import{TubeGeometry}from"generators/primitives/TubeGeometry.js";import{WedgeGeometry}from"generators/primitives/WedgeGeometry.js";import{GableRoofGeometry}from"generators/primitives/GableRoofGeometry.js";import{HalfRoundRoofGeometry}from"generators/primitives/HalfRoundRoofGeometry.js";import{HemisphereGeometry}from"generators/primitives/HemisphereGeometry.js";export class CreatePrimitiveExecutor extends ParametricExecutor{execute(e,r){const{type:t,color:a=8421504,position:o=[0,0,0],name:s="Примитив"}=e.parameters,i=e.parameters.size??25;let m,n=e.parameters.segments??{cube:1,sphere:96,cylinder:128,cone:128,hexagon:6,torus:36,plane:1,pyramid:4,wedge:1,tube:128,frustum:128,polygon:6,wedge:1,gableRoof:1,halfRoundRoof:32,hemisphere:32}[t]??32;const p={type:"primitive",primitiveType:t,color:a,segments:n,originalPosition:o,name:s};switch(t){case"cube":{const r=e.parameters.width??e.parameters.size??i,t=e.parameters.height??e.parameters.size??i,a=e.parameters.depth??e.parameters.size??i;p.width=r,p.height=t,p.depth=a,delete p.size,m=new THREE.BoxGeometry(r,t,a,n,n,n);break}case"sphere":{const r=e.parameters.radius??i/2;p.radius=r,m=new THREE.SphereGeometry(r,n,n);break}case"cylinder":{const r=e.parameters.radius??i/2,t=e.parameters.height??i;p.radius=r,p.height=t,m=new THREE.CylinderGeometry(r,r,t,n,1);break}case"cone":{const r=e.parameters.radius??i/2,t=e.parameters.height??i;p.radius=r,p.height=t,m=new THREE.ConeGeometry(r,t,n);break}case"hexagon":{const r=e.parameters.radius??i/2,t=e.parameters.height??i;p.radius=r,p.height=t,m=new THREE.CylinderGeometry(r,r,t,n);break}case"torus":{const r=e.parameters.majorRadius??i/1.66,t=e.parameters.minorRadius??i/5;p.majorRadius=r,p.minorRadius=t,m=new THREE.TorusGeometry(r,t,n,2*n);break}case"plane":p.size=i,m=new THREE.BoxGeometry(i,i,.01,n,n,n);break;case"pyramid":{const r=e.parameters.radius??i/2,t=e.parameters.height??i;p.radius=r,p.height=t,m=new THREE.ConeGeometry(r,t,n);break}case"tube":{const r=e.parameters.outerRadius??i/2,t=e.parameters.innerRadius??i/4,a=e.parameters.height??i;p.outerRadius=r,p.innerRadius=t,p.height=a,m=new TubeGeometry(r,t,a,n);break}case"frustum":{const r=e.parameters.bottomRadius??i/2,t=e.parameters.topRadius??i/4,a=e.parameters.height??i;p.bottomRadius=r,p.topRadius=t,p.height=a,m=new THREE.CylinderGeometry(t,r,a,n,1);break}case"wedge":{const r=e.parameters.width??i,t=e.parameters.height??i,a=e.parameters.depth??i;p.width=r,p.height=t,p.depth=a,m=new WedgeGeometry(r,t,a);break}case"gableRoof":{const r=e.parameters.width??i,t=e.parameters.height??.6*i,a=e.parameters.depth??i;p.width=r,p.height=t,p.depth=a,m=new GableRoofGeometry(r,t,a);break}case"halfRoundRoof":{const r=e.parameters.radius??i/2,t=e.parameters.height??i;e.parameters.depth;p.radius=r,p.height=t,m=new HalfRoundRoofGeometry(r,t,n);break}case"hemisphere":{const r=e.parameters.radius??i/2;p.radius=r,m=new HemisphereGeometry(r,n,Math.max(1,Math.floor(n/2)));break}default:console.warn(`Unknown primitive type: ${t}, falling back to cube`),p.size=i,m=new THREE.BoxGeometry(i,i,i)}m.computeBoundingBox();const h=m.boundingBox,u=h.max.y-h.min.y,d=new THREE.MeshPhongMaterial({color:a}),c=new THREE.Mesh(m,d);c.castShadow=!0,c.receiveShadow=!0;const g=(new THREE.Vector3).fromArray(o);return"plane"!==t&&(g.y+=u/2),c.position.copy(g),"plane"===t&&(c.rotation.x=-Math.PI/2),e.outputs.length>0?c.uuid=e.outputs[0]:e.outputs=[c.uuid],c.userData=p,c}}