Add basic building blocks

This commit is contained in:
Jens Pitkänen 2024-08-17 21:52:00 +03:00
parent 65807ed5d5
commit 2b321aae22
6 changed files with 133 additions and 2 deletions

16
.editorconfig Normal file
View File

@ -0,0 +1,16 @@
root = true
[*.cs]
# New line preferences
csharp_new_line_before_catch = false
csharp_new_line_before_else = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_anonymous_types = false
csharp_new_line_before_members_in_object_initializers = false
csharp_new_line_before_open_brace = none
csharp_new_line_between_query_expression_clauses = false
dotnet_diagnostic.IDE0002.severity = none
dotnet_diagnostic.IDE0003.severity = none
dotnet_diagnostic.IDE0090.severity = none

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=109 format=4 uid="uid://8po7ftboqq4k"]
[gd_scene load_steps=111 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,6 +8,8 @@
[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"]
[sub_resource type="ArrayMesh" id="ArrayMesh_kaiip"]
lightmap_size_hint = Vector2i(1030, 566)
@ -1018,4 +1020,10 @@ shape = SubResource("ConvexPolygonShape3D_ldbum")
shape = SubResource("ConvexPolygonShape3D_i1n6v")
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(0.975917, -0.0921913, -0.197705, 0, 0.906308, -0.422618, 0.218143, 0.41244, 0.884481, -19.764, 1.6, 44.82)
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")

View File

@ -33,6 +33,12 @@ texture={
rendering/positional_shadow/atlas_quadrant_0_subdiv=2
[physics]
3d/run_on_separate_thread=true
common/physics_ticks_per_second=120
3d/default_gravity=15.0
[rendering]
lights_and_shadows/use_physical_light_units=true

View File

@ -0,0 +1,63 @@
using System.Collections.Generic;
using Godot;
using Godot.Collections;
namespace Gmtk24 {
public partial class BuildingBlockCreator : Node3D {
[Export]
public Node3D Map;
[Export]
public ShaderMaterial BlockMaterial;
public override void _Ready() {
var scale = 0.05f;
var children = Map.FindChildren("*_buildingblock");
foreach (var buildingBlockStaticBody in children) {
var smallVersion = new RigidBody3D();
var smallMesh = new MeshInstance3D {
Mesh = buildingBlockStaticBody.GetChild<MeshInstance3D>(0).Mesh,
Scale = Vector3.One * scale,
};
for (int i = 0; i < smallMesh.GetSurfaceOverrideMaterialCount(); i++) {
var replacedMaterial = smallMesh.Mesh.SurfaceGetMaterial(i);
var transparency = replacedMaterial.Get("transparency");
if (((int)transparency) != 0) {
// Make a new material, using the partly-transparent albedo as an alpha mask
var blockMaterialWithAlphaMask = new ShaderMaterial {
Shader = BlockMaterial.Shader,
};
foreach (var uniform in BlockMaterial.Shader.GetShaderUniformList()) {
var uniformName = (StringName)((Dictionary)uniform).GetValueOrDefault("name");
blockMaterialWithAlphaMask.SetShaderParameter(uniformName, BlockMaterial.GetShaderParameter(uniformName));
}
blockMaterialWithAlphaMask.SetShaderParameter("texture_albedo_for_alpha", replacedMaterial.Get("albedo_texture"));
smallMesh.SetSurfaceOverrideMaterial(i, blockMaterialWithAlphaMask);
} else {
smallMesh.SetSurfaceOverrideMaterial(i, BlockMaterial);
}
}
smallVersion.AddChild(smallMesh);
var collisionShapes = buildingBlockStaticBody.FindChildren("*_collision_shape");
foreach (var shape in collisionShapes) {
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] * scale;
}
smallVersion.AddChild(new CollisionShape3D {
Shape = new ConvexPolygonShape3D {
Points = points,
},
});
}
AddChild(smallVersion);
}
}
public override void _Process(double delta) {
}
}
}

View File

@ -0,0 +1,25 @@
shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_schlick_ggx, depth_prepass_alpha;
uniform vec4 albedo : source_color;
uniform float roughness : hint_range(0.0, 1.0);
uniform float specular : hint_range(0.0, 1.0, 0.01);
uniform float metallic : hint_range(0.0, 1.0, 0.01);
uniform vec3 uv1_scale;
uniform vec3 uv1_offset;
uniform sampler2D texture_albedo_for_alpha : source_color, filter_linear_mipmap, repeat_enable;
void vertex() {
UV = UV * uv1_scale.xy + uv1_offset.xy;
}
void fragment() {
vec2 base_uv = UV;
vec4 albedo_tex_for_alpha = texture(texture_albedo_for_alpha, base_uv);
ALBEDO = albedo.rgb;
METALLIC = metallic;
SPECULAR = specular;
ROUGHNESS = roughness;
ALPHA *= albedo.a * albedo_tex_for_alpha.a;
}

View File

@ -0,0 +1,13 @@
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://bq5oqyuwekryv"]
[ext_resource type="Shader" path="res://textures/building_block.gdshader" id="1_5ux3x"]
[resource]
render_priority = 0
shader = ExtResource("1_5ux3x")
shader_parameter/albedo = Color(0.417896, 0.417896, 0.417896, 1)
shader_parameter/roughness = 0.533
shader_parameter/specular = 0.45
shader_parameter/metallic = null
shader_parameter/uv1_scale = Vector3(1, 1, 1)
shader_parameter/uv1_offset = null