Jump to content
×
×
  • Create New...
  • 1

Mdatr collision as editable mesh


Lynx

Question

someone would be so kind to modify this script so that it is possible to export collisions as editable mesh?

It is only possible to export planes, spheres or cylinders as collision

i can pay for it

This is the hidden content, please

 
-- 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()

This is the hidden content, please
!jUrKEvz4EPKatkcQkGY6qnxX602nv1hFNx32mdW46PA

 

  • Metin2 Dev 4
  • Good 1
  • Dislove 1

My web of new mobs: https://3d4m2.wordpress.com/

3D Pack V1: https://3d4m2.wordpress.com/3dpack-v1/

Skype: lynx.prod

Discord: OneTazo#0346

 

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.


Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.