Go Back   AC3D Forums > Resources > AC3D Plugins and Other Resources
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 19th August 2013, 04:23 PM   #1
Blue Baron
Junior Member
Junior member
 
Join Date: Aug 2013
Posts: 6
Default Plugin: Another OBJ Importer/Exporter

I added normal and group support to the OBJ importer written by Dennis Hawthorne and rearranged the group support of the exporter.

My importer additions create another AC3D object for each named group/material combination. If more than one material is used with a named group, the AC3d object is named with both the group name and the material name.

I have only tested the importer and exporter with a couple multi material/texture objects, but it has worked well for me.

Edit: The binaries are a drop in replacement for the existing plugins, but the existing plugins should be renamed or moved out of the plugin directory first so you can go back to them if you need to in the future.

There are windows binaries at: http://3d.sunrisevr.com/ac3d/obj_impexp_win_1_5.zip.

The source is at: http://3d.sunrisevr.com/ac3d/obj_impexp_src_1_5.zip.

Not bad for a first post, right?

Last edited by Blue Baron; 20th October 2013 at 06:57 AM. Reason: Updated links
Blue Baron is offline   Reply With Quote
Old 22nd August 2013, 03:00 AM   #2
Andy
Administrator
Professional user
 
Andy's Avatar
 
Join Date: Jun 2003
Posts: 4,563
Default Re: Plugin: Another OBJ Importer/Exporter

Yes, an extremely good first post!

I'll look at this after the holiday period with a view to adding into AC3D - if that's ok with you?
Andy is offline   Reply With Quote
Old 25th August 2013, 02:34 PM   #3
Blue Baron
Junior Member
Junior member
 
Join Date: Aug 2013
Posts: 6
Default Re: Plugin: Another OBJ Importer/Exporter

Quote:
Originally Posted by Andy View Post
I'll look at this after the holiday period with a view to adding into AC3D - if that's ok with you?
Yes it is. I would be honored if you do.
Blue Baron is offline   Reply With Quote
Old 15th October 2013, 05:07 AM   #4
coldby
Senior Member
Professional user
 
Join Date: Jun 2006
Posts: 102
Default Re: Plugin: Another OBJ Importer/Exporter

OK I'm two months late, but as I tried to download the plugin I found out it wasn't anymore there, and a further search for "AC3D" in Sunrise website gave no result. What should I think?
coldby is offline   Reply With Quote
Old 20th October 2013, 06:58 AM   #5
Blue Baron
Junior Member
Junior member
 
Join Date: Aug 2013
Posts: 6
Default Re: Plugin: Another OBJ Importer/Exporter

Quote:
Originally Posted by coldby View Post
OK I'm two months late, but as I tried to download the plugin I found out it wasn't anymore there, and a further search for "AC3D" in Sunrise website gave no result. What should I think?
Oops, the link changed with the new website. I have updated the links above.
Blue Baron is offline   Reply With Quote
Old 21st October 2013, 02:30 AM   #6
coldby
Senior Member
Professional user
 
Join Date: Jun 2006
Posts: 102
Default Re: Plugin: Another OBJ Importer/Exporter

Thanks Blue Baron!
coldby is offline   Reply With Quote
Old 26th October 2013, 01:07 PM   #7
jentron
Senior Member
Professional user
 
Join Date: Nov 2007
Posts: 139
Default Re: Plugin: Another OBJ Importer/Exporter

So I downloaded the source-code and made a few small changes to get it to compile under Linux. I found a couple of issues right off, I'm not sure if they're linux only or if they affect the Windows binaries as well?

1. If the material library is missing AC3D aborts. The exception thrown by cstrlist isn't being properly caught in cobj.cpp

2. fopen(foo,"rt") doesn't work to translate Mac \r line ending so Mac written .obj files don't load.

Thanks,

Ron
jentron is offline   Reply With Quote
Old 30th October 2013, 06:05 AM   #8
Blue Baron
Junior Member
Junior member
 
Join Date: Aug 2013
Posts: 6
Default Re: Plugin: Another OBJ Importer/Exporter

Quote:
Originally Posted by jentron View Post
So I downloaded the source-code and made a few small changes to get it to compile under Linux. I found a couple of issues right off, I'm not sure if they're linux only or if they affect the Windows binaries as well?

1. If the material library is missing AC3D aborts. The exception thrown by cstrlist isn't being properly caught in cobj.cpp

2. fopen(foo,"rt") doesn't work to translate Mac \r line ending so Mac written .obj files don't load.

Thanks,

Ron
1. When the material library is missing, the plugin should give an error message, then continue and load the mesh using a generic material, and it does so for me.

2. cstrlist should be breaking lines on either \r or \n on line 128 of cstrlist.h (I think \r has a value of 10 and \n has a value of 13). If some other value is being used for line endings, perhaps the 10 and 13 should be replaced with '\r' and '\n' respectively?

What changes did you have to make to get it to compile under Linux?
Blue Baron is offline   Reply With Quote
Old 30th October 2013, 06:31 PM   #9
jentron
Senior Member
Professional user
 
Join Date: Nov 2007
Posts: 139
Default Re: Plugin: Another OBJ Importer/Exporter

Quote:
Originally Posted by Blue Baron View Post
1. When the material library is missing, the plugin should give an error message, then continue and load the mesh using a generic material, and it does so for me.
I see how that should work, but the exception isn't being caught on my build. I'm not good enough with C++ to figure out why (yet)

Quote:
Originally Posted by Blue Baron View Post
2. cstrlist should be breaking lines on either \r or \n on line 128 of cstrlist.h (I think \r has a value of 10 and \n has a value of 13). If some other value is being used for line endings, perhaps the 10 and 13 should be replaced with '\r' and '\n' respectively?
Line 128 is only stripping the carriage return from the end of the line. I think the problem is on line 116:
FILE *fp = fopen( filename, "rt" );

I don't think Linux supports the "t" or splitting the file on \r only, so later line 123:
while( fgets( dataline, maxchars - 1, fp ) != NULL )

ends up getting maxchars - 1 each pass.

Quote:
Originally Posted by Blue Baron View Post
What changes did you have to make to get it to compile under Linux?
Code:
e28bd8d7216841f63d9367691ed0f414018f9c7f
 .gitignore |    5 +++++
 Makefile   |   24 ++++++++++++++++++++++++
 cobj.cpp   |   17 ++++++++++++-----
 cobj.h     |    4 ++++
 obj_in.cpp |   15 ++++++++++-----
 5 files changed, 55 insertions(+), 10 deletions(-)

diff --git a/.gitignore b/.gitignore
index b4c5695..a312457 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,6 @@
 ac_plugin.h
+*.o
+*.p
+Undoable.h
+Undoables.h
+*.p-bak
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..fdb5791
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,24 @@
+CFLAGS = -g
+ALL_CFLAGS = -I/usr/lib/gcc/i486-linux-gnu/4.2.3/include $(CFLAGS)
+CC=gcc-4.2
+
+OBJS=cobj.o obj_in.o
+
+obj_import.p : $(OBJS)
+	ld -shared *.o -o obj_import.p  -L/usr/lib/gcc/i486-linux-gnu/4.2/  -lstdc++ -lgcc_eh
+
+cobj.o : cobj.cpp cobj.h cstrlist.h cexcept.h
+	$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
+
+obj_in.o : obj_in.cpp cobj.h cstrlist.h cexcept.h
+	$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
+install : obj_import.p
+	cp obj_import.p ~/bin/ac3dlx-7011/plugins/
+
+.PHONY : clean
+
+clean :
+	rm *.o obj_import.p
+
+
+
diff --git a/cobj.cpp b/cobj.cpp
index 0dacfc3..b57effc 100644
--- a/cobj.cpp
+++ b/cobj.cpp
@@ -1,11 +1,16 @@
 // TODO: Remove for Mac compiles
-#define WINDOWS
+//#define WINDOWS
 #include "ac_plugin.h"
 
 #include "cobj.h"
 #include <stdlib.h>
 #include "cstrlist.h"
 
+// Added by Ron Jensen for Linux compile
+#define strcmpi strcasecmp
+#define min(a,b) (((a)<(b))?(a):(b))
+#define max(a,b) (((a)>(b))?(a):(b))
+
 //---------------------------------------------------------------------------------------
 CObj::CObj()
 {
@@ -107,7 +112,9 @@ static void cobj_CleanupStrList( CStrList &strlist )
    for( CStrNode *sn = strlist.mHead; sn != NULL; sn = sn->mNext )
    {
       char *pdest = sn->mText;
-      for( char *p = sn->mText; *p != '\0'; ++p )
+      char *p; // moved definition outside of for loop as that violates ISO standards and won't compile under gcc
+
+      for( p = sn->mText; *p != '\0'; ++p )
       {
          if( *p == '\t' )
          {
@@ -312,7 +319,7 @@ void CObj::LoadFromFile( char *fname )
    cobj_CleanupStrList( matlist );
    // Count the materials
    int m = 0;
-   for( sn = matlist.mHead; sn != NULL; sn = sn->mNext )
+   for( CStrNode *sn = matlist.mHead; sn != NULL; sn = sn->mNext )
    {
       if( strlen( sn->mText ) == 0 )
       {
@@ -332,7 +339,7 @@ void CObj::LoadFromFile( char *fname )
    mMCount = m;
    m = 0;
    CObjMat *currmat = NULL;
-   for( sn = matlist.mHead; sn != NULL; sn = sn->mNext )
+   for( CStrNode *sn = matlist.mHead; sn != NULL; sn = sn->mNext )
    {
       if( strlen( sn->mText ) == 0 )
       {
@@ -439,7 +446,7 @@ void CObj::LoadFromFile( char *fname )
    int vidx, nidx, tidx;
    int currmatidx = -1;
    bool smooth = false;
-   for( sn = strlist.mHead; sn != NULL; sn = sn->mNext )
+   for( CStrNode *sn = strlist.mHead; sn != NULL; sn = sn->mNext )
    {
       if( strlen( sn->mText ) == 0 )
       {
diff --git a/cobj.h b/cobj.h
index 7ae07ab..4c1fec9 100644
--- a/cobj.h
+++ b/cobj.h
@@ -5,6 +5,10 @@
 #include <string.h>
 
 #define COBJ_MAXSTRLEN 8192
+// Added by Ron Jensen for Linux compile
+#define strcmpi strcasecmp
+#define min(a,b) (((a)<(b))?(a):(b))
+#define max(a,b) (((a)>(b))?(a):(b))
 
 //---------------------------------------------------------------------------------------
 // Material
diff --git a/obj_in.cpp b/obj_in.cpp
index 026cbc6..531880b 100644
--- a/obj_in.cpp
+++ b/obj_in.cpp
@@ -1,13 +1,18 @@
 #ifdef _WINDOWS
 #ifndef WINDOWS
 #define WINDOWS
+#define snprintf _snprintf
+#define access _access
+#include <io.h>
 #endif
+#else
+#include <unistd.h>
 #endif
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <io.h>
+
 
 #include "ac_plugin.h"
 #include "Undoables.h"
@@ -104,7 +109,7 @@ static ACObject *do_obj_load( char *filename )
             char texfilename[COBJ_MAXSTRLEN];
             strcpy( texfilename, pathname );
             strcat( texfilename, om->mTexture );
-            if( _access( texfilename, 0 ) == 0 )
+            if( access( texfilename, 0 ) == 0 )
             {
                om->mTextureIndex = add_new_texture_opt( texfilename, om->mTexture );
             }
@@ -149,7 +154,7 @@ static ACObject *do_obj_load( char *filename )
            if( grp->mName == NULL )
            {
               char name[256];
-              _snprintf(name, 256, "g%d%d_%s",grp->mGroupIndex, matgrp->mMatIndex, obj.mM[matgrp->mMatIndex].mName );
+              snprintf(name, 256, "g%d%d_%s",grp->mGroupIndex, matgrp->mMatIndex, obj.mM[matgrp->mMatIndex].mName );
               object_set_name( go, "g" );
            }
            else
@@ -163,11 +168,11 @@ static ACObject *do_obj_load( char *filename )
                 char name[256];
                 if ( obj.mM[matgrp->mMatIndex].mName == NULL )
                 {
-                   _snprintf(name, 256, "%s_%d",grp->mName, matgrp->mMatIndex );
+                   snprintf(name, 256, "%s_%d",grp->mName, matgrp->mMatIndex );
                 }
                 else
                 {
-                   _snprintf(name, 256, "%s_%s",grp->mName, obj.mM[matgrp->mMatIndex].mName );
+                   snprintf(name, 256, "%s_%s",grp->mName, obj.mM[matgrp->mMatIndex].mName );
                 }
                 object_set_name( go, name );
              }
jentron is offline   Reply With Quote
Old 1st November 2013, 02:08 AM   #10
Blue Baron
Junior Member
Junior member
 
Join Date: Aug 2013
Posts: 6
Default Re: Plugin: Another OBJ Importer/Exporter

Quote:
Originally Posted by jentron View Post
I see how that should work, but the exception isn't being caught on my build. I'm not good enough with C++ to figure out why (yet)
So is the CStrList::LoadFromFile function not returning on the throw line, and the plugin is crashing before returning? or is the function returning, but the plugin is crashing before/after the error message?

If the first case, you might want to try adding a return statement after the throw line. Or adding a return value, replacing the throw line with a return statement and replacing the try-catch lines in CObj::LoadFromFile with an if statement.


Quote:
Originally Posted by jentron View Post
Line 128 is only stripping the carriage return from the end of the line. I think the problem is on line 116:
FILE *fp = fopen( filename, "rt" );

I don't think Linux supports the "t" or splitting the file on \r only, so later line 123:
while( fgets( dataline, maxchars - 1, fp ) != NULL )

ends up getting maxchars - 1 each pass.
You're right, I misread the code.

Since the OS is not translating \r to \n, the best option might be to convert the file yourself. I did a search for "mac carriage return line feed" and the pages at http://en.wikipedia.org/wiki/Newline and http://www.danielmiessler.com/study/crlf/ have commands to do this.

Otherwise you would have to find/write a fgets replacement that stops on \r.
Blue Baron is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -4. The time now is 10:02 AM.


AC3D Forum
(C) Inivis Limited 2020