Adrian Bedeau | 22 Jul 2008 03:03
Picon

multiple materials per mesh - new in lib3ds 2.0 ?

Hi,

In looking through this forum a few weeks back, I found this post http://sourceforge.net/mailarchive/forum.php?thread_name=1074644471.3365.48.camel%40localhost&forum_name=lib3ds-devel
from which I concluded that one mesh can only have one material. However, in the upcoming 2.0 release of lib3ds there is an example called cube.c which now leads me to think otherwise. Below is the relevant part of cube.c:
//-------------------------------------------------------------------------------
//first material
  Lib3dsMaterial *mat = lib3ds_material_new("c_tex");
      lib3ds_file_insert_material(file, mat, -1);
      strcpy(mat->texture1_map.name, "cube.tga");
      mat->texture1_map.percent = 1.0;
//second material
      mat = lib3ds_material_new("c_red");
      lib3ds_file_insert_material(file, mat, -1);
      mat->diffuse[0] = 1.0;
      mat->diffuse[1] = 0.0;
      mat->diffuse[2] = 0.0;
//third material
      mat = lib3ds_material_new("c_blue");
      lib3ds_file_insert_material(file, mat, -1);
      mat->diffuse[0] = 0.0;
      mat->diffuse[1] = 0.0;
      mat->diffuse[2] = 1.0;
   }

      Lib3dsMesh *mesh = lib3ds_mesh_new("cube");

      for (i = 0; i < 8; ++i) {
         mesh->faces[i].material = 0;      //I think this is applying the first material to faces  0 through 7
      }
      for (i = 0; i < 2; ++i) {
         mesh->faces[8+i].material = 1; //I think this is applyingthe second material to faces  8 through 9
      }
      for (i = 0; i < 2; ++i) {
         mesh->faces[10+i].material = 2; //I think this is applyingthe third material to faces  10 through 11
      }

//-------------------------------------------------------------------------------

The cube written out has 1 blue face (2 triangles), 1 red face, and 4 grey face. From this it seems that you can have more than one materials per mesh, but one material per face. I am wondering if this is new in lib3ds2.0 or have I always misunderstood that you can have only 1 material per mesh? 

Thank you for taking time to help me.

Adrian
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
lib3ds-devel mailing list
lib3ds-devel@...
https://lists.sourceforge.net/lists/listinfo/lib3ds-devel
Kyprianidis, Jan Eric | 22 Jul 2008 09:30
Picon
Picon

Re: multiple materials per mesh - new in lib3ds 2.0 ?

hi,
the 3ds format allows material assignment per face (and both lib3ds 1.x 
and 2.0 support this).
Note that material handling is a little bit different in lib3ds 2.0.
Indexes are used instead of strings to waste less memory.
--jan eric

Adrian Bedeau wrote:
> Hi,
>
> In looking through this forum a few weeks back, I found this post 
>
http://sourceforge.net/mailarchive/forum.php?thread_name=1074644471.3365.48.camel%40localhost&forum_name=lib3ds-devel 
> <http://sourceforge.net/mailarchive/forum.php?thread_name=1074644471.3365.48.camel%40localhost&forum_name=lib3ds-devel>
> from which I concluded that one mesh can only have one material. 
> However, in the upcoming 2.0 release of lib3ds there is an example 
> called cube.c which now leads me to think otherwise. Below is the 
> relevant part of cube.c:
> //-------------------------------------------------------------------------------
> //first material
>   Lib3dsMaterial *mat = lib3ds_material_new("c_tex");
>       lib3ds_file_insert_material(file, mat, -1);
>       strcpy(mat->texture1_map.name <http://texture1_map.name>, 
> "cube.tga");
>       mat->texture1_map.percent = 1.0;
> //second material
>       mat = lib3ds_material_new("c_red");
>       lib3ds_file_insert_material(file, mat, -1);
>       mat->diffuse[0] = 1.0;
>       mat->diffuse[1] = 0.0;
>       mat->diffuse[2] = 0.0;
> //third material
>       mat = lib3ds_material_new("c_blue");
>       lib3ds_file_insert_material(file, mat, -1);
>       mat->diffuse[0] = 0.0;
>       mat->diffuse[1] = 0.0;
>       mat->diffuse[2] = 1.0;
>    }
>
>       Lib3dsMesh *mesh = lib3ds_mesh_new("cube");
>
>       for (i = 0; i < 8; ++i) {
>          mesh->faces[i].material = 0;      //I think this is applying 
> the first material to faces  0 through 7
>       }
>       for (i = 0; i < 2; ++i) {
>          mesh->faces[8+i].material = 1; //I think this is applyingthe 
> second material to faces  8 through 9
>       }
>       for (i = 0; i < 2; ++i) {
>          mesh->faces[10+i].material = 2; //I think this is applyingthe 
> third material to faces  10 through 11
>       }
>
> //------------------------------------------------------------------------------- 
>
>
> The cube written out has 1 blue face (2 triangles), 1 red face, and 4 
> grey face. From this it seems that you can have more than one 
> materials per mesh, but one material per face. I am wondering if this 
> is new in lib3ds2.0 or have I always misunderstood that you can have 
> only 1 material per mesh? 
>
> Thank you for taking time to help me.
>
> Adrian
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> ------------------------------------------------------------------------
>
> _______________________________________________
> lib3ds-devel mailing list
> lib3ds-devel@...
> https://lists.sourceforge.net/lists/listinfo/lib3ds-devel
>   

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

Gmane