Example #1
0
        public void OnFrame()
        {
            if (UIImGui.requireOpenFolder.SetFalse())
            {
                string path = OpenResourceFolder();
                if (!string.IsNullOrEmpty(path))
                {
                    DirectoryInfo folder = new DirectoryInfo(path);
                    UIImGui.viewRequest = folder;
                    caches.AddFolder(folder);
                }
                gameDriverContext.RequireRender(false);
            }
            if (UIImGui.requestSelectRenderPipelines.SetFalse())
            {
                string path = OpenResourceFolder();
                if (!string.IsNullOrEmpty(path))
                {
                    DirectoryInfo folder = new DirectoryInfo(path);
                    UIImGui.renderPipelinesRequest = folder;
                    caches.AddFolder(folder);
                }
                gameDriverContext.RequireRender(false);
            }
            if (UIImGui.viewRequest != null)
            {
                var view = UIImGui.viewRequest;
                UIImGui.viewRequest   = null;
                UIImGui.currentFolder = view;
                SetViewFolder(view.GetFileSystemInfos());
                gameDriverContext.RequireRender(false);
            }
            if (UIImGui.openRequest != null)
            {
                var file = UIImGui.openRequest;
                UIImGui.openRequest = null;

                string ext = file.Extension.ToLower();
                switch (ext)
                {
                case ".pmx":
                case ".gltf":
                    LoadEntityIntoScene(file);
                    break;

                case ".vmd":
                    BinaryReader reader    = new BinaryReader(file.OpenRead());
                    VMDFormat    motionSet = VMDFormat.Load(reader);
                    if (motionSet.CameraKeyFrames.Count != 0)
                    {
                        var camera = windowSystem.currentChannel.camera;
                        camera.cameraMotion.cameraKeyFrames = motionSet.CameraKeyFrames;
                        for (int i = 0; i < camera.cameraMotion.cameraKeyFrames.Count; i++)
                        {
                            CameraKeyFrame frame = camera.cameraMotion.cameraKeyFrames[i];
                            frame.distance *= 0.1f;
                            frame.position *= 0.1f;
                            camera.cameraMotion.cameraKeyFrames[i] = frame;
                        }
                        camera.CameraMotionOn = true;
                    }
                    else
                    {
                        foreach (var gameObject in this.scene.SelectedGameObjects)
                        {
                            var animationState = gameObject.GetComponent <Components.AnimationStateComponent>();
                            if (animationState != null)
                            {
                                animationState.motionPath = file.FullName;
                            }
                        }

                        gameDriverContext.RequireResetPhysics = true;
                    }
                    break;

                case ".coocoo3dscene":
                    var scene = ReadJsonStream <Coocoo3DScene>(file.OpenRead());
                    scene.ToScene(this.scene, caches);
                    gameDriverContext.RequireResetPhysics = true;
                    break;
                }

                gameDriverContext.RequireRender(true);
            }
            if (UIImGui.requestRecord.SetFalse())
            {
                gameDriverContext.NeedRender = 0;
                string path = OpenResourceFolder();
                if (!string.IsNullOrEmpty(path))
                {
                    DirectoryInfo folder = new DirectoryInfo(path);
                    if (!folder.Exists)
                    {
                        return;
                    }
                    gameDriver.ToRecordMode(folder.FullName);
                }
            }
            if (UIImGui.requestSave.SetFalse())
            {
                FileOpenDialog fileDialog = new FileOpenDialog()
                {
                    file       = new string(new char[512]),
                    fileTitle  = new string(new char[512]),
                    initialDir = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer),
                    filter     = ".coocoo3DScene\0*.coocoo3DScene\0\0",
                    defExt     = "coocoo3DScene",
                    flags      = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008,
                    structSize = Marshal.SizeOf(typeof(FileOpenDialog))
                };
                fileDialog.maxFile      = fileDialog.file.Length;
                fileDialog.maxFileTitle = fileDialog.fileTitle.Length;
                if (GetSaveFileName(fileDialog))
                {
                    var scene = Coocoo3DScene.FromScene(this.scene);

                    SaveJsonStream(new FileInfo(fileDialog.file).Create(), scene);
                }
            }
        }
Example #2
0
        public static Coocoo3DScene FromScene(Scene saveScene)
        {
            Coocoo3DScene scene = new Coocoo3DScene();

            scene.objects = new List <CooSceneObject>();

            foreach (var obj in saveScene.gameObjects)
            {
                var renderer       = obj.GetComponent <MMDRendererComponent>();
                var animationState = obj.GetComponent <AnimationStateComponent>();
                if (renderer != null)
                {
                    CooSceneObject sceneObject = new CooSceneObject(obj);
                    sceneObject.type       = "mmdModel";
                    sceneObject.path       = renderer.meshPath;
                    sceneObject.properties = new Dictionary <string, string>();
                    sceneObject.properties.Add("motion", animationState.motionPath);
                    sceneObject.materials = new Dictionary <string, _cooMaterial>();
                    sceneObject.skinning  = renderer.skinning;
                    sceneObject.enableIK  = renderer.enableIK;
                    foreach (var material in renderer.Materials)
                    {
                        sceneObject.materials[material.Name] = Mat2Mat(material);
                    }
                    scene.objects.Add(sceneObject);
                }
                var meshRenderer = obj.GetComponent <MeshRendererComponent>();
                if (meshRenderer != null)
                {
                    CooSceneObject sceneObject = new CooSceneObject(obj);
                    sceneObject.type      = "model";
                    sceneObject.path      = meshRenderer.meshPath;
                    sceneObject.materials = new Dictionary <string, _cooMaterial>();
                    foreach (var material in meshRenderer.Materials)
                    {
                        sceneObject.materials[material.Name] = Mat2Mat(material);
                    }
                    scene.objects.Add(sceneObject);
                }
                var visual = obj.GetComponent <VisualComponent>();
                if (visual != null)
                {
                    CooSceneObject decalObject = new CooSceneObject(obj);
                    if (visual.UIShowType == Caprice.Display.UIShowType.Decal)
                    {
                        decalObject.type = "decal";
                    }
                    if (visual.UIShowType == Caprice.Display.UIShowType.Light)
                    {
                        decalObject.type = "lighting";
                    }
                    if (visual.UIShowType == Caprice.Display.UIShowType.Particle)
                    {
                        decalObject.type = "particle";
                    }
                    decalObject.visual = new CooSceneObjectVisual(Mat2Mat(visual.material));
                    scene.objects.Add(decalObject);
                }
            }

            return(scene);
        }