Search Unity

Lightmapping of custom meshes

Discussion in 'Editor & General Support' started by maxest, Aug 1, 2012.

  1. maxest

    maxest

    Joined:
    May 2, 2012
    Posts:
    60
    I wrote a class editor that generates meshes in the scene. However, generated lightmaps don't seem to work with those meshes. Is there anything special I should do when generating a mesh from code to make sure lightmaps will work ok with it?
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    The problem my be that only imported Models get a nice unwrapped 2. UV set for light mapping.
    Maybe you can call ModelImporter.generateSecondaryUV to generate this UV set.
     
  3. maxest

    maxest

    Joined:
    May 2, 2012
    Posts:
    60
    The problem is that my mesh has no model importer "attached" to it. In case of a "normal" mesh I can select mesh from its mesh filter component, thus find it in the project hierarchy, and select its importer to change settings. On the other hand, when I select mesh in mesh filter of the object I generated, nothing selects in the project hierarchy.

    Any other ideas?
     
  4. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
  5. maxest

    maxest

    Joined:
    May 2, 2012
    Posts:
    60
    Okay but where do I get input data for it?

    I've just checked Unity's built-in meshes, like plane and cube and they seem to be generated more or less the same way I do generate my mesh. And yet lightmaps show up on those built-in meshes but not on mine. So there is a way to generate this for sure
     
  6. Kuba

    Kuba

    Moderator

    Joined:
    Jan 13, 2009
    Posts:
    416
    zwcloud likes this.
  7. maxest2

    maxest2

    Joined:
    Aug 7, 2012
    Posts:
    1
  8. liszto

    liszto

    Joined:
    Dec 22, 2011
    Posts:
    135
    I want to know how can I do if I got a material with a shader that need 2 UV channel and also need lightmap so the 2nd UV channel ?
    My mesh is composed of 9 submeshs all with differents materials. But I need a little tips only for this with 2 channel uv used.

    If I used the "Generate Lightmapped UV", this destroy the 2nd UV channel cause he probably put it to "default" value when he do that.

    If someone got a solution ?
     
  9. Kuba

    Kuba

    Moderator

    Joined:
    Jan 13, 2009
    Posts:
    416
    If you need to preserve your second UV channel (cause you have some custom data in there for your shader) and create the second UV channel for lightmapping at the same time, you should uncheck "Generate Lightmap UVs", as this will always put the unwrap in your second UV channel.

    If you uncheck that option, you will not get the lightmapping UVs automatically obviously, but you can first move your custom second UV channel to another part of the mesh (e.g. tangents, if you're not using them) and then call Unwrapping.GenerateSecondaryUVSet() (which will put the unwrap into the secondary UV set). You can do that either from an asset postprocessor or from an Editor script.

    It's probably easier to put your custom data into another channel in your modelling app though.
     
  10. PAHeartBeat

    PAHeartBeat

    Joined:
    Jul 11, 2012
    Posts:
    76
    Hi

    I have tried it on it combined mesh, when I tried to regenerated Secondury UV Changel, editor gona to freeze. I am regenarte Secondry UV for Lightmap / lightbaking process. I give Unwarp paramater as bellow
    angleError=88;
    areaError=4;
    hardAngle=8;
    packMargin=15;

    That mesh are combined in Editor using MeshCombine Utility. If any have face that issue please guide...

    Thanks in advance

    edit: I am using Unity 4.5
     
    Last edited: Aug 6, 2014
  11. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    265
    *Edit* actually, you might need to use UnwrapParam.SetDefaults( out param ); before editing the parameters.. it doesn't freeze up when I do it this way:

    UnwrapParam param = new UnwrapParam();
    UnwrapParam.SetDefaults( out param );
    Unwrapping.GenerateSecondaryUVSet( mesh, param );

    I haven't tried non-default params yet though...
     
    Last edited: Oct 19, 2014
    Claytonious likes this.