Ejemplo n.º 1
0
    public void SetObject(int type)
    {
        if (nowObject != null)
        {
            Destroy(nowObject);
            nowObject = null;
        }

        GameObject tObj = null;

        switch (type)
        {
        case 0:
            tObj       = _prefabs[0];
            nowTypeTag = PlaneClassification.Floor;
            break;

        case 1:
            tObj       = _prefabs[1];
            nowTypeTag = PlaneClassification.Table;
            break;
        }

        nowObject = Instantiate(tObj);
        nowObject.transform.SetParent(_objectPool);
        nowObject.transform.localScale = new Vector3(1, 1, 1);
    }
Ejemplo n.º 2
0
        private static int ClassificationToInt(PlaneClassification classification)
        {
            switch (classification)
            {
            case UnityEngine.XR.ARSubsystems.PlaneClassification.None:
                return(0);

            case UnityEngine.XR.ARSubsystems.PlaneClassification.Wall:
                return(1);

            case UnityEngine.XR.ARSubsystems.PlaneClassification.Floor:
                return(2);

            case UnityEngine.XR.ARSubsystems.PlaneClassification.Ceiling:
                return(3);

            case UnityEngine.XR.ARSubsystems.PlaneClassification.Table:
                return(4);

            case UnityEngine.XR.ARSubsystems.PlaneClassification.Seat:
                return(5);

            case UnityEngine.XR.ARSubsystems.PlaneClassification.Door:
                return(6);

            case UnityEngine.XR.ARSubsystems.PlaneClassification.Window:
                return(7);

            default:
                throw new ArgumentOutOfRangeException(nameof(classification), classification, null);
            }
        }
        /// <summary>
        /// Provides a material to be used for rendering a SamplePlane with a given PlaneClassification.
        /// If the classification isn't supported for a unique material, the default plane material will be returned.
        /// </summary>
        public Material GetMaterialFromClassification(PlaneClassification classification)
        {
            foreach (PlaneClassificationPair pair in m_supportedClassifications)
            {
                if (pair.classification == classification)
                {
                    return(pair.material);
                }
            }

            return(m_defaultMaterial);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Splits this polyhedron into two polyhedron by intersecting against a plane.
        /// </summary>
        /// <param name="plane">The splitting plane</param>
        /// <param name="back">The back side of the polyhedron</param>
        /// <param name="front">The front side of the polyhedron</param>
        /// <returns>True if the plane splits the polyhedron, false if the plane doesn't intersect</returns>
        public bool Split(Plane plane, out Polyhedron back, out Polyhedron front)
        {
            back = front = null;

            // Check that this solid actually spans the plane
            List <PlaneClassification> classify = Polygons.Select(x => x.ClassifyAgainstPlane(plane)).Distinct().ToList();

            if (classify.All(x => x != PlaneClassification.Spanning))
            {
                if (classify.Any(x => x == PlaneClassification.Back))
                {
                    back = this;
                }
                else if (classify.Any(x => x == PlaneClassification.Front))
                {
                    front = this;
                }
                return(false);
            }

            List <Plane> backPlanes = new List <Plane> {
                plane
            };
            List <Plane> frontPlanes = new List <Plane> {
                new Plane(-plane.Normal, -plane.DistanceFromOrigin)
            };

            foreach (Polygon face in Polygons)
            {
                PlaneClassification classification = face.ClassifyAgainstPlane(plane);
                if (classification != PlaneClassification.Back)
                {
                    frontPlanes.Add(face.Plane);
                }
                if (classification != PlaneClassification.Front)
                {
                    backPlanes.Add(face.Plane);
                }
            }

            back  = new Polyhedron(backPlanes);
            front = new Polyhedron(frontPlanes);

            return(true);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Constructs a new <see cref="BoundedPlane"/>. This is just a data container
 /// for a plane's session relative data. These are typically created by
 /// <see cref="XRPlaneSubsystem.GetChanges(Unity.Collections.Allocator)"/>.
 /// </summary>
 /// <param name="trackableId">The <see cref="TrackableId"/> associated with the plane.</param>
 /// <param name="subsumedBy">The plane which subsumed this one. Use <see cref="TrackableId.invalidId"/> if it has not been subsumed.</param>
 /// <param name="pose">The <c>Pose</c> associated with the plane.</param>
 /// <param name="center">The center, in plane-space (relative to <paramref name="pose"/>) of the plane.</param>
 /// <param name="size">The dimensions associated with the plane.</param>
 /// <param name="alignment">The <see cref="PlaneAlignment"/> associated with the plane.</param>
 /// <param name="trackingState">The <see cref="TrackingState"/> associated with the plane.</param>
 /// <param name="nativePtr">The native pointer associated with the plane.</param>
 /// <param name="classification">The <see cref="PlaneClassification"/> associated with the plane.</param>
 public BoundedPlane(
     TrackableId trackableId,
     TrackableId subsumedBy,
     Pose pose,
     Vector2 center,
     Vector2 size,
     PlaneAlignment alignment,
     TrackingState trackingState,
     IntPtr nativePtr,
     PlaneClassification classification)
 {
     m_TrackableId    = trackableId;
     m_SubsumedById   = subsumedBy;
     m_Pose           = pose;
     m_Center         = center;
     m_Size           = size;
     m_Alignment      = alignment;
     m_TrackingState  = trackingState;
     m_NativePtr      = nativePtr;
     m_Classification = classification;
 }
Ejemplo n.º 6
0
            /// <summary>
            /// Splits a source polygon along a plane, returning the sub-poly behind the plane in "behind"
            /// and the sub-poly in-front of the plane in "inFront"
            /// </summary>
            public void Split( Plane2 plane, Polygon source, out Polygon behind, out Polygon inFront )
            {
                float tolerance = 0.001f;
                int firstDefiniteClassIndex = -1;
                PlaneClassification[] classifications = new PlaneClassification[ source.Indices.Length ];
                for ( int index = 0; index < source.Indices.Length; ++index )
                {
                    classifications[ index ] = plane.ClassifyPoint( m_Points[ source.Indices[ index ] ], tolerance );
                    if ( ( firstDefiniteClassIndex == -1 ) && ( classifications[ index ] != PlaneClassification.On ) )
                    {
                        firstDefiniteClassIndex = index;
                    }
                }
                if ( firstDefiniteClassIndex > 1 )
                {
                    //	The first two points are on the split plane. This means that we
                    //	can easily classify the polygon as either behind or in front depending on the first
                    //	definite class
                    if ( classifications[ firstDefiniteClassIndex ] == PlaneClassification.Behind )
                    {
                        behind = new Polygon( source.Indices );
                        inFront = null;
                    }
                    else
                    {
                        behind = null;
                        inFront = new Polygon( source.Indices );
                    }
                    return;
                }

                int lastPtIndex = firstDefiniteClassIndex;
                int curPtIndex = ( lastPtIndex + 1 ) % source.Indices.Length;
                Point2 lastPt = m_Points[ source.Indices[ lastPtIndex ] ];
                PlaneClassification lastClass = classifications[ lastPtIndex ];

                List< int > behindPoints = new List< int >( source.Indices.Length + 2 );
                List< int > inFrontPoints = new List< int >( source.Indices.Length + 2 );

                for ( int count = 0; count < source.Indices.Length; ++count )
                {
                    Point2 curPt = m_Points[ source.Indices[ curPtIndex ] ];
                    PlaneClassification curClass = classifications[ curPtIndex ];
                    if ( curClass == PlaneClassification.On )
                    {
                        curClass = lastClass;
                    }

                    if ( curClass != lastClass )
                    {
                        //	Split line on plane
                        Line2Intersection intersection = Intersections2.GetLinePlaneIntersection( lastPt, curPt, plane );
                        int newPtIndex = AddPoint( intersection.IntersectionPosition );
                        behindPoints.Add( newPtIndex );
                        inFrontPoints.Add( newPtIndex );
                    }

                    if ( curClass == PlaneClassification.Behind )
                    {
                        behindPoints.Add( source.Indices[ curPtIndex ] );
                    }
                    else
                    {
                        inFrontPoints.Add( source.Indices[ curPtIndex ] );
                    }

                    lastClass = curClass;
                    lastPt = curPt;

                    curPtIndex = ( curPtIndex + 1 ) % source.Indices.Length;
                }

                behind = ( behindPoints.Count == 0 ) ? null : new Polygon( behindPoints.ToArray( ) );
                inFront = ( inFrontPoints.Count == 0 ) ? null : new Polygon( inFrontPoints.ToArray( ) );
            }
Ejemplo n.º 7
0
 /// <summary>
 /// Determines the classification of an edge with respect to a plane, given the classification of the edge's endpoints
 /// </summary>
 private static bool GetEdgeClassification( PlaneClassification p0Class, PlaneClassification p1Class, out PlaneClassification edgeClass )
 {
     if ( p0Class == p1Class )
     {
         edgeClass = p0Class;
         return true;
     }
     if ( p0Class == PlaneClassification.On )
     {
         edgeClass = p1Class;
         return true;
     }
     if ( p1Class == PlaneClassification.On )
     {
         edgeClass = p0Class;
         return true;
     }
     edgeClass = PlaneClassification.On;
     return false;
 }