Mesh.js 4.6 KB

123456789101112
  1. // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  2. // See https://js.arcgis.com/4.7/esri/copyright.txt for details.
  3. //>>built
  4. define("require exports ../core/tsSupport/declareExtendsHelper ../core/tsSupport/decorateHelper ../core/tsSupport/paramHelper ../core/lang ../core/Logger ../core/accessorSupport/decorators ./Extent ./Geometry ./support/MeshComponent ./support/MeshVertexAttributes ./support/triangulationUtils ./support/meshUtils/centerAt ./support/meshUtils/offset ./support/meshUtils/primitives ./support/meshUtils/rotate".split(" "),function(J,K,x,g,y,t,z,d,r,A,n,B,C,D,E,k,l){var F=z.getLogger("esri.geometry.Mesh"),
  5. G=[1,0,0],H=[0,1,0],I=[0,0,1],p=[0,0,0],m=[0,0,0,0],u=[0,0,0,0],v=[0,0,0,0];return function(w){function b(a){a=w.call(this)||this;a.components=null;a.hasZ=!0;a.hasM=!1;a.vertexAttributes=null;a.type="mesh";return a}x(b,w);q=b;Object.defineProperty(b.prototype,"extent",{get:function(){var a=this.spatialReference,c=this.vertexAttributes&&this.vertexAttributes.position;if(!c||0===c.length||this.components&&0===this.components.length)return new r({xmin:0,ymin:0,zmin:0,xmax:0,ymax:0,zmax:0,spatialReference:a});
  6. a={xmin:Infinity,xmax:-Infinity,ymin:Infinity,ymax:-Infinity,zmin:Infinity,zmax:-Infinity,spatialReference:a};if(!this.components)return new r(this.extendExtent(a,c,null));for(var b=0,e=this.components;b<e.length;b++){var f=e[b];if(f.faces)this.extendExtent(a,c,f.faces);else{this.extendExtent(a,c,null);break}}return new r(a)},enumerable:!0,configurable:!0});b.prototype.addComponent=function(a){this.components||(this.components=[]);this.components.push(a);this.clearCache()};b.prototype.removeComponent=
  7. function(a){if(this.components&&(a=this.components.indexOf(a),-1!==a)){this.components=this.components.splice(a,1);return}F.error("removeComponent()","Provided component is not part of the list of components")};b.prototype.rotate=function(a,c,b,e){l.axisAngleFrom(G,a/180*Math.PI,m);l.axisAngleFrom(H,c/180*Math.PI,u);l.axisAngleFrom(I,b/180*Math.PI,v);l.axisAngleMultiply(m,u,m);l.axisAngleMultiply(m,v,m);l.rotate(this,m,e);return this};b.prototype.offset=function(a,c,b,e){p[0]=a;p[1]=c;p[2]=b;E.offset(this,
  8. p,e);return this};b.prototype.centerAt=function(a,c){D.centerAt(this,a,c);return this};b.prototype.clone=function(){return new q({components:t.clone(this.components),spatialReference:this.spatialReference,vertexAttributes:t.clone(this.vertexAttributes)})};b.prototype.vertexAttributesChanged=function(){this.clearCache()};b.prototype.toJSON=function(a){return this.write({},a)};b.prototype.forEachVertex=function(a,c,b){if(c)for(f=0;f<c.length;f++){var e=3*c[f];b(a[e+0],a[e+1],a[e+2])}else for(var f=
  9. 0;f<a.length;f+=3)b(a[f+0],a[f+1],a[f+2])};b.prototype.extendExtent=function(a,c,b){this.forEachVertex(c,b,function(c,b,d){a.xmin=Math.min(a.xmin,c);a.xmax=Math.max(a.xmax,c);a.ymin=Math.min(a.ymin,b);a.ymax=Math.max(a.ymax,b);a.zmin=Math.min(a.zmin,d);a.zmax=Math.max(a.zmax,d)});return a};b.createBox=function(a,c){a=k.convertUnitGeometry(k.createUnitSizeBox(),a,c);if(c&&c.imageFace&&"all"!==c.imageFace){var b=a.components[0],e=b.faces,f=k.boxFaceOrder[c.imageFace],d=6*f;c=new Uint32Array(6);for(var g=
  10. new Uint32Array(e.length-6),l=0,m=0,h=0;h<e.length;h++)h>=d&&h<d+6?c[l++]=e[h]:g[m++]=e[h];e=new Float32Array(a.vertexAttributes.uv);f*=8;d=[0,1,1,1,1,0,0,0];for(h=0;h<d.length;h++)e[f+h]=d[h];a.vertexAttributes.uv=e;a.components=[new n({faces:c,material:b.material}),new n({faces:g})]}return a};b.createSphere=function(a,b){return k.convertUnitGeometry(k.createUnitSizeSphere(b&&b.densificationFactor||0),a,b)};b.createCylinder=function(a,b){return k.convertUnitGeometry(k.createUnitSizeCylinder(b&&b.densificationFactor||
  11. 0),a,b)};b.createPlane=function(a,b){return k.convertUnitGeometry(k.createUnitSizePlane(b&&b.facing||"up"),a,b)};b.createFromPolygon=function(a,b){var c=C.triangulate(a);return new q({vertexAttributes:{position:c.position},components:[{faces:c.faces,shading:"flat",material:b&&b.material||null}],spatialReference:a.spatialReference})};g([d.property({dependsOn:["vertexAttributes","vertexAttributes.position","components"],json:{read:!1}})],b.prototype,"cache",void 0);g([d.property({type:[n]})],b.prototype,
  12. "components",void 0);g([d.property({dependsOn:["cache"],readOnly:!0,json:{read:!1}})],b.prototype,"extent",null);g([d.property({readOnly:!0,json:{read:!1,write:!1}})],b.prototype,"hasZ",void 0);g([d.property({readOnly:!0,json:{read:!1,write:!1}})],b.prototype,"hasM",void 0);g([d.property({type:B.MeshVertexAttributes,json:{write:!0}})],b.prototype,"vertexAttributes",void 0);g([y(0,d.cast(n))],b.prototype,"addComponent",null);return b=q=g([d.subclass("esri.geometry.Mesh")],b);var q}(d.declared(A))});