블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2318)N
Unity3D (567)N
Programming (471)
Unreal (4)
Gamebryo (56)
Tip & Tech (183)
협업 (34)
3DS Max (3)
Game (12)
Utility (116)
Etc (92)
Link (31)
Portfolio (19)
Subject (90)
iOS,OSX (38)
Android (13)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (1)
Memories (19)
Interest (37)
Thinking (36)
한글 (26)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (19)
Exercise (3)
나만의 맛집 (2)
냥이 (9)
육아 (7)
Total1,339,007
Today20
Yesterday214
Statistics Graph

달력

« » 2019.11
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

공지사항

태그목록

Answer by misterPantoni 

After a lot of tests and googeling around i found a working solution, although i am not totally happy with it:

If you store the lightmaps and the LightmapSettings for each renderer in a custom script, you can load the lightmaps on runtime. Look at this forum post and the sample project provided there, this is how i got it to work:

https://forum.unity3d.com/threads/problems-with-instantiating-baked-prefabs.324514/

The "bad" thing is, that now i need to have a duplicate of the lightmaps stored in my custom script - whenever i try to assign the lightmaps which are "in the scene" (and also after loading the assetbundle, at least in the editor i can see them), they somehow are not beeing loaded correcty by the renderers and i get wrong lightmap positions. So i have to store the lightmaps as extra texture and add them to the lightmap array to use them.

EDIT: The problems with the wrong index were just some indices i messed up - now i got it working the way i want it to, without duplicate Lightmaps. Here is the working script, just place it on the parent object of whatever is lightmapped in your scene you want to use as an assetbundle:

  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class SceneAssetBundleLightmaps : MonoBehaviour{
  5. [System.Serializable]
  6. struct RendererInfo{
  7. public Renderer renderer;
  8. public int lightmapIndex;
  9. public Vector4 lightmapOffsetScale;
  10. }
  11. [SerializeField]
  12. RendererInfo[] m_RendererInfo;
  13. void Awake (){
  14. if (m_RendererInfo == null || m_RendererInfo.Length == 0)
  15. return;
  16. ApplyRendererInfo(m_RendererInfo);
  17. }
  18. static void ApplyRendererInfo (RendererInfo[] infos){
  19. for (int i=0;i<infos.Length;i++){
  20. var info = infos[i];
  21. info.renderer.lightmapIndex = info.lightmapIndex;
  22. info.renderer.lightmapScaleOffset = info.lightmapOffsetScale;
  23. }
  24. }
  25. #if UNITY_EDITOR
  26. [UnityEditor.MenuItem("Assets/Assign Scene Assetbundle Lightmaps")]
  27. static void GenerateLightmapInfo (){
  28. if (UnityEditor.Lightmapping.giWorkflowMode != UnityEditor.Lightmapping.GIWorkflowMode.OnDemand){
  29. Debug.LogError("ExtractLightmapData requires that you have baked you lightmaps and Auto mode is disabled.");
  30. return;
  31. }
  32. //UnityEditor.Lightmapping.Bake();
  33. SceneAssetBundleLightmaps[] prefabs = FindObjectsOfType<SceneAssetBundleLightmaps>();
  34. foreach (var instance in prefabs){
  35. var gameObject = instance.gameObject;
  36. var rendererInfos = new List<RendererInfo>();
  37. var lightmaps = new List<Texture2D>();
  38. GenerateLightmapInfo(gameObject, rendererInfos, lightmaps);
  39. instance.m_RendererInfo = rendererInfos.ToArray();
  40. }
  41. }
  42. static void GenerateLightmapInfo (GameObject root, List<RendererInfo> rendererInfos, List<Texture2D> lightmaps){
  43. var renderers = root.GetComponentsInChildren<MeshRenderer>();
  44. foreach (MeshRenderer renderer in renderers){
  45. if (renderer.lightmapIndex != -1)
  46. {
  47. RendererInfo info = new RendererInfo();
  48. info.renderer = renderer;
  49. info.lightmapOffsetScale = renderer.lightmapScaleOffset;
  50. info.lightmapIndex = renderer.lightmapIndex;
  51. rendererInfos.Add(info);
  52. }
  53. }
  54. }
  55. #endif
  56. }



[출처] http://answers.unity3d.com/questions/1278569/unity-5-lightmapped-scene-assetbundle-problem.html

'Unity3D > LightMap' 카테고리의 다른 글

[펌] Unity 5 lightmapped scene assetbundle problem  (0) 2017.04.19
유니티5 라이트 맵 팁  (0) 2015.06.19
LightMapSize 조절  (0) 2014.03.18
Unity Lightmapping Tips, Tricks and Thoughts  (0) 2014.03.18
Posted by blueasa

댓글을 달아 주세요