Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® Softimage® Modtools / Valve Source (Half Life 2) / Fast physbox creation for physics VMFs
  RSS 2.0 ATOM  

Fast physbox creation for physics VMFs
Rate this thread
 
30333
 
Permlink of this thread  
avatar
  • Total Posts: 144
  • Joined: 19 February 2008 09:28 AM

I made this script recently which uses this program called Stanhull.exe in XSI

(which can be downloaded here: http://www.amillionpixels.us/sourcecode.htm )

After working with Source for about 4 years now, I’ve found its quite impossible to compile a decent phy model for the Source engine without being able to generate perfect convex meshes beforehand.

If any object is even minutely NOT convex the physics model turns out based on all the outer vertices on the model, rather than the seperate elements (resulting in a highly inaccurate and uneconomical shrinkwrapped effect).

This script is very rough (WIP) but it really speeds up making accurate phy models for Source as everything required to make the model work is automated. Once converted the convex meshes are reimported, discontinuity is turned off and a simple cube texture projection is added. You end up with a series of polymeshes called hull**. These are then exported as a physics VMF file.

Note: all meshes to be converted should be in the scene root only.

(Hope it’s useful.)

'UBER-quick perfect phyboxes from selected polymeshes
by Jason Wells aka redmotion - Feb 2009
'
NOTEthat all scene objects to be converted should be under the scene root

dim name
,Objdir,StanhullDir,getObjname,fileOutLoc,cmd,inObj,strCurrentPath

'-------------------------------------------------------------------------------------------
'
set up directory paths here
'Objdir = the directory you want the exported Obj to go to (change if you wish)
Objdir = "C:\3d\Stanhull\"

'
StanhullDir the directory you have put stanhull.exe in (change if you wish)
StanhullDir "C:\3d\Stanhull\"

'current path being used by XSI
strCurrentPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
fileOutLoc = strCurrentPath & "\hull.obj"

LogMessage fileOutLoc
'
--------------------------------------------------------------------------------------------

set list = GetValue"SelectionList" )
if list.
count 0 then
    MsgBox 
"Please select at least one polymesh object first!!"
    
else

'start rendermap make routine - depending on scene size and object complexity this could take a while... :)
    for each item in list
        name = item.name
        if item.type = "polymsh" then
            '
select objects one by one and export
            SelectObj name
, , True
            getObjname 
Objdir "convert.obj"
            
ObjExport getObjname, , , , , , , , , , 0False, , , False
            
            
'set up system command to run Stanhull.exe
            cmd = StanhullDir & "StanHull " & getObjname    
            cmdResult = system( cmd )
            set inObj = ObjImport( fileOutLoc, 1, 0, True, True, False, True )
            
            '
select new object and set up geometry approximation as needed for .phy SMDs
            SelectObj inObj
, , True
            MakeLocal inObj 
".geomapprox"siDefaultPropagation
            SetValue inObj 
".geomapprox.gapproxmoad"False
            
            
'Create projection and freeze - projection needed to export
            CreateProjection , siTxtCubic, siTxtDefaultCubic, , "Texture_Projection"
            FreezeModeling

            end if
        next
end if

INSTRUCTIONS -

unzip stanhull.exe to a directory of your choice and adjust the entries in the script above that start with:

StanhullDir =
(to the path to where you’ve put stanhull.exe)
Objdir =
(to where temp .obj file is put - use the same dir as above for ease)

Select all the meshs to be made convex in the scene, run the script. (convex hull meshes will be piaced back in the scene)



Replies: 0
avatar
  • mslaf
  • Posted: 27 February 2009 06:04 AM

[quote=redmotion;19663]After working with Source for about 4 years now, I’ve found its quite impossible to compile a decent phy model for the Source engine without being able to generate perfect convex meshes beforehand.

This is because the current exporter uses the vertex normals instead of point normals - points are shared vertices - when exporting collision meshes.

I’ve solved the problem of ‘perfect convex’ collision meshes in the exporter I use myself and would gladly share this knowledge with the official developer of SMDTools. Unfortunately I don’t know who is the developer and I have no one to talk to.



Replies: 0
avatar

Why not share it in the downloads section here? I’m sure other Source modellers would find it useful. It’s not necessary to integrate it into the VMF tools.



Replies: 0
avatar
  • mslaf
  • Posted: 27 February 2009 07:55 AM

[quote=redmotion;19677]Why not share it in the downloads section here? I’m sure other Source modellers would find it useful. It’s not necessary to integrate it into the VMF tools.

Because, first, it’s focused on the static geometry only, second it’s a part of much bigger solution I’m currently working on. My exporter, exports all geometry: meshes, collisions, shadow hulls, lods, materials, textures, creates qc and shader files and compiles them - not to mention about a music in the background;) , so it’s much more complex that a simple geometry export - that can be performed using the vbs script. Different philosophy and different workflow.

Thus, it would be much easier to implement it, into much more popular SMDTools.



Replies: 0
avatar

TBH my only problem with the Source Engine process was getting decent physboxes - I’m pretty happy with the rest of it. This little plug in helps me get over the last hurdle and I thought I’d share it with anyone who might find it useful.

So, I guess this is my solution until the future release of mslaf SMDTools… ;) Look forward to ‘em.



Replies: 0
avatar
  • dwigfor
  • Posted: 27 February 2009 09:17 AM

Thanks for your generous contribution, Jason!  I’ve had a problem with my phys boxes, and was enlightened that you needed to turn off discountinuity..  I’ll have to give your script a go and see if I can generate something better than bounding boxes.  :)



Replies: 0
avatar

Cool. If it doesn’t work for you, please post the issue and I’ll do my best to fix it. (Most likely problem will be the directory paths.)

and was enlightened that you needed to turn off discountinuity..

Yeah, so was I! One of my fellow mod members pointed that out to me.

It’s also mentioned here: http://developer.valvesoftware.com/wiki/XSI_foundation_5.1_smd_exporter

Cheers.



Replies: 0