-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Placeholder gizmo for nonmeshed Translokator Instances
- Loading branch information
Showing
7 changed files
with
223 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using Rendering.Graphics; | ||
using System; | ||
using System.Numerics; | ||
using System.Runtime.CompilerServices; | ||
using ResourceTypes.Translokator; | ||
using Utils.Logging; | ||
using Utils.VorticeUtils; | ||
using Vortice.Direct3D; | ||
using Vortice.Direct3D11; | ||
using Vortice.Mathematics; | ||
|
||
namespace Rendering.Core | ||
{ | ||
public class InstanceGizmo | ||
{ | ||
|
||
// Variable for rendering | ||
public RenderModel InstanceModel; | ||
|
||
public InstanceGizmo(RenderModel InModel) | ||
{ | ||
InstanceModel = InModel; | ||
} | ||
|
||
public void InitBuffers(ID3D11Device d3d, ID3D11DeviceContext d3dContext) | ||
{ | ||
InstanceModel.InitBuffers(d3d, d3dContext);//texture should be loaded either differently or rendersingleton should precache it | ||
InstanceModel.AOTexture = LoadTexture(d3d, d3dContext); | ||
} | ||
|
||
public ID3D11ShaderResourceView LoadTexture(ID3D11Device d3d, ID3D11DeviceContext d3dContext) | ||
{ | ||
try | ||
{ | ||
ID3D11Resource ddsResource; | ||
ID3D11ShaderResourceView _temp; | ||
DDSTextureLoader.DDS_ALPHA_MODE mode; | ||
DDSTextureLoader.CreateDDSTextureFromFile(d3d, d3dContext, "Resources/Translokator_Texture.dds", out ddsResource, out _temp, 4096, out mode); | ||
return _temp; | ||
} | ||
catch | ||
{ | ||
Log.WriteLine(string.Format("Failed to load file: {0}", "Resources/Translokator_Texture.dds"), LoggingTypes.FATAL, LogCategoryTypes.IO); | ||
return null; | ||
} | ||
} | ||
|
||
public void UpdateInstanceBuffer(Instance instance, ID3D11Device d3d) | ||
{ | ||
Matrix4x4 newtransform = MatrixUtils.SetMatrix(instance.Quaternion, new Vector3(0.015f,0.015f,0.015f), instance.Position); | ||
|
||
if (!InstanceModel.InstanceTransforms.ContainsKey(instance.RefID)) | ||
{ | ||
InstanceModel.InstanceTransforms.Add(instance.RefID, Matrix4x4.Transpose(newtransform)); | ||
} | ||
else | ||
{ | ||
InstanceModel.InstanceTransforms[instance.RefID] = Matrix4x4.Transpose(newtransform); | ||
} | ||
|
||
InstanceModel.ReloadInstanceBuffer(d3d); | ||
} | ||
|
||
public void UpdateBuffers(ID3D11Device d3d, ID3D11DeviceContext d3dContext) | ||
{ | ||
InstanceModel.UpdateBuffers(d3d, d3dContext); | ||
} | ||
|
||
public void Render(ID3D11Device d3d, ID3D11DeviceContext d3dContext, Camera camera)//render only instances | ||
{ | ||
if (InstanceModel.InstanceTransforms.Count > 0) | ||
{ | ||
VertexBufferView VertexBufferView = new VertexBufferView(InstanceModel.GetVB(), Unsafe.SizeOf<VertexLayouts.NormalLayout.Vertex>(), 0);//polish so getib/vb doesnt have to be used | ||
d3dContext.IASetVertexBuffers(0, VertexBufferView); | ||
d3dContext.IASetIndexBuffer(InstanceModel.GetIB(), Vortice.DXGI.Format.R32_UInt, 0); | ||
d3dContext.IASetPrimitiveTopology(PrimitiveTopology.TriangleList); | ||
d3dContext.PSSetShaderResource(2, InstanceModel.AOTexture); | ||
|
||
InstanceModel.RenderInstances(d3dContext, camera, d3d); | ||
} | ||
} | ||
|
||
public void InstanceTranslokator(Instance instance,ID3D11Device device = null) | ||
{ | ||
Matrix4x4 newtransform = new Matrix4x4(); | ||
|
||
newtransform = MatrixUtils.SetMatrix(instance.Quaternion, new Vector3(0.015f,0.015f,0.015f), instance.Position);//fbx to m2t enlarged the mesh so, beware gltf | ||
|
||
if (!InstanceModel.InstanceTransforms.ContainsKey(instance.RefID)) | ||
{ | ||
InstanceModel.InstanceTransforms.Add(instance.RefID, Matrix4x4.Transpose(newtransform)); | ||
if (device!=null) | ||
{ | ||
InstanceModel.ReloadInstanceBuffer(device); | ||
} | ||
} | ||
} | ||
|
||
public void Select(int InstanceId) | ||
{ | ||
InstanceModel.SelectInstance(InstanceId); | ||
} | ||
|
||
public void Unselect() | ||
{ | ||
InstanceModel.UnselectInstance(); | ||
} | ||
|
||
public void Shutdown() | ||
{ | ||
InstanceModel.Shutdown(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.