CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 02-15-2013, 05:07 PM   #1
BillyClint
Veteran
portfolio
Sam Deiter
Technical Artist
Villingen-Schwenningen, Germany
 
Join Date: Feb 2006
Posts: 38
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.

Code:
n = $.name


And then calling that in the following function like so.

Code:
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.


Code:
---------------------------------------------------- -- 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 ) )
__________________
|*BILLY$CLINT*|




Last edited by BillyClint : 02-15-2013 at 05:11 PM.
 
Old 02-15-2013, 05:20 PM   #2
Swordslayer
isKindOf Artist
 
Swordslayer's Avatar
portfolio
Vojtech Cada
3D generalist
Czech Republic
 
Join Date: Jun 2006
Posts: 376
Send a message via ICQ to Swordslayer
You were quite close, to fix it this should be enough:

Code:
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
__________________
Blog :: LinkedIn profile
 
Old 02-15-2013, 05:25 PM   #3
PiXeL_MoNKeY
Expert
 
PiXeL_MoNKeY's Avatar
Eric Craft
Dallas, USA
 
Join Date: Mar 2002
Posts: 5,668
You could also try removing prefix and instead use:
name:(uniquename ("UCX_"+n+"_001"))

-Eric
__________________
"The Evil Monkey hiding in your closet."
 
Old 02-15-2013, 05:48 PM   #4
BillyClint
Veteran
portfolio
Sam Deiter
Technical Artist
Villingen-Schwenningen, Germany
 
Join Date: Feb 2006
Posts: 38
Quote:
Originally Posted by Swordslayer
You were quite close, to fix it this should be enough:

Code:
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


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.
__________________
|*BILLY$CLINT*|



 
Old 02-15-2013, 07:22 PM   #5
em3
day dreamer
 
em3's Avatar
portfolio
Dave Tyner
3D Artist
Polyform Media
Denver, United%2BStates
 
Join Date: Jan 2004
Posts: 984
Send a message via Yahoo to 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.

Code:
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"
__________________
www.davetyner.com

Last edited by em3 : 02-15-2013 at 07:36 PM.
 
Old 02-15-2013, 09:02 PM   #6
BillyClint
Veteran
portfolio
Sam Deiter
Technical Artist
Villingen-Schwenningen, Germany
 
Join Date: Feb 2006
Posts: 38
Quote:
Originally Posted by 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.

Code:
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"


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.

Code:
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.
__________________
|*BILLY$CLINT*|



 
Old 02-15-2013, 10:03 PM   #7
Swordslayer
isKindOf Artist
 
Swordslayer's Avatar
portfolio
Vojtech Cada
3D generalist
Czech Republic
 
Join Date: Jun 2006
Posts: 376
Send a message via ICQ to Swordslayer
Quote:
Originally Posted by BillyClint
No way by all means if you see something that I could have done better please let me know.


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

Code:
( 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 )
__________________
Blog :: LinkedIn profile
 
Old 02-18-2013, 05:03 PM   #8
BillyClint
Veteran
portfolio
Sam Deiter
Technical Artist
Villingen-Schwenningen, Germany
 
Join Date: Feb 2006
Posts: 38
Quote:
Originally Posted by Swordslayer
I will just leave this here, try to work out what did I change and what could be the reasons

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


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

Code:
("UCX_ " + n + "_")


So thanks again for all the help guys and gals...
__________________
|*BILLY$CLINT*|



 
Old 02-18-2013, 05:03 PM   #9
CGTalk Moderation
Expert
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,478
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 04:18 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.