/* * attempts to load and returns all loaded UDS models in the scene */ public static udRenderInstance[] getUDSInstances() { GameObject[] objects = GameObject.FindGameObjectsWithTag("UDSModel"); int count = 0; udRenderInstance[] modelArray = new udRenderInstance[objects.Length]; for (int i = 0; i < objects.Length; ++i) { UDSModel model = (UDSModel)objects[i].GetComponent("UDSModel"); if (!model.isLoaded) { model.LoadModel(); } if (model.isLoaded) { modelArray[count].pointCloud = model.udModel.pModel; Transform localTransform = objects[i].transform; modelArray[count].worldMatrix = UDUtilities.GetUDMatrix( Matrix4x4.TRS(model.transform.position, model.transform.rotation, model.transform.localScale) * model.modelToPivot ); count++; } } return(modelArray.Where(m => (m.pointCloud != System.IntPtr.Zero)).ToArray()); }
/* * attempts to load and returns all loaded UDS models in the scene */ public static vdkRenderInstance[] getUDSInstances() { GameObject[] objects = GameObject.FindGameObjectsWithTag("UDSModel"); int count = 0; vdkRenderInstance[] modelArray = new vdkRenderInstance[objects.Length]; for (int i = 0; i < objects.Length; ++i) { Component component = objects[i].GetComponent("UDSModel"); UDSModel model = component as UDSModel; if (!model.isLoaded) { model.LoadModel(); } if (model.isLoaded) { modelArray[count].pointCloud = model.udModel.pModel; modelArray[count].worldMatrix = UDUtilities.GetUDMatrix(model.pivotTranslation * model.modelScale * objects[i].transform.localToWorldMatrix * model.pivotTranslation.inverse); count++; } } return(modelArray.Where(m => (m.pointCloud != System.IntPtr.Zero)).ToArray()); }
void Start() { string[] files = Directory.GetFiles(path); double[] rootBaseOffset = new double[3]; Vector3 rootBaseTranslation = Vector3.zero; int baseInd = 0; //index in the list to which all models will be placed relative to for (int i = 0; i < files.Length; ++i) { string file = files[i]; //skip non uds files if (!file.Substring(file.Length - 4).Equals(".uds")) { if (i == baseInd) { ++baseInd; } continue; } GameObject modelGameObject = new GameObject(file); modelGameObject.transform.SetParent(this.transform); modelGameObject.AddComponent <UDSModel>(); UDSModel model = modelGameObject.GetComponent <UDSModel>(); model.path = file; try { model.LoadModel(); } catch { Debug.LogError("load model failed: " + file); if (i == baseInd) { ++baseInd; } continue; } if (i == baseInd) //reference all models to the first { rootBaseOffset = model.header.baseOffset; } model.geolocationOffset = UDUtilities.UDtoGL * -new Vector3( (float)rootBaseOffset[0], (float)rootBaseOffset[1], (float)rootBaseOffset[2] ); modelGameObject.tag = "UDSModel"; model.geolocate = true; } }
// Start is called before the first frame update void Start() { string[] files = Directory.GetFiles(path); Vector3 rootBaseOffset = new Vector3(); for (int i = 0; i < files.Length; ++i) { string file = files[i]; //skip non uds files if (!file.Substring(file.Length - 4).Equals(".uds")) { continue; } GameObject udModel = new GameObject(file); udModel.transform.SetParent(this.transform); udModel.AddComponent <UDSModel>(); UDSModel model = udModel.GetComponent <UDSModel>(); model.path = file; try { model.LoadModel(); } catch { Debug.LogError("load model failed: " + file); continue; } Vector3 baseOffset = new Vector3((float)model.header.baseOffset[0], (float)model.header.baseOffset[1], (float)model.header.baseOffset[2]); if (i == 0) { rootBaseOffset = baseOffset; } model.transform.localPosition = baseOffset - rootBaseOffset; model.transform.localScale = new Vector3((float)model.header.scaledRange, (float)model.header.scaledRange, (float)model.header.scaledRange); model.transform.localRotation = Quaternion.Euler(-90, 0, 0); udModel.tag = "UDSModel"; } }