![]() |
#1 |
Junior Member
Junior member
Join Date: Aug 2013
Posts: 6
|
![]()
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 |
![]() |
![]() |
![]() |
#2 |
Administrator
Professional user
Join Date: Jun 2003
Posts: 4,565
|
![]()
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? |
![]() |
![]() |
![]() |
#3 |
Junior Member
Junior member
Join Date: Aug 2013
Posts: 6
|
![]() |
![]() |
![]() |
![]() |
#4 |
Senior Member
Professional user
Join Date: Jun 2006
Posts: 102
|
![]()
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?
|
![]() |
![]() |
![]() |
#5 |
Junior Member
Junior member
Join Date: Aug 2013
Posts: 6
|
![]() |
![]() |
![]() |
![]() |
#6 |
Senior Member
Professional user
Join Date: Jun 2006
Posts: 102
|
![]()
Thanks Blue Baron!
![]() |
![]() |
![]() |
![]() |
#7 |
Senior Member
Professional user
Join Date: Nov 2007
Posts: 139
|
![]()
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 |
![]() |
![]() |
![]() |
#8 | |
Junior Member
Junior member
Join Date: Aug 2013
Posts: 6
|
![]() Quote:
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? |
|
![]() |
![]() |
![]() |
#9 | |||
Senior Member
Professional user
Join Date: Nov 2007
Posts: 139
|
![]() Quote:
Quote:
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:
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 ); } |
|||
![]() |
![]() |
![]() |
#10 | ||
Junior Member
Junior member
Join Date: Aug 2013
Posts: 6
|
![]() Quote:
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:
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. |
||
![]() |
![]() |
![]() |
|
|