Tweak the building block creator

This commit is contained in:
Jens Pitkänen 2024-08-17 22:05:30 +03:00
parent 2b321aae22
commit 27f9d0b2e5
4 changed files with 31 additions and 19 deletions

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=111 format=4 uid="uid://8po7ftboqq4k"]
[gd_scene load_steps=110 format=4 uid="uid://8po7ftboqq4k"]
[ext_resource type="CameraAttributesPhysical" uid="uid://cxyj2tvfksjl6" path="res://maps/hazy_env_camera_attrs.tres" id="1_r2j1d"]
[ext_resource type="LightmapGIData" uid="uid://bp05p4yab2ukx" path="res://maps/demo.lmbake" id="2_2ehlo"]
@ -8,8 +8,7 @@
[ext_resource type="Material" uid="uid://cobb5bm4y7nk7" path="res://textures/steel.tres" id="6_gip8a"]
[ext_resource type="Material" uid="uid://bpikku6t3gxi5" path="res://textures/white.tres" id="7_70h1h"]
[ext_resource type="Material" uid="uid://dgf570wtqn17j" path="res://textures/steel_fence.tres" id="8_dovc4"]
[ext_resource type="Script" path="res://scripts/BuildingBlockCreator.cs" id="9_87e5i"]
[ext_resource type="Material" uid="uid://bq5oqyuwekryv" path="res://textures/building_block.tres" id="10_u24tg"]
[ext_resource type="PackedScene" uid="uid://b61birqrnbee3" path="res://prefabs/building_block_creator.tscn" id="9_w4r35"]
[sub_resource type="ArrayMesh" id="ArrayMesh_kaiip"]
lightmap_size_hint = Vector2i(1030, 566)
@ -1022,8 +1021,5 @@ shape = SubResource("ConvexPolygonShape3D_i1n6v")
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(0.975917, 0.0634147, -0.208722, 0, 0.956814, 0.290702, 0.218143, -0.283701, 0.93377, -16.896, 2.82889, 36.323)
[node name="BagOfBlocks" type="Node3D" parent="." node_paths=PackedStringArray("Map")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -17.4926, 3.10406, 29.5336)
script = ExtResource("9_87e5i")
Map = NodePath("../FuncGodotMap")
BlockMaterial = ExtResource("10_u24tg")
[node name="BuildingBlockCreator" parent="." node_paths=PackedStringArray("TrenchbroomMap") instance=ExtResource("9_w4r35")]
TrenchbroomMap = NodePath("../FuncGodotMap")

View File

@ -0,0 +1,3 @@
[gd_scene format=3 uid="uid://dbkgssnjj28hp"]
[node name="BuildingBlock" type="RigidBody3D"]

View File

@ -0,0 +1,11 @@
[gd_scene load_steps=4 format=3 uid="uid://b61birqrnbee3"]
[ext_resource type="Script" path="res://scripts/BuildingBlockCreator.cs" id="1_fc08g"]
[ext_resource type="PackedScene" uid="uid://dbkgssnjj28hp" path="res://prefabs/building_block.tscn" id="2_ave1k"]
[ext_resource type="Material" uid="uid://bq5oqyuwekryv" path="res://textures/building_block.tres" id="3_i62u5"]
[node name="BuildingBlockCreator" type="Node3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -17.4926, 3.10406, 29.5336)
script = ExtResource("1_fc08g")
BuildingBlockPrefab = ExtResource("2_ave1k")
BuildingBlockMaterial = ExtResource("3_i62u5")

View File

@ -5,15 +5,17 @@ using Godot.Collections;
namespace Gmtk24 {
public partial class BuildingBlockCreator : Node3D {
[Export]
public Node3D Map;
public Node3D TrenchbroomMap;
[Export]
public ShaderMaterial BlockMaterial;
public PackedScene BuildingBlockPrefab;
[Export]
public ShaderMaterial BuildingBlockMaterial;
public override void _Ready() {
var scale = 0.05f;
var children = Map.FindChildren("*_buildingblock");
var children = TrenchbroomMap.FindChildren("*_buildingblock");
foreach (var buildingBlockStaticBody in children) {
var smallVersion = new RigidBody3D();
var buildingBlock = BuildingBlockPrefab.Instantiate();
var smallMesh = new MeshInstance3D {
Mesh = buildingBlockStaticBody.GetChild<MeshInstance3D>(0).Mesh,
@ -25,19 +27,19 @@ namespace Gmtk24 {
if (((int)transparency) != 0) {
// Make a new material, using the partly-transparent albedo as an alpha mask
var blockMaterialWithAlphaMask = new ShaderMaterial {
Shader = BlockMaterial.Shader,
Shader = BuildingBlockMaterial.Shader,
};
foreach (var uniform in BlockMaterial.Shader.GetShaderUniformList()) {
foreach (var uniform in BuildingBlockMaterial.Shader.GetShaderUniformList()) {
var uniformName = (StringName)((Dictionary)uniform).GetValueOrDefault("name");
blockMaterialWithAlphaMask.SetShaderParameter(uniformName, BlockMaterial.GetShaderParameter(uniformName));
blockMaterialWithAlphaMask.SetShaderParameter(uniformName, BuildingBlockMaterial.GetShaderParameter(uniformName));
}
blockMaterialWithAlphaMask.SetShaderParameter("texture_albedo_for_alpha", replacedMaterial.Get("albedo_texture"));
smallMesh.SetSurfaceOverrideMaterial(i, blockMaterialWithAlphaMask);
} else {
smallMesh.SetSurfaceOverrideMaterial(i, BlockMaterial);
smallMesh.SetSurfaceOverrideMaterial(i, BuildingBlockMaterial);
}
}
smallVersion.AddChild(smallMesh);
buildingBlock.AddChild(smallMesh);
var collisionShapes = buildingBlockStaticBody.FindChildren("*_collision_shape");
foreach (var shape in collisionShapes) {
@ -46,14 +48,14 @@ namespace Gmtk24 {
for (int i = 0; i < bigPoints.Length; i++) {
points[i] = bigPoints[i] * scale;
}
smallVersion.AddChild(new CollisionShape3D {
buildingBlock.AddChild(new CollisionShape3D {
Shape = new ConvexPolygonShape3D {
Points = points,
},
});
}
AddChild(smallVersion);
AddChild(buildingBlock);
}
}