2020-02-26 12:19:55 +01:00
|
|
|
tool
|
2020-06-12 19:55:37 +02:00
|
|
|
extends VoxelChunkMarchingCubes
|
2019-11-20 14:37:34 +01:00
|
|
|
class_name TVVoxelChunk
|
|
|
|
|
|
|
|
# Copyright Péter Magyar relintai@gmail.com
|
|
|
|
# MIT License, might be merged into the Voxelman engine module
|
|
|
|
|
2020-01-31 20:01:34 +01:00
|
|
|
# Copyright (c) 2019-2020 Péter Magyar
|
2019-12-01 23:21:48 +01:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
2019-11-20 14:37:34 +01:00
|
|
|
var _prop_texture_packer : TexturePacker
|
|
|
|
var _textures : Array
|
|
|
|
var _prop_material : SpatialMaterial
|
|
|
|
var _entities_spawned : bool
|
|
|
|
|
2020-06-23 20:58:14 +02:00
|
|
|
var _prop_mesh_instance_rid : RID
|
|
|
|
var _prop_mesh_rid : RID
|
|
|
|
|
2020-07-06 22:33:56 +02:00
|
|
|
#func _init():
|
|
|
|
# add_mesh_data_resource(get_transform().scaled(Vector3(10, 10, 10)), ResourceLoader.load("res://modules/species/Human/Female/character_models/huf_calf_left.gltf"))
|
|
|
|
# add_mesh_data_resource(get_transform().translated(Vector3(0, 4, 0)), ResourceLoader.load("res://modules/species/Human/Female/character_models/huf_calf_left.gltf"))
|
|
|
|
|
|
|
|
|
2020-01-13 00:43:45 +01:00
|
|
|
func _create_meshers():
|
2020-10-06 00:09:25 +02:00
|
|
|
var tj : VoxelTerrarinJob = VoxelTerrarinJob.new()
|
|
|
|
var lj : VoxelLightJob = VoxelLightJob.new()
|
|
|
|
var pj : VoxelPropJob = VoxelPropJob.new()
|
|
|
|
|
|
|
|
var prop_mesher = TVVoxelMesher.new()
|
2020-07-06 22:33:56 +02:00
|
|
|
prop_mesher.base_light_value = 0.45
|
|
|
|
prop_mesher.ao_strength = 0.2
|
|
|
|
prop_mesher.uv_margin = Rect2(0.017, 0.017, 1 - 0.034, 1 - 0.034)
|
|
|
|
prop_mesher.voxel_scale = voxel_scale
|
|
|
|
prop_mesher.build_flags = build_flags
|
2020-10-01 13:47:58 +02:00
|
|
|
prop_mesher.texture_scale = 3
|
2020-07-06 22:33:56 +02:00
|
|
|
|
2020-10-06 00:09:25 +02:00
|
|
|
pj.set_prop_mesher(prop_mesher);
|
2020-08-21 20:18:16 +02:00
|
|
|
|
2020-01-13 00:43:45 +01:00
|
|
|
var mesher : TVVoxelMesher = TVVoxelMesher.new()
|
2019-11-20 14:37:34 +01:00
|
|
|
mesher.base_light_value = 0.45
|
|
|
|
mesher.ao_strength = 0.2
|
|
|
|
mesher.uv_margin = Rect2(0.017, 0.017, 1 - 0.034, 1 - 0.034)
|
2020-03-12 23:26:19 +01:00
|
|
|
mesher.voxel_scale = voxel_scale
|
2020-04-06 14:40:14 +02:00
|
|
|
mesher.build_flags = build_flags
|
2020-10-01 13:47:58 +02:00
|
|
|
mesher.texture_scale = 3
|
2020-08-21 20:18:16 +02:00
|
|
|
mesher.channel_index_type = VoxelChunkDefault.DEFAULT_CHANNEL_TYPE
|
|
|
|
mesher.channel_index_isolevel = VoxelChunkDefault.DEFAULT_CHANNEL_ISOLEVEL
|
2020-10-06 00:09:25 +02:00
|
|
|
tj.add_mesher(mesher)
|
|
|
|
|
|
|
|
|
2020-08-26 00:20:35 +02:00
|
|
|
var cmesher : VoxelMesherBlocky = VoxelMesherBlocky.new()
|
|
|
|
cmesher.texture_scale = 3
|
2020-08-21 20:18:16 +02:00
|
|
|
cmesher.base_light_value = 0.45
|
|
|
|
cmesher.ao_strength = 0.2
|
|
|
|
cmesher.voxel_scale = voxel_scale
|
|
|
|
cmesher.build_flags = build_flags
|
2020-10-06 00:09:25 +02:00
|
|
|
|
2020-08-26 00:20:35 +02:00
|
|
|
if cmesher.build_flags & VoxelChunkDefault.BUILD_FLAG_USE_LIGHTING != 0:
|
|
|
|
cmesher.build_flags = cmesher.build_flags ^ VoxelChunkDefault.BUILD_FLAG_USE_LIGHTING
|
2020-10-06 00:09:25 +02:00
|
|
|
|
2020-08-26 00:20:35 +02:00
|
|
|
cmesher.always_add_colors = true
|
2020-10-06 00:09:25 +02:00
|
|
|
|
2020-08-26 00:20:35 +02:00
|
|
|
# cmesher.channel_index_type = VoxelChunkDefault.DEFAULT_CHANNEL_TYPE
|
2020-08-21 20:18:16 +02:00
|
|
|
cmesher.channel_index_type = VoxelChunkDefault.DEFAULT_CHANNEL_ALT_TYPE
|
2020-10-06 00:09:25 +02:00
|
|
|
tj.add_mesher(cmesher)
|
|
|
|
|
2019-11-20 14:37:34 +01:00
|
|
|
_prop_texture_packer = TexturePacker.new()
|
|
|
|
_prop_texture_packer.max_atlas_size = 1024
|
|
|
|
_prop_texture_packer.margin = 1
|
|
|
|
_prop_texture_packer.background_color = Color(0, 0, 0, 1)
|
|
|
|
_prop_texture_packer.texture_flags = Texture.FLAG_MIPMAPS
|
2020-10-06 00:09:25 +02:00
|
|
|
|
2020-10-06 19:26:13 +02:00
|
|
|
add_job(lj)
|
|
|
|
add_job(tj)
|
|
|
|
add_job(pj)
|
2020-06-23 20:58:14 +02:00
|
|
|
|
2020-04-05 02:27:39 +02:00
|
|
|
#func _build_phase(phase):
|
|
|
|
# if phase == VoxelChunkDefault.BUILD_PHASE_SETUP:
|
|
|
|
# ._build_phase(phase)
|
|
|
|
#
|
|
|
|
# elif phase == VoxelChunkDefault.BUILD_PHASE_LIGHTS:
|
|
|
|
# clear_baked_lights()
|
|
|
|
# generate_random_ao(123)
|
|
|
|
# bake_lights()
|
|
|
|
#
|
|
|
|
# next_phase()
|
2020-04-04 17:29:23 +02:00
|
|
|
|
2020-03-06 21:32:52 +01:00
|
|
|
#set_physics_process_internal(true)
|
2020-04-04 17:29:23 +02:00
|
|
|
# active_build_phase_type = VoxelChunkDefault.BUILD_PHASE_TYPE_PHYSICS_PROCESS
|
2020-04-05 02:27:39 +02:00
|
|
|
# return
|
2020-03-30 19:48:41 +02:00
|
|
|
# elif phase == VoxelChunkDefault.BUILD_PHASE_TERRARIN_MESH:
|
|
|
|
# for i in range(get_mesher_count()):
|
|
|
|
# var mesher : VoxelMesher = get_mesher(i)
|
|
|
|
# mesher.bake_colors(self)
|
2020-03-30 01:22:25 +02:00
|
|
|
#
|
2020-03-30 19:48:41 +02:00
|
|
|
# for i in range(get_mesher_count()):
|
|
|
|
# var mesher : VoxelMesher = get_mesher(i)
|
|
|
|
# mesher.set_library(library)
|
|
|
|
#
|
|
|
|
# var mesh_rid : RID = get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 0)
|
|
|
|
#
|
|
|
|
# if mesh_rid == RID():
|
|
|
|
# create_meshes(MESH_INDEX_TERRARIN, lod_num + 1)
|
|
|
|
# mesh_rid = get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 0)
|
|
|
|
#
|
|
|
|
# var mesher : VoxelMesher = null
|
|
|
|
# for i in range(get_mesher_count()):
|
|
|
|
# var m : VoxelMesher = get_mesher(i)
|
|
|
|
#
|
|
|
|
# if mesher == null:
|
|
|
|
# mesher = m
|
|
|
|
# continue
|
|
|
|
#
|
|
|
|
# mesher.set_material(library.material)
|
|
|
|
# mesher.add_mesher(m)
|
|
|
|
#
|
|
|
|
# if (mesh_rid != RID()):
|
|
|
|
# VisualServer.mesh_clear(mesh_rid)
|
|
|
|
#
|
|
|
|
# if mesher.get_vertex_count() == 0:
|
|
|
|
# next_phase()
|
|
|
|
# return true
|
|
|
|
#
|
|
|
|
# if (mesh_rid == RID()):
|
|
|
|
# create_meshes(MESH_INDEX_TERRARIN, lod_num + 1)
|
|
|
|
# mesh_rid = get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 0)
|
|
|
|
#
|
|
|
|
# var arr : Array = mesher.build_mesh()
|
|
|
|
#
|
|
|
|
# VisualServer.mesh_add_surface_from_arrays(mesh_rid, VisualServer.PRIMITIVE_TRIANGLES, arr)
|
|
|
|
#
|
|
|
|
# if library.get_material(0) != null:
|
|
|
|
# VisualServer.mesh_surface_set_material(mesh_rid, 0, library.get_material(0).get_rid())
|
|
|
|
#
|
|
|
|
## VisualServer.instance_set_visible(get_mesh_instance_rid(), false)
|
|
|
|
#
|
|
|
|
# if generate_lod and lod_num >= 1:
|
|
|
|
# #for lod 1 just remove uv2
|
|
|
|
#
|
|
|
|
# arr[VisualServer.ARRAY_TEX_UV2] = null
|
|
|
|
#
|
|
|
|
# VisualServer.mesh_add_surface_from_arrays(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 1), VisualServer.PRIMITIVE_TRIANGLES, arr)
|
|
|
|
#
|
|
|
|
# if library.get_material(1) != null:
|
|
|
|
# VisualServer.mesh_surface_set_material(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 1), 0, library.get_material(1).get_rid())
|
|
|
|
#
|
|
|
|
# if lod_num >= 2:
|
|
|
|
# arr = merge_mesh_array(arr)
|
|
|
|
#
|
|
|
|
# VisualServer.mesh_add_surface_from_arrays(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 2), VisualServer.PRIMITIVE_TRIANGLES, arr)
|
|
|
|
#
|
|
|
|
# if library.get_material(2) != null:
|
|
|
|
# VisualServer.mesh_surface_set_material(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 2), 0, library.get_material(2).get_rid())
|
|
|
|
#
|
|
|
|
# if lod_num >= 3:
|
|
|
|
# var mat : ShaderMaterial = library.get_material(0) as ShaderMaterial
|
|
|
|
# var tex : Texture = mat.get_shader_param("texture_albedo")
|
|
|
|
#
|
|
|
|
# arr = bake_mesh_array_uv(arr, tex)
|
|
|
|
# arr[VisualServer.ARRAY_TEX_UV] = null
|
|
|
|
#
|
|
|
|
# VisualServer.mesh_add_surface_from_arrays(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 3), VisualServer.PRIMITIVE_TRIANGLES, arr)
|
|
|
|
#
|
|
|
|
# if library.get_material(3) != null:
|
|
|
|
# VisualServer.mesh_surface_set_material(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 3), 0, library.get_material(3).get_rid())
|
|
|
|
## if lod_num > 4:
|
|
|
|
## var fqms : FastQuadraticMeshSimplifier = FastQuadraticMeshSimplifier.new()
|
|
|
|
## fqms.initialize(merged)
|
|
|
|
##
|
|
|
|
## var arr_merged_simplified : Array = merged
|
|
|
|
#
|
|
|
|
## for i in range(2, _lod_meshes.size()):
|
|
|
|
## fqms.simplify_mesh(arr_merged_simplified[0].size() * 0.8, 7)
|
|
|
|
## arr_merged_simplified = fqms.get_arrays()
|
|
|
|
#
|
|
|
|
## if arr_merged_simplified[0].size() == 0:
|
|
|
|
## break
|
|
|
|
#
|
|
|
|
## VisualServer.mesh_add_surface_from_arrays(_lod_meshes[i], VisualServer.PRIMITIVE_TRIANGLES, arr_merged_simplified)
|
|
|
|
#
|
|
|
|
## if library.get_material(i) != null:
|
|
|
|
## VisualServer.mesh_surface_set_material(_lod_meshes[i], 0, library.get_material(i).get_rid())
|
|
|
|
#
|
|
|
|
# next_phase();
|
|
|
|
#
|
|
|
|
# return
|
2020-04-05 02:27:39 +02:00
|
|
|
# else:
|
|
|
|
# ._build_phase(phase)
|
2019-11-20 14:37:34 +01:00
|
|
|
|
2020-07-06 22:33:56 +02:00
|
|
|
#func _build_phase(phase):
|
|
|
|
# if phase == VoxelChunkDefault.BUILD_PHASE_COLLIDER:
|
|
|
|
# active_build_phase_type = VoxelChunkDefault.BUILD_PHASE_TYPE_PHYSICS_PROCESS
|
|
|
|
# return
|
|
|
|
# elif phase == VoxelChunkDefault.BUILD_PHASE_PROP_MESH:
|
|
|
|
# next_phase()
|
|
|
|
# return
|
|
|
|
#
|
|
|
|
# ._build_phase(phase)
|
2020-06-23 20:58:14 +02:00
|
|
|
|
|
|
|
|
2020-07-06 22:33:56 +02:00
|
|
|
#func _build_phase_physics_process(phase):
|
|
|
|
# if phase == VoxelChunkDefault.BUILD_PHASE_PROP_SETUP:
|
|
|
|
## add_prop(ResourceLoader.load("res://prop_tool/ToolTes2at.tres"))
|
|
|
|
# build_phase_prop_mesh()
|
|
|
|
# active_build_phase_type = VoxelChunkDefault.BUILD_PHASE_TYPE_NORMAL
|
|
|
|
# next_phase()
|
|
|
|
# return
|
|
|
|
#
|
|
|
|
# ._build_phase_physics_process(phase)
|
|
|
|
#
|