diffuse lit mesh sprites
parent
4687d57b28
commit
822b897ffc
2
Kav
2
Kav
|
@ -1 +1 @@
|
||||||
Subproject commit 47242e4f52d11b16ec4bc5b630d5d58869dedd92
|
Subproject commit ca6c91446e7a36c72db4f50ba6d7b6ab91a35605
|
|
@ -0,0 +1,16 @@
|
||||||
|
using Encompass;
|
||||||
|
using Kav;
|
||||||
|
|
||||||
|
namespace KavTest
|
||||||
|
{
|
||||||
|
public struct MeshSpriteComponent : IComponent
|
||||||
|
{
|
||||||
|
public MeshSprite MeshSprite { get; }
|
||||||
|
|
||||||
|
public MeshSpriteComponent(
|
||||||
|
MeshSprite meshSprite
|
||||||
|
) {
|
||||||
|
MeshSprite = meshSprite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,29 +0,0 @@
|
||||||
using Encompass;
|
|
||||||
using KavTest.Components;
|
|
||||||
using KavTest.Messages;
|
|
||||||
using Microsoft.Xna.Framework;
|
|
||||||
|
|
||||||
namespace KavTest.Spawners
|
|
||||||
{
|
|
||||||
public class BillboardSpriteSpawner : Spawner<BillboardSpriteSpawnMessage>
|
|
||||||
{
|
|
||||||
protected override void Spawn(in BillboardSpriteSpawnMessage message)
|
|
||||||
{
|
|
||||||
var entity = CreateEntity();
|
|
||||||
|
|
||||||
var transform = new Transform3D(
|
|
||||||
message.Position,
|
|
||||||
Quaternion.Identity,
|
|
||||||
new Vector3(message.Scale, 1)
|
|
||||||
);
|
|
||||||
|
|
||||||
AddComponent(entity, new Transform3DComponent(transform));
|
|
||||||
AddComponent(entity, new SpriteComponent(
|
|
||||||
message.Texture,
|
|
||||||
message.Origin,
|
|
||||||
message.Rotation,
|
|
||||||
message.BillboardConstraint
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
using Encompass;
|
||||||
|
using KavTest.Components;
|
||||||
|
using KavTest.Messages;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
|
namespace KavTest.Spawners
|
||||||
|
{
|
||||||
|
public class MeshSpriteSpawner : Spawner<MeshSpriteSpawnMessage>
|
||||||
|
{
|
||||||
|
protected override void Spawn(in MeshSpriteSpawnMessage message)
|
||||||
|
{
|
||||||
|
var entity = CreateEntity();
|
||||||
|
|
||||||
|
AddComponent(entity, new Transform3DComponent(message.Transform));
|
||||||
|
AddComponent(entity, new MeshSpriteComponent(message.MeshSprite));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -171,6 +171,12 @@ namespace KavTest
|
||||||
|
|
||||||
var mushroomGuyTexture = Texture2D.FromStream(GraphicsDevice, new FileStream("Content/Sprites/mushroomguy.png", FileMode.Open));
|
var mushroomGuyTexture = Texture2D.FromStream(GraphicsDevice, new FileStream("Content/Sprites/mushroomguy.png", FileMode.Open));
|
||||||
|
|
||||||
|
var mushroomGuyMeshSprite = new Kav.MeshSprite(
|
||||||
|
GraphicsDevice,
|
||||||
|
mushroomGuyTexture,
|
||||||
|
Kav.SpriteBillboardConstraint.None
|
||||||
|
);
|
||||||
|
|
||||||
WorldBuilder.AddEngine(new InputEngine(this));
|
WorldBuilder.AddEngine(new InputEngine(this));
|
||||||
WorldBuilder.AddEngine(new AngularVelocityEngine());
|
WorldBuilder.AddEngine(new AngularVelocityEngine());
|
||||||
WorldBuilder.AddEngine(new MoveAlongCurve3DEngine());
|
WorldBuilder.AddEngine(new MoveAlongCurve3DEngine());
|
||||||
|
@ -180,7 +186,7 @@ namespace KavTest
|
||||||
WorldBuilder.AddEngine(new LightBulbSpawner(lightBulbModel));
|
WorldBuilder.AddEngine(new LightBulbSpawner(lightBulbModel));
|
||||||
WorldBuilder.AddEngine(new StaticModelSpawner());
|
WorldBuilder.AddEngine(new StaticModelSpawner());
|
||||||
WorldBuilder.AddEngine(new DirectionalLightSpawner());
|
WorldBuilder.AddEngine(new DirectionalLightSpawner());
|
||||||
WorldBuilder.AddEngine(new BillboardSpriteSpawner());
|
WorldBuilder.AddEngine(new MeshSpriteSpawner());
|
||||||
WorldBuilder.AddGeneralRenderer(new SceneRenderer(GraphicsDevice), 0);
|
WorldBuilder.AddGeneralRenderer(new SceneRenderer(GraphicsDevice), 0);
|
||||||
|
|
||||||
// WorldBuilder.SendMessage(new RustyBallSpawnMessage(
|
// WorldBuilder.SendMessage(new RustyBallSpawnMessage(
|
||||||
|
@ -244,12 +250,9 @@ namespace KavTest
|
||||||
cubeModel
|
cubeModel
|
||||||
));
|
));
|
||||||
|
|
||||||
WorldBuilder.SendMessage(new BillboardSpriteSpawnMessage(
|
WorldBuilder.SendMessage(new MeshSpriteSpawnMessage(
|
||||||
mushroomGuyTexture,
|
new Transform3D(new Vector3(3, 0, 11), Quaternion.Identity, Vector3.One),
|
||||||
new Vector3(3, -2, 8),
|
mushroomGuyMeshSprite
|
||||||
0f,
|
|
||||||
new Vector2(mushroomGuyTexture.Width, mushroomGuyTexture.Height) * 0.025f,
|
|
||||||
Kav.SpriteBillboardConstraint.Full
|
|
||||||
));
|
));
|
||||||
|
|
||||||
// WorldBuilder.SendMessage(new StaticModelSpawnMessage(
|
// WorldBuilder.SendMessage(new StaticModelSpawnMessage(
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
using Encompass;
|
|
||||||
using Kav;
|
|
||||||
using Microsoft.Xna.Framework;
|
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
|
||||||
|
|
||||||
namespace KavTest.Messages
|
|
||||||
{
|
|
||||||
public struct BillboardSpriteSpawnMessage : IMessage
|
|
||||||
{
|
|
||||||
public Texture2D Texture { get; }
|
|
||||||
public Vector3 Position { get; }
|
|
||||||
public Vector2 Origin { get; }
|
|
||||||
public float Rotation { get; }
|
|
||||||
public Vector2 Scale { get; }
|
|
||||||
public SpriteBillboardConstraint BillboardConstraint { get; }
|
|
||||||
|
|
||||||
public BillboardSpriteSpawnMessage(
|
|
||||||
Texture2D texture,
|
|
||||||
Vector3 position,
|
|
||||||
float rotation,
|
|
||||||
Vector2 scale,
|
|
||||||
SpriteBillboardConstraint billboardConstraint
|
|
||||||
) {
|
|
||||||
Texture = texture;
|
|
||||||
Origin = new Vector2(texture.Width / 2, texture.Height);
|
|
||||||
Position = position;
|
|
||||||
Rotation = rotation;
|
|
||||||
Scale = scale;
|
|
||||||
BillboardConstraint = billboardConstraint;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
using Encompass;
|
||||||
|
using Kav;
|
||||||
|
|
||||||
|
namespace KavTest.Messages
|
||||||
|
{
|
||||||
|
public struct MeshSpriteSpawnMessage : IMessage
|
||||||
|
{
|
||||||
|
public Transform3D Transform { get; }
|
||||||
|
public MeshSprite MeshSprite { get; }
|
||||||
|
|
||||||
|
public MeshSpriteSpawnMessage(
|
||||||
|
Transform3D transform,
|
||||||
|
MeshSprite meshSprite
|
||||||
|
) {
|
||||||
|
Transform = transform;
|
||||||
|
MeshSprite = meshSprite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -78,7 +78,9 @@ namespace KavTest.Renderers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Kav.DirectionalLight DirectionalLight()
|
private Kav.DirectionalLight? DirectionalLight()
|
||||||
|
{
|
||||||
|
if (SomeComponent<DirectionalLightComponent>())
|
||||||
{
|
{
|
||||||
var entity = ReadEntity<DirectionalLightComponent>();
|
var entity = ReadEntity<DirectionalLightComponent>();
|
||||||
var transformComponent = GetComponent<Transform3DComponent>(entity);
|
var transformComponent = GetComponent<Transform3DComponent>(entity);
|
||||||
|
@ -90,25 +92,20 @@ namespace KavTest.Renderers
|
||||||
directionalLightComponent.Intensity
|
directionalLightComponent.Intensity
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
private IEnumerable<Sprite> Sprites()
|
|
||||||
{
|
{
|
||||||
foreach (var entity in ReadEntitiesAsEnumerable<SpriteComponent>())
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<(MeshSprite, Matrix)> MeshSpriteTransforms()
|
||||||
|
{
|
||||||
|
foreach (var entity in ReadEntitiesAsEnumerable<MeshSpriteComponent>())
|
||||||
{
|
{
|
||||||
var transformComponent = GetComponent<Transform3DComponent>(entity);
|
var transformComponent = GetComponent<Transform3DComponent>(entity);
|
||||||
var spriteComponent = GetComponent<SpriteComponent>(entity);
|
var spriteComponent = GetComponent<MeshSpriteComponent>(entity);
|
||||||
|
|
||||||
yield return new Sprite(
|
yield return (spriteComponent.MeshSprite, transformComponent.Transform.TransformMatrix);
|
||||||
spriteComponent.Texture,
|
|
||||||
transformComponent.Transform.Position,
|
|
||||||
spriteComponent.Origin,
|
|
||||||
spriteComponent.Rotation,
|
|
||||||
new Vector2(
|
|
||||||
transformComponent.Transform.Scale.X,
|
|
||||||
transformComponent.Transform.Scale.Y
|
|
||||||
),
|
|
||||||
spriteComponent.BillboardConstraint
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,11 +197,11 @@ namespace KavTest.Renderers
|
||||||
ReadComponent<SkyboxComponent>().Skybox
|
ReadComponent<SkyboxComponent>().Skybox
|
||||||
);
|
);
|
||||||
|
|
||||||
Renderer.BillboardSpriteRender(
|
Renderer.MeshSpriteRender(
|
||||||
BillboardTarget,
|
BillboardTarget,
|
||||||
camera,
|
camera,
|
||||||
ModelTransforms,
|
ModelTransforms,
|
||||||
Sprites(),
|
MeshSpriteTransforms(),
|
||||||
AmbientLight,
|
AmbientLight,
|
||||||
PointLights,
|
PointLights,
|
||||||
DirectionalLight()
|
DirectionalLight()
|
||||||
|
|
Loading…
Reference in New Issue