From 550c243152d96a045ffa64749e7e8f7d89eb291e Mon Sep 17 00:00:00 2001 From: pudingus <39903631+pudingus@users.noreply.github.com> Date: Sun, 28 Jun 2020 14:01:40 +0200 Subject: [PATCH] Material fixes --- mafia_4ds/export_mafia_4ds.ms | 58 +++++++++++++++++++++++------------ mafia_4ds/import_mafia_4ds.ms | 8 ++--- mafia_4ds/ui_mafia_4ds.ms | 2 +- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/mafia_4ds/export_mafia_4ds.ms b/mafia_4ds/export_mafia_4ds.ms index 67705c8..90eeaf6 100644 --- a/mafia_4ds/export_mafia_4ds.ms +++ b/mafia_4ds/export_mafia_4ds.ms @@ -106,7 +106,7 @@ 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 ) @@ -114,15 +114,20 @@ fn WriteMaterials f = ) --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 @@ -162,7 +167,7 @@ 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 ) @@ -170,15 +175,19 @@ fn WriteMaterials f = ) --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 @@ -190,9 +199,7 @@ fn WriteMaterials f = WriteLong f 0 WriteLong f 0 ) - ) - - + ) ) ) @@ -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 ( @@ -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 diff --git a/mafia_4ds/import_mafia_4ds.ms b/mafia_4ds/import_mafia_4ds.ms index 5e29764..d216a18 100644 --- a/mafia_4ds/import_mafia_4ds.ms +++ b/mafia_4ds/import_mafia_4ds.ms @@ -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 ) @@ -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 diff --git a/mafia_4ds/ui_mafia_4ds.ms b/mafia_4ds/ui_mafia_4ds.ms index 038b037..30beb6f 100644 --- a/mafia_4ds/ui_mafia_4ds.ms +++ b/mafia_4ds/ui_mafia_4ds.ms @@ -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 (