Hi!
Any ideas how to use AssetBundles with lightmapped objects?
We have baked lightmaps (with built-in Beast) and built an AssetBundle.
When the bundle is loaded, the lightmap data is gone…
Is this bug or “feature”?
BR, Juha
Hi!
Any ideas how to use AssetBundles with lightmapped objects?
We have baked lightmaps (with built-in Beast) and built an AssetBundle.
When the bundle is loaded, the lightmap data is gone…
Is this bug or “feature”?
BR, Juha
BTW, this is the editor script we use to build AssetBundles. Anything wrong here if we want lightmaps to work?
@MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")
static function ExportResource () {
// Bring up save panel
var path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0)
{
// Build the resource file from the active selection.
var selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
Selection.objects = selection;
}
}
BR, Juha
Same problem here, maybe someone from UT can shoot us a yes/no/coming later
Any news about this issue? Sent a question to support almost week ago, but got no reply.
Starting to think, that dedicated support channel for paying pro users could be nice…
Same problem here …
Got answer from Unity Support. The message was that you have to do it manually (which I’ll interpret as to get lightmap index and altas info when building asset bundles and somehow remap that data when assets are loaded). The actual implementation was left as an exercise…
It seems like they “forgot” to implement the lighthmap dependency to AssetBundles, so now every developer have to write their own
hack… Oh dear!
OK, after some testing, here are some tips to proceed…
You don’t need to sore lightmap index and atlas info, they are imported with the objects… that’s good.
You need to include lightmap textures to bundle when building it…
When loading bundle, assign right lightmap textures to right objects and write correct settings to
global lightmapsetting…
Included “just for testing” script as a starting point (ie. it just happen to work in my test scene as the textures
happen to be in proper order etc. In general, mapping to right textures have to be handled some other way…
using UnityEngine;
using System.Collections;
public class AssetBundleLoader : MonoBehaviour
{
Texture2D[] LMTexture = new Texture2D[2];
// Use this for initialization
IEnumerator Start () {
WWW www = new WWW("file://" + Application.dataPath + "/../../BundleLightmap/TestLM.unity3d");
yield return www;
Debug.Log("LOAD:"+ www.assetBundle.mainAsset);
int idx=0;
Object[] obj = www.assetBundle.LoadAll();
foreach (Object o in obj)
{
Debug.Log( o.name);
if (o.GetType() == typeof(GameObject))
{
Instantiate(o);
}
else if (o.GetType() == typeof(Texture2D))
{
LMTexture[idx++] = o as Texture2D;
}
}
LightmapData lmData = new LightmapData();
lmData.lightmapFar = LMTexture[0];
lmData.lightmapNear = LMTexture[1];
LightmapData[] lmDataSet = new LightmapData[1];
lmDataSet[0] = lmData;
LightmapSettings.lightmapsMode = LightmapsMode.Dual;
LightmapSettings.lightmaps = lmDataSet;
}
}
Oh,Thanks.
working it…
sigh…Big problem…
When loading asset bundle and reconstructing the lightmap data, one “hack” I’m using is to look at the attached lightmap texture names.
Currently the generated lightmaps are named as “LightmapNear-0”, “LightmapFar-0” etc. You can use those names to
decode what was the lightmap settings when assets were built… If there is only “Far” lightmaps, the single mode is used.
And the number in the filename is the lightmap index.
Let’s hope this naming convention will not change before we get the proper fix…
Bump
Script to do “set LightmapNear-*”? my god…
Hey I tried to implement something similar to this: loading assetbundles nad reconstructing lightmap data. I tested it with an assetbundle that has several lightmaps. Everything works fine except one tiny detail: in my assetbundle, the renderer lightmapIndex field doesn’t get saved properly
Bad bad bad
Has anyone found a solution for that?
The only solution I found to this problem is to actually not use assetbundles, but to create streamed scenes and load them additively.
The scene maintains all the lightmapping info so you don’t have to worry about rebuilding them on load.
That’s a nice solution if you can live with streamed scenes.
Only one BIG problem → streamed scenes are not compatible with iphone
I have no idea why… In fact when I came up with the solution on pc I was thinking I would just put my streamed scenes in the same local focal as my assetbundles for iphone deployment, but for some reason building streamed scenes is not permitted on iphone.
Did you actually get this solution to work? Tried the same here but it seems the renderer.lightmaIndex gets lost when building the assetBundle.