Rename VoxelAnimation to ModelAnimation.

This commit is contained in:
Paul Chote
2017-06-09 00:32:48 +01:00
committed by reaperrr
parent e1cd00c1dd
commit 4f42778d26
12 changed files with 40 additions and 37 deletions

View File

@@ -14,18 +14,18 @@ using System.Collections.Generic;
namespace OpenRA.Graphics
{
public struct VoxelAnimation
public struct ModelAnimation
{
public readonly Voxel Voxel;
public readonly IModel Model;
public readonly Func<WVec> OffsetFunc;
public readonly Func<IEnumerable<WRot>> RotationFunc;
public readonly Func<bool> DisableFunc;
public readonly Func<uint> FrameFunc;
public readonly bool ShowShadow;
public VoxelAnimation(Voxel voxel, Func<WVec> offset, Func<IEnumerable<WRot>> rotation, Func<bool> disable, Func<uint> frame, bool showshadow)
public ModelAnimation(IModel model, Func<WVec> offset, Func<IEnumerable<WRot>> rotation, Func<bool> disable, Func<uint> frame, bool showshadow)
{
Voxel = voxel;
Model = model;
OffsetFunc = offset;
RotationFunc = rotation;
DisableFunc = disable;

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Graphics
public VoxelRenderData RenderData;
}
public class Voxel
public class Voxel : IModel
{
Limb[] limbData;
float[] transforms;
@@ -31,6 +31,9 @@ namespace OpenRA.Graphics
public readonly uint Frames;
public readonly uint Limbs;
uint IModel.Frames { get { return Frames; } }
uint IModel.Sections { get { return Limbs; } }
public Voxel(VoxelLoader loader, VxlReader vxl, HvaReader hva)
{
if (vxl.LimbCount != hva.LimbCount)

View File

@@ -79,7 +79,7 @@ namespace OpenRA.Graphics
}
public VoxelRenderProxy RenderAsync(
WorldRenderer wr, IEnumerable<VoxelAnimation> voxels, WRot camera, float scale,
WorldRenderer wr, IEnumerable<ModelAnimation> voxels, WRot camera, float scale,
float[] groundNormal, WRot lightSource, float[] lightAmbientColor, float[] lightDiffuseColor,
PaletteReference color, PaletteReference normals, PaletteReference shadowPalette)
{
@@ -116,7 +116,7 @@ namespace OpenRA.Graphics
worldTransform = Util.MatrixMultiply(scaleTransform, worldTransform);
worldTransform = Util.MatrixMultiply(offsetTransform, worldTransform);
var bounds = v.Voxel.Bounds(v.FrameFunc());
var bounds = v.Model.Bounds(v.FrameFunc());
var worldBounds = Util.MatrixAABBMultiply(worldTransform, bounds);
var screenBounds = Util.MatrixAABBMultiply(cameraTransform, worldBounds);
var shadowBounds = Util.MatrixAABBMultiply(shadowTransform, worldBounds);
@@ -197,10 +197,10 @@ namespace OpenRA.Graphics
var lightTransform = Util.MatrixMultiply(Util.MatrixInverse(rotations), invShadowTransform);
var frame = v.FrameFunc();
for (uint i = 0; i < v.Voxel.Limbs; i++)
for (uint i = 0; i < v.Model.Sections; i++)
{
var rd = v.Voxel.RenderData(i);
var t = v.Voxel.TransformationMatrix(i, frame);
var rd = v.Model.RenderData(i);
var t = v.Model.TransformationMatrix(i, frame);
var it = Util.MatrixInverse(t);
if (it == null)
throw new InvalidOperationException("Failed to invert the transformed matrix of frame {0} during RenderAsync.".F(i));

View File

@@ -199,7 +199,7 @@
<Compile Include="Graphics\VoxelRenderer.cs" />
<Compile Include="Graphics\VoxelLoader.cs" />
<Compile Include="Graphics\VoxelProvider.cs" />
<Compile Include="Graphics\VoxelAnimation.cs" />
<Compile Include="Graphics\ModelAnimation.cs" />
<Compile Include="Traits\Player\FrozenActorLayer.cs" />
<Compile Include="Graphics\Theater.cs" />
<Compile Include="Traits\Player\PlayerColorPalette.cs" />

View File

@@ -33,12 +33,12 @@ namespace OpenRA.Mods.Cnc.Traits.Render
public object Create(ActorInitializer init) { return new WithVoxelUnloadBody(init.Self, this); }
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(
public IEnumerable<ModelAnimation> RenderPreviewVoxels(
ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func<WRot> orientation, int facings, PaletteReference p)
{
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
var voxel = VoxelProvider.GetVoxel(image, IdleSequence);
yield return new VoxelAnimation(voxel, () => WVec.Zero,
yield return new ModelAnimation(voxel, () => WVec.Zero,
() => new[] { body.QuantizeOrientation(orientation(), facings) },
() => false, () => 0, ShowShadow);
}
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
var rv = self.Trait<RenderVoxels>();
var idleVoxel = VoxelProvider.GetVoxel(rv.Image, info.IdleSequence);
rv.Add(new VoxelAnimation(idleVoxel, () => WVec.Zero,
rv.Add(new ModelAnimation(idleVoxel, () => WVec.Zero,
() => new[] { body.QuantizeOrientation(self, self.Orientation) },
() => Docked,
() => 0, info.ShowShadow));
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
size = new int2(s, s);
var unloadVoxel = VoxelProvider.GetVoxel(rv.Image, info.UnloadSequence);
rv.Add(new VoxelAnimation(unloadVoxel, () => WVec.Zero,
rv.Add(new ModelAnimation(unloadVoxel, () => WVec.Zero,
() => new[] { body.QuantizeOrientation(self, self.Orientation) },
() => !Docked,
() => 0, info.ShowShadow));

View File

@@ -34,14 +34,14 @@ namespace OpenRA.Mods.Cnc.Traits.Render
public readonly bool ShowShadow = true;
public object Create(ActorInitializer init) { return new WithVoxelWalkerBody(init.Self, this); }
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(
public IEnumerable<ModelAnimation> RenderPreviewVoxels(
ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func<WRot> orientation, int facings, PaletteReference p)
{
var voxel = VoxelProvider.GetVoxel(image, Sequence);
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
var frame = init.Contains<BodyAnimationFrameInit>() ? init.Get<BodyAnimationFrameInit, uint>() : 0;
yield return new VoxelAnimation(voxel, () => WVec.Zero,
yield return new ModelAnimation(voxel, () => WVec.Zero,
() => new[] { body.QuantizeOrientation(orientation(), facings) },
() => false, () => frame, ShowShadow);
}
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
var voxel = VoxelProvider.GetVoxel(rv.Image, info.Sequence);
frames = voxel.Frames;
rv.Add(new VoxelAnimation(voxel, () => WVec.Zero,
rv.Add(new ModelAnimation(voxel, () => WVec.Zero,
() => new[] { body.QuantizeOrientation(self, self.Orientation) },
() => false, () => frame, info.ShowShadow));

View File

@@ -16,7 +16,7 @@ namespace OpenRA.Mods.Common.Graphics
{
public class VoxelPreview : IActorPreview
{
readonly VoxelAnimation[] components;
readonly ModelAnimation[] components;
readonly float scale;
readonly float[] lightAmbientColor;
readonly float[] lightDiffuseColor;
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Graphics
readonly WVec offset;
readonly int zOffset;
public VoxelPreview(VoxelAnimation[] components, WVec offset, int zOffset, float scale, WAngle lightPitch, WAngle lightYaw,
public VoxelPreview(ModelAnimation[] components, WVec offset, int zOffset, float scale, WAngle lightPitch, WAngle lightYaw,
float[] lightAmbientColor, float[] lightDiffuseColor, WAngle cameraPitch,
PaletteReference colorPalette, PaletteReference normalsPalette, PaletteReference shadowPalette)
{

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Graphics
{
public struct VoxelRenderable : IRenderable
{
readonly IEnumerable<VoxelAnimation> voxels;
readonly IEnumerable<ModelAnimation> voxels;
readonly WPos pos;
readonly int zOffset;
readonly WRot camera;
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Graphics
readonly float scale;
public VoxelRenderable(
IEnumerable<VoxelAnimation> voxels, WPos pos, int zOffset, WRot camera, float scale,
IEnumerable<ModelAnimation> voxels, WPos pos, int zOffset, WRot camera, float scale,
WRot lightSource, float[] lightAmbientColor, float[] lightDiffuseColor,
PaletteReference color, PaletteReference normals, PaletteReference shadow)
{
@@ -158,7 +158,7 @@ namespace OpenRA.Mods.Common.Graphics
foreach (var v in draw)
{
var bounds = v.Voxel.Bounds(v.FrameFunc());
var bounds = v.Model.Bounds(v.FrameFunc());
var worldTransform = v.RotationFunc().Reverse().Aggregate(scaleTransform,
(x, y) => OpenRA.Graphics.Util.MatrixMultiply(x, OpenRA.Graphics.Util.MakeFloatMatrix(y.AsMatrix())));
@@ -216,7 +216,7 @@ namespace OpenRA.Mods.Common.Graphics
foreach (var v in draw)
{
var bounds = v.Voxel.Bounds(v.FrameFunc());
var bounds = v.Model.Bounds(v.FrameFunc());
var worldTransform = v.RotationFunc().Reverse().Aggregate(scaleTransform,
(x, y) => OpenRA.Graphics.Util.MatrixMultiply(x, OpenRA.Graphics.Util.MakeFloatMatrix(y.AsMatrix())));

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Traits.Render
{
public interface IRenderActorPreviewVoxelsInfo : ITraitInfo
{
IEnumerable<VoxelAnimation> RenderPreviewVoxels(
IEnumerable<ModelAnimation> RenderPreviewVoxels(
ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func<WRot> orientation, int facings, PaletteReference p);
}
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public class RenderVoxels : IRender, INotifyOwnerChanged
{
readonly List<VoxelAnimation> components = new List<VoxelAnimation>();
readonly List<ModelAnimation> components = new List<ModelAnimation>();
readonly Actor self;
readonly RenderVoxelsInfo info;
readonly BodyOrientation body;
@@ -109,7 +109,7 @@ namespace OpenRA.Mods.Common.Traits.Render
}
public string Image { get { return info.Image ?? self.Info.Name; } }
public void Add(VoxelAnimation v) { components.Add(v); }
public void Remove(VoxelAnimation v) { components.Remove(v); }
public void Add(ModelAnimation v) { components.Add(v); }
public void Remove(ModelAnimation v) { components.Remove(v); }
}
}

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public override object Create(ActorInitializer init) { return new WithVoxelBarrel(init.Self, this); }
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(
public IEnumerable<ModelAnimation> RenderPreviewVoxels(
ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func<WRot> orientation, int facings, PaletteReference p)
{
if (!EnabledByDefault)
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits.Render
Func<WRot> quantizedBody = () => body.QuantizeOrientation(orientation(), facings);
Func<WVec> barrelOffset = () => body.LocalToWorld((t.Offset + LocalOffset.Rotate(quantizedTurret())).Rotate(quantizedBody()));
yield return new VoxelAnimation(voxel, barrelOffset, () => new[] { turretOrientation(), orientation() },
yield return new ModelAnimation(voxel, barrelOffset, () => new[] { turretOrientation(), orientation() },
() => false, () => 0, ShowShadow);
}
}
@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Traits.Render
buildComplete = !self.Info.HasTraitInfo<BuildingInfo>(); // always render instantly for units
var rv = self.Trait<RenderVoxels>();
rv.Add(new VoxelAnimation(VoxelProvider.GetVoxel(rv.Image, Info.Sequence),
rv.Add(new ModelAnimation(VoxelProvider.GetVoxel(rv.Image, Info.Sequence),
BarrelOffset, BarrelRotation,
() => IsTraitDisabled || !buildComplete, () => 0, info.ShowShadow));
}

View File

@@ -28,12 +28,12 @@ namespace OpenRA.Mods.Common.Traits.Render
public override object Create(ActorInitializer init) { return new WithVoxelBody(init.Self, this); }
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(
public IEnumerable<ModelAnimation> RenderPreviewVoxels(
ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func<WRot> orientation, int facings, PaletteReference p)
{
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
var voxel = VoxelProvider.GetVoxel(image, Sequence);
yield return new VoxelAnimation(voxel, () => WVec.Zero,
yield return new ModelAnimation(voxel, () => WVec.Zero,
() => new[] { body.QuantizeOrientation(orientation(), facings) },
() => false, () => 0, ShowShadow);
}
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits.Render
var rv = self.Trait<RenderVoxels>();
var voxel = VoxelProvider.GetVoxel(rv.Image, info.Sequence);
rv.Add(new VoxelAnimation(voxel, () => WVec.Zero,
rv.Add(new ModelAnimation(voxel, () => WVec.Zero,
() => new[] { body.QuantizeOrientation(self, self.Orientation) },
() => IsTraitDisabled, () => 0, info.ShowShadow));

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public override object Create(ActorInitializer init) { return new WithVoxelTurret(init.Self, this); }
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(
public IEnumerable<ModelAnimation> RenderPreviewVoxels(
ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func<WRot> orientation, int facings, PaletteReference p)
{
if (!EnabledByDefault)
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits.Render
var turretFacing = Turreted.TurretFacingFromInit(init, t.InitialFacing, Turret);
Func<WRot> turretBodyOrientation = () => WRot.FromYaw(WAngle.FromFacing(turretFacing()) - orientation().Yaw);
yield return new VoxelAnimation(voxel, turretOffset,
yield return new ModelAnimation(voxel, turretOffset,
() => new[] { turretBodyOrientation(), body.QuantizeOrientation(orientation(), facings) }, () => false, () => 0, ShowShadow);
}
}
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits.Render
buildComplete = !self.Info.HasTraitInfo<BuildingInfo>(); // always render instantly for units
var rv = self.Trait<RenderVoxels>();
rv.Add(new VoxelAnimation(VoxelProvider.GetVoxel(rv.Image, Info.Sequence),
rv.Add(new ModelAnimation(VoxelProvider.GetVoxel(rv.Image, Info.Sequence),
() => turreted.Position(self), TurretRotation,
() => IsTraitDisabled || !buildComplete, () => 0, info.ShowShadow));
}