UNPKG

awv3

Version:
1 lines 17.6 kB
"use strict";function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function transformWorldToScreen(e,t,r,n){r instanceof _three2.default.Object3D&&(r.updateMatrixWorld(),r=r.matrixWorld),r instanceof _three2.default.Matrix4||(r=new _three2.default.Matrix4),e.camera.updateMatrixWorld();var o=new _three2.default.Matrix4;o.getInverse(e.camera.matrixWorld),o.multiplyMatrices(o,r),o.multiplyMatrices(e.camera.projectionMatrix,o);var i=(new _three2.default.Vector4).copy(t).applyMatrix4(o),s=1/i.w,a=(new _three2.default.Vector3).copy(i).multiplyScalar(s),c=new _three2.default.Matrix4;if(n){var u=new _three2.default.Matrix4;u.set(s,0,0,-i.x*s*s,0,s,0,-i.y*s*s,0,0,s,-i.z*s*s,0,0,0,0),c.multiplyMatrices(u,o)}var l=e.dom.clientWidth/2,h=e.dom.clientHeight/2,p=l,d=-h,f=l,_=h,m={};if(m.position=new _three2.default.Vector2,m.position.x=a.x*p+f,m.position.y=a.y*d+_,n){var v=m.derivatives=[],k=c.elements;v.push(new _three2.default.Vector2(p*k[0],d*k[1])),v.push(new _three2.default.Vector2(p*k[4],d*k[5])),v.push(new _three2.default.Vector2(p*k[8],d*k[9]))}return m}function calculateWorldToScreenRadiusMultiplier(e){var t=e.derivatives,r=(new _three2.default.Vector3).set(t[0].x,t[1].x,t[2].x),n=(new _three2.default.Vector3).set(t[0].y,t[1].y,t[2].y),o=r.lengthSq(),i=n.lengthSq(),s=r.dot(n),a=(o+i)/2,c=(o-i)/2,u=c*c+s*s,l=a+Math.sqrt(Math.max(u,0));return Math.sqrt(Math.max(l,0))}function updateSizesAndVisualization(){_sketch2.default.ForObjectsWithChildren(this,function(e){e&&(e.updateSizes&&e.view&&e.updateSizes(e.view),e.updateVisualization&&e.updateVisualization())})}exports.__esModule=!0;var _map=require("babel-runtime/core-js/map"),_map2=_interopRequireDefault(_map),_getPrototypeOf=require("babel-runtime/core-js/object/get-prototype-of"),_getPrototypeOf2=_interopRequireDefault(_getPrototypeOf),_regenerator=require("babel-runtime/regenerator"),_regenerator2=_interopRequireDefault(_regenerator),_asyncToGenerator2=require("babel-runtime/helpers/asyncToGenerator"),_asyncToGenerator3=_interopRequireDefault(_asyncToGenerator2),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_possibleConstructorReturn2=require("babel-runtime/helpers/possibleConstructorReturn"),_possibleConstructorReturn3=_interopRequireDefault(_possibleConstructorReturn2),_inherits2=require("babel-runtime/helpers/inherits"),_inherits3=_interopRequireDefault(_inherits2),_cchelpers=require("sketcher/cchelpers"),_constraintgen=require("sketcher/constraintgen"),_sketch=require("sketcher/sketch"),_sketch2=_interopRequireDefault(_sketch),_constraint=require("sketcher/constraint"),_constraint2=_interopRequireDefault(_constraint),_controls=require("sketcher/controls"),Controls=_interopRequireWildcard(_controls),_geomobjects=require("sketcher/geomobjects"),_orbit=require("controls/orbit"),_orbit2=_interopRequireDefault(_orbit),_plugin=require("core/plugin"),_plugin2=_interopRequireDefault(_plugin),_object=require("three/object3"),_object2=_interopRequireDefault(_object),_three=require("three"),_three2=_interopRequireDefault(_three),_droid_sans_regularTypeface=require("json!../../node_modules/three/examples/fonts/droid/droid_sans_regular.typeface.json"),_droid_sans_regularTypeface2=_interopRequireDefault(_droid_sans_regularTypeface),_helpers=require("core/helpers"),_unittests=require("sketcher/unittests"),_unittests2=_interopRequireDefault(_unittests),CursorPosition=function(e){function t(r){(0,_classCallCheck3.default)(this,t);var n=(0,_possibleConstructorReturn3.default)(this,e.call(this));return n._x=n._y=0,n.notifier=r,n}return(0,_inherits3.default)(t,e),t.prototype.set=function(e,t){this._x=e,this._y=t,this.notifier()},t.prototype.copy=function(e){this.set(e.x,e.y)},t.prototype.clone=function(){return new _three2.default.Vector3(this.x,this.y,this.z)},(0,_createClass3.default)(t,[{key:"x",get:function(){return this._x}},{key:"y",get:function(){return this._y}},{key:"z",get:function(){return 0}}]),t}(_three2.default.Vector3),Sketcher=function(e){function t(r){(0,_classCallCheck3.default)(this,t);var n=(0,_possibleConstructorReturn3.default)(this,e.call(this,r));n.currentSketch=null,n.options.view.scene.add(n),n.__parentView=n.options.view,n.__sketchControlsHandler=null;var o=new _three2.default.FontLoader;n.font=o.parse(_droid_sans_regularTypeface2.default),_constraint2.default.TextParameters.font=n.font,n.modelData={isSketchSelected:!1,promptText:"",isConstraintFormVisible:!1,constraintExpression:"",constraintValue:0,constraintFixed:!0,get constraint(){return{expression:this.constraintExpression,value:this.constraintValue,fixed:this.constraintFixed}},set constraint(e){this.constraintExpression=e.expression,this.constraintValue=e.value,this.constraintFixed=e.fixed},acceptConstraint:function(){},declineConstraint:function(){},_incrementalLevel:!1,expressionSet:[],isHiddenVisible:!1,previousInteractionPoint:new _three2.default.Vector3,interactionPoint:new CursorPosition(n.interactionPointMoved.bind(n)),autoconstraintIncremental:!0,consoleText:""};var i=n;return Object.defineProperty(n.modelData,"incrementalLevel",{enumerable:!0,configurable:!0,get:function(){return this._incrementalLevel},set:function(e){i.setIncrementalLevel(e)}}),n.modelMethods={addExpression:function(){this.expressionSet.push({name:"",value:0,expression:"",fixed:!0,visible:!0})},removeExpression:function(e){var t=this.expressionSet.indexOf(e);t!==-1&&this.expressionSet.splice(t,1)},resetExpressionSet:function(){(0,_cchelpers.trackPromise)(i.currentSketch.updateFromServer(i.server))},submitExpressionSet:function(){var e=this,t=this.expressionSet.map(function(e){return[e.name,e.value,e.expression,e.fixed]}),r=_cchelpers.Interop.UpdateExpressionSet(i.currentSketch,t).execute(i.server);this.incrementalLevel&&(r=r.then(function(){return e.solveConstraints()})),(0,_cchelpers.trackPromise)(r)},chooseTool:n.chooseTool.bind(n),deselectSketch:n.deselectSketch.bind(n),deleteSketch:n.deleteSketch.bind(n),buttonClick:n.buttonClick.bind(n),click:n.click.bind(n),undo:n.undo.bind(n),redo:n.redo.bind(n),solveConstraints:n.solveConstraints.bind(n),autoconstraintAll:n.autoconstraintAll.bind(n),consoleExecute:function(){var e=this.consoleText;if(this.consoleText="",i.__sketchControlsHandler)return i.__sketchControlsHandler.consoleExecute(e)},consoleFocus:function(){r.consoleElement&&r.consoleElement.focus()},runAllTests:function(){(0,_unittests2.default)(i)}},n}return(0,_inherits3.default)(t,e),t.prototype.refresh=function(){this.__parentView.invalidate()},t.prototype.sketchAreaClicked=function(){function e(e){return t.apply(this,arguments)}var t=(0,_asyncToGenerator3.default)(_regenerator2.default.mark(function e(t){return _regenerator2.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.currentSketch===t){e.next=4;break}return e.next=3,this.selectSketch(t);case 3:return e.abrupt("return");case 4:return e.next=6,this.click();case 6:case"end":return e.stop()}},e,this)}));return e}(),t.prototype.sketchAreaRightClicked=function(){function e(e){return t.apply(this,arguments)}var t=(0,_asyncToGenerator3.default)(_regenerator2.default.mark(function e(t){var r,n;return _regenerator2.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t===this.currentSketch){e.next=2;break}return e.abrupt("return");case 2:return r=(0,_getPrototypeOf2.default)(this.__sketchControlsHandler),e.next=5,this.chooseTool("empty");case 5:if(n=(0,_getPrototypeOf2.default)(this.__sketchControlsHandler),r!==n){e.next=9;break}return e.next=9,this.deselectSketch();case 9:case"end":return e.stop()}},e,this)}));return e}(),t.prototype.setActionCursor=function(e){var t=new _map2.default([["empty","default"],["delete","no-drop"],["point","crosshair"],["line","crosshair"],["arc","crosshair"],["polyline","crosshair"],["fixation","default"],["incidence","default"],["distance","default"],["angle","default"],["angleOX","default"],["tangency","default"],["horizontality","default"],["verticality","default"],["perpendicularity","default"],["parallelity","default"],["concentric","default"],["midpoint","default"],["symmetric","default"],["colinear","default"],["equal_distance","default"],["radius","default"],["equal_radius","default"],["horizontal_distance","default"],["vertical_distance","default"],["autoconstraint","default"]]),r=this.__parentView;void 0===e&&this.currentCursor?r.setCursor(this.currentCursor):t.has(e)?(this.currentCursor=t.get(e),r.setCursor(this.currentCursor)):this.currentCursor=null},t.prototype.chooseTool=function(e){if(this.setActionCursor(e),e){"empty"===e&&this.modelData.incrementalLevel&&this.currentSketch.solveConstraints();var t=Controls[e+"Handler"];if(void 0===t)return}return this.__sketchControlsHandler instanceof Controls.polylineHandler&&e&&(e.startsWith("line")||e.startsWith("arc"))?this.__sketchControlsHandler.changeEdgeType(e):(this.__sketchControlsHandler&&this.__sketchControlsHandler.finish(),void(e?this.__sketchControlsHandler=new t(this):this.__sketchControlsHandler=null))},t.prototype.solveConstraints=function(){function e(){return t.apply(this,arguments)}var t=(0,_asyncToGenerator3.default)(_regenerator2.default.mark(function e(){var t;return _regenerator2.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.currentSketch){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,this.currentSketch.solveConstraints();case 4:t=e.sent;case 5:case"end":return e.stop()}},e,this)}));return e}(),t.prototype.setIncrementalLevel=function(){function e(e){return t.apply(this,arguments)}var t=(0,_asyncToGenerator3.default)(_regenerator2.default.mark(function e(t){return _regenerator2.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.modelData._incrementalLevel=t,!t){e.next=4;break}return e.next=4,this.solveConstraints();case 4:case"end":return e.stop()}},e,this)}));return e}(),t.prototype.autoconstraintAll=function(){var e=new _constraintgen.ConstraintGenerator(this.currentSketch),t=e.generateImpliedConstraints();(0,_cchelpers.trackPromise)(this.currentSketch.addToSketch(t,{updateSketch:!0}))},t.prototype.moveUnderConstraints=function(e,t){function r(e){this.sketchStates[1]=this.sketchStates[0],this.sketchStates[0]=this.currentSketch.getState(),this.stateDiff=this.currentSketch.getStateLinearContinuation(this.sketchStates)}function n(){this.mouseStates[1]=this.mouseStates[0],this.mouseStates[0]=t}function o(e){var t=_sketch2.default.ForObjectsWithChildren(e);return t=t.filter(function(e){return e instanceof _geomobjects.Point})}var i=this;if(this.currentSketch){var s=o(e);if(!this.currentSketch.solveInProgress){this.currentSketch.solveInProgress=!0,n.call(this);var a=this.mouseStates[0].clone().sub(this.mouseStates[1]);if(a.length()>0){_cchelpers.logLevel>=5&&console.log(_helpers.Timestamp.get(),"MUC solve");var c=[_cchelpers.Interop.MoveObjects(this.currentSketch,this.movedObject,a)],u=this.currentSketch.updateFromServer(this.server,c).then(function(){r.call(i,s),i.currentSketch.solveInProgress=!1}).catch(function(){i.currentSketch.solveInProgress=!1});(0,_cchelpers.trackPromise)(u)}else this.currentSketch.solveInProgress=!1}}},t.prototype.newSketch=function(e,t,r){var n=[new _three2.default.Vector3(1,0,0),new _three2.default.Vector3(0,1,0),new _three2.default.Vector3(0,0,1)];n.forEach(function(e){return e.applyQuaternion(t)}),n.unshift(e);var o=_sketch2.default.FindSketchSetOf(r);return _cchelpers.Interop.AddSketch(r,n).parseToChildOf(o).execute(this.server)},t.prototype.newSketchFromPlane=function(e){var t=_sketch2.default.FindSketchSetOf(e);return _cchelpers.Interop.AddSketchFromPlane(e).parseToChildOf(t).execute(this.server)},t.prototype.deleteSketch=function(){var e=this;if(confirm("Do you really want to irreversibly delete current sketch and all its contents?")){var t=this.currentSketch;if(t)return this.deselectSketch({skipServerCalls:!0}),t.__box.removeInteraction(),(0,_cchelpers.trackPromise)(_cchelpers.Interop.RemoveSketch(t).execute(this.server).then(function(){t.parent&&t.parent.remove(t),e.refresh()}))}},t.prototype.switchToOrthographicCamera=function(e,t){e.perspectiveControls=e.controls,e.camera=new _three2.default.OrthographicCamera(0,1,1,0),t.localToWorld(e.camera.position.set(0,0,1e3)),e.camera.up.transformDirection(t.matrixWorld),e.camera.size=1,e.controls=e.controls.clone(),e.controls.noRotate=!0,e.controls.zoomMode=_orbit2.default.ZoomMode.Mouse,e.controls.focus(t).zoom(200).now()},t.prototype.switchToPerspectiveCamera=function(e){e.controls=e.perspectiveControls,e.camera=e.controls.camera,e.perspectiveControls=void 0},t.prototype.requestAllButtonChanges=function(e){for(var t=[],r=["incidence","tangency","verticality","horizontality","parallelity","perpendicularity","fixation","colinear","concentric","midpoint","symmetric","equal_distance","equal_radius","distance","horizontal_distance","vertical_distance","radius","angle","angleox"],n=0;n<r.length;n++){var o=r[n];t.push({id:"chooseTool "+o,show:e,name:o.replace("_"," "),group:"constraints",order:t.length})}this.requestButtonChanges(t)},t.prototype.selectSketch=function(){function e(e){return t.apply(this,arguments)}var t=(0,_asyncToGenerator3.default)(_regenerator2.default.mark(function e(t){var r;return _regenerator2.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.currentSketch!==t){e.next=2;break}return e.abrupt("return",!0);case 2:return e.next=4,this.deselectSketch();case 4:if(e.sent){e.next=6;break}return e.abrupt("return",!1);case 6:return this.currentSketch=t,this.modelData.isSketchSelected=!0,this.modelData.expressionSet=t.getPart().members.ExpressionSet.modelData,t.showBox(),t.infiniteBox(),this.switchToOrthographicCamera(this.__parentView,t),this.requestAllButtonChanges(!0),e.next=15,t.updateFromServer(this.server);case 15:return e.next=17,this.chooseTool("empty");case 17:return this.refresh(),this.currentSketch.showGrid(),this.currentSketch.showDimensions(),r=t.getPart().item,r&&r.materials&&r.materials.all&&r.materials.all.forEach(function(e){e.transparent=!0,e.opacity=t.chosenItemOpacity}),e.abrupt("return",!0);case 23:case"end":return e.stop()}},e,this)}));return e}(),t.prototype.deselectSketch=function(){function e(e){return t.apply(this,arguments)}var t=(0,_asyncToGenerator3.default)(_regenerator2.default.mark(function e(t){var r,n;return _regenerator2.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(null!==this.currentSketch){e.next=2;break}return e.abrupt("return",!0);case 2:return r=this.currentSketch.getPart().item,r&&r.materials&&r.materials.all&&r.materials.all.forEach(function(e){e.opacity=1,e.transparent=!1}),this.switchToPerspectiveCamera(this.__parentView),this.requestAllButtonChanges(!1),e.next=8,this.chooseTool(null);case 8:if(this.currentSketch.hideGrid(),this.currentSketch.hideDimensions(),this.currentSketch.hideConstraints(),n=this.currentSketch,t=t||{},t.skipServerCalls){e.next=18;break}return e.next=16,_cchelpers.Interop.Recalc(n).execute(this.server);case 16:return e.next=18,n.updateFromServer(this.server);case 18:return this.currentSketch.updateBox(),this.currentSketch=null,this.modelData.isSketchSelected=!1,this.modelData.expressionSet=[],this.refresh(),e.abrupt("return",!0);case 24:case"end":return e.stop()}},e,this)}));return e}(),t.prototype.buttonClick=function(e){var t=e.split(" ");"chooseTool"===t[0]&&this.chooseTool(t[1])},t.prototype.click=function(){return this.__sketchControlsHandler.click(this.modelData.interactionPoint.clone())},t.prototype.interactionPointMoved=function(){this.__sketchControlsHandler&&this.__sketchControlsHandler.mouseMove(this.modelData.interactionPoint.clone())},t.prototype.undo=function(){},t.prototype.redo=function(){},t.prototype.setPrompt=function(e){this.modelData.promptText=e},t.prototype.askConstraintParams=function(){function e(e){return t.apply(this,arguments)}var t=(0,_asyncToGenerator3.default)(_regenerator2.default.mark(function e(t){var r;return _regenerator2.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.requestModal({title:"Constraint parameters",elements:[{name:"expression",type:"text",value:t.expression},{name:"value",type:"number",value:t.value},{name:"fixed",type:"checkbox",value:t.fixed}]});case 2:return r=e.sent,e.abrupt("return",{expression:r[0].value,value:Number(r[1].value),fixed:r[2].value});case 4:case"end":return e.stop()}},e,this)}));return e}(),t.registerVisualization=function(e,t){var r;t.createInteraction({priority:-1e4}).on((r={},r[_object2.default.Events.Lifecycle.Rendered]=updateSizesAndVisualization,r))},t.mixinPixelSizedGeometry=function(e){return this instanceof _three2.default.Object3D?this.setGeomSizes?(e||(e=1),this.pixelSizes=[].concat(e),this.getSizingPoint||(this.getSizingPoint=function(){return new _three2.default.Vector3}),void(this.updateSizes=function(e){for(var t=this.getSizingPoint(),r=transformWorldToScreen(e,t,this,!0),n=1/calculateWorldToScreenRadiusMultiplier(r),o=this.pixelSizes.slice(0),i=0,s=o.length;i<s;i++)o[i]=o[i]*n;this.setGeomSizes(o)})):void console.warn("PixelSizedGeometry: missing required methods"):void console.warn("PixelSizedGeometry: not a THREE object")},(0,_createClass3.default)(t,[{key:"server",get:function(){return this.socket},set:function(e){this.socket=e}}]),t}(_plugin2.default);exports.default=Sketcher;