void LoadModel() { // Clean up existing model if (m_ModelInstance != null) { GameObject.Destroy(m_ModelInstance.gameObject); } // Early out if we don't have a model to clone. // This can happen if model loading is deferred. if (m_Model == null || m_Model.m_ModelParent == null) { return; } m_ModelInstance = Instantiate(m_Model.m_ModelParent); m_ModelInstance.gameObject.SetActive(true); m_ModelInstance.parent = this.transform; Coords.AsLocal[m_ModelInstance] = TrTransform.identity; float maxExtent = 2 * Mathf.Max(m_Model.m_MeshBounds.extents.x, Mathf.Max(m_Model.m_MeshBounds.extents.y, m_Model.m_MeshBounds.extents.z)); float size; if (maxExtent == 0.0f) { // If we created a widget with a model that doesn't have geo, we won't have calculated a // bounds worth much. In that case, give us a default size. size = 1.0f; } else { size = kInitialSizeMeters_RS * App.METERS_TO_UNITS / maxExtent; } m_InitSize_CS = size / Coords.CanvasPose.scale; // Models are created in the main canvas. Cache model layer in case it's overridden later. HierarchyUtils.RecursivelySetLayer(transform, App.Scene.MainCanvas.gameObject.layer); m_BackupLayer = m_ModelInstance.gameObject.layer; // Set a new batchId on this model so it can be picked up in GPU intersections. m_BatchId = GpuIntersector.GetNextBatchId(); HierarchyUtils.RecursivelySetMaterialBatchID(m_ModelInstance, m_BatchId); WidgetManager.m_Instance.AddWidgetToBatchMap(this, m_BatchId); Vector3 ratios = GetBoundsRatios(m_Model.m_MeshBounds); m_ContainerBloat.x = Mathf.Max(0, m_MinContainerRatio - ratios.x); m_ContainerBloat.y = Mathf.Max(0, m_MinContainerRatio - ratios.y); m_ContainerBloat.z = Mathf.Max(0, m_MinContainerRatio - ratios.z); m_ContainerBloat /= m_MinContainerRatio; // Normalize for the min ratio. m_ContainerBloat *= m_MaxBloat / App.Scene.Pose.scale; // Apply bloat to appropriate axes. m_BoxCollider.size = m_Model.m_MeshBounds.size + m_ContainerBloat; m_BoxCollider.transform.localPosition = m_Model.m_MeshBounds.center; InitSnapGhost(m_Model.m_ModelParent, m_ModelInstance); // Remove previous model vertex recording. WidgetManager.m_Instance.AdjustModelVertCount(-m_NumVertsTrackedByWidgetManager); m_NumVertsTrackedByWidgetManager = 0; m_ObjModelScript = GetComponentInChildren <ObjModelScript>(); m_ObjModelScript.Init(); if (m_ObjModelScript.NumMeshes == 0) { OutputWindowScript.Error("No usable geometry in model"); } else { m_NumVertsTrackedByWidgetManager = m_ObjModelScript.GetNumVertsInMeshes(); WidgetManager.m_Instance.AdjustModelVertCount(m_NumVertsTrackedByWidgetManager); } if (m_Model.IsCached()) { m_Model.RefreshCache(); } }
public int GetNumVertsInModel() { return((m_ObjModelScript != null) ? m_ObjModelScript.GetNumVertsInMeshes() : 0); }