Пример #1
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            if ((LastMotion == null) || (LastMotion.Finished == true))
            {
                var motion_group = Asset.MotionGroups[""];
                int number       = new Random().Next() % motion_group.Length;
                var motion       = (CubismMotion)motion_group[number];
                LastMotion = Asset.StartMotion(CubismAsset.MotionType.Base, motion, false);
            }

            Asset.Update(elapsed);

            GL.Viewport(0, 0, ClientRectangle.Width, ClientRectangle.Height);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            Matrix4 mvp_matrix = Matrix4.Identity;

            mvp_matrix[0, 0] = 2.0f;
            mvp_matrix[1, 1] = 2.0f * Width / Height;
            RenderingManager.Draw(mvp_matrix);

            SwapBuffers();
        }
Пример #2
0
        private void OnCreated(object sender, OpenGL.GlControlEventArgs e)
        {
            // モデルをリソースから読み込む
            // 第2引数にファイル名からリソースを読み込む関数を与える
            Asset = new CubismAsset(@"hiyori_free_t06.model3.json", (string file_path) =>
            {
                // リソースは拡張子を持たず、他のピリオドもアンダーバーに変換されるのでそれに応じて文字列を加工する
                // 普通、画像ファイルはBitmapとして読み込まれるが、resxファイルを編集してあるのでbyte[]として読み込まれる
                string file_name     = Path.GetFileNameWithoutExtension(file_path);
                string resource_name = file_name.Replace('.', '_');
                byte[] byte_array    = (byte[])Hiyori.ResourceManager.GetObject(resource_name);
                return(new MemoryStream(byte_array));
            });

            // 自動まばたきを設定する
            // 自動まばたきで設定するパラメータはmodel3.json中にパラメータグループ"EyeBlink"で指定されている
            var eye_blink_controller = new CubismEyeBlink(Asset.ParameterGroups["EyeBlink"]);

            Asset.StartMotion(CubismAsset.MotionType.Effect, eye_blink_controller);

            // OpenGL.Netを使ったレンダラーを作成する
            Renderer         = new CubismOpenGlNetRenderer();
            RenderingManager = new CubismRenderingManager(Renderer, Asset);

            Timer = Stopwatch.StartNew();
        }
Пример #3
0
        private void UpdateAsset(CubismAsset asset)
        {
            DisposeRenderer();
            if (m_asset != null)
            {
                m_asset.Dispose();
            }

            m_asset = asset;
            if (asset == null)
            {
                return;
            }

            var eye_blink_controller = new CubismEyeBlink(asset.ParameterGroups["EyeBlink"]);

            asset.StartMotion(MotionType.Effect, eye_blink_controller);
            TryUpdateRenderer();
        }
Пример #4
0
        protected override void OnOpenGlRender(GlInterface gl, int fb)
        {
            if (m_asset == null)
            {
                return;
            }

            if ((m_lastmotion == null) || (m_lastmotion.Finished == true))
            {
                var motion_group = m_asset.MotionGroups[""];
                int number       = new Random().Next() % motion_group.Length;
                var motion       = (CubismMotion)motion_group[number];
                m_lastmotion = m_asset.StartMotion(MotionType.Base, motion, false);
            }

            m_asset.Update(m_time.ElapsedMilliseconds / 1000.0);
            m_time.Restart();
            double controlScaling = VisualRoot.RenderScaling;
            int    w = (int)(Bounds.Width * controlScaling);
            int    h = (int)(Bounds.Height * controlScaling);
            double r = Math.Sqrt(((float)w) / h);

            gl.Viewport(0, 0, w, h);
            gl.Clear(GL_COLOR_BUFFER_BIT);

            Matrix4x4 mvp_matrix = Matrix4x4.Identity;

            if (h >= w)
            {
                mvp_matrix.M11 = 1.5f;
                mvp_matrix.M22 = -1.5f * w / h;
            }
            else
            {
                mvp_matrix.M11 = 1.5f * h / w;
                mvp_matrix.M22 = -1.5f;
            }

            m_rendermgr.Draw(mvp_matrix);

            Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.Background);
        }
Пример #5
0
        protected override void OnLoad(EventArgs e)
        {
            GL.ClearColor(0.0f, 0.5f, 0.5f, 1.0f);

            Asset = new CubismAsset(@"hiyori_free_t06.model3.json", (string file_path) =>
            {
                string file_name     = Path.GetFileNameWithoutExtension(file_path);
                string resource_name = file_name.Replace('.', '_');
                byte[] byte_array    = (byte[])Hiyori.ResourceManager.GetObject(resource_name);
                return(new MemoryStream(byte_array));
            });

            var eye_blink_controller = new CubismEyeBlink(Asset.ParameterGroups["EyeBlink"]);

            Asset.StartMotion(CubismAsset.MotionType.Effect, eye_blink_controller);

            Renderer         = new CubismOpenTKRenderer();
            RenderingManager = new CubismRenderingManager(Renderer, Asset);

            base.OnLoad(e);
        }