I know how BoneSys.CreateBone or skinOps.ReplaceVertexWeights work,what I don't understand are something like these(part of zaramot's script)shakotay2 wrote: Then you could read some MaxScript online help to understand functions like
BoneSys.CreateBone and skinOps.ReplaceVertexWeights for example.
Code: Select all
maxweight = 0
if(W1_array[a].Weight1 != 0) then
maxweight = maxweight + W1_array[a].Weight1
if(W1_array[a].Weight2 != 0) then
maxweight = maxweight + W1_array[a].Weight2
if(W1_array[a].Weight3 != 0) then
maxweight = maxweight + W1_array[a].Weight3
if(W1_array[a].Weight4 != 0) then
maxweight = maxweight + W1_array[a].Weight4
.x format file use 4x4 matrix,but seems 3ds Max use 4x3 matrix,something like this
Code: Select all
print $leg_left_ankle.transform
(matrix3 [-0.610972,0.791652,0] [-0.791652,-0.610972,0] [0,0,1] [17.6693,2e-006,1e-006])
I found these from zaramot's script(hope he won't blame me for this,LOL)
Code: Select all
c11 = ReadFloat f; c12 = ReadFloat f; c13 = ReadFloat f; c14 = ReadFloat f
c21 = ReadFloat f; c22 = ReadFloat f; c23 = ReadFloat f; c24 = ReadFloat f
c31 = ReadFloat f; c32 = ReadFloat f; c33 = ReadFloat f; c34 = ReadFloat f
c41 = ReadFloat f; c42 = ReadFloat f; c43 = ReadFloat f; c44 = ReadFloat f
tfm = matrix3 [c11,c12,c13] [c21,c22,c23] [c31,c32,c33] [c41,c42,c43]
tfm=(scaleMatrix [-1,-1,1])*tfm
newBone = bonesys.createbone \
tfm.row4 \
(tfm.row4 + 0.01 * (normalize tfm.row1)) \
(normalize tfm.row3)
newBone.name = BoneName
newBone.width = 0.01
newBone.height = 0.01
newBone.transform = tfm
newBone.setBoneEnable false 0
newBone.wirecolor = white
newbone.showlinks = true
newBone.pos.controller = TCB_position ()
newBone.rotation.controller = TCB_rotation ()
But if I copy this part to my script,bone seems weird
I also got another question.
Seems there are 2 types of matrix in x.format files?
Here's matrix from Frame
Code: Select all
Frame root_ground {
FrameTransformMatrix {
-0.000000,1.000000,0.000000,0.000000,-0.000000,-0.000000,1.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,1.000000;;
}
Frame root_hips {
FrameTransformMatrix {
-0.000000,-0.000000,1.000000,0.000000,-0.000000,1.000000,0.000000,0.000000,-1.000000,0.000000,-0.000000,0.000000,46.984253,-0.000011,0.000005,1.000000;;
}
Code: Select all
template SkinWeights {
<6f0d123b-bad2-4167-a0d0-80224f25fabb>
STRING transformNodeName;
DWORD nWeights;
array DWORD vertexIndices[nWeights];
array FLOAT weights[nWeights];
Matrix4x4 matrixOffset
}
.........................
1.000000,
1.000000,
1.000000,
1.000000,
1.000000,
1.000000,
1.000000,
1.000000,
1.000000,
1.000000,
1.000000,
1.000000,
1.000000,
1.000000,
1.000000;
-1.000000,0.000031,-0.000031,0.000000,-0.000031,-0.000000,1.000000,0.000000,0.000031,1.000000,-0.000000,0.000000,-34.073386,0.181064,-62.320659,1.000000;;
}
I also tried to import these SkinWeights matrix to Max as bone,but it still looks weird
Here's my new script,it can read bone data,weights data and bones' hierarchy now
Code: Select all
if (heapSize < 200000) then
heapSize = 2000000 -- allow ~ 40 MB instead of just 7.5 MB. Prevents "Runtime Error: Out of scripter memory"
fname = getOpenFileName \
caption:"Select a X format file" \
types:"DirectX(.x)|*.x" \
historyCategory:"DirectXObjectPresets"
f = openfile fname
Vert_array = #()
Face_array = #()
Normal_array = #()
UV_array = #()
vertexIndice_array = #()
weights_array = #()
bone_stack = #()
RDL= readline f
BoneName = ""
--Read texture name
while (RDL != " TextureFilename {") do (RDL = readline f)
texture_name = readvalue f
while (RDL != "Frame Object001 {") do
(
RDL = readline f
--Read bone name
if (findString RDL "Frame" != undefined and findString RDL "TransformMatrix" == undefined) do
(
start = (findString RDL "Frame")+6
len = RDL.count-start-1
BoneName = substring RDL start len
append bone_stack BoneName
)
--Read bone data and create bone
if (findString RDL "FrameTransformMatrix" != undefined) do
(
c11 = readvalue f; c12 = readvalue f; c13 = readvalue f; c14 = readvalue f
c21 = readvalue f; c22 = readvalue f; c23 = readvalue f; c24 = readvalue f
c31 = readvalue f; c32 = readvalue f; c33 = readvalue f; c34 = readvalue f
c41 = readvalue f; c42 = readvalue f; c43 = readvalue f; c44 = readvalue f
tfm = matrix3 [c11,c12,c13] [c21,c22,c23] [c31,c32,c33] [c41,c42,c43]
tfm=(scaleMatrix [-1,-1,1])*tfm
newBone = bonesys.createbone \
tfm.row4 \
(tfm.row4 + 0.01 * (normalize tfm.row1)) \
(normalize tfm.row3)
newBone.name = BoneName
newBone.width = 0.01
newBone.height = 0.01
newBone.transform = tfm
newBone.setBoneEnable false 0
newBone.wirecolor = white
newbone.showlinks = true
newBone.pos.controller = TCB_position ()
newBone.rotation.controller = TCB_rotation ()
readline f
readline f
)
--Create bones' hierarchy
if (findString RDL "}" != undefined and (bone_stack.count > 1)) do
(
(getnodebyname (bone_stack[bone_stack.count])).parent = getnodebyname (bone_stack[bone_stack.count-1])
deleteItem bone_stack bone_stack.count
)
)
while (RDL != " Mesh {") do (RDL = readline f)
mesh_count = readvalue f
for i=1 to mesh_count do
(
x = readvalue f
y = readvalue f
z = readvalue f
append Vert_array [x,z,y]
readline f
)
face_count = readvalue f
for i=1 to face_count do
(
readvalue f
p1 = readvalue f
p2 = readvalue f
p3 = readvalue f
append Face_array [p1+1,p2+1,p3+1]
readline f
)
while (RDL != " MeshNormals {") do (RDL = readline f)
normal_count = readvalue f
for i=1 to normal_count do
(
nx = readvalue f
ny = readvalue f
nz = readvalue f
append Normal_array [nx,ny,nz]
readline f
)
while (RDL != " MeshTextureCoords {") do (RDL = readline f)
UV_count = readvalue f
for i=1 to UV_count do
(
u = readvalue f
v = readvalue f
append UV_array [u,1-v,0]
readline f
)
--Read weights
while (eof f == false) do
(
RDL = readline f
if (RDL == " SkinWeights {") do
(
BoneName = readvalue f
weights_number = readvalue f
for i=1 to weights_number do
(
vertexIndice = readvalue f
append vertexIndice_array vertexIndice
)
for i=1 to weights_number do
(
weights = readvalue f
append weights_array weights
)
c11 = readvalue f; c12 = readvalue f; c13 = readvalue f; c14 = readvalue f
c21 = readvalue f; c22 = readvalue f; c23 = readvalue f; c24 = readvalue f
c31 = readvalue f; c32 = readvalue f; c33 = readvalue f; c34 = readvalue f
c41 = readvalue f; c42 = readvalue f; c43 = readvalue f; c44 = readvalue f
)
)
--Build mesh
msh = mesh vertices:Vert_array faces:Face_array
msh.numTVerts = UV_array.count
buildTVFaces msh
for j = 1 to UV_array.count do setTVert msh j UV_array[j]
for j = 1 to face_array.count do setTVFace msh j face_array[j]
close f
--Assign material
texture_path = sysInfo.currentdir
if texture_path[texture_path.count] != "\\" do texture_path += "\\"
texture_path += texture_name
new_mat = StandardMaterial()
new_mat.diffuseMap = Bitmaptex()
new_mat.diffuseMap.filename = texture_path
new_mat.showInViewport = True
msh.Material = new_mat