summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-11-19 23:13:23 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-11-19 23:13:23 +0100
commit1a785420ec47c78ac3f95bd0ece08c819653f6e8 (patch)
tree92ca77abfe9f775f333edc47bf85a0652884840f
parent257127aa7f0fbb66ddd2600dd3d6a6aca60e56b8 (diff)
next commitHEADmain
-rw-r--r--Spritesheet_array.pngbin6613 -> 6886 bytes
-rw-r--r--Spritesheet_array.png~bin6708 -> 6613 bytes
-rw-r--r--block.gd160
-rw-r--r--chunk.gd90
-rw-r--r--main.gd202
-rw-r--r--main.tscn41
-rw-r--r--new_shader.gdshader7
-rw-r--r--new_shader_material.tres1
-rw-r--r--player.gd74
-rw-r--r--project.godot37
10 files changed, 529 insertions, 83 deletions
diff --git a/Spritesheet_array.png b/Spritesheet_array.png
index 25a41fb..82159f8 100644
--- a/Spritesheet_array.png
+++ b/Spritesheet_array.png
Binary files differ
diff --git a/Spritesheet_array.png~ b/Spritesheet_array.png~
index 984cb86..25a41fb 100644
--- a/Spritesheet_array.png~
+++ b/Spritesheet_array.png~
Binary files differ
diff --git a/block.gd b/block.gd
new file mode 100644
index 0000000..bfa9928
--- /dev/null
+++ b/block.gd
@@ -0,0 +1,160 @@
+class_name Block
+extends Resource
+
+
+const FACE_CORNERS = [
+ Vector2(0, 0), Vector2(1, 0),
+ Vector2(0, 1), Vector2(1, 1),
+]
+
+enum Face {
+ FRONT,
+ BACK,
+ LEFT,
+ RIGHT,
+ TOP,
+ BOTTOM,
+}
+
+const FACES = [
+ [ # FRONT
+ [Vector3(-1.0, 1.0, 1.0), Vector3(1.0, -1.0, 1.0), Vector3(-1.0, -1.0, 1.0)],
+ [Vector3(-1.0, 1.0, 1.0), Vector3(1.0, 1.0, 1.0), Vector3(1.0, -1.0, 1.0)],
+ ],
+ [ # BACK
+ [Vector3(1.0, 1.0, -1.0), Vector3(-1.0, -1.0, -1.0), Vector3(1.0, -1.0, -1.0)],
+ [Vector3(1.0, 1.0, -1.0), Vector3(-1.0, 1.0, -1.0), Vector3(-1.0, -1.0, -1.0)],
+ ],
+ [ # LEFT
+ [Vector3(-1.0, 1.0, -1.0), Vector3(-1.0, -1.0, 1.0), Vector3(-1.0, -1.0, -1.0)],
+ [Vector3(-1.0, 1.0, -1.0), Vector3(-1.0, 1.0, 1.0), Vector3(-1.0, -1.0, 1.0)],
+ ],
+ [ # RIGHT
+ [Vector3(1.0, 1.0, 1.0), Vector3(1.0, -1.0, -1.0), Vector3(1.0, -1.0, 1.0)],
+ [Vector3(1.0, 1.0, 1.0), Vector3(1.0, 1.0, -1.0), Vector3(1.0, -1.0, -1.0)],
+ ],
+ [ # TOP
+ [Vector3(-1.0, 1.0, -1.0), Vector3(1.0, 1.0, 1.0), Vector3(-1.0, 1.0, 1.0)],
+ [Vector3(-1.0, 1.0, -1.0), Vector3(1.0, 1.0, -1.0), Vector3(1.0, 1.0, 1.0)],
+ ],
+ [ # BOTTOM
+ [Vector3(-1.0, -1.0, 1.0), Vector3(1.0, -1.0, -1.0), Vector3(-1.0, -1.0, -1.0)],
+ [Vector3(-1.0, -1.0, 1.0), Vector3(1.0, -1.0, 1.0), Vector3(1.0, -1.0, -1.0)],
+ ],
+]
+
+const FACE_UVS = [
+ [ # FRONT
+ [Vector2(0.0, 0.0), Vector2(1.0, 1.0), Vector2(0.0, 1.0)],
+ [Vector2(0.0, 0.0), Vector2(1.0, 0.0), Vector2(1.0, 1.0)],
+ ],
+ [ # BACK
+ [Vector2(0.0, 0.0), Vector2(1.0, 1.0), Vector2(0.0, 1.0)],
+ [Vector2(0.0, 0.0), Vector2(1.0, 0.0), Vector2(1.0, 1.0)],
+ ],
+ [ # LEFT
+ [Vector2(0.0, 0.0), Vector2(1.0, 1.0), Vector2(0.0, 1.0)],
+ [Vector2(0.0, 0.0), Vector2(1.0, 0.0), Vector2(1.0, 1.0)],
+ ],
+ [ # RIGHT
+ [Vector2(0.0, 0.0), Vector2(1.0, 1.0), Vector2(0.0, 1.0)],
+ [Vector2(0.0, 0.0), Vector2(1.0, 0.0), Vector2(1.0, 1.0)],
+ ],
+ [ # TOP
+ [Vector2(0.0, 1.0), Vector2(1.0, 2.0), Vector2(0.0, 2.0)],
+ [Vector2(0.0, 1.0), Vector2(1.0, 1.0), Vector2(1.0, 2.0)],
+ ],
+ [ # BOTTOM
+ [Vector2(1.0, 0.0), Vector2(2.0, 1.0), Vector2(1.0, 1.0)],
+ [Vector2(1.0, 0.0), Vector2(2.0, 0.0), Vector2(2.0, 1.0)],
+ ],
+]
+
+const FACE_NORMALS = [
+ Vector3(0, 0, 1), # FRONT
+ Vector3(0, 0, -1), # BACK
+ Vector3(-1, 0, 0), # LEFT
+ Vector3(1, 0, 0), # RIGHT
+ Vector3(0, 1, 0), # TOP
+ Vector3(0, -1, 0), # BOTTOM
+]
+
+enum Type {
+ AIR,
+ GRASS,
+ DIRT,
+ LEAVES,
+ STONE,
+}
+
+const BLOCK_TYPES = {
+ Type.GRASS: {
+ "uv2s": [
+ Vector2(0, 0), # FRONT
+ Vector2(0, 0), # BACK
+ Vector2(0, 0), # LEFT
+ Vector2(0, 0), # RIGHT
+ Vector2(0, 1), # TOP
+ Vector2(1, 0), # BOTTOM
+ ],
+ },
+ Type.DIRT: {
+ "uv2s": [
+ Vector2(1, 0), # FRONT
+ Vector2(1, 0), # BACK
+ Vector2(1, 0), # LEFT
+ Vector2(1, 0), # RIGHT
+ Vector2(1, 0), # TOP
+ Vector2(1, 0), # BOTTOM
+ ],
+ },
+ Type.LEAVES: {
+ "uv2s": [
+ Vector2(2, 2), # FRONT
+ Vector2(2, 2), # BACK
+ Vector2(2, 2), # LEFT
+ Vector2(2, 2), # RIGHT
+ Vector2(2, 2), # TOP
+ Vector2(2, 2), # BOTTOM
+ ],
+ },
+ Type.STONE: {
+ "uv2s": [
+ Vector2(2, 0), # FRONT
+ Vector2(2, 0), # BACK
+ Vector2(2, 0), # LEFT
+ Vector2(2, 0), # RIGHT
+ Vector2(2, 0), # TOP
+ Vector2(2, 0), # BOTTOM
+ ],
+ },
+}
+
+var position: Vector3
+var type: Type
+
+
+func add_face(surface_tool: SurfaceTool, face: Face):
+ var uv2s = []
+ uv2s.resize(3)
+ uv2s.fill(BLOCK_TYPES[type].uv2s[face])
+
+ var normals = []
+ normals.resize(3)
+ normals.fill(FACE_NORMALS[face])
+
+ for idx in FACES[face].size():
+ var triangle = FACES[face][idx]
+ var triangle_positions = triangle.map(func(item):
+ return item + position
+ )
+
+ var uvs = FACE_UVS[face][idx]
+
+ surface_tool.add_triangle_fan(
+ PackedVector3Array(triangle_positions),
+ PackedVector2Array(uvs),
+ PackedColorArray(),
+ PackedVector2Array(uv2s),
+ PackedVector3Array(normals)
+ )
diff --git a/chunk.gd b/chunk.gd
new file mode 100644
index 0000000..8dcd416
--- /dev/null
+++ b/chunk.gd
@@ -0,0 +1,90 @@
+class_name Chunk
+extends Node
+
+
+var chunk_size := Vector3(16, 16, 16)
+
+@export var noise: FastNoiseLite
+
+var blocks: Array[Block] = []
+
+
+func generate_chunk(row, column, depth):
+ #var material := StandardMaterial3D.new()
+ #material.albedo_texture = preload("res://new_atlas_texture.tres")
+ #material.vertex_color_use_as_albedo = true
+ var material := preload("res://new_shader_material.tres")
+ var st = SurfaceTool.new()
+ st.begin(Mesh.PRIMITIVE_TRIANGLES)
+ st.set_material(material)
+
+ var blocks = []
+
+ for x in chunk_size.x:
+ #blocks[x] = []
+ blocks.append([])
+ for y in chunk_size.y:
+ #blocks[x][y] = []
+ blocks[x].append([])
+ for z in chunk_size.z:
+ var block_position = Vector3(
+ row*chunk_size.x + x,
+ column*chunk_size.y + y,
+ depth*chunk_size.z + z
+ #x,
+ #y,
+ #z
+ ) * 2
+ var value = noise.get_noise_3d(block_position.x, block_position.y, block_position.z) * 100
+
+ var type = Block.Type.AIR
+ if value > -15:
+ type = Block.Type.GRASS
+ elif value > -20:
+ type = Block.Type.STONE
+
+ var block = Block.new()
+ block.position = block_position
+ block.type = type
+
+ blocks[x][y].append(block)
+
+ for x in blocks.size():
+ for y in blocks[x].size():
+ for z in blocks[x][y].size():
+ var block = blocks[x][y][z]
+ var block_position = block.position
+
+ if not block.type == Block.Type.AIR:
+ if block.type == Block.Type.GRASS and blocks[x].size() > y + 1 and not blocks[x][y + 1][z].type == Block.Type.AIR:
+ block.type = Block.Type.DIRT
+
+ var rng = RandomNumberGenerator.new()
+ rng.seed = randi()
+ st.set_color(Color(rng.randf(), rng.randf(), rng.randf()))
+
+ st.set_uv(Vector2(0, 0))
+
+ if (blocks[x][y].size() > z+1 and blocks[x][y][z + 1].type == Block.Type.AIR) or blocks[x][y].size() == z+1:
+ block.add_face(st, Block.Face.FRONT, block)
+
+ if (blocks.size() > x+1 and blocks[x + 1][y][z].type == Block.Type.AIR) or blocks.size() == x+1:
+ block.add_face(st, Block.Face.RIGHT)
+
+ if blocks[x][y].size() > z-1 and (blocks[x][y][z - 1].type == Block.Type.AIR or z == 0):
+ block.add_face(st, Block.Face.BACK)
+
+ if blocks.size() > x-1 and (blocks[x - 1][y][z].type == Block.Type.AIR or x == 0):
+ block.add_face(st, Block.Face.LEFT)
+
+ if (blocks[x].size() > y+1 and blocks[x][y + 1][z].type == Block.Type.AIR) or blocks[x].size() == y+1:
+ block.add_face(st, Block.Face.TOP)
+
+ if blocks[x].size() > y-1 and (blocks[x][y - 1][z].type == Block.Type.AIR or y == 0):
+ block.add_face(st, Block.Face.BOTTOM)
+
+
+ #st.generate_normals()
+ var mesh = MeshInstance3D.new()
+ mesh.mesh = st.commit()
+ mesh.create_trimesh_collision()
diff --git a/main.gd b/main.gd
index 38ab4a1..ae29028 100644
--- a/main.gd
+++ b/main.gd
@@ -1,3 +1,4 @@
+class_name Main
extends Node3D
@@ -44,41 +45,93 @@ var block_faces = [
[Vector3(-1.0, -1.0, 1.0), Vector3(1.0, -1.0, 1.0), Vector3(1.0, -1.0, -1.0)],
],
]
+var block_face_uvs = [
+ [ # FRONT
+ [Vector2(0.0, 0.0), Vector2(1.0, 1.0), Vector2(0.0, 1.0)],
+ [Vector2(0.0, 0.0), Vector2(1.0, 0.0), Vector2(1.0, 1.0)],
+ ],
+ [ # BACK
+ [Vector2(0.0, 0.0), Vector2(1.0, 1.0), Vector2(0.0, 1.0)],
+ [Vector2(0.0, 0.0), Vector2(1.0, 0.0), Vector2(1.0, 1.0)],
+ ],
+ [ # LEFT
+ [Vector2(0.0, 0.0), Vector2(1.0, 1.0), Vector2(0.0, 1.0)],
+ [Vector2(0.0, 0.0), Vector2(1.0, 0.0), Vector2(1.0, 1.0)],
+ ],
+ [ # RIGHT
+ [Vector2(0.0, 0.0), Vector2(1.0, 1.0), Vector2(0.0, 1.0)],
+ [Vector2(0.0, 0.0), Vector2(1.0, 0.0), Vector2(1.0, 1.0)],
+ ],
+ [ # TOP
+ [Vector2(0.0, 1.0), Vector2(1.0, 2.0), Vector2(0.0, 2.0)],
+ [Vector2(0.0, 1.0), Vector2(1.0, 1.0), Vector2(1.0, 2.0)],
+ ],
+ [ # BOTTOM
+ [Vector2(1.0, 0.0), Vector2(2.0, 1.0), Vector2(1.0, 1.0)],
+ [Vector2(1.0, 0.0), Vector2(2.0, 0.0), Vector2(2.0, 1.0)],
+ ],
+]
+var block_face_normals = [
+ Vector3(0, 0, 1), # FRONT
+ Vector3(0, 0, -1), # BACK
+ Vector3(-1, 0, 0), # LEFT
+ Vector3(1, 0, 0), # RIGHT
+ Vector3(0, 1, 0), # TOP
+ Vector3(0, -1, 0), # BOTTOM
+]
enum BlockType {
+ AIR,
GRASS,
+ DIRT,
+ LEAVES,
+ STONE,
}
var block_types = {
BlockType.GRASS: {
- "uvs": [
- [ # FRONT
- [Vector2(0.0, 0.0), Vector2(1.0, 1.0), Vector2(0.0, 1.0)],
- [Vector2(0.0, 0.0), Vector2(1.0, 0.0), Vector2(1.0, 1.0)],
- ],
- [ # BACK
- [Vector2(0.0, 0.0), Vector2(1.0, 1.0), Vector2(0.0, 1.0)],
- [Vector2(0.0, 0.0), Vector2(1.0, 0.0), Vector2(1.0, 1.0)],
- ],
- [ # LEFT
- [Vector2(0.0, 0.0), Vector2(1.0, 1.0), Vector2(0.0, 1.0)],
- [Vector2(0.0, 0.0), Vector2(1.0, 0.0), Vector2(1.0, 1.0)],
- ],
- [ # RIGHT
- [Vector2(0.0, 0.0), Vector2(1.0, 1.0), Vector2(0.0, 1.0)],
- [Vector2(0.0, 0.0), Vector2(1.0, 0.0), Vector2(1.0, 1.0)],
- ],
- [ # TOP
- [Vector2(0.0, 1.0), Vector2(1.0, 2.0), Vector2(0.0, 2.0)],
- [Vector2(0.0, 1.0), Vector2(1.0, 1.0), Vector2(1.0, 2.0)],
- ],
- [ # BOTTOM
- [Vector2(1.0, 0.0), Vector2(2.0, 1.0), Vector2(1.0, 1.0)],
- [Vector2(1.0, 0.0), Vector2(2.0, 0.0), Vector2(2.0, 1.0)],
- ],
+ "uv2s": [
+ Vector2(0, 0), # FRONT
+ Vector2(0, 0), # BACK
+ Vector2(0, 0), # LEFT
+ Vector2(0, 0), # RIGHT
+ Vector2(0, 1), # TOP
+ Vector2(1, 0), # BOTTOM
+ ],
+ },
+ BlockType.DIRT: {
+ "uv2s": [
+ Vector2(1, 0), # FRONT
+ Vector2(1, 0), # BACK
+ Vector2(1, 0), # LEFT
+ Vector2(1, 0), # RIGHT
+ Vector2(1, 0), # TOP
+ Vector2(1, 0), # BOTTOM
+ ],
+ },
+ BlockType.LEAVES: {
+ "uv2s": [
+ Vector2(2, 2), # FRONT
+ Vector2(2, 2), # BACK
+ Vector2(2, 2), # LEFT
+ Vector2(2, 2), # RIGHT
+ Vector2(2, 2), # TOP
+ Vector2(2, 2), # BOTTOM
+ ],
+ },
+ BlockType.STONE: {
+ "uv2s": [
+ Vector2(2, 0), # FRONT
+ Vector2(2, 0), # BACK
+ Vector2(2, 0), # LEFT
+ Vector2(2, 0), # RIGHT
+ Vector2(2, 0), # TOP
+ Vector2(2, 0), # BOTTOM
],
},
}
+var chunks := []
+
func _ready() -> void:
brrr()
@@ -94,9 +147,12 @@ func brrr():
var thread = OtherThread.new()
var rrrb = func():
- for row in range(0, 2):
- for column in range(0, 2):
- for depth in range(0, 2):
+ for row in range(0, 8):
+ chunks.append([])
+ for column in range(0, 4):
+ chunks[row].append([])
+ for depth in range(0, 8):
+ chunks[row][column].append([])
generate_chunk(row, column, depth)
thread.start(rrrb)
@@ -123,19 +179,26 @@ func generate_chunk(row, column, depth):
for z in chunk_size.z:
var block_position = Vector3(
row*chunk_size.x + x,
- depth*chunk_size.y + y,
- column*chunk_size.z + z
+ column*chunk_size.y + y,
+ depth*chunk_size.z + z
#x,
#y,
#z
) * 2
- var value = noise.get_noise_3d(block_position.x, block_position.y, block_position.z)
+ var value = noise.get_noise_3d(block_position.x, block_position.y, block_position.z) * 100
- #blocks[x][y][z] = block_position
- blocks[x][y].append({
+ var type = BlockType.AIR
+ if value > -15:
+ type = BlockType.GRASS
+ elif value > -20:
+ type = BlockType.STONE
+
+ var block = {
"position": block_position,
- "set": abs(value) > 0.2,
- })
+ "type": type,
+ }
+ #blocks[x][y][z] = block_position
+ blocks[x][y].append(block)
for x in blocks.size():
for y in blocks[x].size():
@@ -143,36 +206,40 @@ func generate_chunk(row, column, depth):
var block = blocks[x][y][z]
var block_position = block.position
- if block.set:
+ if not block.type == BlockType.AIR:
+ if block.type == BlockType.GRASS and blocks[x].size() > y + 1 and not blocks[x][y + 1][z].type == BlockType.AIR:
+ block.type = BlockType.DIRT
+
var rng = RandomNumberGenerator.new()
rng.seed = randi()
st.set_color(Color(rng.randf(), rng.randf(), rng.randf()))
st.set_uv(Vector2(0, 0))
- if (blocks[x][y].size() > z+1 and not blocks[x][y][z + 1].set) or blocks[x][y].size() == z+1:
- add_face(st, BlockFace.FRONT, block_position)
+ if (blocks[x][y].size() > z+1 and blocks[x][y][z + 1].type == BlockType.AIR) or blocks[x][y].size() == z+1:
+ add_face(st, BlockFace.FRONT, block)
- if (blocks.size() > x+1 and not blocks[x + 1][y][z].set) or blocks.size() == x+1:
- add_face(st, BlockFace.RIGHT, block_position)
+ if (blocks.size() > x+1 and blocks[x + 1][y][z].type == BlockType.AIR) or blocks.size() == x+1:
+ add_face(st, BlockFace.RIGHT, block)
- if blocks[x][y].size() > z-1 and (not blocks[x][y][z - 1].set or z == 0):
- add_face(st, BlockFace.BACK, block_position)
+ if blocks[x][y].size() > z-1 and (blocks[x][y][z - 1].type == BlockType.AIR or z == 0):
+ add_face(st, BlockFace.BACK, block)
- if blocks.size() > x-1 and (not blocks[x - 1][y][z].set or x == 0):
- add_face(st, BlockFace.LEFT, block_position)
+ if blocks.size() > x-1 and (blocks[x - 1][y][z].type == BlockType.AIR or x == 0):
+ add_face(st, BlockFace.LEFT, block)
- if (blocks[x].size() > y+1 and not blocks[x][y + 1][z].set) or blocks[x].size() == y+1:
- add_face(st, BlockFace.TOP, block_position)
+ if (blocks[x].size() > y+1 and blocks[x][y + 1][z].type == BlockType.AIR) or blocks[x].size() == y+1:
+ add_face(st, BlockFace.TOP, block)
- if blocks[x].size() > y-1 and (not blocks[x][y - 1][z].set or y == 0):
- add_face(st, BlockFace.BOTTOM, block_position)
+ if blocks[x].size() > y-1 and (blocks[x][y - 1][z].type == BlockType.AIR or y == 0):
+ add_face(st, BlockFace.BOTTOM, block)
+ chunks[row][column][depth] = blocks
#st.generate_normals()
var mesh = MeshInstance3D.new()
mesh.mesh = st.commit()
- #mesh.create_trimesh_collision()
+ mesh.create_trimesh_collision()
add_child.call_deferred(mesh)
@@ -181,29 +248,17 @@ func _process(_delta: float) -> void:
pass
-func add_face(surface_tool: SurfaceTool, face: BlockFace, block_position: Vector3):
- var uv2 = []
- uv2.resize(3)
+func add_face(surface_tool: SurfaceTool, face: BlockFace, block: Dictionary):
+ var block_position: Vector3 = block.position
+ var type: BlockType = block.type
+
+ var uv2s = []
+ uv2s.resize(3)
+ uv2s.fill(block_types[type].uv2s[face])
+
var normals = []
normals.resize(3)
- if face == BlockFace.FRONT:
- uv2.fill(Vector2(0, 0))
- normals.fill(Vector3(0, 0, 1))
- elif face == BlockFace.BACK:
- uv2.fill(Vector2(0, 0))
- normals.fill(Vector3(0, 0, -1))
- elif face == BlockFace.LEFT:
- uv2.fill(Vector2(0, 0))
- normals.fill(Vector3(-1, 0, 0))
- elif face == BlockFace.RIGHT:
- uv2.fill(Vector2(0, 0))
- normals.fill(Vector3(1, 0, 0))
- elif face == BlockFace.TOP:
- uv2.fill(Vector2(6, 0))
- normals.fill(Vector3(0, 1, 0))
- elif face == BlockFace.BOTTOM:
- uv2.fill(Vector2(1, 0))
- normals.fill(Vector3(0, -1, 0))
+ normals.fill(block_face_normals[face])
for idx in block_faces[face].size():
var triangle = block_faces[face][idx]
@@ -211,15 +266,12 @@ func add_face(surface_tool: SurfaceTool, face: BlockFace, block_position: Vector
return item + block_position
)
- var uvs = block_types[BlockType.GRASS].uvs[face][idx].map(func(item):
- return item
- #return Vector2(item.x / 6.0, item.y / 3.0)
- )
+ var uvs = block_face_uvs[face][idx]
surface_tool.add_triangle_fan(
PackedVector3Array(triangle_positions),
PackedVector2Array(uvs),
PackedColorArray(),
- PackedVector2Array(uv2),
+ PackedVector2Array(uv2s),
PackedVector3Array(normals)
)
diff --git a/main.tscn b/main.tscn
index c7ff15b..b25da59 100644
--- a/main.tscn
+++ b/main.tscn
@@ -1,7 +1,8 @@
-[gd_scene load_steps=7 format=3 uid="uid://b7k6l3bm1f0db"]
+[gd_scene load_steps=8 format=3 uid="uid://b7k6l3bm1f0db"]
[ext_resource type="Script" path="res://main.gd" id="1_g4bmv"]
-[ext_resource type="Script" path="res://free-look-camera.gd" id="2_rja7k"]
+[ext_resource type="Texture2D" uid="uid://dv842eajslxyw" path="res://icon.svg" id="3_7tj3h"]
+[ext_resource type="Script" path="res://player.gd" id="3_tn7lj"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_vv2it"]
sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
@@ -16,7 +17,7 @@ sky = SubResource("Sky_fy05j")
tonemap_mode = 2
glow_enabled = true
-[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_2vt34"]
+[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_cggfi"]
[node name="Main" type="Node3D"]
script = ExtResource("1_g4bmv")
@@ -32,7 +33,37 @@ directional_shadow_max_distance = 400.0
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.767031, 0.64161, 0, -0.64161, 0.767031, 0.387164, 18.7811, 29.7854)
-script = ExtResource("2_rja7k")
+current = true
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
-material_override = SubResource("StandardMaterial3D_2vt34")
+
+[node name="CharacterBody3D" type="CharacterBody3D" parent="."]
+transform = Transform3D(-0.0770845, 0, 0.997025, 0, 1, 0, -0.997025, 0, -0.0770845, 0, 238.895, 0)
+script = ExtResource("3_tn7lj")
+
+[node name="CollisionShape3D" type="CollisionShape3D" parent="CharacterBody3D"]
+shape = SubResource("CapsuleShape3D_cggfi")
+
+[node name="CameraAnchor" type="Marker3D" parent="CharacterBody3D"]
+transform = Transform3D(0.999999, 0, 0, 0, 1, 0, 7.45058e-09, 0, 1, 0, 0.87, 0)
+
+[node name="Camera" type="Camera3D" parent="CharacterBody3D/CameraAnchor"]
+current = true
+
+[node name="RayCast3D" type="RayCast3D" parent="CharacterBody3D/CameraAnchor/Camera"]
+target_position = Vector3(0, 0, -5)
+
+[node name="CanvasLayer" type="CanvasLayer" parent="CharacterBody3D"]
+
+[node name="CenterContainer" type="CenterContainer" parent="CharacterBody3D/CanvasLayer"]
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+
+[node name="TextureRect" type="TextureRect" parent="CharacterBody3D/CanvasLayer/CenterContainer"]
+custom_minimum_size = Vector2(16, 16)
+layout_mode = 2
+texture = ExtResource("3_7tj3h")
+expand_mode = 1
diff --git a/new_shader.gdshader b/new_shader.gdshader
index 32b1f7c..e9d2a08 100644
--- a/new_shader.gdshader
+++ b/new_shader.gdshader
@@ -1,17 +1,18 @@
shader_type spatial;
uniform sampler2DArray textures : filter_nearest, source_color;
+uniform int elements_per_row;
void vertex() {
// Called for every vertex the material is visible on.
- //vec4 element = texture(textures, vec3(UV, UV2.x));
- //COLOR = element.rgba;
}
void fragment() {
// Called for every pixel the material is visible on.
- vec4 element = texture(textures, vec3(UV, UV2.x));
+ int index = int(UV2.y) * elements_per_row + int(UV2.x);
+ vec4 element = texture(textures, vec3(UV, float(index)));
ALBEDO = element.rgb;
+ //ALPHA = element.a;
}
//void light() {
diff --git a/new_shader_material.tres b/new_shader_material.tres
index 544517f..f01b9b1 100644
--- a/new_shader_material.tres
+++ b/new_shader_material.tres
@@ -6,4 +6,5 @@
[resource]
render_priority = 0
shader = ExtResource("1_ux1ye")
+shader_parameter/elements_per_row = 6
shader_parameter/textures = ExtResource("2_delqc")
diff --git a/player.gd b/player.gd
new file mode 100644
index 0000000..cf8e90e
--- /dev/null
+++ b/player.gd
@@ -0,0 +1,74 @@
+extends CharacterBody3D
+
+
+const SPEED = 20.0
+const JUMP_VELOCITY = 20.0
+
+var acc = 0
+
+
+func _ready() -> void:
+ Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
+
+
+func _input(event: InputEvent) -> void:
+ if event is InputEventMouse and event.is_pressed():
+ Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
+ if event.is_action_pressed("mouse_exit"):
+ Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
+
+ if event is InputEventMouseMotion:
+ $CameraAnchor.rotate_y(deg_to_rad(clamp(-event.relative.x * 0.25, -45, 45)))
+ $CameraAnchor.rotate_object_local(Vector3(1,0,0), deg_to_rad(-event.relative.y * 0.25))
+
+
+func _process(delta: float) -> void:
+ if $CameraAnchor/Camera/RayCast3D.is_colliding():
+ var collider = $CameraAnchor/Camera/RayCast3D.get_collider()
+ var point = $CameraAnchor/Camera/RayCast3D.get_collision_point()
+
+ var block_idx = floor(point / 2)
+ var block_chunk_idx = Vector3(
+ int(floor(point.x / 2)) % 16,
+ int(floor(point.y / 2)) % 16,
+ int(floor(point.z / 2)) % 16
+ )
+ var chunk_idx = floor(point / (16*2))
+
+ acc += delta
+ if acc / 5 > 1.0:
+ acc = 0
+ print(block_chunk_idx)
+ print(chunk_idx)
+ var chunk = get_tree().current_scene.chunks[chunk_idx.x][chunk_idx.y][chunk_idx.z]
+ var block = chunk[block_chunk_idx.x][block_chunk_idx.y][block_chunk_idx.z]
+ print(block)
+ print(Main.BlockType.keys()[block.type])
+
+
+func _physics_process(delta: float) -> void:
+ # Add the gravity.
+ if not is_on_floor():
+ velocity += get_gravity() * delta
+
+ # Handle jump.
+ if Input.is_action_just_pressed("ui_accept") and is_on_floor():
+ velocity.y = JUMP_VELOCITY
+
+ # Get the input direction and handle the movement/deceleration.
+ # As good practice, you should replace UI actions with custom gameplay actions.
+ var input_dir := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
+ var direction := (
+ (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
+ .rotated(Vector3(1, 0, 0), $CameraAnchor.rotation.x)
+ .rotated(Vector3(0, 1, 0), $CameraAnchor.rotation.y)
+ .rotated(Vector3(0, 0, 1), $CameraAnchor.rotation.z)
+ )
+ if direction:
+ velocity.x = direction.x * SPEED
+ velocity.z = direction.z * SPEED
+ else:
+ velocity.x = move_toward(velocity.x, 0, SPEED)
+ velocity.z = move_toward(velocity.z, 0, SPEED)
+
+ move_and_slide()
diff --git a/project.godot b/project.godot
index 1d2e0cb..e6bea42 100644
--- a/project.godot
+++ b/project.godot
@@ -17,6 +17,38 @@ config/icon="res://icon.svg"
[input]
+ui_left={
+"deadzone": 0.5,
+"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
+, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
+]
+}
+ui_right={
+"deadzone": 0.5,
+"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
+, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
+]
+}
+ui_up={
+"deadzone": 0.5,
+"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
+, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
+]
+}
+ui_down={
+"deadzone": 0.5,
+"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194322,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
+, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
+]
+}
camera_move={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":4,"position":Vector2(266, 19),"global_position":Vector2(275, 65),"factor":1.0,"button_index":3,"canceled":false,"pressed":true,"double_click":false,"script":null)
@@ -32,6 +64,11 @@ camera_zoom_in={
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":8,"position":Vector2(147, 18),"global_position":Vector2(156, 64),"factor":0.533333,"button_index":4,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
+mouse_exit={
+"deadzone": 0.5,
+"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
+]
+}
[rendering]