diff --git a/OpenRA.Game/Graphics/VoxelAnimation.cs b/OpenRA.Game/Graphics/ModelAnimation.cs similarity index 79% rename from OpenRA.Game/Graphics/VoxelAnimation.cs rename to OpenRA.Game/Graphics/ModelAnimation.cs index ff510bb264..1fb15e7a7e 100644 --- a/OpenRA.Game/Graphics/VoxelAnimation.cs +++ b/OpenRA.Game/Graphics/ModelAnimation.cs @@ -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 OffsetFunc; public readonly Func> RotationFunc; public readonly Func DisableFunc; public readonly Func FrameFunc; public readonly bool ShowShadow; - public VoxelAnimation(Voxel voxel, Func offset, Func> rotation, Func disable, Func frame, bool showshadow) + public ModelAnimation(IModel model, Func offset, Func> rotation, Func disable, Func frame, bool showshadow) { - Voxel = voxel; + Model = model; OffsetFunc = offset; RotationFunc = rotation; DisableFunc = disable; diff --git a/OpenRA.Game/Graphics/Voxel.cs b/OpenRA.Game/Graphics/Voxel.cs index bb5d28fb9c..81c5cdd304 100644 --- a/OpenRA.Game/Graphics/Voxel.cs +++ b/OpenRA.Game/Graphics/Voxel.cs @@ -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) diff --git a/OpenRA.Game/Graphics/VoxelRenderer.cs b/OpenRA.Game/Graphics/VoxelRenderer.cs index 215fcd794c..a6018675c3 100644 --- a/OpenRA.Game/Graphics/VoxelRenderer.cs +++ b/OpenRA.Game/Graphics/VoxelRenderer.cs @@ -79,7 +79,7 @@ namespace OpenRA.Graphics } public VoxelRenderProxy RenderAsync( - WorldRenderer wr, IEnumerable voxels, WRot camera, float scale, + WorldRenderer wr, IEnumerable 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)); diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index ccba686c73..2a1ee4f3f0 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -199,7 +199,7 @@ - + diff --git a/OpenRA.Mods.Cnc/Traits/Render/WithVoxelUnloadBody.cs b/OpenRA.Mods.Cnc/Traits/Render/WithVoxelUnloadBody.cs index 6c81d55017..712fe15ed1 100644 --- a/OpenRA.Mods.Cnc/Traits/Render/WithVoxelUnloadBody.cs +++ b/OpenRA.Mods.Cnc/Traits/Render/WithVoxelUnloadBody.cs @@ -33,12 +33,12 @@ namespace OpenRA.Mods.Cnc.Traits.Render public object Create(ActorInitializer init) { return new WithVoxelUnloadBody(init.Self, this); } - public IEnumerable RenderPreviewVoxels( + public IEnumerable RenderPreviewVoxels( ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func orientation, int facings, PaletteReference p) { var body = init.Actor.TraitInfo(); 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(); 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)); diff --git a/OpenRA.Mods.Cnc/Traits/Render/WithVoxelWalkerBody.cs b/OpenRA.Mods.Cnc/Traits/Render/WithVoxelWalkerBody.cs index 2ba41825b7..2d50b243a1 100644 --- a/OpenRA.Mods.Cnc/Traits/Render/WithVoxelWalkerBody.cs +++ b/OpenRA.Mods.Cnc/Traits/Render/WithVoxelWalkerBody.cs @@ -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 RenderPreviewVoxels( + public IEnumerable RenderPreviewVoxels( ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func orientation, int facings, PaletteReference p) { var voxel = VoxelProvider.GetVoxel(image, Sequence); var body = init.Actor.TraitInfo(); var frame = init.Contains() ? init.Get() : 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)); diff --git a/OpenRA.Mods.Common/Graphics/VoxelActorPreview.cs b/OpenRA.Mods.Common/Graphics/VoxelActorPreview.cs index dc6d52efa8..6c865d83cb 100644 --- a/OpenRA.Mods.Common/Graphics/VoxelActorPreview.cs +++ b/OpenRA.Mods.Common/Graphics/VoxelActorPreview.cs @@ -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) { diff --git a/OpenRA.Mods.Common/Graphics/VoxelRenderable.cs b/OpenRA.Mods.Common/Graphics/VoxelRenderable.cs index ada39287a8..e7c601526c 100644 --- a/OpenRA.Mods.Common/Graphics/VoxelRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/VoxelRenderable.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Graphics { public struct VoxelRenderable : IRenderable { - readonly IEnumerable voxels; + readonly IEnumerable 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 voxels, WPos pos, int zOffset, WRot camera, float scale, + IEnumerable 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()))); diff --git a/OpenRA.Mods.Common/Traits/Render/RenderVoxels.cs b/OpenRA.Mods.Common/Traits/Render/RenderVoxels.cs index 94a3b94e67..c496896538 100644 --- a/OpenRA.Mods.Common/Traits/Render/RenderVoxels.cs +++ b/OpenRA.Mods.Common/Traits/Render/RenderVoxels.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Traits.Render { public interface IRenderActorPreviewVoxelsInfo : ITraitInfo { - IEnumerable RenderPreviewVoxels( + IEnumerable RenderPreviewVoxels( ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func orientation, int facings, PaletteReference p); } @@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits.Render public class RenderVoxels : IRender, INotifyOwnerChanged { - readonly List components = new List(); + readonly List components = new List(); 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); } } } diff --git a/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs b/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs index 80537f32ac..1d12a9a515 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits.Render public override object Create(ActorInitializer init) { return new WithVoxelBarrel(init.Self, this); } - public IEnumerable RenderPreviewVoxels( + public IEnumerable RenderPreviewVoxels( ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func orientation, int facings, PaletteReference p) { if (!EnabledByDefault) @@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits.Render Func quantizedBody = () => body.QuantizeOrientation(orientation(), facings); Func 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(); // always render instantly for units var rv = self.Trait(); - 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)); } diff --git a/OpenRA.Mods.Common/Traits/Render/WithVoxelBody.cs b/OpenRA.Mods.Common/Traits/Render/WithVoxelBody.cs index c1469ea193..8a154377fd 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithVoxelBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithVoxelBody.cs @@ -28,12 +28,12 @@ namespace OpenRA.Mods.Common.Traits.Render public override object Create(ActorInitializer init) { return new WithVoxelBody(init.Self, this); } - public IEnumerable RenderPreviewVoxels( + public IEnumerable RenderPreviewVoxels( ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func orientation, int facings, PaletteReference p) { var body = init.Actor.TraitInfo(); 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(); 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)); diff --git a/OpenRA.Mods.Common/Traits/Render/WithVoxelTurret.cs b/OpenRA.Mods.Common/Traits/Render/WithVoxelTurret.cs index d50271c5dd..0f23b0e011 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithVoxelTurret.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithVoxelTurret.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits.Render public override object Create(ActorInitializer init) { return new WithVoxelTurret(init.Self, this); } - public IEnumerable RenderPreviewVoxels( + public IEnumerable RenderPreviewVoxels( ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func 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 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(); // always render instantly for units var rv = self.Trait(); - 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)); }