@antv/g-plugin-3d
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -1,1 +0,15 @@ | ||
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("@antv/g-plugin-webgl-renderer"),require("@antv/g"),require("mana-syringe")):"function"==typeof define&&define.amd?define(["@antv/g-plugin-webgl-renderer","@antv/g","mana-syringe"],r):"object"==typeof exports?exports["3D"]=r(require("@antv/g-plugin-webgl-renderer"),require("@antv/g"),require("mana-syringe")):(t.G=t.G||{},t.G["3D"]=r(t.G.WebGL.WebGLRenderer,t.G,t.G.ManaSyringe))}(window,(function(t,r,e){return function(t){var r={};function e(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var o in t)e.d(n,o,function(r){return t[r]}.bind(null,o));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=11)}([function(r,e){r.exports=t},function(t,e){t.exports=r},function(t,r){t.exports=e},,,,,,,,,function(t,r,e){"use strict";e.r(r),e.d(r,"containerModule",(function(){return St})),e.d(r,"Plugin",(function(){return xt})),e.d(r,"Cube",(function(){return mt})),e.d(r,"Sphere",(function(){return _t})),e.d(r,"Grid",(function(){return Mt}));var n={};e.r(n),e.d(n,"create",(function(){return _})),e.d(n,"clone",(function(){return M})),e.d(n,"length",(function(){return S})),e.d(n,"fromValues",(function(){return x})),e.d(n,"copy",(function(){return O})),e.d(n,"set",(function(){return w})),e.d(n,"add",(function(){return B})),e.d(n,"subtract",(function(){return j})),e.d(n,"multiply",(function(){return A})),e.d(n,"divide",(function(){return P})),e.d(n,"ceil",(function(){return G})),e.d(n,"floor",(function(){return F})),e.d(n,"min",(function(){return L})),e.d(n,"max",(function(){return C})),e.d(n,"round",(function(){return D})),e.d(n,"scale",(function(){return V})),e.d(n,"scaleAndAdd",(function(){return z})),e.d(n,"distance",(function(){return U})),e.d(n,"squaredDistance",(function(){return q})),e.d(n,"squaredLength",(function(){return R})),e.d(n,"negate",(function(){return I})),e.d(n,"inverse",(function(){return E})),e.d(n,"normalize",(function(){return T})),e.d(n,"dot",(function(){return k})),e.d(n,"cross",(function(){return N})),e.d(n,"lerp",(function(){return X})),e.d(n,"hermite",(function(){return W})),e.d(n,"bezier",(function(){return H})),e.d(n,"random",(function(){return Q})),e.d(n,"transformMat4",(function(){return Y})),e.d(n,"transformMat3",(function(){return Z})),e.d(n,"transformQuat",(function(){return J})),e.d(n,"rotateX",(function(){return K})),e.d(n,"rotateY",(function(){return $})),e.d(n,"rotateZ",(function(){return tt})),e.d(n,"angle",(function(){return rt})),e.d(n,"zero",(function(){return et})),e.d(n,"str",(function(){return nt})),e.d(n,"exactEquals",(function(){return ot})),e.d(n,"equals",(function(){return it})),e.d(n,"sub",(function(){return ut})),e.d(n,"mul",(function(){return ct})),e.d(n,"div",(function(){return ft})),e.d(n,"dist",(function(){return st})),e.d(n,"sqrDist",(function(){return dt})),e.d(n,"len",(function(){return lt})),e.d(n,"sqrLen",(function(){return ht})),e.d(n,"forEach",(function(){return pt}));var o=e(1),i=e(2),a=e(0),u=function(t,r){return(u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])})(t,r)};function c(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function e(){this.constructor=t}u(t,r),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}var f=function(){return(f=Object.assign||function(t){for(var r,e=1,n=arguments.length;e<n;e++)for(var o in r=arguments[e])Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o]);return t}).apply(this,arguments)};function s(t,r){var e={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(e[n[o]]=t[n[o]])}return e}function d(t,r,e,n){var o,i=arguments.length,a=i<3?r:null===n?n=Object.getOwnPropertyDescriptor(r,e):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,r,e,n);else for(var u=t.length-1;u>=0;u--)(o=t[u])&&(a=(i<3?o(a):i>3?o(r,e,a):o(r,e))||a);return i>3&&a&&Object.defineProperty(r,e,a),a}Object.create;function l(t,r){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var n,o,i=e.call(t),a=[];try{for(;(void 0===r||r-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return a}function h(t,r,e){if(e||2===arguments.length)for(var n,o=0,i=r.length;o<i;o++)!n&&o in r||(n||(n=Array.prototype.slice.call(r,0,o)),n[o]=r[o]);return t.concat(n||Array.prototype.slice.call(r))}var p;Object.create;!function(t){t.Cube="cube",t.Sphere="sphere",t.Grid="grid"}(p||(p={}));var y=function(){function t(){this.dependencies=["height","width","depth","anchor"]}return t.prototype.update=function(t){var r=t.height,e=void 0===r?0:r,n=t.width,o=void 0===n?0:n,i=t.depth;return{width:o,height:e,depth:void 0===i?0:i}},t=d([Object(i.singleton)({token:{token:o.GeometryAABBUpdater,named:p.Cube}})],t)}(),v=function(){function t(){this.dependencies=["height","width","depth","anchor"]}return t.prototype.update=function(t,r){var e=t.height,n=void 0===e?0:e,o=t.width,i=void 0===o?0:o,a=t.depth;return{width:i,height:n,depth:void 0===a?0:a}},t=d([Object(i.singleton)({token:{token:o.GeometryAABBUpdater,named:p.Sphere}})],t)}(),b=function(){function t(){this.dependencies=["width","height","anchor"]}return t.prototype.update=function(t,r){var e=t.width,n=void 0===e?0:e,o=t.height;return{width:n,height:void 0===o?0:o}},t=d([Object(i.singleton)({token:{token:o.GeometryAABBUpdater,named:p.Grid}})],t)}(),g="undefined"!=typeof Float32Array?Float32Array:Array,m=Math.random;Math.PI;function _(){var t=new g(3);return g!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function M(t){var r=new g(3);return r[0]=t[0],r[1]=t[1],r[2]=t[2],r}function S(t){var r=t[0],e=t[1],n=t[2];return Math.hypot(r,e,n)}function x(t,r,e){var n=new g(3);return n[0]=t,n[1]=r,n[2]=e,n}function O(t,r){return t[0]=r[0],t[1]=r[1],t[2]=r[2],t}function w(t,r,e,n){return t[0]=r,t[1]=e,t[2]=n,t}function B(t,r,e){return t[0]=r[0]+e[0],t[1]=r[1]+e[1],t[2]=r[2]+e[2],t}function j(t,r,e){return t[0]=r[0]-e[0],t[1]=r[1]-e[1],t[2]=r[2]-e[2],t}function A(t,r,e){return t[0]=r[0]*e[0],t[1]=r[1]*e[1],t[2]=r[2]*e[2],t}function P(t,r,e){return t[0]=r[0]/e[0],t[1]=r[1]/e[1],t[2]=r[2]/e[2],t}function G(t,r){return t[0]=Math.ceil(r[0]),t[1]=Math.ceil(r[1]),t[2]=Math.ceil(r[2]),t}function F(t,r){return t[0]=Math.floor(r[0]),t[1]=Math.floor(r[1]),t[2]=Math.floor(r[2]),t}function L(t,r,e){return t[0]=Math.min(r[0],e[0]),t[1]=Math.min(r[1],e[1]),t[2]=Math.min(r[2],e[2]),t}function C(t,r,e){return t[0]=Math.max(r[0],e[0]),t[1]=Math.max(r[1],e[1]),t[2]=Math.max(r[2],e[2]),t}function D(t,r){return t[0]=Math.round(r[0]),t[1]=Math.round(r[1]),t[2]=Math.round(r[2]),t}function V(t,r,e){return t[0]=r[0]*e,t[1]=r[1]*e,t[2]=r[2]*e,t}function z(t,r,e,n){return t[0]=r[0]+e[0]*n,t[1]=r[1]+e[1]*n,t[2]=r[2]+e[2]*n,t}function U(t,r){var e=r[0]-t[0],n=r[1]-t[1],o=r[2]-t[2];return Math.hypot(e,n,o)}function q(t,r){var e=r[0]-t[0],n=r[1]-t[1],o=r[2]-t[2];return e*e+n*n+o*o}function R(t){var r=t[0],e=t[1],n=t[2];return r*r+e*e+n*n}function I(t,r){return t[0]=-r[0],t[1]=-r[1],t[2]=-r[2],t}function E(t,r){return t[0]=1/r[0],t[1]=1/r[1],t[2]=1/r[2],t}function T(t,r){var e=r[0],n=r[1],o=r[2],i=e*e+n*n+o*o;return i>0&&(i=1/Math.sqrt(i)),t[0]=r[0]*i,t[1]=r[1]*i,t[2]=r[2]*i,t}function k(t,r){return t[0]*r[0]+t[1]*r[1]+t[2]*r[2]}function N(t,r,e){var n=r[0],o=r[1],i=r[2],a=e[0],u=e[1],c=e[2];return t[0]=o*c-i*u,t[1]=i*a-n*c,t[2]=n*u-o*a,t}function X(t,r,e,n){var o=r[0],i=r[1],a=r[2];return t[0]=o+n*(e[0]-o),t[1]=i+n*(e[1]-i),t[2]=a+n*(e[2]-a),t}function W(t,r,e,n,o,i){var a=i*i,u=a*(2*i-3)+1,c=a*(i-2)+i,f=a*(i-1),s=a*(3-2*i);return t[0]=r[0]*u+e[0]*c+n[0]*f+o[0]*s,t[1]=r[1]*u+e[1]*c+n[1]*f+o[1]*s,t[2]=r[2]*u+e[2]*c+n[2]*f+o[2]*s,t}function H(t,r,e,n,o,i){var a=1-i,u=a*a,c=i*i,f=u*a,s=3*i*u,d=3*c*a,l=c*i;return t[0]=r[0]*f+e[0]*s+n[0]*d+o[0]*l,t[1]=r[1]*f+e[1]*s+n[1]*d+o[1]*l,t[2]=r[2]*f+e[2]*s+n[2]*d+o[2]*l,t}function Q(t,r){r=r||1;var e=2*m()*Math.PI,n=2*m()-1,o=Math.sqrt(1-n*n)*r;return t[0]=Math.cos(e)*o,t[1]=Math.sin(e)*o,t[2]=n*r,t}function Y(t,r,e){var n=r[0],o=r[1],i=r[2],a=e[3]*n+e[7]*o+e[11]*i+e[15];return a=a||1,t[0]=(e[0]*n+e[4]*o+e[8]*i+e[12])/a,t[1]=(e[1]*n+e[5]*o+e[9]*i+e[13])/a,t[2]=(e[2]*n+e[6]*o+e[10]*i+e[14])/a,t}function Z(t,r,e){var n=r[0],o=r[1],i=r[2];return t[0]=n*e[0]+o*e[3]+i*e[6],t[1]=n*e[1]+o*e[4]+i*e[7],t[2]=n*e[2]+o*e[5]+i*e[8],t}function J(t,r,e){var n=e[0],o=e[1],i=e[2],a=e[3],u=r[0],c=r[1],f=r[2],s=o*f-i*c,d=i*u-n*f,l=n*c-o*u,h=o*l-i*d,p=i*s-n*l,y=n*d-o*s,v=2*a;return s*=v,d*=v,l*=v,h*=2,p*=2,y*=2,t[0]=u+s+h,t[1]=c+d+p,t[2]=f+l+y,t}function K(t,r,e,n){var o=[],i=[];return o[0]=r[0]-e[0],o[1]=r[1]-e[1],o[2]=r[2]-e[2],i[0]=o[0],i[1]=o[1]*Math.cos(n)-o[2]*Math.sin(n),i[2]=o[1]*Math.sin(n)+o[2]*Math.cos(n),t[0]=i[0]+e[0],t[1]=i[1]+e[1],t[2]=i[2]+e[2],t}function $(t,r,e,n){var o=[],i=[];return o[0]=r[0]-e[0],o[1]=r[1]-e[1],o[2]=r[2]-e[2],i[0]=o[2]*Math.sin(n)+o[0]*Math.cos(n),i[1]=o[1],i[2]=o[2]*Math.cos(n)-o[0]*Math.sin(n),t[0]=i[0]+e[0],t[1]=i[1]+e[1],t[2]=i[2]+e[2],t}function tt(t,r,e,n){var o=[],i=[];return o[0]=r[0]-e[0],o[1]=r[1]-e[1],o[2]=r[2]-e[2],i[0]=o[0]*Math.cos(n)-o[1]*Math.sin(n),i[1]=o[0]*Math.sin(n)+o[1]*Math.cos(n),i[2]=o[2],t[0]=i[0]+e[0],t[1]=i[1]+e[1],t[2]=i[2]+e[2],t}function rt(t,r){var e=t[0],n=t[1],o=t[2],i=r[0],a=r[1],u=r[2],c=Math.sqrt(e*e+n*n+o*o)*Math.sqrt(i*i+a*a+u*u),f=c&&k(t,r)/c;return Math.acos(Math.min(Math.max(f,-1),1))}function et(t){return t[0]=0,t[1]=0,t[2]=0,t}function nt(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"}function ot(t,r){return t[0]===r[0]&&t[1]===r[1]&&t[2]===r[2]}function it(t,r){var e=t[0],n=t[1],o=t[2],i=r[0],a=r[1],u=r[2];return Math.abs(e-i)<=1e-6*Math.max(1,Math.abs(e),Math.abs(i))&&Math.abs(n-a)<=1e-6*Math.max(1,Math.abs(n),Math.abs(a))&&Math.abs(o-u)<=1e-6*Math.max(1,Math.abs(o),Math.abs(u))}Math.hypot||(Math.hypot=function(){for(var t=0,r=arguments.length;r--;)t+=arguments[r]*arguments[r];return Math.sqrt(t)});var at,ut=j,ct=A,ft=P,st=U,dt=q,lt=S,ht=R,pt=(at=_(),function(t,r,e,n,o,i){var a,u;for(r||(r=3),e||(e=0),u=n?Math.min(n*r+e,t.length):t.length,a=e;a<u;a+=r)at[0]=t[a],at[1]=t[a+1],at[2]=t[a+2],o(at,at,i),t[a]=at[0],t[a+1]=at[1],t[a+2]=at[2];return t}),yt=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.both="\n "+a.Batch.ShaderLibrary.BothDeclaration+"\n ",e.vert="\n "+a.Batch.ShaderLibrary.VertDeclaration+"\n\n layout(location = "+r.a_Position+") attribute vec3 a_Position;\n layout(location = "+r.a_Normal+") attribute vec3 a_Normal;\n #ifdef USE_UV\n layout(location = "+r.a_Uv+") attribute vec2 a_Uv;\n varying vec2 v_Uv;\n #endif\n \n void main() {\n "+a.Batch.ShaderLibrary.Vert+"\n\n gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * vec4(a_Position, 1.0);\n\n "+a.Batch.ShaderLibrary.UvVert+"\n }\n ",e.frag="\n "+a.Batch.ShaderLibrary.FragDeclaration+"\n "+a.Batch.ShaderLibrary.UvFragDeclaration+"\n "+a.Batch.ShaderLibrary.MapFragDeclaration+"\n \n void main() {\n "+a.Batch.ShaderLibrary.Frag+"\n "+a.Batch.ShaderLibrary.MapFrag+"\n\n gl_FragColor = u_Color;\n gl_FragColor.a = gl_FragColor.a * u_Opacity * u_FillOpacity;\n }\n ",e}return c(r,t),r.a_Position=a.AttributeLocation.MAX,r.a_Normal=a.AttributeLocation.MAX+1,r.a_Uv=a.AttributeLocation.MAX+2,r.ub_ObjectParams=1,r}(a.DeviceProgram),vt=function(t){function r(){var r=null!==t&&t.apply(this,arguments)||this;return r.program=new yt,r}return c(r,t),r.prototype.validate=function(t){var r=this.instance;return!r.parsedStyle.map||r.parsedStyle.map===t.parsedStyle.map},r.prototype.buildGeometry=function(){var t=this;this.program.setDefineBool("USE_UV",!0);var r=this.instance.parsedStyle.map;r&&(this.program.setDefineBool("USE_MAP",!0),this.mapping=new a.TextureMapping,this.mapping.texture=this.texturePool.getOrCreateTexture(this.device,r,Object(a.makeTextureDescriptor2D)(a.Format.U8_RGBA_NORM,1,1,1),(function(){t.objects.forEach((function(r){r.renderable.dirty=!0,t.renderingService.dirtify()}))})),this.device.setResourceName(this.mapping.texture,"Image Texture"),this.mapping.sampler=this.renderHelper.getCache().createSampler({wrapS:0,wrapT:0,minFilter:1,magFilter:1,mipFilter:0,minLOD:0,maxLOD:0}));var e=this.buildAttributes(this.objects),n=e.indices,o=e.positions,i=e.normals,u=e.uvs;this.geometry.setIndices(new Uint32Array(n)),this.geometry.vertexCount=36,this.geometry.setVertexBuffer({bufferIndex:1,byteStride:12,frequency:1,attributes:[{format:a.Format.F32_RGB,bufferByteOffset:0,location:yt.a_Position}],data:Float32Array.from(o)}),this.geometry.setVertexBuffer({bufferIndex:2,byteStride:12,frequency:1,attributes:[{format:a.Format.F32_RGB,bufferByteOffset:0,location:yt.a_Normal}],data:Float32Array.from(i)}),this.geometry.setVertexBuffer({bufferIndex:3,byteStride:8,frequency:1,attributes:[{format:a.Format.F32_RG,bufferByteOffset:0,location:yt.a_Uv}],data:Float32Array.from(u)})},r.prototype.updateAttribute=function(r,e,n){t.prototype.updateAttribute.call(this,r,e,n);var o=this.objects.indexOf(r),i=this.geometry;if("width"===e||"height"===e||"depth"===e){var a=this.buildAttributes([r]).positions;i.updateVertexBuffer(1,yt.a_Position,o,new Uint8Array(new Float32Array(a).buffer))}},r.prototype.uploadUBO=function(t){t.setBindingLayouts([{numUniformBuffers:1,numSamplers:1}]),t.setSamplerBindingsFromTextureMappings([this.mapping])},r.prototype.buildAttributes=function(t){var r=[],e=[],o=[],i=[],a=0;return t.forEach((function(t){var u=t.attributes,c=u.widthSegments,f=void 0===c?1:c,s=u.heightSegments,d=void 0===s?1:s,p=u.depthSegments,y=void 0===p?1:p,v=u.height,b=void 0===v?0:v,g=u.width,m=void 0===g?0:g,_=u.depth,M=f,S=d,x=y,O=m/2,w=b/2,B=(void 0===_?0:_)/2,j=[n.fromValues(-O,-w,B),n.fromValues(O,-w,B),n.fromValues(O,w,B),n.fromValues(-O,w,B),n.fromValues(O,-w,-B),n.fromValues(-O,-w,-B),n.fromValues(-O,w,-B),n.fromValues(O,w,-B)],A=[[0,3,1],[4,7,5],[1,4,0],[3,6,2],[1,2,4],[5,6,0]],P=[[0,0,1],[0,0,-1],[0,-1,0],[0,1,0],[1,0,0],[-1,0,0]],G=1,F=2,L=3,C=4,D=5,V=[],z=[],U=[],q=[],R=[],I=0,E=function(t,r,e){var o,i,u,c;for(u=0;u<=r;u++)for(c=0;c<=e;c++){var f=n.create(),s=n.create(),d=n.create(),l=n.create();n.lerp(f,j[A[t][0]],j[A[t][1]],u/r),n.lerp(s,j[A[t][0]],j[A[t][2]],c/e),n.sub(d,s,j[A[t][0]]),n.add(l,f,d),o=u/r,i=c/e,V.push(l[0],l[1],l[2]),z.push(P[t][0],P[t][1],P[t][2]),U.push(o,i),o=.875*(o/=3)+4/64,i=.875*(i/=3)+4/64,o+=t%3/3,i+=Math.floor(t/3)/3,q.push(o,i),u<r&&c<e&&(R.push(I+e+1+a,I+1+a,I+a),R.push(I+e+1+a,I+e+2+a,I+1+a)),I++}};E(0,M,S),E(G,M,S),E(F,M,x),E(L,M,x),E(C,x,S),E(D,x,S),a+=24,r.push.apply(r,h([],l(V),!1)),e.push.apply(e,h([],l(z),!1)),o.push.apply(o,h([],l(U),!1)),i.push.apply(i,h([],l(R),!1))})),{indices:i,positions:r,normals:e,uvs:o}},r=d([Object(i.singleton)()],r)}(a.Batch),bt=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.both="\n "+a.Batch.ShaderLibrary.BothDeclaration+"\n ",e.vert="\n "+a.Batch.ShaderLibrary.VertDeclaration+"\n\n layout(location = "+r.a_Position+") attribute vec3 a_Position;\n layout(location = "+r.a_GridSize+") attribute vec2 a_GridSize;\n\n varying vec3 v_Position;\n varying vec2 v_GridSize;\n \n void main() {\n "+a.Batch.ShaderLibrary.Vert+"\n\n v_GridSize = a_GridSize;\n v_Position = a_Position;\n\n gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * vec4(a_Position, 1.0);\n }\n ",e.frag="\n "+a.Batch.ShaderLibrary.FragDeclaration+"\n\n // #extension GL_OES_standard_derivatives : enable\n\n varying vec3 v_Position;\n varying vec2 v_GridSize;\n \n void main() {\n "+a.Batch.ShaderLibrary.Frag+"\n\n // vec4 u_GridColor = u_StrokeColor;\n vec4 u_GridColor = u_Color;\n float u_GridSize2 = v_GridSize.y;\n\n float wx = v_Position.x;\n float wz = v_Position.z;\n\n float x1 = abs(fract(wx / u_GridSize2 - 0.5) - 0.5) / fwidth(wx) * u_GridSize2;\n float z1 = abs(fract(wz / u_GridSize2 - 0.5) - 0.5) / fwidth(wz) * u_GridSize2;\n\n float v1 = 1.0 - clamp(min(x1, z1), 0.0, 1.0);\n gl_FragColor = mix(gl_FragColor, u_GridColor, v1);\n\n gl_FragColor.a = gl_FragColor.a * u_Opacity;\n }\n ",e}return c(r,t),r.a_Position=a.AttributeLocation.MAX,r.a_GridSize=a.AttributeLocation.MAX+1,r.ub_ObjectParams=1,r}(a.DeviceProgram),gt=function(t){function r(){var r=null!==t&&t.apply(this,arguments)||this;return r.program=new bt,r}return c(r,t),r.prototype.validate=function(t){return!0},r.prototype.updateAttribute=function(r,e,n){t.prototype.updateAttribute.call(this,r,e,n);this.objects.indexOf(r),this.geometry},r.prototype.uploadUBO=function(t){t.setMegaStateFlags({cullMode:0}),t.setBindingLayouts([{numUniformBuffers:1,numSamplers:0}])},r.prototype.buildGeometry=function(){var t=this.instance.attributes,r=t.height,e=t.width/2,n=r/2;this.geometry.setIndices(new Uint32Array([0,3,2,2,1,0])),this.geometry.vertexCount=6,this.geometry.setVertexBuffer({bufferIndex:1,byteStride:12,frequency:1,attributes:[{format:a.Format.F32_RGB,bufferByteOffset:0,location:bt.a_Position}],data:Float32Array.from([-e,0,-n,e,0,-n,e,0,n,-e,0,n])}),this.geometry.setVertexBuffer({bufferIndex:2,byteStride:8,frequency:2,attributes:[{format:a.Format.F32_RG,bufferByteOffset:0,location:bt.a_GridSize,divisor:1}],data:Float32Array.from([10,10])})},r=d([Object(i.singleton)()],r)}(a.Batch),mt=function(t){function r(r){var e=r.style,n=s(r,["style"]);return t.call(this,f({type:p.Cube,style:f({height:0,width:0,depth:0,widthSegments:1,heightSegments:1,depthSegments:1},e)},n))||this}return c(r,t),r}(o.DisplayObject),_t=function(t){function r(r){var e=r.style,n=s(r,["style"]);return t.call(this,f({type:p.Sphere,style:f({},e)},n))||this}return c(r,t),r}(o.DisplayObject),Mt=function(t){function r(r){var e=r.style,n=s(r,["style"]);return t.call(this,f({type:p.Grid,style:f({height:0,width:0},e)},n))||this}return c(r,t),r}(o.DisplayObject);o.globalContainer.register(y),o.globalContainer.register(v),o.globalContainer.register(b);var St=Object(i.Module)((function(t){Object(a.registerModelBuilder)(vt,p.Cube),Object(a.registerModelBuilder)(gt,p.Grid)})),xt=function(){function t(){}return t.prototype.init=function(t){t.load(St,!0)},t.prototype.destroy=function(t){},t}()}])})); | ||
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("mana-syringe"),require("@antv/g-plugin-webgl-renderer")):"function"==typeof define&&define.amd?define(["mana-syringe","@antv/g-plugin-webgl-renderer"],t):"object"==typeof exports?exports["3D"]=t(require("mana-syringe"),require("@antv/g-plugin-webgl-renderer")):(n.G=n.G||{},n.G["3D"]=t(n.G.ManaSyringe,n.G.WebGL.WebGLRenderer))}(window,(function(n,t){return function(n){var t={};function r(e){if(t[e])return t[e].exports;var u=t[e]={i:e,l:!1,exports:{}};return n[e].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=n,r.c=t,r.d=function(n,t,e){r.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:e})},r.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},r.t=function(n,t){if(1&t&&(n=r(n)),8&t)return n;if(4&t&&"object"==typeof n&&n&&n.__esModule)return n;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:n}),2&t&&"string"!=typeof n)for(var u in n)r.d(e,u,function(t){return n[t]}.bind(null,u));return e},r.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(t,"a",t),t},r.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},r.p="",r(r.s=10)}({0:function(t,r){t.exports=n},1:function(n,r){n.exports=t},10:function(n,t,r){"use strict";r.r(t),r.d(t,"CubeGeometry",(function(){return an})),r.d(t,"containerModule",(function(){return cn})),r.d(t,"Plugin",(function(){return fn}));var e={};r.r(e),r.d(e,"create",(function(){return d})),r.d(e,"clone",(function(){return l})),r.d(e,"length",(function(){return h})),r.d(e,"fromValues",(function(){return p})),r.d(e,"copy",(function(){return M})),r.d(e,"set",(function(){return v})),r.d(e,"add",(function(){return y})),r.d(e,"subtract",(function(){return m})),r.d(e,"multiply",(function(){return b})),r.d(e,"divide",(function(){return g})),r.d(e,"ceil",(function(){return x})),r.d(e,"floor",(function(){return j})),r.d(e,"min",(function(){return w})),r.d(e,"max",(function(){return q})),r.d(e,"round",(function(){return O})),r.d(e,"scale",(function(){return _})),r.d(e,"scaleAndAdd",(function(){return S})),r.d(e,"distance",(function(){return A})),r.d(e,"squaredDistance",(function(){return P})),r.d(e,"squaredLength",(function(){return G})),r.d(e,"negate",(function(){return V})),r.d(e,"inverse",(function(){return D})),r.d(e,"normalize",(function(){return L})),r.d(e,"dot",(function(){return z})),r.d(e,"cross",(function(){return E})),r.d(e,"lerp",(function(){return F})),r.d(e,"hermite",(function(){return T})),r.d(e,"bezier",(function(){return C})),r.d(e,"random",(function(){return I})),r.d(e,"transformMat4",(function(){return W})),r.d(e,"transformMat3",(function(){return Q})),r.d(e,"transformQuat",(function(){return R})),r.d(e,"rotateX",(function(){return X})),r.d(e,"rotateY",(function(){return Y})),r.d(e,"rotateZ",(function(){return Z})),r.d(e,"angle",(function(){return k})),r.d(e,"zero",(function(){return B})),r.d(e,"str",(function(){return H})),r.d(e,"exactEquals",(function(){return J})),r.d(e,"equals",(function(){return K})),r.d(e,"sub",(function(){return U})),r.d(e,"mul",(function(){return $})),r.d(e,"div",(function(){return nn})),r.d(e,"dist",(function(){return tn})),r.d(e,"sqrDist",(function(){return rn})),r.d(e,"len",(function(){return en})),r.d(e,"sqrLen",(function(){return un})),r.d(e,"forEach",(function(){return on}));var u=r(0),o=function(n,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,t){n.__proto__=t}||function(n,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])})(n,t)}; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */Object.create;function i(n,t){var r="function"==typeof Symbol&&n[Symbol.iterator];if(!r)return n;var e,u,o=r.call(n),i=[];try{for(;(void 0===t||t-- >0)&&!(e=o.next()).done;)i.push(e.value)}catch(n){u={error:n}}finally{try{e&&!e.done&&(r=o.return)&&r.call(o)}finally{if(u)throw u.error}}return i}function a(n,t,r){if(r||2===arguments.length)for(var e,u=0,o=t.length;u<o;u++)!e&&u in t||(e||(e=Array.prototype.slice.call(t,0,u)),e[u]=t[u]);return n.concat(e||Array.prototype.slice.call(t))}Object.create;var c=r(1),f="undefined"!=typeof Float32Array?Float32Array:Array,s=Math.random;Math.PI;function d(){var n=new f(3);return f!=Float32Array&&(n[0]=0,n[1]=0,n[2]=0),n}function l(n){var t=new f(3);return t[0]=n[0],t[1]=n[1],t[2]=n[2],t}function h(n){var t=n[0],r=n[1],e=n[2];return Math.hypot(t,r,e)}function p(n,t,r){var e=new f(3);return e[0]=n,e[1]=t,e[2]=r,e}function M(n,t){return n[0]=t[0],n[1]=t[1],n[2]=t[2],n}function v(n,t,r,e){return n[0]=t,n[1]=r,n[2]=e,n}function y(n,t,r){return n[0]=t[0]+r[0],n[1]=t[1]+r[1],n[2]=t[2]+r[2],n}function m(n,t,r){return n[0]=t[0]-r[0],n[1]=t[1]-r[1],n[2]=t[2]-r[2],n}function b(n,t,r){return n[0]=t[0]*r[0],n[1]=t[1]*r[1],n[2]=t[2]*r[2],n}function g(n,t,r){return n[0]=t[0]/r[0],n[1]=t[1]/r[1],n[2]=t[2]/r[2],n}function x(n,t){return n[0]=Math.ceil(t[0]),n[1]=Math.ceil(t[1]),n[2]=Math.ceil(t[2]),n}function j(n,t){return n[0]=Math.floor(t[0]),n[1]=Math.floor(t[1]),n[2]=Math.floor(t[2]),n}function w(n,t,r){return n[0]=Math.min(t[0],r[0]),n[1]=Math.min(t[1],r[1]),n[2]=Math.min(t[2],r[2]),n}function q(n,t,r){return n[0]=Math.max(t[0],r[0]),n[1]=Math.max(t[1],r[1]),n[2]=Math.max(t[2],r[2]),n}function O(n,t){return n[0]=Math.round(t[0]),n[1]=Math.round(t[1]),n[2]=Math.round(t[2]),n}function _(n,t,r){return n[0]=t[0]*r,n[1]=t[1]*r,n[2]=t[2]*r,n}function S(n,t,r,e){return n[0]=t[0]+r[0]*e,n[1]=t[1]+r[1]*e,n[2]=t[2]+r[2]*e,n}function A(n,t){var r=t[0]-n[0],e=t[1]-n[1],u=t[2]-n[2];return Math.hypot(r,e,u)}function P(n,t){var r=t[0]-n[0],e=t[1]-n[1],u=t[2]-n[2];return r*r+e*e+u*u}function G(n){var t=n[0],r=n[1],e=n[2];return t*t+r*r+e*e}function V(n,t){return n[0]=-t[0],n[1]=-t[1],n[2]=-t[2],n}function D(n,t){return n[0]=1/t[0],n[1]=1/t[1],n[2]=1/t[2],n}function L(n,t){var r=t[0],e=t[1],u=t[2],o=r*r+e*e+u*u;return o>0&&(o=1/Math.sqrt(o)),n[0]=t[0]*o,n[1]=t[1]*o,n[2]=t[2]*o,n}function z(n,t){return n[0]*t[0]+n[1]*t[1]+n[2]*t[2]}function E(n,t,r){var e=t[0],u=t[1],o=t[2],i=r[0],a=r[1],c=r[2];return n[0]=u*c-o*a,n[1]=o*i-e*c,n[2]=e*a-u*i,n}function F(n,t,r,e){var u=t[0],o=t[1],i=t[2];return n[0]=u+e*(r[0]-u),n[1]=o+e*(r[1]-o),n[2]=i+e*(r[2]-i),n}function T(n,t,r,e,u,o){var i=o*o,a=i*(2*o-3)+1,c=i*(o-2)+o,f=i*(o-1),s=i*(3-2*o);return n[0]=t[0]*a+r[0]*c+e[0]*f+u[0]*s,n[1]=t[1]*a+r[1]*c+e[1]*f+u[1]*s,n[2]=t[2]*a+r[2]*c+e[2]*f+u[2]*s,n}function C(n,t,r,e,u,o){var i=1-o,a=i*i,c=o*o,f=a*i,s=3*o*a,d=3*c*i,l=c*o;return n[0]=t[0]*f+r[0]*s+e[0]*d+u[0]*l,n[1]=t[1]*f+r[1]*s+e[1]*d+u[1]*l,n[2]=t[2]*f+r[2]*s+e[2]*d+u[2]*l,n}function I(n,t){t=t||1;var r=2*s()*Math.PI,e=2*s()-1,u=Math.sqrt(1-e*e)*t;return n[0]=Math.cos(r)*u,n[1]=Math.sin(r)*u,n[2]=e*t,n}function W(n,t,r){var e=t[0],u=t[1],o=t[2],i=r[3]*e+r[7]*u+r[11]*o+r[15];return i=i||1,n[0]=(r[0]*e+r[4]*u+r[8]*o+r[12])/i,n[1]=(r[1]*e+r[5]*u+r[9]*o+r[13])/i,n[2]=(r[2]*e+r[6]*u+r[10]*o+r[14])/i,n}function Q(n,t,r){var e=t[0],u=t[1],o=t[2];return n[0]=e*r[0]+u*r[3]+o*r[6],n[1]=e*r[1]+u*r[4]+o*r[7],n[2]=e*r[2]+u*r[5]+o*r[8],n}function R(n,t,r){var e=r[0],u=r[1],o=r[2],i=r[3],a=t[0],c=t[1],f=t[2],s=u*f-o*c,d=o*a-e*f,l=e*c-u*a,h=u*l-o*d,p=o*s-e*l,M=e*d-u*s,v=2*i;return s*=v,d*=v,l*=v,h*=2,p*=2,M*=2,n[0]=a+s+h,n[1]=c+d+p,n[2]=f+l+M,n}function X(n,t,r,e){var u=[],o=[];return u[0]=t[0]-r[0],u[1]=t[1]-r[1],u[2]=t[2]-r[2],o[0]=u[0],o[1]=u[1]*Math.cos(e)-u[2]*Math.sin(e),o[2]=u[1]*Math.sin(e)+u[2]*Math.cos(e),n[0]=o[0]+r[0],n[1]=o[1]+r[1],n[2]=o[2]+r[2],n}function Y(n,t,r,e){var u=[],o=[];return u[0]=t[0]-r[0],u[1]=t[1]-r[1],u[2]=t[2]-r[2],o[0]=u[2]*Math.sin(e)+u[0]*Math.cos(e),o[1]=u[1],o[2]=u[2]*Math.cos(e)-u[0]*Math.sin(e),n[0]=o[0]+r[0],n[1]=o[1]+r[1],n[2]=o[2]+r[2],n}function Z(n,t,r,e){var u=[],o=[];return u[0]=t[0]-r[0],u[1]=t[1]-r[1],u[2]=t[2]-r[2],o[0]=u[0]*Math.cos(e)-u[1]*Math.sin(e),o[1]=u[0]*Math.sin(e)+u[1]*Math.cos(e),o[2]=u[2],n[0]=o[0]+r[0],n[1]=o[1]+r[1],n[2]=o[2]+r[2],n}function k(n,t){var r=n[0],e=n[1],u=n[2],o=t[0],i=t[1],a=t[2],c=Math.sqrt(r*r+e*e+u*u)*Math.sqrt(o*o+i*i+a*a),f=c&&z(n,t)/c;return Math.acos(Math.min(Math.max(f,-1),1))}function B(n){return n[0]=0,n[1]=0,n[2]=0,n}function H(n){return"vec3("+n[0]+", "+n[1]+", "+n[2]+")"}function J(n,t){return n[0]===t[0]&&n[1]===t[1]&&n[2]===t[2]}function K(n,t){var r=n[0],e=n[1],u=n[2],o=t[0],i=t[1],a=t[2];return Math.abs(r-o)<=1e-6*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(e-i)<=1e-6*Math.max(1,Math.abs(e),Math.abs(i))&&Math.abs(u-a)<=1e-6*Math.max(1,Math.abs(u),Math.abs(a))}Math.hypot||(Math.hypot=function(){for(var n=0,t=arguments.length;t--;)n+=arguments[t]*arguments[t];return Math.sqrt(n)});var N,U=m,$=b,nn=g,tn=A,rn=P,en=h,un=G,on=(N=d(),function(n,t,r,e,u,o){var i,a;for(t||(t=3),r||(r=0),a=e?Math.min(e*t+r,n.length):n.length,i=r;i<a;i+=t)N[0]=n[i],N[1]=n[i+1],N[2]=n[i+2],u(N,N,o),n[i]=N[0],n[i+1]=N[1],n[i+2]=N[2];return n}),an=function(n){function t(t){var r=n.call(this)||this;return r.props=t,r}return function(n,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=n}o(n,t),n.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}(t,n),t.prototype.init=function(){var n=this.buildAttributes();n.indices,n.positions,n.normals,n.uvs},t.prototype.buildAttributes=function(){var n=[],t=[],r=[],u=[],o=0,c=this.props,f=c.widthSegments,s=void 0===f?1:f,d=c.heightSegments,l=void 0===d?1:d,h=c.depthSegments,p=void 0===h?1:h,M=c.height,v=void 0===M?0:M,y=c.width,m=void 0===y?0:y,b=c.depth,g=s,x=l,j=p,w=m/2,q=v/2,O=(void 0===b?0:b)/2,_=[e.fromValues(-w,-q,O),e.fromValues(w,-q,O),e.fromValues(w,q,O),e.fromValues(-w,q,O),e.fromValues(w,-q,-O),e.fromValues(-w,-q,-O),e.fromValues(-w,q,-O),e.fromValues(w,q,-O)],S=[[0,3,1],[4,7,5],[1,4,0],[3,6,2],[1,2,4],[5,6,0]],A=[[0,0,1],[0,0,-1],[0,-1,0],[0,1,0],[1,0,0],[-1,0,0]],P=1,G=2,V=3,D=4,L=5,z=[],E=[],F=[],T=[],C=[],I=0,W=function(n,t,r){var u,i,a,c;for(a=0;a<=t;a++)for(c=0;c<=r;c++){var f=e.create(),s=e.create(),d=e.create(),l=e.create();e.lerp(f,_[S[n][0]],_[S[n][1]],a/t),e.lerp(s,_[S[n][0]],_[S[n][2]],c/r),e.sub(d,s,_[S[n][0]]),e.add(l,f,d),u=a/t,i=c/r,z.push(l[0],l[1],l[2]),E.push(A[n][0],A[n][1],A[n][2]),F.push(u,i),u=.875*(u/=3)+4/64,i=.875*(i/=3)+4/64,u+=n%3/3,i+=Math.floor(n/3)/3,T.push(u,i),a<t&&c<r&&(C.push(I+r+1+o,I+1+o,I+o),C.push(I+r+1+o,I+r+2+o,I+1+o)),I++}};return W(0,g,x),W(P,g,x),W(G,g,j),W(V,g,j),W(D,j,x),W(L,j,x),o+=24,n.push.apply(n,a([],i(z),!1)),t.push.apply(t,a([],i(E),!1)),r.push.apply(r,a([],i(F),!1)),u.push.apply(u,a([],i(C),!1)),{indices:u,positions:n,normals:t,uvs:r}},t}(c.Geometry),cn=Object(u.Module)((function(n){})),fn=function(){function n(){}return n.prototype.init=function(n){n.load(cn,!0)},n.prototype.destroy=function(n){},n}()}})})); |
@@ -1,10 +0,1 @@ | ||
import { GeometryAABBUpdater } from '@antv/g'; | ||
import { ParsedCubeStyleProps } from '../Cube'; | ||
export declare class CubeUpdater implements GeometryAABBUpdater<ParsedCubeStyleProps> { | ||
dependencies: string[]; | ||
update(attributes: ParsedCubeStyleProps): { | ||
width: number; | ||
height: number; | ||
depth: number; | ||
}; | ||
} | ||
@@ -1,37 +0,18 @@ | ||
import { __decorate } from "tslib"; | ||
import { singleton } from 'mana-syringe'; | ||
import { GeometryAABBUpdater } from '@antv/g'; | ||
import { SHAPE_3D } from '../types'; | ||
var CubeUpdater = | ||
/** @class */ | ||
function () { | ||
function CubeUpdater() { | ||
this.dependencies = ['height', 'width', 'depth', 'anchor']; | ||
} // @ts-ignore | ||
CubeUpdater.prototype.update = function (attributes) { | ||
var _a = attributes.height, | ||
height = _a === void 0 ? 0 : _a, | ||
_b = attributes.width, | ||
width = _b === void 0 ? 0 : _b, | ||
_c = attributes.depth, | ||
depth = _c === void 0 ? 0 : _c; | ||
return { | ||
width: width, | ||
height: height, | ||
depth: depth | ||
}; | ||
}; | ||
CubeUpdater = __decorate([singleton({ | ||
token: { | ||
token: GeometryAABBUpdater, | ||
named: SHAPE_3D.Cube | ||
} | ||
})], CubeUpdater); | ||
return CubeUpdater; | ||
}(); | ||
export { CubeUpdater }; | ||
// import { vec3 } from 'gl-matrix'; | ||
// import { singleton } from 'mana-syringe'; | ||
// import { GeometryAABBUpdater, AABB } from '@antv/g'; | ||
// import { ParsedCubeStyleProps } from '../Cube'; | ||
// import { SHAPE_3D } from '../types'; | ||
// @singleton({ token: { token: GeometryAABBUpdater, named: SHAPE_3D.Cube } }) | ||
// export class CubeUpdater implements GeometryAABBUpdater<ParsedCubeStyleProps> { | ||
// dependencies = ['height', 'width', 'depth', 'anchor']; | ||
// // @ts-ignore | ||
// update(attributes: ParsedCubeStyleProps) { | ||
// const { height = 0, width = 0, depth = 0 } = attributes; | ||
// return { | ||
// width, | ||
// height, | ||
// depth, | ||
// }; | ||
// } | ||
// } |
@@ -1,9 +0,1 @@ | ||
import { GeometryAABBUpdater, AABB } from '@antv/g'; | ||
import { GridStyleProps } from '../Grid'; | ||
export declare class GridUpdater implements GeometryAABBUpdater<GridStyleProps> { | ||
dependencies: string[]; | ||
update(attributes: GridStyleProps, aabb: AABB): { | ||
width: number; | ||
height: number; | ||
}; | ||
} | ||
@@ -1,36 +0,18 @@ | ||
import { __decorate } from "tslib"; | ||
import { singleton } from 'mana-syringe'; | ||
import { GeometryAABBUpdater } from '@antv/g'; | ||
import { SHAPE_3D } from '../types'; | ||
var GridUpdater = | ||
/** @class */ | ||
function () { | ||
// @ts-ignore | ||
function GridUpdater() { | ||
this.dependencies = ['width', 'height', 'anchor']; | ||
} // @ts-ignore | ||
GridUpdater.prototype.update = function (attributes, aabb) { | ||
var _a = attributes.width, | ||
width = _a === void 0 ? 0 : _a, | ||
_b = attributes.height, | ||
height = _b === void 0 ? 0 : _b; | ||
return { | ||
width: width, | ||
height: height | ||
}; | ||
}; | ||
GridUpdater = __decorate([singleton({ | ||
token: { | ||
token: GeometryAABBUpdater, | ||
named: SHAPE_3D.Grid | ||
} | ||
}) // @ts-ignore | ||
], GridUpdater); | ||
return GridUpdater; | ||
}(); | ||
export { GridUpdater }; | ||
// import { vec3 } from 'gl-matrix'; | ||
// import { singleton } from 'mana-syringe'; | ||
// import { GeometryAABBUpdater, AABB } from '@antv/g'; | ||
// import { GridStyleProps } from '../Grid'; | ||
// import { SHAPE_3D } from '../types'; | ||
// @singleton({ token: { token: GeometryAABBUpdater, named: SHAPE_3D.Grid } }) | ||
// // @ts-ignore | ||
// export class GridUpdater implements GeometryAABBUpdater<GridStyleProps> { | ||
// dependencies = ['width', 'height', 'anchor']; | ||
// // @ts-ignore | ||
// update(attributes: GridStyleProps, aabb: AABB) { | ||
// const { width = 0, height = 0 } = attributes; | ||
// return { | ||
// width, | ||
// height, | ||
// }; | ||
// } | ||
// } |
@@ -1,10 +0,1 @@ | ||
import { GeometryAABBUpdater, AABB } from '@antv/g'; | ||
import { SphereStyleProps } from '../Sphere'; | ||
export declare class SphereUpdater implements GeometryAABBUpdater<SphereStyleProps> { | ||
dependencies: string[]; | ||
update(attributes: SphereStyleProps, aabb: AABB): { | ||
width: number; | ||
height: number; | ||
depth: number; | ||
}; | ||
} | ||
@@ -1,39 +0,19 @@ | ||
import { __decorate } from "tslib"; | ||
import { singleton } from 'mana-syringe'; | ||
import { GeometryAABBUpdater } from '@antv/g'; | ||
import { SHAPE_3D } from '../types'; | ||
var SphereUpdater = | ||
/** @class */ | ||
function () { | ||
// @ts-ignore | ||
function SphereUpdater() { | ||
this.dependencies = ['height', 'width', 'depth', 'anchor']; | ||
} // @ts-ignore | ||
SphereUpdater.prototype.update = function (attributes, aabb) { | ||
var _a = attributes.height, | ||
height = _a === void 0 ? 0 : _a, | ||
_b = attributes.width, | ||
width = _b === void 0 ? 0 : _b, | ||
_c = attributes.depth, | ||
depth = _c === void 0 ? 0 : _c; | ||
return { | ||
width: width, | ||
height: height, | ||
depth: depth | ||
}; | ||
}; | ||
SphereUpdater = __decorate([singleton({ | ||
token: { | ||
token: GeometryAABBUpdater, | ||
named: SHAPE_3D.Sphere | ||
} | ||
}) // @ts-ignore | ||
], SphereUpdater); | ||
return SphereUpdater; | ||
}(); | ||
export { SphereUpdater }; | ||
// import { vec3 } from 'gl-matrix'; | ||
// import { singleton } from 'mana-syringe'; | ||
// import { GeometryAABBUpdater, AABB } from '@antv/g'; | ||
// import { SphereStyleProps } from '../Sphere'; | ||
// import { SHAPE_3D } from '../types'; | ||
// @singleton({ token: { token: GeometryAABBUpdater, named: SHAPE_3D.Sphere } }) | ||
// // @ts-ignore | ||
// export class SphereUpdater implements GeometryAABBUpdater<SphereStyleProps> { | ||
// dependencies = ['height', 'width', 'depth', 'anchor']; | ||
// // @ts-ignore | ||
// update(attributes: SphereStyleProps, aabb: AABB) { | ||
// const { height = 0, width = 0, depth = 0 } = attributes; | ||
// return { | ||
// width, | ||
// height, | ||
// depth, | ||
// }; | ||
// } | ||
// } |
@@ -1,8 +0,1 @@ | ||
import { BaseStyleProps, DisplayObject, DisplayObjectConfig } from '@antv/g'; | ||
export interface GridStyleProps extends BaseStyleProps { | ||
height: number; | ||
width: number; | ||
} | ||
export declare class Grid extends DisplayObject<GridStyleProps> { | ||
constructor({ style, ...rest }: DisplayObjectConfig<GridStyleProps>); | ||
} | ||
@@ -1,27 +0,20 @@ | ||
import { __assign, __extends, __rest } from "tslib"; | ||
import { DisplayObject } from '@antv/g'; | ||
import { SHAPE_3D } from './types'; | ||
var Grid = | ||
/** @class */ | ||
function (_super) { | ||
__extends(Grid, _super); | ||
function Grid(_a) { | ||
var style = _a.style, | ||
rest = __rest(_a, ["style"]); | ||
return _super.call(this, __assign({ | ||
// @ts-ignore | ||
type: SHAPE_3D.Grid, | ||
style: __assign({ | ||
height: 0, | ||
width: 0 | ||
}, style) | ||
}, rest)) || this; | ||
} | ||
return Grid; | ||
}(DisplayObject); | ||
export { Grid }; | ||
// import { BaseStyleProps, DisplayObject, DisplayObjectConfig } from '@antv/g'; | ||
// import { SHAPE_3D } from './types'; | ||
// export interface GridStyleProps extends BaseStyleProps { | ||
// height: number; | ||
// width: number; | ||
// } | ||
// export class Grid extends DisplayObject<GridStyleProps> { | ||
// constructor({ style, ...rest }: DisplayObjectConfig<GridStyleProps>) { | ||
// super({ | ||
// // @ts-ignore | ||
// type: SHAPE_3D.Grid, | ||
// style: { | ||
// height: 0, | ||
// width: 0, | ||
// ...style, | ||
// }, | ||
// ...rest, | ||
// }); | ||
// } | ||
// } |
import { RendererPlugin } from '@antv/g'; | ||
import { Syringe } from 'mana-syringe'; | ||
import { Cube } from './Cube'; | ||
import { Sphere } from './Sphere'; | ||
import { Grid } from './Grid'; | ||
export * from './geometries'; | ||
export declare const containerModule: import("mana-syringe").SyringeModule; | ||
@@ -11,2 +9,1 @@ export declare class Plugin implements RendererPlugin { | ||
} | ||
export { Cube, Sphere, Grid }; |
@@ -1,22 +0,21 @@ | ||
import { globalContainer } from '@antv/g'; | ||
import { Module } from 'mana-syringe'; | ||
import { registerModelBuilder } from '@antv/g-plugin-webgl-renderer'; | ||
import { CubeUpdater } from './aabb/CubeUpdater'; | ||
import { SphereUpdater } from './aabb/SphereUpdater'; | ||
import { GridUpdater } from './aabb/GridUpdater'; | ||
import { CubeModelBuilder } from './model/Cube'; // import { SphereModelBuilder } from './model/Sphere'; | ||
import { Module } from 'mana-syringe'; // import { registerModelBuilder, Batch } from '@antv/g-plugin-webgl-renderer'; | ||
// import { CubeUpdater } from './aabb/CubeUpdater'; | ||
// import { SphereUpdater } from './aabb/SphereUpdater'; | ||
// import { GridUpdater } from './aabb/GridUpdater'; | ||
// import { CubeModelBuilder } from './model/Cube'; | ||
// // import { SphereModelBuilder } from './model/Sphere'; | ||
// import { GridModelBuilder } from './model/Grid'; | ||
// import { SHAPE_3D } from './types'; | ||
// import { Cube } from './Cube'; | ||
// import { Sphere } from './Sphere'; | ||
// import { Grid } from './Grid'; | ||
import { GridModelBuilder } from './model/Grid'; | ||
import { SHAPE_3D } from './types'; | ||
import { Cube } from './Cube'; | ||
import { Sphere } from './Sphere'; | ||
import { Grid } from './Grid'; // TODO: provide more friendly API like `registerGeometry` | ||
export * from './geometries'; // // TODO: provide more friendly API like `registerGeometry` | ||
// globalContainer.register(CubeUpdater); | ||
// globalContainer.register(SphereUpdater); | ||
// globalContainer.register(GridUpdater); | ||
globalContainer.register(CubeUpdater); | ||
globalContainer.register(SphereUpdater); | ||
globalContainer.register(GridUpdater); | ||
export var containerModule = Module(function (register) { | ||
registerModelBuilder(CubeModelBuilder, SHAPE_3D.Cube); // registerModelBuilder(SphereModelBuilder, SHAPE_3D.Sphere); | ||
registerModelBuilder(GridModelBuilder, SHAPE_3D.Grid); | ||
export var containerModule = Module(function (register) {// registerModelBuilder(CubeModelBuilder, SHAPE_3D.Cube); | ||
// // registerModelBuilder(SphereModelBuilder, SHAPE_3D.Sphere); | ||
// registerModelBuilder(GridModelBuilder, SHAPE_3D.Grid); | ||
}); | ||
@@ -40,3 +39,2 @@ | ||
export { Plugin }; | ||
export { Cube, Sphere, Grid }; | ||
export { Plugin }; // export { Cube, Sphere, Grid }; |
@@ -1,26 +0,1 @@ | ||
import { DisplayObject } from '@antv/g'; | ||
import { Batch, AttributeLocation, DeviceProgram, RenderInst } from '@antv/g-plugin-webgl-renderer'; | ||
import { Cube } from '../Cube'; | ||
declare class CubeProgram extends DeviceProgram { | ||
static a_Position: AttributeLocation; | ||
static a_Normal: number; | ||
static a_Uv: number; | ||
static ub_ObjectParams: number; | ||
both: string; | ||
vert: string; | ||
frag: string; | ||
} | ||
export declare class CubeModelBuilder extends Batch { | ||
program: CubeProgram; | ||
validate(object: DisplayObject): boolean; | ||
buildGeometry(): void; | ||
updateAttribute(object: DisplayObject, name: string, value: any): void; | ||
uploadUBO(renderInst: RenderInst): void; | ||
protected buildAttributes(objects: Cube[]): { | ||
indices: number[]; | ||
positions: number[]; | ||
normals: number[]; | ||
uvs: number[]; | ||
}; | ||
} | ||
export {}; | ||
@@ -1,274 +0,286 @@ | ||
import { __decorate, __extends, __read, __spreadArray } from "tslib"; | ||
import { singleton } from 'mana-syringe'; | ||
import { vec3 } from 'gl-matrix'; | ||
import { Batch, AttributeLocation, DeviceProgram, Format, makeTextureDescriptor2D, TextureMapping } from '@antv/g-plugin-webgl-renderer'; | ||
var primitiveUv1Padding = 4.0 / 64; | ||
var primitiveUv1PaddingScale = 1.0 - primitiveUv1Padding * 2; | ||
var CubeProgram = | ||
/** @class */ | ||
function (_super) { | ||
__extends(CubeProgram, _super); | ||
function CubeProgram() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.both = "\n " + Batch.ShaderLibrary.BothDeclaration + "\n "; | ||
_this.vert = "\n " + Batch.ShaderLibrary.VertDeclaration + "\n\n layout(location = " + CubeProgram.a_Position + ") attribute vec3 a_Position;\n layout(location = " + CubeProgram.a_Normal + ") attribute vec3 a_Normal;\n #ifdef USE_UV\n layout(location = " + CubeProgram.a_Uv + ") attribute vec2 a_Uv;\n varying vec2 v_Uv;\n #endif\n \n void main() {\n " + Batch.ShaderLibrary.Vert + "\n\n gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * vec4(a_Position, 1.0);\n\n " + Batch.ShaderLibrary.UvVert + "\n }\n "; | ||
_this.frag = "\n " + Batch.ShaderLibrary.FragDeclaration + "\n " + Batch.ShaderLibrary.UvFragDeclaration + "\n " + Batch.ShaderLibrary.MapFragDeclaration + "\n \n void main() {\n " + Batch.ShaderLibrary.Frag + "\n " + Batch.ShaderLibrary.MapFrag + "\n\n gl_FragColor = u_Color;\n gl_FragColor.a = gl_FragColor.a * u_Opacity * u_FillOpacity;\n }\n "; | ||
return _this; | ||
} | ||
CubeProgram.a_Position = AttributeLocation.MAX; | ||
CubeProgram.a_Normal = AttributeLocation.MAX + 1; | ||
CubeProgram.a_Uv = AttributeLocation.MAX + 2; | ||
CubeProgram.ub_ObjectParams = 1; | ||
return CubeProgram; | ||
}(DeviceProgram); | ||
var CubeModelBuilder = | ||
/** @class */ | ||
function (_super) { | ||
__extends(CubeModelBuilder, _super); | ||
function CubeModelBuilder() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.program = new CubeProgram(); | ||
return _this; | ||
} | ||
CubeModelBuilder.prototype.validate = function (object) { | ||
var instance = this.instance; // TODO: support different tex map, eg. max 24 like PIXI.js | ||
if (instance.parsedStyle.map && instance.parsedStyle.map !== object.parsedStyle.map) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
CubeModelBuilder.prototype.buildGeometry = function () { | ||
var _this = this; | ||
this.program.setDefineBool('USE_UV', true); | ||
var map = this.instance.parsedStyle.map; | ||
if (map) { | ||
this.program.setDefineBool('USE_MAP', true); | ||
this.mapping = new TextureMapping(); | ||
this.mapping.texture = this.texturePool.getOrCreateTexture(this.device, map, makeTextureDescriptor2D(Format.U8_RGBA_NORM, 1, 1, 1), function () { | ||
// need re-render | ||
_this.objects.forEach(function (object) { | ||
var renderable = object.renderable; | ||
renderable.dirty = true; | ||
_this.renderingService.dirtify(); | ||
}); | ||
}); | ||
this.device.setResourceName(this.mapping.texture, 'Image Texture'); | ||
this.mapping.sampler = this.renderHelper.getCache().createSampler({ | ||
wrapS: 0 | ||
/* Clamp */ | ||
, | ||
wrapT: 0 | ||
/* Clamp */ | ||
, | ||
minFilter: 1 | ||
/* Bilinear */ | ||
, | ||
magFilter: 1 | ||
/* Bilinear */ | ||
, | ||
mipFilter: 0 | ||
/* NoMip */ | ||
, | ||
minLOD: 0, | ||
maxLOD: 0 | ||
}); | ||
} | ||
var _a = this.buildAttributes(this.objects), | ||
indices = _a.indices, | ||
positions = _a.positions, | ||
normals = _a.normals, | ||
uvs = _a.uvs; | ||
this.geometry.setIndices(new Uint32Array(indices)); | ||
this.geometry.vertexCount = 36; | ||
this.geometry.setVertexBuffer({ | ||
bufferIndex: 1, | ||
byteStride: 4 * 3, | ||
frequency: 1 | ||
/* PerVertex */ | ||
, | ||
attributes: [{ | ||
format: Format.F32_RGB, | ||
bufferByteOffset: 4 * 0, | ||
location: CubeProgram.a_Position | ||
}], | ||
data: Float32Array.from(positions) | ||
}); | ||
this.geometry.setVertexBuffer({ | ||
bufferIndex: 2, | ||
byteStride: 4 * 3, | ||
frequency: 1 | ||
/* PerVertex */ | ||
, | ||
attributes: [{ | ||
format: Format.F32_RGB, | ||
bufferByteOffset: 4 * 0, | ||
location: CubeProgram.a_Normal | ||
}], | ||
data: Float32Array.from(normals) | ||
}); | ||
this.geometry.setVertexBuffer({ | ||
bufferIndex: 3, | ||
byteStride: 4 * 2, | ||
frequency: 1 | ||
/* PerVertex */ | ||
, | ||
attributes: [{ | ||
format: Format.F32_RG, | ||
bufferByteOffset: 4 * 0, | ||
location: CubeProgram.a_Uv | ||
}], | ||
data: Float32Array.from(uvs) | ||
}); | ||
}; | ||
CubeModelBuilder.prototype.updateAttribute = function (object, name, value) { | ||
_super.prototype.updateAttribute.call(this, object, name, value); | ||
var index = this.objects.indexOf(object); | ||
var geometry = this.geometry; | ||
if (name === 'width' || name === 'height' || name === 'depth') { | ||
var positions = this.buildAttributes([object]).positions; | ||
geometry.updateVertexBuffer(1, CubeProgram.a_Position, index, new Uint8Array(new Float32Array(positions).buffer)); | ||
} | ||
}; | ||
CubeModelBuilder.prototype.uploadUBO = function (renderInst) { | ||
// need 1 sampler | ||
renderInst.setBindingLayouts([{ | ||
numUniformBuffers: 1, | ||
numSamplers: 1 | ||
}]); | ||
renderInst.setSamplerBindingsFromTextureMappings([this.mapping]); | ||
}; | ||
CubeModelBuilder.prototype.buildAttributes = function (objects) { | ||
var positionsAll = []; | ||
var normalsAll = []; | ||
var uvsAll = []; | ||
var uvs1All = []; | ||
var indicesAll = []; | ||
var indicesStart = 0; | ||
objects.forEach(function (object) { | ||
var attributes = object.attributes; | ||
var _a = attributes.widthSegments, | ||
widthSegments = _a === void 0 ? 1 : _a, | ||
_b = attributes.heightSegments, | ||
heightSegments = _b === void 0 ? 1 : _b, | ||
_c = attributes.depthSegments, | ||
depthSegments = _c === void 0 ? 1 : _c, | ||
_d = attributes.height, | ||
height = _d === void 0 ? 0 : _d, | ||
_e = attributes.width, | ||
width = _e === void 0 ? 0 : _e, | ||
_f = attributes.depth, | ||
depth = _f === void 0 ? 0 : _f; | ||
var ws = widthSegments; | ||
var hs = heightSegments; | ||
var ds = depthSegments; | ||
var hex = width / 2; | ||
var hey = height / 2; | ||
var hez = depth / 2; | ||
var corners = [vec3.fromValues(-hex, -hey, hez), vec3.fromValues(hex, -hey, hez), vec3.fromValues(hex, hey, hez), vec3.fromValues(-hex, hey, hez), vec3.fromValues(hex, -hey, -hez), vec3.fromValues(-hex, -hey, -hez), vec3.fromValues(-hex, hey, -hez), vec3.fromValues(hex, hey, -hez)]; | ||
var faceAxes = [[0, 3, 1], [4, 7, 5], [1, 4, 0], [3, 6, 2], [1, 2, 4], [5, 6, 0] // LEFT | ||
]; | ||
var faceNormals = [[0, 0, 1], [0, 0, -1], [0, -1, 0], [0, 1, 0], [1, 0, 0], [-1, 0, 0] // LEFT | ||
]; | ||
var sides = { | ||
FRONT: 0, | ||
BACK: 1, | ||
TOP: 2, | ||
BOTTOM: 3, | ||
RIGHT: 4, | ||
LEFT: 5 | ||
}; | ||
var positions = []; | ||
var normals = []; | ||
var uvs = []; | ||
var uvs1 = []; | ||
var indices = []; | ||
var vcounter = 0; | ||
var generateFace = function generateFace(side, uSegments, vSegments) { | ||
var u; | ||
var v; | ||
var i; | ||
var j; | ||
for (i = 0; i <= uSegments; i++) { | ||
for (j = 0; j <= vSegments; j++) { | ||
var temp1 = vec3.create(); | ||
var temp2 = vec3.create(); | ||
var temp3 = vec3.create(); | ||
var r = vec3.create(); | ||
vec3.lerp(temp1, corners[faceAxes[side][0]], corners[faceAxes[side][1]], i / uSegments); | ||
vec3.lerp(temp2, corners[faceAxes[side][0]], corners[faceAxes[side][2]], j / vSegments); | ||
vec3.sub(temp3, temp2, corners[faceAxes[side][0]]); | ||
vec3.add(r, temp1, temp3); | ||
u = i / uSegments; | ||
v = j / vSegments; | ||
positions.push(r[0], r[1], r[2]); | ||
normals.push(faceNormals[side][0], faceNormals[side][1], faceNormals[side][2]); | ||
uvs.push(u, v); // pack as 3x2 | ||
// 1/3 will be empty, but it's either that or stretched pixels | ||
// TODO: generate non-rectangular lightMaps, so we could use space without stretching | ||
u /= 3; | ||
v /= 3; | ||
u = u * primitiveUv1PaddingScale + primitiveUv1Padding; | ||
v = v * primitiveUv1PaddingScale + primitiveUv1Padding; | ||
u += side % 3 / 3; | ||
v += Math.floor(side / 3) / 3; | ||
uvs1.push(u, v); | ||
if (i < uSegments && j < vSegments) { | ||
indices.push(vcounter + vSegments + 1 + indicesStart, vcounter + 1 + indicesStart, vcounter + indicesStart); | ||
indices.push(vcounter + vSegments + 1 + indicesStart, vcounter + vSegments + 2 + indicesStart, vcounter + 1 + indicesStart); | ||
} | ||
vcounter++; | ||
} | ||
} | ||
}; | ||
generateFace(sides.FRONT, ws, hs); | ||
generateFace(sides.BACK, ws, hs); | ||
generateFace(sides.TOP, ws, ds); | ||
generateFace(sides.BOTTOM, ws, ds); | ||
generateFace(sides.RIGHT, ds, hs); | ||
generateFace(sides.LEFT, ds, hs); | ||
indicesStart += 24; | ||
positionsAll.push.apply(positionsAll, __spreadArray([], __read(positions), false)); | ||
normalsAll.push.apply(normalsAll, __spreadArray([], __read(normals), false)); | ||
uvsAll.push.apply(uvsAll, __spreadArray([], __read(uvs), false)); | ||
indicesAll.push.apply(indicesAll, __spreadArray([], __read(indices), false)); | ||
}); | ||
return { | ||
indices: indicesAll, | ||
positions: positionsAll, | ||
normals: normalsAll, | ||
uvs: uvsAll | ||
}; // TODO: barycentric & tangent | ||
}; | ||
CubeModelBuilder = __decorate([singleton()], CubeModelBuilder); | ||
return CubeModelBuilder; | ||
}(Batch); | ||
export { CubeModelBuilder }; | ||
// import { DisplayObject } from '@antv/g'; | ||
// import { singleton } from 'mana-syringe'; | ||
// import { vec3 } from 'gl-matrix'; | ||
// import { | ||
// Batch, | ||
// AttributeLocation, | ||
// DeviceProgram, | ||
// Format, | ||
// makeTextureDescriptor2D, | ||
// MipFilterMode, | ||
// TexFilterMode, | ||
// WrapMode, | ||
// TextureMapping, | ||
// RenderInst, | ||
// VertexBufferFrequency, | ||
// } from '@antv/g-plugin-webgl-renderer'; | ||
// import { Cube, CubeStyleProps } from '../Cube'; | ||
// const primitiveUv1Padding = 4.0 / 64; | ||
// const primitiveUv1PaddingScale = 1.0 - primitiveUv1Padding * 2; | ||
// class CubeProgram extends DeviceProgram { | ||
// static a_Position = AttributeLocation.MAX; | ||
// static a_Normal = AttributeLocation.MAX + 1; | ||
// static a_Uv = AttributeLocation.MAX + 2; | ||
// static ub_ObjectParams = 1; | ||
// both: string = ` | ||
// ${Batch.ShaderLibrary.BothDeclaration} | ||
// `; | ||
// vert: string = ` | ||
// ${Batch.ShaderLibrary.VertDeclaration} | ||
// layout(location = ${CubeProgram.a_Position}) attribute vec3 a_Position; | ||
// layout(location = ${CubeProgram.a_Normal}) attribute vec3 a_Normal; | ||
// #ifdef USE_UV | ||
// layout(location = ${CubeProgram.a_Uv}) attribute vec2 a_Uv; | ||
// varying vec2 v_Uv; | ||
// #endif | ||
// void main() { | ||
// ${Batch.ShaderLibrary.Vert} | ||
// gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * vec4(a_Position, 1.0); | ||
// ${Batch.ShaderLibrary.UvVert} | ||
// } | ||
// `; | ||
// frag: string = ` | ||
// ${Batch.ShaderLibrary.FragDeclaration} | ||
// ${Batch.ShaderLibrary.UvFragDeclaration} | ||
// ${Batch.ShaderLibrary.MapFragDeclaration} | ||
// void main() { | ||
// ${Batch.ShaderLibrary.Frag} | ||
// ${Batch.ShaderLibrary.MapFrag} | ||
// gl_FragColor = u_Color; | ||
// gl_FragColor.a = gl_FragColor.a * u_Opacity * u_FillOpacity; | ||
// } | ||
// `; | ||
// } | ||
// @singleton() | ||
// export class CubeModelBuilder extends Batch { | ||
// program = new CubeProgram(); | ||
// validate(object: DisplayObject) { | ||
// const instance = this.instance; | ||
// // TODO: support different tex map, eg. max 24 like PIXI.js | ||
// if (instance.parsedStyle.map && instance.parsedStyle.map !== object.parsedStyle.map) { | ||
// return false; | ||
// } | ||
// return true; | ||
// } | ||
// buildGeometry() { | ||
// this.program.setDefineBool('USE_UV', true); | ||
// const { map } = this.instance.parsedStyle; | ||
// if (map) { | ||
// this.program.setDefineBool('USE_MAP', true); | ||
// this.mapping = new TextureMapping(); | ||
// this.mapping.texture = this.texturePool.getOrCreateTexture( | ||
// this.device, | ||
// map, | ||
// makeTextureDescriptor2D(Format.U8_RGBA_NORM, 1, 1, 1), | ||
// () => { | ||
// // need re-render | ||
// this.objects.forEach((object) => { | ||
// const renderable = object.renderable; | ||
// renderable.dirty = true; | ||
// this.renderingService.dirtify(); | ||
// }); | ||
// }, | ||
// ); | ||
// this.device.setResourceName(this.mapping.texture, 'Image Texture'); | ||
// this.mapping.sampler = this.renderHelper.getCache().createSampler({ | ||
// wrapS: WrapMode.Clamp, | ||
// wrapT: WrapMode.Clamp, | ||
// minFilter: TexFilterMode.Bilinear, | ||
// magFilter: TexFilterMode.Bilinear, | ||
// mipFilter: MipFilterMode.NoMip, | ||
// minLOD: 0, | ||
// maxLOD: 0, | ||
// }); | ||
// } | ||
// const { indices, positions, normals, uvs } = this.buildAttributes(this.objects); | ||
// this.geometry.setIndices(new Uint32Array(indices)); | ||
// this.geometry.vertexCount = 36; | ||
// this.geometry.setVertexBuffer({ | ||
// bufferIndex: 1, | ||
// byteStride: 4 * 3, | ||
// frequency: VertexBufferFrequency.PerVertex, | ||
// attributes: [ | ||
// { | ||
// format: Format.F32_RGB, | ||
// bufferByteOffset: 4 * 0, | ||
// location: CubeProgram.a_Position, | ||
// }, | ||
// ], | ||
// data: Float32Array.from(positions), | ||
// }); | ||
// this.geometry.setVertexBuffer({ | ||
// bufferIndex: 2, | ||
// byteStride: 4 * 3, | ||
// frequency: VertexBufferFrequency.PerVertex, | ||
// attributes: [ | ||
// { | ||
// format: Format.F32_RGB, | ||
// bufferByteOffset: 4 * 0, | ||
// location: CubeProgram.a_Normal, | ||
// }, | ||
// ], | ||
// data: Float32Array.from(normals), | ||
// }); | ||
// this.geometry.setVertexBuffer({ | ||
// bufferIndex: 3, | ||
// byteStride: 4 * 2, | ||
// frequency: VertexBufferFrequency.PerVertex, | ||
// attributes: [ | ||
// { | ||
// format: Format.F32_RG, | ||
// bufferByteOffset: 4 * 0, | ||
// location: CubeProgram.a_Uv, | ||
// }, | ||
// ], | ||
// data: Float32Array.from(uvs), | ||
// }); | ||
// } | ||
// updateAttribute(object: DisplayObject, name: string, value: any) { | ||
// super.updateAttribute(object, name, value); | ||
// const index = this.objects.indexOf(object); | ||
// const geometry = this.geometry; | ||
// if (name === 'width' || name === 'height' || name === 'depth') { | ||
// const { positions } = this.buildAttributes([object]); | ||
// geometry.updateVertexBuffer( | ||
// 1, | ||
// CubeProgram.a_Position, | ||
// index, | ||
// new Uint8Array(new Float32Array(positions).buffer), | ||
// ); | ||
// } | ||
// } | ||
// uploadUBO(renderInst: RenderInst): void { | ||
// // need 1 sampler | ||
// renderInst.setBindingLayouts([{ numUniformBuffers: 1, numSamplers: 1 }]); | ||
// renderInst.setSamplerBindingsFromTextureMappings([this.mapping]); | ||
// } | ||
// protected buildAttributes(objects: Cube[]) { | ||
// const positionsAll: number[] = []; | ||
// const normalsAll: number[] = []; | ||
// const uvsAll: number[] = []; | ||
// const uvs1All: number[] = []; | ||
// const indicesAll: number[] = []; | ||
// let indicesStart = 0; | ||
// objects.forEach((object) => { | ||
// const attributes = object.attributes as CubeStyleProps; | ||
// const { | ||
// widthSegments = 1, | ||
// heightSegments = 1, | ||
// depthSegments = 1, | ||
// height = 0, | ||
// width = 0, | ||
// depth = 0, | ||
// } = attributes; | ||
// const ws = widthSegments; | ||
// const hs = heightSegments; | ||
// const ds = depthSegments; | ||
// const hex = width / 2; | ||
// const hey = height / 2; | ||
// const hez = depth / 2; | ||
// const corners = [ | ||
// vec3.fromValues(-hex, -hey, hez), | ||
// vec3.fromValues(hex, -hey, hez), | ||
// vec3.fromValues(hex, hey, hez), | ||
// vec3.fromValues(-hex, hey, hez), | ||
// vec3.fromValues(hex, -hey, -hez), | ||
// vec3.fromValues(-hex, -hey, -hez), | ||
// vec3.fromValues(-hex, hey, -hez), | ||
// vec3.fromValues(hex, hey, -hez), | ||
// ]; | ||
// const faceAxes = [ | ||
// [0, 3, 1], // FRONT | ||
// [4, 7, 5], // BACK | ||
// [1, 4, 0], // TOP | ||
// [3, 6, 2], // BOTTOM | ||
// [1, 2, 4], // RIGHT | ||
// [5, 6, 0], // LEFT | ||
// ]; | ||
// const faceNormals = [ | ||
// [0, 0, 1], // FRONT | ||
// [0, 0, -1], // BACK | ||
// [0, -1, 0], // TOP | ||
// [0, 1, 0], // BOTTOM | ||
// [1, 0, 0], // RIGHT | ||
// [-1, 0, 0], // LEFT | ||
// ]; | ||
// const sides = { | ||
// FRONT: 0, | ||
// BACK: 1, | ||
// TOP: 2, | ||
// BOTTOM: 3, | ||
// RIGHT: 4, | ||
// LEFT: 5, | ||
// }; | ||
// const positions: number[] = []; | ||
// const normals: number[] = []; | ||
// const uvs: number[] = []; | ||
// const uvs1: number[] = []; | ||
// const indices: number[] = []; | ||
// let vcounter = 0; | ||
// const generateFace = (side: number, uSegments: number, vSegments: number) => { | ||
// let u: number; | ||
// let v: number; | ||
// let i: number; | ||
// let j: number; | ||
// for (i = 0; i <= uSegments; i++) { | ||
// for (j = 0; j <= vSegments; j++) { | ||
// const temp1 = vec3.create(); | ||
// const temp2 = vec3.create(); | ||
// const temp3 = vec3.create(); | ||
// const r = vec3.create(); | ||
// vec3.lerp(temp1, corners[faceAxes[side][0]], corners[faceAxes[side][1]], i / uSegments); | ||
// vec3.lerp(temp2, corners[faceAxes[side][0]], corners[faceAxes[side][2]], j / vSegments); | ||
// vec3.sub(temp3, temp2, corners[faceAxes[side][0]]); | ||
// vec3.add(r, temp1, temp3); | ||
// u = i / uSegments; | ||
// v = j / vSegments; | ||
// positions.push(r[0], r[1], r[2]); | ||
// normals.push(faceNormals[side][0], faceNormals[side][1], faceNormals[side][2]); | ||
// uvs.push(u, v); | ||
// // pack as 3x2 | ||
// // 1/3 will be empty, but it's either that or stretched pixels | ||
// // TODO: generate non-rectangular lightMaps, so we could use space without stretching | ||
// u /= 3; | ||
// v /= 3; | ||
// u = u * primitiveUv1PaddingScale + primitiveUv1Padding; | ||
// v = v * primitiveUv1PaddingScale + primitiveUv1Padding; | ||
// u += (side % 3) / 3; | ||
// v += Math.floor(side / 3) / 3; | ||
// uvs1.push(u, v); | ||
// if (i < uSegments && j < vSegments) { | ||
// indices.push( | ||
// vcounter + vSegments + 1 + indicesStart, | ||
// vcounter + 1 + indicesStart, | ||
// vcounter + indicesStart, | ||
// ); | ||
// indices.push( | ||
// vcounter + vSegments + 1 + indicesStart, | ||
// vcounter + vSegments + 2 + indicesStart, | ||
// vcounter + 1 + indicesStart, | ||
// ); | ||
// } | ||
// vcounter++; | ||
// } | ||
// } | ||
// }; | ||
// generateFace(sides.FRONT, ws, hs); | ||
// generateFace(sides.BACK, ws, hs); | ||
// generateFace(sides.TOP, ws, ds); | ||
// generateFace(sides.BOTTOM, ws, ds); | ||
// generateFace(sides.RIGHT, ds, hs); | ||
// generateFace(sides.LEFT, ds, hs); | ||
// indicesStart += 24; | ||
// positionsAll.push(...positions); | ||
// normalsAll.push(...normals); | ||
// uvsAll.push(...uvs); | ||
// indicesAll.push(...indices); | ||
// }); | ||
// return { | ||
// indices: indicesAll, | ||
// positions: positionsAll, | ||
// normals: normalsAll, | ||
// uvs: uvsAll, | ||
// }; | ||
// // TODO: barycentric & tangent | ||
// } | ||
// } |
@@ -1,18 +0,1 @@ | ||
import { DisplayObject } from '@antv/g'; | ||
import { Batch, AttributeLocation, DeviceProgram, RenderInst } from '@antv/g-plugin-webgl-renderer'; | ||
declare class GridProgram extends DeviceProgram { | ||
static a_Position: AttributeLocation; | ||
static a_GridSize: number; | ||
static ub_ObjectParams: number; | ||
both: string; | ||
vert: string; | ||
frag: string; | ||
} | ||
export declare class GridModelBuilder extends Batch { | ||
program: GridProgram; | ||
validate(object: DisplayObject): boolean; | ||
updateAttribute(object: DisplayObject, name: string, value: any): void; | ||
uploadUBO(renderInst: RenderInst): void; | ||
buildGeometry(): void; | ||
} | ||
export {}; | ||
@@ -1,102 +0,119 @@ | ||
import { __decorate, __extends } from "tslib"; | ||
import { singleton } from 'mana-syringe'; | ||
import { Batch, AttributeLocation, DeviceProgram, Format } from '@antv/g-plugin-webgl-renderer'; | ||
var GridProgram = | ||
/** @class */ | ||
function (_super) { | ||
__extends(GridProgram, _super); | ||
function GridProgram() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.both = "\n " + Batch.ShaderLibrary.BothDeclaration + "\n "; | ||
_this.vert = "\n " + Batch.ShaderLibrary.VertDeclaration + "\n\n layout(location = " + GridProgram.a_Position + ") attribute vec3 a_Position;\n layout(location = " + GridProgram.a_GridSize + ") attribute vec2 a_GridSize;\n\n varying vec3 v_Position;\n varying vec2 v_GridSize;\n \n void main() {\n " + Batch.ShaderLibrary.Vert + "\n\n v_GridSize = a_GridSize;\n v_Position = a_Position;\n\n gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * vec4(a_Position, 1.0);\n }\n "; | ||
_this.frag = "\n " + Batch.ShaderLibrary.FragDeclaration + "\n\n // #extension GL_OES_standard_derivatives : enable\n\n varying vec3 v_Position;\n varying vec2 v_GridSize;\n \n void main() {\n " + Batch.ShaderLibrary.Frag + "\n\n // vec4 u_GridColor = u_StrokeColor;\n vec4 u_GridColor = u_Color;\n float u_GridSize2 = v_GridSize.y;\n\n float wx = v_Position.x;\n float wz = v_Position.z;\n\n float x1 = abs(fract(wx / u_GridSize2 - 0.5) - 0.5) / fwidth(wx) * u_GridSize2;\n float z1 = abs(fract(wz / u_GridSize2 - 0.5) - 0.5) / fwidth(wz) * u_GridSize2;\n\n float v1 = 1.0 - clamp(min(x1, z1), 0.0, 1.0);\n gl_FragColor = mix(gl_FragColor, u_GridColor, v1);\n\n gl_FragColor.a = gl_FragColor.a * u_Opacity;\n }\n "; | ||
return _this; | ||
} | ||
GridProgram.a_Position = AttributeLocation.MAX; | ||
GridProgram.a_GridSize = AttributeLocation.MAX + 1; | ||
GridProgram.ub_ObjectParams = 1; | ||
return GridProgram; | ||
}(DeviceProgram); | ||
var GridModelBuilder = | ||
/** @class */ | ||
function (_super) { | ||
__extends(GridModelBuilder, _super); | ||
function GridModelBuilder() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.program = new GridProgram(); | ||
return _this; | ||
} | ||
GridModelBuilder.prototype.validate = function (object) { | ||
return true; | ||
}; | ||
GridModelBuilder.prototype.updateAttribute = function (object, name, value) { | ||
_super.prototype.updateAttribute.call(this, object, name, value); | ||
var index = this.objects.indexOf(object); | ||
var geometry = this.geometry; | ||
}; | ||
GridModelBuilder.prototype.uploadUBO = function (renderInst) { | ||
renderInst.setMegaStateFlags({ | ||
cullMode: 0 | ||
/* None */ | ||
}); | ||
renderInst.setBindingLayouts([{ | ||
numUniformBuffers: 1, | ||
numSamplers: 0 | ||
}]); | ||
}; | ||
GridModelBuilder.prototype.buildGeometry = function () { | ||
var instance = this.instance; | ||
var _a = instance.attributes, | ||
height = _a.height, | ||
width = _a.width; | ||
var halfWidth = width / 2; | ||
var halfHeight = height / 2; | ||
this.geometry.setIndices(new Uint32Array([0, 3, 2, 2, 1, 0])); | ||
this.geometry.vertexCount = 6; | ||
this.geometry.setVertexBuffer({ | ||
bufferIndex: 1, | ||
byteStride: 4 * 3, | ||
frequency: 1 | ||
/* PerVertex */ | ||
, | ||
attributes: [{ | ||
format: Format.F32_RGB, | ||
bufferByteOffset: 4 * 0, | ||
location: GridProgram.a_Position | ||
}], | ||
data: Float32Array.from([-halfWidth, 0, -halfHeight, halfWidth, 0, -halfHeight, halfWidth, 0, halfHeight, -halfWidth, 0, halfHeight]) | ||
}); | ||
this.geometry.setVertexBuffer({ | ||
bufferIndex: 2, | ||
byteStride: 4 * 2, | ||
frequency: 2 | ||
/* PerInstance */ | ||
, | ||
attributes: [{ | ||
format: Format.F32_RG, | ||
bufferByteOffset: 4 * 0, | ||
location: GridProgram.a_GridSize, | ||
divisor: 1 | ||
}], | ||
data: Float32Array.from([10, 10]) | ||
}); | ||
}; | ||
GridModelBuilder = __decorate([singleton()], GridModelBuilder); | ||
return GridModelBuilder; | ||
}(Batch); | ||
export { GridModelBuilder }; | ||
// import { DisplayObject, Renderable } from '@antv/g'; | ||
// import { inject, singleton } from 'mana-syringe'; | ||
// import { vec3 } from 'gl-matrix'; | ||
// import { | ||
// Batch, | ||
// AttributeLocation, | ||
// CullMode, | ||
// DeviceProgram, | ||
// Format, | ||
// RenderInst, | ||
// VertexBufferFrequency, | ||
// } from '@antv/g-plugin-webgl-renderer'; | ||
// import { GridStyleProps } from '../Grid'; | ||
// class GridProgram extends DeviceProgram { | ||
// static a_Position = AttributeLocation.MAX; | ||
// static a_GridSize = AttributeLocation.MAX + 1; | ||
// static ub_ObjectParams = 1; | ||
// both: string = ` | ||
// ${Batch.ShaderLibrary.BothDeclaration} | ||
// `; | ||
// vert: string = ` | ||
// ${Batch.ShaderLibrary.VertDeclaration} | ||
// layout(location = ${GridProgram.a_Position}) attribute vec3 a_Position; | ||
// layout(location = ${GridProgram.a_GridSize}) attribute vec2 a_GridSize; | ||
// varying vec3 v_Position; | ||
// varying vec2 v_GridSize; | ||
// void main() { | ||
// ${Batch.ShaderLibrary.Vert} | ||
// v_GridSize = a_GridSize; | ||
// v_Position = a_Position; | ||
// gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * vec4(a_Position, 1.0); | ||
// } | ||
// `; | ||
// frag: string = ` | ||
// ${Batch.ShaderLibrary.FragDeclaration} | ||
// // #extension GL_OES_standard_derivatives : enable | ||
// varying vec3 v_Position; | ||
// varying vec2 v_GridSize; | ||
// void main() { | ||
// ${Batch.ShaderLibrary.Frag} | ||
// // vec4 u_GridColor = u_StrokeColor; | ||
// vec4 u_GridColor = u_Color; | ||
// float u_GridSize2 = v_GridSize.y; | ||
// float wx = v_Position.x; | ||
// float wz = v_Position.z; | ||
// float x1 = abs(fract(wx / u_GridSize2 - 0.5) - 0.5) / fwidth(wx) * u_GridSize2; | ||
// float z1 = abs(fract(wz / u_GridSize2 - 0.5) - 0.5) / fwidth(wz) * u_GridSize2; | ||
// float v1 = 1.0 - clamp(min(x1, z1), 0.0, 1.0); | ||
// gl_FragColor = mix(gl_FragColor, u_GridColor, v1); | ||
// gl_FragColor.a = gl_FragColor.a * u_Opacity; | ||
// } | ||
// `; | ||
// } | ||
// @singleton() | ||
// export class GridModelBuilder extends Batch { | ||
// program = new GridProgram(); | ||
// validate(object: DisplayObject) { | ||
// return true; | ||
// } | ||
// updateAttribute(object: DisplayObject, name: string, value: any) { | ||
// super.updateAttribute(object, name, value); | ||
// const index = this.objects.indexOf(object); | ||
// const geometry = this.geometry; | ||
// } | ||
// uploadUBO(renderInst: RenderInst): void { | ||
// renderInst.setMegaStateFlags({ | ||
// cullMode: CullMode.None, | ||
// }); | ||
// renderInst.setBindingLayouts([{ numUniformBuffers: 1, numSamplers: 0 }]); | ||
// } | ||
// buildGeometry() { | ||
// const instance = this.instance; | ||
// const { height, width } = instance.attributes; | ||
// const halfWidth = width / 2; | ||
// const halfHeight = height / 2; | ||
// this.geometry.setIndices(new Uint32Array([0, 3, 2, 2, 1, 0])); | ||
// this.geometry.vertexCount = 6; | ||
// this.geometry.setVertexBuffer({ | ||
// bufferIndex: 1, | ||
// byteStride: 4 * 3, | ||
// frequency: VertexBufferFrequency.PerVertex, | ||
// attributes: [ | ||
// { | ||
// format: Format.F32_RGB, | ||
// bufferByteOffset: 4 * 0, | ||
// location: GridProgram.a_Position, | ||
// }, | ||
// ], | ||
// data: Float32Array.from([ | ||
// -halfWidth, | ||
// 0, | ||
// -halfHeight, | ||
// halfWidth, | ||
// 0, | ||
// -halfHeight, | ||
// halfWidth, | ||
// 0, | ||
// halfHeight, | ||
// -halfWidth, | ||
// 0, | ||
// halfHeight, | ||
// ]), | ||
// }); | ||
// this.geometry.setVertexBuffer({ | ||
// bufferIndex: 2, | ||
// byteStride: 4 * 2, | ||
// frequency: VertexBufferFrequency.PerInstance, | ||
// attributes: [ | ||
// { | ||
// format: Format.F32_RG, | ||
// bufferByteOffset: 4 * 0, | ||
// location: GridProgram.a_GridSize, | ||
// divisor: 1, | ||
// }, | ||
// ], | ||
// data: Float32Array.from([10, 10]), | ||
// }); | ||
// } | ||
// } |
@@ -1,10 +0,1 @@ | ||
import { GeometryAABBUpdater } from '@antv/g'; | ||
import { ParsedCubeStyleProps } from '../Cube'; | ||
export declare class CubeUpdater implements GeometryAABBUpdater<ParsedCubeStyleProps> { | ||
dependencies: string[]; | ||
update(attributes: ParsedCubeStyleProps): { | ||
width: number; | ||
height: number; | ||
depth: number; | ||
}; | ||
} | ||
@@ -1,47 +0,19 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.CubeUpdater = void 0; | ||
var _tslib = require("tslib"); | ||
var _manaSyringe = require("mana-syringe"); | ||
var _g = require("@antv/g"); | ||
var _types = require("../types"); | ||
var CubeUpdater = | ||
/** @class */ | ||
function () { | ||
function CubeUpdater() { | ||
this.dependencies = ['height', 'width', 'depth', 'anchor']; | ||
} // @ts-ignore | ||
CubeUpdater.prototype.update = function (attributes) { | ||
var _a = attributes.height, | ||
height = _a === void 0 ? 0 : _a, | ||
_b = attributes.width, | ||
width = _b === void 0 ? 0 : _b, | ||
_c = attributes.depth, | ||
depth = _c === void 0 ? 0 : _c; | ||
return { | ||
width: width, | ||
height: height, | ||
depth: depth | ||
}; | ||
}; | ||
CubeUpdater = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({ | ||
token: { | ||
token: _g.GeometryAABBUpdater, | ||
named: _types.SHAPE_3D.Cube | ||
} | ||
})], CubeUpdater); | ||
return CubeUpdater; | ||
}(); | ||
exports.CubeUpdater = CubeUpdater; | ||
// import { vec3 } from 'gl-matrix'; | ||
// import { singleton } from 'mana-syringe'; | ||
// import { GeometryAABBUpdater, AABB } from '@antv/g'; | ||
// import { ParsedCubeStyleProps } from '../Cube'; | ||
// import { SHAPE_3D } from '../types'; | ||
// @singleton({ token: { token: GeometryAABBUpdater, named: SHAPE_3D.Cube } }) | ||
// export class CubeUpdater implements GeometryAABBUpdater<ParsedCubeStyleProps> { | ||
// dependencies = ['height', 'width', 'depth', 'anchor']; | ||
// // @ts-ignore | ||
// update(attributes: ParsedCubeStyleProps) { | ||
// const { height = 0, width = 0, depth = 0 } = attributes; | ||
// return { | ||
// width, | ||
// height, | ||
// depth, | ||
// }; | ||
// } | ||
// } | ||
"use strict"; |
@@ -1,9 +0,1 @@ | ||
import { GeometryAABBUpdater, AABB } from '@antv/g'; | ||
import { GridStyleProps } from '../Grid'; | ||
export declare class GridUpdater implements GeometryAABBUpdater<GridStyleProps> { | ||
dependencies: string[]; | ||
update(attributes: GridStyleProps, aabb: AABB): { | ||
width: number; | ||
height: number; | ||
}; | ||
} | ||
@@ -1,46 +0,19 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.GridUpdater = void 0; | ||
var _tslib = require("tslib"); | ||
var _manaSyringe = require("mana-syringe"); | ||
var _g = require("@antv/g"); | ||
var _types = require("../types"); | ||
var GridUpdater = | ||
/** @class */ | ||
function () { | ||
// @ts-ignore | ||
function GridUpdater() { | ||
this.dependencies = ['width', 'height', 'anchor']; | ||
} // @ts-ignore | ||
GridUpdater.prototype.update = function (attributes, aabb) { | ||
var _a = attributes.width, | ||
width = _a === void 0 ? 0 : _a, | ||
_b = attributes.height, | ||
height = _b === void 0 ? 0 : _b; | ||
return { | ||
width: width, | ||
height: height | ||
}; | ||
}; | ||
GridUpdater = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({ | ||
token: { | ||
token: _g.GeometryAABBUpdater, | ||
named: _types.SHAPE_3D.Grid | ||
} | ||
}) // @ts-ignore | ||
], GridUpdater); | ||
return GridUpdater; | ||
}(); | ||
exports.GridUpdater = GridUpdater; | ||
// import { vec3 } from 'gl-matrix'; | ||
// import { singleton } from 'mana-syringe'; | ||
// import { GeometryAABBUpdater, AABB } from '@antv/g'; | ||
// import { GridStyleProps } from '../Grid'; | ||
// import { SHAPE_3D } from '../types'; | ||
// @singleton({ token: { token: GeometryAABBUpdater, named: SHAPE_3D.Grid } }) | ||
// // @ts-ignore | ||
// export class GridUpdater implements GeometryAABBUpdater<GridStyleProps> { | ||
// dependencies = ['width', 'height', 'anchor']; | ||
// // @ts-ignore | ||
// update(attributes: GridStyleProps, aabb: AABB) { | ||
// const { width = 0, height = 0 } = attributes; | ||
// return { | ||
// width, | ||
// height, | ||
// }; | ||
// } | ||
// } | ||
"use strict"; |
@@ -1,10 +0,1 @@ | ||
import { GeometryAABBUpdater, AABB } from '@antv/g'; | ||
import { SphereStyleProps } from '../Sphere'; | ||
export declare class SphereUpdater implements GeometryAABBUpdater<SphereStyleProps> { | ||
dependencies: string[]; | ||
update(attributes: SphereStyleProps, aabb: AABB): { | ||
width: number; | ||
height: number; | ||
depth: number; | ||
}; | ||
} | ||
@@ -1,49 +0,20 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.SphereUpdater = void 0; | ||
var _tslib = require("tslib"); | ||
var _manaSyringe = require("mana-syringe"); | ||
var _g = require("@antv/g"); | ||
var _types = require("../types"); | ||
var SphereUpdater = | ||
/** @class */ | ||
function () { | ||
// @ts-ignore | ||
function SphereUpdater() { | ||
this.dependencies = ['height', 'width', 'depth', 'anchor']; | ||
} // @ts-ignore | ||
SphereUpdater.prototype.update = function (attributes, aabb) { | ||
var _a = attributes.height, | ||
height = _a === void 0 ? 0 : _a, | ||
_b = attributes.width, | ||
width = _b === void 0 ? 0 : _b, | ||
_c = attributes.depth, | ||
depth = _c === void 0 ? 0 : _c; | ||
return { | ||
width: width, | ||
height: height, | ||
depth: depth | ||
}; | ||
}; | ||
SphereUpdater = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({ | ||
token: { | ||
token: _g.GeometryAABBUpdater, | ||
named: _types.SHAPE_3D.Sphere | ||
} | ||
}) // @ts-ignore | ||
], SphereUpdater); | ||
return SphereUpdater; | ||
}(); | ||
exports.SphereUpdater = SphereUpdater; | ||
// import { vec3 } from 'gl-matrix'; | ||
// import { singleton } from 'mana-syringe'; | ||
// import { GeometryAABBUpdater, AABB } from '@antv/g'; | ||
// import { SphereStyleProps } from '../Sphere'; | ||
// import { SHAPE_3D } from '../types'; | ||
// @singleton({ token: { token: GeometryAABBUpdater, named: SHAPE_3D.Sphere } }) | ||
// // @ts-ignore | ||
// export class SphereUpdater implements GeometryAABBUpdater<SphereStyleProps> { | ||
// dependencies = ['height', 'width', 'depth', 'anchor']; | ||
// // @ts-ignore | ||
// update(attributes: SphereStyleProps, aabb: AABB) { | ||
// const { height = 0, width = 0, depth = 0 } = attributes; | ||
// return { | ||
// width, | ||
// height, | ||
// depth, | ||
// }; | ||
// } | ||
// } | ||
"use strict"; |
@@ -1,8 +0,1 @@ | ||
import { BaseStyleProps, DisplayObject, DisplayObjectConfig } from '@antv/g'; | ||
export interface GridStyleProps extends BaseStyleProps { | ||
height: number; | ||
width: number; | ||
} | ||
export declare class Grid extends DisplayObject<GridStyleProps> { | ||
constructor({ style, ...rest }: DisplayObjectConfig<GridStyleProps>); | ||
} | ||
@@ -1,35 +0,21 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.Grid = void 0; | ||
var _tslib = require("tslib"); | ||
var _g = require("@antv/g"); | ||
var _types = require("./types"); | ||
var Grid = | ||
/** @class */ | ||
function (_super) { | ||
(0, _tslib.__extends)(Grid, _super); | ||
function Grid(_a) { | ||
var style = _a.style, | ||
rest = (0, _tslib.__rest)(_a, ["style"]); | ||
return _super.call(this, (0, _tslib.__assign)({ | ||
// @ts-ignore | ||
type: _types.SHAPE_3D.Grid, | ||
style: (0, _tslib.__assign)({ | ||
height: 0, | ||
width: 0 | ||
}, style) | ||
}, rest)) || this; | ||
} | ||
return Grid; | ||
}(_g.DisplayObject); | ||
exports.Grid = Grid; | ||
// import { BaseStyleProps, DisplayObject, DisplayObjectConfig } from '@antv/g'; | ||
// import { SHAPE_3D } from './types'; | ||
// export interface GridStyleProps extends BaseStyleProps { | ||
// height: number; | ||
// width: number; | ||
// } | ||
// export class Grid extends DisplayObject<GridStyleProps> { | ||
// constructor({ style, ...rest }: DisplayObjectConfig<GridStyleProps>) { | ||
// super({ | ||
// // @ts-ignore | ||
// type: SHAPE_3D.Grid, | ||
// style: { | ||
// height: 0, | ||
// width: 0, | ||
// ...style, | ||
// }, | ||
// ...rest, | ||
// }); | ||
// } | ||
// } | ||
"use strict"; |
import { RendererPlugin } from '@antv/g'; | ||
import { Syringe } from 'mana-syringe'; | ||
import { Cube } from './Cube'; | ||
import { Sphere } from './Sphere'; | ||
import { Grid } from './Grid'; | ||
export * from './geometries'; | ||
export declare const containerModule: import("mana-syringe").SyringeModule; | ||
@@ -11,2 +9,1 @@ export declare class Plugin implements RendererPlugin { | ||
} | ||
export { Cube, Sphere, Grid }; |
@@ -6,60 +6,42 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "Cube", { | ||
enumerable: true, | ||
get: function get() { | ||
return _Cube2.Cube; | ||
} | ||
}); | ||
Object.defineProperty(exports, "Grid", { | ||
enumerable: true, | ||
get: function get() { | ||
return _Grid2.Grid; | ||
} | ||
}); | ||
exports.Plugin = void 0; | ||
Object.defineProperty(exports, "Sphere", { | ||
enumerable: true, | ||
get: function get() { | ||
return _Sphere.Sphere; | ||
} | ||
}); | ||
exports.containerModule = void 0; | ||
var _exportNames = { | ||
containerModule: true, | ||
Plugin: true | ||
}; | ||
exports.containerModule = exports.Plugin = void 0; | ||
var _g = require("@antv/g"); | ||
var _manaSyringe = require("mana-syringe"); | ||
var _gPluginWebglRenderer = require("@antv/g-plugin-webgl-renderer"); | ||
var _geometries = require("./geometries"); | ||
var _CubeUpdater = require("./aabb/CubeUpdater"); | ||
var _SphereUpdater = require("./aabb/SphereUpdater"); | ||
var _GridUpdater = require("./aabb/GridUpdater"); | ||
var _Cube = require("./model/Cube"); | ||
var _Grid = require("./model/Grid"); | ||
var _types = require("./types"); | ||
var _Cube2 = require("./Cube"); | ||
var _Sphere = require("./Sphere"); | ||
var _Grid2 = require("./Grid"); | ||
// import { SphereModelBuilder } from './model/Sphere'; | ||
// TODO: provide more friendly API like `registerGeometry` | ||
_g.globalContainer.register(_CubeUpdater.CubeUpdater); | ||
_g.globalContainer.register(_SphereUpdater.SphereUpdater); | ||
_g.globalContainer.register(_GridUpdater.GridUpdater); | ||
var containerModule = (0, _manaSyringe.Module)(function (register) { | ||
(0, _gPluginWebglRenderer.registerModelBuilder)(_Cube.CubeModelBuilder, _types.SHAPE_3D.Cube); // registerModelBuilder(SphereModelBuilder, SHAPE_3D.Sphere); | ||
(0, _gPluginWebglRenderer.registerModelBuilder)(_Grid.GridModelBuilder, _types.SHAPE_3D.Grid); | ||
Object.keys(_geometries).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
if (key in exports && exports[key] === _geometries[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _geometries[key]; | ||
} | ||
}); | ||
}); | ||
// import { registerModelBuilder, Batch } from '@antv/g-plugin-webgl-renderer'; | ||
// import { CubeUpdater } from './aabb/CubeUpdater'; | ||
// import { SphereUpdater } from './aabb/SphereUpdater'; | ||
// import { GridUpdater } from './aabb/GridUpdater'; | ||
// import { CubeModelBuilder } from './model/Cube'; | ||
// // import { SphereModelBuilder } from './model/Sphere'; | ||
// import { GridModelBuilder } from './model/Grid'; | ||
// import { SHAPE_3D } from './types'; | ||
// import { Cube } from './Cube'; | ||
// import { Sphere } from './Sphere'; | ||
// import { Grid } from './Grid'; | ||
// // TODO: provide more friendly API like `registerGeometry` | ||
// globalContainer.register(CubeUpdater); | ||
// globalContainer.register(SphereUpdater); | ||
// globalContainer.register(GridUpdater); | ||
var containerModule = (0, _manaSyringe.Module)(function (register) {// registerModelBuilder(CubeModelBuilder, SHAPE_3D.Cube); | ||
// // registerModelBuilder(SphereModelBuilder, SHAPE_3D.Sphere); | ||
// registerModelBuilder(GridModelBuilder, SHAPE_3D.Grid); | ||
}); | ||
exports.containerModule = containerModule; | ||
@@ -81,4 +63,5 @@ | ||
return Plugin; | ||
}(); | ||
}(); // export { Cube, Sphere, Grid }; | ||
exports.Plugin = Plugin; |
@@ -1,26 +0,1 @@ | ||
import { DisplayObject } from '@antv/g'; | ||
import { Batch, AttributeLocation, DeviceProgram, RenderInst } from '@antv/g-plugin-webgl-renderer'; | ||
import { Cube } from '../Cube'; | ||
declare class CubeProgram extends DeviceProgram { | ||
static a_Position: AttributeLocation; | ||
static a_Normal: number; | ||
static a_Uv: number; | ||
static ub_ObjectParams: number; | ||
both: string; | ||
vert: string; | ||
frag: string; | ||
} | ||
export declare class CubeModelBuilder extends Batch { | ||
program: CubeProgram; | ||
validate(object: DisplayObject): boolean; | ||
buildGeometry(): void; | ||
updateAttribute(object: DisplayObject, name: string, value: any): void; | ||
uploadUBO(renderInst: RenderInst): void; | ||
protected buildAttributes(objects: Cube[]): { | ||
indices: number[]; | ||
positions: number[]; | ||
normals: number[]; | ||
uvs: number[]; | ||
}; | ||
} | ||
export {}; | ||
@@ -1,293 +0,287 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.CubeModelBuilder = void 0; | ||
var _tslib = require("tslib"); | ||
var _manaSyringe = require("mana-syringe"); | ||
var _glMatrix = require("gl-matrix"); | ||
var _gPluginWebglRenderer = require("@antv/g-plugin-webgl-renderer"); | ||
var primitiveUv1Padding = 4.0 / 64; | ||
var primitiveUv1PaddingScale = 1.0 - primitiveUv1Padding * 2; | ||
var CubeProgram = | ||
/** @class */ | ||
function (_super) { | ||
(0, _tslib.__extends)(CubeProgram, _super); | ||
function CubeProgram() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.both = "\n " + _gPluginWebglRenderer.Batch.ShaderLibrary.BothDeclaration + "\n "; | ||
_this.vert = "\n " + _gPluginWebglRenderer.Batch.ShaderLibrary.VertDeclaration + "\n\n layout(location = " + CubeProgram.a_Position + ") attribute vec3 a_Position;\n layout(location = " + CubeProgram.a_Normal + ") attribute vec3 a_Normal;\n #ifdef USE_UV\n layout(location = " + CubeProgram.a_Uv + ") attribute vec2 a_Uv;\n varying vec2 v_Uv;\n #endif\n \n void main() {\n " + _gPluginWebglRenderer.Batch.ShaderLibrary.Vert + "\n\n gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * vec4(a_Position, 1.0);\n\n " + _gPluginWebglRenderer.Batch.ShaderLibrary.UvVert + "\n }\n "; | ||
_this.frag = "\n " + _gPluginWebglRenderer.Batch.ShaderLibrary.FragDeclaration + "\n " + _gPluginWebglRenderer.Batch.ShaderLibrary.UvFragDeclaration + "\n " + _gPluginWebglRenderer.Batch.ShaderLibrary.MapFragDeclaration + "\n \n void main() {\n " + _gPluginWebglRenderer.Batch.ShaderLibrary.Frag + "\n " + _gPluginWebglRenderer.Batch.ShaderLibrary.MapFrag + "\n\n gl_FragColor = u_Color;\n gl_FragColor.a = gl_FragColor.a * u_Opacity * u_FillOpacity;\n }\n "; | ||
return _this; | ||
} | ||
CubeProgram.a_Position = _gPluginWebglRenderer.AttributeLocation.MAX; | ||
CubeProgram.a_Normal = _gPluginWebglRenderer.AttributeLocation.MAX + 1; | ||
CubeProgram.a_Uv = _gPluginWebglRenderer.AttributeLocation.MAX + 2; | ||
CubeProgram.ub_ObjectParams = 1; | ||
return CubeProgram; | ||
}(_gPluginWebglRenderer.DeviceProgram); | ||
var CubeModelBuilder = | ||
/** @class */ | ||
function (_super) { | ||
(0, _tslib.__extends)(CubeModelBuilder, _super); | ||
function CubeModelBuilder() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.program = new CubeProgram(); | ||
return _this; | ||
} | ||
CubeModelBuilder.prototype.validate = function (object) { | ||
var instance = this.instance; // TODO: support different tex map, eg. max 24 like PIXI.js | ||
if (instance.parsedStyle.map && instance.parsedStyle.map !== object.parsedStyle.map) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
CubeModelBuilder.prototype.buildGeometry = function () { | ||
var _this = this; | ||
this.program.setDefineBool('USE_UV', true); | ||
var map = this.instance.parsedStyle.map; | ||
if (map) { | ||
this.program.setDefineBool('USE_MAP', true); | ||
this.mapping = new _gPluginWebglRenderer.TextureMapping(); | ||
this.mapping.texture = this.texturePool.getOrCreateTexture(this.device, map, (0, _gPluginWebglRenderer.makeTextureDescriptor2D)(_gPluginWebglRenderer.Format.U8_RGBA_NORM, 1, 1, 1), function () { | ||
// need re-render | ||
_this.objects.forEach(function (object) { | ||
var renderable = object.renderable; | ||
renderable.dirty = true; | ||
_this.renderingService.dirtify(); | ||
}); | ||
}); | ||
this.device.setResourceName(this.mapping.texture, 'Image Texture'); | ||
this.mapping.sampler = this.renderHelper.getCache().createSampler({ | ||
wrapS: 0 | ||
/* Clamp */ | ||
, | ||
wrapT: 0 | ||
/* Clamp */ | ||
, | ||
minFilter: 1 | ||
/* Bilinear */ | ||
, | ||
magFilter: 1 | ||
/* Bilinear */ | ||
, | ||
mipFilter: 0 | ||
/* NoMip */ | ||
, | ||
minLOD: 0, | ||
maxLOD: 0 | ||
}); | ||
} | ||
var _a = this.buildAttributes(this.objects), | ||
indices = _a.indices, | ||
positions = _a.positions, | ||
normals = _a.normals, | ||
uvs = _a.uvs; | ||
this.geometry.setIndices(new Uint32Array(indices)); | ||
this.geometry.vertexCount = 36; | ||
this.geometry.setVertexBuffer({ | ||
bufferIndex: 1, | ||
byteStride: 4 * 3, | ||
frequency: 1 | ||
/* PerVertex */ | ||
, | ||
attributes: [{ | ||
format: _gPluginWebglRenderer.Format.F32_RGB, | ||
bufferByteOffset: 4 * 0, | ||
location: CubeProgram.a_Position | ||
}], | ||
data: Float32Array.from(positions) | ||
}); | ||
this.geometry.setVertexBuffer({ | ||
bufferIndex: 2, | ||
byteStride: 4 * 3, | ||
frequency: 1 | ||
/* PerVertex */ | ||
, | ||
attributes: [{ | ||
format: _gPluginWebglRenderer.Format.F32_RGB, | ||
bufferByteOffset: 4 * 0, | ||
location: CubeProgram.a_Normal | ||
}], | ||
data: Float32Array.from(normals) | ||
}); | ||
this.geometry.setVertexBuffer({ | ||
bufferIndex: 3, | ||
byteStride: 4 * 2, | ||
frequency: 1 | ||
/* PerVertex */ | ||
, | ||
attributes: [{ | ||
format: _gPluginWebglRenderer.Format.F32_RG, | ||
bufferByteOffset: 4 * 0, | ||
location: CubeProgram.a_Uv | ||
}], | ||
data: Float32Array.from(uvs) | ||
}); | ||
}; | ||
CubeModelBuilder.prototype.updateAttribute = function (object, name, value) { | ||
_super.prototype.updateAttribute.call(this, object, name, value); | ||
var index = this.objects.indexOf(object); | ||
var geometry = this.geometry; | ||
if (name === 'width' || name === 'height' || name === 'depth') { | ||
var positions = this.buildAttributes([object]).positions; | ||
geometry.updateVertexBuffer(1, CubeProgram.a_Position, index, new Uint8Array(new Float32Array(positions).buffer)); | ||
} | ||
}; | ||
CubeModelBuilder.prototype.uploadUBO = function (renderInst) { | ||
// need 1 sampler | ||
renderInst.setBindingLayouts([{ | ||
numUniformBuffers: 1, | ||
numSamplers: 1 | ||
}]); | ||
renderInst.setSamplerBindingsFromTextureMappings([this.mapping]); | ||
}; | ||
CubeModelBuilder.prototype.buildAttributes = function (objects) { | ||
var positionsAll = []; | ||
var normalsAll = []; | ||
var uvsAll = []; | ||
var uvs1All = []; | ||
var indicesAll = []; | ||
var indicesStart = 0; | ||
objects.forEach(function (object) { | ||
var attributes = object.attributes; | ||
var _a = attributes.widthSegments, | ||
widthSegments = _a === void 0 ? 1 : _a, | ||
_b = attributes.heightSegments, | ||
heightSegments = _b === void 0 ? 1 : _b, | ||
_c = attributes.depthSegments, | ||
depthSegments = _c === void 0 ? 1 : _c, | ||
_d = attributes.height, | ||
height = _d === void 0 ? 0 : _d, | ||
_e = attributes.width, | ||
width = _e === void 0 ? 0 : _e, | ||
_f = attributes.depth, | ||
depth = _f === void 0 ? 0 : _f; | ||
var ws = widthSegments; | ||
var hs = heightSegments; | ||
var ds = depthSegments; | ||
var hex = width / 2; | ||
var hey = height / 2; | ||
var hez = depth / 2; | ||
var corners = [_glMatrix.vec3.fromValues(-hex, -hey, hez), _glMatrix.vec3.fromValues(hex, -hey, hez), _glMatrix.vec3.fromValues(hex, hey, hez), _glMatrix.vec3.fromValues(-hex, hey, hez), _glMatrix.vec3.fromValues(hex, -hey, -hez), _glMatrix.vec3.fromValues(-hex, -hey, -hez), _glMatrix.vec3.fromValues(-hex, hey, -hez), _glMatrix.vec3.fromValues(hex, hey, -hez)]; | ||
var faceAxes = [[0, 3, 1], [4, 7, 5], [1, 4, 0], [3, 6, 2], [1, 2, 4], [5, 6, 0] // LEFT | ||
]; | ||
var faceNormals = [[0, 0, 1], [0, 0, -1], [0, -1, 0], [0, 1, 0], [1, 0, 0], [-1, 0, 0] // LEFT | ||
]; | ||
var sides = { | ||
FRONT: 0, | ||
BACK: 1, | ||
TOP: 2, | ||
BOTTOM: 3, | ||
RIGHT: 4, | ||
LEFT: 5 | ||
}; | ||
var positions = []; | ||
var normals = []; | ||
var uvs = []; | ||
var uvs1 = []; | ||
var indices = []; | ||
var vcounter = 0; | ||
var generateFace = function generateFace(side, uSegments, vSegments) { | ||
var u; | ||
var v; | ||
var i; | ||
var j; | ||
for (i = 0; i <= uSegments; i++) { | ||
for (j = 0; j <= vSegments; j++) { | ||
var temp1 = _glMatrix.vec3.create(); | ||
var temp2 = _glMatrix.vec3.create(); | ||
var temp3 = _glMatrix.vec3.create(); | ||
var r = _glMatrix.vec3.create(); | ||
_glMatrix.vec3.lerp(temp1, corners[faceAxes[side][0]], corners[faceAxes[side][1]], i / uSegments); | ||
_glMatrix.vec3.lerp(temp2, corners[faceAxes[side][0]], corners[faceAxes[side][2]], j / vSegments); | ||
_glMatrix.vec3.sub(temp3, temp2, corners[faceAxes[side][0]]); | ||
_glMatrix.vec3.add(r, temp1, temp3); | ||
u = i / uSegments; | ||
v = j / vSegments; | ||
positions.push(r[0], r[1], r[2]); | ||
normals.push(faceNormals[side][0], faceNormals[side][1], faceNormals[side][2]); | ||
uvs.push(u, v); // pack as 3x2 | ||
// 1/3 will be empty, but it's either that or stretched pixels | ||
// TODO: generate non-rectangular lightMaps, so we could use space without stretching | ||
u /= 3; | ||
v /= 3; | ||
u = u * primitiveUv1PaddingScale + primitiveUv1Padding; | ||
v = v * primitiveUv1PaddingScale + primitiveUv1Padding; | ||
u += side % 3 / 3; | ||
v += Math.floor(side / 3) / 3; | ||
uvs1.push(u, v); | ||
if (i < uSegments && j < vSegments) { | ||
indices.push(vcounter + vSegments + 1 + indicesStart, vcounter + 1 + indicesStart, vcounter + indicesStart); | ||
indices.push(vcounter + vSegments + 1 + indicesStart, vcounter + vSegments + 2 + indicesStart, vcounter + 1 + indicesStart); | ||
} | ||
vcounter++; | ||
} | ||
} | ||
}; | ||
generateFace(sides.FRONT, ws, hs); | ||
generateFace(sides.BACK, ws, hs); | ||
generateFace(sides.TOP, ws, ds); | ||
generateFace(sides.BOTTOM, ws, ds); | ||
generateFace(sides.RIGHT, ds, hs); | ||
generateFace(sides.LEFT, ds, hs); | ||
indicesStart += 24; | ||
positionsAll.push.apply(positionsAll, (0, _tslib.__spreadArray)([], (0, _tslib.__read)(positions), false)); | ||
normalsAll.push.apply(normalsAll, (0, _tslib.__spreadArray)([], (0, _tslib.__read)(normals), false)); | ||
uvsAll.push.apply(uvsAll, (0, _tslib.__spreadArray)([], (0, _tslib.__read)(uvs), false)); | ||
indicesAll.push.apply(indicesAll, (0, _tslib.__spreadArray)([], (0, _tslib.__read)(indices), false)); | ||
}); | ||
return { | ||
indices: indicesAll, | ||
positions: positionsAll, | ||
normals: normalsAll, | ||
uvs: uvsAll | ||
}; // TODO: barycentric & tangent | ||
}; | ||
CubeModelBuilder = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)()], CubeModelBuilder); | ||
return CubeModelBuilder; | ||
}(_gPluginWebglRenderer.Batch); | ||
exports.CubeModelBuilder = CubeModelBuilder; | ||
// import { DisplayObject } from '@antv/g'; | ||
// import { singleton } from 'mana-syringe'; | ||
// import { vec3 } from 'gl-matrix'; | ||
// import { | ||
// Batch, | ||
// AttributeLocation, | ||
// DeviceProgram, | ||
// Format, | ||
// makeTextureDescriptor2D, | ||
// MipFilterMode, | ||
// TexFilterMode, | ||
// WrapMode, | ||
// TextureMapping, | ||
// RenderInst, | ||
// VertexBufferFrequency, | ||
// } from '@antv/g-plugin-webgl-renderer'; | ||
// import { Cube, CubeStyleProps } from '../Cube'; | ||
// const primitiveUv1Padding = 4.0 / 64; | ||
// const primitiveUv1PaddingScale = 1.0 - primitiveUv1Padding * 2; | ||
// class CubeProgram extends DeviceProgram { | ||
// static a_Position = AttributeLocation.MAX; | ||
// static a_Normal = AttributeLocation.MAX + 1; | ||
// static a_Uv = AttributeLocation.MAX + 2; | ||
// static ub_ObjectParams = 1; | ||
// both: string = ` | ||
// ${Batch.ShaderLibrary.BothDeclaration} | ||
// `; | ||
// vert: string = ` | ||
// ${Batch.ShaderLibrary.VertDeclaration} | ||
// layout(location = ${CubeProgram.a_Position}) attribute vec3 a_Position; | ||
// layout(location = ${CubeProgram.a_Normal}) attribute vec3 a_Normal; | ||
// #ifdef USE_UV | ||
// layout(location = ${CubeProgram.a_Uv}) attribute vec2 a_Uv; | ||
// varying vec2 v_Uv; | ||
// #endif | ||
// void main() { | ||
// ${Batch.ShaderLibrary.Vert} | ||
// gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * vec4(a_Position, 1.0); | ||
// ${Batch.ShaderLibrary.UvVert} | ||
// } | ||
// `; | ||
// frag: string = ` | ||
// ${Batch.ShaderLibrary.FragDeclaration} | ||
// ${Batch.ShaderLibrary.UvFragDeclaration} | ||
// ${Batch.ShaderLibrary.MapFragDeclaration} | ||
// void main() { | ||
// ${Batch.ShaderLibrary.Frag} | ||
// ${Batch.ShaderLibrary.MapFrag} | ||
// gl_FragColor = u_Color; | ||
// gl_FragColor.a = gl_FragColor.a * u_Opacity * u_FillOpacity; | ||
// } | ||
// `; | ||
// } | ||
// @singleton() | ||
// export class CubeModelBuilder extends Batch { | ||
// program = new CubeProgram(); | ||
// validate(object: DisplayObject) { | ||
// const instance = this.instance; | ||
// // TODO: support different tex map, eg. max 24 like PIXI.js | ||
// if (instance.parsedStyle.map && instance.parsedStyle.map !== object.parsedStyle.map) { | ||
// return false; | ||
// } | ||
// return true; | ||
// } | ||
// buildGeometry() { | ||
// this.program.setDefineBool('USE_UV', true); | ||
// const { map } = this.instance.parsedStyle; | ||
// if (map) { | ||
// this.program.setDefineBool('USE_MAP', true); | ||
// this.mapping = new TextureMapping(); | ||
// this.mapping.texture = this.texturePool.getOrCreateTexture( | ||
// this.device, | ||
// map, | ||
// makeTextureDescriptor2D(Format.U8_RGBA_NORM, 1, 1, 1), | ||
// () => { | ||
// // need re-render | ||
// this.objects.forEach((object) => { | ||
// const renderable = object.renderable; | ||
// renderable.dirty = true; | ||
// this.renderingService.dirtify(); | ||
// }); | ||
// }, | ||
// ); | ||
// this.device.setResourceName(this.mapping.texture, 'Image Texture'); | ||
// this.mapping.sampler = this.renderHelper.getCache().createSampler({ | ||
// wrapS: WrapMode.Clamp, | ||
// wrapT: WrapMode.Clamp, | ||
// minFilter: TexFilterMode.Bilinear, | ||
// magFilter: TexFilterMode.Bilinear, | ||
// mipFilter: MipFilterMode.NoMip, | ||
// minLOD: 0, | ||
// maxLOD: 0, | ||
// }); | ||
// } | ||
// const { indices, positions, normals, uvs } = this.buildAttributes(this.objects); | ||
// this.geometry.setIndices(new Uint32Array(indices)); | ||
// this.geometry.vertexCount = 36; | ||
// this.geometry.setVertexBuffer({ | ||
// bufferIndex: 1, | ||
// byteStride: 4 * 3, | ||
// frequency: VertexBufferFrequency.PerVertex, | ||
// attributes: [ | ||
// { | ||
// format: Format.F32_RGB, | ||
// bufferByteOffset: 4 * 0, | ||
// location: CubeProgram.a_Position, | ||
// }, | ||
// ], | ||
// data: Float32Array.from(positions), | ||
// }); | ||
// this.geometry.setVertexBuffer({ | ||
// bufferIndex: 2, | ||
// byteStride: 4 * 3, | ||
// frequency: VertexBufferFrequency.PerVertex, | ||
// attributes: [ | ||
// { | ||
// format: Format.F32_RGB, | ||
// bufferByteOffset: 4 * 0, | ||
// location: CubeProgram.a_Normal, | ||
// }, | ||
// ], | ||
// data: Float32Array.from(normals), | ||
// }); | ||
// this.geometry.setVertexBuffer({ | ||
// bufferIndex: 3, | ||
// byteStride: 4 * 2, | ||
// frequency: VertexBufferFrequency.PerVertex, | ||
// attributes: [ | ||
// { | ||
// format: Format.F32_RG, | ||
// bufferByteOffset: 4 * 0, | ||
// location: CubeProgram.a_Uv, | ||
// }, | ||
// ], | ||
// data: Float32Array.from(uvs), | ||
// }); | ||
// } | ||
// updateAttribute(object: DisplayObject, name: string, value: any) { | ||
// super.updateAttribute(object, name, value); | ||
// const index = this.objects.indexOf(object); | ||
// const geometry = this.geometry; | ||
// if (name === 'width' || name === 'height' || name === 'depth') { | ||
// const { positions } = this.buildAttributes([object]); | ||
// geometry.updateVertexBuffer( | ||
// 1, | ||
// CubeProgram.a_Position, | ||
// index, | ||
// new Uint8Array(new Float32Array(positions).buffer), | ||
// ); | ||
// } | ||
// } | ||
// uploadUBO(renderInst: RenderInst): void { | ||
// // need 1 sampler | ||
// renderInst.setBindingLayouts([{ numUniformBuffers: 1, numSamplers: 1 }]); | ||
// renderInst.setSamplerBindingsFromTextureMappings([this.mapping]); | ||
// } | ||
// protected buildAttributes(objects: Cube[]) { | ||
// const positionsAll: number[] = []; | ||
// const normalsAll: number[] = []; | ||
// const uvsAll: number[] = []; | ||
// const uvs1All: number[] = []; | ||
// const indicesAll: number[] = []; | ||
// let indicesStart = 0; | ||
// objects.forEach((object) => { | ||
// const attributes = object.attributes as CubeStyleProps; | ||
// const { | ||
// widthSegments = 1, | ||
// heightSegments = 1, | ||
// depthSegments = 1, | ||
// height = 0, | ||
// width = 0, | ||
// depth = 0, | ||
// } = attributes; | ||
// const ws = widthSegments; | ||
// const hs = heightSegments; | ||
// const ds = depthSegments; | ||
// const hex = width / 2; | ||
// const hey = height / 2; | ||
// const hez = depth / 2; | ||
// const corners = [ | ||
// vec3.fromValues(-hex, -hey, hez), | ||
// vec3.fromValues(hex, -hey, hez), | ||
// vec3.fromValues(hex, hey, hez), | ||
// vec3.fromValues(-hex, hey, hez), | ||
// vec3.fromValues(hex, -hey, -hez), | ||
// vec3.fromValues(-hex, -hey, -hez), | ||
// vec3.fromValues(-hex, hey, -hez), | ||
// vec3.fromValues(hex, hey, -hez), | ||
// ]; | ||
// const faceAxes = [ | ||
// [0, 3, 1], // FRONT | ||
// [4, 7, 5], // BACK | ||
// [1, 4, 0], // TOP | ||
// [3, 6, 2], // BOTTOM | ||
// [1, 2, 4], // RIGHT | ||
// [5, 6, 0], // LEFT | ||
// ]; | ||
// const faceNormals = [ | ||
// [0, 0, 1], // FRONT | ||
// [0, 0, -1], // BACK | ||
// [0, -1, 0], // TOP | ||
// [0, 1, 0], // BOTTOM | ||
// [1, 0, 0], // RIGHT | ||
// [-1, 0, 0], // LEFT | ||
// ]; | ||
// const sides = { | ||
// FRONT: 0, | ||
// BACK: 1, | ||
// TOP: 2, | ||
// BOTTOM: 3, | ||
// RIGHT: 4, | ||
// LEFT: 5, | ||
// }; | ||
// const positions: number[] = []; | ||
// const normals: number[] = []; | ||
// const uvs: number[] = []; | ||
// const uvs1: number[] = []; | ||
// const indices: number[] = []; | ||
// let vcounter = 0; | ||
// const generateFace = (side: number, uSegments: number, vSegments: number) => { | ||
// let u: number; | ||
// let v: number; | ||
// let i: number; | ||
// let j: number; | ||
// for (i = 0; i <= uSegments; i++) { | ||
// for (j = 0; j <= vSegments; j++) { | ||
// const temp1 = vec3.create(); | ||
// const temp2 = vec3.create(); | ||
// const temp3 = vec3.create(); | ||
// const r = vec3.create(); | ||
// vec3.lerp(temp1, corners[faceAxes[side][0]], corners[faceAxes[side][1]], i / uSegments); | ||
// vec3.lerp(temp2, corners[faceAxes[side][0]], corners[faceAxes[side][2]], j / vSegments); | ||
// vec3.sub(temp3, temp2, corners[faceAxes[side][0]]); | ||
// vec3.add(r, temp1, temp3); | ||
// u = i / uSegments; | ||
// v = j / vSegments; | ||
// positions.push(r[0], r[1], r[2]); | ||
// normals.push(faceNormals[side][0], faceNormals[side][1], faceNormals[side][2]); | ||
// uvs.push(u, v); | ||
// // pack as 3x2 | ||
// // 1/3 will be empty, but it's either that or stretched pixels | ||
// // TODO: generate non-rectangular lightMaps, so we could use space without stretching | ||
// u /= 3; | ||
// v /= 3; | ||
// u = u * primitiveUv1PaddingScale + primitiveUv1Padding; | ||
// v = v * primitiveUv1PaddingScale + primitiveUv1Padding; | ||
// u += (side % 3) / 3; | ||
// v += Math.floor(side / 3) / 3; | ||
// uvs1.push(u, v); | ||
// if (i < uSegments && j < vSegments) { | ||
// indices.push( | ||
// vcounter + vSegments + 1 + indicesStart, | ||
// vcounter + 1 + indicesStart, | ||
// vcounter + indicesStart, | ||
// ); | ||
// indices.push( | ||
// vcounter + vSegments + 1 + indicesStart, | ||
// vcounter + vSegments + 2 + indicesStart, | ||
// vcounter + 1 + indicesStart, | ||
// ); | ||
// } | ||
// vcounter++; | ||
// } | ||
// } | ||
// }; | ||
// generateFace(sides.FRONT, ws, hs); | ||
// generateFace(sides.BACK, ws, hs); | ||
// generateFace(sides.TOP, ws, ds); | ||
// generateFace(sides.BOTTOM, ws, ds); | ||
// generateFace(sides.RIGHT, ds, hs); | ||
// generateFace(sides.LEFT, ds, hs); | ||
// indicesStart += 24; | ||
// positionsAll.push(...positions); | ||
// normalsAll.push(...normals); | ||
// uvsAll.push(...uvs); | ||
// indicesAll.push(...indices); | ||
// }); | ||
// return { | ||
// indices: indicesAll, | ||
// positions: positionsAll, | ||
// normals: normalsAll, | ||
// uvs: uvsAll, | ||
// }; | ||
// // TODO: barycentric & tangent | ||
// } | ||
// } | ||
"use strict"; |
@@ -1,18 +0,1 @@ | ||
import { DisplayObject } from '@antv/g'; | ||
import { Batch, AttributeLocation, DeviceProgram, RenderInst } from '@antv/g-plugin-webgl-renderer'; | ||
declare class GridProgram extends DeviceProgram { | ||
static a_Position: AttributeLocation; | ||
static a_GridSize: number; | ||
static ub_ObjectParams: number; | ||
both: string; | ||
vert: string; | ||
frag: string; | ||
} | ||
export declare class GridModelBuilder extends Batch { | ||
program: GridProgram; | ||
validate(object: DisplayObject): boolean; | ||
updateAttribute(object: DisplayObject, name: string, value: any): void; | ||
uploadUBO(renderInst: RenderInst): void; | ||
buildGeometry(): void; | ||
} | ||
export {}; | ||
@@ -1,111 +0,120 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.GridModelBuilder = void 0; | ||
var _tslib = require("tslib"); | ||
var _manaSyringe = require("mana-syringe"); | ||
var _gPluginWebglRenderer = require("@antv/g-plugin-webgl-renderer"); | ||
var GridProgram = | ||
/** @class */ | ||
function (_super) { | ||
(0, _tslib.__extends)(GridProgram, _super); | ||
function GridProgram() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.both = "\n " + _gPluginWebglRenderer.Batch.ShaderLibrary.BothDeclaration + "\n "; | ||
_this.vert = "\n " + _gPluginWebglRenderer.Batch.ShaderLibrary.VertDeclaration + "\n\n layout(location = " + GridProgram.a_Position + ") attribute vec3 a_Position;\n layout(location = " + GridProgram.a_GridSize + ") attribute vec2 a_GridSize;\n\n varying vec3 v_Position;\n varying vec2 v_GridSize;\n \n void main() {\n " + _gPluginWebglRenderer.Batch.ShaderLibrary.Vert + "\n\n v_GridSize = a_GridSize;\n v_Position = a_Position;\n\n gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * vec4(a_Position, 1.0);\n }\n "; | ||
_this.frag = "\n " + _gPluginWebglRenderer.Batch.ShaderLibrary.FragDeclaration + "\n\n // #extension GL_OES_standard_derivatives : enable\n\n varying vec3 v_Position;\n varying vec2 v_GridSize;\n \n void main() {\n " + _gPluginWebglRenderer.Batch.ShaderLibrary.Frag + "\n\n // vec4 u_GridColor = u_StrokeColor;\n vec4 u_GridColor = u_Color;\n float u_GridSize2 = v_GridSize.y;\n\n float wx = v_Position.x;\n float wz = v_Position.z;\n\n float x1 = abs(fract(wx / u_GridSize2 - 0.5) - 0.5) / fwidth(wx) * u_GridSize2;\n float z1 = abs(fract(wz / u_GridSize2 - 0.5) - 0.5) / fwidth(wz) * u_GridSize2;\n\n float v1 = 1.0 - clamp(min(x1, z1), 0.0, 1.0);\n gl_FragColor = mix(gl_FragColor, u_GridColor, v1);\n\n gl_FragColor.a = gl_FragColor.a * u_Opacity;\n }\n "; | ||
return _this; | ||
} | ||
GridProgram.a_Position = _gPluginWebglRenderer.AttributeLocation.MAX; | ||
GridProgram.a_GridSize = _gPluginWebglRenderer.AttributeLocation.MAX + 1; | ||
GridProgram.ub_ObjectParams = 1; | ||
return GridProgram; | ||
}(_gPluginWebglRenderer.DeviceProgram); | ||
var GridModelBuilder = | ||
/** @class */ | ||
function (_super) { | ||
(0, _tslib.__extends)(GridModelBuilder, _super); | ||
function GridModelBuilder() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.program = new GridProgram(); | ||
return _this; | ||
} | ||
GridModelBuilder.prototype.validate = function (object) { | ||
return true; | ||
}; | ||
GridModelBuilder.prototype.updateAttribute = function (object, name, value) { | ||
_super.prototype.updateAttribute.call(this, object, name, value); | ||
var index = this.objects.indexOf(object); | ||
var geometry = this.geometry; | ||
}; | ||
GridModelBuilder.prototype.uploadUBO = function (renderInst) { | ||
renderInst.setMegaStateFlags({ | ||
cullMode: 0 | ||
/* None */ | ||
}); | ||
renderInst.setBindingLayouts([{ | ||
numUniformBuffers: 1, | ||
numSamplers: 0 | ||
}]); | ||
}; | ||
GridModelBuilder.prototype.buildGeometry = function () { | ||
var instance = this.instance; | ||
var _a = instance.attributes, | ||
height = _a.height, | ||
width = _a.width; | ||
var halfWidth = width / 2; | ||
var halfHeight = height / 2; | ||
this.geometry.setIndices(new Uint32Array([0, 3, 2, 2, 1, 0])); | ||
this.geometry.vertexCount = 6; | ||
this.geometry.setVertexBuffer({ | ||
bufferIndex: 1, | ||
byteStride: 4 * 3, | ||
frequency: 1 | ||
/* PerVertex */ | ||
, | ||
attributes: [{ | ||
format: _gPluginWebglRenderer.Format.F32_RGB, | ||
bufferByteOffset: 4 * 0, | ||
location: GridProgram.a_Position | ||
}], | ||
data: Float32Array.from([-halfWidth, 0, -halfHeight, halfWidth, 0, -halfHeight, halfWidth, 0, halfHeight, -halfWidth, 0, halfHeight]) | ||
}); | ||
this.geometry.setVertexBuffer({ | ||
bufferIndex: 2, | ||
byteStride: 4 * 2, | ||
frequency: 2 | ||
/* PerInstance */ | ||
, | ||
attributes: [{ | ||
format: _gPluginWebglRenderer.Format.F32_RG, | ||
bufferByteOffset: 4 * 0, | ||
location: GridProgram.a_GridSize, | ||
divisor: 1 | ||
}], | ||
data: Float32Array.from([10, 10]) | ||
}); | ||
}; | ||
GridModelBuilder = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)()], GridModelBuilder); | ||
return GridModelBuilder; | ||
}(_gPluginWebglRenderer.Batch); | ||
exports.GridModelBuilder = GridModelBuilder; | ||
// import { DisplayObject, Renderable } from '@antv/g'; | ||
// import { inject, singleton } from 'mana-syringe'; | ||
// import { vec3 } from 'gl-matrix'; | ||
// import { | ||
// Batch, | ||
// AttributeLocation, | ||
// CullMode, | ||
// DeviceProgram, | ||
// Format, | ||
// RenderInst, | ||
// VertexBufferFrequency, | ||
// } from '@antv/g-plugin-webgl-renderer'; | ||
// import { GridStyleProps } from '../Grid'; | ||
// class GridProgram extends DeviceProgram { | ||
// static a_Position = AttributeLocation.MAX; | ||
// static a_GridSize = AttributeLocation.MAX + 1; | ||
// static ub_ObjectParams = 1; | ||
// both: string = ` | ||
// ${Batch.ShaderLibrary.BothDeclaration} | ||
// `; | ||
// vert: string = ` | ||
// ${Batch.ShaderLibrary.VertDeclaration} | ||
// layout(location = ${GridProgram.a_Position}) attribute vec3 a_Position; | ||
// layout(location = ${GridProgram.a_GridSize}) attribute vec2 a_GridSize; | ||
// varying vec3 v_Position; | ||
// varying vec2 v_GridSize; | ||
// void main() { | ||
// ${Batch.ShaderLibrary.Vert} | ||
// v_GridSize = a_GridSize; | ||
// v_Position = a_Position; | ||
// gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * vec4(a_Position, 1.0); | ||
// } | ||
// `; | ||
// frag: string = ` | ||
// ${Batch.ShaderLibrary.FragDeclaration} | ||
// // #extension GL_OES_standard_derivatives : enable | ||
// varying vec3 v_Position; | ||
// varying vec2 v_GridSize; | ||
// void main() { | ||
// ${Batch.ShaderLibrary.Frag} | ||
// // vec4 u_GridColor = u_StrokeColor; | ||
// vec4 u_GridColor = u_Color; | ||
// float u_GridSize2 = v_GridSize.y; | ||
// float wx = v_Position.x; | ||
// float wz = v_Position.z; | ||
// float x1 = abs(fract(wx / u_GridSize2 - 0.5) - 0.5) / fwidth(wx) * u_GridSize2; | ||
// float z1 = abs(fract(wz / u_GridSize2 - 0.5) - 0.5) / fwidth(wz) * u_GridSize2; | ||
// float v1 = 1.0 - clamp(min(x1, z1), 0.0, 1.0); | ||
// gl_FragColor = mix(gl_FragColor, u_GridColor, v1); | ||
// gl_FragColor.a = gl_FragColor.a * u_Opacity; | ||
// } | ||
// `; | ||
// } | ||
// @singleton() | ||
// export class GridModelBuilder extends Batch { | ||
// program = new GridProgram(); | ||
// validate(object: DisplayObject) { | ||
// return true; | ||
// } | ||
// updateAttribute(object: DisplayObject, name: string, value: any) { | ||
// super.updateAttribute(object, name, value); | ||
// const index = this.objects.indexOf(object); | ||
// const geometry = this.geometry; | ||
// } | ||
// uploadUBO(renderInst: RenderInst): void { | ||
// renderInst.setMegaStateFlags({ | ||
// cullMode: CullMode.None, | ||
// }); | ||
// renderInst.setBindingLayouts([{ numUniformBuffers: 1, numSamplers: 0 }]); | ||
// } | ||
// buildGeometry() { | ||
// const instance = this.instance; | ||
// const { height, width } = instance.attributes; | ||
// const halfWidth = width / 2; | ||
// const halfHeight = height / 2; | ||
// this.geometry.setIndices(new Uint32Array([0, 3, 2, 2, 1, 0])); | ||
// this.geometry.vertexCount = 6; | ||
// this.geometry.setVertexBuffer({ | ||
// bufferIndex: 1, | ||
// byteStride: 4 * 3, | ||
// frequency: VertexBufferFrequency.PerVertex, | ||
// attributes: [ | ||
// { | ||
// format: Format.F32_RGB, | ||
// bufferByteOffset: 4 * 0, | ||
// location: GridProgram.a_Position, | ||
// }, | ||
// ], | ||
// data: Float32Array.from([ | ||
// -halfWidth, | ||
// 0, | ||
// -halfHeight, | ||
// halfWidth, | ||
// 0, | ||
// -halfHeight, | ||
// halfWidth, | ||
// 0, | ||
// halfHeight, | ||
// -halfWidth, | ||
// 0, | ||
// halfHeight, | ||
// ]), | ||
// }); | ||
// this.geometry.setVertexBuffer({ | ||
// bufferIndex: 2, | ||
// byteStride: 4 * 2, | ||
// frequency: VertexBufferFrequency.PerInstance, | ||
// attributes: [ | ||
// { | ||
// format: Format.F32_RG, | ||
// bufferByteOffset: 4 * 0, | ||
// location: GridProgram.a_GridSize, | ||
// divisor: 1, | ||
// }, | ||
// ], | ||
// data: Float32Array.from([10, 10]), | ||
// }); | ||
// } | ||
// } | ||
"use strict"; |
{ | ||
"name": "@antv/g-plugin-3d", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Provide 3D extension for G", | ||
@@ -40,6 +40,7 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@antv/util": "^2.0.13" | ||
"@antv/util": "^2.0.13", | ||
"tslib": "^2.3.1" | ||
}, | ||
"peerDependencies": { | ||
"@antv/g": "^1.0.1", | ||
"@antv/g": "^5.0.1", | ||
"@antv/g-plugin-webgl-renderer": "^1.0.1", | ||
@@ -51,3 +52,3 @@ "mana-syringe": "^0.2.2" | ||
}, | ||
"gitHead": "d09726ac85b8738d53c97002a98848b4a450bfcd" | ||
"gitHead": "3d4d25c30b0134186e9e6e4adb54052ee581df48" | ||
} |
@@ -9,7 +9,7 @@ # 3D extension for G | ||
import { Canvas, Group } from '@antv/g'; | ||
import { Renderer as WebGLRenderer } from '@antv/g-webgl'; | ||
import { Cube, Plugin } from '@antv/g-plugin-3d'; | ||
import { Renderer } from '@antv/g-webgl'; | ||
import { CubeGeometry, MeshBasicMaterial, Mesh, Plugin } from '@antv/g-plugin-3d'; | ||
// create a webgl renderer | ||
const webglRenderer = new WebGLRenderer(); | ||
const webglRenderer = new Renderer(); | ||
webglRenderer.registerPlugin(new Plugin()); | ||
@@ -25,11 +25,27 @@ | ||
// create a cube | ||
const cube = new Cube({ | ||
// create a geometry | ||
const geometry = new CubeGeometry({ | ||
width: 200, | ||
height: 200, | ||
depth: 200, | ||
}); | ||
// create a material | ||
const material = new MeshBasicMaterial({ | ||
color: '#1890FF', | ||
}); | ||
// create a cube mesh | ||
const cube = new Mesh({ | ||
style: { | ||
width: 200, | ||
height: 200, | ||
depth: 200, | ||
fill: '#1890FF', | ||
geometry, | ||
material, | ||
}, | ||
}); | ||
// append to canvas | ||
canvas.appendChild(cube); | ||
// transform it like other 2D shapes | ||
cube.translate(100, 100, 0); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74
2181
50
92373
5
1
+ Addedtslib@^2.3.1