@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 986 B
JavaScript
import{math as s}from"../../core/math/math.js";import{calculateTangents as t}from"./geometry-utils.js";import{Geometry as h}from"./geometry.js";class a extends h{constructor(h={}){var a,o,n,i,e;super();const r=null!=(a=h.tubeRadius)?a:.2,u=null!=(o=h.ringRadius)?o:.3,l=(null!=(n=h.sectorAngle)?n:360)*s.DEG_TO_RAD,c=null!=(i=h.segments)?i:30,M=null!=(e=h.sides)?e:20,m=[],p=[],g=[],f=[];for(let s=0;s<=M;s++)for(let t=0;t<=c;t++){const h=Math.cos(l*t/c)*(u+r*Math.cos(2*Math.PI*s/M)),a=Math.sin(2*Math.PI*s/M)*r,o=Math.sin(l*t/c)*(u+r*Math.cos(2*Math.PI*s/M)),n=Math.cos(l*t/c)*Math.cos(2*Math.PI*s/M),i=Math.sin(2*Math.PI*s/M),e=Math.sin(l*t/c)*Math.cos(2*Math.PI*s/M),I=s/M,P=1-t/c;if(m.push(h,a,o),p.push(n,i,e),g.push(I,1-P),s<M&&t<c){const h=s*(c+1)+t,a=(s+1)*(c+1)+t,o=s*(c+1)+(t+1),n=(s+1)*(c+1)+(t+1);f.push(h,a,o),f.push(a,n,o)}}this.positions=m,this.normals=p,this.uvs=g,this.uvs1=g,this.indices=f,h.calculateTangents&&(this.tangents=t(m,p,g,f))}}export{a as TorusGeometry};