Fix building blocks

This commit is contained in:
Jens Pitkänen 2024-08-18 22:31:54 +03:00
parent bbd953aefa
commit c2103b2810
2 changed files with 12 additions and 7 deletions

View File

@ -60,7 +60,8 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.332064, 1.5426, 3.65156)
[node name="table" parent="." instance=ExtResource("11_7trvw")]
transform = Transform3D(-0.0123217, 0, 0.999924, 0, 1, 0, -0.999924, 0, -0.0123217, 0, 0, 0)
[node name="Node3D" parent="table" index="2"]
[node name="Node3D" parent="table" index="2" node_paths=PackedStringArray("TrenchbroomMap")]
TrenchbroomMap = NodePath("../../DemoMap")
BuildingBlockMaterial = ExtResource("12_i3ahj")
BuildingBlockScale = 0.005

View File

@ -19,8 +19,10 @@ namespace Gmtk24 {
CollisionLayer = 0b10,
};
var smallMesh = (MeshInstance3D)buildingBlockStaticBody.GetChild<MeshInstance3D>(0).Duplicate();
smallMesh.Scale = Vector3.One * BuildingBlockScale;
var smallMesh = new MeshInstance3D {
Mesh = buildingBlockStaticBody.GetChild<MeshInstance3D>(0).Mesh,
Scale = Vector3.One * BuildingBlockScale,
};
for (int i = 0; i < smallMesh.GetSurfaceOverrideMaterialCount(); i++) {
var replacedMaterial = smallMesh.Mesh.SurfaceGetMaterial(i);
var transparency = replacedMaterial.Get("transparency");
@ -37,14 +39,16 @@ namespace Gmtk24 {
var collisionShapes = buildingBlockStaticBody.FindChildren("*_collision_shape");
foreach (var shape in collisionShapes) {
CollisionShape3D newShape = (CollisionShape3D)shape.Duplicate();
var bigPoints = ((ConvexPolygonShape3D)newShape.Shape).Points;
var bigPoints = ((ConvexPolygonShape3D)((CollisionShape3D)shape).Shape).Points;
var points = new Vector3[bigPoints.Length];
for (int i = 0; i < bigPoints.Length; i++) {
points[i] = bigPoints[i] * BuildingBlockScale;
}
((ConvexPolygonShape3D)newShape.Shape).Points = points;
buildingBlock.AddChild(newShape);
buildingBlock.AddChild(new CollisionShape3D {
Shape = new ConvexPolygonShape3D {
Points = points,
},
});
}
AddChild(buildingBlock);