How to Import **SHP File (TS) ** in Godot ? I Want Make SoftWare to Process Image With .shp file

Question

How to Import SHP File in Godot ?

Godot Version

4.5.stable

Hello , I want make new SHP&PAL tool , But I encountered a little difficulty and need help.
The problem of data import has been bothering me for three or four days , I have to seek help.
Current situation is:

  • PIC is load ok , but hasn’t begun to do image processing , like scale crop etc…
  • SHP File has problem to read.Read FileHead is OK.
  • Pal File is easy to load , but color remap is used gdshader file.
    gdshader creater is pYMxlobo/256-shader.

When I Use The Godot to Read .shp File (Westwood SHP Format TS)
Then I have someproblem with DataType.

I already successful to read the Image with :
EveryFrame’s_offset_pos // EveryFrame’s_length and width // anime_frame_size

head= [ 0 , 78 , 66 , 744 ]
frame_num : 1 frame_offset = vec2( 32 , 7 ) frame_size = ve2( 13 , 29 )

There is my GDScript :

This website is .shp file type infomation.

But I don’t know How to Convert the other type var with godot to read correct.

:: split ::

If you have any way to fix this , to make things easy. I will thanks for your help. ofcause, you can goto my github site,to find this project to download this project, and help me please.

Finally, Thanks For Your Help.

statement: I don’t use any other languageScript , Because I really to want to use 100%GDScript to finish my work.

You don’t need to convert the data to a string and then read it back. You can just use the FileAccess API directly by opening the file with FileAccess.open() to read the data from it.

You can also use FileAccess.get_file_as_bytes() to get the raw PackedByteArray data and manually manage the read of the bytes using the PackedByteArray API or plug it into a StreamPeerBuffer so you don’t have to deal with advancing the reading cursor manually.

Example using FileAccess and StreamPeerBuffer APIs:

func using_fileaccess() -> void:
	var file = FileAccess.open("res://assets/re1.shp", FileAccess.READ)

	var empty = file.get_16()
	var full_width = file.get_16()
	var full_height = file.get_16()
	var nr_of_frames = file.get_16()

	printt(empty, full_width, full_height, nr_of_frames)

	for i in nr_of_frames:
		var frame_x = file.get_16()
		var frame_y = file.get_16()
		var frame_w = file.get_16()
		var frame_h = file.get_16()
		var flags = file.get_32()
		var frame_color_r = file.get_8()
		var frame_color_g = file.get_8()
		var frame_color_b = file.get_8()
		var frame_color_a = file.get_8()
		var _reserved = file.get_32() # Not used
		var data_offset = file.get_32()
		prints("--- Frame %s" % i, data_offset, "x,y,w,h", frame_x, frame_y, frame_w, frame_h, "flags", flags, "rgba", frame_color_r, frame_color_g, frame_color_b, frame_color_a)


func using_streampeerbuffer() -> void:
	var bytes = FileAccess.get_file_as_bytes("res://assets/re1.shp")

	var stream = StreamPeerBuffer.new()
	stream.data_array = bytes

	var empty = stream.get_u16()
	var full_width = stream.get_u16()
	var full_height = stream.get_u16()
	var nr_of_frames = stream.get_u16()

	printt(empty, full_width, full_height, nr_of_frames)

	for i in nr_of_frames:
		var frame_x = stream.get_u16()
		var frame_y = stream.get_u16()
		var frame_w = stream.get_u16()
		var frame_h = stream.get_u16()
		var flags = stream.get_u32()
		var frame_color_r = stream.get_u8()
		var frame_color_g = stream.get_u8()
		var frame_color_b = stream.get_u8()
		var frame_color_a = stream.get_u8()
		var _reserved = stream.get_u32() #not used
		var data_offset = stream.get_u32()
		prints("--- Frame %s" % i, data_offset, "x,y,w,h", frame_x, frame_y, frame_w, frame_h, "flags", flags, "rgba", frame_color_r, frame_color_g, frame_color_b, frame_color_a)
1 Like

thanks reply , i will edit my code in few moment future.