Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentModel.cs
浏览该文件的文档.
1using Engine;
6
7namespace Game {
8 public class ComponentModel : Component {
10
11 public bool IsSet;
12 public bool Animated;
13 public bool IsExtrasDrawn;
14
16
17 public Model m_model;
18
20
22
26 public Vector3 ModelOffset { get; set; }
27
31 public float Transparent { get; set; }
32
36 public float ModelScale { get; set; }
37
41 public string TextureRoute { get; set; }
42
46 public string ModelRoute { get; set; }
47
48 public float? Opacity { get; set; }
49
50 public Vector3? DiffuseColor { get; set; }
51
52 public Vector4? EmissionColor { get; set; }
53
54 public Model Model {
55 get => m_model;
56 set => SetModel(value);
57 }
58
59 public Texture2D TextureOverride { get; set; }
60
61 public virtual Func<bool> OnAnimate { get; set; }
62
63 public bool CastsShadow { get; set; }
64
65 public int PrepareOrder { get; set; }
66
67 public virtual ModelRenderingMode RenderingMode { get; set; }
68
69 public int[] MeshDrawOrders { get; set; }
70
71 public bool IsVisibleForCamera { get; set; }
72
74
75 public virtual Matrix? GetBoneTransform(int boneIndex) => m_boneTransforms[boneIndex];
76
77 public virtual void SetBoneTransform(int boneIndex, Matrix? transformation) {
78 bool canScale = boneIndex == Model.RootBone.Index;
79 Matrix? tf = canScale ? Matrix.CreateScale(ModelScale) * transformation : transformation;
81 }
82
83 public virtual void CalculateAbsoluteBonesTransforms(Camera camera) {
84 bool flag = false;
86 "OnModelCalculateBones",
87 loader => {
88 loader.OnModelCalculateBones(this, camera, out bool skip);
89 flag |= skip;
90 return false;
91 }
92 );
93 if (flag) {
94 return;
95 }
97 }
98
99 public virtual void CalculateIsVisible(Camera camera) {
100 bool flag = false;
102 "OnModelCalculateIsVisible",
103 loader => {
104 loader.OnModelCalculateIsVisible(this, camera, out bool skip);
105 flag |= skip;
106 return false;
107 }
108 );
109 if (flag) {
110 return;
111 }
113 IsVisibleForCamera = false;
114 return;
115 }
116 float num = MathUtils.Sqr(m_subsystemSky.VisibilityRange);
117 Vector3 vector = m_componentFrame.Position - camera.ViewPosition;
118 vector.Y *= m_subsystemSky.VisibilityRangeYMultiplier;
119 if (vector.LengthSquared() < num) {
122 }
123 else {
124 IsVisibleForCamera = false;
125 }
126 }
127
128 public virtual void Animate() {
129 Animated = false;
131 "OnAnimateModel",
132 loader => {
133 loader.OnAnimateModel(this, out bool skip);
134 Animated |= skip;
135 return false;
136 }
137 );
138 }
139
140 public virtual void DrawExtras(Camera camera) {
141 IsExtrasDrawn = false;
143 "OnModelDrawExtra",
144 loader => {
145 loader.OnModelDrawExtra(this, camera, out bool skip);
146 IsExtrasDrawn |= skip;
147 return false;
148 }
149 );
150 }
151
152 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
153 m_subsystemSky = Project.FindSubsystem<SubsystemSky>(true);
154 m_componentFrame = Entity.FindComponent<ComponentFrame>(true);
155 ModelRoute = valuesDictionary.GetValue("ModelName", "");
156 string modeltype = valuesDictionary.GetValue("ModelType", "Engine.Graphics.Model");
157 Type type = TypeCache.FindType(modeltype, true, true);
159 CastsShadow = valuesDictionary.GetValue<bool>("CastsShadow");
160 TextureRoute = valuesDictionary.GetValue("TextureOverride", "");
161 TextureOverride = string.IsNullOrEmpty(TextureRoute) ? null : ContentManager.Get<Texture2D>(TextureRoute);
162 PrepareOrder = valuesDictionary.GetValue<int>("PrepareOrder");
163 Transparent = valuesDictionary.GetValue("Transparent", 1f);
164 ModelScale = valuesDictionary.GetValue("ModelScale", 1f);
165 m_boundingSphereRadius = valuesDictionary.GetValue<float>("BoundingSphereRadius");
166 }
167
168 public virtual void SetModel(Model model) {
169 IsSet = false;
171 "OnSetModel",
172 modLoader => {
173 modLoader.OnSetModel(this, model, out IsSet);
174 return false;
175 }
176 );
177 if (IsSet) {
178 return;
179 }
180 m_model = model;
181 if (m_model != null) {
182 m_boneTransforms = new Matrix?[m_model.Bones.Count];
184 MeshDrawOrders = Enumerable.Range(0, m_model.Meshes.Count).ToArray();
185 }
186 else {
187 m_boneTransforms = null;
189 MeshDrawOrders = null;
190 }
191 }
192
193 public virtual void ProcessBoneHierarchy(ModelBone modelBone, Matrix currentTransform, Matrix[] transforms) {
194 Matrix m = modelBone.Transform;
195 if (m_boneTransforms[modelBone.Index].HasValue) {
196 Vector3 translation = m.Translation;
197 m.Translation = Vector3.Zero;
198 m *= m_boneTransforms[modelBone.Index].Value;
199 m.Translation += translation;
200 Matrix.MultiplyRestricted(ref m, ref currentTransform, out transforms[modelBone.Index]);
201 }
202 else {
203 Matrix.MultiplyRestricted(ref m, ref currentTransform, out transforms[modelBone.Index]);
204 }
205 foreach (ModelBone childBone in modelBone.ChildBones) {
206 ProcessBoneHierarchy(childBone, transforms[modelBone.Index], transforms);
207 }
208 }
209 }
210}
bool Intersection(Vector3 point)
ReadOnlyList< ModelBone > ChildBones
static int Sqr(int x)
static Type FindType(string typeName, bool skipSystemAssemblies, bool throwIfNotFound)
Vector3 ViewPosition
GameWidget GameWidget
BoundingFrustum ViewFrustum
Matrix ViewMatrix
virtual void SetBoneTransform(int boneIndex, Matrix? transformation)
virtual void CalculateIsVisible(Camera camera)
virtual void DrawExtras(Camera camera)
virtual void SetModel(Model model)
virtual ModelRenderingMode RenderingMode
virtual Func< bool > OnAnimate
virtual void CalculateAbsoluteBonesTransforms(Camera camera)
string ModelRoute
模型路径
Vector3 ModelOffset
模型偏移
ComponentFrame m_componentFrame
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
float ModelScale
模型大小缩放
virtual void ProcessBoneHierarchy(ModelBone modelBone, Matrix currentTransform, Matrix[] transforms)
string TextureRoute
纹理路径
float Transparent
模型透明度
virtual ? Matrix GetBoneTransform(int boneIndex)
static object Get(Type type, string name)
ValuesDictionary ValuesDictionary
bool IsEntityFirstPersonTarget(Entity entity)
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
static Matrix CreateTranslation(float x, float y, float z)
static void MultiplyRestricted(ref Matrix m1, ref Matrix m2, out Matrix result)
Vector3 Translation
static Matrix CreateScale(float scale)
static readonly Vector3 Zero
float LengthSquared()