/// <summary>
        /// Gets the object space to world space transformation for the given Visual3D
        /// </summary>
        /// <param name="visual3DStart">The visual whose world space transform should be found</param>
        /// <param name="viewport">The containing Viewport3D for the Visual3D</param>
        /// <returns>The world space transformation</returns>
        internal static Matrix3D GetWorldTransformationMatrix(Visual3D visual3DStart, out Viewport3DVisual viewport)
        {
            DependencyObject dependencyObject = visual3DStart;
            Matrix3D         worldTransform   = Matrix3D.Identity;

            while (dependencyObject != null)
            {
                Visual3D visual3D = dependencyObject as Visual3D;

                // we reached the top
                if (visual3D == null)
                {
                    break;
                }

                Transform3D transform = (Transform3D)visual3D.GetValue(Visual3D.TransformProperty);

                if (transform != null)
                {
                    transform.Append(ref worldTransform);
                }

                dependencyObject = VisualTreeHelper.GetParent(dependencyObject);
            }

            if (dependencyObject != null)
            {
                viewport = (Viewport3DVisual)dependencyObject;
            }
            else
            {
                viewport = null;
            }

            return(worldTransform);
        }