rajout d'un fichier json pour répertorier les matériaux

pull/41/head
Valentin Stark 3 years ago
parent 04321706ab
commit 656f1a2f0b
  1. 22
      LICENSE.md
  2. 27
      utils/world_generation/WorldGeneration.gd
  3. 5
      world/materials/materials.json
  4. 0
      world/materials/world.material
  5. 5
      world/world.tres

@ -1,22 +0,0 @@
The MIT License (MIT)
Copyright (c) 2021 João Marinheiro
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -4,7 +4,7 @@ class_name WorldGeneration
export(int) var width = 2048 export(int) var width = 2048
export(int) var height = 2048 export(int) var height = 2048
export(int) var spacing = 5 export(int) var spacing = 40
export(int, 1, 9) var octaves = 5 export(int, 1, 9) var octaves = 5
export(int, 1, 30) var wavelength = 8 export(int, 1, 30) var wavelength = 8
export(int) var border_width = 200 export(int) var border_width = 200
@ -71,6 +71,12 @@ func init_data():
center.set_data("coast", is_coast(center.to_point())) center.set_data("coast", is_coast(center.to_point()))
# if center.get_data("ocean"): # if center.get_data("ocean"):
# center.set_elevation(-1.0) # center.set_elevation(-1.0)
center.set_data("material", "grass")
if center.get_data("mountain"):
center.set_data("material", "stone")
if center.get_data("coast"):
center.set_data("material", "sand")
@ -236,7 +242,7 @@ func find_elevation(point):
elevation = min(elevation, 1) elevation = min(elevation, 1)
elevation = round(elevation * terraces) / terraces elevation = (elevation * terraces) / terraces
return elevation return elevation
@ -274,20 +280,19 @@ func is_coast(point):
func create_mesh(): func create_mesh():
var file = File.new()
file.open("res://world/materials/materials.json", File.READ)
var materials = JSON.parse(file.get_as_text()).result
var st = SurfaceTool.new() var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES) st.begin(Mesh.PRIMITIVE_TRIANGLES)
var factor = Vector3(1, 120, 1) var factor = Vector3(1, 120, 1)
for center in Global.terrain.get_centers(): for center in Global.terrain.get_centers():
if not center.get_data("water"): if not center.get_data("water"):
var top_uv = Vector2(0, 0) var material_id = materials[center.get_data("material")]
var border_uv = Vector2(1, 0) var top_uv = Vector2(0, float(material_id) / (materials.size()-1))
if center.get_data("mountain"): var border_uv = Vector2(1, float(material_id) / (materials.size()-1))
top_uv = Vector2(1, 0.5)
border_uv = Vector2(1, 0.5)
if center.get_data("coast"):
top_uv = Vector2(1, 1)
border_uv = Vector2(1, 1)
for edge in center.borders(): for edge in center.borders():
if edge.end_center().get_elevation() < edge.start_center().get_elevation(): if edge.end_center().get_elevation() < edge.start_center().get_elevation():
@ -325,7 +330,7 @@ func create_mesh():
var mi = MeshInstance.new() var mi = MeshInstance.new()
mi.mesh = st.commit() mi.mesh = st.commit()
var material = load("res://world/world.material") var material = load("res://world/materials/world.material")
mi.set_surface_material(0, material) mi.set_surface_material(0, material)
mi.create_trimesh_collision() mi.create_trimesh_collision()
mi.cast_shadow = GeometryInstance.SHADOW_CASTING_SETTING_ON mi.cast_shadow = GeometryInstance.SHADOW_CASTING_SETTING_ON

@ -0,0 +1,5 @@
{
"grass": 0,
"stone": 1,
"sand": 2
}

@ -1,5 +0,0 @@
[gd_resource type="SpatialMaterial" format=2]
[resource]
params_diffuse_mode = 1
albedo_color = Color( 0.125, 0.5, 0.275, 1 )
Loading…
Cancel
Save