示例#1
0
        protected virtual void DrawBasic()
        {
            TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);

            Draw("emit", "This allows you to control the hit data this component sends out.\n\nPointsIn3D = Point drawing in 3D.\n\nPointsOnUV = Point drawing on UV (requires non-convex MeshCollider).\n\nTrianglesIn3D = Triangle drawing in 3D (requires non-convex MeshCollider).");
            BeginError(Any(tgts, t => t.Layers == 0));
            Draw("layers", "The layers you want the raycast to hit.");
            EndError();
            Draw("guiLayers", "Fingers that began touching the screen on top of these UI layers will be ignored.");
            BeginError(Any(tgts, t => P3dHelper.GetCamera(t.Camera) == null));
            Draw("_camera", "Orient to a specific camera?\n\nNone = MainCamera.");
            EndError();

            Separator();

            Draw("rotateTo", "This allows you to control how the paint is rotated.\n\nNormal = The rotation will be based on a normal direction, and rolled relative to an up axis.\n\nWorld = The rotation will be aligned to the world, or given no rotation.\n\nThisRotation = The current Transform.rotation will be used.\n\nThisLocalRotation = The current Transform.localRotation will be used.\n\nCustomRotation = The specified Transform.rotation will be used.\n\nCustomLocalRotation = The specified Transform.localRotation will be used.");
            if (Any(tgts, t => t.RotateTo == P3dHitScreenBase.RotationType.Normal))
            {
                BeginIndent();
                Draw("normalDirection", "Which direction should the hit point rotation be based on?", "Direction");
                Draw("normalRelativeTo", "Based on the normal direction, what should the rotation be rolled relative to?\n\nWorldUp = It will be rolled so the up vector is world up.\n\nCameraUp = It will be rolled so the up vector is camera up.\n\nDrawAngle = It will be rolled according to the mouse/finger movement on screen.", "Relative To");
                EndIndent();
            }
            if (Any(tgts, t => t.RotateTo == P3dHitScreenBase.RotationType.CustomRotation || t.RotateTo == P3dHitScreenBase.RotationType.CustomLocalRotation))
            {
                BeginIndent();
                Draw("customTransform", "This allows you to specify the Transform when using RotateTo = CustomRotation/CustomLocalRotation.");
                EndIndent();
            }
        }
        private void DoThrow(Vector2 screenPosition)
        {
            if (prefab != null)
            {
                var camera = P3dHelper.GetCamera();

                if (camera != null)
                {
                    if (storeStates == true)
                    {
                        P3dStateManager.StoreAllStates();
                    }

                    // Find the ray for this screen position
                    var ray      = camera.ScreenPointToRay(screenPosition);
                    var rotation = Quaternion.LookRotation(ray.direction);

                    // Loop through all prefabs and spawn them
                    var clone = Instantiate(prefab, ray.origin, rotation);

                    clone.SetActive(true);

                    // Throw with velocity?
                    var cloneRigidbody = clone.GetComponent <Rigidbody>();

                    if (cloneRigidbody != null)
                    {
                        cloneRigidbody.velocity = clone.transform.forward * Speed;
                    }
                }
            }
        }
示例#3
0
        private void PaintAt(Vector2 screenPosition, bool preview, float pressure, object owner)
        {
            var camera = P3dHelper.GetCamera(_camera);

            if (camera != null)
            {
                if (touchOffset != 0.0f && Input.touchCount > 0)
                {
                    screenPosition.y += touchOffset * P3dInputManager.ScaleFactor;
                }

                var ray = camera.ScreenPointToRay(screenPosition);
                var hit = default(RaycastHit);

                if (Physics.Raycast(ray, out hit, float.PositiveInfinity, layers) == true)
                {
                    var finalUp       = orientation == OrientationType.CameraUp ? camera.transform.up : Vector3.up;
                    var finalPosition = hit.point + hit.normal * offset;
                    var finalNormal   = normal == NormalType.HitNormal ? -hit.normal : ray.direction;
                    var finalRotation = Quaternion.LookRotation(finalNormal, finalUp);

                    hitCache.InvokeRaycast(gameObject, null, null, preview, hit, pressure);

                    DispatchHits(preview, hit.collider, finalPosition, finalRotation, pressure, owner);

                    return;
                }
            }

            BreakHits(owner);
        }
示例#4
0
        protected virtual void LateUpdate()
        {
            if (interval >= 0.0f)
            {
                current += Time.fixedDeltaTime;

                if (current >= interval)
                {
                    current = 0.0f;

                    if (pointA != null && pointB != null)
                    {
                        var camera    = P3dHelper.GetCamera(_camera);
                        var positionA = pointA.position;
                        var positionB = pointB.position;
                        var finalUp   = orientation == OrientationType.CameraUp && camera != null ? camera.transform.up : Vector3.up;
                        var rotation  = Quaternion.LookRotation(positionB - positionA, finalUp);

                        SubmitLine(preview, priority, pointA.position, pointB.position, rotation, pressure, this);
                    }
                }
            }

            UpdatePointAndLine();
        }
示例#5
0
        protected virtual void Update()
        {
            if (prefab != null && Input.GetMouseButtonDown(0) == true && P3dInputManager.PointOverGui(Input.mousePosition) == false)
            {
                var camera = P3dHelper.GetCamera();

                if (camera != null)
                {
                    if (storeStates == true)
                    {
                        P3dStateManager.StoreAllStates();
                    }

                    // Find the ray for this screen position
                    var ray      = camera.ScreenPointToRay(Input.mousePosition);
                    var rotation = Quaternion.LookRotation(ray.direction);

                    // Loop through all prefabs and spawn them
                    var clone = Instantiate(prefab, ray.origin, rotation);

                    // Throw with velocity?
                    var cloneRigidbody = clone.GetComponent <Rigidbody>();

                    if (cloneRigidbody != null)
                    {
                        cloneRigidbody.velocity = clone.transform.forward * Speed;
                    }
                }
            }
        }
示例#6
0
        protected void PaintAt(Vector2 screenPosition, bool preview, float pressure)
        {
            var camera = P3dHelper.GetCamera();

            if (camera != null)
            {
                var hit = default(RaycastHit);
                var ray = camera.ScreenPointToRay(screenPosition);

                if (Physics.Raycast(ray, out hit, float.PositiveInfinity, layers) == true)
                {
                    var point  = hit.point;
                    var normal = -ray.direction;

                    if (offset != 0.0f)
                    {
                        point += hit.normal * offset;
                    }

                    if (useHitNormal == true)
                    {
                        normal = hit.normal;
                    }

                    GetComponentsInChildren(hitHandlers);

                    for (var i = 0; i < hitHandlers.Count; i++)
                    {
                        hitHandlers[i].HandleHit(point, normal, preview, pressure);
                    }
                }
            }
        }
示例#7
0
        protected override void OnInspector()
        {
            BeginError(Any(t => P3dHelper.GetCamera(t.Camera) == null));
            Draw("_camera", "Orient to a specific camera?\n\nNone = MainCamera.");
            EndError();
            BeginError(Any(t => t.Layers == 0));
            Draw("layers", "The layers you want the raycast to hit.");
            EndError();
            Draw("spacing", "If you want the paint to continuously apply while moving the mouse, this allows you to set how many pixels are between each step.\n\n0 = Paint once when released.\n\n-1 = Paint every frame.");
            Draw("key", "The key that must be held for this component to activate on desktop platforms.\n\nNone = Any mouse button.");

            Separator();

            Draw("rotateTo", "This allows you to control how the paint is rotated.\n\nNormal = The rotation will be based on a normal direction, and rolled relative to an up axis.\n\nWorld = The rotation will be aligned to the world, or given no rotation.\n\nThisRotation = The current Transform.rotation will be used.\n\nThisLocalRotation = The current Transform.localRotation will be used.\n\nCustomRotation = The specified Transform.rotation will be used.\n\nCustomLocalRotation = The specified Transform.localRotation will be used.");
            if (Any(t => t.RotateTo == P3dHitScreen.RotationType.Normal))
            {
                BeginIndent();
                Draw("normalDirection", "Which direction should the hit point rotation be based on?", "Direction");
                Draw("normalRelativeTo", "Based on the normal direction, what should the rotation be rolled relative to?\n\nWorldUp = It will be rolled so the up vector is world up.\n\nCameraUp = It will be rolled so the up vector is camera up.", "Relative To");
                EndIndent();
            }
            if (Any(t => t.RotateTo == P3dHitScreen.RotationType.CustomRotation || t.RotateTo == P3dHitScreen.RotationType.CustomLocalRotation))
            {
                BeginIndent();
                Draw("customTransform", "This allows you to specify the Transform when using RotateTo = CustomRotation/CustomLocalRotation.");
                EndIndent();
            }

            Draw("offset", "If you want the raycast hit point to be offset from the surface a bit, this allows you to set by how much in world space.");
            Draw("touchOffset", "If you want the hit point to be offset upwards when using touch input, this allows you to specify the physical distance the hit will be offset by on the screen. This is useful if you find paint hard to see because it's underneath your finger.");
            Draw("storeStates", "Should painting triggered from this component be eligible for being undone?");

            Separator();

            Draw("showPreview", "Should the applied paint be applied as a preview?");
            Draw("priority", "This allows you to override the order this paint gets applied to the object during the current frame.");

            Separator();

            Draw("draw", "This allows you to control how the drawn shape is filled.\n\nPoints = Point drawing in 3D.\n\nPointsIn3DFilled = Point drawing in 3D, then the drawn shape will be filled in with points in a regular grid.\n\nPointsOnUV = Point drawing on UV (requires non-convex MeshCollider).\n\nTrianglesIn3D = Triangle drawing in 3D.");
            if (Any(t => t.Draw == P3dHitScreen.DrawType.PointsIn3DFilled))
            {
                BeginIndent();
                Draw("fillSpacing", "This allows you to set the pixel distance between each grid point.\n\nNOTE: The lower you set this, the lower the performance will be.", "Spacing");
                EndIndent();
            }

            Separator();

            base.OnInspector();

            var point    = Target.Draw == P3dHitScreen.DrawType.PointsIn3D || Target.Draw == P3dHitScreen.DrawType.PointsIn3DFilled;
            var line     = point == true && Target.ConnectHits == true;
            var triangle = Target.Draw == P3dHitScreen.DrawType.TrianglesIn3D;
            var coord    = Target.Draw == P3dHitScreen.DrawType.PointsOnUV;

            Target.HitCache.Inspector(Target.gameObject, point: point, line: line, triangle: triangle, coord: coord);
        }
示例#8
0
        private void SubmitHit(bool preview)
        {
            if (pointA != null && pointB != null)
            {
                var camera    = P3dHelper.GetCamera(_camera);
                var positionA = pointA.position;
                var positionB = pointB.position;
                var finalUp   = orientation == OrientationType.CameraUp && camera != null ? camera.transform.up : Vector3.up;
                var rotation  = Quaternion.LookRotation(positionB - positionA, finalUp);

                SubmitLine(preview, priority, pointA.position, pointB.position, rotation, pressure, this);
            }
        }
        private void SubmitHit(bool preview)
        {
            if (pointA != null && pointB != null)
            {
                var camera    = P3dHelper.GetCamera(_camera);
                var positionA = pointA.position;
                var positionB = pointB.position;
                var finalUp   = orientation == OrientationType.CameraUp && camera != null ? camera.transform.up : Vector3.up;
                var vector    = positionB - positionA;
                var rotation  = vector != Vector3.zero ? Quaternion.LookRotation(vector, finalUp) : Quaternion.identity;

                connector.SubmitLine(gameObject, preview, priority, pointA.position, pointB.position, rotation, pressure, this);
            }
        }
示例#10
0
            public static void SetMatrix(Vector3 position, Quaternion rotation, float angle, Vector3 size)
            {
                var up     = Vector3.up;
                var camera = P3dHelper.GetCamera();

                if (camera != null)
                {
                    up = camera.transform.up;
                }

                //cachedMatrix    = Matrix4x4.Translate(position) * Matrix4x4.Rotate(rotation * Quaternion.Euler(0.0f, 0.0f, angle)) * Matrix4x4.Scale(size);
                cachedMatrix    = Matrix4x4.TRS(position, rotation * Quaternion.Euler(0.0f, 0.0f, angle), size);
                cachedPosition  = position;
                cachedSqrRadius = (size * 0.5f).sqrMagnitude;
                cachedDirection = rotation * Vector3.forward;
            }
示例#11
0
        protected virtual void LateUpdate()
        {
            var camera = P3dHelper.GetCamera();

            if (camera != null)
            {
                var ray = camera.ScreenPointToRay(P3dInputManager.MousePosition);
                var hit = default(RaycastHit);
                var cam = camera.transform.rotation;

                if (Physics.Raycast(ray, out hit, simulatedReach) == true)
                {
                    hitDistance = hit.distance;
                    hitRotation = Quaternion.Inverse(cam) * Quaternion.LookRotation(-hit.normal);
                }

                var leftHandRot = Quaternion.Slerp(cam, cam * hitRotation, simulatedNormalInfluence) * Quaternion.Euler(simulatedTilt.x, -simulatedTilt.y, simulatedTilt.z);
                var leftHandPos = ray.GetPoint(hitDistance) + leftHandRot * new Vector3(simulatedOffset.x, simulatedOffset.y, simulatedOffset.z);

                SetSimulatedState(XRNode.LeftHand, leftHandPos, leftHandRot);

                var rightHandRot = Quaternion.Slerp(cam, cam * hitRotation, simulatedNormalInfluence) * Quaternion.Euler(simulatedTilt.x, simulatedTilt.y, simulatedTilt.z);
                var rightHandPos = ray.GetPoint(hitDistance) + rightHandRot * new Vector3(simulatedOffset.x, -simulatedOffset.y, simulatedOffset.z);

                SetSimulatedState(XRNode.RightHand, rightHandPos, rightHandRot);

                SetSimulatedState(XRNode.Head, camera.transform.position, camera.transform.rotation);

                SetSimulatedState(XRNode.CenterEye, camera.transform.position, camera.transform.rotation);

                SetSimulatedState(XRNode.LeftEye, camera.transform.TransformPoint(simulatedEyeOffset.x, simulatedEyeOffset.y, simulatedEyeOffset.z), camera.transform.rotation);

                SetSimulatedState(XRNode.RightEye, camera.transform.TransformPoint(-simulatedEyeOffset.x, simulatedEyeOffset.y, simulatedEyeOffset.z), camera.transform.rotation);
            }

            for (var i = 0; i <= 8; i++)
            {
                UpdateTools((XRNode)i);
            }

            PrevLeftTrigger  = LeftTrigger;
            PrevLeftGrip     = LeftGrip;
            PrevRightTrigger = RightTrigger;
            PrevRightGrip    = RightGrip;
        }
示例#12
0
        protected virtual void Update()
        {
            inputManager.Update(key);

            if (prefab != null)
            {
                var fingers = inputManager.Fingers;

                if (fingers.Count == 1 && fingers[0].Down == true && fingers[0].StartedOverGui == false)
                {
                    var camera = P3dHelper.GetCamera();

                    if (camera != null)
                    {
                        if (storeStates == true)
                        {
                            P3dStateManager.StoreAllStates();
                        }

                        // Find the ray for this screen position
                        var ray      = camera.ScreenPointToRay(P3dInputManager.MousePosition);
                        var rotation = Quaternion.LookRotation(ray.direction);

                        // Loop through all prefabs and spawn them
                        var clone = Instantiate(prefab, ray.origin, rotation);

                        clone.SetActive(true);

                        // Throw with velocity?
                        var cloneRigidbody = clone.GetComponent <Rigidbody>();

                        if (cloneRigidbody != null)
                        {
                            cloneRigidbody.velocity = clone.transform.forward * Speed;
                        }
                    }
                }
            }
        }
示例#13
0
        private void PaintAt(Link link, Vector2 screenPosition, bool preview, float pressure, object owner)
        {
            if (link != null)
            {
                link.Record(screenPosition);
            }

            var camera = P3dHelper.GetCamera(_camera);

            if (camera != null)
            {
                if (touchOffset != 0.0f && P3dInputManager.TouchCount > 0)
                {
                    screenPosition.y += touchOffset * P3dInputManager.ScaleFactor;
                }

                var ray = camera.ScreenPointToRay(screenPosition);
                var hit = default(RaycastHit);

                if (Physics.Raycast(ray, out hit, float.PositiveInfinity, layers) == true)
                {
                    var finalPosition = hit.point + hit.normal * offset;
                    var finalRotation = Quaternion.identity;

                    switch (rotateTo)
                    {
                    case RotationType.Normal:
                    {
                        var finalNormal = default(Vector3);

                        switch (normalDirection)
                        {
                        case DirectionType.HitNormal: finalNormal = hit.normal; break;

                        case DirectionType.RayDirection: finalNormal = -ray.direction; break;

                        case DirectionType.CameraDirection: finalNormal = -camera.transform.forward; break;
                        }

                        var finalUp = default(Vector3);

                        switch (normalRelativeTo)
                        {
                        case RelativeType.WorldUp: finalUp = Vector3.up; break;

                        case RelativeType.CameraUp: finalUp = camera.transform.up; break;
                        }

                        finalRotation = Quaternion.LookRotation(-finalNormal, finalUp);
                    }
                    break;

                    case RotationType.World: finalRotation = Quaternion.identity; break;

                    case RotationType.ThisRotation: finalRotation = transform.rotation; break;

                    case RotationType.ThisLocalRotation: finalRotation = transform.localRotation; break;

                    case RotationType.CustomRotation: if (customTransform != null)
                        {
                            finalRotation = customTransform.rotation;
                        }
                        break;

                    case RotationType.CustomLocalRotation: if (customTransform != null)
                        {
                            finalRotation = customTransform.localRotation;
                        }
                        break;
                    }

                    switch (draw)
                    {
                    case DrawType.PointsIn3D:
                    case DrawType.PointsIn3DFilled:
                    {
                        SubmitPoint(preview, priority, pressure, finalPosition, finalRotation, owner);
                    }
                    break;

                    case DrawType.PointsOnUV:
                    {
                        hitCache.InvokeCoord(gameObject, preview, priority, pressure, new P3dHit(hit), finalRotation);
                    }
                    break;

                    case DrawType.TrianglesIn3D:
                    {
                        hitCache.InvokeTriangle(gameObject, preview, priority, pressure, hit, finalRotation);
                    }
                    break;
                    }

                    return;
                }
            }

            BreakHits(owner);
        }
示例#14
0
        protected void PaintAt(P3dPointConnector connector, P3dHitCache hitCache, Vector2 screenPosition, Vector2 screenPositionOld, bool preview, float pressure, object owner)
        {
            var camera = P3dHelper.GetCamera(_camera);

            if (camera != null)
            {
                if (touchOffset != 0.0f && P3dInputManager.TouchCount > 0)
                {
                    screenPosition.y += touchOffset / P3dInputManager.ScaleFactor;
                }

                var ray           = camera.ScreenPointToRay(screenPosition);
                var hit2D         = Physics2D.GetRayIntersection(ray, float.PositiveInfinity, layers);
                var hit3D         = default(RaycastHit);
                var finalPosition = default(Vector3);
                var finalRotation = default(Quaternion);

                // Hit 3D?
                if (Physics.Raycast(ray, out hit3D, float.PositiveInfinity, layers) == true && (hit2D.collider == null || hit3D.distance < hit2D.distance))
                {
                    CalcHitData(hit3D.point, hit3D.normal, ray, camera, screenPositionOld, out finalPosition, out finalRotation);

                    if (emit == EmitType.PointsIn3D)
                    {
                        if (connector != null)
                        {
                            connector.SubmitPoint(gameObject, preview, priority, pressure, finalPosition, finalRotation, owner);
                        }
                        else
                        {
                            hitCache.InvokePoint(gameObject, preview, priority, pressure, finalPosition, finalRotation);
                        }

                        return;
                    }
                    else if (emit == EmitType.PointsOnUV)
                    {
                        hitCache.InvokeCoord(gameObject, preview, priority, pressure, new P3dHit(hit3D), finalRotation);

                        return;
                    }
                    else if (emit == EmitType.TrianglesIn3D)
                    {
                        hitCache.InvokeTriangle(gameObject, preview, priority, pressure, hit3D, finalRotation);

                        return;
                    }
                }
                // Hit 2D?
                else if (hit2D.collider != null)
                {
                    CalcHitData(hit2D.point, hit2D.normal, ray, camera, screenPositionOld, out finalPosition, out finalRotation);

                    if (emit == EmitType.PointsIn3D)
                    {
                        if (connector != null)
                        {
                            connector.SubmitPoint(gameObject, preview, priority, pressure, finalPosition, finalRotation, owner);
                        }
                        else
                        {
                            hitCache.InvokePoint(gameObject, preview, priority, pressure, finalPosition, finalRotation);
                        }

                        return;
                    }
                }
            }

            if (connector != null)
            {
                connector.BreakHits(owner);
            }
        }