Notifications
Clear all

[Closed] Collision Export Name issuse

Hey Everybody,

I have to update a script that I have for making Unreal collision in 3Ds max and I am having an issue getting something named correctly. The issue is that when I export from 3Ds Max 2012 into Unreal with the current script setup, Unreal will miss the collision in the file. After some searching around the web I found out that its because the collision object needs to have the same name as the mesh that its attached to.

At first I thought that it would as simple as adding this to the top of my code.

n = $.name

And then calling that in the following function like so.

the_box = Box prefix: "UCX_ " + n as string + length:l width:w height:h pos:c 

But that did not work and I am pretty sure that it is because I am trying to appended the name in the wrong location but I am not really sure where I would have to call it. In the end I would like for the name to look like the following…

UCX_SelectedObjectName_00(This number needs to still increment)

Here is the completed script for anyone to have a look at and let me know what I need to do or where I need to look to fix this issue.


----------------------------------------------------
-- UCX Collision Box 
-- 05.10.2010
-- Sam Deiter
---------------------------------------------------

---------------------------------------------------
-- This script allows you to make a a UCX collision box using your current selection 
-- in edit poly mode. 

---------------------------------------------------


macroscript UCXCollisionBoxMacro
    category:"Unreal Tools"
    buttonText:"UCX Collision Box"
    toolTip:"Make a single UCX Collision Box"

(

n = $.name 

--Set up the min and max values that will need to create the box	
fn minimum a b =
(
	if a > b then return b
		return a
)

fn maximum a b =
(
	if a < b then return b
		return a
)

-- Get your current selection

selectedFaces = polyop.GetFaceSelection selection[1]
selectedVerts = polyop.getVertsUsingFace selection[1] selectedFaces

-- Min and Max of your selection
boxmin = point3 0 0 0
boxmax = point3 0 0 0
firstVertex = true


-- Loop to see the min and max of your selection
for i = 1 to selectedVerts.count do
(
	if selectedVerts[i] == true do
	(
		vertex = selection[1].verts[i]
		if firstVertex == true then
		(
			boxmin.x = vertex.pos.x
			boxmax.x = vertex.pos.x
			boxmin.y = vertex.pos.y
			boxmax.y = vertex.pos.y
			boxmin.z = vertex.pos.z
			boxmax.z = vertex.pos.z
			firstVertex = false
		)
		else 
		(
			boxmin.x = minimum vertex.pos.x boxmin.x
			boxmin.y = minimum vertex.pos.y boxmin.y
			boxmin.z = minimum vertex.pos.z boxmin.z
			
			boxmax.x = maximum vertex.pos.x boxmax.x
			boxmax.y = maximum vertex.pos.y boxmax.y			
			boxmax.z = maximum vertex.pos.z boxmax.z
		)
	)
)


center = point3  0 0 0
center.x = (boxmax.x - boxmin.x) * 0.5 + boxmin.x
center.y = (boxmax.y - boxmin.y) * 0.5 + boxmin.y
center.z = (boxmax.z - boxmin.z) * 0.5 + boxmin.z

--print center
--print boxmax
--print boxmin
--for i in obj = selection[1].selectedFaces collect i.index do
--for i in local obj = selection[1] do

-- Creat a collision prim using your selection
	
(
		l   = (boxmax.y - boxmin.y)
		w = (boxmax.x - boxmin.x)
		h =  (boxmax.z - boxmin.z)
		c = center - [0, 0, (h/2)]		
	--What do I have to add here to get the name to  UCX_SelectedObjectName_00
		the_box = Box prefix: "UCX_ "  length:l width:w height:h  pos:c + "String" 
		convertToPoly(the_box)
		the_box.wireColor = (color 255 0 255  )
		the_box.xray = on
		
		
)

)



7 Replies

You were quite close, to fix it this should be enough:

the_box = Box prefix:("UCX_ " + n + "_") length:l width:w height:h pos:c

There are some suboptimal things in the code such as custom min max functions instead of amin amax, bool == true comparisons and the like but that’s not what you asked for (or care about, as far as I can say) so I’ll leave it as is

You could also try removing prefix and instead use:
name:(uniquename (“UCX_”+n+”_001″))

-Eric

No way by all means if you see something that I could have done better please let me know. I have been trying really hard to get my head around max script as I feel it’s one of my weaker areas so go right a head and let me know if there is a better way to do something.

Also side note that did work but. So simple but now I have another error that I am trying to figure out. Thanks again for the help.

1 Reply
(@swordslayer)
Joined: 11 months ago

Posts: 0

I will just leave this here, try to work out what did I change and what could be the reasons

(
	fn extremePoint p1 p2 comp =
		Point3 (comp p1.x p2.x) (comp p1.y p2.y) (comp p1.z p2.z)

	local obj = selection[1]
	local n = obj.name

	-- Get your current selection
	local selectedFaces = polyop.getFaceSelection obj
	local selectedVerts = polyop.getVertsUsingFace obj selectedFaces

	-- Min and Max of your selection
	local boxmin, boxmax
	local firstVertex = true

	for i in selectedVerts do
	(
		local vertexPos = obj.verts[i].pos
		if firstVertex then
		(
			boxmin = vertexPos
			boxmax = vertexPos
			firstVertex = false
		)
		else
		(
			boxmin = extremePoint vertexPos boxmin amin
			boxmax = extremePoint vertexPos boxmax amax
		)
	)

	local size = boxmax - boxmin
	local boxPos = (boxmax + boxmin)/2 - [0, 0, size.z/2]

	-- Creat a collision prim using your selection
	local the_box = Box prefix:("UCX_ " + n + "_") length:size.y width:size.x height:size.z pos:boxPos
	convertToPoly the_box
	the_box.wireColor = (color 255 0 255)
	the_box.xray = on
)

 em3

You are trying to create collision meshes for your objects for Unreal engine? What error are you getting?

I was working on something similar to this a few years ago. Mine just draws a box around the object. Did some digging and found this code – not sure if it helps or not but fwiw.


Objs = for i in geometry collect i		
		for o in Objs do --move objects to postion relative to 0
		(
			myX = (o.max.x*-1)
			myY = (o.max.y*-1)
			myZ = (o.max.z*-1)
			move o [myX,myY,myZ]
				c = snapshot o
				c.transform = matrix3 1
				bb = c.max - c.min
				b = box width:bb[1] length:bb[2] height:bb[3]
				CenterPivot b
				delete c
				b.transform = o.transform
				b.pivot = o.pivot
				b.name = "UCX_" + o.name
		)

--DenisT helped me with this part and by "help" I mean he did the whole thing.

(
      local dirName = @"your directory name"
      
      for node in Objs where isvalidnode (mate = getNodeByName ("UCX_" + node.name) firstonly:on) do 
      (
          select #(node,mate)
        exportFile (dirname + node.name + ".ase") #noPrompt selectedOnly:on
      )

	)
	theOutputFile = File + "_Ex"

1 Reply
(@billyclint)
Joined: 11 months ago

Posts: 0

Thanks for the code I will try it out. There where two problems that I was having. The first one was due to a blasted space in the name. The .FBX format does not like spaces any where in the collision name. If you have one the collision will not import correctly and by correctly I mean not import at all.

The second problem that I had was how to to get the UCX collision box to use UCX_The_Object_name_00. I solved that issue by doing the following.

the_box = Box prefix: ("UCX_"+n+"_") length:l width:w height:h pos:c

So I have this working for the most part now. Now I have to fix another issue with my exporter not working correctly now. Thanks for all the help and if you have any advice on how I can do thing better I am all ears.

Thanks for the help and I have not had a chance to look what you did yet but it is something I am planing for this week. Thanks again for all the help and I did get this working with using this line of code

("UCX_ " + n + "_")

So thanks again for all the help guys and gals…