public void OnBodyScaledCallback(Body body)
        {
            GameObject      gameObject = UnityUtil.BodyMapper.FirstOrDefault(x => x.Value.BodyId.ptr == body.BodyId.ptr).Key;
            LeapInteraction properties = gameObject.GetComponent <LeapInteraction>();
            float           bodyScale  = body.Scale;
            float           scaleRatio = bodyScale / properties.scale;

            gameObject.transform.localScale *= scaleRatio;
            properties.scale = bodyScale;
        }
示例#2
0
        static protected void RepositionHeldBody(GameObject gameObject, Body leapBody)
        {
            LeapTransform leapTransform        = leapBody.Transform;
            LeapTransform targetUnityTransform = LeapTransformToUnity(leapTransform, gameObject);

            LeapInteraction leapInteraction = gameObject.GetComponent <LeapInteraction>();

            if (gameObject.GetComponent <Rigidbody>().isKinematic || !leapInteraction.UseVelocity)
            {
                ApplyTargetUnityTransformAsVelocities(targetUnityTransform, gameObject);

                gameObject.transform.position = targetUnityTransform.Position;
                gameObject.transform.rotation = targetUnityTransform.Rotation;
                if (true)
                {
                    LeapInteraction props = gameObject.GetComponent <LeapInteraction>();
                    props.tmpVelocity        = gameObject.GetComponent <Rigidbody>().velocity;
                    props.tmpAngularVelocity = gameObject.GetComponent <Rigidbody>().angularVelocity;
                    props.velocityToTransfer = true;

                    gameObject.GetComponent <Rigidbody>().velocity        = Vector3.zero;
                    gameObject.GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
                }
            }
            else
            {
                ApplyTargetUnityTransformAsVelocities(targetUnityTransform, gameObject);
            }

            if (UnityUtil.FilterHandCollisionPerColliderExplicitly && !leapInteraction.CollisionsWithHandFilteredOut)
            {
                HandViewer.Instance.DisableHandCollisionsWithGameObject(gameObject);
                leapInteraction.CollisionsWithHandFilteredOut = true;
            }

            if (UnityUtil.LayerForHeldObjects != UnityUtil.LayerForReleasedObjects)
            {
                SetLayerForHierarchy(gameObject, UnityUtil.LayerForHeldObjects);
            }
        }
示例#3
0
        static protected void RepositionFreeBody(GameObject gameObject, Body leapBody)
        {
            LeapInteraction props = gameObject.GetComponent <LeapInteraction>();

            if (props.velocityToTransfer)
            {
                gameObject.GetComponent <Rigidbody>().velocity        = props.tmpVelocity;
                gameObject.GetComponent <Rigidbody>().angularVelocity = props.tmpAngularVelocity;
                props.velocityToTransfer = false;
            }

            LeapInteraction leapInteraction = gameObject.GetComponent <LeapInteraction>();

            if (UnityUtil.FilterHandCollisionPerColliderExplicitly && leapInteraction.CollisionsWithHandFilteredOut)
            {
                HandViewer.Instance.EnableHandCollisionsWithGameObject(gameObject);
                leapInteraction.CollisionsWithHandFilteredOut = false;
            }

            if (UnityUtil.LayerForReleasedObjects != UnityUtil.LayerForHeldObjects)
            {
                SetLayerForHierarchy(gameObject, UnityUtil.LayerForReleasedObjects);
            }
        }
示例#4
0
        public Body AddBodyToLeapFromUnity(Rigidbody rigidbody)
        {
            LeapInteraction properties = rigidbody.GetComponent <LeapInteraction>();

            if (rigidbody.collider && properties)
            {
                Collider[] colliders = rigidbody.GetComponents <Collider>();

                Shape shape = new Shape();
                foreach (Collider collider in colliders)
                {
                    if (collider is SphereCollider)
                    {
                        float          scale = rigidbody.transform.lossyScale.x;
                        SphereCollider sc    = collider as SphereCollider;
                        shape = Shape.CreateSphere(sc.radius * scale);
                    }
                    else if (collider is CapsuleCollider)
                    {
                        float           scale = rigidbody.transform.lossyScale.x;
                        CapsuleCollider cc    = collider as CapsuleCollider;
                        shape = Shape.CreateCapsule((Shape.CapsuleOrientation)cc.direction, Math.Max(0f, cc.height / 2f - cc.radius) * scale, cc.radius * scale);
                    }
                    else if (collider is BoxCollider)
                    {
                        BoxCollider bc    = collider as BoxCollider;
                        Vector3     scale = collider.transform.lossyScale;
                        shape = Shape.CreateBox(Vector3.Scale(bc.size, scale) / 2f, 0f);
                    }
                }

                if (shape != IntPtr.Zero)
                {
                    Body body = new Body();//shape);
                    body.Shape = shape;
                    body.Mass  = rigidbody.mass;

                    // Add body anchors.
                    for (int i = 0; i < rigidbody.transform.childCount; i++)
                    {
                        Transform child = rigidbody.transform.GetChild(i);
                        if (child.name.StartsWith("Anchor") || child.name.StartsWith("ClickAnchor"))
                        {
                            LeapTransform anchor = new LeapTransform();
                            anchor.Position = Vector3.Scale(child.localPosition - rigidbody.transform.rotation * TransformSyncUtil.GetCenterFromCollider(rigidbody.gameObject), rigidbody.transform.lossyScale);
                            anchor.Rotation = child.localRotation;
                            if (child.name.StartsWith("Anchor"))
                            {
                                body.Shape.AddAnchor(anchor);
                            }
                            if (child.name.StartsWith("ClickAnchor"))
                            {
                                body.Shape.AddClickAnchor(anchor);
                            }
                        }
                    }

                    // Apply BodyProperties
                    properties.ApplyToBody(body);

                    Scene.AddBody(body);
                    BodyMapper.Add(rigidbody.gameObject, body);

                    rigidbody.maxAngularVelocity = 100.0f;

                    return(body);
                }
            }
            return(null);
        }