UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 1.84 kB
import{RENDERSTYLE_WIREFRAME as s}from"./constants.js";import{MeshInstance as t}from"./mesh-instance.js";import{MorphInstance as n}from"./morph-instance.js";import{SkinInstance as e}from"./skin-instance.js";class h{constructor(){this.graph=null,this.meshInstances=[],this.skinInstances=[],this.morphInstances=[],this.cameras=[],this.lights=[],this._shadersVersion=0,this._immutable=!1}getGraph(){return this.graph}setGraph(s){this.graph=s}getCameras(){return this.cameras}setCameras(s){this.cameras=s}getLights(){return this.lights}setLights(s){this.lights=s}getMaterials(){const s=[];for(let t=0;t<this.meshInstances.length;t++){const n=this.meshInstances[t];-1===s.indexOf(n.material)&&s.push(n.material)}return s}clone(){const s=[],r=[],i=function t(n){const e=n.clone();s.push(n),r.push(e);for(let s=0;s<n._children.length;s++)e.addChild(t(n._children[s]));return e}(this.graph),a=[],c=[],o=[];for(let s=0;s<this.skinInstances.length;s++){const t=this.skinInstances[s].skin,n=new e(t),h=[];for(let s=0;s<t.boneNames.length;s++){const n=t.boneNames[s],e=i.findByName(n);h.push(e)}n.bones=h,c.push(n)}for(let s=0;s<this.morphInstances.length;s++){const t=this.morphInstances[s].morph,e=new n(t);o.push(e)}for(let n=0;n<this.meshInstances.length;n++){const e=this.meshInstances[n],h=s.indexOf(e.node),i=new t(e.mesh,e.material,r[h]);if(e.skinInstance){const s=this.skinInstances.indexOf(e.skinInstance);i.skinInstance=c[s]}if(e.morphInstance){const s=this.morphInstances.indexOf(e.morphInstance);i.morphInstance=o[s]}a.push(i)}const m=new h;return m.graph=i,m.meshInstances=a,m.skinInstances=c,m.morphInstances=o,m.getGraph().syncHierarchy(),m}destroy(){const s=this.meshInstances;for(let t=0;t<s.length;t++)s[t].destroy();this.meshInstances.length=0}generateWireframe(){t._prepareRenderStyleForArray(this.meshInstances,s)}}export{h as Model};