1 #region Copyright & License Information 2 /* 3 * Copyright 2007-2020 The OpenRA Developers (see AUTHORS) 4 * This file is part of OpenRA, which is free software. It is made 5 * available to you under the terms of the GNU General Public License 6 * as published by the Free Software Foundation, either version 3 of 7 * the License, or (at your option) any later version. For more 8 * information, see COPYING. 9 */ 10 #endregion 11 12 using System.Collections.Generic; 13 using OpenRA.Graphics; 14 using OpenRA.Primitives; 15 16 namespace OpenRA.Mods.Common.Graphics 17 { 18 public class ModelPreview : IActorPreview 19 { 20 readonly ModelAnimation[] components; 21 readonly float scale; 22 readonly float[] lightAmbientColor; 23 readonly float[] lightDiffuseColor; 24 readonly WRot lightSource; 25 readonly WRot camera; 26 readonly PaletteReference colorPalette; 27 readonly PaletteReference normalsPalette; 28 readonly PaletteReference shadowPalette; 29 readonly WVec offset; 30 readonly int zOffset; 31 ModelPreview(ModelAnimation[] components, WVec offset, int zOffset, float scale, WAngle lightPitch, WAngle lightYaw, float[] lightAmbientColor, float[] lightDiffuseColor, WAngle cameraPitch, PaletteReference colorPalette, PaletteReference normalsPalette, PaletteReference shadowPalette)32 public ModelPreview(ModelAnimation[] components, WVec offset, int zOffset, float scale, WAngle lightPitch, WAngle lightYaw, 33 float[] lightAmbientColor, float[] lightDiffuseColor, WAngle cameraPitch, 34 PaletteReference colorPalette, PaletteReference normalsPalette, PaletteReference shadowPalette) 35 { 36 this.components = components; 37 this.scale = scale; 38 this.lightAmbientColor = lightAmbientColor; 39 this.lightDiffuseColor = lightDiffuseColor; 40 41 lightSource = new WRot(WAngle.Zero, new WAngle(256) - lightPitch, lightYaw); 42 camera = new WRot(WAngle.Zero, cameraPitch - new WAngle(256), new WAngle(256)); 43 44 this.colorPalette = colorPalette; 45 this.normalsPalette = normalsPalette; 46 this.shadowPalette = shadowPalette; 47 48 this.offset = offset; 49 this.zOffset = zOffset; 50 } 51 IActorPreview.Tick()52 void IActorPreview.Tick() { /* not supported */ } 53 IActorPreview.RenderUI(WorldRenderer wr, int2 pos, float scale)54 IEnumerable<IRenderable> IActorPreview.RenderUI(WorldRenderer wr, int2 pos, float scale) 55 { 56 yield return new UIModelRenderable(components, WPos.Zero + offset, pos, zOffset, camera, scale * this.scale, 57 lightSource, lightAmbientColor, lightDiffuseColor, 58 colorPalette, normalsPalette, shadowPalette); 59 } 60 IActorPreview.Render(WorldRenderer wr, WPos pos)61 IEnumerable<IRenderable> IActorPreview.Render(WorldRenderer wr, WPos pos) 62 { 63 yield return new ModelRenderable(components, pos + offset, zOffset, camera, scale, 64 lightSource, lightAmbientColor, lightDiffuseColor, 65 colorPalette, normalsPalette, shadowPalette); 66 } 67 IActorPreview.ScreenBounds(WorldRenderer wr, WPos pos)68 IEnumerable<Rectangle> IActorPreview.ScreenBounds(WorldRenderer wr, WPos pos) 69 { 70 foreach (var c in components) 71 yield return c.ScreenBounds(pos, wr, scale); 72 } 73 } 74 } 75