awv3
Version:
AWV client CAD framework
1 lines • 3.93 kB
JavaScript
;function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function parseLine(e,t){var r=(t.models,t.options,e.line),a=r.groups,o=new _three2.default.LineSegments;return o.visible=1===e.visible,o.renderOrder="undefined"!=typeof _defaults2.default.renderOrder.LineSegments?_defaults2.default.renderOrder.LineSegments:100,o.userData={id:0,parentId:e.id,refs:a.map(function(e){return e.meta})},o.geometry=new _three2.default.BufferGeometry,o.geometry.addAttribute("position",new _three2.default.BufferAttribute(r.vertices,3)),o.geometry.groups=[],t.options.lean?(o.material=new _three2.default.LineBasicMaterial({color:new _three2.default.Color(0),opacity:1,transparent:!0,fog:!1}),o.material.parent=o):o.material=new _three2.default.MultiMaterial(a.map(function(e){convertVectors(e.meta),o.geometry.groups.push({start:e.start/3,count:e.count/3,materialIndex:e.index,meta:e.meta});var t=new _three2.default.LineBasicMaterial({color:new _three2.default.Color(0),opacity:1,transparent:!0,fog:!1});return t.meta=e.meta,t.parent=o,t})),finalize(o,e,a)}function parseMesh(e,t){var r=(t.models,t.options,e.mesh),a=r.groups,o=new _three2.default.Mesh;if(o.visible=1===e.visible,o.renderOrder="undefined"!=typeof _defaults2.default.renderOrder.Mesh?_defaults2.default.renderOrder.Mesh:0,o.userData={id:0,parentId:e.id,refs:a.map(function(e){return e.meta})},t.options.lean)o.geometry=new _three2.default.BufferGeometry,o.geometry.addAttribute("position",new _three2.default.BufferAttribute(r.vertices,3)),o.geometry.setIndex(new _three2.default.BufferAttribute(r.indices,1)),r.normals?o.geometry.addAttribute("normal",new _three2.default.BufferAttribute(r.normals,3)):o.geometry.computeVertexNormals(),!!r.uvs&&geometry.addAttribute("uv",new _three2.default.BufferAttribute(r.uvs,2));else{o.geometry=new _three2.default.Geometry;for(var n=0,i=r.vertices.length/3;n<i;n++)o.geometry.vertices.push(new _three2.default.Vector3(r.vertices[3*n+0],r.vertices[3*n+1],r.vertices[3*n+2]));for(var u=0,l=a[u],s=0,d=r.indices.length/3;s<d;s++){!t.options.lean&&l.start+l.count<=3*s&&(l=a[u++]);var f=r.normals?new _three2.default.Vector3(r.normals[3*s+0],r.normals[3*s+1],r.normals[3*s+2]):void 0;o.geometry.faces.push(new _three2.default.Face3(r.indices[3*s+0],r.indices[3*s+1],r.indices[3*s+2],f,(void 0),t.options.lean?void 0:l.index))}r.normals||o.geometry.computeVertexNormals()}return t.options.lean?(o.material=new _phong2.default({color:e.color,opacity:e.opacity,specular:e.color,emissive:new _three2.default.Color(0),shininess:100}),o.material.parent=o):o.material=new _three2.default.MultiMaterial(a.map(function(t){convertVectors(t.meta);var r=new _phong2.default({color:t.color||e.color,opacity:"undefined"!=typeof t.opacity?t.opacity:e.opacity,specular:t.color||e.color,emissive:new _three2.default.Color(0),shininess:100});return r.meta=t.meta,r.parent=o,r})),finalize(o,e,a)}function convertVectors(e){e.box=new _three2.default.Box3(new(Function.prototype.bind.apply(_three2.default.Vector3,[null].concat((0,_toConsumableArray3.default)(e.min)))),new(Function.prototype.bind.apply(_three2.default.Vector3,[null].concat((0,_toConsumableArray3.default)(e.max))))),delete e.min,delete e.max;for(var t in e){var r=e[t];Array.isArray(r)&&3==r.length&&(e[t]=(new _three2.default.Vector3).fromArray(r))}}function finalize(e,t,r){return t.box?(e.geometry.boundingBox=t.box,e.geometry.boundingSphere=t.sphere):(e.geometry.computeBoundingBox(),e.geometry.computeBoundingSphere()),e}exports.__esModule=!0;var _toConsumableArray2=require("babel-runtime/helpers/toConsumableArray"),_toConsumableArray3=_interopRequireDefault(_toConsumableArray2);exports.parseLine=parseLine,exports.parseMesh=parseMesh;var _three=require("three"),_three2=_interopRequireDefault(_three),_phong=require("../materials/phong"),_phong2=_interopRequireDefault(_phong),_defaults=require("../core/defaults"),_defaults2=_interopRequireDefault(_defaults);