public void ProcessVolumeParts(HEU_SessionBase session, List <HEU_PartData> volumeParts) { int numVolumeParts = volumeParts.Count; if (_volumeCache == null) { if (numVolumeParts == 0) { return; } _volumeCache = ScriptableObject.CreateInstance <HEU_VolumeCache>(); _volumeCache.Initialize(this); ParentAsset.AddVolumeCache(_volumeCache); } else if (numVolumeParts == 0) { DestroyVolumeCache(); return; } _volumeCache.GenerateFromParts(session, ParentAsset, volumeParts); }
// LOGIC ----------------------------------------------------------------------------------------------------- public static List<HEU_VolumeCache> UpdateVolumeCachesFromParts(HEU_SessionBase session, HEU_GeoNode ownerNode, List<HEU_PartData> volumeParts, List<HEU_VolumeCache> volumeCaches) { HEU_HoudiniAsset parentAsset = ownerNode.ParentAsset; foreach (HEU_VolumeCache cache in volumeCaches) { // Remove current volume caches from parent asset. // These get added back in below. parentAsset.RemoveVolumeCache(cache); // Mark the cache for updating cache.StartUpdateLayers(); } // This will keep track of volume caches still in use List<HEU_VolumeCache> updatedCaches = new List<HEU_VolumeCache>(); int numParts = volumeParts.Count; for (int i = 0; i < numParts; ++i) { // Get the tile index, if it exists, for this part HAPI_AttributeInfo tileAttrInfo = new HAPI_AttributeInfo(); int[] tileAttrData = new int[0]; HEU_GeneralUtility.GetAttribute(session, ownerNode.GeoID, volumeParts[i].PartID, HEU_Defines.HAPI_HEIGHTFIELD_TILE_ATTR, ref tileAttrInfo, ref tileAttrData, session.GetAttributeIntData); if (tileAttrData != null && tileAttrData.Length > 0) { //Debug.LogFormat("Tile: {0}", tileAttrData[0]); int tile = tileAttrData[0]; HEU_VolumeCache volumeCache = null; // Find cache in updated list for (int j = 0; j < updatedCaches.Count; ++j) { if (updatedCaches[j] != null && updatedCaches[j].TileIndex == tile) { volumeCache = updatedCaches[j]; break; } } if (volumeCache != null) { volumeCache.UpdateLayerFromPart(session, volumeParts[i]); // Skip adding new cache since already found in updated list continue; } // Find existing cache in old list if (volumeCaches != null && volumeCaches.Count > 0) { for(int j = 0; j < volumeCaches.Count; ++j) { if (volumeCaches[j] != null && volumeCaches[j].TileIndex == tile) { volumeCache = volumeCaches[j]; break; } } } // Create new cache for this tile if not found if (volumeCache == null) { volumeCache = ScriptableObject.CreateInstance<HEU_VolumeCache>(); volumeCache.Initialize(ownerNode, tile); volumeCache.StartUpdateLayers(); } volumeCache.UpdateLayerFromPart(session, volumeParts[i]); if (!updatedCaches.Contains(volumeCache)) { updatedCaches.Add(volumeCache); } } else { // No tile index. Most likely a single terrain tile. HEU_VolumeCache volumeCache = null; if (updatedCaches.Count == 0) { // Create a single volume cache, or use existing if it was just 1. // If more than 1 volume cache exists, this will recreate a single one if (volumeCaches == null || volumeCaches.Count != 1) { volumeCache = ScriptableObject.CreateInstance<HEU_VolumeCache>(); volumeCache.Initialize(ownerNode, 0); volumeCache.StartUpdateLayers(); } else if (volumeCaches.Count == 1) { // Keep the single volumecache volumeCache = volumeCaches[0]; } if (!updatedCaches.Contains(volumeCache)) { updatedCaches.Add(volumeCache); } } else { // Reuse the updated cache volumeCache = updatedCaches[0]; } volumeCache.UpdateLayerFromPart(session, volumeParts[i]); } } foreach (HEU_VolumeCache cache in updatedCaches) { // Add to parent for UI and preset parentAsset.AddVolumeCache(cache); // Finish update by keeping just the layers in use for each volume cache. cache.FinishUpdateLayers(); } return updatedCaches; }