How to load a geometry (.obj, .wrl, .jvx, ... )

Have jReality programming problems or questions? Post them here.
Post Reply
rafax
Posts: 16
Joined: Sat 17. Apr 2010, 12:39

How to load a geometry (.obj, .wrl, .jvx, ... )

Post by rafax » Wed 18. Aug 2010, 11:24

Hi,

To view a geometry, we can just use the interface and open it. But, how can I load it from my program and do some processing on it?

Regards

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: How to load a geometry (.obj, .wrl, .jvx, ... )

Post by gunn » Mon 23. Aug 2010, 21:13

To see how to read a file into a Java program, see the following jReality tutorial:
http://www3.math.tu-berlin.de/jreality/ ... e_a_reader

If you need also to write the results out again, there are a more restricted set of classes for writing. Please post again if you want more information on these.
jReality core developer

rafax
Posts: 16
Joined: Sat 17. Apr 2010, 12:39

Re: How to load a geometry (.obj, .wrl, .jvx, ... )

Post by rafax » Wed 25. Aug 2010, 11:00

Thank you!

The problem is only that, one need to load it from file via a javacode. I think there is a way to load it directly from the interface and the javacode will get the geometry from the viewer automatically for processing. In this case, we can process any geometry we want without specifing the path but I need a hint for that.

Regards

rafax
Posts: 16
Joined: Sat 17. Apr 2010, 12:39

Re: How to load a geometry (.obj, .wrl, .jvx, ... )

Post by rafax » Wed 25. Aug 2010, 12:14

Hi,

Instead of ScenegraphGomponent, is it possible to get an indexedFaceSet of the geometry?

Regards

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: How to load a geometry (.obj, .wrl, .jvx, ... )

Post by gunn » Wed 25. Aug 2010, 13:01

You can get the first geometry found (by depth-first traversal) of the scene graph rooted at a SceneGraphComponent using the following code snippet:

Code: Select all

#import de.jreality.import.SceneGraphUtility
SceneGraphComponent sgc = ... // produce a SceneGraphComponent containing Geometry
Geometry geom = getFirstGeometry(sgc);
if (geom instanceof IndexedFaceSet) {
...
}
Note the method returns a Geometry. If you expect it to be an IndexedFaceSet, you'll need to check as shown in the code.

If your SceneGraphComponent contains more than one geometry of interest, then you'll probably need to merge the geometries into a single one. To do this, see the tutorial
http://www3.math.tu-berlin.de/jreality/ ... ge_factory
jReality core developer

rafax
Posts: 16
Joined: Sat 17. Apr 2010, 12:39

Re: How to load a geometry (.obj, .wrl, .jvx, ... )

Post by rafax » Wed 8. Sep 2010, 12:20

Hi,

I don't know if you are familiar with the old Half edge data structure of JReality, actually I can not use a converter from the ifs to the heds,
so, I can not process any obj.

Code: Select all

Input input = Input.getInput("6prism.obj");
ifset= (IndexedFaceSet) Readers.read(input).getGeometry();
heds = Converter.hedsFromIfs(ifset);
I got the following errors,

Code: Select all

	at de.jtem.halfedge.jReality.converter.ConverterJR2Heds.getDataListOfTyp(ConverterJR2Heds.java:66)
	at de.jtem.halfedge.jReality.converter.ConverterJR2Heds.ifs2heds(ConverterJR2Heds.java:163)
If you could help me!
Regards

sechel
Posts: 69
Joined: Tue 2. Oct 2007, 09:20

Re: How to load a geometry (.obj, .wrl, .jvx, ... )

Post by sechel » Wed 8. Sep 2010, 16:19

Hi,
please try to invoke the method
IndexedFaceSetUtility.makeConsistentOrientation()
on the IndexedFaceSet and try if this solves the problem.

rafax
Posts: 16
Joined: Sat 17. Apr 2010, 12:39

Re: How to load a geometry (.obj, .wrl, .jvx, ... )

Post by rafax » Wed 22. Sep 2010, 15:31

Hi there,

In fact the brut casting (IndexedFaceSet) doesn't even work. Does anyone has issues for getting IndexedFaceSet from the given Obj?

Regards

sechel
Posts: 69
Joined: Tue 2. Oct 2007, 09:20

Re: How to load a geometry (.obj, .wrl, .jvx, ... )

Post by sechel » Mon 27. Sep 2010, 13:02

Try to do something like this:

Code: Select all

ReaderOBJ reader = new ReaderOBJ();
SceneGraphComponent c = reader.read(file);
Geometry g = SceneGraphUtility.getFirstGeometry(c);
if (g == null) return;
if (g instanceof IndexedFaceSet) {
	IndexedFaceSet ifs = (IndexedFaceSet)g;
	IndexedFaceSetUtility.calculateAndSetNormals(ifs);
}

rafax
Posts: 16
Joined: Sat 17. Apr 2010, 12:39

Re: How to load a geometry (.obj, .wrl, .jvx, ... )

Post by rafax » Thu 30. Sep 2010, 19:49

Thanks! :D

Post Reply