示例#1
0
 internal static void Recycle(PlaneVisual planeVisual)
 {
     // Release any UnityObject references so they can be cleaned up
     planeVisual.GameObject = null;
     planeVisual.Mesh       = null;
     planeVisual.Collider   = null;
     k_Pool.Enqueue(planeVisual);
 }
示例#2
0
 void PlaneRemovedHandler(MRPlane plane)
 {
     if (m_Planes.TryGetValue(plane.id, out var planeVisual))
     {
         UnityObjectUtils.Destroy(planeVisual.GameObject);
         UnityObjectUtils.Destroy(planeVisual.Mesh);
         m_Planes.Remove(plane.id);
         PlaneVisual.Recycle(planeVisual);
     }
 }
        // We also need rectangelHeightDirection because we are actually rendering a 2D rectangle and not a real infinitive plane
        // and the rectangle need a Vector3D that specifies the direction of its height (defined in Size)
        private void ChangePlane(Point3D pointOnPlane, Vector3D planeNormal, Vector3D rectangelHeightDirection)
        {
            _pointOnPlane = pointOnPlane;
            _planeNormal  = planeNormal;

            PlaneVisual.BeginInit();

            PlaneVisual.CenterPosition  = pointOnPlane;
            PlaneVisual.Normal          = planeNormal;
            PlaneVisual.HeightDirection = rectangelHeightDirection;

            PlaneVisual.EndInit();
        }
示例#4
0
        void CreateOrUpdateGameObject(MRPlane plane)
        {
            if (MARSCore.instance.paused)
            {
                return;
            }

            GameObject   go;
            Mesh         mesh         = null;
            MeshCollider meshCollider = null;
            var          id           = plane.id;
            var          useGeometry  = m_UsePlaneGeometry && plane.vertices != null;
            var          makeEdge     = m_EdgeSettings.MakeEdge;

            if (m_Planes.TryGetValue(id, out var planeVisual))
            {
                go           = planeVisual.GameObject;
                mesh         = planeVisual.Mesh;
                meshCollider = planeVisual.Collider;
                if (useGeometry && mesh == null)
                {
                    mesh             = new Mesh();
                    planeVisual.Mesh = mesh;
                }
            }
            else
            {
                go = Instantiate(m_PlanePrefab, transform);

#if UNITY_EDITOR
                // This allows the instantiated objects to use layer locking for scene picking in the editor.
                if (m_UseParentLayer)
                {
                    go.SetLayerAndHideFlagsRecursively(gameObject.layer, HideFlags.DontSave);
                }
                else
                {
                    go.SetHideFlagsRecursively(HideFlags.DontSave);
                }
#else
                go.SetHideFlagsRecursively(HideFlags.DontSave);
#endif

                if (useGeometry)
                {
                    mesh = new Mesh();

                    var meshFilter = go.GetComponentInChildren <MeshFilter>();
                    if (meshFilter)
                    {
                        meshFilter.sharedMesh = mesh;
                    }

                    meshCollider = go.GetComponentInChildren <MeshCollider>();
                    if (meshCollider)
                    {
                        meshCollider.sharedMesh = mesh;
                    }

                    planeVisual = PlaneVisual.GetOrCreate(go, mesh, meshCollider, makeEdge);
                }
                else
                {
                    planeVisual = PlaneVisual.GetOrCreate(go, null, null, makeEdge);
                }

                m_Planes.Add(id, planeVisual);
            }

            var goTransform = go.transform;
            var pose        = this.ApplyOffsetToPose(plane.pose);
            goTransform.SetWorldPose(pose);

            var cameraScale = this.GetCameraScale();
            if (useGeometry)
            {
                var vertices            = plane.vertices;
                var textureCoordinates  = plane.textureCoordinates;
                var textureCoordinates2 = planeVisual.TextureCoordinates2;
                var indices             = plane.indices;
                if (makeEdge)
                {
                    planeVisual.InitializeEdgeLists();
                    PlaneUtils.GeneratePlaneWithBorders(plane.pose, vertices, planeVisual.Vertices, planeVisual.TextureCoordinates,
                                                        planeVisual.TextureCoordinates2, planeVisual.Indices, m_EdgeSettings);

                    vertices           = planeVisual.Vertices;
                    textureCoordinates = planeVisual.TextureCoordinates;
                    indices            = planeVisual.Indices;
                }
                else
                {
                    // Need to set uv2's with all 0's to clear out edge UVs if they exist (can happen if MakeEdge is toggled during play mode)
                    var vertexCount = vertices.Count;
                    textureCoordinates2.SetSize(vertexCount);
                    for (var i = 0; i < vertexCount; i++)
                    {
                        textureCoordinates2[i] = default;
                    }
                }

                goTransform.localScale = Vector3.one * cameraScale;
                mesh.triangles         = null;
                mesh.SetVertices(vertices);
                mesh.SetUVs(0, textureCoordinates);
                mesh.SetUVs(1, textureCoordinates2);
                mesh.SetTriangles(indices, 0, true);
                mesh.RecalculateNormals();

                if (meshCollider != null)
                {
                    meshCollider.sharedMesh = mesh; // this needs to re-applied to take effect
                }
            }
            else
            {
                var extents = plane.extents;
                goTransform.position  += pose.rotation * (plane.center * cameraScale);
                goTransform.localScale = new Vector3(extents.x, 1f, extents.y) * cameraScale;
            }
        }
示例#5
0
 void Awake()
 {
     PlaneVisual.InitializePool(m_EdgeSettings.MakeEdge);
 }