コード例 #1
0
        public void Import(string filename)
        {
            Scene scene = Scene.Open(filename);

            CommandGroup group = new CommandGroup();

            var cameras = scene.ReadAll <CameraControllerSample>();

            foreach (var camera in cameras)
            {
                CameraControllerSample sample = camera.sample;

                GameObject cameraPrefab = ResourceManager.GetPrefab(PrefabID.Camera);
                GameObject instance     = SceneManager.InstantiateUnityPrefab(cameraPrefab);
                GameObject newObject    = SceneManager.AddObject(instance);

                newObject.name = camera.path.GetName();
                sample.CopyToCamera(newObject.GetComponent <CameraController>());
                Maths.DecomposeMatrix(sample.transform, out Vector3 position, out Quaternion rotation, out Vector3 scale);
                newObject.transform.localPosition = position;
                newObject.transform.localRotation = rotation;
                newObject.transform.localScale    = scale;
            }

            foreach (var m in scene.ReadAll <MeshSample>())
            {
                MeshSample sample = m.sample;

                GameObject gobject = new GameObject();
                gobject.name = m.path.GetName();
                Maths.DecomposeMatrix(sample.transform, out Vector3 position, out Quaternion rotation, out Vector3 scale);
                gobject.transform.localPosition = position;
                gobject.transform.localRotation = rotation;
                gobject.transform.localScale    = scale;

                Mesh mesh = new Mesh();
                mesh.SetVertices(sample.points);
                mesh.SetNormals(sample.normals);
                mesh.SetUVs(0, sample.st as Vector2[]);
                mesh.SetTriangles(sample.faceVertexIndices, 0);

                MeshFilter meshFilter = gobject.AddComponent <MeshFilter>();
                meshFilter.sharedMesh = mesh;
                MeshRenderer mr = gobject.AddComponent <MeshRenderer>();
                mr.sharedMaterial = ResourceManager.GetMaterial(MaterialID.ObjectOpaque);
                gobject.AddComponent <MeshCollider>();

                SceneManager.AddObject(gobject);
            }

            group.Submit();

            scene.Close();
        }
コード例 #2
0
ファイル: USDSceneExporter.cs プロジェクト: ubisoft/vrtist
        public static void ExportCamera(ObjectContext objContext, ExportContext exportContext)
        {
            UnityEngine.Profiling.Profiler.BeginSample("USD: Camera Conversion");

            CameraControllerSample sample = (CameraControllerSample)objContext.sample;
            CameraController       camera = objContext.gameObject.GetComponent <CameraController>();
            var  path        = objContext.path;
            var  scene       = exportContext.scene;
            bool fastConvert = exportContext.basisTransform == BasisTransformation.FastWithNegativeScale;

            // If doing a fast conversion, do not let the constructor do the change of basis for us.
            sample.CopyFromCamera(camera, convertTransformToUsd: !fastConvert);

            if (fastConvert)
            {
                // Partial change of basis.
                var basisChange = Matrix4x4.identity;
                // Invert the forward vector.
                basisChange[2, 2] = -1;
                // Full change of basis would be b*t*b-1, but here we're placing only a single inversion
                // at the root of the hierarchy, so all we need to do is get the camera into the same
                // space.
                sample.transform = sample.transform * basisChange;

                // Is this also a root path?
                // If so the partial basis conversion must be completed on the camera itself.
                if (path.LastIndexOf("/") == 0)
                {
                    sample.transform = basisChange * sample.transform;
                }
            }

            UnityEngine.Profiling.Profiler.EndSample();

            UnityEngine.Profiling.Profiler.BeginSample("USD: Camera Write");
            scene.Write(path, sample);
            UnityEngine.Profiling.Profiler.EndSample();
        }