awv3
Version:
⚡ AWV3 embedded CAD
9 lines • 6.28 kB
JavaScript
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var _getOwnPropertyNames=require('babel-runtime/core-js/object/get-own-property-names'),_getOwnPropertyNames2=_interopRequireDefault(_getOwnPropertyNames),_map=require('babel-runtime/core-js/map'),_map2=_interopRequireDefault(_map),_freeze=require('babel-runtime/core-js/object/freeze'),_freeze2=_interopRequireDefault(_freeze),_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),_promise=require('babel-runtime/core-js/promise'),_promise2=_interopRequireDefault(_promise),_sketcher=require('../sketcher'),_sketcher2=_interopRequireDefault(_sketcher),_expressions=require('./expressions'),_three=require('three'),THREE=_interopRequireWildcard(_three);function _interopRequireWildcard(obj){if(obj&&obj.__esModule)return obj;var newObj={};if(null!=obj)for(var key in obj)Object.prototype.hasOwnProperty.call(obj,key)&&(newObj[key]=obj[key]);return newObj.default=obj,newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}//asynchronous and caching image loader
var loadedImagesMap={};function loadImage(b){return b?(b in loadedImagesMap||(loadedImagesMap[b]=new _promise2.default(function(c,d){var e=new THREE.TextureLoader;e.load(b,c,void 0,d)})),loadedImagesMap[b]):_promise2.default.reject()}/*
* Constraint - a Javascript representation of LGS 2D constraint
* optional attributes: expression: string, value: number, fixed: boolean
*/var Constraint=function(){function Constraint(b,c,d){(0,_classCallCheck3.default)(this,Constraint),this.points=[],b=b||[],this.typename=b[0],this.type=b[1],this.args=c||[],d=d||{},this.expression=d.expression,this.value=d.value,this.fixed=d.fixed,this.mesh=this.interact=new THREE.Mesh(new THREE.PlaneGeometry(1,1),new THREE.MeshBasicMaterial()),this.add(this.mesh),this.hide()}return(0,_createClass3.default)(Constraint,[{key:'getData',value:function getData(){var b=[this.typename,this.type],c=this.args,d={expression:this.expression,value:this.value,fixed:this.fixed};return[b,c,d]}},{key:'updateMatrixFromMatrixWorld',value:function updateMatrixFromMatrixWorld(){// constraints don't have a sane coordinate system on the server, so ignore it
}},{key:'loadTexture',value:function(){function loadTexture(){return _ref.apply(this,arguments)}var _ref=(0,_asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(){var b,c,d,e;return _regenerator2.default.wrap(function _callee$(_context){for(;1;)switch(_context.prev=_context.next){case 0:return b=Constraint.TextParameters,c=b.imgPath(this),_context.prev=1,_context.next=4,loadImage(c);case 4:d=_context.sent,this.mesh.material=new THREE.MeshBasicMaterial({map:d,polygonOffset:!0,polygonOffsetFactor:-3,polygonOffsetUnits:-15}),_context.next=12;break;case 8:_context.prev=8,_context.t0=_context['catch'](1),e=new THREE.TextGeometry(this.typename,b),this.mesh=this.interact=new THREE.Mesh(e,new THREE.MeshBasicMaterial({color:b.color}));case 12:case'end':return _context.stop();}},_callee,this,[[1,8]])}));return loadTexture}()},{key:'updateGeometry',value:function updateGeometry(){}},{key:'show',value:function show(){this.visible=!0}},{key:'hide',value:function hide(){this.visible=!1}},{key:'hover',value:function hover(){this.args.forEach(function(b){b.interact&&b.interact.hover&&b.interact.hover()})}},{key:'unhover',value:function unhover(){this.args.forEach(function(b){b.interact&&b.interact.unhover&&b.interact.unhover()})}//required method for updateSizes
},{key:'setGeomSizes',value:function setGeomSizes(b){var c=b[0];this.mesh.scale.set(c,c,c)}},{key:'prepareAddOnServer',value:function prepareAddOnServer(b){return this.args.map(function(c){return b.getAncestorOnSketch(c)}),(0,_expressions.Return)((0,_expressions.AddConstraint)(b,this.typename,this.type,this.args,this.expression,this.value,this.fixed))}},{key:'prepareUpdateToServer',value:function prepareUpdateToServer(b){return this.args.map(function(c){return b.getAncestorOnSketch(c)}),(0,_expressions.Return)((0,_expressions.UpdateConstraint)(b,this,this.args,this.expression,this.value,this.fixed))}},{key:'prepareRemoveOnServer',value:function prepareRemoveOnServer(b){return(0,_expressions.Return)((0,_expressions.RemoveConstraint)(b,this))}}]),Constraint}();// Default parameters for displaying constraints. See THREE.TextGeometry for explanation.
exports.default=Constraint;Constraint.TextParameters={color:48896,size:1,height:1,font:'droid sans',weight:'normal',style:'normal',imgPath:function imgPath(){/*return "path/to/img.png";*/}},Constraint.Type=(0,_freeze2.default)({// type: [typename, ClassCad type]
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(b){var c=Constraint.Type[b][1];c!==void 0&&Constraint.TypeFromCctype.set(c,b)}),Constraint.prototype.thickness=16;