void IDiffResolver.BeforeDiff(Asset baseAsset, Asset asset1, Asset asset2) { Guid newId; var baseEntityAsset = (EntityAsset)baseAsset; var entityAsset1 = (EntityAsset)asset1; var entityAsset2 = (EntityAsset)asset2; // Let's remap IDs in asset2 (if it comes from a FBX or such, we need to do that) var oldBaseTree = new EntityTreeAsset(baseEntityAsset.Hierarchy); var newBaseTree = new EntityTreeAsset(entityAsset2.Hierarchy); var idRemapping = new Dictionary <Guid, Guid>(); // Try to transfer ID from old base to new base var mergeResult = AssetMerge.Merge(oldBaseTree, newBaseTree, oldBaseTree, node => { if (typeof(Guid).IsAssignableFrom(node.InstanceType) && node.BaseNode != null && node.Asset1Node != null) { idRemapping.Add((Guid)node.Asset1Node.Instance, (Guid)node.BaseNode.Instance); } return(AssetMergePolicies.MergePolicyAsset2AsNewBaseOfAsset1(node)); }); if (mergeResult.HasErrors) { //mergeResult.CopyTo(); } EntityAnalysis.RemapEntitiesId(entityAsset2.Hierarchy, idRemapping); }
public static EntityHierarchyData ImportScene(UFile sourceUrl, EntityAsset source, Guid sourceRootEntity, out EntityBase entityBase) { if (source == null) { throw new ArgumentNullException("source"); } // Extract the scene starting from given root var newAsset = ExtractSceneClone(source, sourceRootEntity); // Generate entity mapping var entityMapping = new Dictionary <Guid, Guid>(); var reverseEntityMapping = new Dictionary <Guid, Guid>(); foreach (var entity in newAsset.Hierarchy.Entities) { // Generate new Id var newEntityId = Guid.NewGuid(); // Update mappings entityMapping.Add(newEntityId, entity.Id); reverseEntityMapping.Add(entity.Id, newEntityId); // Update entity with new id entity.Id = newEntityId; } // Rewrite entity references // Should we nullify invalid references? EntityAnalysis.RemapEntitiesId(newAsset.Hierarchy, reverseEntityMapping); // Add asset base entityBase = new EntityBase { Base = new AssetBase(sourceUrl, newAsset), SourceRoot = sourceRootEntity, IdMapping = entityMapping }; return(newAsset.Hierarchy); }