Skip to content

Commit

Permalink
优化二极管材质显示,修复开关拨动杆角度
Browse files Browse the repository at this point in the history
  • Loading branch information
CS-LX committed Dec 29, 2023
1 parent e13f443 commit 4fb1cd2
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 22 deletions.
118 changes: 118 additions & 0 deletions Gigavolt/Assets/Models/GVAdjustableDelayGate.dae
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="utf-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<asset>
<contributor>
<author>Blender User</author>
<authoring_tool>Blender 3.4.0 commit date:2022-12-06, commit time:18:46, hash:a95bf1ac01be</authoring_tool>
</contributor>
<created>2023-12-29T14:58:41</created>
<modified>2023-12-29T14:58:41</modified>
<unit name="meter" meter="1"/>
<up_axis>Z_UP</up_axis>
</asset>
<library_images/>
<library_geometries>
<geometry id="Top-mesh" name="Top">
<mesh>
<source id="Top-mesh-positions">
<float_array id="Top-mesh-positions-array" count="9">-14.66092 -12.75 6.25 0 12.90661 6.25 14.66092 -12.75 6.25</float_array>
<technique_common>
<accessor source="#Top-mesh-positions-array" count="3" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Top-mesh-normals">
<float_array id="Top-mesh-normals-array" count="3">0 0 1</float_array>
<technique_common>
<accessor source="#Top-mesh-normals-array" count="1" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Top-mesh-map-0">
<float_array id="Top-mesh-map-0-array" count="6">0.6383232 0.4439836 0.6742048 0.4439836 0.656264 0.4718921</float_array>
<technique_common>
<accessor source="#Top-mesh-map-0-array" count="3" stride="2">
<param name="S" type="float"/>
<param name="T" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="Top-mesh-vertices">
<input semantic="POSITION" source="#Top-mesh-positions"/>
</vertices>
<triangles count="1">
<input semantic="VERTEX" source="#Top-mesh-vertices" offset="0"/>
<input semantic="NORMAL" source="#Top-mesh-normals" offset="1"/>
<input semantic="TEXCOORD" source="#Top-mesh-map-0" offset="2" set="0"/>
<p>0 0 0 2 0 1 1 0 2</p>
</triangles>
</mesh>
</geometry>
<geometry id="Body-mesh" name="Body">
<mesh>
<source id="Body-mesh-positions">
<float_array id="Body-mesh-positions-array" count="27">-14.66092 -12.75 6.25 0 12.90661 6.25 14.66092 -12.75 6.25 -25 -18.75 0 25 -18.75 0 0 25 0 -25 -18.75 6.25 0 25 6.25 25 -18.75 6.25</float_array>
<technique_common>
<accessor source="#Body-mesh-positions-array" count="9" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Body-mesh-normals">
<float_array id="Body-mesh-normals-array" count="18">0 -1 0 0.8682432 0.4961389 0 -0.8682432 0.4961389 0 0 0 -1 0 0 1 0 0 1</float_array>
<technique_common>
<accessor source="#Body-mesh-normals-array" count="6" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Body-mesh-map-0">
<float_array id="Body-mesh-map-0-array" count="78">0.937177 0.702866 0.87522 0.702866 0.87522 0.695054 0.87522 0.695054 0.937177 0.695054 0.937177 0.702866 0.929908 0.722397 0.87522 0.722397 0.87522 0.714585 0.87522 0.714585 0.929908 0.714585 0.929908 0.722397 0.929908 0.710679 0.87522 0.710679 0.87522 0.702866 0.87522 0.702866 0.929908 0.702866 0.929908 0.710679 0.906263 0.735041 0.875669 0.687452 0.936856 0.687452 0.906264 0.7218921 0.875671 0.687457 0.8883232 0.6939836 0.8883232 0.6939836 0.936857 0.687457 0.9242048 0.6939836 0.906264 0.7218921 0.936857 0.687457 0.906264 0.735047 0.906264 0.7218921 0.906264 0.735047 0.875671 0.687457 0.8883232 0.6939836 0.875671 0.687457 0.936857 0.687457 0.906264 0.7218921 0.9242048 0.6939836 0.936857 0.687457</float_array>
<technique_common>
<accessor source="#Body-mesh-map-0-array" count="39" stride="2">
<param name="S" type="float"/>
<param name="T" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="Body-mesh-vertices">
<input semantic="POSITION" source="#Body-mesh-positions"/>
</vertices>
<triangles count="13">
<input semantic="VERTEX" source="#Body-mesh-vertices" offset="0"/>
<input semantic="NORMAL" source="#Body-mesh-normals" offset="1"/>
<input semantic="TEXCOORD" source="#Body-mesh-map-0" offset="2" set="0"/>
<p>3 0 0 4 0 1 8 0 2 8 0 3 6 0 4 3 0 5 4 1 6 5 1 7 7 1 8 7 1 9 8 1 10 4 1 11 5 2 12 3 2 13 6 2 14 6 2 15 7 2 16 5 2 17 5 3 18 4 3 19 3 3 20 1 4 21 6 4 22 0 4 23 0 5 24 8 5 25 2 5 26 1 5 27 8 5 28 7 5 29 1 5 30 7 5 31 6 5 32 0 5 33 6 5 34 8 5 35 1 5 36 2 5 37 8 5 38</p>
</triangles>
</mesh>
</geometry>
</library_geometries>
<library_visual_scenes>
<visual_scene id="Scene" name="Scene">
<node id="GVAdjustableDelayGate" name="GVAdjustableDelayGate" type="NODE">
<matrix sid="transform">1 0 0 0 0 -4.37114e-8 1 0 0 -1 -4.37114e-8 0 0 0 0 1</matrix>
<node id="Body" name="Body" type="NODE">
<matrix sid="transform">0.01 0 0 0 0 0.01 1.19209e-9 0 0 -1.19209e-9 0.01 0 0 0 0 1</matrix>
<instance_geometry url="#Body-mesh" name="Body"/>
</node>
<node id="Top" name="Top" type="NODE">
<matrix sid="transform">0.01 0 0 0 0 0.01 1.19209e-9 0 0 -1.19209e-9 0.01 0 0 0 0 1</matrix>
<instance_geometry url="#Top-mesh" name="Top"/>
</node>
</node>
</visual_scene>
</library_visual_scenes>
<scene>
<instance_visual_scene url="#Scene"/>
</scene>
</COLLADA>
140 changes: 120 additions & 20 deletions Gigavolt/Block/Gate/GVAdjustableDelayGateBlock.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,106 @@
using System;
using System.Collections.Generic;
using Engine;
using Engine.Graphics;
using Engine.Media;

namespace Game {
public class GVAdjustableDelayGateBlock : RotateableMountedGVElectricElementBlock, IPaintableBlock {
namespace Game
{
public class GVAdjustableDelayGateBlock : RotateableMountedGVElectricElementBlock, IPaintableBlock
{
public const int Index = 808;
public readonly Texture2D WhiteTexture = Texture2D.Load(new Image(1, 1) { Pixels = { [0] = Color.White } });

public GVAdjustableDelayGateBlock() : base("Models/Gates", "AdjustableDelayGate", 0.375f) { }
public GVAdjustableDelayGateBlock() : base("Models/GVAdjustableDelayGate", "Body", 0.375f) { }

//顶部有颜色的部分
public BlockMesh[] m_blockMeshes_Top = new BlockMesh[24];

public BlockMesh m_standaloneBlockMesh_Top = new BlockMesh();

public override void Initialize()
{
//原先获取主体模型部分保留
base.Initialize();
//获取顶部模型
Model model = ContentManager.Get<Model>("Models/GVAdjustableDelayGate");
Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Top").ParentBone);
for (int i = 0; i < 6; i++)
{
float radians;
bool flag;
if (i < 4)
{
radians = i * (float)Math.PI / 2f;
flag = false;
}
else if (i == 4)
{
radians = -(float)Math.PI / 2f;
flag = true;
}
else
{
radians = (float)Math.PI / 2f;
flag = true;
}
for (int j = 0; j < 4; j++)
{
float radians2 = -j * (float)Math.PI / 2f;
int num = (i << 2) + j;
Matrix m = Matrix.CreateRotationX((float)Math.PI / 2f) * Matrix.CreateRotationZ(radians2) * Matrix.CreateTranslation(0f, 0f, -0.5f) * (flag ? Matrix.CreateRotationX(radians) : Matrix.CreateRotationY(radians)) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f);
m_blockMeshes_Top[num] = new BlockMesh();
m_blockMeshes_Top[num]
.AppendModelMeshPart(
model.FindMesh("Top").MeshParts[0],
boneAbsoluteTransform * m,
false,
false,
false,
false,
Color.White
);
}
}
Matrix m2 = Matrix.CreateRotationY(-(float)Math.PI / 2f) * Matrix.CreateRotationZ((float)Math.PI / 2f);
m_standaloneBlockMesh_Top.AppendModelMeshPart(
model.FindMesh("Top").MeshParts[0],
boneAbsoluteTransform * m2,
false,
false,
false,
false,
Color.White
);
}

public override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List<BlockDropValue> dropValues, out bool showDebris) {
public override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List<BlockDropValue> dropValues, out bool showDebris)
{
showDebris = true;
if (toolLevel >= RequiredToolLevel) {
if (toolLevel >= RequiredToolLevel)
{
int delay = GetDelay(Terrain.ExtractData(oldValue));
int data = SetDelay(0, delay);
dropValues.Add(new BlockDropValue { Value = Terrain.MakeBlockValue(Index, 0, data), Count = 1 });
}
}

public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData) {
public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
{
int? blockColor = GetColor(Terrain.ExtractData(value));
environmentData = environmentData ?? BlocksManager.m_defaultEnvironmentData;
BlocksManager.DrawMeshBlock(
primitivesRenderer,
m_standaloneBlockMesh,
environmentData.SubsystemTerrain == null ? BlocksTexturesManager.DefaultBlocksTexture : environmentData.SubsystemTerrain.SubsystemAnimatedTextures.AnimatedBlocksTexture,
color,
2f * size,
ref matrix,
environmentData
);
BlocksManager.DrawMeshBlock(
primitivesRenderer,
m_standaloneBlockMesh_Top,
blockColor.HasValue ? WhiteTexture :
environmentData.SubsystemTerrain == null ? BlocksTexturesManager.DefaultBlocksTexture : environmentData.SubsystemTerrain.SubsystemAnimatedTextures.AnimatedBlocksTexture,
blockColor.HasValue ? color * SubsystemPalette.GetColor(environmentData, blockColor) : color,
Expand All @@ -34,16 +110,28 @@ public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int valu
);
}

public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z) {
public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
{
int num = Terrain.ExtractData(value) & 0x1F;
if (num < m_blockMeshes.Length) {
if (num < m_blockMeshes.Length)
{
int? blockColor = GetColor(Terrain.ExtractData(value));
generator.GenerateMeshVertices(
this,
x,
y,
z,
m_blockMeshes[num],
Color.White,
null,
geometry.SubsetOpaque
);
generator.GenerateMeshVertices(
this,
x,
y,
z,
m_blockMeshes_Top[num],
blockColor.HasValue ? SubsystemPalette.GetColor(generator, blockColor) : Color.White,
null,
blockColor.HasValue ? geometry.GetGeometry(WhiteTexture).SubsetOpaque : geometry.SubsetOpaque
Expand All @@ -64,15 +152,19 @@ public override void GenerateTerrainVertices(BlockGeometryGenerator generator, T

public override GVElectricElement CreateGVElectricElement(SubsystemGVElectricity subsystemGVElectricity, int value, int x, int y, int z) => new AdjustableDelayGateGVElectricElement(subsystemGVElectricity, new CellFace(x, y, z, GetFace(value)));

public override GVElectricConnectorType? GetGVConnectorType(SubsystemTerrain terrain, int value, int face, int connectorFace, int x, int y, int z) {
public override GVElectricConnectorType? GetGVConnectorType(SubsystemTerrain terrain, int value, int face, int connectorFace, int x, int y, int z)
{
int data = Terrain.ExtractData(value);
if (GetFace(value) == face) {
if (GetFace(value) == face)
{
GVElectricConnectorDirection? connectorDirection = SubsystemGVElectricity.GetConnectorDirection(GetFace(value), GetRotation(data), connectorFace);
if (connectorDirection == GVElectricConnectorDirection.Bottom) {
if (connectorDirection == GVElectricConnectorDirection.Bottom)
{
return GVElectricConnectorType.Input;
}
if (connectorDirection == GVElectricConnectorDirection.Top
|| connectorDirection == GVElectricConnectorDirection.In) {
|| connectorDirection == GVElectricConnectorDirection.In)
{
return GVElectricConnectorType.Output;
}
}
Expand All @@ -83,7 +175,8 @@ public override void GenerateTerrainVertices(BlockGeometryGenerator generator, T

public static int SetDelay(int data, int delay) => (data & -8161) | ((delay & 0xFF) << 5);

public override IEnumerable<int> GetCreativeValues() {
public override IEnumerable<int> GetCreativeValues()
{
yield return Terrain.MakeBlockValue(Index);
yield return Terrain.MakeBlockValue(Index, 0, SetColor(0, 0));
yield return Terrain.MakeBlockValue(Index, 0, SetColor(0, 8));
Expand All @@ -104,7 +197,8 @@ public override IEnumerable<int> GetCreativeValues() {
public override string GetCategory(int value) => GetColor(Terrain.ExtractData(value)).HasValue ? "GV Electrics Multiple" : "GV Electrics Regular";
public override int GetDisplayOrder(int value) => GetColor(Terrain.ExtractData(value)).HasValue ? 12 : base.GetDisplayOrder(value);

public override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value) {
public override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value)
{
int? paintColor = GetColor(Terrain.ExtractData(value));
return paintColor.HasValue ? SubsystemPalette.GetName(subsystemTerrain, paintColor, "单向二极管") : base.GetDisplayName(subsystemTerrain, value);
}
Expand All @@ -113,14 +207,17 @@ public override string GetDisplayName(SubsystemTerrain subsystemTerrain, int val

public override bool IsEditable_(int value) => !GetColor(Terrain.ExtractData(value)).HasValue;

public override int GetConnectionMask(int value) {
public override int GetConnectionMask(int value)
{
int? color = GetColor(Terrain.ExtractData(value));
return color.HasValue ? 1 << color.Value : int.MaxValue;
}

public static int? GetColor(int data) {
public static int? GetColor(int data)
{
int? result = (data >> 14) & 0xF;
switch (result.Value) {
switch (result.Value)
{
case 0: return null;
case <= 7:
result--;
Expand All @@ -129,9 +226,12 @@ public override int GetConnectionMask(int value) {
return result;
}

public static int SetColor(int data, int? color) {
if (color.HasValue) {
if (color.Value < 7) {
public static int SetColor(int data, int? color)
{
if (color.HasValue)
{
if (color.Value < 7)
{
color++;
}
return (data & -245761) | ((color.Value & 0xF) << 14);
Expand Down
2 changes: 1 addition & 1 deletion Gigavolt/Block/Source/GVButtonBlock.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Engine;
using Engine.Graphics;
Expand Down
2 changes: 1 addition & 1 deletion Gigavolt/Block/Source/GVSwitchBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override void Initialize()
{
int num = (i << 1) | j;
Matrix matrix = i >= 4 ? i != 4 ? Matrix.CreateRotationX((float)Math.PI) * Matrix.CreateTranslation(0.5f, 1f, 0.5f) : Matrix.CreateTranslation(0.5f, 0f, 0.5f) : Matrix.CreateRotationX((float)Math.PI / 2f) * Matrix.CreateTranslation(0f, 0f, -0.5f) * Matrix.CreateRotationY(i * (float)Math.PI / 2f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f);
Matrix matrix2 = Matrix.CreateRotationX(j == 0 ? MathUtils.DegToRad(30f) : MathUtils.DegToRad(-75f));
Matrix matrix2 = Matrix.CreateRotationX(j == 0 ? MathUtils.DegToRad(30f) : MathUtils.DegToRad(-30f));
//主体模型
m_blockMeshesByIndex_Body[num] = new BlockMesh();
m_blockMeshesByIndex_Body[num]
Expand Down

0 comments on commit 4fb1cd2

Please sign in to comment.