mde helper tool

Indította fabtam11, 2018-10-21, 22:03:13

Üdv
Valaki találkozott már a sima nem ricky92-féle mde helper toollal?
Ha igen, akkor képes lenne nekem ellinkelni? Köszi!  ::)

Remélem erre gondósz:
[spoiler].ms-be mencsd le ::)[/spoiler]
/*************************************************************************

Metin2 MDE Tool Version 2.0 by ricky92

Copyright © 2012-2014 Riccardo Sabbatini (ricky92 / [email protected])

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

**************************************************************************/

global MDE_dialog

MacroScript Load_MDE category:"MDE Tool" buttonText:"Import MDE file" tooltip:"Import MDE file"
(
fn ReadFixedString f maxLen =
(
local retStr = ""
local char = 0
for i = 1 to maxLen while (char != 0 or i == 1) do
(
char = ReadByte f #unsigned
if char != 0 do retStr += bit.IntAsChar(char)
)
fseek f (maxLen - 1 - retStr.count) #seek_cur
retStr
)

fName = getOpenFileName types:"MDE Files (*.mde)|*.mde"
if fName != undefined do
(
f = fopen fName "rb"
if f != undefined do
(
headerText = ReadFixedString f 11
case (headerText) of
(
"EffectData":
(
numMeshes = ReadLong f
numFrames = (ReadLong f) - 1

animationRange = interval 0 numFrames

for meshIdx = 1 to numMeshes do
(
resName = ReadFixedString f 32
resPath = ReadFixedString f 128

vertexCount = ReadLong f
indexCount = ReadLong f
facesCount = indexCount / 3
UVMapCount = ReadLong f

opacity = ReadFloat f

vertList = #()
facesList = #()
uvMapList = #()
uvFacesList = #()

for vertIdx = 1 to vertexCount do
(
vertX = ReadFloat f
vertY = ReadFloat f
vertZ = ReadFloat f
append vertList [vertX, vertY, vertZ]
)

for faceIdx = 1 to facesCount do
(
face1 = (ReadLong f) + 1
face2 = (ReadLong f) + 1
face3 = (ReadLong f) + 1
append facesList [face1, face2, face3]
)

disableSceneRedraw()
suspendEditing()

obj = mesh vertices:vertList faces:facesList name:resName

obj.pivot = obj.center

with undo off
(
setNumTVerts obj UVMapCount

for UVIdx = 1 to UVMapCount do
(
tu = ReadFloat f
tv = ReadFloat f
setTVert obj UVIdx tu tv 0.0
)

buildTVFaces obj

for UVFaceIdx = 1 to facesCount do
(
uvface1 = (ReadLong f) + 1
uvface2 = (ReadLong f) + 1
uvface3 = (ReadLong f) + 1
setTVFace obj UVFaceIdx uvface1 uvface2 uvface3
)

mat = standardMaterial name:resName
if MDE_dialog == undefined or MDE_dialog.chkMaterialBlend.checked do
(
extArr = filterString resPath "."
if extArr.count > 0 do
(
fExt = extArr[extArr.count]
bBlend = bitmapTexture name:(resName+"_blend") fileName:resPath
mat.opacityMap = bBlend

if fExt == "jpg" or fExt == "jpeg" then
(
bBlend.alphasource = 1
bBlend.monoOutput = 0
)
else
(
bBlend.alphasource = 0
bBlend.monoOutput = 1
)
)
--messageBox("Material should be blended! Ext: "+(subString resName -3 3))
)

bTex = bitmapTexture name:(resName+"_diff") fileName:resPath

mat.opacity = opacity * 100.0

mat.diffuseMap = bTex
mat.twoSided = true

showTextureMap mat on

obj.material = mat

unwrap = Unwrap_UVW()

addModifier obj unwrap

select obj

with animate on
(
for frameIdx = 1 to numFrames do
(
at time frameIdx
(
opacity = ReadFloat f
mat.opacity = opacity * 100.0

for vertIdx = 1 to vertexCount do
(
vertX = ReadFloat f
vertY = ReadFloat f
vertZ = ReadFloat f
meshOp.setVert obj #(vertIdx) [vertX, vertY, vertZ]
)

for faceIdx = 1 to facesCount do
(
face1 = (ReadLong f) + 1
face2 = (ReadLong f) + 1
face3 = (ReadLong f) + 1
/* The following line can work only if no modifiers
    are present on the mesh, but this is not the case.
    However, it seems to be unnecessary, as the faces
    should always be the same */
-- setFace obj faceIdx [face1, face2, face3]
)

-- Workaround for vertex animation... no idea why, but it works. Thanks to martysama0134 for this.
setFaceSelection obj (getFaceSelection obj) keep:true

for UVIdx = 1 to UVMapCount do
(
tu = ReadFloat f
tv = ReadFloat f
unwrap.SetVertexPosition frameIdx UVIdx [tu, tv, 0.0]
)

for UVFaceIdx = 1 to facesCount do
(
uvface1 = (ReadLong f) + 1
uvface2 = (ReadLong f) + 1
uvface3 = (ReadLong f) + 1
meshOp.setMapFace obj 1 UVFaceIdx [uvface1, uvface2, uvface3]
)
) -- at time i
) -- for numFrames
) -- animate
) -- undo off
clearSelection()
resumeEditing()
enableSceneRedraw()

/* Seems to be unnecessary, as standard display looks better than HW one
if (((maxVersion())[1] / 1000) >= 12) do
(
vss = maxops.getViewportShadingSettings()
vss.ActivateViewportShading = true
)*/
) -- for numMeshes
)
"MDEData002":
(
messageBox("MDE Type 2 currently unsupported.")
)
default:
(
messageBox("Unsupported header for MDE file (\""+headerText+"\").")
)
) -- case (headerText)
) -- f != undefined
) -- fName != undefined
)

MacroScript Save_MDE category:"MDE Tool" buttonText:"Export MDE file" tooltip:"Export MDE file"
(
fn WriteFixedString f str maxLen =
(
if str.count >= maxLen do
(
str = substring str 1 (maxLen - 1)
)
WriteString f str
remainingBytes = maxLen - 1 - str.count
for i = 1 to remainingBytes do WriteByte f 0
)

fName = getSaveFilename types:"MDE Files (*.mde)|*.mde"
if fName != undefined do
(
f = fopen fName "wb"
if f != undefined do
(
WriteString f "EffectData"
meshes = for i in $* where ((classOf i) == editable_mesh and not i.isHidden) collect i
WriteLong f meshes.count
WriteLong f (animationRange.end + 1)

for k = 1 to meshes.count do
(
obj = meshes[k]
WriteFixedString f obj.name 32
texName = ""
if obj.material != undefined and obj.material.diffuseMap != undefined and obj.material.diffuseMap.fileName != undefined do
texName = obj.material.diffuseMap.fileName
WriteFixedString f texName 128

numVerts = getNumVerts obj
numFaces = getNumFaces obj
numUVMap = getNumTVerts obj

WriteLong f numVerts
WriteLong f (numFaces * 3)
WriteLong f numUVMap

for j = 0 to animationRange.end do
(
at time j
(
with undo off
(
snap = snapshot obj
currentOpacity = 1.0
if obj.material != undefined do
currentOpacity = obj.material.opacity / 100.0
WriteFloat f currentOpacity
for i = 1 to numVerts do
(
vertex = getVert snap i
WriteFloat f vertex.X
WriteFloat f vertex.Y
WriteFloat f vertex.Z
)

for i = 1 to numFaces do
(
face = getFace snap i
WriteLong f ((face.X as integer) - 1)
WriteLong f ((face.Y as integer) - 1)
WriteLong f ((face.Z as integer) - 1)
)

for i = 1 to numUVMap do
(
TVertex = getTVert snap i
WriteFloat f TVertex.X
WriteFloat f TVertex.Y
)

for i = 1 to numFaces do
(
UVFace = getTVFace snap i
WriteLong f ((UVFace.X as integer) - 1)
WriteLong f ((UVFace.Y as integer) - 1)
WriteLong f ((UVFace.Z as integer) - 1)
)
delete snap
)
)
)
) -- for meshes.count
fclose f
)
) -- fName != undefined
)

function MDE_help =
(
utility MDE_helpDialog "Metin2 MDE Tool by ricky92 - Help"
(
label helpTextLn1 "The MDE file format allows to export meshes to be" pos: [15, 10]
label helpTextLn2 "used in Metin2 effects." pos: [15, 25]
label helpTextLn3 "It has support for vertex (almost any regular animation" pos: [15, 40]
label helpTextLn4 "can be automatically converted to a vertex animation)" pos: [15, 55]
label helpTextLn5 "and UV animations, but due to its format the resulting" pos: [15, 70]
label helpTextLn6 "file can easily get too big, so vertices and frame" pos: [15, 85]
label helpTextLn7 "count should be kept to the lowest possible" pos: [15, 100]
label helpTextLn8 "(or acceptable) values." pos: [15, 115]
label helpTextLn9 "Only Editable Meshes will be exported!" pos: [15, 135]
label copyright "Copyright © ricky92" align:#center offset: [0, 20]
)
createDialog MDE_helpDialog 300 200
)
m
function MDE_GUI =
(
utility MDE_dialog "Metin2 MDE Tool by ricky92"
(
checkbox chkMaterialBlend "Make textures transparent" align:#center height: 20 checked: on
button btnImport "Import MDE" align:#center width: 200 height: 20
button btnExport "Export MDE" align:#center width: 200 height: 20
button btnHelp "Help" align:#center width: 45 height: 18

on btnImport pressed do
(
macros.run "MDE Tool" "Load_MDE"
)

on btnExport pressed do
(
macros.run "MDE Tool" "Save_MDE"
)

on btnHelp pressed do
(
MDE_help()
)
)
createDialog MDE_dialog width: 230
)

MDE_GUI()


Nekem semmi baja pedig :o ???
Tök jól tud impozni meg expozni is ::) :-X