View Single Post
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