Пример #1
0
        /// <summary>
        /// Copys all relevant values of the given camera to the current camera sample.
        /// </summary>
        /// <param name="camera">The camera to copy.</param>
        /// <param name="convertTransformToUsd">
        ///   If true, converts the transform matrix from left handed(Unity) to right handed(USD). If
        ///   you're unsure about this parameter, it should be left to the default value of true.
        /// </param>
        public void CopyFromCamera(UnityEngine.Camera camera, bool convertTransformToUsd = true)
        {
            // GfCamera is a gold mine of camera math.
            pxr.GfCamera c = new pxr.GfCamera();

            // Setup focalLength & apertures.
            c.SetPerspectiveFromAspectRatioAndFieldOfView(camera.aspect, camera.fieldOfView,
                                                          pxr.GfCamera.FOVDirection.FOVVertical);
            clippingRange      = new UnityEngine.Vector2(camera.nearClipPlane, camera.farClipPlane);
            focalLength        = c.GetFocalLength();
            horizontalAperture = c.GetHorizontalAperture();
            verticalAperture   = c.GetVerticalAperture();
            projection         = camera.orthographic
                        ? ProjectionType.Orthographic
                        : ProjectionType.Perspective;

            var tr = camera.transform;

            transform = UnityEngine.Matrix4x4.TRS(tr.localPosition,
                                                  tr.localRotation,
                                                  tr.localScale);
            if (convertTransformToUsd)
            {
                ConvertTransform();
            }
        }
Пример #2
0
        /// <summary>
        /// Copyies the current sample values to the given camera.
        /// </summary>
        public void CopyToCamera(UnityEngine.Camera camera, bool setTransform)
        {
            // GfCamera is a gold mine of camera math.
            pxr.GfCamera c = new pxr.GfCamera(UnityTypeConverter.ToGfMatrix(transform),
                                              projection == ProjectionType.Perspective ? pxr.GfCamera.Projection.Perspective
                                                   : pxr.GfCamera.Projection.Orthographic,
                                              this.horizontalAperture,
                                              this.verticalAperture,
                                              this.horizontalApertureOffset,
                                              this.verticalApertureOffset,
                                              this.focalLength);

            camera.orthographic  = c.GetProjection() == pxr.GfCamera.Projection.Orthographic;
            camera.fieldOfView   = c.GetFieldOfView(pxr.GfCamera.FOVDirection.FOVVertical);
            camera.aspect        = c.GetAspectRatio();
            camera.nearClipPlane = clippingRange.x;
            camera.farClipPlane  = clippingRange.y;

            if (camera.orthographic)
            {
                // Note that USD default scale is cm and aperture is in mm.
                // Also Unity ortho size is the half aperture, so divide USD by 2.
                camera.orthographicSize = (verticalAperture / 10.0f) / 2.0f;
            }

            if (setTransform)
            {
                var tr = camera.transform;
                var xf = transform;
                UnityTypeConverter.SetTransform(xf, tr);
            }
        }
Пример #3
0
        /// <summary>
        /// Copyies the current sample values to the given camera.
        /// </summary>
        public void CopyToCamera(UnityEngine.Camera camera)
        {
            // GfCamera is a gold mine of camera math.
            pxr.GfCamera c = new pxr.GfCamera(UnityTypeConverter.ToGfMatrix(transform));

            camera.orthographic  = c.GetProjection() == pxr.GfCamera.Projection.Orthographic;
            camera.fieldOfView   = c.GetFieldOfView(pxr.GfCamera.FOVDirection.FOVVertical);
            camera.aspect        = c.GetAspectRatio();
            camera.nearClipPlane = c.GetClippingRange().GetMin();
            camera.farClipPlane  = c.GetClippingRange().GetMax();

            var tr = camera.transform;
            var xf = transform;

            UnityTypeConverter.SetTransform(xf, tr);
        }