Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));

            var supported = Device.GetSupportedFeatureLevel();
            Console.WriteLine("device supported {0}", supported);

            if (supported < SharpDX.Direct3D.FeatureLevel.Level_10_0)
            return;

            TSOConfig tso_config;

            string tso_config_file = Path.Combine(Application.StartupPath, @"config.xml");
            if (File.Exists(tso_config_file))
            tso_config = TSOConfig.Load(tso_config_file);
            else
            tso_config = new TSOConfig();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new TSOForm(tso_config, args));

            TSOForm form = new TSOForm(tso_config, args);

            form.Show();
            using (RenderLoop loop = new RenderLoop(form))
            {
            while (loop.NextFrame())
            {
                form.FrameMove();
            }
            }
        }
Exemplo n.º 2
0
        public TSOForm(TSOConfig tso_config, string[] args)
        {
            InitializeComponent();
            this.ClientSize = tso_config.ClientSize;

            for (int i = 0; i < keysEnabled.Length; i++)
            {
                keysEnabled[i] = true;
            }
            this.KeyDown += new KeyEventHandler(form_OnKeyDown);
            this.KeyUp   += new KeyEventHandler(form_OnKeyUp);

            this.DragDrop += new DragEventHandler(form_OnDragDrop);
            this.DragOver += new DragEventHandler(form_OnDragOver);

            this.viewer        = new Viewer();
            viewer.DeviceSize  = tso_config.DeviceSize;
            viewer.ScreenColor = tso_config.ScreenColor;
            viewer.HohoAlpha   = tso_config.HohoAlpha;

            this.fig_form = new FigureForm();

            if (viewer.InitializeApplication(this, true))
            {
                viewer.FigureEvent += delegate(object sender, EventArgs e)
                {
                    Figure fig;
                    if (viewer.TryGetFigure(out fig))
                    {
                        fig_form.SetFigure(fig);
                    }
                    else
                    {
                        fig_form.Clear();
                    }
                };
                viewer.Camera.SetTranslation(0.0f, +10.0f, +44.0f);
                foreach (string arg in args)
                {
                    viewer.LoadAnyFile(arg, true);
                }
                if (viewer.FigureList.Count == 0)
                {
                    viewer.LoadAnyFile(Path.Combine(save_path, "system.tdcgsav.png"), true);
                }

                string script_file = Path.Combine(Application.StartupPath, "Script.cs");
                if (File.Exists(script_file))
                {
                    string assembly_file = Path.GetTempFileName();
                    var    script        = CSScript.Load(script_file, assembly_file, true, null).CreateInstance("TDCG.Script").AlignToInterface <IScript>();
                    script.Hello(viewer);
                }

                this.timer1.Enabled = true;
            }
        }
Exemplo n.º 3
0
        public static TSOConfig Load(string source_file)
        {
            XmlReader     reader     = XmlReader.Create(source_file);
            XmlSerializer serializer = new XmlSerializer(typeof(TSOConfig));
            TSOConfig     config     = serializer.Deserialize(reader) as TSOConfig;

            reader.Close();
            return(config);
        }
Exemplo n.º 4
0
        public TSOForm(Viewer viewer, MainForm owner_form)
        {
            InitializeComponent();

            TSOConfig tso_config = new TSOConfig();

            this.ClientSize = tso_config.ClientSize;
            this.Text       = "TSOView";
            this.AllowDrop  = true;

            for (int i = 0; i < keysEnabled.Length; i++)
            {
                keysEnabled[i] = true;
            }
            this.KeyDown += new KeyEventHandler(form_OnKeyDown);
            this.KeyUp   += new KeyEventHandler(form_OnKeyUp);

            this.DragDrop += new DragEventHandler(form_OnDragDrop);
            this.DragOver += new DragEventHandler(form_OnDragOver);

            this.viewer     = viewer;
            this.fig_form   = new FigureForm();
            this.owner_form = owner_form;

            if (viewer.InitializeApplication(this, true))
            {
                viewer.FigureEvent += delegate(object sender, EventArgs e)
                {
                    Figure fig;
                    if (viewer.TryGetFigure(out fig))
                    {
                        viewer.Camera.SetCenter(fig.Center);
                    }
                };
                viewer.FigureEvent += delegate(object sender, EventArgs e)
                {
                    Figure fig;
                    if (viewer.TryGetFigure(out fig))
                    {
                        fig_form.SetFigure(fig);
                    }
                    else
                    {
                        fig_form.Clear();
                    }
                };

                this.timer1.Enabled = true;

                viewer.Camera.Translation = new Vector3(0.0f, 0.0f, +50.0f);
            }
        }
Exemplo n.º 5
0
        public TSOForm(TSOConfig tso_config, string[] args)
        {
            this.tso_config = tso_config;

            InitializeComponent();
            this.ClientSize = tso_config.ClientSize;

            this.DragDrop += new DragEventHandler(form_OnDragDrop);
            this.DragOver += new DragEventHandler(form_OnDragOver);

            this.UserResized += delegate(Object sender, EventArgs e)
            {
                userResized = true;
            };

            this.viewer        = new Viewer();
            viewer.ScreenColor = tso_config.ScreenColor;

            this.fig_form = new FigureForm();

            if (viewer.InitializeApplication(this, tso_config))
            {
                viewer.figures.FigureEvent += delegate(object sender, EventArgs e)
                {
                    Figure fig;
                    if (viewer.figures.TryGetFigure(out fig))
                    {
                        fig_form.SetFigure(fig);
                    }
                    else
                    {
                        fig_form.Clear();
                    }
                };
                viewer.Camera.SetTranslation(tso_config.Position);
                foreach (string arg in args)
                {
                    viewer.figures.LoadAnyFile(arg, true);
                }
                if (viewer.figures.Count == 0)
                {
                    viewer.figures.LoadAnyFile(Path.Combine(save_path, @"system.tdcgsav.png"), true);
                }
                //this.timer1.Enabled = true;
            }

            directInput = new DirectInput();
            keyboard    = new Keyboard(directInput);
            keyboard.Acquire();

            keyboardState = keyboard.GetCurrentState();
        }
Exemplo n.º 6
0
        public TSOForm(TSOConfig tso_config, string[] args)
        {
            this.tso_config = tso_config;

            InitializeComponent();
            this.ClientSize = tso_config.ClientSize;

            this.DragDrop += new DragEventHandler(form_OnDragDrop);
            this.DragOver += new DragEventHandler(form_OnDragOver);

            this.UserResized += delegate(Object sender, EventArgs e)
            {
            userResized = true;
            };

            this.viewer = new Viewer();
            viewer.ScreenColor = tso_config.ScreenColor;

            this.fig_form = new FigureForm();

            if (viewer.InitializeApplication(this, tso_config))
            {
            viewer.figures.FigureEvent += delegate(object sender, EventArgs e)
            {
                Figure fig;
                if (viewer.figures.TryGetFigure(out fig))
                    fig_form.SetFigure(fig);
                else
                    fig_form.Clear();
            };
            viewer.Camera.SetTranslation(tso_config.Position);
            foreach (string arg in args)
                viewer.figures.LoadAnyFile(arg, true);
            if (viewer.figures.Count == 0)
                viewer.figures.LoadAnyFile(Path.Combine(save_path, @"system.tdcgsav.png"), true);
            //this.timer1.Enabled = true;
            }

            directInput = new DirectInput();
            keyboard = new Keyboard(directInput);
            keyboard.Acquire();

            keyboardState = keyboard.GetCurrentState();
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));

            TSOConfig tso_config;

            string tso_config_file = Path.Combine(Application.StartupPath, @"config.xml");

            if (File.Exists(tso_config_file))
            {
                tso_config = TSOConfig.Load(tso_config_file);
            }
            else
            {
                tso_config = new TSOConfig();
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new TSOForm(tso_config, args));
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));

            var supported = Device.GetSupportedFeatureLevel();

            Console.WriteLine("device supported {0}", supported);

            if (supported < SharpDX.Direct3D.FeatureLevel.Level_10_0)
            {
                return;
            }

            TSOConfig tso_config;

            string tso_config_file = Path.Combine(Application.StartupPath, @"config.xml");

            if (File.Exists(tso_config_file))
            {
                tso_config = TSOConfig.Load(tso_config_file);
            }
            else
            {
                tso_config = new TSOConfig();
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            TSOForm form = new TSOForm(tso_config, args);

            form.Show();
            using (RenderLoop loop = new RenderLoop(form))
            {
                while (loop.NextFrame())
                {
                    form.Render();
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// deviceを作成します。
        /// </summary>
        /// <param name="control">レンダリング先となるcontrol</param>
        /// <param name="tso_config">設定</param>
        /// <returns>deviceの作成に成功したか</returns>
        public bool InitializeApplication(Control control, TSOConfig tso_config)
        {
            this.tso_config = tso_config;
            SetControl(control);

            control.MouseDown += new MouseEventHandler(form_OnMouseDown);
            control.MouseMove += new MouseEventHandler(form_OnMouseMove);

            {
            device = new Device(DriverType.Hardware, DeviceCreationFlags.None);

            var desc = new SharpDX.DXGI.SwapChainDescription()
            {
                BufferCount = 1,
                Usage = SharpDX.DXGI.Usage.RenderTargetOutput,
                OutputHandle = control.Handle,
                IsWindowed = true,
                ModeDescription = new SharpDX.DXGI.ModeDescription(0, 0, new SharpDX.DXGI.Rational(60, 1), SharpDX.DXGI.Format.R8G8B8A8_UNorm),
                SampleDescription = DetectSampleDescription(device, SharpDX.DXGI.Format.D32_Float),
                Flags = SharpDX.DXGI.SwapChainFlags.AllowModeSwitch,
                SwapEffect = SharpDX.DXGI.SwapEffect.Discard
            };
            dxgi_factory = new SharpDX.DXGI.Factory();
            swap_chain = new SharpDX.DXGI.SwapChain(dxgi_factory, device, desc);
            }

            ctx = device.ImmediateContext;

            Stopwatch sw = new Stopwatch();
            sw.Start();

            string effect_file = Path.Combine(Application.StartupPath, @"toonshader.fx.bin");
            if (! File.Exists(effect_file))
            {
            Console.WriteLine("File not found: " + effect_file);
            return false;
            }
            try
            {
            var shader_bytecode = ShaderBytecode.FromFile(effect_file);
            effect = new Effect(device, shader_bytecode);
            }
            catch (SharpDX.CompilationException e)
            {
            Console.WriteLine(e.Message + ": " + effect_file);
            return false;
            }

            sw.Stop();
            Console.WriteLine("toonshader.fx.bin read time: " + sw.Elapsed);

            string techmap_file = Path.Combine(Application.StartupPath, @"techmap.txt");
            if (! File.Exists(techmap_file))
            {
            Console.WriteLine("File not found: " + techmap_file);
            return false;
            }
            techmap.Load(techmap_file);

            World_variable = effect.GetVariableBySemantic("World").AsMatrix();
            WorldView_variable = effect.GetVariableBySemantic("WorldView").AsMatrix();
            WorldViewProjection_variable = effect.GetVariableBySemantic("WorldViewProjection").AsMatrix();
            /* for HUD */
            Projection_variable = effect.GetVariableBySemantic("Projection").AsMatrix();

            LocalBoneMats_variable = effect.GetVariableByName("LocalBoneMats").AsMatrix();
            LightDirForced_variable = effect.GetVariableByName("LightDirForced").AsVector();
            UVSCR_variable = effect.GetVariableByName("UVSCR").AsVector();

            cb_variable = effect.GetConstantBufferByName("cb");

            ShadeTex_texture_variable = effect.GetVariableByName("ShadeTex_texture").AsShaderResource();
            ColorTex_texture_variable = effect.GetVariableByName("ColorTex_texture").AsShaderResource();

            figures.Camera = camera;
            figures.TSOFileOpen += delegate(TSOFile tso)
            {
            tso.Open(device, effect);
            techmap.AssignTechniqueIndices(tso);
            };

            // Define an input layout to be passed to the vertex shader.
            var technique = effect.GetTechniqueByIndex(0);
            il = new InputLayout(device, technique.GetPassByIndex(0).Description.Signature, TSOSubMesh.ie);

            // Setup the immediate context to use the shaders and model we defined.
            ctx.InputAssembler.InputLayout = il;

            camera.Update();

            DefineBlendState();
            DefineDepthStencilState();
            DefineRasterizerState();

            return true;
        }
Exemplo n.º 10
0
        /// <summary>
        /// deviceを作成します。
        /// </summary>
        /// <param name="control">レンダリング先となるcontrol</param>
        /// <param name="tso_config">設定</param>
        /// <returns>deviceの作成に成功したか</returns>
        public bool InitializeApplication(Control control, TSOConfig tso_config)
        {
            this.tso_config = tso_config;
            SetControl(control);

            control.MouseDown += new MouseEventHandler(form_OnMouseDown);
            control.MouseMove += new MouseEventHandler(form_OnMouseMove);

            var desc = new SharpDX.DXGI.SwapChainDescription()
            {
                BufferCount       = 1,
                Usage             = SharpDX.DXGI.Usage.RenderTargetOutput,
                OutputHandle      = control.Handle,
                IsWindowed        = true,
                ModeDescription   = new SharpDX.DXGI.ModeDescription(0, 0, new SharpDX.DXGI.Rational(60, 1), SharpDX.DXGI.Format.B8G8R8A8_UNorm),
                SampleDescription = new SharpDX.DXGI.SampleDescription(4, 0),
                Flags             = SharpDX.DXGI.SwapChainFlags.AllowModeSwitch,
                SwapEffect        = SharpDX.DXGI.SwapEffect.Discard
            };

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out device, out swap_chain);

            //DetectSampleDescription(device, SharpDX.DXGI.Format.D32_Float);

            ctx = device.ImmediateContext;

            Stopwatch sw = new Stopwatch();

            sw.Start();

            string effect_file = Path.Combine(Application.StartupPath, @"toonshader.fx.bin");

            if (!File.Exists(effect_file))
            {
                Console.WriteLine("File not found: " + effect_file);
                return(false);
            }
            try
            {
                var shader_bytecode = ShaderBytecode.FromFile(effect_file);
                effect = new Effect(device, shader_bytecode);
            }
            catch (SharpDX.CompilationException e)
            {
                Console.WriteLine(e.Message + ": " + effect_file);
                return(false);
            }

            sw.Stop();
            Console.WriteLine("toonshader.fx.bin read time: " + sw.Elapsed);

            string techmap_file = Path.Combine(Application.StartupPath, @"techmap.txt");

            if (!File.Exists(techmap_file))
            {
                Console.WriteLine("File not found: " + techmap_file);
                return(false);
            }
            techmap.Load(techmap_file);

            World_variable               = effect.GetVariableBySemantic("World").AsMatrix();
            WorldView_variable           = effect.GetVariableBySemantic("WorldView").AsMatrix();
            WorldViewProjection_variable = effect.GetVariableBySemantic("WorldViewProjection").AsMatrix();
            /* for normal in view */
            View_variable = effect.GetVariableBySemantic("View").AsMatrix();
            /* for HUD */
            Projection_variable = effect.GetVariableBySemantic("Projection").AsMatrix();

            LocalBoneMats_variable  = effect.GetVariableByName("LocalBoneMats").AsMatrix();
            LightDirForced_variable = effect.GetVariableByName("LightDirForced").AsVector();
            UVSCR_variable          = effect.GetVariableByName("UVSCR").AsVector();

            cb_variable = effect.GetConstantBufferByName("cb");

            ShadeTex_texture_variable = effect.GetVariableByName("ShadeTex_texture").AsShaderResource();
            ColorTex_texture_variable = effect.GetVariableByName("ColorTex_texture").AsShaderResource();

            figures.Camera       = camera;
            figures.TSOFileOpen += delegate(TSOFile tso)
            {
                tso.Open(device, effect);
                techmap.AssignTechniqueIndices(tso);
            };

            // Define an input layout to be passed to the vertex shader.
            var technique = effect.GetTechniqueByIndex(0);

            il = new InputLayout(device, technique.GetPassByIndex(0).Description.Signature, TSOSubMesh.ie);

            // Setup the immediate context to use the shaders and model we defined.
            ctx.InputAssembler.InputLayout = il;

            camera.Update();

            DefineBlendState();
            DefineDepthStencilState();
            DefineRasterizerState();

            return(true);
        }
Exemplo n.º 11
0
        public TSOForm(TSOConfig tso_config, string[] args)
        {
            InitializeComponent();
            this.ClientSize = tso_config.ClientSize;
            if (tso_config.PseudoFullScreen)
            {
                this.FormBorderStyle = FormBorderStyle.None;
            }
            if (tso_config.Keying)
            {
                this.TransparencyKey = tso_config.ScreenColor;
            }

            for (int i = 0; i < keysEnabled.Length; i++)
            {
                keysEnabled[i] = true;
            }
            this.KeyDown += new KeyEventHandler(form_OnKeyDown);
            this.KeyUp   += new KeyEventHandler(form_OnKeyUp);

            this.DragDrop += new DragEventHandler(form_OnDragDrop);
            this.DragOver += new DragEventHandler(form_OnDragOver);

            this.viewer        = new Viewer();
            viewer.Windowed    = tso_config.Windowed;
            viewer.DeviceSize  = tso_config.DeviceSize;
            viewer.ScreenColor = tso_config.ScreenColor;
            viewer.Ambient     = tso_config.Ambient;
            viewer.HohoAlpha   = tso_config.HohoAlpha;
            viewer.XRGBDepth   = tso_config.XRGBDepth;
            viewer.SetDepthMapFormat(tso_config.DepthMapFormat);
            viewer.SetNormalMapFormat(tso_config.NormalMapFormat);
            viewer.SetProjectionMode(tso_config.ProjectionMode);
            viewer.SetRenderMode(tso_config.RenderMode);
            viewer.MainGel   = tso_config.MainGel;
            viewer.ScreenDof = tso_config.ScreenDof;

            this.figureForm = new FigureForm();
            this.configForm = new ConfigForm();

            CameraConfig    camera_config    = new CameraConfig();
            DepthMapConfig  depthmap_config  = new DepthMapConfig();
            OcclusionConfig occlusion_config = new OcclusionConfig();
            DiffusionConfig diffusion_config = new DiffusionConfig();

            viewer.CameraConfig    = camera_config;
            viewer.DepthMapConfig  = depthmap_config;
            viewer.OcclusionConfig = occlusion_config;
            viewer.DiffusionConfig = diffusion_config;

            configForm.CameraConfig    = camera_config;
            configForm.DepthMapConfig  = depthmap_config;
            configForm.OcclusionConfig = occlusion_config;
            configForm.DiffusionConfig = diffusion_config;
            configForm.ConfigConnect();

            this.record = new Record(viewer, tso_config.RecordStep);

            if (viewer.InitializeApplication(this, true))
            {
                viewer.ConfigConnect();
                figureForm.SetViewer(viewer);
                viewer.FigureSelectEvent += delegate(object sender, EventArgs e)
                {
                    Figure fig;
                    if (viewer.TryGetFigure(out fig))
                    {
                        figureForm.SetFigure(fig);
                    }
                    else
                    {
                        figureForm.Clear();
                    }
                };
                viewer.Camera.SetTranslation(0.0f, +10.0f, +44.0f);
                foreach (string arg in args)
                {
                    viewer.LoadAnyFile(arg, true);
                }
                if (viewer.FigureList.Count == 0)
                {
                    viewer.LoadAnyFile(Path.Combine(save_path, "system.tdcgsav.png"), true);
                }

                this.timer1.Enabled = true;
            }
        }
Exemplo n.º 12
0
        public TSOForm(TSOConfig tso_config, string[] args)
        {
            InitializeComponent();
            this.ClientSize = tso_config.ClientSize;
            this.AllowDrop  = true;

            for (int i = 0; i < keysEnabled.Length; i++)
            {
                keysEnabled[i] = true;
            }
            this.KeyDown += new KeyEventHandler(form_OnKeyDown);
            this.KeyUp   += new KeyEventHandler(form_OnKeyUp);

            this.DragDrop += new DragEventHandler(form_OnDragDrop);
            this.DragOver += new DragEventHandler(form_OnDragOver);

            this.viewer   = new Viewer(false);
            this.fig_form = new FigureForm();
            this.tbr      = new TransBoneRotation();

            if (viewer.InitializeApplication(this, true))
            {
                viewer.FigureEvent += delegate(object sender, EventArgs e)
                {
                    Figure fig;
                    if (viewer.TryGetFigure(out fig))
                    {
                        viewer.Camera.SetCenter(fig.Center);
                    }
                };
                viewer.FigureEvent += delegate(object sender, EventArgs e)
                {
                    Figure fig;
                    if (viewer.TryGetFigure(out fig))
                    {
                        fig_form.SetFigure(fig);
                    }
                    else
                    {
                        fig_form.Clear();
                    }
                };
                foreach (string arg in args)
                {
                    viewer.LoadAnyFile(arg, true);
                }

                // �����|�[�Y��TMO�𓾂Ă���
                Figure fig_forPose;
                viewer.TryGetFigure(out fig_forPose);
                tbr.SetInitPose(fig_forPose);

                /*string script_file = Path.Combine(Application.StartupPath, "Script.cs");
                 * if (File.Exists(script_file))
                 * {
                 *  var script = CSScript.Load(script_file).CreateInstance("TDCG.Script").AlignToInterface<IScript>();
                 *  script.Hello(viewer);
                 * }*/

                this.timer1.Enabled = true;

                viewer.Camera.Translation = new Vector3(0.0f, 0.0f, +50.0f);
            }
        }