예제 #1
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);
            }
        }
예제 #2
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);
        }
예제 #3
0
        public static void CameraTest2()
        {
            CameraSample sample = new CameraSample();

            sample.transform     = UnityEngine.Matrix4x4.identity;
            sample.clippingRange = new UnityEngine.Vector2(.01f, 10);

            // GfCamera is a gold mine of camera math.
            pxr.GfCamera c = new pxr.GfCamera(UnityTypeConverter.ToGfMatrix(UnityEngine.Matrix4x4.identity));

            sample.focalLength        = c.GetFocalLength();
            sample.horizontalAperture = c.GetHorizontalAperture();
            sample.verticalAperture   = c.GetVerticalAperture();

            var scene = USD.NET.Scene.Create();

            scene.Write("/Foo/Bar", sample);
        }
예제 #4
0
        public static void ExportSkelAnimation(ObjectContext objContext, ExportContext exportContext)
        {
            var scene     = exportContext.scene;
            var sample    = (SkelAnimationSample)objContext.sample;
            var go        = objContext.gameObject;
            var boneNames = exportContext.skelSortedMap[go.transform];
            var skelRoot  = go.transform;

            sample.joints = new string[boneNames.Count];

            var worldXf    = new Matrix4x4[boneNames.Count];
            var worldXfInv = new Matrix4x4[boneNames.Count];

            string rootPath = UnityTypeConverter.GetPath(go.transform);

            var basisChange = Matrix4x4.identity;

            basisChange[2, 2] = -1;

            for (int i = 0; i < boneNames.Count; i++)
            {
                var bonePath = boneNames[i];
                if (!exportContext.pathToBone.ContainsKey(bonePath))
                {
                    sample.joints[i] = "";
                    continue;
                }

                var bone = exportContext.pathToBone[bonePath];
                sample.joints[i] = bonePath.Replace(rootPath + "/", "");

                worldXf[i] = bone.localToWorldMatrix;
                if (exportContext.basisTransform == BasisTransformation.SlowAndSafe)
                {
                    worldXf[i] = UnityTypeConverter.ChangeBasis(worldXf[i]);
                }

                worldXfInv[i] = worldXf[i].inverse;
            }

            var rootXf = skelRoot.localToWorldMatrix.inverse;

            if (exportContext.basisTransform == BasisTransformation.SlowAndSafe)
            {
                rootXf = UnityTypeConverter.ChangeBasis(rootXf);
            }

            var skelWorldTransform = UnityTypeConverter.ToGfMatrix(rootXf);

            pxr.VtMatrix4dArray vtJointsLS    = new pxr.VtMatrix4dArray((uint)boneNames.Count);
            pxr.VtMatrix4dArray vtJointsWS    = UnityTypeConverter.ToVtArray(worldXf);
            pxr.VtMatrix4dArray vtJointsWSInv = UnityTypeConverter.ToVtArray(worldXfInv);

            var translations = new pxr.VtVec3fArray();
            var rotations    = new pxr.VtQuatfArray();

            sample.scales = new pxr.VtVec3hArray();

            var topo = new pxr.UsdSkelTopology(UnityTypeConverter.ToVtArray(sample.joints));

            pxr.UsdCs.UsdSkelComputeJointLocalTransforms(topo,
                                                         vtJointsWS,
                                                         vtJointsWSInv,
                                                         vtJointsLS,
                                                         skelWorldTransform);

            pxr.UsdCs.UsdSkelDecomposeTransforms(
                vtJointsLS,
                translations,
                rotations,
                sample.scales);
            sample.translations = UnityTypeConverter.FromVtArray(translations);
            sample.rotations    = UnityTypeConverter.FromVtArray(rotations);

            scene.Write(objContext.path, sample);
        }