Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentGlowingEyes.cs
浏览该文件的文档.
1using Engine;
5
6namespace Game {
9
11
13
15
16 public static int[] m_drawOrders = new int[1];
17
18 public Vector3 GlowingEyesOffset { get; set; }
19
20 public Color GlowingEyesColor { get; set; }
21
22 public int[] DrawOrders => m_drawOrders;
23
24 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
25 m_subsystemGlow = Project.FindSubsystem<SubsystemGlow>(true);
26 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
28 GlowingEyesOffset = valuesDictionary.GetValue<Vector3>("GlowingEyesOffset");
29 GlowingEyesColor = valuesDictionary.GetValue<Color>("GlowingEyesColor");
30 }
31
32 public override void OnEntityAdded() {
33 for (int i = 0; i < m_eyeGlowPoints.Length; i++) {
34 m_eyeGlowPoints[i] = m_subsystemGlow.AddGlowPoint();
35 }
36 }
37
38 public override void OnEntityRemoved() {
39 for (int i = 0; i < m_eyeGlowPoints.Length; i++) {
40 m_subsystemGlow.RemoveGlowPoint(m_eyeGlowPoints[i]);
41 }
42 }
43
44 public virtual void Draw(Camera camera, int drawOrder) {
45 if (m_eyeGlowPoints[0] == null
46 || !m_componentCreatureModel.IsVisibleForCamera) {
47 return;
48 }
51 ModelBone modelBone = m_componentCreatureModel.Model.FindBone("Head", false);
52 if (modelBone == null) {
53 return;
54 }
55 Matrix matrix = m_componentCreatureModel.AbsoluteBoneTransformsForCamera[modelBone.Index];
56 matrix *= camera.InvertedViewMatrix;
57 Vector3 vector = Vector3.Normalize(matrix.Up);
58 float num = Vector3.Dot(matrix.Translation - camera.ViewPosition, camera.ViewDirection);
59 if (num > 0f) {
60 Vector3 translation = matrix.Translation;
61 int cellLight = m_subsystemTerrain.Terrain.GetCellLight(
62 Terrain.ToCell(translation.X),
63 Terrain.ToCell(translation.Y),
64 Terrain.ToCell(translation.Z)
65 );
66 float num2 = LightingManager.LightIntensityByLightValue[cellLight];
67 float num3 = 0f - Vector3.Dot(vector, Vector3.Normalize(matrix.Translation - camera.ViewPosition)) > 0.7f ? 1 : 0;
68 num3 *= MathUtils.Saturate(1f * (num - 1f));
69 num3 *= MathUtils.Saturate((1f - num2 - 0.5f) / 0.5f);
70 if (num3 > 0.25f) {
71 Vector3 vector2 = Vector3.Normalize(matrix.Right);
72 Vector3 vector3 = -Vector3.Normalize(matrix.Forward);
73 Color color = GlowingEyesColor * num3;
74 m_eyeGlowPoints[0].Position = translation
75 + vector2 * GlowingEyesOffset.X
76 + vector3 * GlowingEyesOffset.Y
77 + vector * GlowingEyesOffset.Z;
78 m_eyeGlowPoints[0].Right = vector2;
79 m_eyeGlowPoints[0].Up = vector3;
80 m_eyeGlowPoints[0].Forward = vector;
81 m_eyeGlowPoints[0].Size = 0.01f;
82 m_eyeGlowPoints[0].FarSize = 0.06f;
83 m_eyeGlowPoints[0].FarDistance = 14f;
84 m_eyeGlowPoints[0].Color = color;
85 m_eyeGlowPoints[1].Position = translation
86 - vector2 * GlowingEyesOffset.X
87 + vector3 * GlowingEyesOffset.Y
88 + vector * GlowingEyesOffset.Z;
89 m_eyeGlowPoints[1].Right = vector2;
90 m_eyeGlowPoints[1].Up = vector3;
91 m_eyeGlowPoints[1].Forward = vector;
92 m_eyeGlowPoints[1].Size = 0.01f;
93 m_eyeGlowPoints[1].FarSize = 0.06f;
94 m_eyeGlowPoints[1].FarDistance = 14f;
95 m_eyeGlowPoints[1].Color = color;
96 }
97 }
98 }
99 }
100}
static float Saturate(float x)
Vector3 ViewPosition
Matrix InvertedViewMatrix
Vector3 ViewDirection
virtual void Draw(Camera camera, int drawOrder)
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
ComponentCreatureModel m_componentCreatureModel
static readonly float[] LightIntensityByLightValue
static int ToCell(float x)
ValuesDictionary ValuesDictionary
static Color Transparent
定义 Color.cs:5
Vector3 Translation
Vector3 Forward
static Vector3 Normalize(Vector3 v)
static float Dot(Vector3 v1, Vector3 v2)