예제 #1
0
        private void AnimationBox_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            //https://social.msdn.microsoft.com/Forums/windows/en-US/5333cdf2-a669-467c-99ae-1530e91da43a/checkedlistbox-allow-only-one-item-to-be-selected?forum=winforms
            if (e.NewValue == CheckState.Checked)
            {
                for (var ix = 0; ix < animationBox.Items.Count; ++ix)
                {
                    if (e.Index != ix)
                    {
                        animationBox.ItemCheck -= AnimationBox_ItemCheck;
                        animationBox.SetItemChecked(ix, false);
                        animationBox.ItemCheck += AnimationBox_ItemCheck;
                    }
                }

                ActiveAnimation = animationBox.Items[e.Index] as ValveResourceFormat.ResourceTypes.Animation.Animation;
            }
            else if (e.CurrentValue == CheckState.Checked && cameraBox.CheckedItems.Count == 1)
            {
                e.NewValue = CheckState.Checked;
            }
        }
예제 #2
0
        private void MeshControl_Load(object sender, EventArgs e)
        {
            meshControl.MakeCurrent();

            Console.WriteLine("OpenGL version: " + GL.GetString(StringName.Version));
            Console.WriteLine("OpenGL vendor: " + GL.GetString(StringName.Vendor));
            Console.WriteLine("GLSL version: " + GL.GetString(StringName.ShadingLanguageVersion));

            CheckOpenGL();
            LoadBoundingBox();

            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);

            GL.ClearColor(Settings.BackgroundColor);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            InitializeInputTick();

            // If no defaul camera was found, make one up
            if (ActiveCamera == null)
            {
                ActiveCamera = Camera.FromBoundingBox(MinBounds, MaxBounds);
            }

            cameraBox.Items.Add(ActiveCamera, true);

            // Set camera viewport size
            ActiveCamera.SetViewportSize(meshControl.Width, meshControl.Width);

            foreach (var cameraInfo in cameras)
            {
                var camera = new Camera(cameraInfo.Item2, cameraInfo.Item1);
                cameraBox.Items.Add(camera);
            }

            ActiveAnimation = Animations.Count > 0 ? Animations[0] : null;
            animationBox.Items.AddRange(Animations.ToArray());

            foreach (var obj in MeshesToRender)
            {
                obj.LoadFromResource(MaterialLoader);
            }

            // Gather render modes
            var renderModes = MeshesToRender
                              .SelectMany(mesh => mesh.DrawCalls.SelectMany(drawCall => drawCall.Shader.RenderModes))
                              .Distinct()
                              .ToArray();

            if (SubjectType == RenderSubject.Model)
            {
                renderModeComboBox.Items.Clear();
                renderModeComboBox.Items.Add("Change render mode...");
                renderModeComboBox.Items.AddRange(renderModes);
                renderModeComboBox.SelectedIndex = 0;
            }

#if DEBUG
            Debug.Setup();
#endif

            // Create animation texture
            AnimationTexture = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, AnimationTexture);
            // Set clamping to edges
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            // Set nearest-neighbor sampling since we don't want to interpolate matrix rows
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Nearest);
            //Unbind texture again
            GL.BindTexture(TextureTarget.Texture2D, 0);

            // TODO: poor hack
            FileExtensions.ClearCache();

            Loaded = true;

            Console.WriteLine("{0} draw calls total", MeshesToRender.Sum(x => x.DrawCalls.Count));
        }