Add support for voxels in actor previews.

This commit is contained in:
Paul Chote
2014-07-21 17:36:12 +12:00
parent 3903b9b2b5
commit b5e4e0e074
7 changed files with 142 additions and 6 deletions

View File

@@ -9,13 +9,16 @@
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
using OpenRA.Mods.RA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
public class RenderVoxelsInfo : ITraitInfo, Requires<IBodyOrientationInfo>
public interface IRenderActorPreviewVoxelsInfo { IEnumerable<VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p); }
public class RenderVoxelsInfo : ITraitInfo, IRenderActorPreviewInfo, Requires<IBodyOrientationInfo>
{
[Desc("Defaults to the actor name.")]
public readonly string Image = null;
@@ -34,7 +37,27 @@ namespace OpenRA.Mods.RA.Render
public readonly WAngle LightYaw = WAngle.FromDegrees(240);
public readonly float[] LightAmbientColor = new float[] {0.6f, 0.6f, 0.6f};
public readonly float[] LightDiffuseColor = new float[] {0.4f, 0.4f, 0.4f};
public virtual object Create(ActorInitializer init) { return new RenderVoxels(init.self, this); }
public virtual IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init)
{
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
var sequenceProvider = init.World.Map.SequenceProvider;
var image = Image ?? init.Actor.Name;
var facings = body.QuantizedFacings == -1 ? init.Actor.Traits.Get<IQuantizeBodyOrientationInfo>().QuantizedBodyFacings(sequenceProvider, init.Actor) : body.QuantizedFacings;
var palette = init.WorldRenderer.Palette(Palette ?? (init.Owner != null ? PlayerPalette + init.Owner.InternalName : null));
var facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 0;
var orientation = WRot.FromFacing(facing);
var components = init.Actor.Traits.WithInterface<IRenderActorPreviewVoxelsInfo>()
.SelectMany(rvpi => rvpi.RenderPreviewVoxels(init, this, image, orientation, facings, palette))
.ToArray();
yield return new VoxelPreview(components, WVec.Zero, 0, this, body.CameraPitch, palette,
init.WorldRenderer.Palette(NormalsPalette), init.WorldRenderer.Palette("shadow"));
}
}
public class RenderVoxels : IRender, INotifyOwnerChanged

View File

@@ -11,11 +11,12 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
public class WithVoxelBarrelInfo : ITraitInfo, Requires<RenderVoxelsInfo>
public class WithVoxelBarrelInfo : ITraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>
{
[Desc("Voxel sequence name to use")]
public readonly string Sequence = "barrel";
@@ -25,6 +26,22 @@ namespace OpenRA.Mods.RA.Render
public readonly WVec LocalOffset = WVec.Zero;
public object Create(ActorInitializer init) { return new WithVoxelBarrel(init.self, this); }
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p)
{
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
var armament = init.Actor.Traits.WithInterface<ArmamentInfo>()
.First(a => a.Name == Armament);
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
.First(tt => tt.Turret == armament.Turret);
var voxel = VoxelProvider.GetVoxel(image, Sequence);
var turretOrientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(t.InitialFacing) - orientation.Yaw), facings);
var turretOffset = body.LocalToWorld(t.Offset.Rotate(orientation));
yield return new VoxelAnimation(voxel, () => turretOffset, () => new [] { turretOrientation, orientation },
() => false, () => 0);
}
}
public class WithVoxelBarrel

View File

@@ -9,19 +9,31 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
[Desc("Also returns a default selection size that is calculated automatically from the voxel dimensions.")]
public class WithVoxelBodyInfo : ITraitInfo, IQuantizeBodyOrientationInfo, Requires<RenderVoxelsInfo>
public class WithVoxelBodyInfo : ITraitInfo, IQuantizeBodyOrientationInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>
{
public readonly string Sequence = "idle";
public object Create(ActorInitializer init) { return new WithVoxelBody(init.self, this); }
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p)
{
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
var voxel = VoxelProvider.GetVoxel(image, "idle");
var bodyOrientation = new[] { body.QuantizeOrientation(orientation, facings) };
yield return new VoxelAnimation(voxel, () => WVec.Zero,
() => bodyOrientation,
() => false, () => 0);
}
public int QuantizedBodyFacings(SequenceProvider sequenceProvider, ActorInfo ai) { return 0; }
}

View File

@@ -11,11 +11,12 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
public class WithVoxelTurretInfo : ITraitInfo, Requires<RenderVoxelsInfo>
public class WithVoxelTurretInfo : ITraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>, Requires<TurretedInfo>
{
[Desc("Voxel sequence name to use")]
public readonly string Sequence = "turret";
@@ -24,6 +25,20 @@ namespace OpenRA.Mods.RA.Render
public readonly string Turret = "primary";
public object Create(ActorInitializer init) { return new WithVoxelTurret(init.self, this); }
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p)
{
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
.First(tt => tt.Turret == Turret);
var voxel = VoxelProvider.GetVoxel(image, Sequence);
var turretOffset = body.LocalToWorld(t.Offset.Rotate(orientation));
var turretBodyOrientation = new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(t.InitialFacing) - orientation.Yaw);
var turretOrientation = new[] { turretBodyOrientation, body.QuantizeOrientation(orientation, facings) };
yield return new VoxelAnimation(voxel, () => turretOffset, () => turretOrientation, () => false, () => 0);
}
}
public class WithVoxelTurret