UNPKG

awv3

Version:
1 lines 6.92 kB
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function loadImage(e){return e?(e in loadedImagesMap||(loadedImagesMap[e]=new _promise2.default(function(t,r){var n=new _three2.default.TextureLoader;n.load(e,t,void 0,r)})),loadedImagesMap[e]):_promise2.default.reject()}exports.__esModule=!0;var _getOwnPropertyNames=require("babel-runtime/core-js/object/get-own-property-names"),_getOwnPropertyNames2=_interopRequireDefault(_getOwnPropertyNames),_freeze=require("babel-runtime/core-js/object/freeze"),_freeze2=_interopRequireDefault(_freeze),_toConsumableArray2=require("babel-runtime/helpers/toConsumableArray"),_toConsumableArray3=_interopRequireDefault(_toConsumableArray2),_map=require("babel-runtime/core-js/map"),_map2=_interopRequireDefault(_map),_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),_possibleConstructorReturn2=require("babel-runtime/helpers/possibleConstructorReturn"),_possibleConstructorReturn3=_interopRequireDefault(_possibleConstructorReturn2),_inherits2=require("babel-runtime/helpers/inherits"),_inherits3=_interopRequireDefault(_inherits2),_promise=require("babel-runtime/core-js/promise"),_promise2=_interopRequireDefault(_promise),_ccobjects=require("../sketcher/ccobjects"),_sketcher=require("../sketcher/sketcher"),_sketcher2=_interopRequireDefault(_sketcher),_cchelpers=require("../sketcher/cchelpers"),_view=require("../core/view"),_view2=_interopRequireDefault(_view),_three=require("three"),_three2=_interopRequireDefault(_three),loadedImagesMap={},Constraint=function(e){function t(r,n,a){(0,_classCallCheck3.default)(this,t);var s=(0,_possibleConstructorReturn3.default)(this,e.call(this));return _sketcher2.default.mixinPixelSizedGeometry.call(s,s.thickness),s.points=[],r=r||[],s.typename=r[0],s.type=r[1],s.args=n||[],a=a||{},s.expression=a.expression,s.value=a.value,s.fixed=a.fixed,s.mesh=s.interact=new _three2.default.Mesh(new _three2.default.PlaneGeometry(1,1),new _three2.default.MeshBasicMaterial),s.add(s.mesh),s.hide(),s}return(0,_inherits3.default)(t,e),t.prototype.getData=function(){var e=[this.typename,this.type],t=this.args,r={expression:this.expression,value:this.value,fixed:this.fixed};return[e,t,r]},t.prototype.addMember=function(e){switch(_ccobjects.ClassCadObject.prototype.addMember.apply(this,arguments),e.userData.memberInfo.name){case"value":this.value=e.valueOf(),this.expression=e.userData.memberInfo.expression,this.fixed=e.userData.memberInfo.fixed;break;case"entities":this.args=e}},t.prototype.finishedUpdating=function(){this.typename=t.TypeFromCctype.get(this.type),this.loadTexture()},t.prototype.updateMatrixFromMatrixWorld=function(){},t.prototype.loadTexture=function(){function e(){return r.apply(this,arguments)}var r=(0,_asyncToGenerator3.default)(_regenerator2.default.mark(function e(){var r,n,a,s;return _regenerator2.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.TextParameters,n=r.imgPath(this),e.prev=2,e.next=5,loadImage(n);case 5:a=e.sent,this.mesh.material=new _three2.default.MeshBasicMaterial({map:a,polygonOffset:!0,polygonOffsetFactor:-3,polygonOffsetUnits:-15}),e.next=13;break;case 9:e.prev=9,e.t0=e.catch(2),s=new _three2.default.TextGeometry(this.typename,r),this.mesh=this.interact=new _three2.default.Mesh(s,new _three2.default.MeshBasicMaterial({color:r.color}));case 13:case 14:case"end":return e.stop()}},e,this,[[2,9]])}));return e}(),t.prototype.updateGeometry=function(){},t.prototype.show=function(){this.visible=!0},t.prototype.hide=function(){this.visible=!1},t.prototype.hover=function(){this.args.forEach(function(e){e.interact&&e.interact.hover&&e.interact.hover()})},t.prototype.unhover=function(){this.args.forEach(function(e){e.interact&&e.interact.unhover&&e.interact.unhover()})},t.prototype.setGeomSizes=function(e){var t=e[0];this.mesh.scale.set(t,t,t)},t.prototype.getState=function(){var e=this,t=new _map2.default;return["expression","value","fixed"].forEach(function(r){return t.set(r,e[r])}),t},t.prototype.applyStateDiff=function(e){var t=this;["expression","value","fixed"].forEach(function(r){e.has(r)&&(t[r]=e.get(r))})},t.prototype.prepareAddOnServer=function(e){var t=this.args.map(function(t){return e.getAncestorOnSketch(t)});return _cchelpers.Statement.JSONExport.apply(_cchelpers.Statement,[_cchelpers.Expression.AddConstraint(e,this.typename,this.type,this.args,this.expression,this.value,this.fixed)].concat((0,_toConsumableArray3.default)(t))).then(_cchelpers.parseTo.apply(void 0,[this].concat((0,_toConsumableArray3.default)(t))))},t.prototype.prepareUpdateToServer=function(e){var t=this.args.map(function(t){return e.getAncestorOnSketch(t)});return _cchelpers.Statement.JSONExport.apply(_cchelpers.Statement,[_cchelpers.Expression.UpdateConstraint(e,this,this.args,this.expression,this.value,this.fixed)].concat((0,_toConsumableArray3.default)(t))).then(_cchelpers.parseTo.apply(void 0,[this].concat((0,_toConsumableArray3.default)(t))))},t.prototype.prepareRemoveOnServer=function(e){return _cchelpers.Statement.Return(_cchelpers.Expression.RemoveConstraint(e,this))},t}(_ccobjects.ClassCadObject);exports.default=Constraint,Constraint.TextParameters={color:48896,size:1,height:1,font:"droid sans",weight:"normal",style:"normal",imgPath:function(e){}},Constraint.Type=(0,_freeze2.default)({FIXATION:["FIXATION","CC_2DFixationConstraint"],INCIDENCE:["INCIDENCE","CC_2DCoincidentConstraint"],DISTANCE:["DISTANCE","CC_2DOffsetConstraint"],ANGLE:["ANGLE","CC_2DAngleConstraint"],ANGLEOX:["ANGLEOX","CC_2DAngleOXConstraint"],TANGENCY:["TANGENCY","CC_2DTangentSketchConstraint"],HORIZONTALITY:["HORIZONTALITY","CC_2DHorizontalConstraint"],VERTICALITY:["VERTICALITY","CC_2DVerticalConstraint"],PERPENDICULARITY:["PERPENDICULARITY","CC_2DPerpendicularConstraint"],PARALLELITY:["PARALLELITY","CC_2DParallelConstraint"],CONCENTRIC:["CONCENTRIC","CC_2DConcentricConstraint"],MIDPOINT:["MIDPOINT","CC_2DMidpointConstraint"],SYMMETRIC:["SYMMETRIC","CC_2DSymmetryConstraint"],COLINEAR:["COLINEAR","CC_2DColinearConstraint"],EQUAL_DISTANCE:["EQUAL_DISTANCE","CC_2DEqualLengthConstraint"],RADIUS:["RADIUS","CC_2DRadiusConstraint"],EQUAL_RADIUS:["EQUAL_RADIUS","CC_2DEqualRadiusConstraint"],HORIZONTAL_DISTANCE:["HORIZONTAL_DISTANCE","CC_2DHorizontalDistanceConstraint"],VERTICAL_DISTANCE:["VERTICAL_DISTANCE","CC_2DVerticalDistanceConstraint"]}),Constraint.TypeFromCctype=new _map2.default,(0,_getOwnPropertyNames2.default)(Constraint.Type).forEach(function(e){var t=Constraint.Type[e][1];void 0!==t&&(Constraint.TypeFromCctype.set(t,e),_ccobjects.ClassCadObject.classMapping[t]=Constraint)}),Constraint.prototype.thickness=16;