Code : Tout sélectionner
global $rotate=false
func _FilesplitBytes($file,$max=0)
$filePtr=FileOpen($file,16)
$filesize=$max
local $fileLoad[$filesize+5]
$content=FileRead($filePtr)
$fileload[0]=$filesize
ProgressOn("lecture...","","starting...")
for $i=3 to ($filesize+3)*2 step 2
$pos=($i-3)/2
$fileLoad[$pos+1]=StringMid($content,$i,2)
ProgressSet(int(($pos/$filesize)*100),$pos&" octets lu sur "&$filesize)
next
ProgressOff()
FileClose($filePtr)
return $fileload
EndFunc
func readUint32($data,$pos)
if $rotate=false Then
$return=$data[$pos]
$pos+=1
$return=$return&$data[$pos]
$pos+=1
$return=$return&$data[$pos]
$pos+=1
$return=$return&$data[$pos]
$pos+=1
return "0x"&$return
Else
$pos+=3
$return=$data[$pos]
$pos-=1
$return=$return&$data[$pos]
$pos-=1
$return=$return&$data[$pos]
$pos-=1
$return=$return&$data[$pos]
$pos-=1
return "0x"&$return
EndIf
EndFunc
func readChar($data,$start,$len=1)
$return=""
for $start=$start to $start+$len-1 step 1
$return=$return&chr("0x"&$data[$start])
Next
return $return
EndFunc
func readfloat($data,$pos)
$src = DllStructCreate("byte;byte;byte;byte")
$psrc = DllStructGetPtr($src)
$dest = DllStructCreate("float")
$pdest = DllStructGetPtr($dest)
if $rotate=false Then
DllStructSetData($src, 1, "0x"&$data[$pos])
DllStructSetData($src, 2, "0x"&$data[$pos+1])
DllStructSetData($src, 3, "0x"&$data[$pos+2])
DllStructSetData($src, 4, "0x"&$data[$pos+3])
Else
DllStructSetData($src, 1, "0x"&$data[$pos+3])
DllStructSetData($src, 2, "0x"&$data[$pos+2])
DllStructSetData($src, 3, "0x"&$data[$pos+1])
DllStructSetData($src, 4, "0x"&$data[$pos+0])
EndIf
; Perform the "conversion"
_MemMoveMemory($psrc, $pdest, 4)
return DllStructGetData($dest, 1)
EndFunc
func saveSplit($file,$data)
ProgressOn("sauvegarde...","","starting...")
$fileptr2=FileOpen($file,18)
for $i=1 to $data[0] step 1
if $data[$i]<>"" Then
FileWrite($fileptr2,"0x"&$data[$i])
Else
FileWrite($fileptr2,"0x"&"00")
EndIf
ProgressSet(int(($i/$data[0])*100),$i&" sur "&$data[0]&" octets sauvegardé")
Next
EndFunc
func writefloat($data,$float,$pos)
$src = DllStructCreate("byte;byte;byte;byte")
$psrc = DllStructGetPtr($src)
$dest = DllStructCreate("float")
$pdest = DllStructGetPtr($dest)
DllStructSetData($dest, 1, $float)
_MemMoveMemory($pdest, $psrc, 4)
if $rotate=false Then
$data[$pos]= stringmid(hex(DllStructGetData($src, 1)),7,2)
$data[$pos+1]= stringmid(hex(DllStructGetData($src, 2)),7,2)
$data[$pos+2]= stringmid(hex(DllStructGetData($src, 3)),7,2)
$data[$pos+3]= stringmid(hex(DllStructGetData($src, 4)),7,2)
Else
$data[$pos+3]= stringmid(hex(DllStructGetData($src, 1)),7,2)
$data[$pos+2]= stringmid(hex(DllStructGetData($src, 2)),7,2)
$data[$pos+1]= stringmid(hex(DllStructGetData($src, 3)),7,2)
$data[$pos]= stringmid(hex(DllStructGetData($src, 4)),7,2)
EndIf
return $data
EndFunc
func writeUint32($data,$uint32,$pos)
$uint32=hex($uint32)
if $rotate=false Then
$data[$pos]= StringMid($uint32,0,2)
$data[$pos+1]= StringMid($uint32,3,2)
$data[$pos+2]= StringMid($uint32,5,2)
$data[$pos+3]= StringMid($uint32,7,2)
Else
$data[$pos+3]= StringMid($uint32,0,2)
$data[$pos+2]= StringMid($uint32,3,2)
$data[$pos+1]= StringMid($uint32,5,2)
$data[$pos]= StringMid($uint32,7,2)
EndIf
return $data
EndFunc
func writechar($data,$char,$start,$len)
$charpos=1
for $i=$start to $start+$len-1 step 1
$data[$i]=stringmid(hex(asc(stringmid($char,$charpos,1))),7,2)
$charpos+=1
next
return $data
EndFunc
func _isM2($data)
if readchar($data,1,4)="MD20" then
return True
Else
return False
EndIf
EndFunc
func _getModelName($data)
$rotate=True
return readChar($data,readUint32($data,0x00C+1),readUint32($data,0x008+1))
EndFunc
func _getmodelvertices($data)
$count=0
$rotate=true
$len=readUint32($data,0x03C+1)*48+readUint32($data,0x040+1)
$len2=readUint32($data,0x03C+1)
$name=FileOpen("C:\result.g3w",2)
FileWrite($name,"Figure Géospace"&@crlf&"Numéro de version: 1"&@crlf&@crlf&"Uxyz par rapport à la petite dimension de la fenêtre: 0.1"&@crlf&"Rotations de Rxyz: verticale: 0 horizontale: 0 frontale: 0"&@crlf&"Repère Rxyz affiché"&@crlf)
ProgressOn("lecture...","","starting...")
for $i=readUint32($data,0x040+1) to $len-48 step 48
$rotate=False
$X=readfloat($data,$i+1)
$Z=(-1*readfloat($data,$i+5))
$Y=readfloat($data,$i+9)
FileWrite($name, @crlf&"A"&$count&" point libre dans l'espace"&@crlf&" Objet libre A"&$count&", paramètres: "&$X&", "&$Y&", "&$Z)
$count+=1
progressset(($i/$len)*100,$count&" sommets lu dans le tableau sur "&dec($len2))
Next
FileWrite($name,@crlf&@crlf&"Fin de la figure")
FileClose($name)
EndFunc
func savebinnaryInCsv($data,$name)
$hwnd=FileOpen($name&".csv",2)
for $i=1 to $data[0] step 1
FileWrite($hwnd,$data[$i]&";")
Next
EndFunc
func readbinnaryOfCsv($file);utilisé pour tester plus rapidement a cause de la lenteur de la fonction d'ouverture
return stringsplit(FileRead($file),";")
EndFunc