Skip to content

Commit

Permalink
Imported verts with two weights are now normalized
Browse files Browse the repository at this point in the history
  • Loading branch information
pudingus committed Jul 29, 2020
1 parent c403573 commit 39f1476
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 55 deletions.
59 changes: 27 additions & 32 deletions mafia_4ds/export_mafia_4ds.ms
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ struct WeightedVertex (
vertid
)

fn isNodeDescendantOf node node2 = (
while node.parent != undefined and node.parent != node2 do (
node = node.parent
)
node.parent == node2
)

fn ExtractWeights mnode = (

local lodnodes = copy mnode.lods #noMap
Expand Down Expand Up @@ -405,52 +412,40 @@ fn ExtractWeights mnode = (

boneid = skinBoneIds[id]
)
else (

else (
local id1 = skinOps.GetVertexWeightBoneID bskin i 1
local id2 = skinOps.GetVertexWeightBoneID bskin i 2

local globBoneId1 = skinBoneIds[id1]
local globBoneId2 = skinBoneIds[id2]
local globBoneId2 = skinBoneIds[id2]

local useId
local boneNode1 = boneNodes[globBoneId1]
local boneNode2 = boneNodes[globBoneId2]

if parentBoneIds[globBoneId1] == globBoneId2 then (
local weight1 = skinOps.GetVertexWeight bskin i 1
local weight2 = skinOps.GetVertexWeight bskin i 2

if isNodeDescendantOf boneNode1 boneNode2 then (
useId = 1
weight = weight1
boneid = globBoneId1
)
else if parentBoneIds[globBoneId2] == globBoneId1 then (
useId = 2
)
else if parentBoneIds[globBoneId1] == 0 and parentBoneIds[globBoneId2] != 0 then (
else if isNodeDescendantOf boneNode2 boneNode1 then (
useId = 2
weight = weight2
boneid = globBoneId2
)
else if parentBoneIds[globBoneId2] == 0 and parentBoneIds[globBoneId1] != 0 then (
useId = 1
)

if useId == undefined then (
local weight1 = skinOps.GetVertexWeight bskin i 1
local weight2 = skinOps.GetVertexWeight bskin i 2

if weight1 > weight2 then (
weight = weight1
boneid = globBoneId1
else (
if weight2 > weight1 then (
weight = weight2
boneid = globBoneId2
)
else (
weight = weight2
boneid = globBoneId2
weight = weight1
boneid = globBoneId1
)
)
else (
weight = skinOps.GetVertexWeight bskin i useId
if useId == 1 then boneId = globBoneId1
else boneId = globBoneId2
)
)

-- local boneNode = skinOps.GetBoneNode bskin boneid
-- local handle = boneNode.inode.handle
-- boneid = boneHandleIds[handle]
)
)

wv = WeightedVertex()
Expand Down
30 changes: 8 additions & 22 deletions mafia_4ds/import_mafia_4ds.ms
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,12 @@ struct TBuffer (
mskinsArrays = #(),
skinNodesArrays = #(),
boneNodes = #(), --sorted in boneid order
bones_ids = #(),
mtargets = #(),
targetNodes = #()
)

fn CreateSkins buffer = (
local boneNodes = buffer.boneNodes
local bones_ids = buffer.bones_ids

for s = 1 to buffer.mskinsArrays.count do (
local mskins = buffer.mskinsArrays[s]
Expand All @@ -391,22 +389,12 @@ fn CreateSkins buffer = (
)
)

for i = 1 to nnode.numverts do (
skinOps.unNormalizeVertex oskin i true
)

local vertId = 1

for i = 1 to mskin.vgroups.count do (
local grp = mskin.vgroups[i]
local boneid1 = i
local boneid2 = grp.boneId + 1

local parnode = boneNodes[boneid1].parent
local parid
if parnode != undefined then (
parid = bones_ids[parnode.inode.handle]
)
local boneid1 = i
local boneid2 = grp.boneId

for j = 1 to grp.numW1Verts do (
local weight = 1.0
Expand All @@ -415,11 +403,12 @@ fn CreateSkins buffer = (
vertId += 1
)

for weight in grp.weights do (
for weight in grp.weights do (
if boneid2 == 0 then skinOps.unNormalizeVertex oskin vertId true
skinOps.SetVertexWeights oskin vertId boneid1 weight

if parid != undefined then (
skinOps.SetVertexWeights oskin vertId parid (1.0 - weight)
if boneid2 != 0 then (
skinOps.SetVertexWeights oskin vertId boneid2 (1.0 - weight)
)

vertId += 1
Expand Down Expand Up @@ -514,12 +503,9 @@ fn CreateObjects mobjects = (
10: (
local mbone = mobj.definitions[1]
nnode = CreateBone mbone mobj
Layers.AddTo nnode "Bones"

buffer.bones_ids[nnode.inode.handle] = mbone.boneId+1

buffer.boneNodes[mbone.boneId+1] = nnode
Layers.AddTo nnode "Bones"

buffer.boneNodes[mbone.boneId+1] = nnode

--format "% | objId: % | boneid: %\n" mobj.name i mbone.boneid
)
Expand Down
2 changes: 1 addition & 1 deletion mafia_4ds/ui_mafia_4ds.ms
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ utility MafiaTools "Mafia 4ds Import/Export"
--button btnBitmapPaths "Texture paths..." align:#left

label bout "by pudingus" offset:[0,20]
label version "v0.4.2-preview"
label version "v0.4.2"

on btnImport pressed do
(
Expand Down

0 comments on commit 39f1476

Please sign in to comment.