UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 1.31 kB
import{Mat4 as s}from"../../core/math/mat4.js";import{PRIMITIVE_LINES as t}from"../../platform/graphics/constants.js";import{Mesh as o}from"../mesh.js";import{MeshInstance as e}from"../mesh-instance.js";import{GraphNode as h}from"../graph-node.js";const i=new h;i.worldTransform=s.IDENTITY,i._dirtyWorld=i._dirtyNormal=!1;class r{constructor(s,t,e){this.material=t,this.layer=e,this.positions=[],this.colors=[],this.mesh=new o(s),this.meshInstance=null}addLines(s,t){const o=this.positions,e=s.length;for(let t=0;t<e;t++){const e=s[t];o.push(e.x,e.y,e.z)}const h=this.colors;if(t.length)for(let s=0;s<e;s++){const o=t[s];h.push(o.r,o.g,o.b,o.a)}else for(let s=0;s<e;s++)h.push(t.r,t.g,t.b,t.a)}addLinesArrays(s,t){const o=this.positions;for(let t=0;t<s.length;t+=3)o.push(s[t],s[t+1],s[t+2]);const e=this.colors;if(t.length)for(let s=0;s<t.length;s+=4)e.push(t[s],t[s+1],t[s+2],t[s+3]);else{const o=s.length/3;for(let s=0;s<o;s++)e.push(t.r,t.g,t.b,t.a)}}onPreRender(s,o){this.positions.length>0&&this.material.transparent===o&&(this.mesh.setPositions(this.positions),this.mesh.setColors(this.colors),this.mesh.update(t,!1),this.meshInstance||(this.meshInstance=new e(this.mesh,this.material,i)),s.push(this.meshInstance))}clear(){this.positions.length=0,this.colors.length=0}}export{r as ImmediateBatch};