Obj2JME group naming patch

Hello!



I've done an addition to OBJ 2 JME converter to support 3D Studio Max generated files.

It only exports groups of objects and this cause the current converter to name nodes as temp1, temp2, and so on…



So I've managed to name generated object like the group in which they are defined if the object name is missing.



Here follows the patch:



Index: src/com/jmex/model/converters/ObjToJme.java
===================================================================
--- src/com/jmex/model/converters/ObjToJme.java   (revision 4059)
+++ src/com/jmex/model/converters/ObjToJme.java   (working copy)
@@ -99,6 +99,8 @@
     private MaterialGrouping curGroup;
     /** Last 'Object' name in the file */
     private String curObjectName = null;
+    /** Last 'Group' name in the file */
+    private String curGroupName = null;
     /** Default material group for groups without a material */
     private MaterialGrouping defaultMaterialGroup;
     /** Maps material names to the actual material object * */
@@ -187,8 +189,7 @@
             ArraySet thisSet = materialSets.get(thisGroup);
             if (thisSet.indexes.size() < 3)
                 continue;
-            TriMesh thisMesh = new TriMesh(thisSet.objName == null ? "temp" + i
-                    : thisSet.objName);
+            TriMesh thisMesh = new TriMesh(thisSet.objName == null ? "temp" + i : thisSet.objName);
             Vector3f[] vert = new Vector3f[thisSet.sets.size()];
             Vector3f[] norm = new Vector3f[vert.length];
             Vector2f[] text = new Vector2f[vert.length];
@@ -269,9 +270,10 @@
         } else if ("g".equals(parts[0])) {
             // see what the material name is if there isn't a name, assume its
             // the default group
-            if (parts.length >= 2 && materialNames.get(parts[1]) != null
-                    && materialNames.get(parts[1]) != null)
+            if (parts.length >= 2 && materialNames.get(parts[1]) != null) {
+                curGroupName = parts[1];
                 curGroup = materialNames.get(parts[1]);
+            }
             else
                 setDefaultGroup();
             return;
@@ -395,8 +397,14 @@
 
     private void addFaces(String[] parts) {
         ArraySet thisMat = materialSets.get(curGroup);
-        if (thisMat.objName == null && curObjectName != null)
-            thisMat.objName = curObjectName;
+        if (thisMat.objName == null) {
+            if (curObjectName != null) {
+                thisMat.objName = curObjectName;
+            }
+            else if (curGroupName != null) {
+                thisMat.objName = curGroupName;
+            }  
+        }
         IndexSet first = new IndexSet(parts[1]);
         int firstIndex = thisMat.findSet(first);
         IndexSet second = new IndexSet(parts[2]);



Cheers,
Eduard

Hey Eduard,



can you post a non-max OBJ and a max-OBJ so we can see the difference?  you can text edit OBJ files and just post the text here if you want (if they are less than 10,000 lines each).  Also, if you need an non-max model; either let me know or export one with blender (just a couple of cubes side by side would be enough I think).

I suppose the max exporter uses the "g" (group) statement to name the object instead of the "o" (object) statement which causes the jME importer to simply use the default name ("temp"). I think applying this patch is fine, you can still name your objects with the "o" keyword if you choose which means both old and new functionality is supported.

Max currently export layers as group without specifying objects name.

Momoko_Fan is right and i think my patch doesn't affect previous behaviour as it fallback to group name only if object name is missing.



Thanks :wink:

Is everyone happy?

i am, please commit, i am waiting for it  :wink:

happy too.

Commited, r4071