Skip to content

Commit

Permalink
Material fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pudingus committed Jun 28, 2020
1 parent cdb07a0 commit 550c243
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
58 changes: 38 additions & 20 deletions mafia_4ds/export_mafia_4ds.ms
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,28 @@ fn WriteMaterials f =
if mat.reflectionMapEnable then (
WriteFloat f (mat.reflectionMapAmount / 100.0)

if mat.reflectionMap != undefined then (
if (mat.reflectionMap != undefined) and (classof mat.reflectionMap == Bitmaptexture) then (
local filename = filenameFromPath mat.reflectionMap.filename
WriteText f filename
)
else WriteByte f 0
)

--diffuse map
if (mat.diffuseMapEnable) and (diffuseMap != undefined) then (
if (mat.diffuseMapEnable) and (mat.diffuseMap != undefined) and (classof mat.diffuseMap == Bitmaptexture) then (

local filename = filenameFromPath mat.diffuseMap.filename
WriteText f filename

--alpha map
if mat.opacityMapEnable then (
local filename = filenameFromPath mat.opacityMap.filename
WriteText f filename
if (mat.opacityMapEnable) and (filename.count > 0) then (
--alpha map
if (mat.opacityMap != undefined) and (classof mat.opacityMap == Bitmaptexture) then (
local filename = filenameFromPath mat.opacityMap.filename
WriteText f filename
)
else WriteByte f 0
)

)
else WriteByte f 0

Expand Down Expand Up @@ -162,23 +167,27 @@ fn WriteMaterials f =
if mat.envMapEnable then (
WriteFloat f (mat.envMapAmount / 100.0)

if mat.envMap != undefined then (
if (mat.envMap != undefined) and (classof mat.envMap == Bitmaptexture) then (
local filename = filenameFromPath mat.envMap.filename
WriteText f filename
)
else WriteByte f 0
)

--diffuse map
if (mat.diffuseMapEnable) and (diffuseMap != undefined) then (
if (mat.diffuseMapEnable) and (mat.diffuseMap != undefined) and (classof mat.diffuseMap == Bitmaptexture) then (

local filename = filenameFromPath mat.diffuseMap.filename
WriteText f filename

--alpha map
if mat.alphaMapEnable then (
local filename = filenameFromPath mat.alphaMap.filename
WriteText f filename
)

if (mat.alphaMapEnable) and (filename.count > 0) then (
--alpha map
if (mat.alphaMap != undefined) and (classof mat.alphaMap == Bitmaptexture) then (
local filename = filenameFromPath mat.alphaMap.filename
WriteText f filename
)
else WriteByte f 0
)
)
else WriteByte f 0

Expand All @@ -190,9 +199,7 @@ fn WriteMaterials f =
WriteLong f 0
WriteLong f 0
)
)


)
)

)
Expand Down Expand Up @@ -529,7 +536,11 @@ fn CollectLodsCompat mobj = (

for i = 1 to lodmesh.numVerts do (
local vert = (in coordsys local getVert lodmesh i) + lodnode.objectOffsetPos
local tvert = getTVert lodmesh i
local tvert = [0,0,0]
if meshop.getMapsupport lodmesh 1 then (
tvert = getTVert lodmesh i
)

local normal

if normMod != undefined then (
Expand Down Expand Up @@ -582,12 +593,19 @@ fn CollectVerts lodmesh lodnode = (

for i = 1 to lodmesh.numfaces do (
local face = getFace lodmesh i
local tface = meshop.getMapFace lodmesh 1 i
local tface
if meshop.getMapsupport lodmesh 1 then (
tface = meshop.getMapFace lodmesh 1 i
)

local rnormals = meshop.getFaceRNormals lodmesh i

for v = 1 to 3 do (
local pos = (in coordsys local getVert lodmesh (face[v] as integer)) + lodnode.objectOffsetPos
local uv = getTVert lodmesh (tface[v] as integer)
local uv = [0,0,0]
if tface != undefined then (
uv = getTVert lodmesh (tface[v] as integer)
)
local normal
if normmod != undefined then (
local n = EN_getnormalid i v node:lodnode
Expand Down
8 changes: 4 additions & 4 deletions mafia_4ds/import_mafia_4ds.ms
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ fn AddToLodLayer lodId obj = (
)

fn ReadText f = (
local len = ReadByte f
local len = ReadByte f #unsigned

local result
if len > 0 then (
local fmt = "%"
local ss = StringStream ""
for i = 1 to len do (
format fmt (bit.intAsChar(ReadByte f)) to:ss
format fmt (bit.intAsChar(ReadByte f #unsigned)) to:ss
)
result = ss as string
)
Expand Down Expand Up @@ -730,8 +730,8 @@ fn ReadObjects f = (
if objectType == 1 do --visual object
(
visualType = ReadByte f
renderFlags = ReadByte f
renderFlags2 = ReadByte f
renderFlags = ReadByte f #unsigned
renderFlags2 = ReadByte f #unsigned
)
--general block

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 Tools v4"
--button btnBitmapPaths "Texture paths..." align:#left

label bout "by pudingus" offset:[0,20]
label version "v0.3.0"
label version "v0.3.1"

on btnImport pressed do
(
Expand Down

0 comments on commit 550c243

Please sign in to comment.