Пример #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
        public void CreateLight(string lightType)
        {
            GameObject light = null;

            switch (lightType)
            {
            case "Sun":
                light = ResourceManager.GetPrefab(PrefabID.SunLight);
                break;

            case "Spot":
                light = ResourceManager.GetPrefab(PrefabID.SpotLight);
                break;

            case "Point":
                light = ResourceManager.GetPrefab(PrefabID.PointLight);
                break;
            }

            if (light)
            {
                Matrix4x4 matrix = parentContainer.worldToLocalMatrix * mouthpiece.localToWorldMatrix * Matrix4x4.Scale(new Vector3(10f, 10f, 10f));

                GameObject instance = SceneManager.InstantiateUnityPrefab(light);
                Vector3    position = matrix.GetColumn(3);
                Quaternion rotation = Quaternion.AngleAxis(180, Vector3.forward) * Quaternion.LookRotation(matrix.GetColumn(2), matrix.GetColumn(1));
                Vector3    scale    = new Vector3(matrix.GetColumn(0).magnitude, matrix.GetColumn(1).magnitude, matrix.GetColumn(2).magnitude);

                CommandGroup undoGroup = new CommandGroup("Instantiate Light");
                try
                {
                    ClearSelection();
                    CommandAddGameObject command = new CommandAddGameObject(instance);
                    command.Submit();
                    instance = command.newObject;
                    AddToSelection(instance);
                    SceneManager.SetObjectTransform(instance, position, rotation, scale);
                    Selection.HoveredObject = instance;
                }
                finally
                {
                    undoGroup.Submit();
                }
            }
        }
Пример #3
0
        protected override void DoUpdateGui()
        {
            VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.gripButton, () =>
            {
                if (UIObject)
                {
                    Matrix4x4 matrix        = cameraContainer.worldToLocalMatrix * mouthpiece.localToWorldMatrix * Matrix4x4.Scale(new Vector3(5f, 5f, 5f));
                    GameObject cameraPrefab = ResourceManager.GetPrefab(PrefabID.Camera);

                    GameObject instance = SceneManager.InstantiateUnityPrefab(cameraPrefab);
                    Vector3 position    = matrix.GetColumn(3);
                    Quaternion rotation = Quaternion.AngleAxis(180, Vector3.forward) * Quaternion.LookRotation(matrix.GetColumn(2), matrix.GetColumn(1));
                    Vector3 scale       = new Vector3(matrix.GetColumn(0).magnitude, matrix.GetColumn(1).magnitude, matrix.GetColumn(2).magnitude);

                    CommandGroup undoGroup = new CommandGroup("Instantiate Camera");
                    try
                    {
                        ClearSelection();
                        CommandAddGameObject command = new CommandAddGameObject(instance);
                        command.Submit();
                        GameObject newCamera = command.newObject;
                        AddToSelection(newCamera);
                        SceneManager.SetObjectTransform(instance, position, rotation, scale);
                        Selection.HoveredObject = newCamera;
                    }
                    finally
                    {
                        undoGroup.Submit();
                        UIObject = null;
                    }
                }
                OnStartGrip();
            },
                                () =>
            {
                OnEndGrip();
            });

            // called to update focal slider value
            UpdateUI();
        }