Skip to content

Commit

Permalink
fix(tools/mesh/transformEdge): improve edge detection for meshes that…
Browse files Browse the repository at this point in the history
… are not flat
  • Loading branch information
meszaros-lajos-gyorgy committed Aug 19, 2023
1 parent c25e0ae commit 5c66710
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/tools/mesh/connectEdgeTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const connectEdgeTo = (source: BufferGeometry, target: BufferGeometry) =>
const edgeIdx = sourceEdgeVertices.findIndex((edgeVertex) => {
return edgeVertex.equals(vertex.vector)
})

if (edgeIdx !== -1) {
const [edgePoint] = sourceEdgeVertices.splice(edgeIdx, 1)

Expand Down
12 changes: 6 additions & 6 deletions src/tools/mesh/transformEdge.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { BufferAttribute, EdgesGeometry, Mesh } from 'three'
import { BufferAttribute, Mesh } from 'three'
import { Vector3 } from '@src/Vector3.js'
import { categorizeVertices } from '@tools/mesh/categorizeVertices.js'
import { getVertices } from '@tools/mesh/getVertices.js'

export const transformEdge = (offset: Vector3, mesh: Mesh) => {
// TODO: instead of EdgesGeometry try using the edge detection code from the Alia's nightmare level
// EdgesGeometry fails if the geometry is already bumped
const edge = new EdgesGeometry(mesh.geometry)
const edgeVertices = getVertices(edge)
const { edges, corners } = categorizeVertices(mesh.geometry)
const edgeVertices = [...edges, ...corners]

const vertices = getVertices(mesh.geometry)
const coords = mesh.geometry.getAttribute('position') as BufferAttribute

vertices.forEach((vertex) => {
const edgeIdx = edgeVertices.findIndex((edgeVertex) => {
return edgeVertex.vector.equals(vertex.vector)
return edgeVertex.equals(vertex.vector)
})

if (edgeIdx !== -1) {
edgeVertices.splice(edgeIdx, 1)
coords.setX(vertex.idx, vertex.vector.x + offset.x)
Expand Down

0 comments on commit 5c66710

Please sign in to comment.