public static List <RevitFilePreview> RevitFilePreviews(this FamilyLibrary familyLibrary, string categoryName = null, string familyName = null, string familyTypeName = null) { IEnumerable <RevitFilePreview> files = familyLibrary?.Files; if (files == null) { return(null); } if (!string.IsNullOrWhiteSpace(categoryName)) { files = files.Where(x => x.CategoryName == categoryName); } if (!string.IsNullOrWhiteSpace(familyName)) { files = files.Where(x => x.FamilyName == familyName); } if (!string.IsNullOrWhiteSpace(familyTypeName)) { files = files.Where(x => x.FamilyTypeNames.Any(y => y == familyTypeName)); } return(files.ToList()); }
private IEnumerator PlaceFamily(string familyId) { if (FamilyLibrary.GetFamily(familyId) != null) { FamilyInstance newFam = new FamilyInstance { FamilyId = familyId, Transform = new Common.Models.Transform { BasisX = new XYZ { X = this.transform.right.x, Y = this.transform.right.z, Z = this.transform.right.y }, BasisY = new XYZ { X = this.transform.forward.x, Y = this.transform.forward.z, Z = this.transform.forward.y }, BasisZ = new XYZ { X = this.transform.up.x, Y = this.transform.up.z, Z = this.transform.up.y }, Origin = new XYZ { X = this.transform.position.x * Helpers.Constants.FT_PER_M, Y = this.transform.position.z * Helpers.Constants.FT_PER_M, Z = this.transform.position.y * Helpers.Constants.FT_PER_M } } }; Debug.Log($"Requesting new family"); newFam = StreamVR.Instance.PlaceFamilyInstance(newFam); Debug.Log($"Loading family instance"); yield return(this.LoadInstance(newFam)); FamilyInstanceLibrary.AddFamily(newFam, this.gameObject); } else { Debug.LogError($"Can't create family from missing ID {familyId}"); } }
public static FamilyLoadSettings FamilyLoadSettings(FamilyLibrary familyLibrary = null, bool overwriteFamily = true, bool overwriteParameterValues = true) { FamilyLoadSettings familyLoadSettings = new FamilyLoadSettings() { OverwriteFamily = overwriteFamily, OverwriteParameterValues = overwriteParameterValues }; if (familyLibrary != null) { familyLoadSettings.FamilyLibrary = familyLibrary; } return(familyLoadSettings); }
public void Connect(StreamVROptions options) { this.options = options; if (!string.IsNullOrEmpty(this.options.NatsBusUrl)) { BusConnector.ConfigureEndpoint(this.options.NatsBusUrl); } if (!string.IsNullOrEmpty(this.options.ModelServerUrl)) { FamilyLibrary.ConfigureModelServerURL(this.options.ModelServerUrl); MaterialLibrary.ConfigureModelServerURL(this.options.ModelServerUrl); } this.comms = BusConnector.Connect(); }
public static List <string> CategoryNames(this FamilyLibrary familyLibrary, string familyName, string familyTypeName = null) { if (familyLibrary?.Files == null) { return(null); } IEnumerable <RevitFilePreview> files = familyLibrary.Files.Where(x => x.FamilyName == familyName); if (!string.IsNullOrWhiteSpace(familyTypeName)) { files = files.Where(x => x.FamilyTypeNames.Any(y => y == familyTypeName)); } return(files.Select(x => x.CategoryName).Distinct().ToList()); }
private IEnumerator LoadFamiles() { System.Diagnostics.Stopwatch s = new System.Diagnostics.Stopwatch(); s.Start(); if (StreamVR.Instance.Families != null) { FamilyLibrary.LoadFamilies(StreamVR.Instance.Families); } if (StreamVR.Instance.FamilyInstances != null) { this.GetComponent <FamilyPlacer>().Place(StreamVR.Instance.FamilyInstances); FamilyLibrary.LoadFamilies(StreamVR.Instance.Families); } yield return(0); Debug.Log($"StreamVR Family load in: {s.ElapsedMilliseconds}ms"); s.Stop(); }
public static FamilyLibrary Append(this FamilyLibrary familyLibrary, IEnumerable <string> paths) { if (familyLibrary == null) { return(null); } List <RevitFilePreview> families = new List <RevitFilePreview>(); foreach (string path in paths) { if (familyLibrary.Files != null && familyLibrary.Files.Any(x => x.Path == path)) { continue; } RevitFilePreview family = Create.RevitFilePreview(path); if (family != null) { families.Add(family); } } if (families.Count == 0) { return(familyLibrary); } FamilyLibrary newLibrary = familyLibrary.ShallowClone(); newLibrary.Files = families; if (familyLibrary.Files != null) { newLibrary.Files.AddRange(familyLibrary.Files); } return(newLibrary); }
public static FamilyLibrary Append(this FamilyLibrary familyLibrary, string directory, bool topDirectoryOnly = false) { if (familyLibrary == null) { return(null); } if (string.IsNullOrEmpty(directory) || !Directory.Exists(directory)) { return(familyLibrary); } DirectoryInfo directoryInfo = new DirectoryInfo(directory); SearchOption searchOption = SearchOption.AllDirectories; if (topDirectoryOnly) { searchOption = SearchOption.TopDirectoryOnly; } FileInfo[] fileInfos = directoryInfo.GetFiles("*.rfa", searchOption); return(familyLibrary.Append(fileInfos.Select(x => x.FullName))); }
private IEnumerator LoadInstance(FamilyInstance f) { this.instanceData = f; this.InstanceData = Newtonsoft.Json.JsonConvert.SerializeObject(f); this.fam = FamilyLibrary.GetFamily(f.FamilyId); if (this.fam == null) { throw new System.Exception("Family " + f.FamilyId + " is not loaded"); } if (f.HostId != null) { this.host = GeometryLibrary.GetObject(f.HostId); } #if UNITY_EDITOR this.name = $"Family ({f.Id} - {this.fam.Tag} - {this.fam.ModelName ?? this.fam.FamilyName})"; #else this.name = f.Id; #endif // GameObject model = (GameObject)Resources.Load($"Families/{this.fam.Name}/model"); CoroutineWithData <object> cd = new CoroutineWithData <object>(this, FamilyLibrary.ResolveFamilyOBJ(f.FamilyId, f.VariantId)); yield return(cd.coroutine); object result = cd.result; if (result != null) { byte[] objData = cd.result as byte[]; // Debug.Log("PLACING FAMILY"); GameObject modelInstance; using (var textStream = new MemoryStream(objData)) { modelInstance = new OBJLoader().Load(textStream); } var initialRotation = modelInstance.transform.localRotation; modelInstance.transform.parent = this.transform; modelInstance.transform.localPosition = Vector3.zero; modelInstance.transform.localRotation = initialRotation; modelInstance.transform.localScale = new Vector3( Helpers.Constants.M_PER_FT, Helpers.Constants.M_PER_FT, Helpers.Constants.M_PER_FT ); foreach (var l in modelInstance.GetComponentsInChildren <Light>()) { l.gameObject.transform.rotation = Quaternion.LookRotation(Vector3.down); } foreach (UnityEngine.Transform child in transform) { foreach (UnityEngine.Transform geo in child) { var c = geo.GetComponent <FamilyGeometryController>(); if (c != null) { c.CollisionEnter += this.OnCollsionEnterEvent; c.CollisionExit += this.OnCollisionExitEvent; } } } // Debug.Log("Children " + count); } #if UNITY_EDITOR StartCoroutine(CheckForUpdate()); #endif }
public static FamilyLibrary Append(this FamilyLibrary familyLibrary, string path) { return(familyLibrary.Append(new List <string> { path })); }
public static List <string> Paths(this FamilyLibrary familyLibrary, string categoryName = null, string familyName = null, string typeName = null) { return(familyLibrary?.RevitFilePreviews(categoryName, familyName, typeName)?.Select(x => x.Path).ToList()); }