@@ -17,8 +17,7 @@ onready var oColumnEditorVoxelView = Nodelist.list["oColumnEditorVoxelView"]
17
17
onready var oMapProperties = Nodelist .list ["oMapProperties" ]
18
18
19
19
const IMAGE_FORMAT = Image .FORMAT_RGB8
20
- const textureWidth = 256
21
- const textureHeight = 2176
20
+
22
21
enum {
23
22
LOADING_NOT_STARTED
24
23
LOADING_IN_PROGRESS
@@ -45,6 +44,7 @@ func _notification(what: int):
45
44
yield (get_tree (),'idle_frame' )
46
45
oMapProperties ._on_MapProperties_visibility_changed () # Refresh list of styles if it's visible
47
46
47
+
48
48
func _on_ReloadTextureMapsButton_pressed ():
49
49
if texturesLoadedState != LOADING_IN_PROGRESS : # Don't do anything if it's already doing something
50
50
oMessage .quick ("Reloading tilesets" )
@@ -96,6 +96,7 @@ func start():
96
96
if oDataSlab .get_cell (0 ,0 ) != - 1 :
97
97
set_current_texture_pack ()
98
98
99
+
99
100
func scan_dk_data_directory ():
100
101
var path = oGame .DK_DATA_DIRECTORY
101
102
var dictionary = {}
@@ -105,7 +106,7 @@ func scan_dk_data_directory():
105
106
var fileName = dir .get_next ()
106
107
while fileName != "" :
107
108
if dir .current_is_dir () == false :
108
- if fileName .to_upper ().begins_with ("TMAPA " ) == true : # Get file regardless of case (case insensitive)
109
+ if fileName .to_upper ().begins_with ("TMAP " ) == true : # Get file regardless of case (case insensitive)
109
110
if fileName .to_upper ().get_extension () == "DAT" :
110
111
if fileName .to_upper ().begins_with ("TMAPANIM" ) == false :
111
112
var getModifiedTime = File .new ().get_modified_time (path .plus_file (fileName ))
@@ -121,25 +122,33 @@ func convert_tmapa_to_image(tmapaDatPath):
121
122
var file = File .new ()
122
123
if file .open (tmapaDatPath , File .READ ) == OK :
123
124
CODETIME_START = OS .get_ticks_msec ()
125
+ var imageSize = file .get_len () # (Width * Height)
124
126
125
- var img = Image .new ()
126
- img .create (textureWidth , textureHeight , false , IMAGE_FORMAT )
127
- file .seek (0 )
128
- img .lock ()
129
- for y in textureHeight :
130
- for x in textureWidth :
131
- var paletteIndex = file .get_8 ()
132
- img .set_pixel (x ,y ,paletteData [paletteIndex ])
133
- img .unlock ()
134
-
135
- print ('Converted tmapa*.dat to image in: ' + str (OS .get_ticks_msec ()- CODETIME_START )+ 'ms' )
127
+ var dkTextureData = file .get_buffer (imageSize )
136
128
file .close ()
137
129
130
+ var data = PoolByteArray ()
131
+ data .resize (256 * 2176 * 3 )
132
+ data .fill (0 ) # Any space that goes beyond the size of tmapb will be set to black
133
+
134
+ var idx = 0
135
+ for i in imageSize :
136
+ var color = paletteData [dkTextureData [i ]]
137
+ data [idx ] = color .r8
138
+ data [idx + 1 ] = color .g8
139
+ data [idx + 2 ] = color .b8
140
+ idx += 3
141
+
142
+ var img = Image .new ()
143
+ img .create_from_data (256 , 2176 , false , IMAGE_FORMAT , data )
144
+
145
+ print ("Converted " + str (tmapaDatPath .get_file ()) + " to image in: " + str (OS .get_ticks_msec () - CODETIME_START ) + "ms" )
138
146
return img
139
147
else :
140
148
print ("Failed to open file." )
141
149
return null
142
150
151
+
143
152
func save_image_as_png (img , inputPath ):
144
153
var fileName = inputPath .get_file ().get_basename ().to_lower () + ".png"
145
154
@@ -152,57 +161,77 @@ func save_image_as_png(img, inputPath):
152
161
153
162
func load_cache_filename (path ):
154
163
var fileName = path .get_file ().get_basename ().to_lower ()
155
- var cachePath = Settings .unearthdata .plus_file (fileName + ".png" )
164
+
165
+ if (fileName .to_lower ().find ("tmapa" ) == - 1 ):
166
+ return
167
+
168
+ var cachePathtmapa = Settings .unearthdata .plus_file (fileName + ".png" )
169
+ var cachePathtmapb = Settings .unearthdata .plus_file (fileName .replace ("tmapa" ,"tmapb" ) + ".png" )
156
170
var tmapaNumber = int (fileName .to_lower ().trim_prefix ("tmapa" )) # Get the specific position to create within the array
157
-
158
- if File .new ().file_exists (cachePath ) == true :
171
+
172
+ if File .new ().file_exists (cachePathtmapa ) == true :
159
173
# Need to call load() on an Image class if I want the save and load to work correctly (otherwise it saves too fast and doesn't load or something)
160
- var img = Image .new ()
161
- img .load (cachePath )
162
- load_image_into_cache (img , tmapaNumber )
174
+ var imgA = Image .new ()
175
+ imgA .load (cachePathtmapa )
176
+ var imgB = Image .new ()
177
+ imgB .load (cachePathtmapb )
178
+ load_image_into_cache (imgA , imgB , tmapaNumber )
163
179
# print('Loaded cache file: ' + cachePath)
164
180
return OK
165
181
else :
166
- print ('Cache file not found: ' + cachePath )
182
+ print ('Cache file not found: ' + cachePathtmapa )
167
183
cachedTextures .clear ()
168
184
return FAILED
169
185
170
- func load_image_into_cache (img , tmapaNumber ):
186
+
187
+ func load_image_into_cache (imgA , imgB , tmapaNumber ):
171
188
tmapaNumber = int (tmapaNumber )
172
189
while cachedTextures .size () <= tmapaNumber : # Fill all array positions, in case a tmapa00#.dat file inbetween is deleted
173
190
cachedTextures .append ([null , null ])
174
- cachedTextures [tmapaNumber ] = convert_img_to_two_texture_arrays (img )
191
+ cachedTextures [tmapaNumber ] = convert_img_to_two_texture_arrays (imgA ,imgB )
192
+
175
193
176
194
# SLICE COUNT being too high is the reason TextureArray doesn't work on old PC. (NOT IMAGE SIZE, NOT MIPMAPS EITHER)
177
195
# RES files might actually take longer to generate a TextureArray from than PNG, not sure.
178
- func convert_img_to_two_texture_arrays (img ):
179
- if img .get_format () != IMAGE_FORMAT :
180
- img .convert (IMAGE_FORMAT )
181
-
196
+ func convert_img_to_two_texture_arrays (imgA ,imgB ):
197
+ if imgA .get_format () != IMAGE_FORMAT :
198
+ imgA .convert (IMAGE_FORMAT )
199
+ if imgB .get_format () != IMAGE_FORMAT :
200
+ imgB .convert (IMAGE_FORMAT )
201
+
182
202
var twoTextureArrays = [
183
203
TextureArray .new (),
184
204
TextureArray .new (),
205
+ TextureArray .new (),
206
+ TextureArray .new (),
185
207
]
186
208
var xSlices = 8
187
209
var ySlices = 34
188
210
var sliceWidth = 32 # img.get_width() / xSlices;
189
211
var sliceHeight = 32 # img.get_height() / ySlices;
190
212
twoTextureArrays [0 ].create (sliceWidth , sliceHeight , xSlices * ySlices , IMAGE_FORMAT , TextureLayered .FLAG_MIPMAPS + TextureLayered .FLAG_ANISOTROPIC_FILTER )
191
213
twoTextureArrays [1 ].create (sliceWidth , sliceHeight , xSlices * ySlices , IMAGE_FORMAT , TextureLayered .FLAG_MIPMAPS + TextureLayered .FLAG_ANISOTROPIC_FILTER )
214
+ twoTextureArrays [2 ].create (sliceWidth , sliceHeight , xSlices * ySlices , IMAGE_FORMAT , TextureLayered .FLAG_MIPMAPS + TextureLayered .FLAG_ANISOTROPIC_FILTER )
215
+ twoTextureArrays [3 ].create (sliceWidth , sliceHeight , xSlices * ySlices , IMAGE_FORMAT , TextureLayered .FLAG_MIPMAPS + TextureLayered .FLAG_ANISOTROPIC_FILTER )
192
216
193
- for i in 2 :
217
+ for i in 4 :
194
218
var yOffset = 0
195
- if i == 1 :
219
+ if i == 1 or i == 3 :
196
220
yOffset = 34
197
221
198
222
for y in ySlices :
199
223
for x in xSlices :
200
- var slice = img .get_rect (Rect2 (x * sliceWidth , (y + yOffset )* sliceHeight , sliceWidth , sliceHeight ))
224
+ var slice
225
+ if i < 2 :
226
+ slice = imgA .get_rect (Rect2 (x * sliceWidth , (y + yOffset )* sliceHeight , sliceWidth , sliceHeight ))
227
+ else :
228
+ slice = imgB .get_rect (Rect2 (x * sliceWidth , (y + yOffset )* sliceHeight , sliceWidth , sliceHeight ))
201
229
slice .generate_mipmaps () # Important otherwise it's black when zoomed out
202
230
twoTextureArrays [i ].set_layer_data (slice , (y * xSlices )+ x )
203
231
204
232
return twoTextureArrays
205
233
234
+
206
235
func set_current_texture_pack ():
207
236
var value = oDataLevelStyle .data
208
237
@@ -215,29 +244,39 @@ func set_current_texture_pack():
215
244
216
245
# 2D
217
246
if oOverheadGraphics .arrayOfColorRects .size () > 0 :
218
- oOverheadGraphics .arrayOfColorRects [0 ].get_material ().set_shader_param ("dkTextureMap_Split_A" , cachedTextures [value ][0 ])
219
- oOverheadGraphics .arrayOfColorRects [0 ].get_material ().set_shader_param ("dkTextureMap_Split_B" , cachedTextures [value ][1 ])
247
+ oOverheadGraphics .arrayOfColorRects [0 ].get_material ().set_shader_param ("dkTextureMap_Split_A1" , cachedTextures [value ][0 ])
248
+ oOverheadGraphics .arrayOfColorRects [0 ].get_material ().set_shader_param ("dkTextureMap_Split_A2" , cachedTextures [value ][1 ])
249
+ oOverheadGraphics .arrayOfColorRects [0 ].get_material ().set_shader_param ("dkTextureMap_Split_B1" , cachedTextures [value ][2 ])
250
+ oOverheadGraphics .arrayOfColorRects [0 ].get_material ().set_shader_param ("dkTextureMap_Split_B2" , cachedTextures [value ][3 ])
220
251
221
252
# 3D
222
253
if oGame3D .materialArray .size () > 0 :
223
- oGame3D .materialArray [0 ].set_shader_param ("dkTextureMap_Split_A" , cachedTextures [value ][0 ])
224
- oGame3D .materialArray [0 ].set_shader_param ("dkTextureMap_Split_B" , cachedTextures [value ][1 ])
254
+ oGame3D .materialArray [0 ].set_shader_param ("dkTextureMap_Split_A1" , cachedTextures [value ][0 ])
255
+ oGame3D .materialArray [0 ].set_shader_param ("dkTextureMap_Split_A2" , cachedTextures [value ][1 ])
256
+ oGame3D .materialArray [0 ].set_shader_param ("dkTextureMap_Split_B1" , cachedTextures [value ][2 ])
257
+ oGame3D .materialArray [0 ].set_shader_param ("dkTextureMap_Split_B2" , cachedTextures [value ][3 ])
225
258
226
259
for nodeID in get_tree ().get_nodes_in_group ("VoxelViewer" ):
227
260
if nodeID .oAllVoxelObjects .mesh != null :
228
- nodeID .oAllVoxelObjects .mesh .surface_get_material (0 ).set_shader_param ("dkTextureMap_Split_A" , cachedTextures [value ][0 ])
229
- nodeID .oAllVoxelObjects .mesh .surface_get_material (0 ).set_shader_param ("dkTextureMap_Split_B" , cachedTextures [value ][1 ])
261
+ nodeID .oAllVoxelObjects .mesh .surface_get_material (0 ).set_shader_param ("dkTextureMap_Split_A1" , cachedTextures [value ][0 ])
262
+ nodeID .oAllVoxelObjects .mesh .surface_get_material (0 ).set_shader_param ("dkTextureMap_Split_A2" , cachedTextures [value ][1 ])
263
+ nodeID .oAllVoxelObjects .mesh .surface_get_material (0 ).set_shader_param ("dkTextureMap_Split_B1" , cachedTextures [value ][2 ])
264
+ nodeID .oAllVoxelObjects .mesh .surface_get_material (0 ).set_shader_param ("dkTextureMap_Split_B2" , cachedTextures [value ][3 ])
230
265
if nodeID .oSelectedVoxelObject .mesh != null :
231
- nodeID .oSelectedVoxelObject .mesh .surface_get_material (0 ).set_shader_param ("dkTextureMap_Split_A" , cachedTextures [value ][0 ])
232
- nodeID .oSelectedVoxelObject .mesh .surface_get_material (0 ).set_shader_param ("dkTextureMap_Split_B" , cachedTextures [value ][1 ])
266
+ nodeID .oSelectedVoxelObject .mesh .surface_get_material (0 ).set_shader_param ("dkTextureMap_Split_A1" , cachedTextures [value ][0 ])
267
+ nodeID .oSelectedVoxelObject .mesh .surface_get_material (0 ).set_shader_param ("dkTextureMap_Split_A2" , cachedTextures [value ][1 ])
268
+ nodeID .oSelectedVoxelObject .mesh .surface_get_material (0 ).set_shader_param ("dkTextureMap_Split_B1" , cachedTextures [value ][2 ])
269
+ nodeID .oSelectedVoxelObject .mesh .surface_get_material (0 ).set_shader_param ("dkTextureMap_Split_B2" , cachedTextures [value ][3 ])
233
270
234
271
assign_textures_to_slab_window (value )
235
272
236
273
237
274
func assign_textures_to_slab_window (value ): # Called by SlabStyleWindow
238
275
for nodeID in get_tree ().get_nodes_in_group ("SlabDisplay" ):
239
- nodeID .get_material ().set_shader_param ("dkTextureMap_Split_A" , cachedTextures [value ][0 ])
240
- nodeID .get_material ().set_shader_param ("dkTextureMap_Split_B" , cachedTextures [value ][1 ])
276
+ nodeID .get_material ().set_shader_param ("dkTextureMap_Split_A1" , cachedTextures [value ][0 ])
277
+ nodeID .get_material ().set_shader_param ("dkTextureMap_Split_A2" , cachedTextures [value ][1 ])
278
+ nodeID .get_material ().set_shader_param ("dkTextureMap_Split_B1" , cachedTextures [value ][2 ])
279
+ nodeID .get_material ().set_shader_param ("dkTextureMap_Split_B2" , cachedTextures [value ][3 ])
241
280
242
281
243
282
0 commit comments