{"version":3,"sources":["webpack:///webpack/universalModuleDefinition?5ca6","webpack:///canvas.js","webpack:///./src/web/canvas.js","webpack:///./src/ui/canvas/index.js","webpack:///./src/ui/canvas/canvas.js","webpack:///./src/ui/canvas/material-canvas.js"],"names":["root","factory","exports","module","define","amd","this","webpackJsonpGrafika","0","__webpack_require__","3","_interopRequireWildcard","obj","__esModule","newObj","key","Object","prototype","hasOwnProperty","call","default","_lodash","_canvas","Canvas","_window","window","Cx","assign","6","defineProperty","value","keys","forEach","enumerable","get","_materialCanvas","7","StaticCanvas","undefined","_config","_gear","_cdl","_view","View","extend","View2D_Mixin","DocumentView_Mixin","SelectedFigures_Mixin","FigureConditions_Mixin","typeName","Properties","mainDocument","type","def","owned","set","v","_setDoc","background","_setBackground","allowMultiDocumentSelection","postResize","Config","keepLowerLeftCornerAsOrigin","centerPages","viewCenter","document","_document","doc","zoomToFit$","zoomToFitFigures$","apply","arguments","resetToOrigin","zoomPages","add","figures","config","selector","layer","destinationLayerSelector","setActiveLayerBy","callParent","figureAtPointEx","docPoint","tabFigures","_allowMultiDocumentSelection","editingContent","topFigureFromEx","activeSelectableFiguresForDoc","_mainDocument","_background","getBrushAtPoint","lFigure","brushHitTest","tight","polyregion","brush","empty","figure","fromFigures","filterRight","frame_","contains","candidates","map","brushPerformHitTest","length","candidate","brushCheckCandidates","k","kEnd","lOptions","frameBased","figureView","hitTest","polyregionHit","activePage","layerBy","activeDocument","activeLayer","drawPage","page","context","transform","_this","forEachFigure","draw","redrawFigure","renderer","mapToFigureViews","figureViews","init","addEvents","_bind","SyncedFigureViews","view","pageViewTransforms","WeakMap","Debug","canvas","Document","oldDoc","unlinkDoc","_activeDocumentChanged","selectedFigures","_clear","linkDoc","fireEvent","otherDocFor","otherDocPageFor","backgroundPageFor","mainDocumentPageFor","fireChangeEvents","_unlinkMainDoc","_linkMainDoc","link","on_pageschanged","pages","on_activepagechanged","unlink","_unlinkBackground","_linkBackground","dispose","redrawDoc","redraw","on_rendercomplete","render$","viewTransform","pageViewTransform","backgroundPages","_pages","pageId","_id","backgroundPage","find","id","Math","min","indexOf","mainDocumentPages","mainDocumentPage","getZoomToFitFigures","visibleCrossDocumentPageFiguresOf","visibleFigures","concat","zoomToFitPages$","_this2","margin","_defaultMargin","map$","Figures","bounds$","then","bounds","zoomAround","on_zoomupdated","zoom","_this3","center","_this4","Point","setPageViewTransform","added","removed","_this5","ViewTransform","delete","on_historycommitstarted","waitFor","_this6","_undoRedoViewTransform","cloneDeep","on_undo","onUndoRedoRevert","on_redo","on_revert","_this7","InteractiveView_Mixin","createRenderers","Plugin","ActiveRenderer","insertViewPlugins","plugins","renderPlugins","useSpecialPens","SpecialPens","insert","ViewControls","PluginsLayer","AlignmentLines","FigureAnnotations","Tools","108","createAboveSceneCamera","width","height","THREE","OrthographicCamera","updateAboveSceneCamera","camera","left","right","top","bottom","updateProjectionMatrix","MaterialCanvas","NormalMapImage","target","drawTo_normal","src","initPlugin","imagePromise","image","console","log","_ref","save","rect","Matrix","m","scale","materialScale","transformContext","fillStyle","createPattern","fill","restore","createTextures","TextureComposition","textureType","createScene","Composition","main","material","Renderer3D","initThreeScene","threeScene","Scene","createDrawingSurface","light","_light","HemisphereLight","position","light3","PointLight","light2","clamp","d","max","addEventListener","event","p","viewPoint","x","y","updateDrawingSurface","_documentPlane","remove","_documentGeometry","_documentMaterial","MeshPhongMaterial","texture","threeTexture","normalMap","emissive","Color","specular","shininess","transparent","_texture$composedCanv","composedCanvas","planeGeometry","PlaneBufferGeometry","plane","Mesh","updateSize","draw3D","render"],"mappings":"CAAA,SAAAA,EAAAC,GACA,gBAAAC,UAAA,gBAAAC,QACAA,OAAAD,QAAAD,IACA,kBAAAG,gBAAAC,IACAD,UAAAH,GACA,gBAAAC,SACAA,QAAA,QAAAD,IAEAD,EAAA,QAAAC,KACCK,KAAA,WACD,MCAOC,sBAAqB,IAEtBC,EACA,SAASL,EAAQD,EAASO,GAE/BN,EAAOD,QAAUO,EAAoB,IAKhCC,EACA,SA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,kBAnG0C,WAoGxChK,KAAK+J,OAAO,MACZ/J,KAAK4E,WAALX,MAAAjE,KAAmBkE,YAGrBoP,WAxG0C,SAwG9BjF,EAAOC,GACjBtO,KAAK4E,WAAWyJ,EAAMC,GACtBtO,KAAKkS,uBAELzD,EAAuBzO,KAAK0O,OAAO1O,KAAKqO,MAAMrO,KAAKsO,SAGrDiF,OA/G0C,SA+GlC5L,GACN6H,QAAQC,IAAI,WAEZ9H,EAAS6L,OAAQxT,KAAK+Q,WAAY/Q,KAAK0O","file":"canvas.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"Grafika\"] = factory();\n\telse\n\t\troot[\"Grafika\"] = factory();\n})(this, function() {\nreturn \n\n\n/** WEBPACK FOOTER **\n ** webpack/universalModuleDefinition\n **/","(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"Grafika\"] = factory();\n\telse\n\t\troot[\"Grafika\"] = factory();\n})(this, function() {\nreturn webpackJsonpGrafika([1],{\n\n/***/ 0:\n/***/ function(module, exports, __webpack_require__) {\n\n\tmodule.exports = __webpack_require__(3);\n\n\n/***/ },\n\n/***/ 3:\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\n\t\n\tvar _lodash = __webpack_require__(4);\n\t\n\tvar _canvas = __webpack_require__(6);\n\t\n\tvar Canvas = _interopRequireWildcard(_canvas);\n\t\n\t__webpack_require__(109);\n\t\n\tfunction _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }\n\t\n\tvar _window = window;\n\tvar Cx = _window.Cx;\n\t\n\t\n\t(0, _lodash.assign)(Cx, Canvas);\n\n/***/ },\n\n/***/ 6:\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\t\n\tvar _canvas = __webpack_require__(7);\n\t\n\tObject.keys(_canvas).forEach(function (key) {\n\t if (key === \"default\") return;\n\t Object.defineProperty(exports, key, {\n\t enumerable: true,\n\t get: function () {\n\t return _canvas[key];\n\t }\n\t });\n\t});\n\t\n\tvar _materialCanvas = __webpack_require__(108);\n\t\n\tObject.keys(_materialCanvas).forEach(function (key) {\n\t if (key === \"default\") return;\n\t Object.defineProperty(exports, key, {\n\t enumerable: true,\n\t get: function () {\n\t return _materialCanvas[key];\n\t }\n\t });\n\t});\n\n/***/ },\n\n/***/ 7:\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\texports.Canvas = exports.StaticCanvas = undefined;\n\t\n\tvar _config = __webpack_require__(2);\n\t\n\tvar _lodash = __webpack_require__(4);\n\t\n\tvar _gear = __webpack_require__(8);\n\t\n\tvar _cdl = __webpack_require__(15);\n\t\n\tvar _view = __webpack_require__(84);\n\t\n\t__webpack_require__(102);\n\t\n\t__webpack_require__(105);\n\t\n\t__webpack_require__(106);\n\t\n\t__webpack_require__(107);\n\t\n\tvar StaticCanvas = exports.StaticCanvas = _view.View.extend(_view.View2D_Mixin).extend(_view.DocumentView_Mixin).extend(_view.SelectedFigures_Mixin).extend(_cdl.FigureConditions_Mixin).extend({\n\t\n\t typeName: 'StaticCanvas',\n\t\n\t Properties: {\n\t\n\t mainDocument: { type: 'Document', def: null, owned: false, set: function (v) {\n\t this._setDoc(v);\n\t }\n\t },\n\t\n\t background: { type: 'Document', def: null, owned: false, set: function (v) {\n\t this._setBackground(v);\n\t }\n\t },\n\t\n\t allowMultiDocumentSelection: { type: 'boolean', def: false }\n\t\n\t },\n\t postResize: function () {\n\t if (_config.Config.keepLowerLeftCornerAsOrigin) {\n\t this.centerPages(this.viewCenter);\n\t }\n\t },\n\t\n\t get document() {\n\t return this._document;\n\t },\n\t set document(doc) {\n\t this._setDoc(doc);\n\t },\n\t\n\t zoomToFit$: function () /* ...params */{\n\t return this.zoomToFitFigures$.apply(this, arguments);\n\t },\n\t resetToOrigin: function () {\n\t this.zoomPages(1);\n\t this.centerPages(this.viewCenter);\n\t },\n\t\n\t // [TODO] Allow apps to better configure addition using general filters\n\t\n\t add: function (figures, config) {\n\t var selector = config && config.layer || this.destinationLayerSelector;\n\t if (selector) {\n\t this.setActiveLayerBy(selector);\n\t }\n\t return this.callParent(figures, config);\n\t },\n\t\n\t\n\t // Allow Multi Document Selection\n\t figureAtPointEx: function (docPoint, tabFigures) {\n\t if (this._allowMultiDocumentSelection && !this._document.editingContent()) {\n\t return this.topFigureFromEx(this.activeSelectableFiguresForDoc(this._mainDocument), docPoint, tabFigures) || this.topFigureFromEx(this.activeSelectableFiguresForDoc(this._background), docPoint, tabFigures);\n\t } else {\n\t return this.callParent(docPoint, tabFigures);\n\t }\n\t },\n\t getBrushAtPoint: function (docPoint) {\n\t var lFigure = this.brushHitTest(this.activeSelectableFiguresForDoc(this._mainDocument), docPoint) || this.brushHitTest(this.activeSelectableFiguresForDoc(this._background), docPoint);\n\t\n\t if (lFigure != null && lFigure.tight) {\n\t if (lFigure.polyregion != null && lFigure.polyregion.brush != null && !lFigure.polyregion.brush.empty()) return lFigure.polyregion.brush;\n\t\n\t return lFigure.figure ? lFigure.figure.brush : null;\n\t }\n\t\n\t return null;\n\t },\n\t brushHitTest: function (fromFigures, docPoint) {\n\t var figures = (0, _gear.filterRight)(fromFigures, function (figure) {\n\t return figure.frame_().contains(docPoint);\n\t });\n\t var candidates = (0, _lodash.map)(figures, function (figure) {\n\t return { figure: figure, docPoint: docPoint, tight: false, polyregion: null };\n\t });\n\t return this.brushPerformHitTest(candidates);\n\t },\n\t brushPerformHitTest: function (candidates) {\n\t if (candidates.length === 0) {\n\t return null; // Nothing around\n\t }\n\t var candidate = this.brushCheckCandidates(candidates);\n\t if (candidate) {\n\t candidate.tight = true;\n\t return candidate;\n\t }\n\t return null;\n\t },\n\t brushCheckCandidates: function (candidates) {\n\t for (var k = 0, kEnd = candidates.length; k < kEnd; ++k) {\n\t var candidate = candidates[k];\n\t var lOptions = { frameBased: false };\n\t if (this.figureView(candidate.figure).hitTest(candidate.docPoint, lOptions)) {\n\t candidate.polyregion = lOptions.polyregionHit;\n\t return candidate;\n\t }\n\t }\n\t },\n\t setActiveLayerBy: function (selector) {\n\t var doc = this._mainDocument,\n\t layer = doc.activePage.layerBy(selector);\n\t if (!layer) {\n\t doc = this._background;\n\t layer = doc.activePage.layerBy(selector);\n\t }\n\t\n\t if (layer) {\n\t this.activeDocument = doc;\n\t this.activeLayer = layer;\n\t }\n\t return this;\n\t },\n\t\n\t\n\t // [TODO] insertViewPlugins\n\t\n\t drawPage: function (page, context, transform, config) {\n\t var _this = this;\n\t\n\t page.forEachFigure(function (figure) {\n\t _this.figureView(figure).draw(context, transform, config);\n\t });\n\t },\n\t redrawFigure: function (figure) {\n\t this.renderer.redrawFigure(this, figure);\n\t },\n\t mapToFigureViews: function (figures) {\n\t return this.figureViews.mapToFigureViews(figures);\n\t },\n\t figureView: function (figure) {\n\t return this.figureViews.get(figure);\n\t },\n\t init: function () {\n\t var config = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];\n\t\n\t\n\t this.addEvents('brushselected', 'activedocumentchanged', 'newdocument', 'newbackground');\n\t\n\t this._bind('zoomToFit$')._bind('zoomToFitPages$');\n\t\n\t this.figureViews = new _view.SyncedFigureViews({ view: this });\n\t\n\t this.pageViewTransforms = new WeakMap();\n\t\n\t // Broadcast the first view for debugging\n\t var Debug = _config.Config.Debug;\n\t if (Debug && !Debug.canvas) {\n\t Debug.canvas = this;\n\t }\n\t\n\t this.callParent(config);\n\t\n\t // Keep this at the end of the init function, because events are triggered\n\t // that needs all Mixins to be already initialized\n\t this._setBackground(new _cdl.Document());\n\t this._setDoc(new _cdl.Document());\n\t },\n\t\n\t\n\t // Intiatilization of documents and DocumentView interaction\n\t //----------------------------------------------------------------------------\n\t // The docs are linked to the figureViews here, the active document events\n\t // are linked directly in activeDocument\n\t\n\t get activeDocument() {\n\t return this._document;\n\t },\n\t set activeDocument(doc) {\n\t var oldDoc = this._document;\n\t if (oldDoc !== doc) {\n\t if (oldDoc) {\n\t this.unlinkDoc(oldDoc);\n\t }\n\t\n\t this._activeDocumentChanged = true;\n\t\n\t // assert( v === this._mainDocument || v === this._background );\n\t this._document = doc;\n\t this.selectedFigures._clear();\n\t\n\t this.linkDoc(doc);\n\t this.fireEvent('activedocumentchanged', doc);\n\t }\n\t },\n\t\n\t otherDocFor: function (doc) {\n\t return doc === this._mainDocument ? this._background : this._mainDocument;\n\t },\n\t otherDocPageFor: function (page) {\n\t return page.document === this.mainDocument ? this.backgroundPageFor(page) : this.mainDocumentPageFor(page);\n\t },\n\t fireChangeEvents: function (type, doc) {\n\t var _activeDocumentChanged = this._activeDocumentChanged;\n\t\n\t this._activeDocumentChanged = false;\n\t\n\t return this.callParent(type, doc) || _activeDocumentChanged;\n\t },\n\t _setDoc: function (doc) {\n\t var oldDoc = this._mainDocument;\n\t if (oldDoc) {\n\t this._unlinkMainDoc(oldDoc);\n\t }\n\t this._mainDocument = doc;\n\t // Keep the main document as the active document\n\t if (!this._document || this._document === oldDoc) {\n\t this.activeDocument = doc;\n\t }\n\t this._linkMainDoc(doc);\n\t if (_config.Config.keepLowerLeftCornerAsOrigin) {\n\t this.centerPages(this.viewCenter);\n\t }\n\t this.fireEvent('newdocument', this, doc, oldDoc);\n\t },\n\t _linkMainDoc: function (doc) {\n\t this.figureViews.link(doc);\n\t this.on_pageschanged(doc, doc.pages);\n\t this.on_activepagechanged(doc, doc.activePage);\n\t },\n\t _unlinkMainDoc: function (doc) {\n\t this.figureViews.unlink(doc);\n\t },\n\t _setBackground: function (doc) {\n\t var oldDoc = this._background;\n\t if (oldDoc) {\n\t this._unlinkBackground(oldDoc);\n\t }\n\t this._background = doc;\n\t this._linkBackground(doc);\n\t this.fireEvent('newbackground', this, doc, oldDoc);\n\t },\n\t _linkBackground: function (doc) {\n\t this.figureViews.link(doc);\n\t },\n\t _unlinkBackground: function (doc) {\n\t this.figureViews.unlink(doc);\n\t },\n\t dispose: function () {\n\t this._unlinkBackground(this.background);\n\t this._unlinkMainDoc(this.mainDocument);\n\t this.callParent();\n\t },\n\t redrawDoc: function () {\n\t this.redraw('document', 'background'); // [TODO] Hack for demo, not needed\n\t\n\t /*\r\n\t if( this.doc === this.mainDocument ) {\r\n\t this.redraw('document');\r\n\t }\r\n\t else {\r\n\t this.redraw('background');\r\n\t }\r\n\t */\n\t },\n\t\n\t\n\t // Syncronization between mainDocument and background\n\t //---------------------------------------------------------------------------------------\n\t\n\t on_rendercomplete: function (doc) {\n\t // If the document was commited, also issue a render of the other doc because Canvas\n\t // promises that everything is going to get rendered after that (if not we could have\n\t // bugs with patterns like change doc > zoom to fit doc > doc.commit$\n\t this.otherDocFor(doc).render$();\n\t this.callParent.apply(this, arguments);\n\t },\n\t on_activepagechanged: function (doc, page) {\n\t this.otherDocFor(doc).activePage = this.otherDocPageFor(page);\n\t this.viewTransform = this.pageViewTransform(this.mainDocument.activePage);\n\t this.callParent(doc, page);\n\t },\n\t\n\t\n\t // [TODO] Add options for different background/mainDocument setups\n\t // Avoid assuming an structure. Directly provide Apps configuration\n\t // points to decide how pages are syncronized. For some applications\n\t // the background pages may be totally independent of the main document\n\t\n\t backgroundPageFor: function (page) {\n\t var background = this._background;\n\t var backgroundPages = background._pages;\n\t var pageId = page._id;\n\t\n\t var backgroundPage = pageId !== null ? (0, _lodash.find)(backgroundPages, { id: page.id }) : null;\n\t if (!backgroundPage) {\n\t var pages = this._mainDocument._pages;\n\t backgroundPage = backgroundPages[Math.min(pages.indexOf(page), backgroundPages.length - 1)];\n\t }\n\t return backgroundPage;\n\t },\n\t mainDocumentPageFor: function (page) {\n\t var mainDocument = this._mainDocument;\n\t var mainDocumentPages = mainDocument._pages;\n\t var pageId = page._id;\n\t\n\t var mainDocumentPage = pageId !== null ? (0, _lodash.find)(mainDocumentPages, { id: page.id }) : null;\n\t if (!mainDocumentPage) {\n\t var pages = this._background._pages;\n\t mainDocumentPage = mainDocumentPages[Math.min(pages.indexOf(page), mainDocumentPages.length - 1)];\n\t }\n\t return mainDocumentPage;\n\t },\n\t\n\t\n\t // Page independent view transforms\n\t //--------------------------------------------------------------------------------\n\t\n\t // [TODO] We could use getState/setState to store the viewTransform for each page\n\t\n\t getZoomToFitFigures: function () {\n\t return this.visibleCrossDocumentPageFiguresOf(this.activePage);\n\t },\n\t visibleCrossDocumentPageFiguresOf: function (page) {\n\t var figures = page.visibleFigures;\n\t var backgroundPage = this.backgroundPageFor(page);\n\t return backgroundPage ? figures.concat(backgroundPage.visibleFigures) : figures;\n\t },\n\t zoomToFitPages$: function () {\n\t var _this2 = this;\n\t\n\t var margin = arguments.length <= 0 || arguments[0] === undefined ? this._defaultMargin() : arguments[0];\n\t\n\t return (0, _gear.map$)(this._mainDocument._pages, function (page) {\n\t var figures = _this2.visibleCrossDocumentPageFiguresOf(page);\n\t return _cdl.Figures.bounds$(figures).then(function (bounds) {\n\t _this2.pageViewTransform(page).zoomAround(_this2, bounds, margin);\n\t });\n\t }).then(function () {\n\t return _this2.on_zoomupdated();\n\t });\n\t },\n\t zoomPages: function (zoom) {\n\t var _this3 = this;\n\t\n\t (0, _lodash.forEach)(this.mainDocument.pages, function (page) {\n\t _this3.pageViewTransform(page).zoom = zoom;\n\t });\n\t this.on_zoomupdated();\n\t return this;\n\t },\n\t centerPages: function (center) {\n\t var _this4 = this;\n\t\n\t (0, _lodash.forEach)(this._mainDocument._pages, function (page) {\n\t _this4.pageViewTransform(page).center = new _cdl.Point(center);\n\t });\n\t this.on_zoomupdated();\n\t return this;\n\t },\n\t pageViewTransform: function (page) {\n\t var viewTransform = this.pageViewTransforms.get(page);\n\t if (!viewTransform) {\n\t viewTransform = this.pageViewTransforms.get(this.otherDocPageFor(page));\n\t }\n\t return viewTransform;\n\t },\n\t setPageViewTransform: function (page, viewTransform) {\n\t this.pageViewTransforms.set(page, viewTransform);\n\t },\n\t\n\t\n\t // [TODO]\n\t // This can be improved by linking pages when commiting ( undoPage, redoPage links )\n\t // That will allow to even preserve zooming when adding or deleting pages\n\t // and could simplify a lot of this code\n\t\n\t on_pageschanged: function (doc, added, removed) {\n\t var _this5 = this;\n\t\n\t if (added) {\n\t (0, _lodash.forEach)(added, function (page) {\n\t if (!_this5.pageViewTransform(page)) {\n\t _this5.setPageViewTransform(page, new _view.ViewTransform());\n\t }\n\t });\n\t }\n\t if (removed) {\n\t (0, _lodash.forEach)(removed, function (page) {\n\t return _this5.pageViewTransforms.delete(page);\n\t });\n\t }\n\t this.callParent(doc, added, removed);\n\t },\n\t on_historycommitstarted: function (doc, waitFor, type) {\n\t var _this6 = this;\n\t\n\t this._undoRedoViewTransform = (0, _gear.cloneDeep)((0, _lodash.map)(doc.pages, function (page) {\n\t return _this6.pageViewTransform(page);\n\t }));\n\t this.callParent(doc, waitFor, type);\n\t },\n\t on_undo: function (doc) {\n\t this.onUndoRedoRevert(doc);\n\t this.callParent.apply(this, arguments);\n\t },\n\t on_redo: function (doc) {\n\t this.onUndoRedoRevert(doc);\n\t this.callParent.apply(this, arguments);\n\t },\n\t on_revert: function (doc) {\n\t this.onUndoRedoRevert(doc);\n\t this.callParent.apply(this, arguments);\n\t },\n\t onUndoRedoRevert: function (doc) {\n\t var _this7 = this;\n\t\n\t var pages = doc.pages;\n\t\n\t if (this._undoRedoViewTransform.length === pages.length) {\n\t\n\t // Pages have not change, maintain zoom for them\n\t (0, _lodash.forEach)(pages, function (page, k) {\n\t _this7.setPageViewTransform(page, _this7._undoRedoViewTransform[k]);\n\t });\n\t\n\t this.viewTransform = this.pageViewTransform(doc.activePage);\n\t this._undoRedoViewTransform = [];\n\t\n\t this.render$();\n\t } else {\n\t this.zoomToFitPages$().then(this.render$);\n\t }\n\t }\n\t});\n\t\n\tvar Canvas = exports.Canvas = StaticCanvas.extend(_view.InteractiveView_Mixin).extend({\n\t\n\t typeName: 'Canvas',\n\t\n\t Properties: {\n\t\n\t // [TODO] Use conditions\n\t // dblclickContentEditionEnabled: { type: 'function', def(/*figure*/) { return true; } },\n\t },\n\t\n\t createRenderers: function () {\n\t return [_view.Plugin.ActiveRenderer()];\n\t },\n\t\n\t\n\t // [TODO] Work in progress to properly separate Static and Interactive Canvas\n\t\n\t insertViewPlugins: function (plugins) {\n\t\n\t var renderPlugins = _config.Config.useSpecialPens ? [_view.Plugin.SpecialPens()] : [];\n\t\n\t plugins.insert(0, renderPlugins.concat(this.createRenderers()).concat([_view.Plugin.ViewControls(), _view.Plugin.PluginsLayer(), _view.Plugin.AlignmentLines(), _view.Plugin.FigureAnnotations(), _view.Plugin.Tools()]));\n\t }\n\t});\n\n/***/ },\n\n/***/ 108:\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\texports.MaterialCanvas = undefined;\n\t\n\tvar _config = __webpack_require__(2);\n\t\n\tvar _view = __webpack_require__(84);\n\t\n\tvar _gear = __webpack_require__(8);\n\t\n\tvar _cdl = __webpack_require__(15);\n\t\n\tvar _canvas = __webpack_require__(7);\n\t\n\t/* globals THREE */\n\t\n\tfunction createAboveSceneCamera(width, height) {\n\t return new THREE.OrthographicCamera(-width / 2, width / 2, height / 2, -height / 2, 0, 30);\n\t}\n\t\n\tfunction updateAboveSceneCamera(camera, width, height) {\n\t camera.left = width / -2;\n\t camera.right = width / 2;\n\t camera.top = height / 2;\n\t camera.bottom = height / -2;\n\t camera.updateProjectionMatrix();\n\t}\n\t\n\t// [TODO] Plugin.TextureImage({ textureType: 'normal', src: ... })\n\t\n\t_view.Plugin.NormalMapImage = _view.Plugin.extend({ typeName: 'NormalMapImage',\n\t\n\t target: 'document',\n\t drawTo_normal: ['normal'],\n\t\n\t Properties: {\n\t src: { type: 'string', def: 'texture.jpg' }\n\t },\n\t\n\t initPlugin: function (view) {\n\t var _this = this;\n\t\n\t (0, _gear.imagePromise)(this.src).then(function (image) {\n\t _this.image = image;\n\t view.redraw('normal');\n\t console.log('loaded');\n\t });\n\t },\n\t draw: function (_ref) {\n\t var context = _ref.context;\n\t var transform = _ref.transform;\n\t var image = this.image;\n\t\n\t if (!image) {\n\t return;\n\t }\n\t context.save();\n\t var canvas = context.canvas;\n\t\n\t context.rect(0, 0, canvas.width, canvas.height);\n\t _cdl.Matrix.m(transform, _cdl.Matrix.scale(_config.Config.materialScale || 0.2)).transformContext(context);\n\t context.fillStyle = context.createPattern(image, 'repeat');\n\t context.fill();\n\t context.restore();\n\t }\n\t});\n\t\n\tvar MaterialCanvas = exports.MaterialCanvas = _canvas.Canvas.extend({ typeName: 'MaterialCanvas',\n\t\n\t Properties: {},\n\t\n\t createTextures: function () {\n\t return [new _view.TextureComposition({ textureType: 'normal' }), new _view.TextureComposition({ textureType: 'color' })];\n\t },\n\t createScene: function () {\n\t return new _view.Composition({ textureType: '3D', main: true });\n\t },\n\t createRenderers: function () {\n\t return this.callParent().concat([_view.Plugin.NormalMapImage({ src: 'texture-' + (_config.Config.material || 1) + '.jpg' }), _view.Plugin.Renderer3D()]);\n\t },\n\t init: function () {\n\t var config = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];\n\t\n\t window.canvas = this;\n\t this.callParent(config);\n\t this.initThreeScene();\n\t },\n\t initThreeScene: function () {\n\t var _this2 = this;\n\t\n\t var threeScene = this.threeScene = new THREE.Scene();\n\t\n\t var width = this.width;\n\t var height = this.height;\n\t\n\t this.camera = createAboveSceneCamera(width, height);\n\t\n\t this.createDrawingSurface();\n\t\n\t var light = this._light = new THREE.HemisphereLight(0xaaaaaa, 0x808080, 0.5);\n\t threeScene.add(light);\n\t light.position.set(200, 200, 300);\n\t\n\t var light3 = new THREE.PointLight(0xaaaaaa, 0.5);\n\t light3.position.set(150, 150, 500);\n\t threeScene.add(light3);\n\t\n\t var light2 = new THREE.PointLight(0xaaaaaa, 0.5);\n\t light2.position.set(0, 850, 850);\n\t threeScene.add(light2);\n\t\n\t var clamp = function (v) {\n\t var d = 400;\n\t return Math.min(Math.max(v, -d), d);\n\t };\n\t document.addEventListener('mousemove', function (event) {\n\t var width = _this2.width;\n\t var height = _this2.height;\n\t\n\t var p = _this2.viewPoint(event);\n\t light2.position.set(clamp(p.x - width / 2, 20), 850, 850 + clamp(p.y - height / 2));\n\t _this2.redraw('3D');\n\t }, false);\n\t },\n\t createDrawingSurface: function () {\n\t // There is an issue with updating the texture of the plane geometry\n\t // For the prototype, I just recreate the scene but we need to fix this\n\t // to improve performance\n\t this.updateDrawingSurface();\n\t },\n\t updateDrawingSurface: function () {\n\t\n\t if (this._documentPlane) {\n\t this.threeScene.remove(this._documentPlane);\n\t this._documentGeometry.dispose();\n\t this._documentMaterial.dispose();\n\t }\n\t\n\t var material = this._documentMaterial = new THREE.MeshPhongMaterial({\n\t\n\t map: this.texture('color').threeTexture,\n\t normalMap: this.texture('normal').threeTexture,\n\t\n\t // color : new THREE.Color(\"rgb(155,196,30)\"),\n\t emissive: new THREE.Color(\"#\" + (_config.Config.emissive || \"222222\")),\n\t specular: new THREE.Color(\"#\" + (_config.Config.specular || \"888888\")),\n\t shininess: _config.Config.shininess || 10\n\t });\n\t\n\t material.transparent = true;\n\t\n\t var _texture$composedCanv = this.texture('color').composedCanvas;\n\t var width = _texture$composedCanv.width;\n\t var height = _texture$composedCanv.height;\n\t\n\t var planeGeometry = this._documentGeometry = new THREE.PlaneBufferGeometry(width, height);\n\t\n\t var plane = this._documentPlane = new THREE.Mesh(planeGeometry, material);\n\t\n\t console.log(this.height - height);\n\t console.log(width - this.width);\n\t plane.position.set((width - this.width) / 2, -(height - this.height) / 2, 0);\n\t\n\t this.threeScene.add(plane);\n\t },\n\t on_rendercomplete: function () {\n\t this.redraw('3D');\n\t this.callParent.apply(this, arguments);\n\t },\n\t updateSize: function (width, height) {\n\t this.callParent(width, height);\n\t this.updateDrawingSurface();\n\t\n\t updateAboveSceneCamera(this.camera, this.width, this.height);\n\t },\n\t draw3D: function (renderer) {\n\t console.log('draw 3D');\n\t\n\t renderer.render(this.threeScene, this.camera);\n\t }\n\t});\n\n/***/ }\n\n})\n});\n;\n\n\n/** WEBPACK FOOTER **\n ** canvas.js\n **/","import { assign } from 'lodash';\r\n\r\nimport * as Canvas from '../ui/canvas';\r\nimport '../ui/plugin';\r\n\r\nlet { Cx } = window;\r\n\r\nassign( Cx, Canvas );\r\n\n\n\n/** WEBPACK FOOTER **\n ** ./src/web/canvas.js\n **/","export * from './canvas';\r\nexport * from './material-canvas';\r\n\n\n\n/** WEBPACK FOOTER **\n ** ./src/ui/canvas/index.js\n **/","import { Config } from 'config';\r\n\r\nimport { forEach, map, find } from 'lodash';\r\n\r\nimport { cloneDeep, map$, filterRight } from 'gear';\r\n\r\nimport { Point,\r\n Document, Figures,\r\n FigureConditions_Mixin } from 'cdl';\r\n\r\nimport { View, Plugin, SyncedFigureViews,\r\n View2D_Mixin, ViewTransform,\r\n DocumentView_Mixin,\r\n SelectedFigures_Mixin,\r\n InteractiveView_Mixin } from '../view';\r\n\r\nimport '../plugin/active-renderer';\r\nimport '../plugin/special-pens';\r\nimport '../plugin/alignment-lines';\r\nimport '../plugin/figure-annotations';\r\n\r\n\r\nexport const StaticCanvas = View.extend( View2D_Mixin )\r\n .extend( DocumentView_Mixin )\r\n .extend( SelectedFigures_Mixin )\r\n .extend( FigureConditions_Mixin ).extend({\r\n\r\n typeName: 'StaticCanvas',\r\n\r\n Properties: {\r\n\r\n mainDocument: { type: 'Document', def: null, owned: false, set( v ) { this._setDoc(v); } },\r\n\r\n background: { type: 'Document', def: null, owned: false, set( v ) { this._setBackground(v); } },\r\n\r\n allowMultiDocumentSelection: { type: 'boolean', def: false },\r\n\r\n },\r\n postResize() {\r\n if (Config.keepLowerLeftCornerAsOrigin) {\r\n this.centerPages(this.viewCenter);\r\n }\r\n },\r\n get document() {\r\n return this._document;\r\n },\r\n set document( doc ) {\r\n this._setDoc(doc);\r\n },\r\n\r\n zoomToFit$(/* ...params */) {\r\n return this.zoomToFitFigures$(...arguments);\r\n },\r\n\r\n resetToOrigin() {\r\n this.zoomPages(1);\r\n this.centerPages(this.viewCenter);\r\n },\r\n // [TODO] Allow apps to better configure addition using general filters\r\n\r\n add( figures, config ) {\r\n const selector = ( config && config.layer ) || this.destinationLayerSelector;\r\n if( selector ) {\r\n this.setActiveLayerBy(selector);\r\n }\r\n return this.callParent(figures,config);\r\n },\r\n\r\n // Allow Multi Document Selection\r\n figureAtPointEx( docPoint, tabFigures ) {\r\n if( this._allowMultiDocumentSelection && ! this._document.editingContent() ) {\r\n return this.topFigureFromEx( this.activeSelectableFiguresForDoc(this._mainDocument), docPoint, tabFigures ) ||\r\n this.topFigureFromEx( this.activeSelectableFiguresForDoc(this._background), docPoint, tabFigures );\r\n }\r\n else {\r\n return this.callParent(docPoint,tabFigures);\r\n }\r\n },\r\n\r\n getBrushAtPoint( docPoint ) {\r\n let lFigure = this.brushHitTest( this.activeSelectableFiguresForDoc(this._mainDocument), docPoint) ||\r\n this.brushHitTest( this.activeSelectableFiguresForDoc(this._background), docPoint );\r\n\r\n if (lFigure != null && lFigure.tight) \r\n {\r\n if (lFigure.polyregion != null && lFigure.polyregion.brush != null && !lFigure.polyregion.brush.empty())\r\n return lFigure.polyregion.brush;\r\n\r\n return lFigure.figure?lFigure.figure.brush:null;\r\n }\r\n \r\n return null;\r\n },\r\n\r\n brushHitTest( fromFigures, docPoint ) {\r\n const figures = filterRight( fromFigures, figure => {\r\n return figure.frame_().contains(docPoint);\r\n });\r\n const candidates = map( figures, figure => {\r\n return { figure, docPoint, tight: false, polyregion:null };\r\n });\r\n return this.brushPerformHitTest(candidates);\r\n },\r\n\r\n brushPerformHitTest( candidates ) {\r\n if( candidates.length === 0 ) {\r\n return null; // Nothing around\r\n }\r\n const candidate = this.brushCheckCandidates( candidates );\r\n if( candidate ) {\r\n candidate.tight = true;\r\n return candidate;\r\n }\r\n return null;\r\n },\r\n\r\n brushCheckCandidates( candidates ) {\r\n for( let k = 0, kEnd = candidates.length; k < kEnd; ++k ) {\r\n const candidate = candidates[k];\r\n const lOptions = {frameBased:false};\r\n if( this.figureView(candidate.figure).hitTest(candidate.docPoint, lOptions) ) {\r\n candidate.polyregion = lOptions.polyregionHit;\r\n return candidate;\r\n }\r\n }\r\n },\r\n\r\n\r\n setActiveLayerBy( selector ) {\r\n let doc = this._mainDocument,\r\n layer = doc.activePage.layerBy(selector);\r\n if( ! layer ) {\r\n doc = this._background;\r\n layer = doc.activePage.layerBy(selector);\r\n }\r\n\r\n if( layer ) {\r\n this.activeDocument = doc;\r\n this.activeLayer = layer;\r\n }\r\n return this;\r\n },\r\n\r\n // [TODO] insertViewPlugins\r\n\r\n drawPage( page, context, transform, config ) {\r\n page.forEachFigure( figure => {\r\n this.figureView(figure).draw(context,transform,config);\r\n });\r\n },\r\n\r\n redrawFigure( figure ) {\r\n this.renderer.redrawFigure(this,figure);\r\n },\r\n\r\n mapToFigureViews( figures ) {\r\n return this.figureViews.mapToFigureViews(figures);\r\n },\r\n\r\n figureView( figure ) {\r\n return this.figureViews.get(figure);\r\n },\r\n\r\n init( config = {} ) {\r\n\r\n this.addEvents(\r\n 'brushselected',\r\n 'activedocumentchanged',\r\n 'newdocument',\r\n 'newbackground'\r\n );\r\n\r\n this._bind('zoomToFit$')\r\n ._bind('zoomToFitPages$');\r\n\r\n this.figureViews = new SyncedFigureViews({ view: this });\r\n\r\n this.pageViewTransforms = new WeakMap();\r\n\r\n // Broadcast the first view for debugging\r\n const Debug = Config.Debug;\r\n if( Debug && ! Debug.canvas ) {\r\n Debug.canvas = this;\r\n }\r\n\r\n this.callParent(config);\r\n\r\n // Keep this at the end of the init function, because events are triggered\r\n // that needs all Mixins to be already initialized\r\n this._setBackground( new Document() );\r\n this._setDoc( new Document() );\r\n },\r\n\r\n\r\n // Intiatilization of documents and DocumentView interaction\r\n //----------------------------------------------------------------------------\r\n // The docs are linked to the figureViews here, the active document events\r\n // are linked directly in activeDocument\r\n\r\n get activeDocument() {\r\n return this._document;\r\n },\r\n set activeDocument( doc ) {\r\n const oldDoc = this._document;\r\n if( oldDoc !== doc ) {\r\n if( oldDoc ){\r\n this.unlinkDoc(oldDoc);\r\n }\r\n\r\n this._activeDocumentChanged = true;\r\n\r\n // assert( v === this._mainDocument || v === this._background );\r\n this._document = doc;\r\n this.selectedFigures._clear();\r\n\r\n this.linkDoc(doc);\r\n this.fireEvent('activedocumentchanged',doc);\r\n }\r\n },\r\n\r\n otherDocFor( doc ) {\r\n return doc === this._mainDocument ? this._background : this._mainDocument;\r\n },\r\n\r\n otherDocPageFor( page ){\r\n return page.document === this.mainDocument ? this.backgroundPageFor(page)\r\n : this.mainDocumentPageFor(page);\r\n },\r\n\r\n fireChangeEvents( type, doc ) {\r\n const { _activeDocumentChanged } = this;\r\n this._activeDocumentChanged = false;\r\n\r\n return this.callParent(type,doc) || _activeDocumentChanged;\r\n },\r\n\r\n _setDoc( doc ) {\r\n const oldDoc = this._mainDocument;\r\n if( oldDoc ) {\r\n this._unlinkMainDoc(oldDoc);\r\n }\r\n this._mainDocument = doc;\r\n // Keep the main document as the active document\r\n if( ! this._document || this._document === oldDoc ) {\r\n this.activeDocument = doc;\r\n }\r\n this._linkMainDoc(doc);\r\n if (Config.keepLowerLeftCornerAsOrigin) {\r\n this.centerPages(this.viewCenter);\r\n }\r\n this.fireEvent('newdocument',this,doc,oldDoc);\r\n },\r\n _linkMainDoc( doc ) {\r\n this.figureViews.link(doc);\r\n this.on_pageschanged(doc,doc.pages);\r\n this.on_activepagechanged(doc,doc.activePage);\r\n },\r\n _unlinkMainDoc( doc ) {\r\n this.figureViews.unlink(doc);\r\n },\r\n\r\n\r\n _setBackground( doc ) {\r\n const oldDoc = this._background;\r\n if( oldDoc ) {\r\n this._unlinkBackground(oldDoc);\r\n }\r\n this._background = doc;\r\n this._linkBackground(doc);\r\n this.fireEvent('newbackground',this,doc,oldDoc);\r\n },\r\n _linkBackground( doc ) {\r\n this.figureViews.link(doc);\r\n },\r\n _unlinkBackground( doc ) {\r\n this.figureViews.unlink(doc);\r\n },\r\n\r\n dispose() {\r\n this._unlinkBackground(this.background);\r\n this._unlinkMainDoc(this.mainDocument);\r\n this.callParent();\r\n },\r\n\r\n redrawDoc() {\r\n this.redraw('document','background'); // [TODO] Hack for demo, not needed\r\n\r\n /*\r\n if( this.doc === this.mainDocument ) {\r\n this.redraw('document');\r\n }\r\n else {\r\n this.redraw('background');\r\n }\r\n */\r\n },\r\n\r\n // Syncronization between mainDocument and background\r\n //---------------------------------------------------------------------------------------\r\n\r\n on_rendercomplete( doc ) {\r\n // If the document was commited, also issue a render of the other doc because Canvas\r\n // promises that everything is going to get rendered after that (if not we could have\r\n // bugs with patterns like change doc > zoom to fit doc > doc.commit$\r\n this.otherDocFor(doc).render$();\r\n this.callParent(...arguments);\r\n },\r\n\r\n on_activepagechanged( doc, page ) {\r\n this.otherDocFor(doc).activePage = this.otherDocPageFor(page);\r\n this.viewTransform = this.pageViewTransform(this.mainDocument.activePage);\r\n this.callParent(doc,page);\r\n },\r\n\r\n // [TODO] Add options for different background/mainDocument setups\r\n // Avoid assuming an structure. Directly provide Apps configuration\r\n // points to decide how pages are syncronized. For some applications\r\n // the background pages may be totally independent of the main document\r\n\r\n backgroundPageFor( page ) {\r\n const background = this._background;\r\n const backgroundPages = background._pages;\r\n const pageId = page._id;\r\n\r\n let backgroundPage = pageId !== null ? find( backgroundPages, { id: page.id } ) : null;\r\n if( ! backgroundPage ) {\r\n const pages = this._mainDocument._pages;\r\n backgroundPage = backgroundPages[Math.min(pages.indexOf(page),backgroundPages.length-1)];\r\n }\r\n return backgroundPage;\r\n },\r\n\r\n mainDocumentPageFor( page ) {\r\n const mainDocument = this._mainDocument;\r\n const mainDocumentPages = mainDocument._pages;\r\n const pageId = page._id;\r\n\r\n let mainDocumentPage = pageId !== null ? find( mainDocumentPages, { id: page.id } ) : null;\r\n if( ! mainDocumentPage ) {\r\n const pages = this._background._pages;\r\n mainDocumentPage = mainDocumentPages[Math.min(pages.indexOf(page), mainDocumentPages.length-1)];\r\n }\r\n return mainDocumentPage;\r\n },\r\n\r\n // Page independent view transforms\r\n //--------------------------------------------------------------------------------\r\n\r\n // [TODO] We could use getState/setState to store the viewTransform for each page\r\n\r\n getZoomToFitFigures() {\r\n return this.visibleCrossDocumentPageFiguresOf(this.activePage);\r\n },\r\n\r\n visibleCrossDocumentPageFiguresOf( page ) {\r\n const figures = page.visibleFigures;\r\n const backgroundPage = this.backgroundPageFor(page);\r\n return backgroundPage ? figures.concat( backgroundPage.visibleFigures ) : figures;\r\n },\r\n\r\n zoomToFitPages$( margin = this._defaultMargin() ) {\r\n return map$(this._mainDocument._pages, page => {\r\n const figures = this.visibleCrossDocumentPageFiguresOf(page);\r\n return Figures.bounds$(figures).then( bounds => {\r\n this.pageViewTransform(page).zoomAround(this,bounds,margin);\r\n });\r\n }).then( () => this.on_zoomupdated() );\r\n },\r\n\r\n zoomPages( zoom ) {\r\n forEach(this.mainDocument.pages, page => {\r\n this.pageViewTransform(page).zoom = zoom;\r\n });\r\n this.on_zoomupdated();\r\n return this;\r\n },\r\n\r\n centerPages( center ) {\r\n forEach( this._mainDocument._pages, page => {\r\n this.pageViewTransform(page).center = new Point( center );\r\n });\r\n this.on_zoomupdated();\r\n return this;\r\n },\r\n\r\n pageViewTransform( page ) {\r\n let viewTransform = this.pageViewTransforms.get(page);\r\n if( ! viewTransform ){\r\n viewTransform = this.pageViewTransforms.get( this.otherDocPageFor(page) );\r\n }\r\n return viewTransform;\r\n },\r\n\r\n setPageViewTransform( page, viewTransform ) {\r\n this.pageViewTransforms.set(page,viewTransform);\r\n },\r\n\r\n // [TODO]\r\n // This can be improved by linking pages when commiting ( undoPage, redoPage links )\r\n // That will allow to even preserve zooming when adding or deleting pages\r\n // and could simplify a lot of this code\r\n\r\n on_pageschanged( doc, added, removed ) {\r\n if( added ) {\r\n forEach( added, page => {\r\n if( ! this.pageViewTransform(page) ){\r\n this.setPageViewTransform(page,new ViewTransform());\r\n }\r\n });\r\n }\r\n if( removed ) {\r\n forEach( removed, page => this.pageViewTransforms.delete(page) );\r\n }\r\n this.callParent(doc,added,removed);\r\n },\r\n\r\n on_historycommitstarted( doc, waitFor, type ) {\r\n this._undoRedoViewTransform = cloneDeep(\r\n map( doc.pages, page => this.pageViewTransform(page) )\r\n );\r\n this.callParent(doc,waitFor,type);\r\n },\r\n\r\n on_undo( doc ){\r\n this.onUndoRedoRevert(doc);\r\n this.callParent(...arguments);\r\n },\r\n on_redo( doc ){\r\n this.onUndoRedoRevert(doc);\r\n this.callParent(...arguments);\r\n },\r\n on_revert( doc ){\r\n this.onUndoRedoRevert( doc );\r\n this.callParent(...arguments);\r\n },\r\n\r\n onUndoRedoRevert( doc ) {\r\n const { pages } = doc;\r\n if( this._undoRedoViewTransform.length === pages.length ) {\r\n\r\n // Pages have not change, maintain zoom for them\r\n forEach( pages, (page,k) => {\r\n this.setPageViewTransform( page, this._undoRedoViewTransform[k] );\r\n });\r\n\r\n this.viewTransform = this.pageViewTransform(doc.activePage);\r\n this._undoRedoViewTransform = [];\r\n\r\n this.render$();\r\n }\r\n else {\r\n this.zoomToFitPages$().then(this.render$);\r\n }\r\n },\r\n\r\n});\r\n\r\n\r\nexport const Canvas = StaticCanvas.extend( InteractiveView_Mixin ).extend({\r\n\r\n typeName: 'Canvas',\r\n\r\n Properties: {\r\n\r\n // [TODO] Use conditions\r\n // dblclickContentEditionEnabled: { type: 'function', def(/*figure*/) { return true; } },\r\n },\r\n\r\n createRenderers() {\r\n return [ Plugin.ActiveRenderer() ];\r\n },\r\n\r\n // [TODO] Work in progress to properly separate Static and Interactive Canvas\r\n\r\n insertViewPlugins( plugins ) {\r\n\r\n const renderPlugins = Config.useSpecialPens ? [ Plugin.SpecialPens() ] : [];\r\n\r\n plugins.insert(0,\r\n\r\n renderPlugins.concat( this.createRenderers() ).concat([\r\n\r\n Plugin.ViewControls(),\r\n\r\n Plugin.PluginsLayer(),\r\n\r\n Plugin.AlignmentLines(),\r\n Plugin.FigureAnnotations(),\r\n\r\n Plugin.Tools()\r\n\r\n ]));\r\n }\r\n\r\n});\r\n\n\n\n/** WEBPACK FOOTER **\n ** ./src/ui/canvas/canvas.js\n **/","/* globals THREE */\r\n\r\nimport { Config } from 'config';\r\n\r\nimport { Composition, TextureComposition } from '../view';\r\n\r\nimport { imagePromise } from 'gear';\r\n\r\nimport { Matrix } from 'cdl';\r\n\r\nimport { Canvas } from './canvas';\r\n\r\nimport { Plugin } from '../view';\r\n\r\nfunction createAboveSceneCamera( width, height ) {\r\n return new THREE.OrthographicCamera( -width/2, width/2, height/2, -height/2, 0, 30 );\r\n}\r\n\r\nfunction updateAboveSceneCamera( camera, width, height ) {\r\n camera.left = width / - 2;\r\n camera.right = width / 2;\r\n camera.top = height / 2;\r\n camera.bottom = height / - 2;\r\n camera.updateProjectionMatrix();\r\n}\r\n\r\n// [TODO] Plugin.TextureImage({ textureType: 'normal', src: ... })\r\n\r\nPlugin.NormalMapImage = Plugin.extend({ typeName: 'NormalMapImage',\r\n\r\n target: 'document',\r\n drawTo_normal: [ 'normal' ],\r\n\r\n Properties: {\r\n src: { type: 'string', def: 'texture.jpg' }\r\n },\r\n\r\n initPlugin(view) {\r\n imagePromise(this.src) .then( image => {\r\n this.image = image;\r\n view.redraw('normal');\r\n console.log('loaded');\r\n });\r\n },\r\n\r\n draw({ context, transform }) {\r\n const { image } = this;\r\n if( ! image ) {\r\n return;\r\n }\r\n context.save();\r\n const { canvas } = context;\r\n context.rect( 0, 0, canvas.width, canvas.height);\r\n Matrix.m( transform, Matrix.scale( Config.materialScale || 0.2 ) ).transformContext(context);\r\n context.fillStyle = context.createPattern(image,'repeat');\r\n context.fill();\r\n context.restore();\r\n }\r\n});\r\n\r\nexport const MaterialCanvas = Canvas.extend({ typeName: 'MaterialCanvas',\r\n\r\n Properties: {\r\n\r\n },\r\n\r\n createTextures() {\r\n return [ new TextureComposition({ textureType: 'normal' }),\r\n new TextureComposition({ textureType: 'color' }) ];\r\n },\r\n\r\n createScene() {\r\n return new Composition({ textureType: '3D', main: true });\r\n },\r\n\r\n createRenderers() {\r\n return this.callParent().concat( [ Plugin.NormalMapImage({ src: 'texture-'+ ( Config.material || 1 ) +'.jpg' }),\r\n Plugin.Renderer3D() ]);\r\n },\r\n\r\n init( config = {} ) {\r\n window.canvas = this;\r\n this.callParent(config);\r\n this.initThreeScene();\r\n },\r\n\r\n initThreeScene() {\r\n\r\n const threeScene = this.threeScene = new THREE.Scene();\r\n\r\n const { width, height } = this;\r\n this.camera = createAboveSceneCamera(width,height);\r\n\r\n this.createDrawingSurface();\r\n\r\n const light = this._light = new THREE.HemisphereLight(0xaaaaaa, 0x808080, 0.5);\r\n threeScene.add(light);\r\n light.position.set(200, 200, 300);\r\n\r\n const light3 = new THREE.PointLight( 0xaaaaaa, 0.5 );\r\n light3.position.set( 150, 150, 500 );\r\n threeScene.add(light3);\r\n\r\n const light2 = new THREE.PointLight( 0xaaaaaa, 0.5 );\r\n light2.position.set( 0, 850, 850 );\r\n threeScene.add(light2);\r\n\r\n const clamp = function(v){\r\n const d = 400;\r\n return Math.min(Math.max(v,-d),d);\r\n };\r\n document.addEventListener( 'mousemove', event => {\r\n const { width, height } = this;\r\n const p = this.viewPoint(event);\r\n light2.position.set( clamp( p.x - width/2, 20 ), 850 , 850 + clamp( ( p.y - height / 2 )) );\r\n this.redraw('3D');\r\n }, false );\r\n },\r\n\r\n createDrawingSurface() {\r\n // There is an issue with updating the texture of the plane geometry\r\n // For the prototype, I just recreate the scene but we need to fix this\r\n // to improve performance\r\n this.updateDrawingSurface();\r\n },\r\n\r\n updateDrawingSurface() {\r\n\r\n if( this._documentPlane ){\r\n this.threeScene.remove(this._documentPlane);\r\n this._documentGeometry.dispose();\r\n this._documentMaterial.dispose();\r\n }\r\n\r\n const material = this._documentMaterial = new THREE.MeshPhongMaterial({\r\n\r\n map: this.texture('color').threeTexture,\r\n normalMap: this.texture('normal').threeTexture,\r\n\r\n // color : new THREE.Color(\"rgb(155,196,30)\"),\r\n emissive : new THREE.Color(\"#\"+( Config.emissive || \"222222\" )),\r\n specular : new THREE.Color(\"#\"+( Config.specular || \"888888\" )),\r\n shininess : Config.shininess || 10\r\n });\r\n\r\n material.transparent = true;\r\n\r\n const { width, height } = this.texture('color').composedCanvas;\r\n const planeGeometry = this._documentGeometry = new THREE.PlaneBufferGeometry(width,height);\r\n\r\n const plane = this._documentPlane = new THREE.Mesh( planeGeometry, material );\r\n\r\n console.log(this.height - height);\r\n console.log( width - this.width );\r\n plane.position.set( (width - this.width)/2, -(height - this.height)/2, 0 );\r\n\r\n this.threeScene.add( plane );\r\n },\r\n\r\n on_rendercomplete() {\r\n this.redraw('3D');\r\n this.callParent(...arguments);\r\n },\r\n\r\n updateSize( width, height ) {\r\n this.callParent(width,height);\r\n this.updateDrawingSurface();\r\n\r\n updateAboveSceneCamera(this.camera,this.width,this.height);\r\n },\r\n\r\n draw3D( renderer ) {\r\n console.log('draw 3D');\r\n\r\n renderer.render( this.threeScene, this.camera );\r\n }\r\n});\r\n\n\n\n/** WEBPACK FOOTER **\n ** ./src/ui/canvas/material-canvas.js\n **/"],"sourceRoot":""}