Skip to content

Commit

Permalink
Animation viewer (WIP)
Browse files Browse the repository at this point in the history
* Rewrite most of the model viewer, implement animation viewing functionality
    * TODO: port vertex weighting to GLSL shader
* Modify main form to accomodate animation viewer,
    * added a new animation menu dropdown, including functionality to load animations stored externally
    * put the original tree view under a tab named 'Model Editor', added a second tab for just animations
    * added animation slider, play and stop buttons
* Add basic icons to tree view
  • Loading branch information
Chris Weermann (TGE) committed Dec 4, 2018
1 parent c18e474 commit f008ab0
Show file tree
Hide file tree
Showing 61 changed files with 2,049 additions and 788 deletions.
2 changes: 2 additions & 0 deletions GFDLibrary.Playground/GFDLibrary.Playground.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -31,6 +32,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
15 changes: 15 additions & 0 deletions GFDLibrary.Rendering.OpenGL/ConversionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using OpenTK;

namespace GFDLibrary.Rendering.OpenGL
{
public static class ConversionHelper
{
public static unsafe Matrix4 Convert( this System.Numerics.Matrix4x4 value ) => *( Matrix4* )&value;
public static unsafe Vector3 Convert( this System.Numerics.Vector3 value ) => *( Vector3* ) &value;
public static unsafe Vector4 Convert( this System.Numerics.Vector4 value ) => *( Vector4* )&value;
public static unsafe Quaternion Convert( this System.Numerics.Quaternion value ) => *( Quaternion* )&value;

public static unsafe System.Numerics.Quaternion Convert( this Quaternion value ) => *( System.Numerics.Quaternion* )&value;
public static unsafe System.Numerics.Vector3 Convert( this Vector3 value ) => *( System.Numerics.Vector3* )&value;
}
}
84 changes: 84 additions & 0 deletions GFDLibrary.Rendering.OpenGL/GFDLibrary.Rendering.OpenGL.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D3676CBB-FAF8-4D38-BC6D-8F1E539E0B5C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>GFDLibrary.Rendering.OpenGL</RootNamespace>
<AssemblyName>GFDLibrary.Rendering.OpenGL</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>7.3</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="OpenTK">
<HintPath>..\Dependencies\OpenTK\OpenTK.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConversionHelper.cs" />
<Compile Include="GLBuffer.cs" />
<Compile Include="GLCamera.cs" />
<Compile Include="GLMaterial.cs" />
<Compile Include="GLMesh.cs" />
<Compile Include="GLModel.cs" />
<Compile Include="GLNode.cs" />
<Compile Include="GLOrthographicCamera.cs" />
<Compile Include="GLPerspectiveCamera.cs" />
<Compile Include="GLPerspectiveFreeCamera.cs" />
<Compile Include="GLPerspectiveTargetCamera.cs" />
<Compile Include="GLShaderProgram.cs" />
<Compile Include="GLShaderProgramBuilder.cs" />
<Compile Include="GLTexture.cs" />
<Compile Include="GLVertexArray.cs" />
<Compile Include="GLVertexAttributeBuffer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GFDLibrary\GFDLibrary.csproj">
<Project>{a41ac644-a107-4788-8e4f-e10cca64f3b6}</Project>
<Name>GFDLibrary</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
67 changes: 67 additions & 0 deletions GFDLibrary.Rendering.OpenGL/GLBuffer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Runtime.CompilerServices;
using OpenTK.Graphics.OpenGL;

namespace GFDLibrary.Rendering.OpenGL
{
public class GLBuffer<T> : IDisposable where T : struct
{
public int Id { get; }

public int Count { get; }

public int Stride { get; }

public int TotalSize { get; }

public GLBuffer(BufferTarget target, T[] data)
{
// generate buffer id
Id = GL.GenBuffer();

// mark buffer as active
GL.BindBuffer( target, Id );

Count = data.Length;
Stride = Unsafe.SizeOf<T>();
TotalSize = Stride * Count;

// upload data to buffer store
#if GL_DEBUG
try
{
#endif
GL.BufferData( target, TotalSize, data, BufferUsageHint.StreamDraw );
#if GL_DEBUG
}
catch ( Exception )
{
}
#endif
}

#region IDisposable Support
private bool disposedValue = false; // To detect redundant calls

protected virtual void Dispose( bool disposing )
{
if ( !disposedValue )
{
if ( disposing )
{
GL.DeleteBuffer( Id );
}

disposedValue = true;
}
}

// This code added to correctly implement the disposable pattern.
public void Dispose()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
Dispose( true );
}
#endregion
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using OpenTK;

namespace GFDStudio.GUI.Controls.ModelView
namespace GFDLibrary.Rendering.OpenGL
{
public abstract class GLCamera
{
Expand All @@ -19,23 +19,23 @@ public abstract class GLCamera
/// </summary>
public float ZFar { get; set; }

public GLCamera( Vector3 translation, float zNear, float zFar )
protected GLCamera( Vector3 translation, float zNear, float zFar )
{
Translation = translation;
ZNear = zNear;
ZFar = zFar;
}

public abstract Matrix4 CalculateProjectionMatrix();
public abstract Matrix4 Projection { get; }

public abstract Matrix4 CalculateViewMatrix();
public abstract Matrix4 View { get; }

public Matrix4 CalculateViewProjectionMatrix()
{
var projection = CalculateProjectionMatrix();
var view = CalculateViewMatrix();
public Matrix4 ViewProjection => View * Projection;

return view * projection;
public void Bind( GLShaderProgram shaderProgram )
{
shaderProgram.SetUniform( "view", View);
shaderProgram.SetUniform( "projection", Projection);
}
}
}
89 changes: 89 additions & 0 deletions GFDLibrary.Rendering.OpenGL/GLMaterial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using GFDLibrary.Materials;
using OpenTK;
using OpenTK.Graphics.OpenGL;

namespace GFDLibrary.Rendering.OpenGL
{
public interface IGLMaterial : IDisposable
{
void Bind( GLShaderProgram shaderProgram );
}

public delegate GLTexture MaterialTextureCreator( Material material, string textureName );

public class GLMaterial : IGLMaterial
{
public Vector4 Ambient { get; set; }

public Vector4 Diffuse { get; set; }

public Vector4 Specular { get; set; }

public Vector4 Emissive { get; set; }

public GLTexture DiffuseTexture { get; set; }

public bool HasAlphaTransparency { get; set; }

public bool HasDiffuseTexture => DiffuseTexture != null;

public GLMaterial( Material material, MaterialTextureCreator textureCreator )
{
// color parameters
Ambient = material.Ambient.Convert();
Diffuse = material.Diffuse.Convert();
Specular = material.Specular.Convert();
Emissive = material.Emissive.Convert();

// texture
if ( material.DiffuseMap != null )
{
DiffuseTexture = textureCreator( material, material.DiffuseMap.Name );
HasAlphaTransparency = material.DrawOrder != MaterialDrawOrder.Front;
}
}

public GLMaterial()
{
}

public void Bind( GLShaderProgram shaderProgram )
{
shaderProgram.SetUniform( "matHasDiffuse", HasDiffuseTexture );

if ( HasDiffuseTexture )
DiffuseTexture.Bind();

shaderProgram.SetUniform( "matAmbient", Ambient );
shaderProgram.SetUniform( "matDiffuse", Diffuse );
shaderProgram.SetUniform( "matSpecular", Specular );
shaderProgram.SetUniform( "matEmissive", Emissive );
shaderProgram.SetUniform( "matHasAlphaTransparency", HasAlphaTransparency );
}


#region IDisposable Support
private bool mDisposed; // To detect redundant calls

protected virtual void Dispose( bool disposing )
{
if ( !mDisposed )
{
if ( disposing )
{
DiffuseTexture?.Dispose();
}

mDisposed = true;
}
}
// This code added to correctly implement the disposable pattern.
public void Dispose()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
Dispose( true );
}
#endregion
}
}
Loading

0 comments on commit f008ab0

Please sign in to comment.