markuno_lib 1.2.61 → 1.2.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/markcad.js +4 -4
- package/bin/markuno.js +1 -1
- package/package.json +1 -1
- package/types/markcad.d.ts +2 -7
package/bin/markcad.js
CHANGED
|
@@ -66,7 +66,7 @@ constructor(p1,p2,x2=null,y2=null){"number"==typeof p1&&"number"==typeof p2&&nul
|
|
|
66
66
|
* Estende la linea di una certa lunghezza o fino all'intersezione con un'altra linea
|
|
67
67
|
* @param {number|Linea2} l - Lunghezza di estensione o linea da intersecare
|
|
68
68
|
* @returns {Linea2} Nuova linea estesa
|
|
69
|
-
*/estendi(l){if("number"==typeof l){if(!l)return this;let{p1:p1,p2:p2,dx:dx,dy:dy,len:len}=this;return len?(dx/=len,dy/=len,l>0?new Linea2(p1,new Punto2(p2.x+dx*l,p2.y+dy*l)):new Linea2(new Punto2(p1.x+dx*l,p1.y+dy*l),p2)):this}if(l instanceof Linea2){const intersectionPoint=this.interseca(l);if(!intersectionPoint)return this;return(intersectionPoint.x-this.p1.x)**2+(intersectionPoint.y-this.p1.y)**2<(intersectionPoint.x-this.p2.x)**2+(intersectionPoint.y-this.p2.y)**2?new Linea2(intersectionPoint,this.p2):new Linea2(this.p1,intersectionPoint)}}puntot(t){return new Punto2(this.p1.x+(this.p2.x-this.p1.x)*t,this.p1.y+(this.p2.y-this.p1.y)*t)}proiezionet(p){const{p1:p1,dx:dx,dy:dy,len2:len2}=this;if(len2<.001)return;const t=((p.x-p1.x)*dx+(p.y-p1.y)*dy)/len2;return{p:new Punto2(p1.x+t*dx,p1.y+t*dy),t:t}}proiezione(p){const r=this.proiezionet(p);return r?r.p:void 0}
|
|
69
|
+
*/estendi(l){if("number"==typeof l){if(!l)return this;let{p1:p1,p2:p2,dx:dx,dy:dy,len:len}=this;return len?(dx/=len,dy/=len,l>0?new Linea2(p1,new Punto2(p2.x+dx*l,p2.y+dy*l)):new Linea2(new Punto2(p1.x+dx*l,p1.y+dy*l),p2)):this}if(l instanceof Linea2){const intersectionPoint=this.interseca(l);if(!intersectionPoint)return this;return(intersectionPoint.x-this.p1.x)**2+(intersectionPoint.y-this.p1.y)**2<(intersectionPoint.x-this.p2.x)**2+(intersectionPoint.y-this.p2.y)**2?new Linea2(intersectionPoint,this.p2):new Linea2(this.p1,intersectionPoint)}}puntot(t){return new Punto2(this.p1.x+(this.p2.x-this.p1.x)*t,this.p1.y+(this.p2.y-this.p1.y)*t)}setlunghezza(l){let tm=this.len;if(tm&&l){let t=l/tm,p2=this.puntot(t);this.p2=p2}}proiezionet(p){const{p1:p1,dx:dx,dy:dy,len2:len2}=this;if(len2<.001)return;const t=((p.x-p1.x)*dx+(p.y-p1.y)*dy)/len2;return{p:new Punto2(p1.x+t*dx,p1.y+t*dy),t:t}}proiezione(p){const r=this.proiezionet(p);return r?r.p:void 0}
|
|
70
70
|
/**
|
|
71
71
|
* Calcola il vettore direzione normalizzato della linea
|
|
72
72
|
* @returns {Punto2} Vettore direzione
|
|
@@ -530,7 +530,7 @@ function calcoladivisioni(ff,notused,shape2,oggetti){return makedivisions(ff,sha
|
|
|
530
530
|
* @param {string} id - Identificatore
|
|
531
531
|
* @param {THREE.Material} [mat=null] - Materiale da applicare
|
|
532
532
|
* @returns {THREE.Line} Linea 3D
|
|
533
|
-
*/function getline(l,id,mat=null){const lineGeometry=(new THREE.BufferGeometry).setFromPoints([new THREE.Vector3(l.p1.x,0,l.p1.y),new THREE.Vector3(l.p2.x,0,l.p2.y)]);
|
|
533
|
+
*/function getspriteid(id,size=5,color="#000"){const cnv=document.createElement("canvas"),ctx=cnv.getContext("2d");ctx.font="48px sans-serif";const w=Math.ceil(ctx.measureText(id).width)+16;cnv.width=w,cnv.height=64,ctx.font="48px sans-serif",ctx.textBaseline="middle",ctx.fillStyle="rgba(0,0,0,0)",ctx.fillRect(0,0,w,64),ctx.fillStyle=color,ctx.fillText(id,8,32);const map=new THREE.CanvasTexture(cnv);map.needsUpdate=!0,map.minFilter=THREE.LinearFilter;const sm=new THREE.SpriteMaterial({map:map,transparent:!0}),sp=new THREE.Sprite(sm),k=size/20;return sp.scale.set(w*k,64*k,1),sp}function getline(l,id,mat=null){const lineGeometry=(new THREE.BufferGeometry).setFromPoints([new THREE.Vector3(l.p1.x,0,l.p1.y),new THREE.Vector3(l.p2.x,0,l.p2.y)]);let tm=new THREE.Line(lineGeometry,mat||randombasemat());if(id){let sp=getspriteid(id||"",8,"#F00");sp.position.set((l.p1.x+l.p2.x)/2,0,(l.p1.y+l.p2.y)/2),tm.add(sp)}return tm}
|
|
534
534
|
/**
|
|
535
535
|
* Crea un punto 3D rappresentato da una sfera
|
|
536
536
|
* @param {Object} p - Coordinate del punto
|
|
@@ -538,7 +538,7 @@ function calcoladivisioni(ff,notused,shape2,oggetti){return makedivisions(ff,sha
|
|
|
538
538
|
* @param {THREE.Material} [mat=null] - Materiale da applicare
|
|
539
539
|
* @param {number} [size=5] - Dimensione della sfera
|
|
540
540
|
* @returns {THREE.Mesh} Punto 3D
|
|
541
|
-
*/function getpoint(p,id,mat=null,size=5){const pointgeom=new THREE.SphereGeometry(size,8,8);
|
|
541
|
+
*/function getpoint(p,id,mat=null,size=5){let tm;const pointgeom=new THREE.SphereGeometry(size,8,8);if(tm=new THREE.Mesh(pointgeom,mat||randombasemat()),id){let sp=getspriteid(id||"",size);sp.position.set(1.2*size,0,1.2*size),tm.add(sp)}return tm.position.set(p.x,0,p.y),tm}async function smat(gcad,file,op={}){op||(op={});let ky=hash(file+JSON.stringify(op));return gcad.smats[ky]||(gcad.smats[ky]=await async function smat0(gcad,file,op={}){let fileini=file,paramstr="",isColore=!1;file.startsWith("#")&&(isColore=!0,/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})(?=$|[[(])/.test(file)||(file=file.slice(1)));let basefile=file;const paramMatch=file.match(/^(.*)\[([^\]]+)\]$/);paramMatch&&(basefile=paramMatch[1],paramstr=paramMatch[2]);const p={};paramstr&¶mstr.split(/[,;]/).forEach((kv=>{let[k,v]=kv.split("=").map((x=>x.trim()));void 0!==v&&(["e"].includes(k)?p[k]=v.startsWith("0x")?parseInt(v):parseFloat(v):isNaN(parseFloat(v))?p[k]=v:p[k]=parseFloat(v))}));const mappaParam={s:["sx","sy"],sx:["sx"],sy:["sy"],rot:["rot"],br:["brightness"],r:["roughness"],m:["metalness"],h:["bumpScale"],n:["normalScale"],d:["bumpScale"],b:["bumpScale"],e:["emissiveIntensity"],ec:["emissive"],env:["envMapIntensity"],o:["opacity"],t:["transparent"],at:["alphaTest"]};let rot0=op.rot,scale0=parseFloat(op.s)||1;delete op.s;let optot={...op};for(let k in p)if(mappaParam[k])for(let t of mappaParam[k])optot[t]=p[k];let transparent=!!optot?.transparent,sx=(optot.sx??optot.s??p.sx??p.s??1)*scale0,sy=(optot.sy??optot.s??p.sy??p.s??1)*scale0,rot=Number((optot.rot??0)+(rot0??0))*PIF;try{let tm={roughness:optot.roughness??.5,metalness:optot.metalness??0,side:THREE.DoubleSide,envMapIntensity:optot.env??.6};if(void 0!==optot.normalScale){let ns=Number(optot.normalScale);isNaN(ns)||0===ns||(tm.normalScale=new THREE.Vector2(ns,ns))}let hasNormal=!1,hasBump=!1;if(file.includes("(")||isColore){let{base:base,files:files,transparent:t2}=function getFilesToLoad(isColore,basefile){let files=[],m=basefile.match(/^([^(]+)\((([a-zA-Z0-9_\-/]+)_([a-z]+)|([a-z]+))\)$/);if(!m)return{base:basefile,files:files};let base=m[1],transparent=!1,mapalias=m[3]||base,suffstr=m[4]||m[5]||"";isColore||files.push({suff:"",file:`${base}.webp`});for(let s of suffstr)"t"==s?(transparent=!0,m[3]&&suffissoMap[s]&&files.push({suff:s,file:`${mapalias}_${s}.webp`})):suffissoMap[s]&&files.push({suff:s,file:`${mapalias}_${s}.webp`});return{base:base,files:files,transparent:transparent}}(isColore,basefile);if(transparent=t2,files.some((f=>"n"===f.suff))&&(files=files.filter((f=>"h"!==f.suff))),0===optot.roughness&&(files=files.filter((f=>"r"!==f.suff))),0===optot.metalness&&(files=files.filter((f=>"m"!==f.suff))),0===optot.emissiveIntensity&&(files=files.filter((f=>"e"!==f.suff))),files&&files.length){let textures=await Promise.all(files.map((f=>gcad.tex(f.file,sx,sy,rot).catch((()=>null)))));for(let i=0;i<files.length;i++){let t=textures[i];if(!t)continue;let suff=files[i].suff,{prop:prop,extra:extra}=suffissoMap[suff];tm[prop]=t,"normalMap"===extra?(hasNormal=!0,tm.normalMap=t,tm.normalScale=tm.normalScale??new THREE.Vector2(1,1)):"bumpScale"===extra?(hasBump=!0,tm.bumpMap=t):Array.isArray(extra)&&extra.includes("emissive")&&void 0!==optot.emissiveIntensity&&0!==optot.emissiveIntensity&&(tm.emissive=optot.emissive||16777215,tm.emissiveIntensity=optot.emissiveIntensity??1)}}isColore&&(tm.color=new THREE.Color(base))}else if(basefile.includes(".")){let tx=await gcad.tex(basefile,sx,sy,rot);if(!tx)return mwhite;tm.map=tx}if(hasNormal&&hasBump?delete tm.bumpMap:hasBump&&(tm.bumpScale=optot.bumpScale??.03),tm.transparent=!!transparent,tm.transparent&&(tm.depthWrite=!1,tm.opacity=optot?.opacity??1),void 0!==optot.brightness){let bf=Number(optot.brightness);!isNaN(bf)&&bf>0&&1!==bf&&(tm.color||(tm.color=new THREE.Color(1,1,1)),tm.color.multiplyScalar(bf))}return new THREE.MeshStandardMaterial(tm)}catch(error){return console.log("errore mat:",error.message,fileini),mwhite}}
|
|
542
542
|
/**
|
|
543
543
|
* Estrae tutte le texture usate nella scena glb e le converte in file WEBP.
|
|
544
544
|
* @param {THREE.Object3D} root - nodo root (es: gltf.scene)
|
|
@@ -1095,7 +1095,7 @@ constructor(data,position,debugMessage){this.data=data,this.offset=position,this
|
|
|
1095
1095
|
/**
|
|
1096
1096
|
* Libera tutte le risorse caricate
|
|
1097
1097
|
*/
|
|
1098
|
-
async function clearmat(){for(const key in _textures)if(_textures[key]){const texture=await _textures[key];texture?.dispose()}for(const key in _smats)_smats[key]&&_smats[key]?.dispose();for(const[key,texOrPromise]of textureCache.entries()){const texture=texOrPromise instanceof Promise?await texOrPromise:texOrPromise;texture?.dispose&&texture.dispose()}textureCache.clear(),_textures={},_smats={}}return{clearmatricole:()=>{_gmatricole={}},islog:islog,clear:async function clear(){function destroymesh(mesh){function disposeMaterial(material){material.map&&material.map.dispose(),material.lightMap&&material.lightMap.dispose(),material.bumpMap&&material.bumpMap.dispose(),material.normalMap&&material.normalMap.dispose(),material.specularMap&&material.specularMap.dispose(),material.dispose()}mesh&&mesh.traverse((child=>{child.isMesh&&(child.geometry.dispose(),child.material&&(Array.isArray(child.material)?child.material.forEach(disposeMaterial):disposeMaterial(child.material)))}))}_gmatricole={},_cachefn={},THREE.Cache.clear();for(const c in _geometries)_geometries[c]?.dispose();for(const key in _meshes)if(_meshes[key]){destroymesh(await _meshes[key])}await clearmat(),_movs={},_textures={},_meshes={},_geometries={},_smats={},_scripts={}},clearmat:clearmat,getScript:async function getScript(file){file.endsWith(".custom")?file=file.slice(0,-7):file.endsWith(".js")&&(file=file.slice(0,-3));let key=hash(`${getcat()}|${file}`);if(!_scripts[key]){let script;try{script=await P.fetch("mufiles/customfn",{id:getcat(),name:file,ispar:1})}catch(error){script=`log('undefined ${getcat()}/${file}: ${error.message}');`}_scripts[key]=script}return _scripts[key]},checkScripts:async function checkScripts(files){let cl=[];if(!files||!Array.isArray(files))return;let ct=getcat();files=[...files,"_ricalcolatop","_ricalcolaaltri","_ricalcolalinee"];for(let f of files){let key=hash(`${ct}|${f}`);_scripts[key]||cl.push(f)}if(cl?.length){let scripts=await P.fetch("mufiles/customfn",{id:ct,name:cl,ispar:1});if(scripts)for(let s of scripts){let key=hash(`${ct}|${s.n}`);_scripts[key]=s.v}}},get loaderGLTF(){return _loaderGLTF},get gmats(){return _gmatricole},scripts:()=>Object.keys(_scripts),get geo(){return _geometries},get movs(){return _movs},get textures(){return _textures},get smats(){return _smats},get meshes(){return _meshes},get cacheFns(){return _cachefn},dump(){console.log(`SMATS:\n${Object.keys(_smats).join(" - ")};\nGEOMS:\n${Object.keys(_geometries).join(" - ")};\nTEX:\n${Object.keys(_textures).join(" - ")};\nMESH:\n${Object.keys(_meshes).join(" - ")};\n`)},get cat(){return getcat()},pushcat(cat){cats.push(cat)},popcat:()=>(cats.length>1&&cats.length--,getcat()),async tex(file,sx=1,sy,rot){
|
|
1098
|
+
async function clearmat(){for(const key in _textures)if(_textures[key]){const texture=await _textures[key];texture?.dispose()}for(const key in _smats)_smats[key]&&_smats[key]?.dispose();for(const[key,texOrPromise]of textureCache.entries()){const texture=texOrPromise instanceof Promise?await texOrPromise:texOrPromise;texture?.dispose&&texture.dispose()}textureCache.clear(),_textures={},_smats={}}return{clearmatricole:()=>{_gmatricole={}},islog:islog,clear:async function clear(){function destroymesh(mesh){function disposeMaterial(material){material.map&&material.map.dispose(),material.lightMap&&material.lightMap.dispose(),material.bumpMap&&material.bumpMap.dispose(),material.normalMap&&material.normalMap.dispose(),material.specularMap&&material.specularMap.dispose(),material.dispose()}mesh&&mesh.traverse((child=>{child.isMesh&&(child.geometry.dispose(),child.material&&(Array.isArray(child.material)?child.material.forEach(disposeMaterial):disposeMaterial(child.material)))}))}_gmatricole={},_cachefn={},THREE.Cache.clear();for(const c in _geometries)_geometries[c]?.dispose();for(const key in _meshes)if(_meshes[key]){destroymesh(await _meshes[key])}await clearmat(),_movs={},_textures={},_meshes={},_geometries={},_smats={},_scripts={}},clearmat:clearmat,getScript:async function getScript(file){file.endsWith(".custom")?file=file.slice(0,-7):file.endsWith(".js")&&(file=file.slice(0,-3));let key=hash(`${getcat()}|${file}`);if(!_scripts[key]){let script;try{script=await P.fetch("mufiles/customfn",{id:getcat(),name:file,ispar:1})}catch(error){script=`log('undefined ${getcat()}/${file}: ${error.message}');`}_scripts[key]=script}return _scripts[key]},checkScripts:async function checkScripts(files){let cl=[];if(!files||!Array.isArray(files))return;let ct=getcat();files=[...files,"_ricalcolatop","_ricalcolaaltri","_ricalcolalinee"];for(let f of files){let key=hash(`${ct}|${f}`);_scripts[key]||cl.push(f)}if(cl?.length){let scripts=await P.fetch("mufiles/customfn",{id:ct,name:cl,ispar:1});if(scripts)for(let s of scripts){let key=hash(`${ct}|${s.n}`);_scripts[key]=s.v}}},get loaderGLTF(){return _loaderGLTF},get gmats(){return _gmatricole},scripts:()=>Object.keys(_scripts),get geo(){return _geometries},get movs(){return _movs},get textures(){return _textures},get smats(){return _smats},get meshes(){return _meshes},get cacheFns(){return _cachefn},dump(){console.log(`SMATS:\n${Object.keys(_smats).join(" - ")};\nGEOMS:\n${Object.keys(_geometries).join(" - ")};\nTEX:\n${Object.keys(_textures).join(" - ")};\nMESH:\n${Object.keys(_meshes).join(" - ")};\n`)},get cat(){return getcat()},pushcat(cat){cats.push(cat)},popcat:()=>(cats.length>1&&cats.length--,getcat()),async tex(file,sx=1,sy,rot){let key;return sy||(sy=sx),rot||(rot=0),"__alpha"==file?(key=file,_textures[key]||(_textures[key]=function getfortransparent(){const texture=new THREE.CanvasTexture(function generateTexture(){const canvas=document.createElement("canvas");canvas.width=2,canvas.height=2;const context=canvas.getContext("2d");return context.fillStyle="white",context.fillRect(0,1,2,1),canvas}());return texture.magFilter=THREE.NearestFilter,texture.wrapT=THREE.RepeatWrapping,texture.wrapS=THREE.RepeatWrapping,texture.repeat.set(1,3.5),texture}()),_textures[key]):(key=hash(`${getcat()}|${file}|${sx}|${sy}|${rot}`),_textures[key]||(_textures[key]=new Promise(((resolve,reject)=>{let url;if(file.startsWith("https://"))url=file;else if(P._cdn)if(file.includes("/")){let v=file.split("/");url=`${P._cdn}${v[0]}/textures/${v[1]}`}else url=`${P._cdn}${getcat()}/textures/${file}`;else url=P.fullget("mufiles/getfile",{id:getcat(),subfolder:"textures",name:file,force:1});if(textureCache.has(url)){const tex=textureCache.get(url).clone();return tex.wrapS=THREE.RepeatWrapping,tex.wrapT=THREE.RepeatWrapping,tex.repeat.set(.001*sx,.001*sy),tex.rotation=rot,tex.colorSpace=THREE.SRGBColorSpace,void resolve(tex)}_loadertex.load(url,(tex=>{textureCache.set(url,tex),tex.wrapS=THREE.RepeatWrapping,tex.wrapT=THREE.RepeatWrapping,tex.repeat.set(.001*sx,.001*sy),tex.rotation=rot,resolve(tex)}),void 0,(error=>{console.log(`Manca Texture ${file}!. questo rallenta molto il processo`),delete _textures[key],resolve(void 0)}))}))),_textures[key])},async get3ds(file){file.endsWith(".3ds")&&(file=file.slice(0,-4));const key=hash(`${getcat()}|${file}.3ds`);return _meshes[key]||(_meshes[key]=await new Promise(((resolve,reject)=>{let url,urlt="";file.startsWith("https://")?(url=`${file}.3ds`,urlt=url):P._cdn?(url=`${P._cdn}${getcat()}/3d/${file}.3ds`,urlt=`${P._cdn}${getcat()}/3d/${file}/`):(url=P.fullget("mufiles/getfile",{id:getcat(),subfolder:"3d",name:file,ext:".3ds"}),urlt=url+"&tex="),_loader3DS.setResourcePath(urlt),_loader3DS.load(url,(object=>{const cache=new WeakMap;object.traverse((n=>{n.isMesh&&n.material&&(n.material=Array.isArray(n.material)?n.material.map((e=>to_std(e,cache))):to_std(n.material,cache))})),object.userData||(object.userData={}),object.userData._ky=key,resolve(object)}),void 0,(error=>{console.log(error),delete _meshes[key],resolve(void 0)}))}))),_meshes[key]},async getglb(file){const ext=".glb";file.endsWith(ext)&&(file=file.slice(0,-4)),file.startsWith("https://")||(file=file.replace(/\//g,"+"));let elemento=(file=file.split("+"))[1];file=file[0];const key=hash(`${getcat()}|${file}${ext}`);_meshes[key]||(_meshes[key]=await new Promise(((resolve,reject)=>{let url;url=file.startsWith("https://")?`${file}.glb`:P._cdn?`${P._cdn}${getcat()}/3d/${file}.glb`:P.fullget("mufiles/getfile",{id:getcat(),subfolder:"3d",name:file,ext:ext}),_loaderGLTF.setPath(""),_loaderGLTF.setResourcePath((resource=>(console.log("risorsa",resource),`${url}&tex=${resource}`))),_loaderGLTF.load(url,(async gltf=>{const object=gltf.scene;object.userData||(object.userData={}),object.userData._ky=key,resolve(object)}),void 0,(error=>{console.log(error),delete _meshes[key],resolve(void 0)}))})));let tm=_meshes[key];if(elemento){let n=tm?.getObjectByName(elemento);n&&(tm=n)}return tm},replacemats(bb,mats,callback){if(!Array.isArray(mats)||0==mats.length)return bb;const leggi_slot=mat=>{if(!mat)return-1;let s=(mat?.map?.name||mat?.name||mat?.map?.userData?.name||"").toString().trim();if(callback){const s1=callback(s);void 0!==s1&&(s=s1)}if(s.includes("_")&&(s=s.split("_").pop()),!s)return-1;const n=parseInt(s,10);return n>=1&&n<=9?n:-1};let serve_clone=!1,ky=String(bb.userData?._ky||"");if(bb.traverse((n=>{if(!n.isMesh)return;const ms=Array.isArray(n.material)?n.material:[n.material];for(const m of ms){const k=leggi_slot(m);k>0&&mats[k-1]&&(serve_clone=!0,ky+="|"+(mats[k-1].name||mats[k-1].uuid))}})),serve_clone){if(ky=hash(ky),_meshes[ky])return _meshes[ky];const cc=bb.clone(!0);cc.traverse((n=>{if(n.isMesh)if(Array.isArray(n.material))n.material=n.material.map((m=>{if(!m)return m;const k=leggi_slot(m);if(k>0&&mats[k-1]){const t=mats[k-1];return t.needsUpdate=!0,t}return m}));else{const m=n.material,k=leggi_slot(m);n.material=k>0&&mats[k-1]?(mats[k-1].needsUpdate=!0,mats[k-1]):m}})),cc.userData=cc.userData||{},cc.userData._ky=ky,_meshes[ky]=cc,bb=cc}return bb}}}const originalMaterials=new Map;
|
|
1099
1099
|
/**
|
|
1100
1100
|
* Salva i materiali originali di tutti i mesh nel gruppo (solo layer <= 20)
|
|
1101
1101
|
* @param {THREE.Object3D} gruppo
|
package/bin/markuno.js
CHANGED
|
@@ -115,7 +115,7 @@ function setOggetto(objDestinazione,objSorgente){"object"==typeof objDestinazion
|
|
|
115
115
|
/**
|
|
116
116
|
* Converte la lista degli errori in stringa
|
|
117
117
|
* @returns {string} Rappresentazione testuale degli errori
|
|
118
|
-
*/toString(){const cl=[];for(const e of this.err){const m="object"==typeof e.msg?JSON.stringify(e.msg):e.msg||"";cl.push(`${e.row?e.row+":":""}${m}`)}return cl.join("\n")}},toNum=(n,dec=-1)=>{const num="string"==typeof n?parseFloat(n)||0:n;if(dec<0)return num||0;const factor=Math.pow(10,dec);return Math.round(num*factor)/factor||0};function getheaddims(dims){let res;try{res="object"==typeof dims&&dims?dims:JSON.parse(dims||"{}")}catch(error){res={}}return res||(res={}),res.l||(res.l={visible:1,val:1e3,min:0,max:1e4}),res.a||(res.a={visible:1,val:1e3,min:0,max:1e4}),res.p||(res.p={visible:1,val:1e3,min:0,max:1e4}),res}function sortrows(rows){const k2=Object.keys(rows).sort(),out={};for(let i=0;i<k2.length;i++){const k=k2[i],kk=rows[k];i+1<k2.length&&k2[i+1].startsWith(k+".")?kk.hasliv=1:delete kk.hasliv,out[k]=kk}return out}const REGEX_PARENTESI=/(?<!\w)\(/g,REGEX_NUMERO=/^-?[0-9.]+$/,REGEX_FUNZIONE=/^(\w+)(!)?\[(.*)?\]$/,
|
|
118
|
+
*/toString(){const cl=[];for(const e of this.err){const m="object"==typeof e.msg?JSON.stringify(e.msg):e.msg||"";cl.push(`${e.row?e.row+":":""}${m}`)}return cl.join("\n")}},toNum=(n,dec=-1)=>{const num="string"==typeof n?parseFloat(n)||0:n;if(dec<0)return num||0;const factor=Math.pow(10,dec);return Math.round(num*factor)/factor||0};function getheaddims(dims){let res;try{res="object"==typeof dims&&dims?dims:JSON.parse(dims||"{}")}catch(error){res={}}return res||(res={}),res.l||(res.l={visible:1,val:1e3,min:0,max:1e4}),res.a||(res.a={visible:1,val:1e3,min:0,max:1e4}),res.p||(res.p={visible:1,val:1e3,min:0,max:1e4}),res}function sortrows(rows){const k2=Object.keys(rows).sort(),out={};for(let i=0;i<k2.length;i++){const k=k2[i],kk=rows[k];i+1<k2.length&&k2[i+1].startsWith(k+".")?kk.hasliv=1:delete kk.hasliv,out[k]=kk}return out}const REGEX_PARENTESI=/(?<!\w)\(/g,REGEX_NUMERO=/^-?[0-9.]+$/,REGEX_FUNZIONE=/^(\w+)(!)?\[(.*)?\]$/,REGEX_DIGIT=/[0-9.]/,REGEX_OPERATOR=/[+\-*/^%]/,REGEX_ALPHA=/[a-zA-Z]/i;function valutaparentesi(expression){for(expression=(expression+"").trim();;){const tm=REGEX_PARENTESI.exec(expression);if(!tm)break;{const{i:i,res:res}=parsevar(expression,tm.index+1,"(",")");if(i<=0)break;expression=expression.substring(0,tm.index)+valutaparentesi(res[0])+(i>=0?expression.substring(i+1):"")}}return function operatoricomparazione(expression){let left,right;const operators={"||":()=>valutaparentesi(left)||valutaparentesi(right)?1:0,"|":()=>valutaparentesi(left)||valutaparentesi(right)?1:0,"&&":()=>valutaparentesi(left)&&valutaparentesi(right)?1:0,"&":()=>valutaparentesi(left)&&valutaparentesi(right)?1:0,"<<=":()=>clean(left)<=clean(right),">>=":()=>clean(left)>=clean(right),"===":()=>clean(left)==clean(right),"==":()=>clean(left)==clean(right),"!!":()=>clean(left)!=clean(right),"<<":()=>clean(left)<clean(right),">>":()=>clean(left)>clean(right),"<=":()=>muCalcbase(left)<=muCalcbase(right),">=":()=>muCalcbase(left)>=muCalcbase(right),"<":()=>muCalcbase(left)<muCalcbase(right),">":()=>muCalcbase(left)>muCalcbase(right),"=":()=>muCalcbase(left)==muCalcbase(right),"!":()=>muCalcbase(left)!=muCalcbase(right)};let operatorIndex=-1,op="";for(const operator in operators)if(operatorIndex=expression.indexOf(operator),operatorIndex>=0){op=operator;break}return-1!==operatorIndex?(left=expression.slice(0,operatorIndex),right=expression.slice(operatorIndex+op.length),operators[op]&&operators[op]()?1:0):muCalcbase(expression)}(expression=function valutainsiemi(expression){if(expression.includes("[")){function resinisiemi(rr){const v1=rr[1],fl=!!rr[2],vv=getcolonne(rr[3]);for(const v of vv)if(v==v1)return fl?"0":"1";return fl?"1":"0"}for(;;){const rr=REGEX_FUNZIONE.exec(expression);if(!rr)break;{const tm=resinisiemi(rr);expression=expression.substring(0,rr.index)+tm+expression.substring(rr.index+rr[0].length)}}}return expression}(expression))}const mathFunctions={sqrt:x=>Math.sqrt(x),sqr:x=>Math.sqrt(x),pow:(x,y)=>Math.pow(x,y),int:x=>Math.floor(x),floor:(x,d=0)=>Math.floor((Number.parseFloat(x)||0)*10**d)/10**d,round:(x,d=0)=>Math.round((Number.parseFloat(x)||0)*10**d)/10**d,dec:(x,d=0)=>Math.floor((Number.parseFloat(x)||0)*10**d)/10**d,abs:x=>Math.abs(x),sin:x=>Math.sin(x*Math.PI/180),cos:x=>Math.cos(x*Math.PI/180),tan:x=>Math.tan(x*Math.PI/180),asin:x=>180*Math.asin(x)/Math.PI,acos:x=>180*Math.acos(x)/Math.PI,atan:x=>180*Math.atan(x)/Math.PI,atan2:(y,x)=>180*Math.atan2(y,x)/Math.PI,log:x=>Math.log(x),log10:x=>Math.log10(x),min:(...args)=>Math.min(...args),max:(...args)=>Math.max(...args),clamp:(x,x1,x2)=>Math.max(x1,Math.min(x2,x)),rnd:(a,b)=>a?b?Math.floor(Math.random()*(b-a+1))+a:Math.floor(Math.random()*a):Math.random(),cas:(a,b)=>Math.floor(Math.random()*(b-a+1))+a};function muCalcbase(expression){let index=0;function parseOperator(){const op=expression[index];return REGEX_OPERATOR.test(op)?(index++,op):null}function parsePrimary(){if("+"===expression[index]||"-"===expression[index]){return("-"===expression[index++]?-1:1)*parsePrimary()}if(REGEX_DIGIT.test(expression[index]))return function parseNumber(){const start=index;for(;index<expression.length&®EX_DIGIT.test(expression[index]);)index++;return Number(expression.slice(start,index))}();if("("===expression[index]){index++;const result=parseExpr();return")"===expression[index]&&index++,result}return REGEX_ALPHA.test(expression[index])?function parseFunctions(){const ex=expression.slice(index);if(!ex)return 0;for(const[name,func]of Object.entries(mathFunctions)){const match=new RegExp(`^(${name})\\(`,"i").exec(ex);if(match){index+=match[0].length;let pars=[];for(;;){let tm=parseExpr();if(pars.push(tm),")"===expression[index]){index++;break}if(","!=expression[index])break;index++}return func(...pars)}}return index++,parseExpr()}():0}function parseFactor(){let left=parsePrimary();for(;index<expression.length&&/[/*^%]/.test(expression[index]);){const op=parseOperator(),right=parsePrimary();"*"===op?left*=right:"/"===op?left=right?left/right:0:"%"===op?left=right?left%right:0:"^"===op&&(left=Math.pow(left,right))}return left}function parseExpr(){let left=parseFactor();for(;index<expression.length&&/[+-]/.test(expression[index]);){const op=parseOperator(),right=parseFactor();"+"===op?left+=right:"-"===op&&(left-=right)}return left}return expression=expression.replace(/\s/g,""),parseExpr()}
|
|
119
119
|
/**
|
|
120
120
|
* Valuta un'espressione matematica o logica e restituisce il risultato
|
|
121
121
|
* @param {string|number} expression - L'espressione da valutare
|
package/package.json
CHANGED
package/types/markcad.d.ts
CHANGED
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
* @returns {Linea2} Nuova linea estesa
|
|
39
39
|
*/ estendi(l: number | Linea2): Linea2;
|
|
40
40
|
puntot(t: any): Punto2;
|
|
41
|
+
setlunghezza(l: any): void;
|
|
41
42
|
proiezionet(p: any): {
|
|
42
43
|
p: Punto2;
|
|
43
44
|
t: number;
|
|
@@ -405,13 +406,7 @@ export function getextrude(gcad: any, pts: any, h?: number, holes?: any[], mat?:
|
|
|
405
406
|
export function getface(gcad: any, x: any, y: any, mat: any, op?: {}): any;
|
|
406
407
|
export function getfakeshadow(gcad: any, shape: any, alfa: any): any;
|
|
407
408
|
export function getfakeshadow2(w: any, h: any, map: any): any;
|
|
408
|
-
|
|
409
|
-
* Crea una linea 3D
|
|
410
|
-
* @param {Object} l - Oggetto contenente punti p1 e p2
|
|
411
|
-
* @param {string} id - Identificatore
|
|
412
|
-
* @param {THREE.Material} [mat=null] - Materiale da applicare
|
|
413
|
-
* @returns {THREE.Line} Linea 3D
|
|
414
|
-
*/ export function getline(l: any, id: string, mat?: THREE.Material): THREE.Line;
|
|
409
|
+
export function getline(l: any, id: any, mat?: any): any;
|
|
415
410
|
export function getlinesgeom(edges: any, layer?: number): any;
|
|
416
411
|
export function getmesh(geom: any, material: any, layer?: number, clone?: boolean): any;
|
|
417
412
|
/**
|