Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentVrHandsModel.cs
浏览该文件的文档.
1using Engine;
5
6namespace Game {
9
11
13
15
17
19
20 public float m_pokeAnimationTime;
21
22 public double m_nextHandLightTime;
23
24 public float m_handLight;
25
26 public int m_itemLight;
27
29
31
32 public static LitShader m_shader = new(2, false, false, true, false, false);
33
34 public static int[] m_drawOrders = [1];
35
36 public Vector3 ItemOffsetOrder { get; set; }
37
38 public Vector3 ItemRotationOrder { get; set; }
39
40 public int[] DrawOrders => m_drawOrders;
41
42 public UpdateOrder UpdateOrder => UpdateOrder.FirstPersonModels;
43
44 public virtual void Draw(Camera camera, int drawOrder) {
45 if (!(m_componentPlayer.ComponentHealth.Health > 0f)
47 || !m_componentPlayer.ComponentInput.IsControlledByVr) {
48 return;
49 }
50 Vector3 eyePosition = m_componentPlayer.ComponentCreatureModel.EyePosition;
51 int x = Terrain.ToCell(eyePosition.X);
52 int num = Terrain.ToCell(eyePosition.Y);
53 int z = Terrain.ToCell(eyePosition.Z);
54 int activeBlockValue = m_componentMiner.ActiveBlockValue;
57 if (num2.HasValue) {
59 m_handLight = num2.Value;
60 }
61 }
62 Matrix identity = Matrix.Identity;
63 if (m_pokeAnimationTime > 0f) {
64 float num3 = MathF.Sin(MathF.Sqrt(m_pokeAnimationTime) * (float)Math.PI);
65 if (activeBlockValue != 0) {
66 identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(90f)) * num3);
67 }
68 else {
69 identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(45f)) * num3);
70 }
71 }
73 return;
74 }
76 * Matrix.CreateWorld(camera.ViewPosition, camera.ViewDirection, camera.ViewUp)
77 * camera.ViewMatrix;
78 Matrix controllerMatrix = VrManager.GetControllerMatrix(VrController.Right);
79 if (activeBlockValue == 0) {
80 Display.DepthStencilState = DepthStencilState.Default;
81 Display.RasterizerState = RasterizerState.CullCounterClockwiseScissor;
82 m_shader.Texture = m_componentPlayer.ComponentCreatureModel.TextureOverride;
83 m_shader.SamplerState = SamplerState.PointClamp;
84 m_shader.MaterialColor = Vector4.One;
85 m_shader.AmbientLightColor = new Vector3(m_handLight * LightingManager.LightAmbient);
86 m_shader.DiffuseLightColor1 = new Vector3(m_handLight);
87 m_shader.DiffuseLightColor2 = new Vector3(m_handLight);
88 m_shader.LightDirection1 = -Vector3.TransformNormal(LightingManager.DirectionToLight1, camera.ViewMatrix);
89 m_shader.LightDirection2 = -Vector3.TransformNormal(LightingManager.DirectionToLight2, camera.ViewMatrix);
90 m_shader.Transforms.View = Matrix.Identity;
91 m_shader.Transforms.Projection = camera.ProjectionMatrix;
92 m_shader.Transforms.World[0] = Matrix.CreateScale(0.01f) * identity * controllerMatrix * matrix;
93 foreach (ModelMesh mesh in m_vrHandModel.Meshes) {
94 foreach (ModelMeshPart meshPart in mesh.MeshParts) {
96 PrimitiveType.TriangleList,
98 meshPart.VertexBuffer,
99 meshPart.IndexBuffer,
100 meshPart.StartIndex,
101 meshPart.IndicesCount
102 );
103 }
104 }
105 }
106 else {
107 if (num >= 0
108 && num <= 255) {
109 TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z);
110 if (chunkAtCell != null
111 && chunkAtCell.State >= TerrainChunkState.InvalidVertices1) {
112 m_itemLight = m_subsystemTerrain.Terrain.GetCellLightFast(x, num, z);
113 }
114 }
115 int num4 = Terrain.ExtractContents(activeBlockValue);
116 Block block = BlocksManager.Blocks[num4];
117 Vector3 vector = block.InHandRotation * ((float)Math.PI / 180f) + m_itemRotation;
118 Matrix matrix2 = Matrix.CreateFromYawPitchRoll(vector.Y, vector.X, vector.Z)
120 * identity
122 * controllerMatrix
123 * matrix;
124 m_drawBlockEnvironmentData.DrawBlockMode = DrawBlockMode.FirstPerson;
125 m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain;
126 m_drawBlockEnvironmentData.InWorldMatrix = matrix2;
127 m_drawBlockEnvironmentData.Humidity = m_subsystemTerrain.Terrain.GetHumidity(x, z);
128 m_drawBlockEnvironmentData.Temperature = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z)
130 m_drawBlockEnvironmentData.Light = m_itemLight;
131 m_drawBlockEnvironmentData.EnvironmentTemperature = m_componentPlayer.ComponentVitalStats.EnvironmentTemperature;
132 block.DrawBlock(m_primitivesRenderer, activeBlockValue, Color.White, block.InHandScale, ref matrix2, m_drawBlockEnvironmentData);
133 }
135 }
136
144
145 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
146 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
147 m_componentPlayer = Entity.FindComponent<ComponentPlayer>(true);
148 m_componentMiner = Entity.FindComponent<ComponentMiner>(true);
149 m_vrHandModel = ContentManager.Get<Model>(valuesDictionary.GetValue<string>("VrHandModelName"));
150 }
151 }
152}
Engine.Vector3 Vector3
static readonly DepthStencilState Default
static void DrawIndexed(PrimitiveType primitiveType, Shader shader, VertexBuffer vertexBuffer, IndexBuffer indexBuffer, int startIndex, int indicesCount)
ReadOnlyList< ModelMeshPart > MeshParts
static readonly RasterizerState CullCounterClockwiseScissor
static float Saturate(float x)
static float DegToRad(float degrees)
static double FrameStartTime
定义 Time.cs:42
float InHandScale
Vector3 InHandOffset
void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
绘制方块_用于绘制方块物品形态
Vector3 ViewPosition
GameWidget GameWidget
Vector3 ViewUp
Matrix ViewMatrix
Vector3 ViewDirection
Matrix ProjectionMatrix
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
virtual void Draw(Camera camera, int drawOrder)
DrawBlockEnvironmentData m_drawBlockEnvironmentData
static object Get(Type type, string name)
static readonly Vector3 DirectionToLight2
static readonly float LightAmbient
static ? float CalculateSmoothLight(SubsystemTerrain subsystemTerrain, Vector3 p)
static readonly Vector3 DirectionToLight1
static Func< int, int > GetTemperatureAdjustmentAtHeight
TerrainChunkState State
static int ExtractContents(int value)
static int ToCell(float x)
static Matrix HmdMatrixInverted
static Matrix GetControllerMatrix(VrController controller)
static bool IsControllerPresent(VrController controller)
ValuesDictionary ValuesDictionary
bool IsEntityFirstPersonTarget(Entity entity)
static Color White
static Matrix CreateRotationX(float radians)
static Matrix CreateTranslation(float x, float y, float z)
static readonly Matrix Identity
static Matrix CreateFromYawPitchRoll(float yaw, float pitch, float roll)
static Matrix CreateWorld(Vector3 position, Vector3 forward, Vector3 up)
static Matrix CreateScale(float scale)
static Vector3 Lerp(Vector3 v1, Vector3 v2, float f)
static Vector3 TransformNormal(Vector3 v, Matrix m)
static readonly Vector3 Zero
static readonly Vector4 One