Code Monkey home page Code Monkey logo

Comments (7)

yperess avatar yperess commented on September 27, 2024

Never mind, I was using ObjUtils.convertToRenderable incorrectly (after splitting the object instead of before). Sorry!

from obj.

javagl avatar javagl commented on September 27, 2024

Thanks for this hint. I remember trying out this case, namely whether it makes a difference whether one

  • first splits and then converts to renderable
  • first converts to renderable and then splits

I think it should work also when first splitting and then converting to renderable. I'll try it out with your model and try to figure out where the difference comes from, and whether it can be fixed sensibly.

(Reopening, so that it doesn't get buried (so easily))

from obj.

wvc avatar wvc commented on September 27, 2024

Hi,

Not sure if it is related to this issue, but your triangulation code is wrong (ObjUtils.triangulate) . It creates a triangle fan starting from the first vertex, but this doesn't work for concave (non-convex) facets/polygons. It can create triangles that overlap each other.
I haven't found a java-implementation of triangulation for concave polygons/facets yet. I've seen some libraries (in c++, javascript) that delegate to an OpenGL method: gluTesselate , which should do it correctly. But no pure-Java implementation yet.

If it is not related to this issue, could you create an issue from this?

from obj.

javagl avatar javagl commented on September 27, 2024

@wvc This is probably unrelated to the original issue, but we can quickly talk about this here.

I disagree when you say that the code of triangulate is "wrong". It is not. It does triangulate the face, exactly as described in the JavaDoc:

 * This method will simply subdivide faces with more than 3 vertices so 
 * that all faces in the output will be triangles.

That's the claim. Nothing more. Nothing less.

Right now, the implementation is trivial, and essentially consists of 3 lines of code - it indeed only creates a simple triangle fan. If this is not a satisfactory output, then everybody is free to either use any tool to preprocess their OBJ, or to use this library (free of charge...) to load an OBJ, and handle the non-triangular faces as they wish: They can think about concave polygons, non-planar polygons, degenerate polygons, self-intersecting polygons, non-connected polygons, winding rules, or even try to compute a conforming delaunay triangulation (if the face is planar).

This library is supposed to do one job, and to do it right. And this job is to load OBJs.

(The claim that it does this job better than most other OBJ loaders may sound bold. But... let's be honest: That's not such a high bar. Everybody who is concerned with graphics has written some ""OBJ loader"" at least once in their life...)

Things like the triangulation (or convertToRenderable in general, or the OBJ splitting) are convenience functions that are still simple enough to be justified, considering that basically everybody who wants to load an OBJ wants to render it. But more complex triangulations are a rabbit hole that I certainly won't dive into in the context of this library.

from obj.

wvc avatar wvc commented on September 27, 2024

Alright, just wanted to point it out in case it was related to this issue (since it is still open). I came across your library while searching for a Java triangulation library. In the end, I decided to implement an ear-cutting algorithm myself, which seems to work ok for regular, simple polygons without holes. It still produces very slender triangles though (much like with triangle fans), but a refinement step with flipping triangles according to the Delauney criterion should improve that.

There are some nice references here (not affiliated): http://vterrain.org/Implementation/Libs/triangulate.html Unfortunately, most are c++ implementations which hampered my all-Java approach.

from obj.

javagl avatar javagl commented on September 27, 2024

(That link is broken in some odd way, but one can copy+paste it).

Indeed, I've recently been looking at triangulation as well. I considered creating a standalone library for that (independent of this OBJ loader). In fact, I created Java bindings for http://www.cs.cmu.edu/~quake/triangle.html quite a while ago, and contacted the author (several times) whether it's OK to publish them, but received no response. A few days ago, I tried to compile the library on Windows 10, and encountered some unexplicable issues, so I'll likely abandon that.

But I still consider to create 1. either a Java library for Delaunay triangulation or 2. create bindings for a more "modern" (C++-based) library, or 3. create a Java port of an existing implementation, like https://doc.cgal.org/latest/Triangulation_2/index.html or https://www.geometrictools.com/Samples/Geometrics.html#Delaunay2D

But again: This would all be independent of the OBJ library (of course), and is nothing that I've scheduled right now - only something of which I thought "yeah, could be nice to have...".

from obj.

javagl avatar javagl commented on September 27, 2024

This issue was actually resolved, and only kept open because I intended to do further tests. If I'm gonna do that, it will be independent of this issue.

from obj.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.