mesh.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import { Task } from 'mol-task'
  7. import { ValueCell } from 'mol-util'
  8. import { Vec3, Mat4 } from 'mol-math/linear-algebra'
  9. import { Sphere3D } from 'mol-math/geometry'
  10. import { transformPositionArray/* , transformDirectionArray, getNormalMatrix */ } from '../../util';
  11. import { GeometryUtils } from '../geometry';
  12. import { createMarkers } from '../marker-data';
  13. import { TransformData } from '../transform-data';
  14. import { LocationIterator } from '../../util/location-iterator';
  15. import { createColors } from '../color-data';
  16. import { ChunkedArray } from 'mol-data/util';
  17. import { ParamDefinition as PD } from 'mol-util/param-definition';
  18. import { calculateBoundingSphere } from 'mol-gl/renderable/util';
  19. import { Theme } from 'mol-theme/theme';
  20. import { MeshValues } from 'mol-gl/renderable/mesh';
  21. import { Color } from 'mol-util/color';
  22. import { BaseGeometry } from '../base';
  23. import { createEmptyOverpaint } from '../overpaint-data';
  24. export interface Mesh {
  25. readonly kind: 'mesh',
  26. /** Number of vertices in the mesh */
  27. vertexCount: number,
  28. /** Number of triangles in the mesh */
  29. triangleCount: number,
  30. /** Vertex buffer as array of xyz values wrapped in a value cell */
  31. readonly vertexBuffer: ValueCell<Float32Array>,
  32. /** Index buffer as array of vertex index triplets wrapped in a value cell */
  33. readonly indexBuffer: ValueCell<Uint32Array>,
  34. /** Normal buffer as array of xyz values for each vertex wrapped in a value cell */
  35. readonly normalBuffer: ValueCell<Float32Array>,
  36. /** Group buffer as array of group ids for each vertex wrapped in a value cell */
  37. readonly groupBuffer: ValueCell<Float32Array>,
  38. /** Flag indicating if normals are computed for the current set of vertices */
  39. normalsComputed: boolean,
  40. /** Bounding sphere of the mesh */
  41. boundingSphere?: Sphere3D
  42. }
  43. export namespace Mesh {
  44. export function createEmpty(mesh?: Mesh): Mesh {
  45. const vb = mesh ? mesh.vertexBuffer.ref.value : new Float32Array(0)
  46. const ib = mesh ? mesh.indexBuffer.ref.value : new Uint32Array(0)
  47. const nb = mesh ? mesh.normalBuffer.ref.value : new Float32Array(0)
  48. const gb = mesh ? mesh.groupBuffer.ref.value : new Float32Array(0)
  49. return {
  50. kind: 'mesh',
  51. vertexCount: 0,
  52. triangleCount: 0,
  53. vertexBuffer: mesh ? ValueCell.update(mesh.vertexBuffer, vb) : ValueCell.create(vb),
  54. indexBuffer: mesh ? ValueCell.update(mesh.indexBuffer, ib) : ValueCell.create(ib),
  55. normalBuffer: mesh ? ValueCell.update(mesh.normalBuffer, nb) : ValueCell.create(nb),
  56. groupBuffer: mesh ? ValueCell.update(mesh.groupBuffer, gb) : ValueCell.create(gb),
  57. normalsComputed: true,
  58. }
  59. }
  60. export function fromArrays(vertices: Float32Array, indices: Uint32Array, normals: Float32Array, groups: Float32Array, vertexCount: number, triangleCount: number, normalsComputed: boolean): Mesh {
  61. return {
  62. kind: 'mesh',
  63. vertexCount,
  64. triangleCount,
  65. vertexBuffer: ValueCell.create(vertices),
  66. indexBuffer: ValueCell.create(indices),
  67. normalBuffer: ValueCell.create(normals),
  68. groupBuffer: ValueCell.create(groups),
  69. normalsComputed,
  70. }
  71. }
  72. export function computeNormalsImmediate(mesh: Mesh) {
  73. if (mesh.normalsComputed) return;
  74. const normals = mesh.normalBuffer.ref.value.length >= mesh.vertexCount * 3
  75. ? mesh.normalBuffer.ref.value : new Float32Array(mesh.vertexBuffer.ref.value.length);
  76. const v = mesh.vertexBuffer.ref.value, triangles = mesh.indexBuffer.ref.value;
  77. if (normals === mesh.normalBuffer.ref.value) {
  78. for (let i = 0, ii = 3 * mesh.vertexCount; i < ii; i += 3) {
  79. normals[i] = 0; normals[i + 1] = 0; normals[i + 2] = 0;
  80. }
  81. }
  82. const x = Vec3.zero(), y = Vec3.zero(), z = Vec3.zero(), d1 = Vec3.zero(), d2 = Vec3.zero(), n = Vec3.zero();
  83. for (let i = 0, ii = 3 * mesh.triangleCount; i < ii; i += 3) {
  84. const a = 3 * triangles[i], b = 3 * triangles[i + 1], c = 3 * triangles[i + 2];
  85. Vec3.fromArray(x, v, a);
  86. Vec3.fromArray(y, v, b);
  87. Vec3.fromArray(z, v, c);
  88. Vec3.sub(d1, z, y);
  89. Vec3.sub(d2, x, y);
  90. Vec3.cross(n, d1, d2);
  91. normals[a] += n[0]; normals[a + 1] += n[1]; normals[a + 2] += n[2];
  92. normals[b] += n[0]; normals[b + 1] += n[1]; normals[b + 2] += n[2];
  93. normals[c] += n[0]; normals[c + 1] += n[1]; normals[c + 2] += n[2];
  94. }
  95. for (let i = 0, ii = 3 * mesh.vertexCount; i < ii; i += 3) {
  96. const nx = normals[i];
  97. const ny = normals[i + 1];
  98. const nz = normals[i + 2];
  99. const f = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
  100. normals[i] *= f; normals[i + 1] *= f; normals[i + 2] *= f;
  101. // console.log([normals[i], normals[i + 1], normals[i + 2]], [v[i], v[i + 1], v[i + 2]])
  102. }
  103. ValueCell.update(mesh.normalBuffer, normals);
  104. mesh.normalsComputed = true;
  105. }
  106. export function checkForDuplicateVertices(mesh: Mesh, fractionDigits = 3) {
  107. const v = mesh.vertexBuffer.ref.value
  108. const map = new Map<string, number>()
  109. const hash = (v: Vec3, d: number) => `${v[0].toFixed(d)}|${v[1].toFixed(d)}|${v[2].toFixed(d)}`
  110. let duplicates = 0
  111. const a = Vec3.zero()
  112. for (let i = 0, il = mesh.vertexCount; i < il; ++i) {
  113. Vec3.fromArray(a, v, i * 3)
  114. const k = hash(a, fractionDigits)
  115. const count = map.get(k)
  116. if (count !== undefined) {
  117. duplicates += 1
  118. map.set(k, count + 1)
  119. } else {
  120. map.set(k, 1)
  121. }
  122. }
  123. return duplicates
  124. }
  125. export function computeNormals(surface: Mesh): Task<Mesh> {
  126. return Task.create<Mesh>('Surface (Compute Normals)', async ctx => {
  127. if (surface.normalsComputed) return surface;
  128. await ctx.update('Computing normals...');
  129. computeNormalsImmediate(surface);
  130. return surface;
  131. });
  132. }
  133. export function transformImmediate(mesh: Mesh, t: Mat4) {
  134. transformRangeImmediate(mesh, t, 0, mesh.vertexCount)
  135. }
  136. export function transformRangeImmediate(mesh: Mesh, t: Mat4, offset: number, count: number) {
  137. const v = mesh.vertexBuffer.ref.value
  138. transformPositionArray(t, v, offset, count)
  139. // TODO normals transformation does not work for an unknown reason, ASR
  140. // if (mesh.normalBuffer.ref.value) {
  141. // const n = getNormalMatrix(Mat3.zero(), t)
  142. // transformDirectionArray(n, mesh.normalBuffer.ref.value, offset, count)
  143. // mesh.normalsComputed = true;
  144. // }
  145. ValueCell.update(mesh.vertexBuffer, v);
  146. mesh.normalsComputed = false;
  147. }
  148. export function computeBoundingSphere(mesh: Mesh): Task<Mesh> {
  149. return Task.create<Mesh>('Mesh (Compute Bounding Sphere)', async ctx => {
  150. if (mesh.boundingSphere) {
  151. return mesh;
  152. }
  153. await ctx.update('Computing bounding sphere...');
  154. const vertices = mesh.vertexBuffer.ref.value;
  155. let x = 0, y = 0, z = 0;
  156. for (let i = 0, _c = vertices.length; i < _c; i += 3) {
  157. x += vertices[i];
  158. y += vertices[i + 1];
  159. z += vertices[i + 2];
  160. }
  161. x /= mesh.vertexCount;
  162. y /= mesh.vertexCount;
  163. z /= mesh.vertexCount;
  164. let r = 0;
  165. for (let i = 0, _c = vertices.length; i < _c; i += 3) {
  166. const dx = x - vertices[i];
  167. const dy = y - vertices[i + 1];
  168. const dz = z - vertices[i + 2];
  169. r = Math.max(r, dx * dx + dy * dy + dz * dz);
  170. }
  171. mesh.boundingSphere = {
  172. center: Vec3.create(x, y, z),
  173. radius: Math.sqrt(r)
  174. }
  175. return mesh;
  176. });
  177. }
  178. /**
  179. * Ensure that each vertices of each triangle have the same group id.
  180. * Note that normals are copied over and can't be re-created from the new mesh.
  181. */
  182. export function uniformTriangleGroup(mesh: Mesh, splitTriangles = true) {
  183. const { indexBuffer, vertexBuffer, groupBuffer, normalBuffer, triangleCount, vertexCount } = mesh
  184. const ib = indexBuffer.ref.value
  185. const vb = vertexBuffer.ref.value
  186. const gb = groupBuffer.ref.value
  187. const nb = normalBuffer.ref.value
  188. // new
  189. const index = ChunkedArray.create(Uint32Array, 3, 1024, triangleCount)
  190. // re-use
  191. const vertex = ChunkedArray.create(Float32Array, 3, 1024, vb)
  192. vertex.currentIndex = vertexCount * 3
  193. vertex.elementCount = vertexCount
  194. const normal = ChunkedArray.create(Float32Array, 3, 1024, nb)
  195. normal.currentIndex = vertexCount * 3
  196. normal.elementCount = vertexCount
  197. const group = ChunkedArray.create(Float32Array, 1, 1024, gb)
  198. group.currentIndex = vertexCount
  199. group.elementCount = vertexCount
  200. const vi = Vec3.zero()
  201. const vj = Vec3.zero()
  202. const vk = Vec3.zero()
  203. const ni = Vec3.zero()
  204. const nj = Vec3.zero()
  205. const nk = Vec3.zero()
  206. function add(i: number) {
  207. Vec3.fromArray(vi, vb, i * 3)
  208. Vec3.fromArray(ni, nb, i * 3)
  209. ChunkedArray.add3(vertex, vi[0], vi[1], vi[2])
  210. ChunkedArray.add3(normal, ni[0], ni[1], ni[2])
  211. }
  212. function addMid(i: number, j: number) {
  213. Vec3.fromArray(vi, vb, i * 3)
  214. Vec3.fromArray(vj, vb, j * 3)
  215. Vec3.scale(vi, Vec3.add(vi, vi, vj), 0.5)
  216. Vec3.fromArray(ni, nb, i * 3)
  217. Vec3.fromArray(nj, nb, j * 3)
  218. Vec3.scale(ni, Vec3.add(ni, ni, nj), 0.5)
  219. ChunkedArray.add3(vertex, vi[0], vi[1], vi[2])
  220. ChunkedArray.add3(normal, ni[0], ni[1], ni[2])
  221. }
  222. function addCenter(i: number, j: number, k: number) {
  223. Vec3.fromArray(vi, vb, i * 3)
  224. Vec3.fromArray(vj, vb, j * 3)
  225. Vec3.fromArray(vk, vb, k * 3)
  226. Vec3.scale(vi, Vec3.add(vi, Vec3.add(vi, vi, vj), vk), 1/3)
  227. Vec3.fromArray(ni, nb, i * 3)
  228. Vec3.fromArray(nj, nb, j * 3)
  229. Vec3.fromArray(nk, nb, k * 3)
  230. Vec3.scale(ni, Vec3.add(ni, Vec3.add(ni, ni, nj), nk), 1/3)
  231. ChunkedArray.add3(vertex, vi[0], vi[1], vi[2])
  232. ChunkedArray.add3(normal, ni[0], ni[1], ni[2])
  233. }
  234. function split2(i0: number, i1: number, i2: number, g0: number, g1: number) {
  235. ++newTriangleCount
  236. add(i0); addMid(i0, i1); addMid(i0, i2);
  237. ChunkedArray.add3(index, newVertexCount, newVertexCount + 1, newVertexCount + 2)
  238. for (let j = 0; j < 3; ++j) ChunkedArray.add(group, g0)
  239. newVertexCount += 3
  240. newTriangleCount += 2
  241. add(i1); add(i2); addMid(i0, i1); addMid(i0, i2);
  242. ChunkedArray.add3(index, newVertexCount, newVertexCount + 1, newVertexCount + 3)
  243. ChunkedArray.add3(index, newVertexCount, newVertexCount + 3, newVertexCount + 2)
  244. for (let j = 0; j < 4; ++j) ChunkedArray.add(group, g1)
  245. newVertexCount += 4
  246. }
  247. let newVertexCount = vertexCount
  248. let newTriangleCount = 0
  249. if (splitTriangles) {
  250. for (let i = 0, il = triangleCount; i < il; ++i) {
  251. const i0 = ib[i * 3], i1 = ib[i * 3 + 1], i2 = ib[i * 3 + 2]
  252. const g0 = gb[i0], g1 = gb[i1], g2 = gb[i2]
  253. if (g0 === g1 && g0 === g2) {
  254. ++newTriangleCount
  255. ChunkedArray.add3(index, i0, i1, i2)
  256. } else if (g0 === g1) {
  257. split2(i2, i0, i1, g2, g0)
  258. } else if (g0 === g2) {
  259. split2(i1, i2, i0, g1, g2)
  260. } else if (g1 === g2) {
  261. split2(i0, i1, i2, g0, g1)
  262. } else {
  263. newTriangleCount += 2
  264. add(i0); addMid(i0, i1); addMid(i0, i2); addCenter(i0, i1, i2);
  265. ChunkedArray.add3(index, newVertexCount, newVertexCount + 1, newVertexCount + 3)
  266. ChunkedArray.add3(index, newVertexCount, newVertexCount + 3, newVertexCount + 2)
  267. for (let j = 0; j < 4; ++j) ChunkedArray.add(group, g0)
  268. newVertexCount += 4
  269. newTriangleCount += 2
  270. add(i1); addMid(i1, i2); addMid(i1, i0); addCenter(i0, i1, i2);
  271. ChunkedArray.add3(index, newVertexCount, newVertexCount + 1, newVertexCount + 3)
  272. ChunkedArray.add3(index, newVertexCount, newVertexCount + 3, newVertexCount + 2)
  273. for (let j = 0; j < 4; ++j) ChunkedArray.add(group, g1)
  274. newVertexCount += 4
  275. newTriangleCount += 2
  276. add(i2); addMid(i2, i1); addMid(i2, i0); addCenter(i0, i1, i2);
  277. ChunkedArray.add3(index, newVertexCount + 3, newVertexCount + 1, newVertexCount)
  278. ChunkedArray.add3(index, newVertexCount + 2, newVertexCount + 3, newVertexCount)
  279. for (let j = 0; j < 4; ++j) ChunkedArray.add(group, g2)
  280. newVertexCount += 4
  281. }
  282. }
  283. } else {
  284. for (let i = 0, il = triangleCount; i < il; ++i) {
  285. const i0 = ib[i * 3], i1 = ib[i * 3 + 1], i2 = ib[i * 3 + 2]
  286. const g0 = gb[i0], g1 = gb[i1], g2 = gb[i2]
  287. if (g0 !== g1 || g0 !== g2) {
  288. ++newTriangleCount
  289. add(i0); add(i1); add(i2)
  290. ChunkedArray.add3(index, newVertexCount, newVertexCount + 1, newVertexCount + 2)
  291. const g = g1 === g2 ? g1 : g0
  292. for (let j = 0; j < 3; ++j) ChunkedArray.add(group, g)
  293. newVertexCount += 3
  294. } else {
  295. ++newTriangleCount
  296. ChunkedArray.add3(index, i0, i1, i2)
  297. }
  298. }
  299. }
  300. const newIb = ChunkedArray.compact(index)
  301. const newVb = ChunkedArray.compact(vertex)
  302. const newNb = ChunkedArray.compact(normal)
  303. const newGb = ChunkedArray.compact(group)
  304. mesh.vertexCount = newVertexCount
  305. mesh.triangleCount = newTriangleCount
  306. ValueCell.update(vertexBuffer, newVb) as ValueCell<Float32Array>
  307. ValueCell.update(groupBuffer, newGb) as ValueCell<Float32Array>
  308. ValueCell.update(indexBuffer, newIb) as ValueCell<Uint32Array>
  309. ValueCell.update(normalBuffer, newNb) as ValueCell<Float32Array>
  310. return mesh
  311. }
  312. //
  313. export const Params = {
  314. ...BaseGeometry.Params,
  315. doubleSided: PD.Boolean(false),
  316. flipSided: PD.Boolean(false),
  317. flatShaded: PD.Boolean(false),
  318. }
  319. export type Params = typeof Params
  320. export const Utils: GeometryUtils<Mesh, Params> = {
  321. Params,
  322. createEmpty,
  323. createValues,
  324. createValuesSimple,
  325. updateValues,
  326. updateBoundingSphere,
  327. createRenderableState: BaseGeometry.createRenderableState,
  328. updateRenderableState: BaseGeometry.updateRenderableState
  329. }
  330. function createValues(mesh: Mesh, transform: TransformData, locationIt: LocationIterator, theme: Theme, props: PD.Values<Params>): MeshValues {
  331. const { instanceCount, groupCount } = locationIt
  332. if (instanceCount !== transform.instanceCount.ref.value) {
  333. throw new Error('instanceCount values in TransformData and LocationIterator differ')
  334. }
  335. const color = createColors(locationIt, theme.color)
  336. const marker = createMarkers(instanceCount * groupCount)
  337. const overpaint = createEmptyOverpaint()
  338. const counts = { drawCount: mesh.triangleCount * 3, groupCount, instanceCount }
  339. const { boundingSphere, invariantBoundingSphere } = calculateBoundingSphere(
  340. mesh.vertexBuffer.ref.value, mesh.vertexCount,
  341. transform.aTransform.ref.value, instanceCount
  342. )
  343. return {
  344. aPosition: mesh.vertexBuffer,
  345. aNormal: mesh.normalBuffer,
  346. aGroup: mesh.groupBuffer,
  347. elements: mesh.indexBuffer,
  348. boundingSphere: ValueCell.create(boundingSphere),
  349. invariantBoundingSphere: ValueCell.create(invariantBoundingSphere),
  350. ...color,
  351. ...marker,
  352. ...overpaint,
  353. ...transform,
  354. ...BaseGeometry.createValues(props, counts),
  355. dDoubleSided: ValueCell.create(props.doubleSided),
  356. dFlatShaded: ValueCell.create(props.flatShaded),
  357. dFlipSided: ValueCell.create(props.flipSided),
  358. }
  359. }
  360. function createValuesSimple(mesh: Mesh, props: Partial<PD.Values<Params>>, colorValue: Color, sizeValue: number, transform?: TransformData) {
  361. const s = BaseGeometry.createSimple(colorValue, sizeValue, transform)
  362. const p = { ...PD.getDefaultValues(Params), ...props }
  363. return createValues(mesh, s.transform, s.locationIterator, s.theme, p)
  364. }
  365. function updateValues(values: MeshValues, props: PD.Values<Params>) {
  366. BaseGeometry.updateValues(values, props)
  367. ValueCell.updateIfChanged(values.dDoubleSided, props.doubleSided)
  368. ValueCell.updateIfChanged(values.dFlatShaded, props.flatShaded)
  369. ValueCell.updateIfChanged(values.dFlipSided, props.flipSided)
  370. }
  371. function updateBoundingSphere(values: MeshValues, mesh: Mesh) {
  372. const { boundingSphere, invariantBoundingSphere } = calculateBoundingSphere(
  373. values.aPosition.ref.value, mesh.vertexCount,
  374. values.aTransform.ref.value, values.instanceCount.ref.value
  375. )
  376. if (!Sphere3D.equals(boundingSphere, values.boundingSphere.ref.value)) {
  377. ValueCell.update(values.boundingSphere, boundingSphere)
  378. }
  379. if (!Sphere3D.equals(invariantBoundingSphere, values.invariantBoundingSphere.ref.value)) {
  380. ValueCell.update(values.invariantBoundingSphere, invariantBoundingSphere)
  381. }
  382. }
  383. }
  384. // function addVertex(src: Float32Array, i: number, dst: Float32Array, j: number) {
  385. // dst[3 * j] += src[3 * i];
  386. // dst[3 * j + 1] += src[3 * i + 1];
  387. // dst[3 * j + 2] += src[3 * i + 2];
  388. // }
  389. // function laplacianSmoothIter(surface: Surface, vertexCounts: Int32Array, vs: Float32Array, vertexWeight: number) {
  390. // const triCount = surface.triangleIndices.length,
  391. // src = surface.vertices;
  392. // const triangleIndices = surface.triangleIndices;
  393. // for (let i = 0; i < triCount; i += 3) {
  394. // const a = triangleIndices[i],
  395. // b = triangleIndices[i + 1],
  396. // c = triangleIndices[i + 2];
  397. // addVertex(src, b, vs, a);
  398. // addVertex(src, c, vs, a);
  399. // addVertex(src, a, vs, b);
  400. // addVertex(src, c, vs, b);
  401. // addVertex(src, a, vs, c);
  402. // addVertex(src, b, vs, c);
  403. // }
  404. // const vw = 2 * vertexWeight;
  405. // for (let i = 0, _b = surface.vertexCount; i < _b; i++) {
  406. // const n = vertexCounts[i] + vw;
  407. // vs[3 * i] = (vs[3 * i] + vw * src[3 * i]) / n;
  408. // vs[3 * i + 1] = (vs[3 * i + 1] + vw * src[3 * i + 1]) / n;
  409. // vs[3 * i + 2] = (vs[3 * i + 2] + vw * src[3 * i + 2]) / n;
  410. // }
  411. // }
  412. // async function laplacianSmoothComputation(ctx: Computation.Context, surface: Surface, iterCount: number, vertexWeight: number) {
  413. // await ctx.updateProgress('Smoothing surface...', true);
  414. // const vertexCounts = new Int32Array(surface.vertexCount),
  415. // triCount = surface.triangleIndices.length;
  416. // const tris = surface.triangleIndices;
  417. // for (let i = 0; i < triCount; i++) {
  418. // // in a triangle 2 edges touch each vertex, hence the constant.
  419. // vertexCounts[tris[i]] += 2;
  420. // }
  421. // let vs = new Float32Array(surface.vertices.length);
  422. // let started = Utils.PerformanceMonitor.currentTime();
  423. // await ctx.updateProgress('Smoothing surface...', true);
  424. // for (let i = 0; i < iterCount; i++) {
  425. // if (i > 0) {
  426. // for (let j = 0, _b = vs.length; j < _b; j++) vs[j] = 0;
  427. // }
  428. // surface.normals = void 0;
  429. // laplacianSmoothIter(surface, vertexCounts, vs, vertexWeight);
  430. // const t = surface.vertices;
  431. // surface.vertices = <any>vs;
  432. // vs = <any>t;
  433. // const time = Utils.PerformanceMonitor.currentTime();
  434. // if (time - started > Computation.UpdateProgressDelta) {
  435. // started = time;
  436. // await ctx.updateProgress('Smoothing surface...', true, i + 1, iterCount);
  437. // }
  438. // }
  439. // return surface;
  440. // }
  441. // /*
  442. // * Smooths the vertices by averaging the neighborhood.
  443. // *
  444. // * Resets normals. Might replace vertex array.
  445. // */
  446. // export function laplacianSmooth(surface: Surface, iterCount: number = 1, vertexWeight: number = 1): Computation<Surface> {
  447. // if (iterCount < 1) iterCount = 0;
  448. // if (iterCount === 0) return Computation.resolve(surface);
  449. // return computation(async ctx => await laplacianSmoothComputation(ctx, surface, iterCount, (1.1 * vertexWeight) / 1.1));
  450. // }