@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 1.31 kB
JavaScript
import{Vec3 as e}from"../../core/math/vec3.js";import{calculateTangents as t}from"./geometry-utils.js";import{Geometry as s}from"./geometry.js";const n=4/64;class l extends s{constructor(s={}){var l,o,r,h,u;super();const i=null!=(l=s.halfExtents)?l:new e(.5,.5,.5),w=null!=(o=s.widthSegments)?o:1,m=null!=(r=s.lengthSegments)?r:1,p=null!=(h=s.heightSegments)?h:1,c=null!=(u=s.yOffset)?u:0,x=-i.y+c,a=i.y+c,f=[new e(-i.x,x,i.z),new e(i.x,x,i.z),new e(i.x,a,i.z),new e(-i.x,a,i.z),new e(i.x,x,-i.z),new e(-i.x,x,-i.z),new e(-i.x,a,-i.z),new e(i.x,a,-i.z)],g=[[0,1,3],[4,5,7],[3,2,6],[1,0,4],[1,4,2],[5,0,6]],z=[[0,0,1],[0,0,-1],[0,1,0],[0,-1,0],[1,0,0],[-1,0,0]],y=1,d=2,v=3,j=4,S=5,b=[],E=[],M=[],O=[];let T=0;const k=(t,s,l)=>{const o=new e,r=new e,h=new e,u=new e;for(let e=0;e<=s;e++)for(let i=0;i<=l;i++){o.lerp(f[g[t][0]],f[g[t][1]],e/s),r.lerp(f[g[t][0]],f[g[t][2]],i/l),h.sub2(r,f[g[t][0]]),u.add2(o,h);let w=e/s,m=i/l;b.push(u.x,u.y,u.z),E.push(z[t][0],z[t][1],z[t][2]),M.push(w,1-m),w=.875*w+n,m=.875*m+n,w/=3,m/=3,w+=t%3/3,m+=Math.floor(t/3)/3,e<s&&i<l&&(O.push(T+l+1,T+1,T),O.push(T+l+1,T+l+2,T+1)),T++}};k(0,w,p),k(y,w,p),k(d,w,m),k(v,w,m),k(j,m,p),k(S,m,p),this.positions=b,this.normals=E,this.uvs=M,this.uvs1=M,this.indices=O,s.calculateTangents&&(this.tangents=t(b,E,M,O))}}export{l as BoxGeometry};