UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 2.18 kB
import{Vec3 as s}from"../../core/math/vec3.js";import{Geometry as t}from"./geometry.js";const h=4/64,o=.875;class e extends t{constructor(t,e,n,p,u,a){super();const c=new s,r=new s,M=new s,i=new s,l=new s,f=new s,I=[],P=[],m=[],w=[],x=[];let z;if(n>0)for(let s=0;s<=p;s++)for(let a=0;a<=u;a++){const z=a/u*2*Math.PI-Math.PI,v=Math.sin(z),y=Math.cos(z);l.set(v*t,-n/2,y*t),i.set(v*e,n/2,y*e),c.lerp(l,i,s/p),r.sub2(i,l).normalize(),f.set(y,0,-v),M.cross(f,r).normalize(),I.push(c.x,c.y,c.z),P.push(M.x,M.y,M.z);let d=a/u,j=s/p;m.push(d,1-j);const b=j;if(j=d,d=b,d=d*o+h,j=j*o+h,d/=3,w.push(d,1-j),s<p&&a<u){const t=s*(u+1)+a,h=s*(u+1)+(a+1),o=(s+1)*(u+1)+a,e=(s+1)*(u+1)+(a+1);x.push(t,h,o),x.push(h,e,o)}}if(a){const s=Math.floor(u/2),t=u,a=n/2;for(let n=0;n<=s;n++){const p=n*Math.PI*.5/s,u=Math.sin(p),c=Math.cos(p);for(let p=0;p<=t;p++){const r=2*p*Math.PI/t-Math.PI/2,M=Math.sin(r),i=Math.cos(r)*u,l=c,f=M*u;let x=1-p/t,z=1-n/s;I.push(i*e,l*e+a,f*e),P.push(i,l,f),m.push(x,1-z),x=x*o+h,z=z*o+h,x/=3,z/=3,x+=1/3,w.push(x,1-z)}}z=(p+1)*(u+1);for(let h=0;h<s;++h)for(let s=0;s<t;++s){const o=h*(t+1)+s,e=o+t+1;x.push(z+o+1,z+e,z+o),x.push(z+o+1,z+e+1,z+e)}for(let n=0;n<=s;n++){const p=.5*Math.PI+n*Math.PI*.5/s,u=Math.sin(p),c=Math.cos(p);for(let p=0;p<=t;p++){const r=2*p*Math.PI/t-Math.PI/2,M=Math.sin(r),i=Math.cos(r)*u,l=c,f=M*u;let x=1-p/t,z=1-n/s;I.push(i*e,l*e-a,f*e),P.push(i,l,f),m.push(x,1-z),x=x*o+h,z=z*o+h,x/=3,z/=3,x+=2/3,w.push(x,1-z)}}z=(p+1)*(u+1)+(t+1)*(s+1);for(let h=0;h<s;++h)for(let s=0;s<t;++s){const o=h*(t+1)+s,e=o+t+1;x.push(z+o+1,z+e,z+o),x.push(z+o+1,z+e+1,z+e)}}else{if(z=(p+1)*(u+1),t>0)for(let s=0;s<u;s++){const e=s/u*2*Math.PI,p=Math.sin(e),a=-n/2,c=Math.cos(e);let r=1-(p+1)/2,M=(c+1)/2;I.push(p*t,a,c*t),P.push(0,-1,0),m.push(r,1-M),r=r*o+h,M=M*o+h,r/=3,M/=3,r+=1/3,w.push(r,1-M),s>1&&x.push(z,z+s,z+s-1)}if(z+=u,e>0)for(let s=0;s<u;s++){const t=s/u*2*Math.PI,p=Math.sin(t),a=n/2,c=Math.cos(t);let r=1-(p+1)/2,M=(c+1)/2;I.push(p*e,a,c*e),P.push(0,1,0),m.push(r,1-M),r=r*o+h,M=M*o+h,r/=3,M/=3,r+=2/3,w.push(r,1-M),s>1&&x.push(z,z+s-1,z+s)}}this.positions=I,this.normals=P,this.uvs=m,this.uvs1=w,this.indices=x}}export{e as ConeBaseGeometry};