Exemplo n.º 1
0
        void UpdateSymmetryPointerTransforms()
        {
            switch (m_CurrentSymmetryMode)
            {
            case SymmetryMode.SinglePlane:
            {
                Plane       plane = m_SymmetryWidgetScript.ReflectionPlane;
                TrTransform xf0   = TrTransform.FromTransform(m_MainPointerData.m_Script.transform);
                TrTransform xf1   = plane.ReflectPoseKeepHandedness(xf0);
                xf1.ToTransform(m_Pointers[1].m_Script.transform);

                // This is a hack.
                // In the event that the user is painting on a plane stencil and that stencil is
                // orthogonal to the symmetry plane, the main pointer and mirrored pointer will
                // have the same depth and their strokes will overlap, causing z-fighting.
                if (WidgetManager.m_Instance.ActiveStencil != null)
                {
                    m_Pointers[1].m_Script.transform.position +=
                        m_Pointers[1].m_Script.transform.forward * m_SymmetryPointerStencilBoost;
                }
                break;
            }

            case SymmetryMode.FourAroundY:
            {
                TrTransform pointer0 = TrTransform.FromTransform(m_MainPointerData.m_Script.transform);
                // aboutY is an operator that rotates worldspace objects N degrees around the widget's Y
                TrTransform aboutY;
                {
                    var   xfWidget = TrTransform.FromTransform(m_SymmetryWidget);
                    float angle    = 360f / m_NumActivePointers;
                    aboutY = TrTransform.TR(Vector3.zero, Quaternion.AngleAxis(angle, Vector3.up));
                    // convert from widget-local coords to world coords
                    aboutY = xfWidget * aboutY * xfWidget.inverse;
                }

                TrTransform cur = TrTransform.identity;
                for (int i = 1; i < m_NumActivePointers; ++i)
                {
                    cur = aboutY * cur;                 // stack another rotation on top
                    var tmp = (cur * pointer0);         // Work around 2018.3.x Mono parse bug
                    tmp.ToTransform(m_Pointers[i].m_Script.transform);
                }
                break;
            }

            case SymmetryMode.DebugMultiple:
            {
                var xf0 = m_Pointers[0].m_Script.transform;
                for (int i = 1; i < m_NumActivePointers; ++i)
                {
                    var xf = m_Pointers[i].m_Script.transform;
                    xf.position = xf0.position + m_SymmetryDebugMultipleOffset * i;
                    xf.rotation = xf0.rotation;
                }
                break;
            }
            }
        }
Exemplo n.º 2
0
        /// Plays back a named transform onto the current transform from a usd path.
        /// The transform can optionally be smoothed using exponential smoothing.
        /// Smoothing will be clamped between 0 - 1.
        public void StartPlayback(string sketchName = "/Sketch", string xformName = "/VideoCamera",
                                  float smoothing   = 0)
        {
            m_xformName   = xformName;
            m_Smoothing   = Mathf.Clamp01(smoothing);
            m_IsRecording = false;

            // Older versions of Tilt Brush exported usda camera paths in decimeters. We now
            // export in meters to match USD geometry export. Older versions also didn't export any sketch
            // data so we check here for the presence of sketch data to decide how to treat the camera
            // path units.
            bool hasSketchRoot = m_Scene.Stage.GetPrimAtPath(new pxr.SdfPath(sketchName));

            m_xformName = hasSketchRoot ? sketchName + xformName : xformName;
            float scale = hasSketchRoot ? App.UNITS_TO_METERS : 1;

            m_UnitsInMeters = hasSketchRoot;

            m_Scene.Time            = null;
            m_UsdCameraInfo         = new UsdCameraSample();
            m_UsdCameraInfo.shutter = new USD.NET.Unity.CameraSample.Shutter();
            m_Scene.Read(m_xformName, m_UsdCameraInfo);

            m_UsdCamera  = new UsdCameraXformSample();
            m_Scene.Time = 0;

            m_Scene.Read(m_xformName, m_UsdCamera);
            var basisMat = AxisConvention.GetFromUnity(AxisConvention.kUsd)
                           * Matrix4x4.Scale(Vector3.one * scale);

            m_UsdCamera.transform = ExportUtils.ChangeBasis(m_UsdCamera.transform, basisMat, basisMat.inverse);

            TrTransform xf_WS = UsdXformToWorldSpaceXform(m_UsdCamera);

            xf_WS.ToTransform(transform);

            m_PlaybackCameras = FindObjectsOfType <Camera>();
        }
Exemplo n.º 3
0
        public void Deserialize()
        {
            m_Scene.Read(m_xformName, m_UsdCamera);

            var basisMat = Matrix4x4.identity;

            if (m_UnitsInMeters)
            {
                basisMat[0, 0] *= App.METERS_TO_UNITS;
                basisMat[1, 1] *= App.METERS_TO_UNITS;
                basisMat[2, 2] *= -1 * App.METERS_TO_UNITS;
            }
            m_UsdCamera.transform = ExportUtils.ChangeBasis(m_UsdCamera.transform, basisMat, basisMat.inverse);

            TrTransform xf_WS  = UsdXformToWorldSpaceXform(m_UsdCamera);
            TrTransform old_WS = TrTransform.FromTransform(transform);
            TrTransform new_WS = TrTransform.Lerp(old_WS, xf_WS, 1 - m_Smoothing);

            new_WS.scale = m_UsdCameraInfo.eyeScale != 0 ? m_UsdCameraInfo.eyeScale : 1;
            new_WS.ToTransform(transform);

            // Pre-M23.3, .usd files won't have fov defined, so this value will be negative.
            if (m_UsdCamera.fov > 0)
            {
                // A bit brute force, but we're running through all cameras in the scene to make
                // sure the preview shows the modified fov.
                for (int i = 0; i < m_PlaybackCameras.Length; ++i)
                {
                    if (m_PlaybackCameras[i].gameObject.activeInHierarchy &&
                        m_PlaybackCameras[i].isActiveAndEnabled)
                    {
                        m_PlaybackCameras[i].fieldOfView = m_UsdCamera.fov;
                    }
                }
            }
        }