Hi, 

What's the status of lib3ds these days?  It doesn't seem to have had a
release in many years, but a brief glance at the mailing list archives
shows a fair bit of activity there.

Also, the following is a patch I wrote to add handling for "object
chunks" (HIDDEN etc); I originally sent this to the debian lib3ds
maintainer, but he seem to have disappeared:


lib3ds ignores various "object flag" chunks like LIB3DS_OBJ_HIDDEN
(basically all chunks with prefix "LIB3DS_OBJ_").

This is particularly annoying in the case of LIB3DS_OBJ_HIDDEN, because
many 3ds models contain hidden elements which are not intended to be
rendered (e.g., multiple copies of part of the model might be provided,
each in a different state, with only one not marked as hidden); when the
hidden parts _are_ rendered, it can screw up the result.

I've attached a patch which handles this chunks.  It basically adds a
new field "obj_flags" to the Lib3dsMesh, Lib3dsCamera, and Lib3dsCamera
structures, and a new enum Lib3dsObjFlags.  Each bit of the obj_flags
field corresponds to one value in Lib3dsObjFlags.

BTW, compiling lib3ds with gcc-4.1 resulted in a non-working library
(lots of strange problems, basically it didn't parse 3ds files
correctly).  Compiling with gcc-3.3 worked fine.


diff -ruN -X../diff.xcl lib3ds-1.2.0/lib3ds/camera.h lib3ds-1.2.0-miles-20060404/lib3ds/camera.h
--- lib3ds-1.2.0/lib3ds/camera.h	2001-07-08 04:05:30.000000000 +0900
+++ lib3ds-1.2.0-miles-20060404/lib3ds/camera.h	2006-04-04 17:04:30.000000000 +0900
@@ -45,6 +45,7 @@
     Lib3dsBool see_cone;
     Lib3dsFloat near_range;
     Lib3dsFloat far_range;
+    Lib3dsDword obj_flags;
 }; 
 
 extern LIB3DSAPI Lib3dsCamera* lib3ds_camera_new(const char *name);
diff -ruN -X../diff.xcl lib3ds-1.2.0/lib3ds/file.c lib3ds-1.2.0-miles-20060404/lib3ds/file.c
--- lib3ds-1.2.0/lib3ds/file.c	2001-08-07 19:25:43.000000000 +0900
+++ lib3ds-1.2.0-miles-20060404/lib3ds/file.c	2006-04-04 18:20:44.000000000 +0900
@@ -308,6 +308,10 @@
   Lib3dsChunk c;
   char name[64];
   Lib3dsWord chunk;
+  Lib3dsWord obj_flags = 0;
+  Lib3dsMesh *mesh = 0;
+  Lib3dsCamera *camera = 0;
+  Lib3dsLight *light = 0;
 
   if (!lib3ds_chunk_read_start(&c, LIB3DS_NAMED_OBJECT, io)) {
     return(LIB3DS_FALSE);
@@ -322,8 +326,6 @@
     switch (chunk) {
       case LIB3DS_N_TRI_OBJECT:
         {
-          Lib3dsMesh *mesh;
-
           mesh=lib3ds_mesh_new(name);
           if (!mesh) {
             return(LIB3DS_FALSE);
@@ -337,8 +339,6 @@
         break;
       case LIB3DS_N_CAMERA:
         {
-          Lib3dsCamera *camera;
-
           camera=lib3ds_camera_new(name);
           if (!camera) {
             return(LIB3DS_FALSE);
@@ -352,8 +352,6 @@
         break;
       case LIB3DS_N_DIRECT_LIGHT:
         {
-          Lib3dsLight *light;
-
           light=lib3ds_light_new(name);
           if (!light) {
             return(LIB3DS_FALSE);
@@ -365,11 +363,49 @@
           lib3ds_file_insert_light(file, light);
         }
         break;
+
+	/* Object flag chunks */
+      case LIB3DS_OBJ_HIDDEN:
+	obj_flags |= LIB3DS_OBJF_HIDDEN;
+	break;
+      case LIB3DS_OBJ_VIS_LOFTER:
+	obj_flags |= LIB3DS_OBJF_VIS_LOFTER;
+	break;
+      case LIB3DS_OBJ_DOESNT_CAST:
+	obj_flags |= LIB3DS_OBJF_DOESNT_CAST;
+	break;
+      case LIB3DS_OBJ_DONT_RECVSHADOW:
+	obj_flags |= LIB3DS_OBJF_DONT_RECVSHADOW;
+	break;
+      case LIB3DS_OBJ_MATTE:
+	obj_flags |= LIB3DS_OBJF_MATTE;
+	break;
+      case LIB3DS_OBJ_FAST:
+	obj_flags |= LIB3DS_OBJF_FAST;
+	break;
+      case LIB3DS_OBJ_PROCEDURAL:
+	obj_flags |= LIB3DS_OBJF_PROCEDURAL;
+	break;
+      case LIB3DS_OBJ_FROZEN:
+	obj_flags |= LIB3DS_OBJF_FROZEN;
+	break;
+
       default:
         lib3ds_chunk_unknown(chunk);
     }
   }
   
+  /* Set the object flags; we do this after the loop so that we don't
+     depend on the chunk order.  */
+  if (obj_flags) {
+    if (mesh)
+      mesh->obj_flags = obj_flags;
+    if (light)
+      light->obj_flags = obj_flags;
+    if (camera)
+      camera->obj_flags = obj_flags;
+  }
+
   lib3ds_chunk_read_end(&c, io);
   return(LIB3DS_TRUE);
 }
@@ -762,6 +798,36 @@
   return(LIB3DS_TRUE);
 }
 
+static void
+obj_flags_write(Lib3dsDword obj_flags, Lib3dsIo *io)
+{
+  Lib3dsChunk c;
+  c.size = 6;
+  c.chunk = LIB3DS_OBJ_HIDDEN;
+  if (obj_flags & LIB3DS_OBJF_HIDDEN)
+    lib3ds_chunk_write (&c, io);
+  c.chunk = LIB3DS_OBJ_VIS_LOFTER;
+  if (obj_flags & LIB3DS_OBJF_VIS_LOFTER)
+    lib3ds_chunk_write (&c, io);
+  c.chunk = LIB3DS_OBJ_DOESNT_CAST;
+  if (obj_flags & LIB3DS_OBJF_DOESNT_CAST)
+    lib3ds_chunk_write (&c, io);
+  c.chunk = LIB3DS_OBJ_DONT_RECVSHADOW;
+  if (obj_flags & LIB3DS_OBJF_DONT_RECVSHADOW)
+    lib3ds_chunk_write (&c, io);
+  c.chunk = LIB3DS_OBJ_MATTE;
+  if (obj_flags & LIB3DS_OBJF_MATTE)
+    lib3ds_chunk_write (&c, io);
+  c.chunk = LIB3DS_OBJ_FAST;
+  if (obj_flags & LIB3DS_OBJF_FAST)
+    lib3ds_chunk_write (&c, io);
+  c.chunk = LIB3DS_OBJ_PROCEDURAL;
+  if (obj_flags & LIB3DS_OBJF_PROCEDURAL)
+    lib3ds_chunk_write (&c, io);
+  c.chunk = LIB3DS_OBJ_FROZEN;
+  if (obj_flags & LIB3DS_OBJF_FROZEN)
+    lib3ds_chunk_write (&c, io);
+}
 
 static Lib3dsBool
 mdata_write(Lib3dsFile *file, Lib3dsIo *io)
@@ -841,6 +907,8 @@
       }
       lib3ds_io_write_string(io, p->name);
       lib3ds_camera_write(p,io);
+      if (p->obj_flags)
+	obj_flags_write (p->obj_flags, io);
       if (!lib3ds_chunk_write_end(&c,io)) {
         return(LIB3DS_FALSE);
       }
@@ -857,6 +925,8 @@
       }
       lib3ds_io_write_string(io,p->name);
       lib3ds_light_write(p,io);
+      if (p->obj_flags)
+	obj_flags_write (p->obj_flags, io);
       if (!lib3ds_chunk_write_end(&c,io)) {
         return(LIB3DS_FALSE);
       }
@@ -873,6 +943,8 @@
       }
       lib3ds_io_write_string(io, p->name);
       lib3ds_mesh_write(p,io);
+      if (p->obj_flags)
+	obj_flags_write (p->obj_flags, io);
       if (!lib3ds_chunk_write_end(&c,io)) {
         return(LIB3DS_FALSE);
       }
diff -ruN -X../diff.xcl lib3ds-1.2.0/lib3ds/light.h lib3ds-1.2.0-miles-20060404/lib3ds/light.h
--- lib3ds-1.2.0/lib3ds/light.h	2001-07-08 04:05:30.000000000 +0900
+++ lib3ds-1.2.0-miles-20060404/lib3ds/light.h	2006-04-04 17:22:23.000000000 +0900
@@ -63,6 +63,7 @@
     Lib3dsFloat ray_bias;
     Lib3dsFloat hot_spot;
     Lib3dsFloat fall_off;
+    Lib3dsDword obj_flags;
 }; 
 
 extern LIB3DSAPI Lib3dsLight* lib3ds_light_new(const char *name);
diff -ruN -X../diff.xcl lib3ds-1.2.0/lib3ds/mesh.h lib3ds-1.2.0-miles-20060404/lib3ds/mesh.h
--- lib3ds-1.2.0/lib3ds/mesh.h	2001-07-08 04:05:30.000000000 +0900
+++ lib3ds-1.2.0-miles-20060404/lib3ds/mesh.h	2006-04-04 17:04:11.000000000 +0900
@@ -110,6 +110,7 @@
     Lib3dsFace *faceL;
     Lib3dsBoxMap box_map;
     Lib3dsMapData map_data;
+    Lib3dsDword obj_flags;
 }; 
 
 extern LIB3DSAPI Lib3dsMesh* lib3ds_mesh_new(const char *name);
diff -ruN -X../diff.xcl lib3ds-1.2.0/lib3ds/types.h lib3ds-1.2.0-miles-20060404/lib3ds/types.h
--- lib3ds-1.2.0/lib3ds/types.h	2001-07-08 04:05:30.000000000 +0900
+++ lib3ds-1.2.0-miles-20060404/lib3ds/types.h	2006-04-04 18:20:10.000000000 +0900
@@ -118,6 +118,19 @@
 
 typedef struct _Lib3dsNode Lib3dsNode;
 
+typedef enum _Lib3dsObjFlags {
+    /* We use the prefix "LIB3DS_OBJF_" for these flags as LIB3DS_OBJ_ is
+       already used by the corresponding chunks.  */
+    LIB3DS_OBJF_HIDDEN		= 0x0001,
+    LIB3DS_OBJF_VIS_LOFTER	= 0x0002,
+    LIB3DS_OBJF_DOESNT_CAST	= 0x0004,
+    LIB3DS_OBJF_MATTE		= 0x0008,
+    LIB3DS_OBJF_FAST		= 0x0010,
+    LIB3DS_OBJF_PROCEDURAL	= 0x0020,
+    LIB3DS_OBJF_FROZEN		= 0x0040,
+    LIB3DS_OBJF_DONT_RECVSHADOW = 0x0080
+} Lib3dsObjFlags;
+
 typedef union _Lib3dsUserData {
     void *p;
     Lib3dsIntd i;
Files ../orig/lib3ds-1.2.0/tools/3ds2m and ./tools/3ds2m differ
Files ../orig/lib3ds-1.2.0/tools/3dsdump and ./tools/3dsdump differ

Thanks,

-Miles

-- 
"Suppose we've chosen the wrong god. Every time we go to church we're
just making him madder and madder." -- Homer Simpson
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
lib3ds-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lib3ds-devel

Reply via email to