Skip to content

Commit

Permalink
Fix skin exporting on older versions
Browse files Browse the repository at this point in the history
  • Loading branch information
pudingus committed Jul 28, 2020
1 parent 2367bc1 commit cd0b427
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
2 changes: 1 addition & 1 deletion mafia_4ds/4ds.ms
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ fn Write4ds f m4ds = (
WriteObject f mobj
)

WriteByte f false
WriteByte f 0
)

fn WriteHeader f = (
Expand Down
41 changes: 28 additions & 13 deletions mafia_4ds/export_mafia_4ds.ms
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ fn ExtractMaterials = (
mmaterials
)

local boneArray = #()
local boneNodes = #()
local boneNodeNames = #()
local boneHandleIds = #()

fn CollectNodes = (
Expand Down Expand Up @@ -274,9 +275,10 @@ fn CollectNodes = (
--format "obj:% type:% \n" obj.name nodeType

if nodeType == #bone then (
append boneArray obj
append boneNodes obj
append boneNodeNames obj.name
local handle = obj.inode.handle
boneHandleIds[handle] = boneArray.count
boneHandleIds[handle] = boneNodes.count
)
)

Expand Down Expand Up @@ -363,11 +365,21 @@ fn ExtractWeights mnode = (

local lodWeights = #()

for lodnode in lodnodes do (
for lodnode in lodnodes do (
local bskin = GetModByClass lodnode Skin

local weights = #()
max modify mode
modPanel.setCurrentObject bskin

local skinBoneIds = #()
local numbones = skinOps.GetNumberBones bskin
for i = 1 to numbones do (
local boneName = skinOps.GetBoneName bskin i 0
local globBoneId = findItem boneNodeNames boneName
skinBoneIds[i] = globBoneId
)

local weights = #()
local numverts = skinOps.GetNumberVertices bskin
for i = 1 to numverts do (

Expand All @@ -377,11 +389,16 @@ fn ExtractWeights mnode = (
local boneid = 9999
if count > 0 then (
weight = skinOps.GetVertexWeight bskin i 1
boneid = skinOps.GetVertexWeightBoneID bskin i 1
local id = skinOps.GetVertexWeightBoneID bskin i 1

boneid = skinBoneIds[id]


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


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

wv = WeightedVertex()
Expand Down Expand Up @@ -414,11 +431,9 @@ fn ExtractSkin mnode lodWeights = (
mskin.dmin = [-range, -range, -range]
mskin.dmax = [range, range, range]

local bskin = GetModByClass lodnode Skin

local groups = #()

for boneNode in boneArray do (
for boneNode in boneNodes do (
local grp = TSkinVertexGroup()
grp.numW1Verts = 0

Expand Down Expand Up @@ -451,7 +466,7 @@ fn ExtractSkin mnode lodWeights = (
for i = 1 to groups.count do (
local grp = groups[i]
local boneId = i
local boneNode = boneArray[boneId]
local boneNode = boneNodes[boneId]

if (grp.numW1Verts > 0) or (grp.weights.count > 0) then (

Expand Down
8 changes: 5 additions & 3 deletions mafia_4ds/import_mafia_4ds.ms
Original file line number Diff line number Diff line change
Expand Up @@ -670,16 +670,18 @@ fn Main = (
CreateMaterials m4ds.materials
local buffer = CreateObjects m4ds.objects

if MafiaTools.importNormals.checked == true then (
ImportNormals()
)

--LinkTargets buffer

CreateSkins buffer

Layers.Hide #("Disabled")
--Layers.HideLods #{1..9}

if MafiaTools.importNormals.checked == true then (
ImportNormals()
)

)

local end = timeStamp()
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.0"
label version "v0.4.1"

on btnImport pressed do
(
Expand Down

0 comments on commit cd0b427

Please sign in to comment.