awv3
Version:
AWV client CAD framework
1 lines • 4.5 kB
JavaScript
"use strict";function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t["default"]=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}exports.__esModule=!0;var _getIterator2=require("babel-runtime/core-js/get-iterator"),_getIterator3=_interopRequireDefault(_getIterator2),_extends2=require("babel-runtime/helpers/extends"),_extends3=_interopRequireDefault(_extends2),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_three=require("three"),_three2=_interopRequireDefault(_three);require("perfnow");var _helpers=require("../core/helpers"),Helpers=_interopRequireWildcard(_helpers),_tween=require("../animation/tween"),_tween2=_interopRequireDefault(_tween),Renderer=function(){function e(){var t=this,i=arguments.length<=0||void 0===arguments[0]?Error.log("Factory was initialized without canvas"):arguments[0],r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];(0,_classCallCheck3["default"])(this,e),r=(0,_extends3["default"])({resolution:parseFloat(Helpers.url("resolution"))||1,pixelated:Helpers.url("pixelated")||!1,clearColor:new _three2["default"].Color(0),place:"first",startImmediately:!0,precision:"highp",premultipliedAlpha:!0,stencil:!0,depth:!0,preserveDrawingBuffer:!0,alpha:!0,antialias:!0,logarithmicDepthBuffer:!1,sortObjects:!0,autoClear:!1,canvasStyle:"position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; overflow: hidden;",shadowMapEnabled:!0,shadowMapType:_three2["default"].PCFShadowMap},r),this.canvas=i,this.resolution=r.resolution,this.clearColor=r.clearColor,this.gl=new _three2["default"].WebGLRenderer({precision:r.precision,premultipliedAlpha:r.premultipliedAlpha,stencil:r.stencil,depth:r.depth,preserveDrawingBuffer:r.preserveDrawingBuffer,alpha:r.alpha,antialias:r.antialias,logarithmicDepthBuffer:r.logarithmicDepthBuffer}),this.context=this.gl.domElement,this.context.setAttribute("style",r.canvasStyle),r.pixelated&&(this.context.style.imageRendering="pixelated"),this.gl.sortObjects=r.sortObjects,this.gl.autoClear=r.autoClear,this.gl.shadowMap.enabled=r.shadowMapEnabled,this.gl.shadowMap.type=r.shadowMapType,"last"===r.place?i.dom.appendChild(this.context):i.dom.insertBefore(this.context,i.dom.firstChild),window.addEventListener("resize",function(){return t.resize()},!1),this.resize(),setTimeout(function(){return t.resize()},1),setTimeout(function(){return t.resize()},100),setTimeout(function(){return t.resize()},500),this.gl.setScissorTest(!1),this.gl.setClearColor(this.clearColor,0),this.gl.clear(),this.gl.setScissorTest(!0);var a=this;this.invalidateFrames=1,this.dirty=!0,this.time=0,this.render=function(e){if(a.time=e,requestAnimationFrame(a.render),a.invalidateFrames>0&&a.dirty){var t=a.context.getBoundingClientRect();t.left==a.offset.left&&t.top==a.offset.top&&t.width==a.offset.width&&t.height==a.offset.height||(a.offset=t,a.invalidateCanvas(),t.width==a.offset.width&&t.height==a.offset.height||a.gl.setSize(a.offset.width*a.resolution,a.offset.height*a.resolution,!1)),a.invalidateFrames--}_tween2["default"].update(e);for(var i=!0,r=a.canvas.views,s=Array.isArray(r),l=0,r=s?r:(0,_getIterator3["default"])(r);;){var n;if(s){if(l>=r.length)break;n=r[l++]}else{if(l=r.next(),l.done)break;n=l.value}var o=n;o.clear(e)&&(i=!1)}for(var h=a.canvas.views,d=Array.isArray(h),u=0,h=d?h:(0,_getIterator3["default"])(h);;){var f;if(d){if(u>=h.length)break;f=h[u++]}else{if(u=h.next(),u.done)break;f=u.value}var p=f;p.render(e)}i&&(a.dirty=!1)},r.startImmediately&&this.start()}return e.prototype.start=function(){this.render(performance.now())},e.prototype.resize=function(){this.offset=this.context.getBoundingClientRect(),this.gl.setSize(this.offset.width*this.resolution,this.offset.height*this.resolution,!1),this.invalidateCanvas(30),this.invalidateViews(30)},e.prototype.invalidateCanvas=function(){var e=arguments.length<=0||void 0===arguments[0]?1:arguments[0];this.invalidateFrames+=e,this.invalidateFrames>60&&(this.invalidateFrames=60)},e.prototype.invalidateViews=function(){var e=arguments.length<=0||void 0===arguments[0]?1:arguments[0];this.dirty=!0;for(var t=this.canvas.views,i=Array.isArray(t),r=0,t=i?t:(0,_getIterator3["default"])(t);;){var a;if(i){if(r>=t.length)break;a=t[r++]}else{if(r=t.next(),r.done)break;a=r.value}var s=a;s.invalidate(e)}},e}();exports["default"]=Renderer;