Routine de chargement des Objets "LWO" (LightWave Objet)

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
GallyHC
Messages : 1703
Inscription : lun. 17/déc./2007 12:44

Routine de chargement des Objets "LWO" (LightWave Objet)

Message par GallyHC »

Bonjour,

Voila une petite routine qui permet de chargement des objets lightwave. Cette routine envois pour le moment les informations du ficher dans le debugger (j'espère pouvoir faire une routine de visualisation d'ici quelque temps ^^).

J'avais déjà posté a ce sujet mais je m'été aperçu d'un bug au niveau de redimensionnement de l'espace mémoire.

Pour le zip > http://www.pbfrance.com/?url=source&cmd=viewer&val=52
pour le parser > http://www.pbfrance.com/php/form_source ... php?num=52

Le code-source pour ceux qui ne veulent aller sur PBFrance ^^ :

Code : Tout sélectionner

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

; +--------------------------------------------------------------------------+
; |                                                                          |
; +--------------------------------------------------------------------------+

EnableExplicit
EnableASM

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

; +--------------------------------------------------------------------------+
; |                                                                          |
; +--------------------------------------------------------------------------+

Structure lwo_header
  form.s{4}
  flen.l
  lwo2.s{4}
EndStructure

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

; +--------------------------------------------------------------------------+
; |                                                                          |
; +--------------------------------------------------------------------------+

Procedure.w BigEndianToWord(*address.WORD)
; ROUTINE DE CONVERSION BIG ENDIAN VERS WORD.
  CompilerIf #PB_Processor_x86 
    EnableASM
    XOr eax, eax
    MOV ax,word [p.p_address]
    XCHG ah,al 
    ProcedureReturn
    DisableASM
  CompilerElseIf #PB_Processor_x64
    EnableASM
    XOr rax, rax
    MOV ax,word [p.p_address]
    XCHG ah,al 
    ProcedureReturn
    DisableASM
  CompilerElse
    Protected result.w
    PokeB(@result + 1, PeekB(*address    ) & $ff)
    PokeB(@result    , PeekB(*address + 1) & $ff)
    ProcedureReturn result
  CompilerEndIf

EndProcedure

Procedure.l BigEndianToLong(number.l)
; ROUTINE DE CONVERSION BIG ENDIAN VERS LONG.
  CompilerIf #PB_Processor_x86 
    EnableASM
    mov eax, [p.v_number]
    BSWAP eax
    ProcedureReturn
    DisableASM
  CompilerElseIf #PB_Processor_x64
    EnableASM
    mov rax, [p.v_number]
    BSWAP rax
    ProcedureReturn
    DisableASM
  CompilerElse
    ProcedureReturn (number & $ff) << 24 + (number & $ff00) << 8 + (number >> 8) & $ff00 + (number >> 24) & $ff
  CompilerEndIf

EndProcedure

Procedure.f BigEndianToFloat(number.l)
; ROUTINE DE CONVERSION BIG ENDIAN VERS FLOAT.
  Define fvalue.f

  CompilerIf #PB_Processor_x86 
    EnableASM
    mov eax, [p.v_number]
    BSWAP eax
    mov [p.v_fvalue], eax
    DisableASM
  CompilerElseIf #PB_Processor_x64
    EnableASM
    mov rax, [p.v_number]
    BSWAP rax
    mov [p.v_fvalue], rax
    DisableASM
  CompilerElse
    number = ((number >>  8) & $00ff00ff) | ((number <<  8) & $ff00ff00)
    number = ((number >> 16) & $0000ffff) | ((number << 16) & $ffff0000)
    MoveMemory(@number, @fvalue, 4)
  CompilerEndIf
  
  ProcedureReturn fvalue
  
EndProcedure

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

; +--------------------------------------------------------------------------+
; |                                                                          |
; +--------------------------------------------------------------------------+

Procedure loader_lwo(filename.s, factor.f = 1)
; ROUTINE DE CHARGEMENT DES FICHIERS LIGHTWAVE
  Protected *buffer
  Protected fprogress.f
  Protected.s stemp, svalu
  Protected.i i, j, k, ifile, iflen, itlen, imlen, iface, inobjet, inpoint, inbnbox
  Protected header.lwo_header
  
  ifile = ReadFile(#PB_Any, filename)
  If ifile <> 0
    iflen = Lof(ifile)
    header\form = ReadString(ifile, #PB_Ascii, 4)
    header\flen = ReadLong  (ifile              )
    header\lwo2 = ReadString(ifile, #PB_Ascii, 4)
    ;
    ; VERIFICATION DES INFORMATIONS DU HEADER.
    ;
    If header\form = "FORM" And header\lwo2 = "LWO2" And BigEndianToLong(header\flen) + 8 = iflen
      ;
      While Eof(ifile) = #Null
        ;
        ; ROUTINE DE RECHERCHE DU TAG DU FICHIER.
        ;
        *buffer = ReAllocateMemory(*buffer, 4)
        ReadData(ifile, *buffer, MemorySize(*buffer))         ; "TAG" DU FICHIER.
        stemp = PeekS(*buffer, MemorySize(*buffer), #PB_Ascii)
        ;
        ; RECUPERATION DES INFORMATIONS DU TAG.
        ;
        itlen = BigEndianToLong(ReadLong(ifile))             ; INFORMATION DU TAG.
        *buffer = ReAllocateMemory(*buffer, itlen + 1)
        ReadData(ifile, *buffer, itlen)
        ;
        ; ANALYSE ET RECUPERATION DES INFORAMTIONS.
        ;
        Select stemp
          Case "TAGS"
            Debug ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
            Debug ">>>>>>>> TAGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
            Debug ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
            stemp = #NULL$
            For i = 0 To itlen - 1 Step 1
              If PeekA(*buffer + i) <> 0
                stemp + PeekS(*buffer + i, 1, #PB_Ascii)
              Else
                If LCase(stemp) <> "dkblu" And LCase(stemp) <> "model" And stemp <> #NULL$
                  inobjet + 1
                  Debug "COLOR NAME" + Str(inobjet) + " = " + stemp
                EndIf
                stemp = #NULL$
              EndIf
            Next i
            Debug "TOTAL COLOR(S) : " + Str(inobjet)
          Case "LAYR"
            Debug ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
            Debug ">>>>>>>> LAYR >>>>>>>> NOUVELLE OBJET >>>>>>>>>>>>>>>>"
            Debug ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
            imlen = BigEndianToLong(PeekL(*buffer))
            Debug "OBJET : " + Str(imlen)
          Case "PNTS"
            Debug ">>>>>>>> PNTS"
            For i = 0 To itlen - 11 Step 12
              inpoint + 1
              Debug "X" + Str(inpoint) + " = " + StrF(BigEndianToFloat(PeekL(*buffer + i    )) * factor) 
              Debug "Y" + Str(inpoint) + " = " + StrF(BigEndianToFloat(PeekL(*buffer + i + 4)) * factor)
              Debug "Z" + Str(inpoint) + " = " + StrF(BigEndianToFloat(PeekL(*buffer + i + 8)) * factor)
            Next i
            Debug "TOTAL POINT(s) : " + Str(inpoint)
          Case "BBOX"
            Debug ">>>>>>>> BBOX"
            For i = 0 To itlen - 11 Step 12
              inbnbox + 1
              Debug "X" + Str(inbnbox) + " = " + StrF(BigEndianToFloat(PeekL(*buffer + i    )) * factor)  
              Debug "Y" + Str(inbnbox) + " = " + StrF(BigEndianToFloat(PeekL(*buffer + i + 4)) * factor)  
              Debug "Z" + Str(inbnbox) + " = " + StrF(BigEndianToFloat(PeekL(*buffer + i + 8)) * factor)  
            Next i
            Debug "TOTAL POINT(s) : " + Str(inbnbox)
          Case "POLS"
            Debug ">>>>>>>> POLS"
            If PeekS(*buffer, 4, #PB_Ascii) = "FACE"
              iface = 0 
              For i = 5 To itlen Step 2
                k = PeekC(*buffer + i)
                Debug k
                Select k
                  Case 2
                    iface + 1
                    Debug "Face 1 = " + Str(PeekC(*buffer + i + 2))
                    Debug "Face 2 = " + Str(PeekC(*buffer + i + 4))
                    Debug "----"
                    i + (k * 2)
                  Case 3
                    iface + 1
                    Debug "Face 1 = " + Str(PeekC(*buffer + i + 2))
                    Debug "Face 2 = " + Str(PeekC(*buffer + i + 4))
                    Debug "Face 3 = " + Str(PeekC(*buffer + i + 6))
                    Debug "----"
                    i + (k * 2)
                  Case 4
                    iface + 1
                    Debug "Face 1 = " + Str(PeekC(*buffer + i + 2))
                    Debug "Face 2 = " + Str(PeekC(*buffer + i + 4))
                    Debug "Face 3 = " + Str(PeekC(*buffer + i + 6))
                    Debug "Face 4 = " + Str(PeekC(*buffer + i + 8))
                    Debug "----"
                    i + (k * 2)
                  Default
                    iface + 1
                    For j = 1 To k Step 1
                      Debug "Face " + Str(j) + " = " + Str(PeekC(*buffer + i + (j * 2)))
                    Next j
                    Debug "----"
                    i + (k * 2)
                EndSelect
              Next i
              Debug "TOTAL FACE(S) = " + Str(iface)
            EndIf
          Case "PTAG"
            Debug ">>>>>>>> PTAG"
            If PeekS(*buffer, 4, #PB_Ascii) = "SURF"
              Debug "Find SURF"
              For i = 7 To itlen Step 4
                Debug "COLOR FACE " + Str((i / 4)) + " = " + Str(PeekC(*buffer + i))
              Next i
            EndIf
          Case "VMPA"
            Debug ">>>>>>>> VMPA"
          Case "VMAD"
            Debug ">>>>>>>> VMAD"
          Case "CLIP"
            Debug ">>>>>>>> CLIP"
          Case "SURF"
            Debug ">>>>>>>> SURF"
            svalu = PeekS(*buffer, -1, #PB_Ascii)
            j = Len(svalu) + 1
            Debug "NAME = " + svalu
            For i = j To itlen Step 1
              stemp = PeekS(*buffer + i, -1, #PB_Ascii)
              i + Len(stemp)
              Select stemp
                Case "COLR"
                  Debug "Find COLR"
                  imlen = BigEndianToWord(*buffer + i)
                  Debug "R: " + Str(BigEndianToFloat(PeekL(*buffer + i + 2 )) * 255)
                  Debug "G: " + Str(BigEndianToFloat(PeekL(*buffer + i + 6 )) * 255)
                  Debug "B: " + Str(BigEndianToFloat(PeekL(*buffer + i + 10)) * 255)
                  i + imlen
                Case "DIFF"
                  Debug "Find DIFF"
                  imlen = BigEndianToWord(*buffer + i)
                  i + imlen
                Case "SPEC"
                  Debug "Find SPEC"
                  imlen = BigEndianToWord(*buffer + i)
                  i + imlen
                Case "SMAN"
                  Debug "Find SMAN"
                  imlen = BigEndianToWord(*buffer + i)
                  i + imlen
              EndSelect
            Next i
        EndSelect
        ;
        ; PROGRESSION DE CHARGEMENT DU FICHIER.
        ;
        fprogress = Int((100 / iflen) * Loc(ifile))
        ;Debug "CHARGEMENT : " + Str(fprogress) + "%"
        ;
        ; PROGRESSION DE CHARGEMENT DU FICHIER.
        ;
      Wend
    EndIf
   CloseFile(ifile)
  EndIf

EndProcedure

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

; +--------------------------------------------------------------------------+
; |                                                                          |
; +--------------------------------------------------------------------------+

;
; EXEMPLE DE CHARGEMENT D'UN FICHIER LWO.
;
loader_lwo("cube.lwo")
Cordialement,
GallyHC
Dernière modification par GallyHC le jeu. 20/nov./2014 18:39, modifié 2 fois.
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
Avatar de l’utilisateur
djes
Messages : 4252
Inscription : ven. 11/févr./2005 17:34
Localisation : Arras, France

Re: Routine de chargement des Objets "LWO" (LightWave Objet)

Message par djes »

Salut Gally !
Je suis un peu embêté, je pensais avoir posté depuis longtemps le même type de code, et je me rends compte que non. Alors voilà, comme c'est un vieux machin, pas très propre, que je ne l'ai pas testé avec les dernières versions de PB, je le poste ici, tu en fais ce que tu veux, il y a sûrement un ou deux trucs qui pourront t'être utiles.
Fichier lwo_loader.pb

Code : Tout sélectionner

;**********************
;* by djes
;* http://djes.free.fr
;* 4 nov 2005
;**********************

IncludePath "..\include\"
XIncludeFile "d3dx9.pbi"
XIncludeFile "headers.pb"

;*********************************************************************************************************************************************************************

Procedure LWO_Load(filename.s)
;*
;* >= Filename.s : name of lwo file to load
;*

	f.f=0																											;a float var
	w.w=0																											;a word var
	l.l=0																											;a long var
	
	points_index_start.l=0

	;*** Does the file exists?

	If ReadFile(0,filename)

		v.l=ReadLong(0)																					;read a long
		tag.s="AAAA"
		PokeL(@tag,v)																						;write rode tag in tag string
		Debug "FORM? -> "+tag,2

		filesize.l=ReadLong(0)																	;read a long
		MOV eax,filesize																				;convert endians and put the int to float
		BSWAP eax 
		MOV filesize,eax		
		Debug "File size = "+Str(filesize),2

		v.l=ReadLong(0)																					;read a long
		tag2.s="AAAA"
		PokeL(@tag2,v)																					;write rode tag in tag string
		Debug "File type : "+tag2,2

		;*** Regular IFF file ?
	
		If tag="FORM" And Lof(0)=filesize+8 And tag2="LWO2" And Eof(0) = #Null	

			AddElement(objects())
			object_id.l=ListIndex(objects())
	
			total_points_nb.l=0
			total_layers_nb.l=0
			total_polygons_nb.l=0
	
			;*** Looking for tags
	
			While Eof(0) = #Null																	;loop as long the 'end of file' isn't reached
	
				v.l=ReadLong(0)																			;read a long
				tag.s="AAAA"
				PokeL(@tag,v)		
				Debug v,2
	
				;*** Proceed tags
	
				Select tag
	
				Case "LAYR"
	
					;*** Layer found
	
					Debug "LAYR found",2
					AddElement(layers())
					total_layers_nb+1
					layers()\object_id=object_id
					layer_id.l=ListIndex(layers())
	
					;*** Pass over the tag
	
					v.l=ReadLong(0)																		;read a long
					MOV eax,v																					;convert endians and put the int to float
					BSWAP eax 
					MOV v,eax
;					!MOV eax,dword [v_v]															;convert endians and put the int to float
;					!bswap eax 
;					!MOV dword [v_v],eax
					Debug Str(v),3
					FileSeek(0,Loc(0)+v)															;jump over the tag
		
					;*** Process rest of the LAYR tag
	
					While Eof(0) = #Null															;loop as long the 'end of file' isn't reached
	
						v.l=ReadLong(0)																	;read a long
						tag.s="AAAA"
						PokeL(@tag,v)
						
						;*** Looking for geometry tags
	
						Select tag
	
						Case "PNTS"
	
							;*** Points found
	
							Debug "PNTS found",2
							
							;*** Nb of points
	
							nb.l=ReadLong(0)																	;read a long
							MOV eax,nb																				;convert endians 
							BSWAP eax 
							MOV nb,eax	
;							!MOV eax,dword [v_nb]															;convert endians 
;							!bswap eax 
;							!MOV dword [v_nb],eax	
							Debug "Nb of points : "+Str(nb/12),2
							points_index_start=ListIndex(points())+1

							;*** One point = 12 bytes mini (4 bytes per axis)
	
							If nb>=$C						
	
								;*** Loop over points
	
								While Eof(0) = #Null And nb>0									;read sequentially x, y, z
	
									;*** New point
	
									AddElement(points())
									AddElement(transformed_points())
									total_points_nb+1
	
									l.l=ReadLong(0)																;read a long
									MOV eax,l																			;convert endians and put the int to float
									BSWAP eax 
									MOV f,eax	
;									!MOV eax,dword [v_l]													;convert endians and put the int to float
;									!bswap eax 
;									!MOV dword [v_f],eax	
									points()\x=f													
									Debug "x  "+StrF(f),3
	
									l.l=ReadLong(0)
									MOV eax,l																			;convert endians and put the int to float
									BSWAP eax 
									MOV f,eax	
;									!MOV eax,dword [v_l]
;									!bswap eax 
;									!MOV dword [v_f],eax	
									points()\y=f
									Debug "y  "+StrF(f),3
	
									l.l=ReadLong(0)
									MOV eax,l																			;convert endians and put the int to float
									BSWAP eax 
									MOV f,eax	
;									!MOV eax,dword [v_l]
;									!bswap eax 
;									!MOV dword [v_f],eax	
									points()\z=f
									Debug "z  "+StrF(f),3
	
									nb-12
	
								Wend
							EndIf
						
						Case "POLS"
						
							;*** Polygons found
	
							Debug "POLS found",2
						
							;*** Get size of this tag to process only this one
	
							pols_tagsize.l=ReadLong(0)													;read a long
							MOV eax,pols_tagsize																;convert endians 
							BSWAP eax 
							MOV pols_tagsize,eax	
;							!MOV eax,dword [v_pols_tagsize]											;convert endians 
;							!bswap eax 
;							!MOV dword [v_pols_tagsize],eax
	
							If Eof(0) = #Null
	
								;*** Get polygon type
	
								v.l=ReadLong(0)
								pols_tagsize-4
								tag.s="AAAA"
								PokeL(@tag,v)
								Debug tag,3
		
								Select tag
								Case "FACE"
								
									;*** Regular polygon found (first, nb of points, then index of points)
	
									Debug "FACE found",2
		
									;*** Process tag
	
									While Eof(0) = #Null And pols_tagsize>0							
		
										;*** How many points in this pol
	
										points_nb.w=ReadWord(0)
										pols_tagsize-2
										MOV ax,points_nb															;convert endians
										XCHG ah,al 
										MOV points_nb,ax
;										!MOV ax,word [v_points_nb]										;convert endians
;										!xchg ah,al 
;										!MOV word [v_points_nb],ax
										Debug "Nb of points in this polygon : "+Str(points_nb),2
					
										If points_nb>0							
	
											;*** There's at least one point : new polygon
	
											AddElement(polygons())
											
											objects()\polygons_nb+1
											total_polygons_nb+1
											polygons()\points_nb=points_nb
											polygons()\points_list=ListIndex(polygon_points_index())+1	;This polygon first point index position
											polygons()\layer_id=layer_id
	
											;*** Process all points of this poly : store indexes in polygon_points_index(), and first one pos in the polygon structure, with the nb of points
	
											While Eof(0) = #Null And points_nb>0

												AddElement(polygon_points_index())	

												;*** Is this a long index, or a short? (more than 65279 points in this poly:long)
	
												If ReadByte(0)<>$FF													;read first byte, if $FF, index is a long, else it's a word
	
													;*** New short (word, 2 bytes) size index
	
													FileSeek(0,Loc(0)-1)											;read a word
													w.w=ReadWord(0)	
													pols_tagsize-2
													MOV ax,w																	;convert endians
													XCHG ah,al
													MOV w,ax
;													!MOV ax,word [v_w]												;convert endians
;													!xchg ah,al
;													!MOV word [v_w],ax
													polygon_points_index()=w+points_index_start			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug w,3
													points_nb-1

												Else
	
													;*** New long (3 bytes in fact) size index
	
													FileSeek(0,Loc(0)-1)									;read a long
													l.l=ReadLong(0)	
													pols_tagsize-4
													MOV eax,l															;convert endians
													BSWAP eax 
													AND eax,$00FFFFFF
													MOV l,eax
;													!MOV eax,dword [v_l]									;convert endians
;													!bswap eax 
;													!AND eax,$00FFFFFF
;													!MOV dword [v_l],eax
													polygon_points_index()=l+points_index_start			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug l,3
													points_nb-1					
	
												EndIf										
											Wend
										EndIf
									Wend
									
								Case "PTCH"
								
									;*** Patch polygon found (first, nb of points, then index of points). Read only the cage polygons
	
									Debug "PTCH found",2
		
									;*** Process tag
	
									While Eof(0) = #Null And pols_tagsize>0							
		
										;*** How many points in this pol
	
										points_nb.w=ReadWord(0)
										pols_tagsize-2
										MOV ax,points_nb															;convert endians
										XCHG ah,al 
										MOV points_nb,ax
;										!MOV ax,word [v_points_nb]										;convert endians
;										!xchg ah,al 
;										!MOV word [v_points_nb],ax
										Debug "Nb of points in this patch polygon : "+Str(points_nb),2
					
										If points_nb>0							
	
											;*** There's at least one point : new polygon
	
											AddElement(polygons())
											objects()\polygons_nb+1
											total_polygons_nb+1
											polygons()\points_nb=points_nb
											polygons()\points_list=ListIndex(polygon_points_index())+1	;This polygon first point index position
											polygons()\layer_id=layer_id
	
											;*** Process all points of this poly : store indexes in polygon_points_index(), and first one pos in the polygon structure, with the nb of points
	
											While Eof(0) = #Null And points_nb>0
	
												AddElement(polygon_points_index())
											
												;*** Is this a long index, or a short? (more than 65279 points in this poly:long)
	
												If ReadByte(0)<>$FF										;read first byte, if $FF, index is a long, else it's a word
	
													;*** New short (word, 2 bytes) size index
	
													FileSeek(0,Loc(0)-1)									;read a word
													w.w=ReadWord(0)	
													pols_tagsize-2
													MOV ax,w															;convert endians
													XCHG ah,al
													MOV w,ax
;													!MOV ax,word [v_w]										;convert endians
;													!xchg ah,al
;													!MOV word [v_w],ax
													polygon_points_index()=w;+points_index_start			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug w,3
													points_nb-1

												Else
	
													;*** New long (3 bytes in fact) size index
	
													FileSeek(0,Loc(0)-1)									;read a long
													l.l=ReadLong(0)	
													pols_tagsize-4
													MOV eax,l															;convert endians
													BSWAP eax 
													AND eax,$00FFFFFF
													MOV l,eax
;													!MOV eax,dword [v_l]									;convert endians
;													!bswap eax 
;													!AND eax,$00FFFFFF
;													!MOV dword [v_l],eax
													polygon_points_index()=l+points_index_start			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug l,3
													points_nb-1
	
												EndIf										
											Wend
										EndIf
									Wend									
								Default

									;*** Pass over the unknown tag
					
									Debug tag+" found",2
									FileSeek(0,Loc(0)+pols_tagsize)
					
								EndSelect
							EndIf

						Default

							;*** Pass over the unknown tag
			
							Debug tag+" found",2
							v.l=ReadLong(0)																;read a long
							MOV eax,v																			;convert endians and put the int to float
							BSWAP eax 
							MOV v,eax
		;					!MOV eax,dword [v_v]													;convert endians and put the int to float
		;					!bswap eax 
		;					!MOV dword [v_v],eax
							Debug Str(v),3
							FileSeek(0,Loc(0)+v)
			
						EndSelect
						;**************************
					Wend
					
					current_layer+1																		;next layer (if exists)
				
				;*** Process others tag
	
				Default
	
					Debug tag+" found",2
					l.l=ReadLong(0)
					MOV eax,l																					;convert endians
					BSWAP eax 
					MOV l,eax
;					!MOV eax,dword [v_l]															;convert endians
;					!bswap eax 
;					!MOV dword [v_l],eax
					Debug l,3
					FileSeek(0,Loc(0)+l)															;jump over the tag
	
				EndSelect
				;**************************
				
			Wend
			
		EndIf
		
		CloseFile(0)              															;close the previously opened file
	
	Else
	
		MessageRequester("Information","Couldn't open the file!")
	
	EndIf
	
	Debug Str(total_layers_nb)+" layer(s)",1
	Debug Str(total_polygons_nb)+" polygon(s)",1
	Debug Str(total_points_nb)+" point(s)",1

EndProcedure
Procedure LWO_Load_Mem(filename.s)
;*
;* >= Filename.s : name of lwo file to load
;*

	f.f=0																								;a float var
	w.w=0																								;a word var
	l.l=0																								;a long var
	
	points_index_start.l=0

	;*** Does the file exists?

	If ReadFile(0,filename)

		v.l=ReadLong(0)																				;read a long
		tag.s="AAAA"
		PokeL(@tag,v)																					;write rode tag in tag string
		Debug "FORM? -> "+tag,2

		filesize.l=ReadLong(0)																;read a long
		MOV eax,filesize																			;convert endians and put the int to float
		BSWAP eax 
		MOV filesize,eax		
		Debug "File size = "+Str(filesize),2

		v.l=ReadLong(0)																				;read a long
		tag2.s="AAAA"
		PokeL(@tag2,v)																				;write rode tag in tag string
		Debug "File type : "+tag2,2

		;*** Regular IFF file ?
	
		If tag="FORM" And Lof(0)=filesize+8 And tag2="LWO2" And Eof(0) = #Null	

			AddElement(objects())
			object_id.l=ListIndex(objects())
	
			total_points_nb.l=0
			total_layers_nb.l=0
			total_polygons_nb.l=0
	
			;*** Looking for tags
	
			While Eof(0) = #Null																;loop as long the 'end of file' isn't reached
	
				v.l=ReadLong(0)																		;read a long
				tag.s="AAAA"
				PokeL(@tag,v)		
				Debug v,2
	
				;*** Proceed tags
	
				Select tag
	
				Case "LAYR"
	
					;*** Layer found
	
					Debug "LAYR found",2
					AddElement(layers())
					total_layers_nb+1
					layers()\object_id=object_id
					layer_id.l=ListIndex(layers())
	
					;*** Pass over the tag
	
					v.l=ReadLong(0)																		;read a long
					MOV eax,v																					;convert endians and put the int to float
					BSWAP eax 
					MOV v,eax
;					!MOV eax,dword [v_v]															;convert endians and put the int to float
;					!bswap eax 
;					!MOV dword [v_v],eax
					Debug Str(v),3
					FileSeek(0,Loc(0)+v)															;jump over the tag
		
					;*** Process rest of the LAYR tag
	
					While Eof(0) = #Null															;loop as long the 'end of file' isn't reached
	
						v.l=ReadLong(0)																	;read a long
						tag.s="AAAA"
						PokeL(@tag,v)
						
						;*** Looking for geometry tags
	
						Select tag
	
						Case "PNTS"
	
							;*** Points found
	
							Debug "PNTS found",2
							
							;*** Nb of points
	
							nb.l=ReadLong(0)															;read a long
							MOV eax,nb																		;convert endians 
							BSWAP eax 
							MOV nb,eax	
;							!MOV eax,dword [v_nb]													;convert endians 
;							!bswap eax 
;							!MOV dword [v_nb],eax	
							Debug "Nb of points : "+Str(nb/12),2
;							points_index_start=ListIndex(points())+1

							;*** One point = 12 bytes mini (4 bytes per axis)
	
							If nb>=$C				

								objects()\points_nb=nb/12
								objects()\points=AllocateMemory(SizeOf(vector)*nb/12)
								objects()\transformed_points=AllocateMemory(SizeOf(vector)*nb/12)
								*obj.vector=objects()\points
	
								;*** Loop over points
	
								While Eof(0) = #Null And nb>0							;read sequentially x, y, z
	
									;*** New point
	
;									AddElement(points())
;									AddElement(transformed_points())
									total_points_nb+1
	
									l.l=ReadLong(0)														;read a long
									MOV eax,l																	;convert endians and put the int to float
									BSWAP eax 
									MOV f,eax	
;									!MOV eax,dword [v_l]											;convert endians and put the int to float
;									!bswap eax 
;									!MOV dword [v_f],eax	
									*obj\x=f													
									Debug "x  "+StrF(f),3
	
									l.l=ReadLong(0)
									MOV eax,l																	;convert endians and put the int to float
									BSWAP eax 
									MOV f,eax	
;									!MOV eax,dword [v_l]
;									!bswap eax 
;									!MOV dword [v_f],eax	
									*obj\y=f													
									Debug "y  "+StrF(f),3
	
									l.l=ReadLong(0)
									MOV eax,l																	;convert endians and put the int to float
									BSWAP eax 
									MOV f,eax	
;									!MOV eax,dword [v_l]
;									!bswap eax 
;									!MOV dword [v_f],eax	
									*obj\z=f													
									Debug "z  "+StrF(f),3
	
									nb-12
									*obj+12
	
								Wend
							EndIf
						
						Case "POLS"
						
							;*** Polygons found
	
							Debug "POLS found",2
						
							;*** Get size of this tag to process only this one
	
							pols_tagsize.l=ReadLong(0)											;read a long
							MOV eax,pols_tagsize														;convert endians 
							BSWAP eax 
							MOV pols_tagsize,eax	
;							!MOV eax,dword [v_pols_tagsize]									;convert endians 
;							!bswap eax 
;							!MOV dword [v_pols_tagsize],eax
	
							If Eof(0) = #Null
	
								;*** Get polygon type
	
								v.l=ReadLong(0)
								pols_tagsize-4
								tag.s="AAAA"
								PokeL(@tag,v)
								Debug tag,3
		
								Select tag
								Case "FACE"
								
									;*** Regular polygon found (first, nb of points, then index of points)
	
									Debug "FACE found",2
		
									;*** Process tag
	
									While Eof(0) = #Null And pols_tagsize>0							
		
										;*** How many points in this pol
	
										points_nb.w=ReadWord(0)
										pols_tagsize-2
										MOV ax,points_nb														;convert endians
										XCHG ah,al 
										MOV points_nb,ax
;										!MOV ax,word [v_points_nb]									;convert endians
;										!xchg ah,al 
;										!MOV word [v_points_nb],ax
										Debug "Nb of points in this polygon : "+Str(points_nb),2
					
										If points_nb>0							
	
											;*** There's at least one point : new polygon
	
											AddElement(polygons())
											objects()\polygons_nb+1
											total_polygons_nb+1
											polygons()\points_nb=points_nb
;											polygons()\points_list=ListIndex(polygon_points_index())+1	;This polygon first point index position
											polygons()\points_list=ListIndex(*polygon_transformed_points_ptrs())+1	;This polygon first point index position (old one+1)
											polygons()\layer_id=layer_id
	
											;*** Process all points of this poly : store indexes in polygon_points_index(), and first one pos in the polygon structure, with the nb of points
	
											While Eof(0) = #Null And points_nb>0

;												AddElement(polygon_points_index())	
												AddElement(*polygon_transformed_points_ptrs())	

												;*** Is this a long index, or a short? (more than 65279 points in this poly:long)
	
												If ReadByte(0)<>$FF										;read first byte, if $FF, index is a long, else it's a word
	
													;*** New short (word, 2 bytes) size index
	
													FileSeek(0,Loc(0)-1)									;read a word
													w.w=ReadWord(0)	
													pols_tagsize-2
													MOV ax,w															;convert endians
													XCHG ah,al
													MOV w,ax
;													!MOV ax,word [v_w]										;convert endians
;													!xchg ah,al
;													!MOV word [v_w],ax
;													polygon_points_index()=l+points_index_start			;value+start of this object's points list
													*polygon_transformed_points_ptrs()=w*SizeOf(vector)+objects()\transformed_points			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug w,3
													points_nb-1

												Else
	
													;*** New long (3 bytes in fact) size index
	
													FileSeek(0,Loc(0)-1)									;read a long
													l.l=ReadLong(0)	
													pols_tagsize-4
													MOV eax,l															;convert endians
													BSWAP eax 
													AND eax,$00FFFFFF
													MOV l,eax
;													!MOV eax,dword [v_l]									;convert endians
;													!bswap eax 
;													!AND eax,$00FFFFFF
;													!MOV dword [v_l],eax
;													polygon_points_index()=l+points_index_start			;value+start of this object's points list
													*polygon_transformed_points_ptrs()=l*SizeOf(vector)+objects()\transformed_points			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug l,3
													points_nb-1					
	
												EndIf										
											Wend
										EndIf
									Wend
									
								Case "PTCH"
								
									;*** Patch polygon found (first, nb of points, then index of points). Read only the cage polygons
	
									Debug "PTCH found",2
		
									;*** Process tag
	
									While Eof(0) = #Null And pols_tagsize>0							
		
										;*** How many points in this pol
	
										points_nb.w=ReadWord(0)
										pols_tagsize-2
										MOV ax,points_nb															;convert endians
										XCHG ah,al 
										MOV points_nb,ax
;										!MOV ax,word [v_points_nb]										;convert endians
;										!xchg ah,al 
;										!MOV word [v_points_nb],ax
										Debug "Nb of points in this patch polygon : "+Str(points_nb),2
					
										If points_nb>0							
	
											;*** There's at least one point : new polygon
	
											AddElement(polygons())
											objects()\polygons_nb+1
											total_polygons_nb+1
											polygons()\points_nb=points_nb
;											polygons()\points_list=ListIndex(polygon_points_index())+1	;This polygon first point index position
											polygons()\points_list=ListIndex(*polygon_transformed_points_ptrs())+1	;This polygon first point index position (old one+1)
											polygons()\layer_id=layer_id
	
											;*** Process all points of this poly : store indexes in polygon_points_index(), and first one pos in the polygon structure, with the nb of points
	
											While Eof(0) = #Null And points_nb>0
	
;												AddElement(polygon_points_index())	
												AddElement(*polygon_transformed_points_ptrs())	
											
												;*** Is this a long index, or a short? (more than 65279 points in this poly:long)
	
												If ReadByte(0)<>$FF										;read first byte, if $FF, index is a long, else it's a word
	
													;*** New short (word, 2 bytes) size index
	
													FileSeek(0,Loc(0)-1)									;read a word
													w.w=ReadWord(0)	
													pols_tagsize-2
													MOV ax,w															;convert endians
													XCHG ah,al
													MOV w,ax
;													!MOV ax,word [v_w]										;convert endians
;													!xchg ah,al
;													!MOV word [v_w],ax

;													polygon_points_index()=w+points_index_start			;value+start of this object's points list
													*polygon_transformed_points_ptrs()=w*SizeOf(vector)+objects()\transformed_points			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug w,3
													points_nb-1

												Else
	
													;*** New long (3 bytes in fact) size index
	
													FileSeek(0,Loc(0)-1)									;read a long
													l.l=ReadLong(0)	
													pols_tagsize-4
													MOV eax,l															;convert endians
													BSWAP eax 
													AND eax,$00FFFFFF
													MOV l,eax
;													!MOV eax,dword [v_l]									;convert endians
;													!bswap eax 
;													!AND eax,$00FFFFFF
;													!MOV dword [v_l],eax

;													polygon_points_index()=l+points_index_start			;value+start of this object's points list
													*polygon_transformed_points_ptrs()=l*SizeOf(vector)+objects()\transformed_points			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug l,3
													points_nb-1
	
												EndIf										
											Wend
										EndIf
									Wend									
								Default

									;*** Pass over the unknown tag
					
									Debug tag+" found",2
									FileSeek(0,Loc(0)+pols_tagsize)
					
								EndSelect
							EndIf

						Default

							;*** Pass over the unknown tag
			
							Debug tag+" found",2
							v.l=ReadLong(0)																;read a long
							MOV eax,v																			;convert endians and put the int to float
							BSWAP eax 
							MOV v,eax
		;					!MOV eax,dword [v_v]													;convert endians and put the int to float
		;					!bswap eax 
		;					!MOV dword [v_v],eax
							Debug Str(v),3
							FileSeek(0,Loc(0)+v)
			
						EndSelect
						;**************************
					Wend
					
					current_layer+1																		;next layer (if exists)
				
				;*** Process others tag
	
				Default
	
					Debug tag+" found",2
					l.l=ReadLong(0)
					MOV eax,l																					;convert endians
					BSWAP eax 
					MOV l,eax
;					!MOV eax,dword [v_l]															;convert endians
;					!bswap eax 
;					!MOV dword [v_l],eax
					Debug l,3
					FileSeek(0,Loc(0)+l)															;jump over the tag
	
				EndSelect
				;**************************
				
			Wend
			
		EndIf
		
		CloseFile(0)              															; close the previously opened file
	
	Else
	
		MessageRequester("Information","Couldn't open the file!")
	
	EndIf
	
	Debug Str(total_layers_nb)+" layer(s)",1
	Debug Str(total_polygons_nb)+" polygon(s)",1
	Debug Str(total_points_nb)+" point(s)",1

EndProcedure
Procedure LWO_Load_D3D(filename.s)
;*
;* >= Filename.s : name of lwo file to load
;*

	f.f=0																								;a float var
	w.w=0																								;a word var
	l.l=0																								;a long var
	
	points_index_start.l=0

	;*** Does the file exists?

	If ReadFile(0,filename)

		v.l=ReadLong(0)																				;read a long
		tag.s="AAAA"
		PokeL(@tag,v)																					;write rode tag in tag string
		Debug "FORM? -> "+tag,2

		filesize.l=ReadLong(0)																;read a long
		MOV eax,filesize																			;convert endians and put the int to float
		BSWAP eax 
		MOV filesize,eax		
		Debug "File size = "+Str(filesize),2

		v.l=ReadLong(0)																				;read a long
		tag2.s="AAAA"
		PokeL(@tag2,v)																				;write rode tag in tag string
		Debug "File type : "+tag2,2

		;*** Regular IFF file ?
	
		If tag="FORM" And Lof(0)=filesize+8 And tag2="LWO2" And Eof(0) = #Null	

			AddElement(d3d_objects())
			object_id.l=ListIndex(d3d_objects())
	
			total_points_nb.l=0
			total_layers_nb.l=0
			total_polygons_nb.l=0
	
			;*** Looking for tags
	
			While Eof(0) = #Null																;loop as long the 'end of file' isn't reached
	
				v.l=ReadLong(0)																		;read a long
				tag.s="AAAA"
				PokeL(@tag,v)		
				Debug v,2
	
				;*** Proceed tags
	
				Select tag
	
				Case "LAYR"
	
					;*** Layer found
	
					Debug "LAYR found",2
					AddElement(layers())
					total_layers_nb+1
					layers()\object_id=object_id
					layer_id.l=ListIndex(layers())
	
					;*** Pass over the tag
	
					v.l=ReadLong(0)																		;read a long
					MOV eax,v																					;convert endians and put the int to float
					BSWAP eax 
					MOV v,eax
;					!MOV eax,dword [v_v]															;convert endians and put the int to float
;					!bswap eax 
;					!MOV dword [v_v],eax
					Debug Str(v),3
					FileSeek(0,Loc(0)+v)															;jump over the tag
		
					;*** Process rest of the LAYR tag
	
					While Eof(0) = #Null															;loop as long the 'end of file' isn't reached
	
						v.l=ReadLong(0)																	;read a long
						tag.s="AAAA"
						PokeL(@tag,v)
						
						;*** Looking for geometry tags
	
						Select tag
	
						Case "PNTS"
	
							;*** Points found
	
							Debug "PNTS found",2
							
							;*** Nb of points
	
							nb.l=ReadLong(0)															;read a long
							MOV eax,nb																		;convert endians 
							BSWAP eax 
							MOV nb,eax	
;							!MOV eax,dword [v_nb]													;convert endians 
;							!bswap eax 
;							!MOV dword [v_nb],eax	
							Debug "Nb of points : "+Str(nb/12),2
;							points_index_start=ListIndex(points())+1

							;*** One point = 12 bytes mini (4 bytes per axis)
	
							If nb>=$C				

								d3d_objects()\points_nb=nb/12
								d3d_objects()\points=AllocateMemory(SizeOf(vector)*d3d_objects()\points_nb)
								d3d_objects()\transformed_points=AllocateMemory(SizeOf(CUSTOMVERTEX)*d3d_objects()\points_nb)
								*obj.vector=d3d_objects()\points
	
								;*** Loop over points
	
								While Eof(0) = #Null And nb>0							;read sequentially x, y, z
	
									;*** New point
	
;									AddElement(points())
;									AddElement(transformed_points())
									total_points_nb+1
	
									l.l=ReadLong(0)														;read a long
									MOV eax,l																	;convert endians and put the int to float
									BSWAP eax 
									MOV f,eax	
;									!MOV eax,dword [v_l]											;convert endians and put the int to float
;									!bswap eax 
;									!MOV dword [v_f],eax	
									*obj\x=f													
									Debug "x  "+StrF(f),3
	
									l.l=ReadLong(0)
									MOV eax,l																	;convert endians and put the int to float
									BSWAP eax 
									MOV f,eax	
;									!MOV eax,dword [v_l]
;									!bswap eax 
;									!MOV dword [v_f],eax	
									*obj\y=f													
									Debug "y  "+StrF(f),3
	
									l.l=ReadLong(0)
									MOV eax,l																	;convert endians and put the int to float
									BSWAP eax 
									MOV f,eax	
;									!MOV eax,dword [v_l]
;									!bswap eax 
;									!MOV dword [v_f],eax	
									*obj\z=f													
									Debug "z  "+StrF(f),3
	
									nb-12
									*obj+SizeOf(vector)
	
								Wend
							EndIf
						
						Case "POLS"
						
							;*** Polygons found
	
							Debug "POLS found",2
						
							;*** Get size of this tag to process only this one
	
							pols_tagsize.l=ReadLong(0)											;read a long
							MOV eax,pols_tagsize														;convert endians 
							BSWAP eax 
							MOV pols_tagsize,eax	
;							!MOV eax,dword [v_pols_tagsize]									;convert endians 
;							!bswap eax 
;							!MOV dword [v_pols_tagsize],eax
	
							If Eof(0) = #Null
	
								;*** Get polygon type
	
								v.l=ReadLong(0)
								pols_tagsize-4
								tag.s="AAAA"
								PokeL(@tag,v)
								Debug tag,3
		
								Select tag
								Case "FACE"
								
									;*** Regular polygon found (first, nb of points, then index of points)
	
									Debug "FACE found",2
		
									;*** Process tag
	
									While Eof(0) = #Null And pols_tagsize>0							
		
										;*** How many points in this pol
	
										points_nb.w=ReadWord(0)
										pols_tagsize-2
										MOV ax,points_nb														;convert endians
										XCHG ah,al 
										MOV points_nb,ax
;										!MOV ax,word [v_points_nb]									;convert endians
;										!xchg ah,al 
;										!MOV word [v_points_nb],ax
										Debug "Nb of points in this polygon : "+Str(points_nb),2
					
										If points_nb>0							
	
											;*** There's at least one point : new polygon
	
											AddElement(polygons())
											d3d_objects()\polygons_nb+1
											total_polygons_nb+1
											polygons()\points_nb=points_nb
;											polygons()\points_list=ListIndex(polygon_points_index())+1	;This polygon first point index position
											polygons()\points_list=ListIndex(polygon_transformed_points_index())+1	;This polygon first point index position (old one+1)
											polygons()\layer_id=layer_id
											d3d_objects()\edges_nb+points_nb	;total nb of edges
	
											;*** Process all points of this poly : store indexes in polygon_points_index(), and first one pos in the polygon structure, with the nb of points
	
											While Eof(0) = #Null And points_nb>0

;												AddElement(polygon_points_index())	
												AddElement(polygon_transformed_points_index())	

												;*** Is this a long index, or a short? (more than 65279 points in this poly:long)
	
												If ReadByte(0)<>$FF										;read first byte, if $FF, index is a long, else it's a word
	
													;*** New short (word, 2 bytes) size index
	
													FileSeek(0,Loc(0)-1)									;read a word
													w.w=ReadWord(0)	
													pols_tagsize-2
													MOV ax,w															;convert endians
													XCHG ah,al
													MOV w,ax
;													!MOV ax,word [v_w]										;convert endians
;													!xchg ah,al
;													!MOV word [v_w],ax
;													polygon_points_index()=l+points_index_start			;value+start of this object's points list
													polygon_transformed_points_index()=w;*SizeOf(CUSTOMVERTEX)+d3d_objects()\transformed_points			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug w,3
													points_nb-1

												Else
	
													;*** New long (3 bytes in fact) size index
	
													FileSeek(0,Loc(0)-1)									;read a long
													l.l=ReadLong(0)	
													pols_tagsize-4
													MOV eax,l															;convert endians
													BSWAP eax 
													AND eax,$00FFFFFF
													MOV l,eax
;													!MOV eax,dword [v_l]									;convert endians
;													!bswap eax 
;													!AND eax,$00FFFFFF
;													!MOV dword [v_l],eax
;													polygon_points_index()=l+points_index_start			;value+start of this object's points list
													polygon_transformed_points_index()=l;*SizeOf(CUSTOMVERTEX)+d3d_objects()\transformed_points			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug l,3
													points_nb-1					
	
												EndIf										
											Wend
										EndIf
									Wend
									
								Case "PTCH"
								
									;*** Patch polygon found (first, nb of points, then index of points). Read only the cage polygons
	
									Debug "PTCH found",2
		
									;*** Process tag
	
									While Eof(0) = #Null And pols_tagsize>0							
		
										;*** How many points in this pol
	
										points_nb.w=ReadWord(0)
										pols_tagsize-2
										MOV ax,points_nb															;convert endians
										XCHG ah,al 
										MOV points_nb,ax
;										!MOV ax,word [v_points_nb]										;convert endians
;										!xchg ah,al 
;										!MOV word [v_points_nb],ax
										Debug "Nb of points in this patch polygon : "+Str(points_nb),2
					
										If points_nb>0							
	
											;*** There's at least one point : new polygon
	
											AddElement(polygons())
											d3d_objects()\polygons_nb+1
											total_polygons_nb+1
											polygons()\points_nb=points_nb
;											polygons()\points_list=ListIndex(polygon_points_index())+1	;This polygon first point index position
											polygons()\points_list=ListIndex(polygon_transformed_points_index())+1	;This polygon first point index position (old one+1)
											polygons()\layer_id=layer_id
											d3d_objects()\edges_nb+points_nb	;total nb of edges
	
											;*** Process all points of this poly : store indexes in polygon_points_index(), and first one pos in the polygon structure, with the nb of points
	
											While Eof(0) = #Null And points_nb>0
	
;												AddElement(polygon_points_index())	
												AddElement(polygon_transformed_points_index())
											
												;*** Is this a long index, or a short? (more than 65279 points in this poly:long)
	
												If ReadByte(0)<>$FF										;read first byte, if $FF, index is a long, else it's a word
	
													;*** New short (word, 2 bytes) size index
	
													FileSeek(0,Loc(0)-1)									;read a word
													w.w=ReadWord(0)	
													pols_tagsize-2
													MOV ax,w															;convert endians
													XCHG ah,al
													MOV w,ax
;													!MOV ax,word [v_w]										;convert endians
;													!xchg ah,al
;													!MOV word [v_w],ax

;													polygon_points_index()=w+points_index_start			;value+start of this object's points list
													polygon_transformed_points_index()=w;*SizeOf(CUSTOMVERTEX)+d3d_objects()\transformed_points			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug w,3
													points_nb-1

												Else
	
													;*** New long (3 bytes in fact) size index
	
													FileSeek(0,Loc(0)-1)									;read a long
													l.l=ReadLong(0)	
													pols_tagsize-4
													MOV eax,l															;convert endians
													BSWAP eax 
													AND eax,$00FFFFFF
													MOV l,eax
;													!MOV eax,dword [v_l]									;convert endians
;													!bswap eax 
;													!AND eax,$00FFFFFF
;													!MOV dword [v_l],eax

;													polygon_points_index()=l+points_index_start			;value+start of this object's points list
													polygon_transformed_points_index()=l;*SizeOf(CUSTOMVERTEX)+d3d_objects()\transformed_points			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug l,3
													points_nb-1
	
												EndIf										
											Wend
										EndIf
									Wend									
								Default

									;*** Pass over the unknown tag
					
									Debug tag+" found",2
									FileSeek(0,Loc(0)+pols_tagsize)
					
								EndSelect
							EndIf

						Default

							;*** Pass over the unknown tag
			
							Debug tag+" found",2
							v.l=ReadLong(0)																;read a long
							MOV eax,v																			;convert endians and put the int to float
							BSWAP eax 
							MOV v,eax
		;					!MOV eax,dword [v_v]													;convert endians and put the int to float
		;					!bswap eax 
		;					!MOV dword [v_v],eax
							Debug Str(v),3
							FileSeek(0,Loc(0)+v)
			
						EndSelect
						;**************************
					Wend
					
					current_layer+1																		;next layer (if exists)
				
				;*** Process others tag
	
				Default
	
					Debug tag+" found",2
					l.l=ReadLong(0)
					MOV eax,l																					;convert endians
					BSWAP eax 
					MOV l,eax
;					!MOV eax,dword [v_l]															;convert endians
;					!bswap eax 
;					!MOV dword [v_l],eax
					Debug l,3
					FileSeek(0,Loc(0)+l)															;jump over the tag
	
				EndSelect
				;**************************
				
			Wend
			
		EndIf
		
		CloseFile(0)              															; close the previously opened file
	
	Else
	
		MessageRequester("Information","Couldn't open the file!")
	
	EndIf

	Debug Str(total_layers_nb)+" layer(s)",1
	Debug Str(total_polygons_nb)+" polygon(s)",1
	Debug Str(total_points_nb)+" point(s)",1

EndProcedure
;*********************************************************************************************************************************************************************

Fichier headers.pb

Code : Tout sélectionner

;**********************
;* by djes
;* http://djes.free.fr
;* 4 nov 2005
;**********************

;#PI=3.14159265

Structure matrix
	mat.f[9]
EndStructure

Structure vector
	x.f
	y.f
	z.f
EndStructure

Structure dot
	x.f
	y.f
EndStructure

Structure CUSTOMVERTEX 
	x.f 
	y.f 
	z.f 
	rhw.f 
	color.l   ; DWord = L 
EndStructure 
Structure CLIPPLANE
	a.f
	b.f
	c.f
	d.f
EndStructure

Structure object
	pivot.vector
	rotation.matrix
	parent.l
	*points.vector
	*transformed_points.vector
	points_nb.l
	polygons_nb.l
EndStructure

Structure d3d_object
	pivot.vector
	rotation.matrix
	parent.l
	points_nb.l
	edges_nb.l
	polygons_nb.l
	*points.vector
	*transformed_points.CUSTOMVERTEX
	*vertexbuffer.IDirect3DVertexBuffer9
	*indexbuffer.IDirect3DIndexBuffer9
EndStructure

Structure layer
	object_id.l
	pivot.vector
	rotation.matrix
	parent.l
EndStructure

Structure polygon
	layer_id.l
	points_list.l
	points_nb.l
EndStructure

Structure obj_point
	pos.vector
EndStructure

Structure surface
	polygon_id.l
EndStructure

Global NewList objects.object()
Global NewList d3d_objects.d3d_object()
Global NewList layers.layer()
Global NewList polygons.polygon()
Global NewList polygon_points_index.l()
Global NewList *polygon_transformed_points_ptrs.vector()
Global NewList polygon_transformed_points_index.l()
Global NewList points.vector()
Global NewList transformed_points.vector()

Global screen_dist.f, screen_ppd.f, screen_x_center.f, screen_y_center.f
Fichier d3dx9.pbi

Code : Tout sélectionner

;//////////////////////////////////////////////////////////////////////////////
;//
;//  Copyright (C) Microsoft Corporation.  All Rights Reserved.
;//
;//  File:       d3dx9.h
;//  Content:    D3DX utility library
;//
;//////////////////////////////////////////////////////////////////////////////
;/
;/ Converted By Steven (Dreglor) Garcia
;/ Designed For Use with PureBasic 4.0
;/ Created on: 3-18-06
;/ Updated: 3-20-06
;/
;/ December(2005) Version
;/

CompilerIf Defined(__D3DX_INTERNAL__, #PB_Constant)
  CompilerError "Incorrect D3DX header used"
CompilerEndIf

CompilerIf Defined(__D3DX9_H__, #PB_Constant) = #False
  #__D3DX9_H__ = 1
  
  ;// Defines
  
  ;Limit.h subistiudes
  
  XIncludeFile "DxCommon.pbi"
  
  #D3DX_DEFAULT  = (-1)
  #D3DX_DEFAULT_NONPOW2 = (-2)
  #D3DX_DEFAULT_FLOAT = #FLT_MAX
  #D3DX_FROM_FILE = (-3)
  #D3DFMT_FROM_FILE = (-3)
  
  
  
  ;// Includes
  IncludeFile "d3d9.pbi"
  ;IncludeFile "d3d9types.pbi"
  IncludeFile "d3dx9math.pbi"
  IncludeFile "d3dx9core.pbi"
  IncludeFile "d3dx9xof.pbi"
  IncludeFile "d3dx9mesh.pbi"
  IncludeFile "d3dx9shader.pbi"
  IncludeFile "d3dx9effect.pbi"
  IncludeFile "d3dx9tex.pbi"
  IncludeFile "d3dx9shape.pbi"
  IncludeFile "d3dx9anim.pbi"
  
  
  ;// Errors
  #_FACDD = $876
  
  Macro MAKE_DDHRESULT(code)
    MAKE_HRESULT(1, #_FACDD, code)
  EndMacro
  
  Enumeration
    #D3DXERR_CANNOTMODIFYINDEXBUFFER = MAKE_DDHRESULT(2900)
    #D3DXERR_INVALIDMESH = MAKE_DDHRESULT(2901)
    #D3DXERR_CANNOTATTRSORT = MAKE_DDHRESULT(2902)
    #D3DXERR_SKINNINGNOTSUPPORTED = MAKE_DDHRESULT(2903)
    #D3DXERR_TOOMANYINFLUENCES = MAKE_DDHRESULT(2904)
    #D3DXERR_INVALIDDATA = MAKE_DDHRESULT(2905)
    #D3DXERR_LOADEDMESHASNODATA = MAKE_DDHRESULT(2906)
    #D3DXERR_DUPLICATENAMEDFRAGMENT = MAKE_DDHRESULT(2907)
    #D3DXERR_CANNOTREMOVELASTITEM	= MAKE_DDHRESULT(2908)
  EndEnumeration
  Macro D3DXERR
   l
  EndMacro

CompilerEndIf ;//__D3DX9_H__
Avatar de l’utilisateur
GallyHC
Messages : 1703
Inscription : lun. 17/déc./2007 12:44

Re: Routine de chargement des Objets "LWO" (LightWave Objet)

Message par GallyHC »

Bonjour Djes,

De mémoire dans ton code la conversion ASM pour les Endians de fontionne plus depuis la "V5.xx".

GallyHC
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
Avatar de l’utilisateur
djes
Messages : 4252
Inscription : ven. 11/févr./2005 17:34
Localisation : Arras, France

Re: Routine de chargement des Objets "LWO" (LightWave Objet)

Message par djes »

GallyHC a écrit :Bonjour Djes,

De mémoire dans ton code la conversion ASM pour les Endians de fontionne plus depuis la "V5.xx".

GallyHC
Ca ne m'étonne pas ! Tu veux que je regarde ?
Avatar de l’utilisateur
GallyHC
Messages : 1703
Inscription : lun. 17/déc./2007 12:44

Re: Routine de chargement des Objets "LWO" (LightWave Objet)

Message par GallyHC »

Oui, pourquoi pas ^^, perso j'avais fait cela :

Code : Tout sélectionner

Procedure.w EndianToWord(*address.WORD)
; ROUTINE DE CONVERSION ENDIAN VERS WORD.
  Protected result.w

  PokeB(@result + 1, PeekB(*address    ) & $ff)
  PokeB(@result    , PeekB(*address + 1) & $ff)
  ProcedureReturn result

EndProcedure

Procedure.l EndianToLong(number.l)
; ROUTINE DE CONVERDTION ENDIAN VERS LONG.
  ProcedureReturn (number & $ff) << 24 + (number & $ff00) << 8 + (number >> 8) & $ff00 + (number >> 24) & $ff

EndProcedure

Procedure.f EndianToFloat(number.l)
; ROUTINE DE CONVERDTION ENDIAN VERS FLOAT.
  Define fvalue.f

  number = ((number >>  8) & $00ff00ff) | ((number <<  8) & $ff00ff00)
  number = ((number >> 16) & $0000ffff) | ((number << 16) & $ffff0000)
  MoveMemory(@number, @fvalue, 4)
  ProcedureReturn fvalue

EndProcedure
Mais je pense que tu peux faire beaucoup mieux que moi. En gros il faut "Endian vers Long", "Endian vers Word" et "Endian vers Float".

Merci d'avance,
GallyHC
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
Avatar de l’utilisateur
djes
Messages : 4252
Inscription : ven. 11/févr./2005 17:34
Localisation : Arras, France

Re: Routine de chargement des Objets "LWO" (LightWave Objet)

Message par djes »

Voilà ; j'ai mis (mais pas testé) la version x64 et la version x86. J'ai aussi changé le nom des procédures pour que ce soit plus correct (endian seul ne veut rien dire pour le nom d'une procédure=>big endian).

Code : Tout sélectionner

Procedure.w BigEndianToWord(*address.WORD)
  ; ROUTINE DE CONVERSION BIG ENDIAN VERS WORD.
  
  CompilerIf #PB_Processor_x86 
    EnableASM
    XOr eax, eax
    MOV ax,word [p.p_address] 															;convert endians
    XCHG ah,al 
    ProcedureReturn
    DisableASM
  CompilerElseIf #PB_Processor_x64
    EnableASM
    XOr rax, rax
    MOV ax,word [p.p_address] 															;convert endians
    XCHG ah,al 
    ProcedureReturn
    DisableASM
  CompilerElse
    Protected result.w
    PokeB(@result + 1, PeekB(*address    ) & $ff)
    PokeB(@result    , PeekB(*address + 1) & $ff)
    ProcedureReturn result
  CompilerEndIf
  
EndProcedure

Procedure.l BigEndianToLong(number.l)
  ; ROUTINE DE CONVERSION BIG ENDIAN VERS LONG.
  
  CompilerIf #PB_Processor_x86 
    EnableASM
    mov eax, [p.v_number]
    BSWAP eax
    ProcedureReturn
    DisableASM
  CompilerElseIf #PB_Processor_x64
    EnableASM
    mov rax, [p.v_number]
    BSWAP rax
    ProcedureReturn
    DisableASM
  CompilerElse
    ProcedureReturn (number & $ff) << 24 + (number & $ff00) << 8 + (number >> 8) & $ff00 + (number >> 24) & $ff
  CompilerEndIf
  
EndProcedure

Procedure.f BigEndianToFloat(number.l)
  ; ROUTINE DE CONVERSION BIG ENDIAN VERS FLOAT.
  
  Define fvalue.f
  
  CompilerIf #PB_Processor_x86 
    EnableASM
    mov eax, [p.v_number]
    BSWAP eax
    mov [p.v_fvalue], eax
    DisableASM
  CompilerElseIf #PB_Processor_x64
    EnableASM
    mov rax, [p.v_number]
    BSWAP rax
    mov [p.v_fvalue], rax
    DisableASM
  CompilerElse
    number = ((number >>  8) & $00ff00ff) | ((number <<  8) & $ff00ff00)
    number = ((number >> 16) & $0000ffff) | ((number << 16) & $ffff0000)
    MoveMemory(@number, @fvalue, 4)
  CompilerEndIf
  
  ProcedureReturn fvalue
  
EndProcedure
Avatar de l’utilisateur
GallyHC
Messages : 1703
Inscription : lun. 17/déc./2007 12:44

Re: Routine de chargement des Objets "LWO" (LightWave Objet)

Message par GallyHC »

Bonjour Djes,

Merci, J'ai tester pour x86 et x64 et cela fonctionne très bien. Et merci pour la correction BigEndian ^^.

GallyHC
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
Répondre