Fiddle with Block Creation
This commit is contained in:
parent
7dfaf8ad6e
commit
eac93e3f97
20
scenes/BuildingBlockScene.tscn
Normal file
20
scenes/BuildingBlockScene.tscn
Normal file
@ -0,0 +1,20 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://bmewhw3f0n2s8"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/BuildingBlock.cs" id="1_htnym"]
|
||||
[ext_resource type="Shader" path="res://textures/building_block.gdshader" id="2_dc3y0"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_q3u5a"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("2_dc3y0")
|
||||
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
|
||||
|
||||
[node name="BuildingBlockScene" type="RigidBody3D"]
|
||||
script = ExtResource("1_htnym")
|
||||
|
||||
[node name="MeshInstance" type="MeshInstance3D" parent="."]
|
||||
material_override = SubResource("ShaderMaterial_q3u5a")
|
@ -1,13 +1,12 @@
|
||||
[gd_scene load_steps=9 format=3 uid="uid://8po7ftboqq4k"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://8po7ftboqq4k"]
|
||||
|
||||
[ext_resource type="CameraAttributesPhysical" uid="uid://cxyj2tvfksjl6" path="res://scenes/hazy_env_camera_attrs.tres" id="1_r2j1d"]
|
||||
[ext_resource type="PackedScene" uid="uid://br315evr8x2gt" path="res://scenes/hazy_env.tscn" id="2_le85m"]
|
||||
[ext_resource type="LightmapGIData" uid="uid://bp05p4yab2ukx" path="res://scenes/demo/demo.lmbake" id="2_thfwf"]
|
||||
[ext_resource type="PackedScene" path="res://scenes/demo/demo_map.tscn" id="4_0ojvw"]
|
||||
[ext_resource type="PackedScene" uid="uid://bqts60gpnb82d" path="res://scenes/demo/demo_map.tscn" id="4_0ojvw"]
|
||||
[ext_resource type="PackedScene" uid="uid://wjbuh7jk50nm" path="res://scenes/player.tscn" id="10_3xiy2"]
|
||||
[ext_resource type="PackedScene" uid="uid://d02cqylu3xwos" path="res://scenes/table.tscn" id="11_7trvw"]
|
||||
[ext_resource type="PackedScene" uid="uid://c670g1qg5gaug" path="res://scenes/interface/pause_menu.tscn" id="11_lav3p"]
|
||||
[ext_resource type="Material" uid="uid://bq5oqyuwekryv" path="res://textures/building_block.tres" id="12_i3ahj"]
|
||||
|
||||
[node name="Demo" type="Node3D"]
|
||||
|
||||
@ -55,12 +54,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.332064, 1.5426, 3.65156)
|
||||
|
||||
[node name="PauseMenu" parent="." instance=ExtResource("11_lav3p")]
|
||||
|
||||
[node name="table" parent="." instance=ExtResource("11_7trvw")]
|
||||
[node name="table" parent="." node_paths=PackedStringArray("TrenchbroomMap") 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_paths=PackedStringArray("TrenchbroomMap")]
|
||||
TrenchbroomMap = NodePath("../../DemoMap")
|
||||
BuildingBlockMaterial = ExtResource("12_i3ahj")
|
||||
BuildingBlockScale = 0.005
|
||||
|
||||
[editable path="table"]
|
||||
TrenchbroomMap = NodePath("../DemoMap")
|
||||
RelativeScale = 0.005
|
||||
|
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=135 format=4 uid="uid://d4fn0ljcmjdnb"]
|
||||
[gd_scene load_steps=135 format=4 uid="uid://bqts60gpnb82d"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/func_godot/src/map/func_godot_map.gd" id="1_2fyf3"]
|
||||
[ext_resource type="Resource" uid="uid://byyagd41ivbt1" path="res://trenchbroom/map_settings.tres" id="2_bv511"]
|
||||
|
@ -1,21 +1,54 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://d02cqylu3xwos"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://d02cqylu3xwos"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://diwlyi146eroa" path="res://models/table.fbx" id="1_1soa3"]
|
||||
[ext_resource type="Script" path="res://scripts/BuildingBlockCreator.cs" id="2_rqgiy"]
|
||||
[ext_resource type="Script" path="res://scripts/Table.cs" id="1_cb7s1"]
|
||||
[ext_resource type="Material" uid="uid://bq5oqyuwekryv" path="res://textures/building_block.tres" id="2_1s35y"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_iiew7"]
|
||||
size = Vector3(1.26587, 0.102112, 2.3989)
|
||||
|
||||
[node name="table" type="StaticBody3D"]
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_kn6mn"]
|
||||
size = Vector3(1.3, 5, 0.01)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_5k7xn"]
|
||||
size = Vector3(2.4, 5, 0.01)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_3kmm7"]
|
||||
size = Vector3(1.3, 0.2, 2.4)
|
||||
|
||||
[node name="table" type="StaticBody3D" node_paths=PackedStringArray("SpawnPoint")]
|
||||
collision_layer = 3
|
||||
collision_mask = 3
|
||||
script = ExtResource("1_cb7s1")
|
||||
BlockMaterial = ExtResource("2_1s35y")
|
||||
SpawnPoint = NodePath("SpawnPoint")
|
||||
BlockMask = 2
|
||||
|
||||
[node name="table" parent="." instance=ExtResource("1_1soa3")]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
[node name="TableCollider" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00354004, 1.05606, -0.00126699)
|
||||
shape = SubResource("BoxShape3D_iiew7")
|
||||
|
||||
[node name="Node3D" type="Node3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.58235, 0)
|
||||
script = ExtResource("2_rqgiy")
|
||||
[node name="SpawnPoint" type="Node3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.7677, 0)
|
||||
|
||||
[node name="Wall1" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.6, 1.2)
|
||||
shape = SubResource("BoxShape3D_kn6mn")
|
||||
|
||||
[node name="Wall2" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.6, -1.2)
|
||||
shape = SubResource("BoxShape3D_kn6mn")
|
||||
|
||||
[node name="Wall3" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -0.65, 3.6, 0)
|
||||
shape = SubResource("BoxShape3D_5k7xn")
|
||||
|
||||
[node name="Wall4" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0.65, 3.6, 0)
|
||||
shape = SubResource("BoxShape3D_5k7xn")
|
||||
|
||||
[node name="Roof" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 6, 0)
|
||||
shape = SubResource("BoxShape3D_3kmm7")
|
||||
|
63
scripts/BuildingBlock.cs
Normal file
63
scripts/BuildingBlock.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using System;
|
||||
|
||||
namespace Gmtk24 {
|
||||
public partial class BuildingBlock : RigidBody3D {
|
||||
public BaseBlock Base;
|
||||
public ShaderMaterial Material;
|
||||
public float RelativeScale;
|
||||
|
||||
public BuildingBlock() {
|
||||
Name = "BuildingBlock";
|
||||
}
|
||||
|
||||
public override void _Ready() {
|
||||
base._Ready();
|
||||
|
||||
var meshInstance = new MeshInstance3D() {
|
||||
Mesh = Base.Mesh,
|
||||
Scale = Vector3.One * RelativeScale,
|
||||
};
|
||||
AddChild(meshInstance);
|
||||
|
||||
for (int i = 0; i < meshInstance.GetSurfaceOverrideMaterialCount(); i++) {
|
||||
var replacedMaterial = meshInstance.Mesh.SurfaceGetMaterial(i);
|
||||
var transparency = replacedMaterial.Get("transparency");
|
||||
if (((int)transparency) != 0) {
|
||||
ShaderMaterial newMat = (ShaderMaterial)Material.Duplicate();
|
||||
newMat.SetShaderParameter("texture_albedo_for_alpha", replacedMaterial.Get("albedo_texture"));
|
||||
meshInstance.SetSurfaceOverrideMaterial(i, newMat);
|
||||
} else {
|
||||
meshInstance.SetSurfaceOverrideMaterial(i, Material);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var shape in Base.Colliders) {
|
||||
var bigPoints = ((ConvexPolygonShape3D)shape.Shape).Points;
|
||||
var points = new Vector3[bigPoints.Length];
|
||||
for (int i = 0; i < bigPoints.Length; i++) {
|
||||
points[i] = bigPoints[i] * RelativeScale;
|
||||
}
|
||||
AddChild(new CollisionShape3D {
|
||||
Shape = new ConvexPolygonShape3D {
|
||||
Points = points,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public struct BaseBlock {
|
||||
public Mesh Mesh;
|
||||
public Array<CollisionShape3D> Colliders;
|
||||
|
||||
public BaseBlock(StaticBody3D reference) {
|
||||
Mesh = ((MeshInstance3D)reference.FindChild("*_mesh_instance")).Mesh;
|
||||
Colliders = new Array<CollisionShape3D>();
|
||||
foreach (var shape in reference.FindChildren("*_collision_shape")) {
|
||||
Colliders.Add((CollisionShape3D)shape);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
namespace Gmtk24 {
|
||||
public partial class BuildingBlockCreator : Node3D {
|
||||
[Export]
|
||||
public Node3D TrenchbroomMap;
|
||||
// [Export]
|
||||
// public PackedScene BuildingBlockPrefab;
|
||||
[Export]
|
||||
public ShaderMaterial BuildingBlockMaterial;
|
||||
[Export]
|
||||
public float BuildingBlockScale = 0.05f;
|
||||
|
||||
public override void _Ready() {
|
||||
var children = TrenchbroomMap.FindChildren("*_buildingblock");
|
||||
foreach (var buildingBlockStaticBody in children) {
|
||||
var buildingBlock = new RigidBody3D() {
|
||||
CollisionMask = 0b10,
|
||||
CollisionLayer = 0b10,
|
||||
};
|
||||
|
||||
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");
|
||||
if (((int)transparency) != 0) {
|
||||
// Make a new material, using the partly-transparent albedo as an alpha mask
|
||||
var blockMaterialWithAlphaMask = (ShaderMaterial)BuildingBlockMaterial.Duplicate();
|
||||
blockMaterialWithAlphaMask.SetShaderParameter("texture_albedo_for_alpha", replacedMaterial.Get("albedo_texture"));
|
||||
smallMesh.SetSurfaceOverrideMaterial(i, blockMaterialWithAlphaMask);
|
||||
} else {
|
||||
smallMesh.SetSurfaceOverrideMaterial(i, BuildingBlockMaterial);
|
||||
}
|
||||
}
|
||||
buildingBlock.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] * BuildingBlockScale;
|
||||
}
|
||||
buildingBlock.AddChild(new CollisionShape3D {
|
||||
Shape = new ConvexPolygonShape3D {
|
||||
Points = points,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
AddChild(buildingBlock);
|
||||
var rng = new RandomNumberGenerator();
|
||||
buildingBlock.Translate(Vector3.One * rng.Randf() * 0.5f);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta) {
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
|
||||
namespace Gmtk24 {
|
||||
public partial class Table : StaticBody3D {
|
||||
[Export(PropertyHint.NodeType, "FuncGodotMap")]
|
||||
public Node3D TrenchbroomMap;
|
||||
[Export(PropertyHint.Range, "0.005,0.1,0.005,or_greater")]
|
||||
public float RelativeScale = 0.05f;
|
||||
[Export]
|
||||
public ShaderMaterial BlockMaterial;
|
||||
[Export]
|
||||
public Node3D SpawnPoint;
|
||||
[Export(PropertyHint.LayersAvoidance)]
|
||||
public uint BlockMask;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready() {
|
||||
Vector3 SpawnPos = Vector3.Zero;
|
||||
|
||||
if (SpawnPoint != null)
|
||||
SpawnPos = SpawnPoint.GlobalPosition - GlobalPosition;
|
||||
|
||||
SpawnBlocks(SpawnPos);
|
||||
}
|
||||
|
||||
public void SpawnBlocks(Vector3 position) {
|
||||
var rng = new RandomNumberGenerator();
|
||||
|
||||
var children = TrenchbroomMap.FindChildren("*_buildingblock");
|
||||
foreach (StaticBody3D buildingBlockStaticBody in children.Cast<StaticBody3D>()) {
|
||||
|
||||
var baseBlock = new BuildingBlock.BaseBlock(buildingBlockStaticBody);
|
||||
|
||||
var block = new BuildingBlock() {
|
||||
Base = baseBlock,
|
||||
Material = BlockMaterial,
|
||||
Position = position + Vector3.One * (rng.Randf() * 0.5f - 0.25f) + Vector3.Up * rng.Randf(),
|
||||
CollisionMask = BlockMask,
|
||||
CollisionLayer = BlockMask,
|
||||
RelativeScale = RelativeScale,
|
||||
};
|
||||
|
||||
AddChild(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user