Beispiel #1
0
        override public bool FindRayIntersection(Ray3f ray, out SORayHit hit)
        {
            hit = null;

            Ray     sceneRay = GetScene().ToSceneRay(ray);
            Frame3f frameL   = GetLocalFrame(CoordSpace.ObjectCoords);
            Ray     localRay = frameL.ToFrame(sceneRay);

            float sceneWidth = GetScene().ToSceneDimension(visibleWidth);

            AxisAlignedBox3d hitBox = localBounds;

            hitBox.Expand(sceneWidth * 0.5f);
            Bounds hitBounds = new Bounds((Vector3)hitBox.Center, (Vector3)hitBox.Diagonal);

            if (hitBounds.IntersectRay(localRay) == false)
            {
                return(false);
            }

            double rayHitT;

            if (CurveUtils.FindClosestRayIntersection(curve, sceneWidth * 0.5f, localRay, out rayHitT))
            {
                hit           = new SORayHit();
                hit.fHitDist  = (float)rayHitT;
                hit.hitPos    = localRay.GetPoint(hit.fHitDist);
                hit.hitPos    = GetScene().ToWorldP(frameL.FromFrameP(hit.hitPos));
                hit.hitNormal = Vector3.zero;
                hit.hitGO     = root;
                hit.hitSO     = this;
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        public virtual bool FindNearest(Vector3d point, double maxDist, out SORayHit nearest, CoordSpace eInCoords)
        {
            nearest = null;

            // convert to local
            Vector3f local_pt = SceneTransforms.TransformTo((Vector3f)point, this, eInCoords, CoordSpace.ObjectCoords);

            AxisAlignedBox3f bounds        = GetLocalBoundingBox();
            float            local_dist    = bounds.Distance(local_pt);
            float            dist_incoords = SceneTransforms.TransformTo(local_dist, this, CoordSpace.ObjectCoords, eInCoords);

            if (dist_incoords > maxDist)
            {
                return(false);
            }

            nearest          = new SORayHit();
            nearest.fHitDist = dist_incoords;
            Vector3f nearPt = bounds.NearestPoint(local_pt);

            nearest.hitPos    = SceneTransforms.TransformTo(nearPt, this, CoordSpace.ObjectCoords, eInCoords);
            nearest.hitNormal = Vector3f.Zero;
            nearest.hitGO     = RootGameObject;
            nearest.hitSO     = this;
            return(true);
        }
Beispiel #3
0
        override public bool FindRayIntersection(Ray3f ray, out SORayHit hit)
        {
            hit = null;
            GameObjectRayHit hitg = null;

            if (FindGORayIntersection(ray, out hitg))
            {
                if (hitg.hitGO != null)
                {
                    hit = new SORayHit(hitg, this);

                    // compute analytic normal on cylinder body
                    if (hitg.hitGO == body)
                    {
                        Vector3 up = this.RootGameObject.GetRotation() * Vector3.up;
                        Vector3 l  = hitg.hitPos - this.RootGameObject.GetPosition();
                        l -= Vector3.Dot(l, up) * up;
                        l.Normalize();
                        hit.hitNormal = l;
                    }

                    return(true);
                }
            }
            return(false);
        }
Beispiel #4
0
        // tests SceneObjects and Bounds
        public bool FindSceneRayIntersection(Ray3f ray, out AnyRayHit hit, bool bFindBoundsHits = true, Func <SceneObject, bool> sofilter = null)
        {
            hit = null;

            SORayHit         bestSOHit     = null;
            GameObjectRayHit bestBoundsHit = null;

            bool bHitSO     = FindSORayIntersection(ray, out bestSOHit, sofilter);
            bool bHitBounds = bFindBoundsHits && FindWorldBoundsHit(ray, out bestBoundsHit);

            if (bHitSO && bHitBounds)
            {
                if (bestSOHit.fHitDist < bestBoundsHit.fHitDist)
                {
                    hit = new AnyRayHit(bestSOHit);
                }
                else
                {
                    hit = new AnyRayHit(bestBoundsHit, HitType.BoundsObjectHit);
                }
            }
            else if (bHitSO)
            {
                hit = new AnyRayHit(bestSOHit);
            }
            else if (bHitBounds)
            {
                hit = new AnyRayHit(bestBoundsHit, HitType.BoundsObjectHit);
            }
            return(hit != null);
        }
Beispiel #5
0
 public AnyRayHit(SORayHit init)
 {
     hitPos   = init.hitPos;
     fHitDist = init.fHitDist;
     hitGO    = init.hitGO;
     eType    = HitType.SceneObjectHit;
     hitSO    = init.hitSO;
 }
Beispiel #6
0
        public bool FindSORayIntersection_PivotPriority(Ray ray, out SORayHit hit, Func <SceneObject, bool> filter = null)
        {
            bool bHitPivot = HUDUtil.FindNearestRayIntersection(SceneObjects, ray, out hit, (s) => { return(s is PivotSO); });

            if (bHitPivot)
            {
                return(true);
            }
            return(HUDUtil.FindNearestRayIntersection(SceneObjects, ray, out hit, filter));
        }
Beispiel #7
0
        public bool FindSORayIntersection_PivotPriority(Ray3f ray, out SORayHit hit, Func <SceneObject, bool> filter = null)
        {
            bool bHitPivot = HUDUtil.FindNearestRayIntersection(VisibleSceneObjects, ray, out hit, is_priority_pivot);

            if (bHitPivot)
            {
                return(true);
            }
            return(HUDUtil.FindNearestRayIntersection(VisibleSceneObjects, ray, out hit,
                                                      (SelectionMask == null) ? filter : mask_filter(filter)));
        }
Beispiel #8
0
        // does not test bounds!
        // [TODO] this is going to be weird... need to test bounds, I think
        public bool FindAnyRayIntersection(Ray3f ray, out AnyRayHit hit)
        {
            hit = null;

            UIRayHit bestUIHit = null;
            SORayHit bestSOHit = null;

            foreach (var ui in vUIElements)
            {
                UIRayHit uiHit;
                if (ui.FindRayIntersection(ray, out uiHit))
                {
                    if (bestUIHit == null || uiHit.fHitDist < bestUIHit.fHitDist)
                    {
                        bestUIHit = uiHit;
                    }
                }
            }
            foreach (var so in VisibleSceneObjects)
            {
                if (!is_selectable(so))
                {
                    continue;
                }
                SORayHit objHit;
                if (so.FindRayIntersection(ray, out objHit))
                {
                    if (bestSOHit == null || objHit.fHitDist < bestSOHit.fHitDist)
                    {
                        bestSOHit = objHit;
                    }
                }
            }
            if (bestUIHit != null)
            {
                if (bestSOHit == null || bestSOHit.fHitDist > bestUIHit.fHitDist)
                {
                    hit = new AnyRayHit(bestUIHit);
                }
                else
                {
                    hit = new AnyRayHit(bestSOHit);
                }
            }
            else if (bestSOHit != null)
            {
                hit = new AnyRayHit(bestSOHit);
            }

            return(hit != null);
        }
Beispiel #9
0
        public bool FindRayIntersection(Ray ray, out SORayHit hit)
        {
            hit = null;
            GameObjectRayHit hitg = null;

            if (FindGORayIntersection(ray, out hitg))
            {
                if (hitg.hitGO != null)
                {
                    hit = new SORayHit(hitg, this);
                    return(true);
                }
            }
            return(false);
        }
Beispiel #10
0
        public bool FindRayIntersection(Ray3f ray, out SORayHit hit)
        {
            hit = null;
            if (EnableSelection == false)
            {
                return(false);
            }

            bool bHit = SceneUtil.FindNearestRayIntersection(vChildren, ray, out hit);

            if (bHit)
            {
                hit.hitSO = this;
            }
            return(bHit);
        }
Beispiel #11
0
        public bool FindRayIntersection(Ray3f ray, out SORayHit hit)
        {
            hit = null;
            if (SelectionMode == SelectionModes.NoSelection)
            {
                return(false);
            }

            bool bHit = SceneUtil.FindNearestRayIntersection(vChildren, ray, out hit);

            if (bHit && SelectionMode == SelectionModes.SelectGroup)
            {
                hit.hitSO = this;
            }
            return(bHit);
        }
Beispiel #12
0
        public bool FindSORayIntersection(Ray ray, out SORayHit hit)
        {
            hit = null;

            foreach (SceneObject so in vObjects)
            {
                SORayHit objHit;
                if (so.FindRayIntersection(ray, out objHit))
                {
                    if (hit == null || objHit.fHitDist < hit.fHitDist)
                    {
                        hit = objHit;
                    }
                }
            }
            return(hit != null);
        }
Beispiel #13
0
        override public bool FindRayIntersection(Ray3f ray, out SORayHit hit)
        {
            hit = null;
            GameObjectRayHit hitg = null;

            if (FindGORayIntersection(ray, out hitg))
            {
                if (hitg.hitGO != null)
                {
                    hit = new SORayHit(hitg, this);

                    // compute analytic normal
                    hit.hitNormal = (hit.hitPos - this.RootGameObject.GetPosition()).Normalized;

                    return(true);
                }
            }
            return(false);
        }
Beispiel #14
0
        override public bool FindRayIntersection(Ray3f worldRay, out SORayHit hit)
        {
            hit = null;

            // project world ray into local coords
            FScene scene    = GetScene();
            Ray3f  sceneRay = scene.ToSceneRay(worldRay);
            Ray3f  localRay = SceneTransforms.SceneToObject(this, sceneRay);

            // also need width in local coords
            float sceneWidth = scene.ToSceneDimension(visibleWidth);
            float localWidth = SceneTransforms.SceneToObject(this, sceneWidth) * HitWidthMultiplier;

            // bounding-box hit test (would be nice to do w/o object allocation...)
            AxisAlignedBox3d hitBox = localBounds;

            hitBox.Expand(localWidth);
            IntrRay3AxisAlignedBox3 box_test = new IntrRay3AxisAlignedBox3(localRay, hitBox);

            if (box_test.Find() == false)
            {
                return(false);
            }

            // raycast against curve (todo: spatial data structure for this? like 2D polycurve bbox tree?)
            double rayHitT;

            if (CurveUtils.FindClosestRayIntersection(curve, localWidth, localRay, out rayHitT))
            {
                hit = new SORayHit();
                // transform local hit point back into world coords
                Vector3f rayPos   = localRay.PointAt((float)rayHitT);
                Vector3f scenePos = SceneTransforms.ObjectToSceneP(this, rayPos);
                hit.hitPos    = SceneTransforms.SceneToWorldP(scene, scenePos);
                hit.fHitDist  = worldRay.Project(hit.hitPos);
                hit.hitNormal = Vector3f.Zero;
                hit.hitGO     = root;
                hit.hitSO     = this;
                return(true);
            }
            return(false);
        }
Beispiel #15
0
        public virtual bool FindNearest(Vector3d point, double maxDist, out SORayHit nearest, CoordSpace eInCoords)
        {
            nearest = null;
            if (enable_spatial == false)
            {
                return(false);
            }

            if (spatial == null)
            {
                spatial = new DMeshAABBTree3(mesh);
                spatial.Build();
            }

            // convert to local
            Vector3f local_pt = SceneTransforms.TransformTo((Vector3f)point, this, eInCoords, CoordSpace.ObjectCoords);

            if (mesh.CachedBounds.Distance(local_pt) > maxDist)
            {
                return(false);
            }

            int tid = spatial.FindNearestTriangle(local_pt);

            if (tid != DMesh3.InvalidID)
            {
                DistPoint3Triangle3 dist = MeshQueries.TriangleDistance(mesh, tid, local_pt);

                nearest          = new SORayHit();
                nearest.fHitDist = (float)Math.Sqrt(dist.DistanceSquared);

                Frame3f f_local = new Frame3f(dist.TriangleClosest, mesh.GetTriNormal(tid));
                Frame3f f       = SceneTransforms.TransformTo(f_local, this, CoordSpace.ObjectCoords, eInCoords);

                nearest.hitPos    = f.Origin;
                nearest.hitNormal = f.Z;
                nearest.hitGO     = RootGameObject;
                nearest.hitSO     = this;
                return(true);
            }
            return(false);
        }
Beispiel #16
0
        public virtual bool FindNearest(Vector3d point, double maxDist, out SORayHit nearest, CoordSpace eInCoords)
        {
            nearest = null;

            Frame3f f    = this.GetLocalFrame(eInCoords);
            double  dist = (f.Origin - point).Length;

            if (dist > maxDist)
            {
                return(false);
            }

            nearest           = new SORayHit();
            nearest.fHitDist  = (float)dist;
            nearest.hitPos    = f.Origin;
            nearest.hitNormal = Vector3f.Zero;
            nearest.hitGO     = RootGameObject;
            nearest.hitSO     = this;
            return(true);
        }
Beispiel #17
0
        /// <summary>
        /// Find intersection of *WORLD* ray with Mesh
        /// </summary>
        override public bool FindRayIntersection(Ray3f rayW, out SORayHit hit)
        {
            hit = null;
            if (enable_spatial == false)
            {
                return(false);
            }

            if (spatial == null)
            {
                spatial = new DMeshAABBTree3(mesh);
                spatial.Build();
            }

            // convert ray to local
            Frame3f f = new Frame3f(rayW.Origin, rayW.Direction);

            f = SceneTransforms.TransformTo(f, this, CoordSpace.WorldCoords, CoordSpace.ObjectCoords);
            Ray3d local_ray = new Ray3d(f.Origin, f.Z);

            int hit_tid = spatial.FindNearestHitTriangle(local_ray);

            if (hit_tid != DMesh3.InvalidID)
            {
                IntrRay3Triangle3 intr = MeshQueries.TriangleIntersection(mesh, hit_tid, local_ray);

                Frame3f hitF = new Frame3f(local_ray.PointAt(intr.RayParameter), mesh.GetTriNormal(hit_tid));
                hitF = SceneTransforms.TransformTo(hitF, this, CoordSpace.ObjectCoords, CoordSpace.WorldCoords);

                hit           = new SORayHit();
                hit.hitPos    = hitF.Origin;
                hit.hitNormal = hitF.Z;
                hit.hitIndex  = hit_tid;
                hit.fHitDist  = hit.hitPos.Distance(rayW.Origin);   // simpler than transforming!
                hit.hitGO     = RootGameObject;
                hit.hitSO     = this;
                return(true);
            }
            return(false);
        }
Beispiel #18
0
        /// <summary>
        /// Find intersection of *WORLD* ray with Mesh
        /// </summary>
        override public bool FindRayIntersection(Ray3f rayW, out SORayHit hit)
        {
            hit = null;
            if (enable_spatial == false)
            {
                return(false);
            }

            validate_spatial();

            // convert ray to local
            FScene scene     = this.GetScene();
            Ray3f  rayS      = scene.ToSceneRay(rayW);
            Ray3d  local_ray = SceneTransforms.SceneToObject(this, rayS);

            int hit_tid = spatial.FindNearestHitTriangle(local_ray);

            if (hit_tid != DMesh3.InvalidID)
            {
                IntrRay3Triangle3 intr = MeshQueries.TriangleIntersection(mesh, hit_tid, local_ray);

                Vector3f hitPos = (Vector3f)local_ray.PointAt(intr.RayParameter);
                hitPos = SceneTransforms.ObjectToSceneP(this, hitPos);
                hitPos = scene.ToWorldP(hitPos);

                Vector3f hitNormal = (Vector3f)mesh.GetTriNormal(hit_tid);
                hitNormal = SceneTransforms.ObjectToSceneN(this, hitNormal);
                hitNormal = scene.ToWorldN(hitNormal);

                hit           = new SORayHit();
                hit.hitPos    = hitPos;
                hit.hitNormal = hitNormal;
                hit.hitIndex  = hit_tid;
                hit.fHitDist  = hit.hitPos.Distance(rayW.Origin);   // simpler than transforming!
                hit.hitGO     = RootGameObject;
                hit.hitSO     = this;
                return(true);
            }
            return(false);
        }
Beispiel #19
0
        // [RMS] this is not working right now...
        override public bool FindRayIntersection(Ray3f ray, out SORayHit hit)
        {
            hit = null;
            if (enable_spatial == false)
            {
                return(false);
            }

            if (spatial == null)
            {
                spatial = new DMeshAABBTree3(mesh);
                spatial.Build();
            }

            Transform xform = ((GameObject)RootGameObject).transform;

            // convert ray to local
            Ray3d local_ray = new Ray3d();

            local_ray.Origin    = xform.InverseTransformPoint(ray.Origin);
            local_ray.Direction = xform.InverseTransformDirection(ray.Direction);
            local_ray.Direction.Normalize();

            int hit_tid = spatial.FindNearestHitTriangle(local_ray);

            if (hit_tid != DMesh3.InvalidID)
            {
                IntrRay3Triangle3 intr = MeshQueries.TriangleIntersection(mesh, hit_tid, local_ray);

                hit           = new SORayHit();
                hit.fHitDist  = (float)intr.RayParameter;
                hit.hitPos    = xform.TransformPoint((Vector3f)local_ray.PointAt(intr.RayParameter));
                hit.hitNormal = xform.TransformDirection((Vector3f)mesh.GetTriNormal(hit_tid));
                hit.hitGO     = RootGameObject;
                hit.hitSO     = this;
                return(true);
            }
            return(false);
        }
        override public bool UpdateCapture(InputEvent e)
        {
            if (eState == CaptureState.ClickType && FindHitGO(e.ray) != null)
            {
                return(true);
            }

            // otherwise we fall into drag state
            eState = CaptureState.DragType;

            SORayHit hit = null;

            if (TargetScene.FindSORayIntersection(e.ray, out hit))
            {
                if (hit.hitSO != lastHitObject)
                {
                    if (lastHitObject != null)
                    {
                        lastHitObject.PopOverrideMaterial();
                    }
                    lastHitObject = hit.hitSO;
                    if (lastHitObject.GetActiveMaterial() != tempMaterial)
                    {
                        lastHitObject.PushOverrideMaterial(tempMaterial);
                    }
                }
            }
            else
            {
                if (lastHitObject != null)
                {
                    lastHitObject.PopOverrideMaterial();
                }
                lastHitObject = null;
            }

            return(true);
        }
Beispiel #21
0
        override public bool FindRayIntersection(Ray3f ray, out SORayHit hit)
        {
            hit = null;

            Frame3f frameW   = GetLocalFrame(CoordSpace.WorldCoords);
            Ray     localRay = frameW.ToFrame(ray);

            Bounds hitBounds = GetLocalBoundingBox();

            if (hitBounds.IntersectRay(localRay) == false)
            {
                return(false);
            }

            GameObjectRayHit goHit;

            if (UnityUtil.FindGORayIntersection(ray, meshGO, out goHit))
            {
                hit = new SORayHit(goHit, this);
                return(true);
            }

            return(false);
        }
Beispiel #22
0
 public bool FindSORayIntersection(Ray3f ray, out SORayHit hit, Func <SceneObject, bool> filter = null)
 {
     return(HUDUtil.FindNearestRayIntersection(VisibleSceneObjects, ray, out hit,
                                               (SelectionMask == null) ? filter : mask_filter(filter)));
 }
Beispiel #23
0
 public bool FindRayIntersection(Ray3f ray, out SORayHit hit)
 {
     hit = null;
     return(false);
 }
Beispiel #24
0
        public static bool FindNearestRayIntersection(IEnumerable <SceneObject> vObjects, Ray3f ray, out SORayHit hit, Func <SceneObject, bool> filter = null)
        {
            hit = null;

            foreach (var so in vObjects)
            {
                if (filter != null && filter(so) == false)
                {
                    continue;
                }
                SORayHit soHit;
                if (so.FindRayIntersection(ray, out soHit))
                {
                    if (hit == null || soHit.fHitDist < hit.fHitDist)
                    {
                        hit = soHit;
                    }
                }
            }
            return(hit != null);
        }
Beispiel #25
0
 public static bool FindNearestPoint(IEnumerable <SceneObject> vSceneObjects, Vector3d point, double maxDist, out SORayHit nearest, CoordSpace eSpace = CoordSpace.WorldCoords)
 {
     nearest = null;
     foreach (var so in vSceneObjects)
     {
         if (so is SpatialQueryableSO)
         {
             SpatialQueryableSO spatialSO = so as SpatialQueryableSO;
             if (spatialSO.SupportsNearestQuery)
             {
                 SORayHit soNearest;
                 if (spatialSO.FindNearest(point, maxDist, out soNearest, eSpace))
                 {
                     if (nearest == null || soNearest.fHitDist < nearest.fHitDist)
                     {
                         nearest = soNearest;
                     }
                 }
             }
         }
     }
     return(nearest != null);
 }
 protected bool FindSORayIntersection(Ray3f ray, out SORayHit hit)
 {
     return((SelectPivotsFirst) ?
            scene.Scene.FindSORayIntersection_PivotPriority(ray, out hit, SelectionFilterF) :
            scene.Scene.FindSORayIntersection(ray, out hit, SelectionFilterF));
 }
Beispiel #27
0
 // stupid but convenient
 public static bool FindNearestRayIntersection(IEnumerable <TransformableSO> vSceneObjects, Ray ray, out SORayHit hit)
 {
     hit = null;
     foreach (var so in vSceneObjects)
     {
         SORayHit soHit;
         if (so.FindRayIntersection(ray, out soHit))
         {
             if (hit == null || soHit.fHitDist < hit.fHitDist)
             {
                 hit = soHit;
             }
         }
     }
     return(hit != null);
 }
Beispiel #28
0
 public bool FindSORayIntersection(Ray ray, out SORayHit hit, Func <SceneObject, bool> filter = null)
 {
     return(HUDUtil.FindNearestRayIntersection(SceneObjects, ray, out hit, filter));
 }