Sometimes we want to deal with vertices of unknown format.
Sure we can obtain the #BytesPerVertex, but that tells us nothing about the actual formatting of the fields within a vertex.
Attached is some code which addresses this very problem, by brute-force cracking an unknown FVF.

GetFVFComponentOffset is a function that will return the offset (within each vertex) of a given FVF component, such as "the fourth set of UV values".
If the component is not present in the FVF, it will return -1 for error.
Also attached is an updated with some macros modified to accept variable input, which was required in order to implement FVF cracking.
Posted on 2006-01-18 23:24:31 by Homer
Here's an actual example which uses the code previously posted.

dwNumTexCoordSets dd 0 ;How many sets of UV data in Vertices
dwOffsetTex0 dd 0 ;Offset to each set of UV data in Vertices
dwOffsetTex1 dd 0
dwOffsetTex2 dd 0
dwOffsetTex3 dd 0
dwOffsetTex4 dd 0
dwOffsetTex5 dd 0
dwOffsetTex6 dd 0
dwOffsetTex7 dd 0
dwSizeOfTex0 dd 0 ;Size of each set of UV data in Vertices
dwSizeOfTex1 dd 0
dwSizeOfTex2 dd 0
dwSizeOfTex3 dd 0
dwSizeOfTex4 dd 0
dwSizeOfTex5 dd 0
dwSizeOfTex6 dd 0
dwSizeOfTex7 dd 0


;Fetch the Flexible Vertex Format used by the mesh
mov dwFVF,$ICall (pMesh::ID3DXMesh.GetFVF)

;"Crack the FVF"
;We want to know how many sets of UV data are in the Vertices
;and obtain the Sizeof and Offset to each set.
;There can be as many as 8 sets of UV data per vertex,
;and each set of UV data can vary in size..

invoke GetTexCoordSetsCount,dwFVF
mov dwNumTexCoordSets,eax
.if eax==0
DbgWarning "The Vertices contain NO TEXTURE COORDS"
DbgDec eax,"#TextureCoord Sets in each Vertex"
.if dwNumTexCoordSets>=1
invoke GetFVFComponentOffset,dwFVF,D3DFVF_TEX0,0
mov dwOffsetTex0,eax
invoke GetTexCoordSetSize,dwFVF,0
mov dwSizeOfTex0,eax
.if dwNumTexCoordSets>=2
invoke GetFVFComponentOffset,dwFVF,D3DFVF_TEX1,1
mov dwOffsetTex1,eax
invoke GetTexCoordSetSize,dwFVF,1
mov dwSizeOfTex1,eax
.if dwNumTexCoordSets>=3
invoke GetFVFComponentOffset,dwFVF,D3DFVF_TEX2,2
mov dwOffsetTex2,eax
invoke GetTexCoordSetSize,dwFVF,2
mov dwSizeOfTex2,eax
.if dwNumTexCoordSets>=4
invoke GetFVFComponentOffset,dwFVF,D3DFVF_TEX3,3
mov dwOffsetTex3,eax
invoke GetTexCoordSetSize,dwFVF,3
mov dwSizeOfTex3,eax
.if dwNumTexCoordSets>=5
invoke GetFVFComponentOffset,dwFVF,D3DFVF_TEX4,4
mov dwOffsetTex4,eax
invoke GetTexCoordSetSize,dwFVF,4
mov dwSizeOfTex4,eax
.if dwNumTexCoordSets>=6
invoke GetFVFComponentOffset,dwFVF,D3DFVF_TEX5,5
mov dwOffsetTex5,eax
invoke GetTexCoordSetSize,dwFVF,5
mov dwSizeOfTex5,eax
.if dwNumTexCoordSets>=7
invoke GetFVFComponentOffset,dwFVF,D3DFVF_TEX6,6
mov dwOffsetTex6,eax
invoke GetTexCoordSetSize,dwFVF,6
mov dwSizeOfTex6,eax
.if dwNumTexCoordSets==8
invoke GetFVFComponentOffset,dwFVF,D3DFVF_TEX7,7
mov dwOffsetTex7,eax
invoke GetTexCoordSetSize,dwFVF,7
mov dwSizeOfTex7,eax
DbgDec eax,"Offset to first TexCoordSet in Vertices"

Posted on 2006-01-19 00:09:11 by Homer