internal void ApplyPatch(RigidBodyPatch patch, bool patchVelocities)
        {
            // Apply any changes made to the state of the mixed reality extension runtime version of the rigid body.

            if (patchVelocities)
            {
                if (patch.Velocity != null && patch.Velocity.IsPatched())
                {
                    _rigidbody.LinearVelocity = _rigidbody.LinearVelocity.GetPatchApplied(_sceneRoot.ToGlobal(Velocity.ApplyPatch(patch.Velocity).ToVector3()));
                }
                if (patch.AngularVelocity != null && patch.AngularVelocity.IsPatched())
                {
                    var angularVelocity = _sceneRoot.ToGlobal(AngularVelocity.ApplyPatch(patch.AngularVelocity).ToVector3());
                    angularVelocity.x          = Mathf.Deg2Rad(angularVelocity.x);
                    angularVelocity.y          = Mathf.Deg2Rad(angularVelocity.y);
                    angularVelocity.z          = Mathf.Deg2Rad(angularVelocity.z);
                    _rigidbody.AngularVelocity = _rigidbody.AngularVelocity.GetPatchApplied(angularVelocity);
                }
            }

            if (patch.Mass.HasValue)
            {
                _rigidbody.Mass = _rigidbody.Mass.GetPatchApplied(Mass.ApplyPatch(patch.Mass));
            }
            if (patch.DetectCollisions.HasValue)
            {
                var collisionShape = _rigidbody.GetChild <CollisionShape>();
                collisionShape.Disabled = collisionShape.Disabled.GetPatchApplied(!DetectCollisions.ApplyPatch(patch.DetectCollisions));
            }
            if (patch.CollisionDetectionMode.HasValue)
            {
                switch (patch.CollisionDetectionMode)
                {
                case MRECollisionDetectionMode.Continuous:
                case MRECollisionDetectionMode.ContinuousDynamic:
                    _rigidbody.ContinuousCd = true;
                    break;

                case MRECollisionDetectionMode.Discrete:
                    _rigidbody.ContinuousCd = false;
                    break;
                }
            }
            if (patch.UseGravity.HasValue)
            {
                _rigidbody.GravityScale = (bool)patch.UseGravity ? 1 : 0;
            }
            if (patch.IsKinematic.HasValue)
            {
                IsKinematic = patch.IsKinematic.Value;
            }
            if (patch.ConstraintFlags.HasValue)
            {
                if ((bool)patch.ConstraintFlags?.HasFlag(MRERigidBodyConstraints.FreezePositionX))
                {
                    _rigidbody.AxisLockLinearX = true;
                }
                if ((bool)patch.ConstraintFlags?.HasFlag(MRERigidBodyConstraints.FreezePositionY))
                {
                    _rigidbody.AxisLockLinearY = true;
                }
                if ((bool)patch.ConstraintFlags?.HasFlag(MRERigidBodyConstraints.FreezePositionZ))
                {
                    _rigidbody.AxisLockLinearZ = true;
                }
                if ((bool)patch.ConstraintFlags?.HasFlag(MRERigidBodyConstraints.FreezeRotationX))
                {
                    _rigidbody.AxisLockAngularX = true;
                }
                if ((bool)patch.ConstraintFlags?.HasFlag(MRERigidBodyConstraints.FreezeRotationY))
                {
                    _rigidbody.AxisLockAngularY = true;
                }
                if ((bool)patch.ConstraintFlags?.HasFlag(MRERigidBodyConstraints.FreezeRotationZ))
                {
                    _rigidbody.AxisLockAngularZ = true;
                }
            }
        }
Beispiel #2
0
        internal void ApplyPatch(RigidBodyPatch patch, bool patchVelocities)
        {
            // Apply any changes made to the state of the mixed reality extension runtime version of the rigid body.

            if (patchVelocities)
            {
                if (patch.Velocity != null && patch.Velocity.IsPatched())
                {
                    _rigidbody.velocity = _rigidbody.velocity.GetPatchApplied(_sceneRoot.TransformDirection(Velocity.ApplyPatch(patch.Velocity).ToVector3()));
                }
                if (patch.AngularVelocity != null && patch.AngularVelocity.IsPatched())
                {
                    _rigidbody.angularVelocity = _rigidbody.angularVelocity.GetPatchApplied(_sceneRoot.TransformDirection(AngularVelocity.ApplyPatch(patch.AngularVelocity).ToVector3()));
                }
            }

            if (patch.Mass.HasValue)
            {
                _rigidbody.mass = _rigidbody.mass.GetPatchApplied(Mass.ApplyPatch(patch.Mass));
            }
            if (patch.DetectCollisions.HasValue)
            {
                _rigidbody.detectCollisions = _rigidbody.detectCollisions.GetPatchApplied(DetectCollisions.ApplyPatch(patch.DetectCollisions));
            }
            if (patch.CollisionDetectionMode.HasValue)
            {
                _rigidbody.collisionDetectionMode = _rigidbody.collisionDetectionMode.GetPatchApplied(CollisionDetectionMode.ApplyPatch(patch.CollisionDetectionMode));
            }
            if (patch.UseGravity.HasValue)
            {
                _rigidbody.useGravity = _rigidbody.useGravity.GetPatchApplied(UseGravity.ApplyPatch(patch.UseGravity));
            }
            if (patch.IsKinematic.HasValue)
            {
                _rigidbody.isKinematic = _rigidbody.isKinematic.GetPatchApplied(IsKinematic.ApplyPatch(patch.IsKinematic));
            }
            _rigidbody.constraints = (RigidbodyConstraints)((int)_rigidbody.constraints).GetPatchApplied((int)ConstraintFlags.ApplyPatch(patch.ConstraintFlags));
        }
Beispiel #3
0
 internal void ApplyPatch(RigidBodyPatch patch)
 {
     // Apply any changes made to the state of the mixed reality extension runtime version of the rigid body.
     if (patch.Position != null && patch.Position.IsPatched())
     {
         var localPosition = _sceneRoot.InverseTransformPoint(_rigidbody.position).ToMWVector3();
         _rigidbody.position = _rigidbody.position.GetPatchApplied(_sceneRoot.TransformPoint(localPosition.ApplyPatch(patch.Position).ToVector3()));
     }
     if (patch.Rotation != null && patch.Rotation.IsPatched())
     {
         var localRotation = (_rigidbody.rotation * _sceneRoot.rotation).ToMWQuaternion();
         _rigidbody.rotation = _sceneRoot.rotation * _rigidbody.rotation.GetPatchApplied(localRotation.ApplyPatch(patch.Rotation));
     }
     if (patch.Velocity != null && patch.Velocity.IsPatched())
     {
         _rigidbody.velocity = _rigidbody.velocity.GetPatchApplied(_sceneRoot.TransformDirection(Velocity.ApplyPatch(patch.Velocity).ToVector3()));
     }
     if (patch.AngularVelocity != null && patch.AngularVelocity.IsPatched())
     {
         _rigidbody.angularVelocity = _rigidbody.angularVelocity.GetPatchApplied(_sceneRoot.TransformDirection(AngularVelocity.ApplyPatch(patch.AngularVelocity).ToVector3()));
     }
     if (patch.Mass.HasValue)
     {
         _rigidbody.mass = _rigidbody.mass.GetPatchApplied(Mass.ApplyPatch(patch.Mass));
     }
     if (patch.DetectCollisions.HasValue)
     {
         _rigidbody.detectCollisions = _rigidbody.detectCollisions.GetPatchApplied(DetectCollisions.ApplyPatch(patch.DetectCollisions));
     }
     if (patch.CollisionDetectionMode.HasValue)
     {
         _rigidbody.collisionDetectionMode = _rigidbody.collisionDetectionMode.GetPatchApplied(CollisionDetectionMode.ApplyPatch(patch.CollisionDetectionMode));
     }
     if (patch.UseGravity.HasValue)
     {
         _rigidbody.useGravity = _rigidbody.useGravity.GetPatchApplied(UseGravity.ApplyPatch(patch.UseGravity));
     }
     _rigidbody.constraints = (RigidbodyConstraints)((int)_rigidbody.constraints).GetPatchApplied((int)ConstraintFlags.ApplyPatch(patch.ConstraintFlags));
 }