private static CollectionData GetCollectionArray(Rig3DCollection collection) { var objs = FlattenChildren(collection.transform); var bounds = new Bounds(); var array = new JArray(); foreach (var behaviour in objs) { var jobj = CreateJsonObject(behaviour, collection.Exports, collection.NormalizeDepth); if (collection.CalculateBounds) { foreach (var renderer in behaviour.GetComponentsInChildren<Renderer>()) { bounds.Encapsulate(renderer.bounds); } } if (collection.CullingLayer >= 0) { jobj.Add("cullingLayer", collection.CullingLayer); } array.Add(jobj); } return new CollectionData { Collection = array, Bounds = bounds, }; }
private static void AddCollectionToMeshArray(Rig3DCollection collection, ref Dictionary<Mesh, MeshData> map) { var objs = FlattenChildren(collection.transform); foreach (var behaviour in objs) { var jobj = CreateJsonObject(behaviour.parent, collection.Exports, collection.NormalizeDepth); var mesh = behaviour.GetComponentInChildren<MeshFilter>(); if (mesh == null) { Debug.LogWarningFormat("Object {0} was marked as static mssh but did not contain a mesh filter component", behaviour); continue; } MeshData meshData; map.TryGetValue(mesh.sharedMesh, out meshData); if (meshData == null) { Debug.LogWarningFormat("Could not find mesh data for objcet {0} (mesh: {1})", behaviour, mesh.sharedMesh.name); continue; } if (collection.CullingLayer >= 0) { jobj.Add("cullingLayer", collection.CullingLayer); } if (collection.GetTexture) { var renderer = behaviour.GetComponentInChildren<MeshRenderer>(); var texture = renderer.sharedMaterial.GetTexture("_MainTex"); var path = AssetDatabase.GetAssetPath(texture); jobj.Add("textureName", Path.GetFileName(path)); } meshData.Instances.Add(jobj); } }