Ejemplo n.º 1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _fontTexture?.Dispose();
         _fontDefault?.Dispose();
         _rasterizerWireframe?.Dispose();
         _vertexBufferVisibility?.Dispose();
         _gizmo?.Dispose();
         _plane?.Dispose();
         _wadRenderer?.Dispose();
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 2
0
 public void Dispose()
 {
     _rasterizerWireframe?.Dispose();
     _rotationHelperGeometry?.Dispose();
     _cylinder?.Dispose();
     _cube?.Dispose();
     _cone?.Dispose();
     _torus?.Dispose();
 }
Ejemplo n.º 3
0
 public void Dispose()
 {
     if (_vertexBuffer != null)
     {
         _vertexBuffer.Dispose();
     }
     if (_indexBuffer != null)
     {
         _indexBuffer.Dispose();
     }
 }
Ejemplo n.º 4
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _fontTexture?.Dispose();
         _fontDefault?.Dispose();
         _gizmo?.Dispose();
         _plane?.Dispose();
         _model?.Dispose();
         _skinModel?.Dispose();
         _wadRenderer?.Dispose();
         _vertexBufferVisibility?.Dispose();
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 5
0
        protected override void OnDraw()
        {
            // To make sure things are in a defined state for legacy rendering...
            ((TombLib.Rendering.DirectX11.Dx11RenderingSwapChain)SwapChain).BindForce();
            ((TombLib.Rendering.DirectX11.Dx11RenderingDevice)Device).ResetState();

            _device.SetDepthStencilState(_device.DepthStencilStates.Default);
            _device.SetRasterizerState(_device.RasterizerStates.CullBack);
            _device.SetBlendState(_device.BlendStates.Opaque);

            Matrix4x4 viewProjection = Camera.GetViewProjectionMatrix(ClientSize.Width, ClientSize.Height);

            /*if (Level != null && Room != null)
             * {
             *  Effect roomsEffect = _deviceManager.Effects["Room"];
             *
             *  roomsEffect.Parameters["TextureEnabled"].SetValue(true);
             *  roomsEffect.Parameters["DrawSectorOutlinesAndUseEditorUV"].SetValue(false);
             *  roomsEffect.Parameters["Highlight"].SetValue(false);
             *  roomsEffect.Parameters["Dim"].SetValue(false);
             *  roomsEffect.Parameters["Color"].SetValue(new Vector4(1.0f, 1.0f, 1.0f, 1.0f));
             *  roomsEffect.Parameters["Texture"].SetResource(_textureAtlas);
             *  roomsEffect.Parameters["TextureSampler"].SetResource(_device.SamplerStates.AnisotropicWrap);
             *  roomsEffect.Parameters["UseVertexColors"].SetValue(true);
             *  roomsEffect.Parameters["TextureAtlasRemappingSize"].SetValue(_textureAtlasRemappingSize);
             *  roomsEffect.Parameters["TextureCoordinateFactor"].SetValue(_textureAtlas == null ? new Vector2(0) : new Vector2(1.0f / _textureAtlas.Width, 1.0f / _textureAtlas.Height));
             *
             *  _device.SetVertexBuffer(0, Room.VertexBuffer);
             *  _device.SetVertexInputLayout(VertexInputLayout.FromBuffer(0, Room.VertexBuffer));
             *
             *  var world = Matrix4x4.CreateTranslation(new Vector3(-RoomPosition.X, 0, -RoomPosition.Z));
             *
             *  roomsEffect.Parameters["ModelViewProjection"].SetValue((world * viewProjection).ToSharpDX());
             *
             *  roomsEffect.Techniques[0].Passes[0].Apply();
             *  _device.Draw(PrimitiveType.TriangleList, Room.VertexBuffer.ElementCount);
             *
             * }*/

            Effect solidEffect = _deviceManager.___LegacyEffects["Solid"];

            if (_model != null)
            {
                var skin   = (_skinModel != null ? _skinModel : _model);
                var effect = _deviceManager.___LegacyEffects["Model"];

                effect.Parameters["Texture"].SetResource(_wadRenderer.Texture);
                effect.Parameters["TextureSampler"].SetResource(_device.SamplerStates.Default);

                // Build animation transforms
                var matrices = new List <Matrix4x4>();
                if (_editor.ValidAnimationAndFrames)
                {
                    for (var b = 0; b < _model.Meshes.Count; b++)
                    {
                        matrices.Add(_model.AnimationTransforms[b]);
                    }
                }
                else
                {
                    foreach (var bone in _model.Bones)
                    {
                        matrices.Add(bone.GlobalTransform);
                    }
                }

                for (int i = 0; i < skin.Meshes.Count; i++)
                {
                    var mesh = skin.Meshes[i];
                    if (mesh.Vertices.Count == 0)
                    {
                        continue;
                    }

                    _device.SetVertexBuffer(0, mesh.VertexBuffer);
                    _device.SetIndexBuffer(mesh.IndexBuffer, true);
                    _device.SetVertexInputLayout(VertexInputLayout.FromBuffer(0, mesh.VertexBuffer));

                    if (SelectedMesh == _model.Meshes[i] && _editor.ValidAnimationAndFrames)
                    {
                        effect.Parameters["Color"].SetValue(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
                    }
                    else
                    {
                        effect.Parameters["Color"].SetValue(Vector4.One);
                    }

                    effect.Parameters["ModelViewProjection"].SetValue((matrices[i] * viewProjection).ToSharpDX());

                    effect.Techniques[0].Passes[0].Apply();

                    foreach (var submesh in mesh.Submeshes)
                    {
                        _device.Draw(PrimitiveType.TriangleList, submesh.Value.NumIndices, submesh.Value.BaseIndex);
                    }

                    //foreach (var submesh in mesh.Submeshes)
                    //   _device.DrawIndexed(PrimitiveType.TriangleList, submesh.Value.NumIndices, submesh.Value.MeshBaseIndex);
                }

                if (_editor.ValidAnimationAndFrames)
                {
                    _device.SetRasterizerState(_rasterizerWireframe);

                    // Draw selection box
                    if (SelectedMesh != null)
                    {
                        if (_vertexBufferVisibility != null)
                        {
                            _vertexBufferVisibility.Dispose();
                        }
                        int meshIndex = _model.Meshes.IndexOf(SelectedMesh);
                        _vertexBufferVisibility = GetVertexBufferFromBoundingBox(Skin.Meshes[meshIndex].BoundingBox);

                        _device.SetVertexBuffer(_vertexBufferVisibility);
                        _device.SetVertexInputLayout(VertexInputLayout.FromBuffer(0, _vertexBufferVisibility));
                        _device.SetIndexBuffer(null, false);

                        solidEffect.Parameters["ModelViewProjection"].SetValue((_model.AnimationTransforms[meshIndex] * viewProjection).ToSharpDX());
                        solidEffect.Parameters["Color"].SetValue(new Vector4(0.0f, 1.0f, 0.0f, 1.0f));
                        solidEffect.CurrentTechnique.Passes[0].Apply();

                        _device.Draw(PrimitiveType.LineList, _vertexBufferVisibility.ElementCount);
                    }

                    // Draw collision box
                    if (Configuration.AnimationEditor_ShowCollisionBox)
                    {
                        if (_vertexBufferVisibility != null)
                        {
                            _vertexBufferVisibility.Dispose();
                        }
                        _vertexBufferVisibility = GetVertexBufferFromBoundingBox(_editor.CurrentKeyFrame.BoundingBox);

                        _device.SetVertexBuffer(_vertexBufferVisibility);
                        _device.SetVertexInputLayout(VertexInputLayout.FromBuffer(0, _vertexBufferVisibility));
                        _device.SetIndexBuffer(null, false);

                        solidEffect.Parameters["ModelViewProjection"].SetValue((viewProjection).ToSharpDX());
                        solidEffect.Parameters["Color"].SetValue(new Vector4(0.0f, 0.0f, 1.0f, 1.0f));
                        solidEffect.CurrentTechnique.Passes[0].Apply();

                        _device.Draw(PrimitiveType.LineList, _vertexBufferVisibility.ElementCount);
                    }
                }
            }

            if (Configuration.AnimationEditor_ShowGrid)
            {
                // Draw the grid
                _device.SetVertexBuffer(0, _plane.VertexBuffer);
                _device.SetVertexInputLayout(VertexInputLayout.FromBuffer(0, _plane.VertexBuffer));
                _device.SetIndexBuffer(_plane.IndexBuffer, true);
                _device.SetRasterizerState(_rasterizerWireframe);

                var shift = Matrix4x4.CreateTranslation(new Vector3(-GridPosition.X, GridPosition.Y, -GridPosition.Z));
                solidEffect.Parameters["ModelViewProjection"].SetValue((shift * viewProjection).ToSharpDX());
                solidEffect.Parameters["Color"].SetValue(Vector4.One);
                solidEffect.Techniques[0].Passes[0].Apply();

                _device.Draw(PrimitiveType.LineList, _plane.VertexBuffer.ElementCount);
            }

            if (Configuration.AnimationEditor_ShowGizmo &&
                SelectedMesh != null && _editor.ValidAnimationAndFrames)
            {
                // Draw the gizmo
                SwapChain.ClearDepth();
                _gizmo.Draw(viewProjection);
            }

            if (_editor.CurrentAnim != null &&
                Configuration.RenderingItem_ShowDebugInfo)
            {
                ((TombLib.Rendering.DirectX11.Dx11RenderingDevice)Device).ResetState(); // To make sure SharpDx.Toolkit didn't change settings.
                string debugMessage = "Frame: " + (_editor.CurrentFrameIndex + 1) + "/" + _editor.CurrentAnim.DirectXAnimation.KeyFrames.Count;
                if (SelectedMesh != null)
                {
                    debugMessage += "\nMesh: " + SelectedMesh.Name;
                    debugMessage += "\nBone: " + _model.Bones[_model.Meshes.IndexOf(SelectedMesh)].Name;
                    debugMessage += "\nRotation: " + _editor.CurrentKeyFrame.Rotations[Model.Meshes.IndexOf(SelectedMesh)];
                }
                SwapChain.RenderText(new Text
                {
                    Font      = _fontDefault,
                    PixelPos  = new Vector2(10, 25),
                    Alignment = new Vector2(0, 0),
                    String    = debugMessage
                });
            }
        }
Ejemplo n.º 6
0
 // Dispose D3D related resources
 public void Dispose()
 {
     m_vertexBuffer.Dispose();
     m_indexBuffer.Dispose();
 }