Skip to content

Commit ffff3a7

Browse files
authored
VMFNode: add optimized option (#67)
1 parent 9d4752b commit ffff3a7

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

addons/godotvmf/godotvmt/vmt_loader.gd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class_name VMTLoader extends RefCounted
33

44
static var texture_sizes_cache: Dictionary = {};
55
static var cached_materials: Dictionary = {};
6+
static var logged_materials: Array[String] = [];
67

78
static func is_file_valid(path: String):
89
var import_path = path + ".import";
@@ -94,6 +95,7 @@ static func normalize_path(path: String) -> String:
9495
static func clear_cache():
9596
cached_materials = {};
9697
texture_sizes_cache = {};
98+
logged_materials = [];
9799

98100
static func has_material(material: String) -> bool:
99101
var material_path = normalize_path(VMFConfig.materials.target_folder + "/" + material + ".tres").to_lower();
@@ -108,6 +110,7 @@ static func has_material(material: String) -> bool:
108110

109111
static func get_material(material: String):
110112
cached_materials = cached_materials if cached_materials else {};
113+
logged_materials = logged_materials if logged_materials else [];
111114

112115
if material in cached_materials:
113116
return cached_materials[material];
@@ -118,7 +121,10 @@ static func get_material(material: String):
118121
material_path = material_path.replace(".tres", ".vmt");
119122

120123
if not ResourceLoader.exists(material_path):
121-
VMFLogger.warn("Material not found: " + material_path);
124+
if not logged_materials.has(material_path):
125+
VMFLogger.warn("Material not found: " + material_path);
126+
logged_materials.append(material_path);
127+
122128
material_path = VMFConfig.materials.fallback_material
123129

124130
if not material_path or not ResourceLoader.exists(material_path): return null;

addons/godotvmf/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="GodotVMF"
44
description="Allows use VMF files in Godot"
55
author="H2xDev"
6-
version="2.2.0"
6+
version="2.2.1"
77
script="godotvmf.gd"

addons/godotvmf/src/vmf_node.gd

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@ var vmf: String = '';
3030

3131
@export_category("Resource Generation")
3232

33-
## Save the resulting geometry mesh as a resource (saves to the geometryFolder in vmf.config.json)
33+
## During import the importer will remove all invisible faces from the mesh.
34+
## Increases the import time
35+
@export var remove_merged_faces: bool = true;
36+
37+
## Save the resulting geometry mesh as a resource (saves to the "Geometry folder" in Project Settings)
3438
@export var save_geometry: bool = true;
3539

36-
## Save the resulting collision shape as a resource (saves to the geometryFolder in vmf.config.json)
40+
## Save the resulting collision shape as a resource (saves to the "Geometry folder" in Project Settings)
3741
@export var save_collision: bool = true;
3842

3943
## Set this to true before import if you're goint to use this node in runtime
40-
var is_runtime = false;
44+
var is_runtime: bool = false;
4145

4246
var vmf_structure: VMFStructure;
4347

@@ -87,7 +91,7 @@ func import_geometry() -> void:
8791
if navmesh: navmesh.free();
8892
if geometry: geometry.free();
8993

90-
var mesh: ArrayMesh = VMFTool.create_mesh(vmf_structure);
94+
var mesh: ArrayMesh = VMFTool.create_mesh(vmf_structure, Vector3.ZERO, remove_merged_faces);
9195
if not mesh: return;
9296

9397
var geometry_mesh := MeshInstance3D.new()

addons/godotvmf/src/vmf_tool.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static func remove_merged_faces(brush_a: VMFSolid, brushes: Array[VMFSolid]) ->
166166

167167

168168
## Returns MeshInstance3D from parsed VMF structure
169-
static func create_mesh(vmf_structure: VMFStructure, offset: Vector3 = Vector3(0, 0, 0)) -> ArrayMesh:
169+
static func create_mesh(vmf_structure: VMFStructure, offset: Vector3 = Vector3.ZERO, optimized: bool = true) -> ArrayMesh:
170170
clear_caches();
171171
var import_scale := VMFConfig.import.scale;
172172

@@ -178,7 +178,7 @@ static func create_mesh(vmf_structure: VMFStructure, offset: Vector3 = Vector3(0
178178
var mesh := ArrayMesh.new();
179179

180180
for brush in brushes:
181-
remove_merged_faces(brush, brushes);
181+
if optimized: remove_merged_faces(brush, brushes);
182182

183183
for side: VMFSide in brush.sides:
184184
var material: String = side.material.to_upper();
@@ -271,7 +271,7 @@ static func create_mesh(vmf_structure: VMFStructure, offset: Vector3 = Vector3(0
271271
var material = VMTLoader.get_material(sides[0].material);
272272
if material: sf.set_material(material);
273273

274-
sf.optimize_indices_for_cache();
274+
if optimized: sf.optimize_indices_for_cache();
275275
sf.generate_normals();
276276
sf.generate_tangents();
277277
sf.commit(mesh);

0 commit comments

Comments
 (0)