Skip to content

Commit 063480e

Browse files
authored
Patch/v2.2.2 (#68)
* VMT context menu: Fix VTF generation * VMF: Fix displacements processing * Bump: v2.2.2
1 parent ffff3a7 commit 063480e

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

addons/godotvmf/godotvmt/vmt_loader.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +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] = [];
6+
static var logged_materials: Array = [];
77

88
static func is_file_valid(path: String):
99
var import_path = path + ".import";

addons/godotvmf/src/vmf_material_conversion_context_menu.gd renamed to addons/godotvmf/godotvmt/vmt_material_conversion_context_menu.gd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func generate_vtf_file(texture: Texture2D) -> PackedByteArray:
9797
if not is_dxt:
9898
image.decompress();
9999
image.compress(Image.COMPRESS_S3TC);
100-
image.convert(Image.FORMAT_DXT3);
100+
image.convert(Image.FORMAT_DXT5);
101101

102102
image.clear_mipmaps();
103103

@@ -106,12 +106,12 @@ func generate_vtf_file(texture: Texture2D) -> PackedByteArray:
106106

107107
bytes += int_to_int32(7); # version major
108108
bytes += int_to_int32(1); # version minor
109-
bytes += int_to_int32(63); # header size for version 7.1
109+
bytes += int_to_int32(64); # header size for version 7.1
110110

111111
bytes += int_to_short(image.get_width()); # width
112112
bytes += int_to_short(image.get_height()); # height
113113

114-
bytes += int_to_int32(VTFLoader.Flags.TEXTUREFLAGS_NOMIP); # flags
114+
bytes += int_to_int32(VTFLoader.Flags.TEXTUREFLAGS_SRGB | VTFLoader.Flags.TEXTUREFLAGS_NOMIP);
115115
bytes += int_to_short(1); # frames
116116
bytes += int_to_short(0); # first frame
117117
bytes += PackedByteArray([0, 0, 0, 0]); # padding
@@ -130,6 +130,7 @@ func generate_vtf_file(texture: Texture2D) -> PackedByteArray:
130130
bytes += int_to_int32(format); # high res image format
131131
bytes += int_to_byte(1) # mipmap count
132132
bytes += int_to_int32(13) # low res image format
133+
bytes += PackedByteArray([0]); # padding
133134

134135
var lowres_image := image.duplicate() as Image;
135136
var lowres_width := 16;

addons/godotvmf/godotvmt/vtf_loader.gd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ enum Flags
3838
TEXTUREFLAGS_CLAMPT = 0x00000008,
3939
TEXTUREFLAGS_ANISOTROPIC = 0x00000010,
4040
TEXTUREFLAGS_HINT_DXT5 = 0x00000020,
41-
TEXTUREFLAGS_PWL_CORRECTED = 0x00000040,
41+
TEXTUREFLAGS_SRGB = 0x00000040,
4242
TEXTUREFLAGS_NORMAL = 0x00000080,
4343
TEXTUREFLAGS_NOMIP = 0x00000100,
4444
TEXTUREFLAGS_NOLOD = 0x00000200,
@@ -266,6 +266,7 @@ func _init(path, duration):
266266
self.frame_duration = duration;
267267

268268
file = FileAccess.open(path, FileAccess.READ);
269+
prints('VTFFLAGS', flags);
269270

270271
static func get_texture(texture: String):
271272
texture = texture.to_lower();

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.1"
6+
version="2.2.2"
77
script="godotvmf.gd"

addons/godotvmf/src/structs/vmf_displacement_info.gd

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var start_point := Vector3(0, 0, 0);
1313
var side: VMFSide;
1414
var brush: VMFSolid;
1515
var vertices: PackedVector3Array;
16+
var elevation: float = 0.0;
1617

1718
func _to_string() -> String:
1819
return "VMFDisplacementInfo(verts_count=%d, edges_count=%d, start_point=%s, side_id=%d, brush_id=%d)" % [verts_count, edges_count, start_point, side.id, brush.id];
@@ -35,9 +36,13 @@ func _init(raw: Dictionary, side: VMFSide, brush: VMFSolid) -> void:
3536
offsets = _parse_vectors('offsets');
3637
offset_normals = _parse_vectors('offset_normals');
3738
alphas = _parse_floats('alphas');
38-
vertices = PackedVector3Array(get_vertices());
39+
elevation = float(raw.get('elevation', 0.0));
3940
disp_info = null;
4041

42+
## Called from the VMFSide during the calculation of its vertices.
43+
func calculate_vertices() -> void:
44+
vertices = PackedVector3Array(get_vertices());
45+
4146
func get_normal(x: float, y: float) -> Vector3:
4247
var index = y + x * verts_count;
4348
if normals.size() == 0:
@@ -96,7 +101,7 @@ func get_vertices() -> Array[Vector3]:
96101
var vr := tr.lerp(br, rblend);
97102
var vert := vl.lerp(vr, cblend);
98103

99-
vert += get_distance(x, y) + get_offset(x, y) + side.plane.normal * disp_info.elevation;
104+
vert += get_distance(x, y) + get_offset(x, y) + side.plane.normal * elevation;
100105

101106
res.append(vert);
102107

addons/godotvmf/src/structs/vmf_side.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ func calculate_vertices() -> void:
7575

7676
vertices = PackedVector3Array(raw_vertices);
7777

78+
if is_displacement:
79+
dispinfo.calculate_vertices();
80+
7881
## Retrns the UV coordinates for the given vertex on this side
7982
func get_uv(vertex: Vector3) -> Vector2:
8083
var uscale: float = uaxis.scale;

0 commit comments

Comments
 (0)