Add support for voxels in actor previews.
This commit is contained in:
58
OpenRA.Mods.RA/Graphics/VoxelActorPreview.cs
Normal file
58
OpenRA.Mods.RA/Graphics/VoxelActorPreview.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Mods.RA.Graphics
|
||||
{
|
||||
public class VoxelPreview : IActorPreview
|
||||
{
|
||||
readonly VoxelAnimation[] components;
|
||||
readonly RenderVoxelsInfo rvi;
|
||||
readonly WRot lightSource;
|
||||
readonly WRot camera;
|
||||
|
||||
readonly PaletteReference colorPalette;
|
||||
readonly PaletteReference normalsPalette;
|
||||
readonly PaletteReference shadowPalette;
|
||||
|
||||
readonly WVec offset;
|
||||
readonly int zOffset;
|
||||
|
||||
public VoxelPreview(VoxelAnimation[] components, WVec offset, int zOffset, RenderVoxelsInfo rvi, WAngle cameraPitch,
|
||||
PaletteReference colorPalette, PaletteReference normalsPalette, PaletteReference shadowPalette)
|
||||
{
|
||||
this.components = components;
|
||||
this.rvi = rvi;
|
||||
lightSource = new WRot(WAngle.Zero,new WAngle(256) - rvi.LightPitch, rvi.LightYaw);
|
||||
camera = new WRot(WAngle.Zero, cameraPitch - new WAngle(256), new WAngle(256));
|
||||
|
||||
this.colorPalette = colorPalette;
|
||||
this.normalsPalette = normalsPalette;
|
||||
this.shadowPalette = shadowPalette;
|
||||
|
||||
this.offset = offset;
|
||||
this.zOffset = zOffset;
|
||||
}
|
||||
|
||||
public void Tick() { /* not supported */ }
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, WPos pos)
|
||||
{
|
||||
yield return new VoxelRenderable(components, pos + offset, zOffset, camera, rvi.Scale,
|
||||
lightSource, rvi.LightAmbientColor, rvi.LightDiffuseColor,
|
||||
colorPalette, normalsPalette, shadowPalette);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -547,6 +547,7 @@
|
||||
<Compile Include="Scripting\Global\MediaGlobal.cs" />
|
||||
<Compile Include="Graphics\ActorPreview.cs" />
|
||||
<Compile Include="Graphics\SpriteActorPreview.cs" />
|
||||
<Compile Include="Graphics\VoxelActorPreview.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user