/// <summary> /// 异步加载组件 /// </summary> /// <param name="model"></param> /// <param name="p_model"></param> /// <returns></returns> public static Task <Dictionary <string, SkpComponent> > GetComponentsAsync(SUModelRef model, SkpModel p_model) { TaskCompletionSource <Dictionary <string, SkpComponent> > tcs = new TaskCompletionSource <Dictionary <string, SkpComponent> >(); Task.Run(() => { long componentsCount = 0; SKPCExport.SUModelGetNumComponentDefinitions(model, ref componentsCount); if (componentsCount > 0) { SUComponentDefinitionRef[] componentRefs = new SUComponentDefinitionRef[componentsCount]; SKPCExport.SUModelGetComponentDefinitions(model, componentsCount, componentRefs, ref componentsCount); TaskExcutor.Run <SkpComponent, SUComponentDefinitionRef>(componentRefs, c => { SkpComponent component = new SkpComponent(p_model); component.Load(c); return(component); }).ContinueWith(t => { if (t.IsFaulted) { tcs.TrySetException(t.Exception); } else { Dictionary <string, SkpComponent> components = t.Result.ToDictionary(p => p.Identity, p => p); tcs.TrySetResult(components); } }); } else { tcs.TrySetResult(new Dictionary <string, SkpComponent>()); } }); return(tcs.Task); }
public static Task <Dictionary <string, SkpGroup> > GetEntityGroupsAsync(SUEntitiesRef p_suEntitiesRef, SkpModel p_model) { TaskCompletionSource <Dictionary <string, SkpGroup> > tcs = new TaskCompletionSource <Dictionary <string, SkpGroup> >(); long groupsCount = 0; SKPCExport.SUEntitiesGetNumGroups(p_suEntitiesRef, ref groupsCount); if (groupsCount > 0) { SUGroupRef[] groupRefs = new SUGroupRef[groupsCount]; SKPCExport.SUEntitiesGetGroups(p_suEntitiesRef, groupsCount, groupRefs, ref groupsCount); TaskExcutor.Run <SkpGroup, SUGroupRef>(groupRefs, g => { SkpGroup group = new SkpGroup(p_model); group.Load(g); return(group); }).ContinueWith(t => { if (t.IsFaulted) { tcs.TrySetException(t.Exception); } else { tcs.TrySetResult(t.Result.ToDictionary(p => p.Identity, p => p)); } }); } else { tcs.TrySetResult(new Dictionary <string, SkpGroup>()); } return(tcs.Task); }
public static Task <Dictionary <string, SkpFace> > GetEntityFacesAsync(SUEntitiesRef p_suEntitiesRef, SkpModel p_model) { TaskCompletionSource <Dictionary <string, SkpFace> > tcs = new TaskCompletionSource <Dictionary <string, SkpFace> >(); long faceCount = 0; SKPCExport.SUEntitiesGetNumFaces(p_suEntitiesRef, ref faceCount); if (faceCount > 0) { SUFaceRef[] faces = new SUFaceRef[faceCount]; SKPCExport.SUEntitiesGetFaces(p_suEntitiesRef, faceCount, faces, ref faceCount); TaskExcutor.Run <SkpFace, SUFaceRef>(faces, f => { SkpFace surface = new SkpFace(p_model); surface.Load(f); return(surface); }).ContinueWith(t => { if (t.IsFaulted) { tcs.TrySetException(t.Exception); } else { tcs.TrySetResult(t.Result.ToDictionary(p => p.Identity, p => p)); } }); } else { tcs.TrySetResult(new Dictionary <string, SkpFace>()); } return(tcs.Task); }