Accessing group names in OBJ files in JMonkey


I’m a fairly new JMonkey, however I’m writing a racing car game in which I use a Basic program to create an OBJ file of the track and Terrain and load this into my JMonkey game.

All OK so far with player control, but what I want to do now is program autonomous vehicle opponents and to do this I need to get the current location of my cars on the track.

The OBJ file defines various track segments thus:

Road faces

usemtl Road
g RoadSeg:0
f 2/3 7/2 6/1
f 2/3 3/4 7/2
g RoadSeg:1
f 6/3 11/2 10/1
f 6/3 7/4 11/2
g RoadSeg:2
f 10/3 15/2 14/1
f 10/3 11/4 15/2
g RoadSeg:3
f 14/3 19/2 18/1
f 14/3 15/4 19/2
g RoadSeg:4
f 18/3 23/2 22/1
f 18/3 19/4 23/2

So I need to access the vertices for RoadSeg:n and compare them to the location of my vehicles.

If I use the following code which I found on this forum somewhere it can’t find the segment.

roadSpatial is the loaded OBJ file

Is this the right code to use ? Does JMonkey recognise the g tag in OBJ files ?

Is there a better way of doing this ?

 private Geometry findGeom(Spatial spatial, String name)
        if (spatial instanceof Node) {
            Node node = (Node) spatial;
            for (int i = 0; i < node.getQuantity(); i++) {
                Spatial child = node.getChild(i);
                System.out.println("Child Spatial=" + child.getName());
                Geometry result = findGeom(child, name);
                if (result != null) {
                    return result;
        } else if (spatial instanceof Geometry) {
            System.out.println("Geometry name=" + spatial.getName());
            if (spatial.getName().startsWith(name)) {
                return (Geometry) spatial;
        return null;

    private void FindRoadSegment()
        Geometry Segment;
        Segment = findGeom(roadSpatial,"RoadSeg:1");
        if(Segment==null )
            System.out.println("Cannot find road Segment Geometry");

No, the default JMonkey .OBJ importer does not recognize the geometry names. Can’t comment on if that code does what you want to, there is however a solution based on a modified OBJLoader class. See this thread:

Thank you for that, I’ll check it out.

This worked, but caused a large decrease in the frame rate. You never get something for nothing I suppose.