I was confused and frustrated by FVF settings and values, so I put this together to try to understand them.
This can combine the different constants to return the final integer value of the FVF setting, as revealed by Matrix1's Get Limb FVF() or DKAVM's DK Get Object FVF().
It can also check all possible combinations of the constants to return the combinations which can make up an integer value returned by these functions. So if you want to duplicate one object's FVF in another, this may be useful. Setting the integer value returned by the plugins can work in cases where that integer value represents a unique combination (true of default import value of 338 or of DBP cube primitive's 274). But not all integer values represent unique combinations. Over 50 combinations can return 14, and if you set this integer using Change Object FVF and check with one of the plugins, it will be returned as the 338 default - presumably because 14 is indeterminate as noted. In such a case, you have to specify the combination of hex constants with Change Object FVF. Which is where this could be a useful tool. Hopefully.
I'm not sure whether the different vertex blending constants or UV set constants should be mutually exclusive or not. If anyone knows, let me know. FVF links which I found useful are in the remarks of the code.
My apologies to everyone for forgetting the DBP notification in the thread title when this was initially posted. Assuming the earlier post was deleted for that reason. :blush:
` FVF constants - with value returned by Matrix1 plugin Get FVF Limb
#constant FVF_XYZ = 0x002 `2 untransformed vertex - discludes FVF_XYZRHW
#constant FVF_XYZRHW = 0x004 `4 tranformed vertex - discludes FVFXYZ and FVF_NORMAL
#constant FVF_XYZB1 = 0x006 `6 position data and weighting values for vertex blending matrix calcs
#constant FVF_XYZB2 = 0x008 `8
#constant FVF_XYZB3 = 0x00a `10
#constant FVF_XYZB4 = 0x00c `12
#constant FVF_XYZB5 = 0x00e `338
#constant FVF_NORMAL = 0x010 `16 vertex normal
#constant FVF_PSIZE = 0x020 `32 vertex point size
#constant FVF_DIFFUSE = 0x040 `64 vertex diffuse color
#constant FVF_SPECULAR = 0x080 `128 vertex specular color
#constant FVF_TEX0 = 0x000 `338 Number of texture coordinate sets for vertex, 1 - 8
#constant FVF_TEX1 = 0x100 `256
#constant FVF_TEX2 = 0x200 `512
#constant FVF_TEX3 = 0x300 `768
#constant FVF_TEX4 = 0x400 `1024
#constant FVF_TEX5 = 0x500 `1280
#constant FVF_TEX6 = 0x600 `1536
#constant FVF_TEX7 = 0x700 `1792
#constant FVF_TEX8 = 0x800 `2048
remstart
(Cagedrei's FVF notes)
FVF value is an integer, calculated by specifying FVF constants combined using the bitwise or operation.
The FVF value of the the DBP primitives is 274.
The "default" FVF (covered in Make Memblock From Mesh documentation) is 338.
FVF_XYZ || FVF_NORMAL || FVF_DIFFUSE plus U and V are contained in the default settings.
FVF_XYZ || FVF_NORMAL || FVF_DIFFUSE || FVF_TEX0 || FVF_TEX2 = 338 ??
An imported object will have these defaults applied
FVF_TEX0 can be added to any combination of other constants without altering the total.
FVF integer values can be acquired using Matrix1 Get Limb FVF() or DKAVM's DK Get Object FVF().
FVF values can be set as integer using Convert Object FVF. Most values represent unique combinations
(except for the addition of FVF_TEX0), but some do not. If either FVF_XYZB5 or FVF_TEX0 is set using
Convert Object FVF with the integer value, the object is converted to the 338 default, as shown by checking
with the plugin tools mentioned above. The value of 14 can be returned by multple combinations. In these two
cases (and others which may not represent unique values), the values should be explicated using the hex values.
There are 1048576 possible combinations of the constants.
http://doc.51windows.net/directx9_sdk/graphics/reference/d3d/constants/D3DFVF.htm
http://www.codesampler.com/d3dbook/chapter_05/chapter_05.htm
http://www.flipcode.com/archives/Flexible_Vertex_Format_Generator.shtml
http://www.vbforums.com/showthread.php?t=548692 (Combination code)
remend
dim fvf(20)
dim fvf$(20,2)
fvf(1) = FVF_XYZ
fvf(2) = FVF_XYZRHW
fvf(3) = FVF_XYZB1
fvf(4) = FVF_XYZB2
fvf(5) = FVF_XYZB3
fvf(6) = FVF_XYZB4
fvf(7) = FVF_XYZB5
fvf(8) = FVF_NORMAL
fvf(9) = FVF_PSIZE
fvf(10) = FVF_DIFFUSE
fvf(11) = FVF_SPECULAR
fvf(12) = FVF_TEX0
fvf(13) = FVF_TEX1
fvf(14) = FVF_TEX2
fvf(15) = FVF_TEX3
fvf(16) = FVF_TEX4
fvf(17) = FVF_TEX5
fvf(18) = FVF_TEX6
fvf(19) = FVF_TEX7
fvf(20) = FVF_TEX8
fvf$(1,1) = "FVF_XYZ"
fvf$(2,1) = "FVF_XYZRHW"
fvf$(3,1) = "FVF_XYZB1"
fvf$(4,1) = "FVF_XYZB2"
fvf$(5,1) = "FVF_XYZB3"
fvf$(6,1) = "FVF_XYZB4"
fvf$(7,1) = "FVF_XYZB5"
fvf$(8,1) = "FVF_NORMAL"
fvf$(9,1) = "FVF_PSIZE"
fvf$(10,1) = "FVF_DIFFUSE"
fvf$(11,1) = "FVF_SPECULAR"
fvf$(12,1) = "FVF_TEX0"
fvf$(13,1) = "FVF_TEX1"
fvf$(14,1) = "FVF_TEX2"
fvf$(15,1) = "FVF_TEX3"
fvf$(16,1) = "FVF_TEX4"
fvf$(17,1) = "FVF_TEX5"
fvf$(18,1) = "FVF_TEX6"
fvf$(19,1) = "FVF_TEX7"
fvf$(20,1) = "FVF_TEX8"
fvf$(1,2) = "0x002"
fvf$(2,2) = "0x004"
fvf$(3,2) = "0x006"
fvf$(4,2) = "0x008"
fvf$(5,2) = "0x00a"
fvf$(6,2) = "0x00c"
fvf$(7,2) = "0x00e"
fvf$(8,2) = "0x010"
fvf$(9,2) = "0x020"
fvf$(10,2) = "0x040"
fvf$(11,2) = "0x080"
fvf$(12,2) = "0x000"
fvf$(13,2) = "0x100"
fvf$(14,2) = "0x200"
fvf$(15,2) = "0x300"
fvf$(16,2) = "0x400"
fvf$(17,2) = "0x500"
fvf$(18,2) = "0x600"
fvf$(19,2) = "0x700"
fvf$(20,2) = "0x800"
calc = 0
calc$ = ""
r$ = ""
rsz = 1
dim rs$(rsz)
rs$ = clear_stringarray(rs$,rsz)
combos = 0
do
cls
set cursor 0,0
print "FVF format value calculator"
print
for i=1 to 20
pad$ = ") "
if i < 10 then pad$ = pad$ + " "
fvfv$ = str$(fvf(i))
if len(fvfv$) = 1 then fvfv$ = fvfv$ + " "
if len(fvfv$) = 2 then fvfv$ = fvfv$ + " "
if len(fvfv$) = 3 then fvfv$ = fvfv$ + " "
print i,pad$,fvf$(i,2)," = ",fvfv$," = ",fvf$(i,1)
next i
print
if calc > 0 then print calc$," = ",calc
if r$ <> "" then print r$
if combos > 0 then print "Checked ",combos," different combinations. "
for i=1 to rsz
if rs$(i) <> "" then print rs$(i)
next i
print
print "Enter 0 (zero) to clear calculation"
print "Enter 21 to break an FVF value into its constants"
input "Enter an index from FVF list to calculate (1-20) ",calcE
r$ = "" : combos = 0 : rs$ = clear_stringarray(rs$,rsz)
if calcE > 0 and calcE < 21
calc = calc || fvf(calcE)
if calc$ <> "" then calc$ = calc$ + " || "
calc$ = calc$ + fvf$(calcE,1)
endif
if calcE = 0 then calc = 0 : calc$ = ""
if calcE = 21
input "Enter an FVF value to calculate (divisible by 2) ",calcE
if calcE = 0 then rs$(1) = fvf$(12,1) + " = 0" `Special case.
if calcE > 0 and calcE mod 2 = 0
input "Enter maximum number of returns (1-20) ",rsz
if rsz > 50 or rsz < 1 then rsz = 1
undim rs$()
dim rs$(rsz)
calc = 0 : calc$ = ""
gosub _calculate_fvf
endif
endif
loop
end
_calculate_fvf:
count = 0 : y = array count(fvf())
rs$ = clear_stringarray(rs$,rsz)
for x=0 to (2 ^ y)-1
r$ = dec_to_bin(x,y)
inc combos
if left$(r$,2) <> "11" and (mid$(r$,2) + mid$(r$,8) <> "11")
for i=1 to len(r$)
t$ = mid$(r$,i)
if t$ = "1"
calc = calc || fvf(i)
if calc$ <> "" then calc$ = calc$ + " || "
calc$ = calc$ + fvf$(i,1)
endif
next i
if calc = calcE
inc count,1
rs$(count) = calc$ + " = " + str$(calc)
calc = 0 : calc$ = "" : r$ = ""
if count = rsz then return
endif
calc = 0 : calc$ = ""
endif
next x
if rs$(1) = "" then r$ = "No results found." else r$ = ""
return
function dec_to_bin(x,s)
r$ = ""
for v=0 to s-1
if x and (2 ^ v)
r$ = r$ + "1"
else
r$ = r$ + "0"
endif
next v
endfunction r$
function clear_stringarray(rs$,rsz)
for i=1 to rsz
rs$(i) = ""
next i
endfunction rs$