THREE.MeshLine.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. function MeshLine_plugin() {
  2. ;(function () {
  3. "use strict";
  4. var root = this
  5. var has_require = typeof require !== 'undefined'
  6. var THREE = root.IV.THREE || has_require && require('three')
  7. if (!THREE)
  8. throw new Error('MeshLine requires three.js')
  9. function MeshLine() {
  10. this.positions = [];
  11. this.previous = [];
  12. this.next = [];
  13. this.side = [];
  14. this.width = [];
  15. this.indices_array = [];
  16. this.uvs = [];
  17. this.counters = [];
  18. this.geometry = new THREE.BufferGeometry();
  19. this.widthCallback = null;
  20. // Used to raycast
  21. this.matrixWorld = new THREE.Matrix4();
  22. }
  23. MeshLine.prototype.setMatrixWorld = function (matrixWorld) {
  24. this.matrixWorld = matrixWorld;
  25. }
  26. MeshLine.prototype.setGeometry = function (g, c) {
  27. this.widthCallback = c;
  28. this.positions = [];
  29. this.counters = [];
  30. // g.computeBoundingBox();
  31. // g.computeBoundingSphere();
  32. // set the normals
  33. // g.computeVertexNormals();
  34. if (g instanceof THREE.Geometry) {
  35. for (var j = 0; j < g.vertices.length; j++) {
  36. var v = g.vertices[j];
  37. var c = j / g.vertices.length;
  38. this.positions.push(v.x, v.y, v.z);
  39. this.positions.push(v.x, v.y, v.z);
  40. this.counters.push(c);
  41. this.counters.push(c);
  42. }
  43. }
  44. if (g instanceof THREE.BufferGeometry) {
  45. // read attribute positions ?
  46. }
  47. if (g instanceof Float32Array || g instanceof Array) {
  48. for (var j = 0; j < g.length; j += 3) {
  49. var c = j / g.length;
  50. this.positions.push(g[j], g[j + 1], g[j + 2]);
  51. this.positions.push(g[j], g[j + 1], g[j + 2]);
  52. this.counters.push(c);
  53. this.counters.push(c);
  54. }
  55. }
  56. this.process();
  57. }
  58. MeshLine.prototype.raycast = (function () {
  59. var inverseMatrix = new THREE.Matrix4();
  60. var ray = new THREE.Ray();
  61. var sphere = new THREE.Sphere();
  62. return function raycast(raycaster, intersects) {
  63. var precision = raycaster.linePrecision;
  64. var precisionSq = precision * precision;
  65. var geometry = this.geometry;
  66. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  67. // Checking boundingSphere distance to ray
  68. sphere.copy(geometry.boundingSphere);
  69. sphere.applyMatrix4(this.matrixWorld);
  70. if (raycaster.ray.intersectSphere(sphere) === false) {
  71. return;
  72. }
  73. inverseMatrix.getInverse(this.matrixWorld);
  74. ray.copy(raycaster.ray).applyMatrix4(inverseMatrix);
  75. var vStart = new THREE.Vector3();
  76. var vEnd = new THREE.Vector3();
  77. var interSegment = new THREE.Vector3();
  78. var interRay = new THREE.Vector3();
  79. var step = this instanceof THREE.LineSegments ? 2 : 1;
  80. if (geometry instanceof THREE.BufferGeometry) {
  81. var index = geometry.index;
  82. var attributes = geometry.attributes;
  83. if (index !== null) {
  84. var indices = index.array;
  85. var positions = attributes.position.array;
  86. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  87. var a = indices[i];
  88. var b = indices[i + 1];
  89. vStart.fromArray(positions, a * 3);
  90. vEnd.fromArray(positions, b * 3);
  91. var distSq = ray.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  92. if (distSq > precisionSq) continue;
  93. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  94. var distance = raycaster.ray.origin.distanceTo(interRay);
  95. if (distance < raycaster.near || distance > raycaster.far) continue;
  96. intersects.push({
  97. distance: distance,
  98. // What do we want? intersection point on the ray or on the segment??
  99. // point: raycaster.ray.at( distance ),
  100. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  101. index: i,
  102. face: null,
  103. faceIndex: null,
  104. object: this
  105. });
  106. }
  107. } else {
  108. var positions = attributes.position.array;
  109. for (var i = 0, l = positions.length / 3 - 1; i < l; i += step) {
  110. vStart.fromArray(positions, 3 * i);
  111. vEnd.fromArray(positions, 3 * i + 3);
  112. var distSq = ray.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  113. if (distSq > precisionSq) continue;
  114. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  115. var distance = raycaster.ray.origin.distanceTo(interRay);
  116. if (distance < raycaster.near || distance > raycaster.far) continue;
  117. intersects.push({
  118. distance: distance,
  119. // What do we want? intersection point on the ray or on the segment??
  120. // point: raycaster.ray.at( distance ),
  121. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  122. index: i,
  123. face: null,
  124. faceIndex: null,
  125. object: this
  126. });
  127. }
  128. }
  129. } else if (geometry instanceof THREE.Geometry) {
  130. var vertices = geometry.vertices;
  131. var nbVertices = vertices.length;
  132. for (var i = 0; i < nbVertices - 1; i += step) {
  133. var distSq = ray.distanceSqToSegment(vertices[i], vertices[i + 1], interRay, interSegment);
  134. if (distSq > precisionSq) continue;
  135. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  136. var distance = raycaster.ray.origin.distanceTo(interRay);
  137. if (distance < raycaster.near || distance > raycaster.far) continue;
  138. intersects.push({
  139. distance: distance,
  140. // What do we want? intersection point on the ray or on the segment??
  141. // point: raycaster.ray.at( distance ),
  142. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  143. index: i,
  144. face: null,
  145. faceIndex: null,
  146. object: this
  147. });
  148. }
  149. }
  150. };
  151. }());
  152. MeshLine.prototype.compareV3 = function (a, b) {
  153. var aa = a * 6;
  154. var ab = b * 6;
  155. return (this.positions[aa] === this.positions[ab]) && (this.positions[aa + 1] === this.positions[ab + 1]) && (this.positions[aa + 2] === this.positions[ab + 2]);
  156. }
  157. MeshLine.prototype.copyV3 = function (a) {
  158. var aa = a * 6;
  159. return [this.positions[aa], this.positions[aa + 1], this.positions[aa + 2]];
  160. }
  161. MeshLine.prototype.process = function () {
  162. var l = this.positions.length / 6;
  163. this.previous = [];
  164. this.next = [];
  165. this.side = [];
  166. this.width = [];
  167. this.indices_array = [];
  168. this.uvs = [];
  169. for (var j = 0; j < l; j++) {
  170. this.side.push(1);
  171. this.side.push(-1);
  172. }
  173. var w;
  174. for (var j = 0; j < l; j++) {
  175. if (this.widthCallback) w = this.widthCallback(j / (l - 1));
  176. else w = 1;
  177. this.width.push(w);
  178. this.width.push(w);
  179. }
  180. for (var j = 0; j < l; j++) {
  181. this.uvs.push(j / (l - 1), 0);
  182. this.uvs.push(j / (l - 1), 1);
  183. }
  184. var v;
  185. if (this.compareV3(0, l - 1)) {
  186. v = this.copyV3(l - 2);
  187. } else {
  188. v = this.copyV3(0);
  189. }
  190. this.previous.push(v[0], v[1], v[2]);
  191. this.previous.push(v[0], v[1], v[2]);
  192. for (var j = 0; j < l - 1; j++) {
  193. v = this.copyV3(j);
  194. this.previous.push(v[0], v[1], v[2]);
  195. this.previous.push(v[0], v[1], v[2]);
  196. }
  197. for (var j = 1; j < l; j++) {
  198. v = this.copyV3(j);
  199. this.next.push(v[0], v[1], v[2]);
  200. this.next.push(v[0], v[1], v[2]);
  201. }
  202. if (this.compareV3(l - 1, 0)) {
  203. v = this.copyV3(1);
  204. } else {
  205. v = this.copyV3(l - 1);
  206. }
  207. this.next.push(v[0], v[1], v[2]);
  208. this.next.push(v[0], v[1], v[2]);
  209. for (var j = 0; j < l - 1; j++) {
  210. var n = j * 2;
  211. this.indices_array.push(n, n + 1, n + 2);
  212. this.indices_array.push(n + 2, n + 1, n + 3);
  213. }
  214. if (!this.attributes) {
  215. this.attributes = {
  216. position: new THREE.BufferAttribute(new Float32Array(this.positions), 3),
  217. previous: new THREE.BufferAttribute(new Float32Array(this.previous), 3),
  218. next: new THREE.BufferAttribute(new Float32Array(this.next), 3),
  219. side: new THREE.BufferAttribute(new Float32Array(this.side), 1),
  220. width: new THREE.BufferAttribute(new Float32Array(this.width), 1),
  221. uv: new THREE.BufferAttribute(new Float32Array(this.uvs), 2),
  222. index: new THREE.BufferAttribute(new Uint16Array(this.indices_array), 1),
  223. counters: new THREE.BufferAttribute(new Float32Array(this.counters), 1)
  224. }
  225. } else {
  226. this.attributes.position.copyArray(new Float32Array(this.positions));
  227. this.attributes.position.needsUpdate = true;
  228. this.attributes.previous.copyArray(new Float32Array(this.previous));
  229. this.attributes.previous.needsUpdate = true;
  230. this.attributes.next.copyArray(new Float32Array(this.next));
  231. this.attributes.next.needsUpdate = true;
  232. this.attributes.side.copyArray(new Float32Array(this.side));
  233. this.attributes.side.needsUpdate = true;
  234. this.attributes.width.copyArray(new Float32Array(this.width));
  235. this.attributes.width.needsUpdate = true;
  236. this.attributes.uv.copyArray(new Float32Array(this.uvs));
  237. this.attributes.uv.needsUpdate = true;
  238. this.attributes.index.copyArray(new Uint16Array(this.indices_array));
  239. this.attributes.index.needsUpdate = true;
  240. }
  241. this.geometry.addAttribute('position', this.attributes.position);
  242. this.geometry.addAttribute('previous', this.attributes.previous);
  243. this.geometry.addAttribute('next', this.attributes.next);
  244. this.geometry.addAttribute('side', this.attributes.side);
  245. this.geometry.addAttribute('width', this.attributes.width);
  246. this.geometry.addAttribute('uv', this.attributes.uv);
  247. this.geometry.addAttribute('counters', this.attributes.counters);
  248. this.geometry.setIndex(this.attributes.index);
  249. }
  250. function memcpy(src, srcOffset, dst, dstOffset, length) {
  251. var i
  252. src = src.subarray || src.slice ? src : src.buffer
  253. dst = dst.subarray || dst.slice ? dst : dst.buffer
  254. src = srcOffset ? src.subarray ?
  255. src.subarray(srcOffset, length && srcOffset + length) :
  256. src.slice(srcOffset, length && srcOffset + length) : src
  257. if (dst.set) {
  258. dst.set(src, dstOffset)
  259. } else {
  260. for (i = 0; i < src.length; i++) {
  261. dst[i + dstOffset] = src[i]
  262. }
  263. }
  264. return dst
  265. }
  266. /**
  267. * Fast method to advance the line by one position. The oldest position is removed.
  268. * @param position
  269. */
  270. MeshLine.prototype.advance = function (position) {
  271. var positions = this.attributes.position.array;
  272. var previous = this.attributes.previous.array;
  273. var next = this.attributes.next.array;
  274. var l = positions.length;
  275. // PREVIOUS
  276. memcpy(positions, 0, previous, 0, l);
  277. // POSITIONS
  278. memcpy(positions, 6, positions, 0, l - 6);
  279. positions[l - 6] = position.x;
  280. positions[l - 5] = position.y;
  281. positions[l - 4] = position.z;
  282. positions[l - 3] = position.x;
  283. positions[l - 2] = position.y;
  284. positions[l - 1] = position.z;
  285. // NEXT
  286. memcpy(positions, 6, next, 0, l - 6);
  287. next[l - 6] = position.x;
  288. next[l - 5] = position.y;
  289. next[l - 4] = position.z;
  290. next[l - 3] = position.x;
  291. next[l - 2] = position.y;
  292. next[l - 1] = position.z;
  293. this.attributes.position.needsUpdate = true;
  294. this.attributes.previous.needsUpdate = true;
  295. this.attributes.next.needsUpdate = true;
  296. };
  297. THREE.ShaderChunk['meshline_vert'] = [
  298. '',
  299. THREE.ShaderChunk.logdepthbuf_pars_vertex,
  300. THREE.ShaderChunk.fog_pars_vertex,
  301. '',
  302. 'attribute vec3 previous;',
  303. 'attribute vec3 next;',
  304. 'attribute float side;',
  305. 'attribute float width;',
  306. 'attribute float counters;',
  307. '',
  308. 'uniform vec2 resolution;',
  309. 'uniform float lineWidth;',
  310. 'uniform vec3 color;',
  311. 'uniform float opacity;',
  312. 'uniform float near;',
  313. 'uniform float far;',
  314. 'uniform float sizeAttenuation;',
  315. '',
  316. 'varying vec2 vUV;',
  317. 'varying vec4 vColor;',
  318. 'varying float vCounters;',
  319. '',
  320. 'vec2 fix( vec4 i, float aspect ) {',
  321. '',
  322. ' vec2 res = i.xy / i.w;',
  323. ' res.x *= aspect;',
  324. ' vCounters = counters;',
  325. ' return res;',
  326. '',
  327. '}',
  328. '',
  329. 'void main() {',
  330. '',
  331. ' float aspect = resolution.x / resolution.y;',
  332. ' float pixelWidthRatio = 1. / (resolution.x * projectionMatrix[0][0]);',
  333. '',
  334. ' vColor = vec4( color, opacity );',
  335. ' vUV = uv;',
  336. '',
  337. ' mat4 m = projectionMatrix * modelViewMatrix;',
  338. ' vec4 finalPosition = m * vec4( position, 1.0 );',
  339. ' vec4 prevPos = m * vec4( previous, 1.0 );',
  340. ' vec4 nextPos = m * vec4( next, 1.0 );',
  341. '',
  342. ' vec2 currentP = fix( finalPosition, aspect );',
  343. ' vec2 prevP = fix( prevPos, aspect );',
  344. ' vec2 nextP = fix( nextPos, aspect );',
  345. '',
  346. ' float pixelWidth = finalPosition.w * pixelWidthRatio;',
  347. ' float w = 1.8 * pixelWidth * lineWidth * width;',
  348. '',
  349. ' if( sizeAttenuation == 1. ) {',
  350. ' w = 1.8 * lineWidth * width;',
  351. ' }',
  352. '',
  353. ' vec2 dir;',
  354. ' if( nextP == currentP ) dir = normalize( currentP - prevP );',
  355. ' else if( prevP == currentP ) dir = normalize( nextP - currentP );',
  356. ' else {',
  357. ' vec2 dir1 = normalize( currentP - prevP );',
  358. ' vec2 dir2 = normalize( nextP - currentP );',
  359. ' dir = normalize( dir1 + dir2 );',
  360. '',
  361. ' vec2 perp = vec2( -dir1.y, dir1.x );',
  362. ' vec2 miter = vec2( -dir.y, dir.x );',
  363. ' //w = clamp( w / dot( miter, perp ), 0., 4. * lineWidth * width );',
  364. '',
  365. ' }',
  366. '',
  367. ' //vec2 normal = ( cross( vec3( dir, 0. ), vec3( 0., 0., 1. ) ) ).xy;',
  368. ' vec2 normal = vec2( -dir.y, dir.x );',
  369. ' normal.x /= aspect;',
  370. ' normal *= .5 * w;',
  371. '',
  372. ' vec4 offset = vec4( normal * side, 0.0, 1.0 );',
  373. ' finalPosition.xy += offset.xy;',
  374. '',
  375. ' gl_Position = finalPosition;',
  376. '',
  377. THREE.ShaderChunk.logdepthbuf_vertex,
  378. THREE.ShaderChunk.fog_vertex && ' vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );',
  379. THREE.ShaderChunk.fog_vertex,
  380. '}'
  381. ].join('\r\n');
  382. THREE.ShaderChunk['meshline_frag'] = [
  383. '',
  384. THREE.ShaderChunk.fog_pars_fragment,
  385. THREE.ShaderChunk.logdepthbuf_pars_fragment,
  386. '',
  387. 'uniform sampler2D map;',
  388. 'uniform sampler2D alphaMap;',
  389. 'uniform float useMap;',
  390. 'uniform float useAlphaMap;',
  391. 'uniform float useDash;',
  392. 'uniform float dashArray;',
  393. 'uniform float dashOffset;',
  394. 'uniform float dashRatio;',
  395. 'uniform float visibility;',
  396. 'uniform float alphaTest;',
  397. 'uniform vec2 repeat;',
  398. '',
  399. 'varying vec2 vUV;',
  400. 'varying vec4 vColor;',
  401. 'varying float vCounters;',
  402. '',
  403. 'void main() {',
  404. '',
  405. THREE.ShaderChunk.logdepthbuf_fragment,
  406. '',
  407. ' vec4 c = vColor;',
  408. ' if( useMap == 1. ) c *= texture2D( map, vUV * repeat );',
  409. ' if( useAlphaMap == 1. ) c.a *= texture2D( alphaMap, vUV * repeat ).a;',
  410. ' if( c.a < alphaTest ) discard;',
  411. ' if( useDash == 1. ){',
  412. ' c.a *= ceil(mod(vCounters + dashOffset, dashArray) - (dashArray * dashRatio));',
  413. ' }',
  414. ' gl_FragColor = c;',
  415. ' gl_FragColor.a *= step(vCounters, visibility);',
  416. '',
  417. THREE.ShaderChunk.fog_fragment,
  418. '}'
  419. ].join('\r\n');
  420. function MeshLineMaterial(parameters) {
  421. THREE.ShaderMaterial.call(this, {
  422. uniforms: Object.assign({},
  423. THREE.UniformsLib.fog,
  424. {
  425. lineWidth: {value: 1},
  426. map: {value: null},
  427. useMap: {value: 0},
  428. alphaMap: {value: null},
  429. useAlphaMap: {value: 0},
  430. color: {value: new THREE.Color(0xffffff)},
  431. opacity: {value: 1},
  432. resolution: {value: new THREE.Vector2(1, 1)},
  433. sizeAttenuation: {value: 1},
  434. near: {value: 1},
  435. far: {value: 1},
  436. dashArray: {value: 0},
  437. dashOffset: {value: 0},
  438. dashRatio: {value: 0.5},
  439. useDash: {value: 0},
  440. visibility: {value: 1},
  441. alphaTest: {value: 0},
  442. repeat: {value: new THREE.Vector2(1, 1)},
  443. }
  444. ),
  445. vertexShader: THREE.ShaderChunk.meshline_vert,
  446. fragmentShader: THREE.ShaderChunk.meshline_frag,
  447. });
  448. this.type = 'MeshLineMaterial';
  449. Object.defineProperties(this, {
  450. lineWidth: {
  451. enumerable: true,
  452. get: function () {
  453. return this.uniforms.lineWidth.value;
  454. },
  455. set: function (value) {
  456. this.uniforms.lineWidth.value = value;
  457. }
  458. },
  459. map: {
  460. enumerable: true,
  461. get: function () {
  462. return this.uniforms.map.value;
  463. },
  464. set: function (value) {
  465. this.uniforms.map.value = value;
  466. }
  467. },
  468. useMap: {
  469. enumerable: true,
  470. get: function () {
  471. return this.uniforms.useMap.value;
  472. },
  473. set: function (value) {
  474. this.uniforms.useMap.value = value;
  475. }
  476. },
  477. alphaMap: {
  478. enumerable: true,
  479. get: function () {
  480. return this.uniforms.alphaMap.value;
  481. },
  482. set: function (value) {
  483. this.uniforms.alphaMap.value = value;
  484. }
  485. },
  486. useAlphaMap: {
  487. enumerable: true,
  488. get: function () {
  489. return this.uniforms.useAlphaMap.value;
  490. },
  491. set: function (value) {
  492. this.uniforms.useAlphaMap.value = value;
  493. }
  494. },
  495. color: {
  496. enumerable: true,
  497. get: function () {
  498. return this.uniforms.color.value;
  499. },
  500. set: function (value) {
  501. this.uniforms.color.value = value;
  502. }
  503. },
  504. opacity: {
  505. enumerable: true,
  506. get: function () {
  507. return this.uniforms.opacity.value;
  508. },
  509. set: function (value) {
  510. this.uniforms.opacity.value = value;
  511. }
  512. },
  513. resolution: {
  514. enumerable: true,
  515. get: function () {
  516. return this.uniforms.resolution.value;
  517. },
  518. set: function (value) {
  519. this.uniforms.resolution.value.copy(value);
  520. }
  521. },
  522. sizeAttenuation: {
  523. enumerable: true,
  524. get: function () {
  525. return this.uniforms.sizeAttenuation.value;
  526. },
  527. set: function (value) {
  528. this.uniforms.sizeAttenuation.value = value;
  529. }
  530. },
  531. near: {
  532. enumerable: true,
  533. get: function () {
  534. return this.uniforms.near.value;
  535. },
  536. set: function (value) {
  537. this.uniforms.near.value = value;
  538. }
  539. },
  540. far: {
  541. enumerable: true,
  542. get: function () {
  543. return this.uniforms.far.value;
  544. },
  545. set: function (value) {
  546. this.uniforms.far.value = value;
  547. }
  548. },
  549. dashArray: {
  550. enumerable: true,
  551. get: function () {
  552. return this.uniforms.dashArray.value;
  553. },
  554. set: function (value) {
  555. this.uniforms.dashArray.value = value;
  556. this.useDash = (value !== 0) ? 1 : 0
  557. }
  558. },
  559. dashOffset: {
  560. enumerable: true,
  561. get: function () {
  562. return this.uniforms.dashOffset.value;
  563. },
  564. set: function (value) {
  565. this.uniforms.dashOffset.value = value;
  566. }
  567. },
  568. dashRatio: {
  569. enumerable: true,
  570. get: function () {
  571. return this.uniforms.dashRatio.value;
  572. },
  573. set: function (value) {
  574. this.uniforms.dashRatio.value = value;
  575. }
  576. },
  577. useDash: {
  578. enumerable: true,
  579. get: function () {
  580. return this.uniforms.useDash.value;
  581. },
  582. set: function (value) {
  583. this.uniforms.useDash.value = value;
  584. }
  585. },
  586. visibility: {
  587. enumerable: true,
  588. get: function () {
  589. return this.uniforms.visibility.value;
  590. },
  591. set: function (value) {
  592. this.uniforms.visibility.value = value;
  593. }
  594. },
  595. alphaTest: {
  596. enumerable: true,
  597. get: function () {
  598. return this.uniforms.alphaTest.value;
  599. },
  600. set: function (value) {
  601. this.uniforms.alphaTest.value = value;
  602. }
  603. },
  604. repeat: {
  605. enumerable: true,
  606. get: function () {
  607. return this.uniforms.repeat.value;
  608. },
  609. set: function (value) {
  610. this.uniforms.repeat.value.copy(value);
  611. }
  612. },
  613. });
  614. this.setValues(parameters);
  615. }
  616. MeshLineMaterial.prototype = Object.create(THREE.ShaderMaterial.prototype);
  617. MeshLineMaterial.prototype.constructor = MeshLineMaterial;
  618. MeshLineMaterial.prototype.isMeshLineMaterial = true;
  619. MeshLineMaterial.prototype.copy = function (source) {
  620. THREE.ShaderMaterial.prototype.copy.call(this, source);
  621. this.lineWidth = source.lineWidth;
  622. this.map = source.map;
  623. this.useMap = source.useMap;
  624. this.alphaMap = source.alphaMap;
  625. this.useAlphaMap = source.useAlphaMap;
  626. this.color.copy(source.color);
  627. this.opacity = source.opacity;
  628. this.resolution.copy(source.resolution);
  629. this.sizeAttenuation = source.sizeAttenuation;
  630. this.near = source.near;
  631. this.far = source.far;
  632. this.dashArray.copy(source.dashArray);
  633. this.dashOffset.copy(source.dashOffset);
  634. this.dashRatio.copy(source.dashRatio);
  635. this.useDash = source.useDash;
  636. this.visibility = source.visibility;
  637. this.alphaTest = source.alphaTest;
  638. this.repeat.copy(source.repeat);
  639. return this;
  640. };
  641. if (typeof exports !== 'undefined') {
  642. if (typeof module !== 'undefined' && module.exports) {
  643. exports = module.exports = {MeshLine: MeshLine, MeshLineMaterial: MeshLineMaterial};
  644. }
  645. exports.MeshLine = MeshLine;
  646. exports.MeshLineMaterial = MeshLineMaterial;
  647. }
  648. else {
  649. root.MeshLine = MeshLine;
  650. root.MeshLineMaterial = MeshLineMaterial;
  651. }
  652. }).call(this);
  653. }