m2 col helper script

08/29/2017 18:24 fenix1990#1
Does anyone have this script enabled to export collisions transformed to editable mesh on 3dmax?

this is the original code of anohros

if anyone would be kind enough to configure it to export transformed collisions to editable mesh in 3dmax id be really grateful


Code:
-- Metin2-Collision Helper
-- Version 2012-06-19T23:15
--
-- Copyright © anohros

function ReadCharacters f len =
(
	str = ""
	for i = 1 to len do
	(
		char = ReadByte f #unsigned
		if char != 0 then
		(
			str += bit.intAsChar char
		)
	)
	return (str as string)
)

function WriteCharacters f str len =
(
	for i = 1 to len do
	(
		if i <= str.count then
		(
			WriteByte f (bit.charAsInt str[i])
		)
		else
		(
			WriteByte f 0
		)
	)
)

function ReadQuat f =
(
	q = [ReadFloat f, ReadFloat f, ReadFloat f, ReadFloat f]
	return q
)

function WriteQuat f q =
(
	WriteFloat f q.x
	WriteFloat f q.y
	WriteFloat f q.z
	WriteFloat f q.w
)

function WritePos f m =
(
	WriteFloat f m.position.x
	WriteFloat f m.position.y
	WriteFloat f m.position.z
)

function WriteVert f vert =
(
	WriteFloat f vert.x
	WriteFloat f vert.y
	WriteFloat f vert.z
)

function SetMeshRotationFromQuat m q =
(
	rotate m (quat q[1] q[2] q[3] q[4])
)

function SetMeshSettings m name =
(
	m.name = name
	m.backfaceCull = false
	m.xray = true
	m.showVertexColors = true
	m.vertexColorsShaded = false
)

function ImportCol filename =
(
	try
	(
		f = fopen filename "rb"
		if f != undefined then
		(
			header = ReadString f
			if header == "AttributeData" then
			(
				countOfMeshes = ReadLong f #unsigned
				countOfPlanes = ReadLong f #unsigned
				for meshIdx = 1 to countOfMeshes do
				(
					type = ReadLong f
					name = ReadCharacters f 32
					posX = ReadFloat f
					posY = ReadFloat f
					posZ = ReadFloat f
					m = undefined
					case type of
					(
						-- collision plane
						0:
						(
							width = ReadFloat f
							length = ReadFloat f
							q = ReadQuat f
							m = plane()
							m.position = [posX, posY, posZ]
							m.width = width
							m.length = length
							SetMeshRotationFromQuat m q
						)
						-- collision sphere
						2:
						(
							radius = ReadFloat f
							q = ReadQuat f
							m = sphere()
							m.position = [posX, posY, posZ]
							m.radius = radius
							SetMeshRotationFromQuat m q
						)
						-- collision cylinder
						3:
						(
							radius = ReadFloat f
							height = ReadFloat f
							q = ReadQuat f
							m = cylinder()
							m.position = [posX, posY, posZ]
							m.radius = radius
							m.height = height
							SetMeshRotationFromQuat m q
						)
					)
					if m != undefined then
					(
						SetMeshSettings m name
					)
				)
				for planeIdx = 1 to countOfPlanes do
				(
					name = ReadCharacters f 32
					vertCount = ReadLong f
					faceCount = vertCount / 3
					m = mesh()
					m.numVerts = vertCount
					m.numFaces = faceCount
					for vertIdx = 1 to vertCount do
					(
						setVert m vertIdx [ReadFloat f, ReadFloat f, ReadFloat f]
					)
					for faceIdx = 0 to (faceCount - 1) do
					(
						faceVertStart = faceIdx * 3
						setFace m (faceIdx + 1) [faceVertStart + 1, faceVertStart + 2, faceVertStart + 3]
					)
					SetMeshSettings m name
				)
			)
		)
		fclose f
	)
	catch
	(
		print(getCurrentException())
	)
)

function ExportCol filename =
(
	try
	(
		f = fopen filename "wb"
		if f != undefined then
		(
			WriteString f "AttributeData"
			WriteLong f 0
			WriteLong f 0
			countOfMeshes = 0
			countOfPlanes = 0
			for m in objects do
			(
				if (findString m.name "collision") != undefined  then
				(
					if (classof m) == plane then
					(
						WriteLong f 0
						WriteCharacters f m.name 32
						WritePos f m
						WriteFloat f m.width
						WriteFloat f m.length
						WriteQuat f (m.rotation as quat)
						countOfMeshes = countOfMeshes + 1
					)
					else if (classof m) == sphere then
					(
						WriteLong f 2
						WriteCharacters f m.name 32
						WritePos f m
						WriteFloat f m.radius
						WriteQuat f (m.rotation as quat)
						countOfMeshes = countOfMeshes + 1
					)
					else if (classof m) == cylinder then
					(
						WriteLong f 3
						WriteCharacters f m.name 32
						WritePos f m
						WriteFloat f m.radius
						WriteFloat f m.height
						WriteQuat f (m.rotation as quat)
						countOfMeshes = countOfMeshes + 1
					)
				)
			)
			for m in objects do
			(
				if (findString m.name "height") != undefined then
				(
					if (classof m) == editable_mesh then
					(
						WriteCharacters f m.name 32
						WriteLong f (m.numFaces * 3)
						for faceIdx = 1 to m.numFaces do
						(
							face = getFace m faceIdx
							for vertIdx = 1 to 3 do
							(
								vert = getVert m face[vertIdx]
								WriteVert f vert
							)
						)
						countOfPlanes = countOfPlanes + 1
					)
				)
			)
			fseek f 14 #seek_set
			WriteLong f countOfMeshes
			WriteLong f countOfPlanes
			fclose f
		)
	)
	catch
	(
		print(getCurrentException())
	)
)

function CollisionHelperHelp =
(
	utility helpDialog "Metin2-Collision Helper - Help"
	(
		label helpTextLn1 "Collision meshes must be labeled with \"collsion**\" tag in mesh name" pos: [15, 10]
		label helpTextLn2 "and the height plane with \"height**\" tag in name." pos: [15, 25]
		label helpTextLn3 "(MDATR file uses two types of collision, the collision mesh like plane," pos: [15, 45]
		label helpTextLn4 "sphere or cylinder shapes and the height plane that represents the ground)" pos: [15, 60]
	)
	createDialog helpDialog 380 85
)

function CollisionHelper =
(
	utility dialog "Metin2-Collision Helper"
	(
		button btnImport "Import collision" pos: [15, 10] width: 200 height: 20
		button btnExport "Export collision" pos: [15, 35] width: 200 height: 20
		button btnHelp "Help" pos: [15, 60] width: 45 height: 18
		label info "Copyright © anohros" pos: [115, 62]
		
		on btnImport pressed do
		(
			fnMDATR = getOpenFileName types: "Collision file (*.mdatr)|*.mdatr" caption: "Select MDATR file"
			if fnMDATR != undefined then
			(
				ImportCol fnMDATR
			)
		)
		
		on btnExport pressed do
		(
			fnMDATR = getSaveFileName types: "Collision file (*.mdatr)|*.mdatr" caption: "Chose MDATR file name"
			if fnMDATR != undefined then
			(
				ExportCol fnMDATR
			)
		)
		
		on btnHelp pressed do
		(
			CollisionHelperHelp()
		)
	)
	createDialog dialog 230 84
)
CollisionHelper()
08/29/2017 18:53 andii#2
Hack/Bot/Script Requests are not allowed. Use the search function
08/30/2017 17:18 Nectix#3
#closed