Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertices v1 and v2 should be different (though vertices deduped?) #6

Open
antoinemacia opened this issue May 31, 2023 · 0 comments
Open

Comments

@antoinemacia
Copy link

antoinemacia commented May 31, 2023

Hello hello!

After many attempts to resolve this I keep getting the error Error: Vertices v1 and v2 should be different when trying to render a SVG from an OBJ loaded. The error seem to come from the Halfedge package

What I've tried

  • Remove duplicate vertices (as per error message)
  • Merge vertices (at various levels of tolerance)
  • Merge geometries

When debugging further, it seemed the safeguard was checking two vertices with the same id? That didn't sound right, and maybe explains why removing duplicate verts didn't make it

Screenshot 2023-05-31 at 1 15 28 pm

This is more or less what Im doing (the different passes are here for testing, I havent got it to work yet)

private renderToSvg = (outlines: THREE.Group) => {
    const meshes = new Array<SVGMesh>()

    outlines.traverse(obj => {
      if ((obj as THREE.Mesh).isMesh) {
        let positions = obj.geometry.attributes.position.array
        positions = new Float32Array(removeDuplicateVertices(positions))

        obj.geometry.setAttribute(
          "position",
          new THREE.BufferAttribute(positions, 3)
        )

        obj.geometry.setDrawRange(0, positions.length)
        obj.updateMatrix()

        meshes.push(new SVGMesh(obj))
      }
    })

    const renderer = new SVGRenderer()
    const fillPass = new FillPass()
    const singularityPass = new SingularityPointPass()
    const visibleContourPass = new VisibleChainPass()
    const hiddenContourPass = new HiddenChainPass()

    renderer.addPass(fillPass)
    renderer.addPass(visibleContourPass)
    renderer.addPass(hiddenContourPass)
    renderer.addPass(singularityPass)

    renderer.viewmap.options.ignoreVisibility = false
    renderer.viewmap.options.updateMeshes = true

    // Get the SVG
    renderer
      .generateSVG(meshes, camera, { w: 1000, h: 1000 })
      .then(svg => {
        SVGRenderer.exportSVG(svg, "scene", { prettify: true })
      })
  }
  
   private removeDuplicateVertices(vertices) {
      var positionLookup = []
      var final = []
  
      vertices.forEach((pos, i) => {
        if (i % 3 === 0) {
          const str = `${pos}, ${pos + 1}, ${pos + 2}`
          if (positionLookup.some(p => p === str)) return
          positionLookup.push(str)
          final.push(pos)
          final.push(pos + 1)
          final.push(pos + 2)
        }
      })
  
      return final
  }

Any suggestions welcome 😄 the potentially offending OBJ Im trying to render from the top is this one: https://drive.google.com/file/d/1lJai_bLgkGG8ZkIQi2q57x236drecOrn/view?usp=sharing

@antoinemacia antoinemacia changed the title Vertices v1 and v2 should be different (though vertice deduped?) Vertices v1 and v2 should be different (though vertices deduped?) May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant