PDA

View Full Version : A little help with the script


LAZER555
01-03-2010, 08:13 PM
Hi, i need help with this particular script made for 3dsmax 5.1 sp1, for exporting biped animation to game format. I'm a complete newbie in maxscript so please take a look at this.

When launched it shows this error: --Unknown property: "position" in undefined
and blue line is selected. It's a working script for all purposes except exporting "ShootDodge".
Please help, i've been stuck on this for a very long time :cry:

macroScript R_ExportBipedAnimation2
category:"RemedyTools"
tooltip:"Export Biped Animation v2"
Icon:#("RemedyTools",8)
(
-- TODO:
-- record and restore timeSlider
local bLinearMovement = false
local bDiagonal = false
local bForward = false
local bSideways = false

include "$scripts/RemedyTools/RemedyTools.ms"
local strConfigFile = getdir #plugcfg + "\\" + "KFExportAdditional.cfg"
local strExportPath
local strExportBaseFilename
local strFilename
local arrVisibleBones = #()
local animationType
local bSilentMode = false

-- ========================================================================
-- Begin helper functions
-- ========================================================================

fn R_writeKFConfig m_strConfigFile fDeltaPos fDeltaRot bLooping iStartFrame iEndFrame iLoopToFrame bLoopInterpolation bDecreaseEndFrameByOne =
(
deleteFile m_strConfigFile
if ( fileExport = createFile m_strConfigFile ) != undefined then
(
if (iLoopToFrame < iStartFrame) then iLoopToFrame = iStartFrame
format "[Animation]\n" to: fileExport
format "FrameToFrameInterpolation = orthonormalized;\n" to: fileExport
format "PositionDelta = %;\n" (floatToString fDeltaPos) to: fileExport
format "RotationDelta = %;\n" (floatToString fDeltaRot) to: fileExport
format "Loop = %;\n" (bLooping as string) to: fileExport
format "StartFrame = %;\n" ((iStartFrame.frame as integer) as string) to: fileExport
format "EndFrame = %;\n" ((iEndFrame.frame as integer) as string) to: fileExport
format "LoopToFrame = %;\n" ((iLoopToFrame.frame as integer) as string) to: fileExport
format "LoopInterpolation = %;\n" (bLoopInterpolation as string) to: fileExport
format "DecreaseEndFrameByOne = %;\n" (bDecreaseEndFrameByOne as string) to: fileExport
flush fileExport
close fileExport
return 0
)
)
-- -----------------------------------------------------------------------
fn R_askForFilename instring =
(
if not (bSilentMode) then
(
f = getSaveFileName filename:instring types:"KF2 Files(*.kf2)|*.kf2|All|*.*|"
if (f == undefined) then
(
MessageBox("debug: got cancel in file name dialog, nothing exported")
)
)
return f
)
-- -----------------------------------------------------------------------
fn R_hideUnwanted =
(
hide $helpers -- by category
hide $helper* -- geometry objects with proper naming
for i = 1 to geometry.count do
(
if ((geometry[i].isFrozen as string == "true") and (findstring geometry[i].name "Bip01" == undefined )) do (hide geometry[i])
)
)

-- -----------------------------------------------------------------------
fn collectVisibleChildren p =
(
for i=1 to p.count do
(
if ((p[i].isHidden as string != "true") and (p[i].isFrozen as string != "true") and (p[i].baseobject as string != "Dummy") and (p[i].baseobject as string != "Free Camera")) then
(
append arrVisibleBones p[i]
)

if (p[i].children.count != 0) do
(
collectVisibleChildren p[i].children
)
)
)
-- -----------------------------------------------------------------------
fn R_miscCS4Fixes =
(
try ($Bip01.controller.figureMode) -- workaround for CS4 network auth problem
catch( startObjectCreation BipedSystem) -- workaround for CS4 network auth problem

(biped.getNode $Bip01 #rarm link:3).name = "Bip01 R Forearm" -- make sure no ForeArm
(biped.getNode $Bip01 #larm link:3).name = "Bip01 L Forearm" -- make sure no ForeArm
if (biped.getNode $Bip01 #rfarmtwist != undefined ) do ( (biped.getNode $Bip01 #rfarmtwist).parent = biped.getNode $Bip01 #rarm link:3 ) -- reparent Twists
if (biped.getNode $Bip01 #lfarmtwist != undefined ) do ( (biped.getNode $Bip01 #lfarmtwist).parent = biped.getNode $Bip01 #larm link:3 ) -- reparent Twists
hide $*twist*
(biped.getNode $Bip01 #footprints).isFrozen = false
(biped.getNode $Bip01 #footprints).isFrozen = true
)
-- -----------------------------------------------------------------------
fn R_setupPaths =
(
optionsFile = openFile ( "C:/MaxPayne2Dev/3dsmax5/" + sysinfo.computername + ".txt" )
strExportPath = readValue optionsFile

-- Make sure path is valid and has trailing slash
if strExportPath[strExportPath.count] != "\\" and strExportPath[strExportPath.count] != "/" then strExportPath = strExportPath + "/"

bIsFemale = findString maxFilePath "Female"
if (bIsFemale != undefined ) then
(
if ($Female_Doctor_A != undefined ) do hide $Female_Doctor_A -- add other used skins here if needed...
strExportPath = strExportPath + "skeletons/female/anim"
)
else
(
strExportPath = strExportPath + "skeletons/male/anim"
)

-- Make sure path is valid
if strExportPath[strExportPath.count] != "\\" and strExportPath[strExportPath.count] != "/" then strExportPath = strExportPath + "/"

deleteFile ((getdir #plugcfg)+"/_KFExport_backup.cfg")
renameFile ((getdir #plugcfg)+"/KFExport.cfg") ((getdir #plugcfg)+"/_KFExport_backup.cfg")
if( copyFile ((getdir #plugcfg)+"/KFExport_AnimationOnly_NoLoop.cfg") ((getdir #plugcfg)+"/KFExport.cfg") == false ) then
(
MessageBox("WARNING: Couldn't write KFExport config...")
)

strExportBaseFilename = replace maxFilename ((findString maxFilename ".max")-3) 7 ""
)
-- -----------------------------------------------------------------------
fn R_ParentDummy =
(
if ( getNodeByName "ParentDummy" != undefined ) then ( /*$Bip01.parent = $ParentDummy*/ )
else
(
local d = dummy()
d.name = "ParentDummy"
$Bip01.parent = d
hide d
)
)
-- -----------------------------------------------------------------------
fn R_CreateMovementDummy m_iStart m_iEnd =
(
local obj = dummy(); obj.position.controller = linear_position(); hide obj -- new helper object
obj.name = "MovementDummy"

if (bLinearMovement == true) then
(
with animate on
(
sliderTime = m_iStart
addNewKey obj.position.controller m_iStart
obj.position.x = $Bip01.transform.position.x;
obj.position.y = $Bip01.transform.position.y;

sliderTime = m_iEnd
addNewKey obj.position.controller m_iEnd
obj.position.x = $Bip01.transform.position.x;
obj.position.y = $Bip01.transform.position.y;
)
)
else
(
-- begin real movement --
sliderTime = m_iStart
with animate on
(
for i = m_iStart to m_iEnd do at time i
(
addNewKey obj.position.controller i
obj.position.x = $Bip01.transform.position.x;
obj.position.y = $Bip01.transform.position.y;
obj.position.z = 0
)
)
-- end real movement --
)
)
-- -----------------------------------------------------------------------
fn exportBase iStart iEnd =
(
local obj
hide $*
for i = 1 to arrVisibleBones.count do (unhide arrVisibleBones[i]); unhide $Bip01

if ($ExportDummy.exportMovement) then
(
local movementNode
local bFakeMovement = false
if ( getNodeByName "MovementDummy" != undefined ) then (bFakeMovement=true) else ( R_CreateMovementDummy iStart iEnd )
movementNode = $MovementDummy;

obj = dummy(); obj.position.controller = linear_position(); hide obj -- new helper object
obj.name = "foo"

if ((bLinearMovement == true) and (bFakeMovement == false)) then
(
-- begin linear animation
with animate on
(
sliderTime = iStart
addNewKey obj.position.controller iStart
obj.position.x = (movementNode.transform.position.x * -1);
obj.position.y = (movementNode.transform.position.y * -1);
format "time: % obj: % \n" iStart obj.position

sliderTime = iEnd
addNewKey obj.position.controller iEnd
obj.position.x = (movementNode.transform.position.x * -1);
obj.position.y = (movementNode.transform.position.y * -1);
format "time: % obj: % \n" iEnd obj.position
)
-- end linear animation
)
else
(
if (bFakeMovement == true) then
(
-- begin fake-in-place for movement with MovementDummy
with animate on; for i = iStart to iEnd do at time i
(
obj.position.x = ($Bip01.transform.position.x * -1)
obj.position.y = ($Bip01.transform.position.y * -1)
obj.position.z = 0
)
-- end fake-in-place
)
else
(
-- begin ok
with animate on; for i = iStart to iEnd do at time i (
obj.position.x = (movementNode.transform.position.x * -1);
obj.position.y = (movementNode.transform.position.y * -1);
obj.position.z = 0
format "obj: % \n" obj.position
)
-- end ok, which still isn't ok
)
)

sliderTime = iStart
$ParentDummy.parent = obj

sliderTime = 0f -- do everything presuming time it at 0
exportFile (R_askForFilename (strExportPath + strExportBaseFilename + ".kf2"))

delete obj
)
else
(
exportFile (R_askForFilename (strExportPath + strExportBaseFilename + ".kf2"))
)
)
-- -----------------------------------------------------------------------
fn exportMovement iStart iEnd =
(
hide $*
obj = dummy(); obj.position.controller = linear_position(); unhide obj -- new helper object
local movementNode
if ( getNodeByName "MovementDummy" != undefined ) then ( movementNode = $MovementDummy ) else ( movementNode = $Bip01 )

with animate on
for i = iStart to iEnd do at time i
(
obj.position = movementNode.transform.position
obj.position.z = 0
--format "% % %\n" i obj.name obj.position
)
exportFile (R_askForFilename (strExportPath + strExportBaseFilename + "_mov" + ".kf2"))
)
-- -----------------------------------------------------------------------
-- exportGetup is hardcoded to use 50f to 75f time segment
fn exportGetup =
(
$Bip01.parent.parent = undefined
hide $*
for i = 1 to arrVisibleBones.count do (unhide arrVisibleBones[i]); unhide $Bip01
obj = dummy name:"GetupDummy"; obj.position.controller = linear_position(); hide obj -- new helper object
sliderTime = 50f
obj.position = $MovementDummy.position
$Bip01.parent.parent = obj
with animate on; for i = 50f to 75f do at time i ( obj.position = $MovementDummy.position * -1 ) -- invert motion
obj.position = [0,0,0]
exportFile (R_askForFilename (strExportPath + strExportBaseFilename + "_Getup" + ".kf2"))
)
-- -----------------------------------------------------------------------

-- ========================================================================
-- Begin real script
-- ========================================================================

-- preconditions: MovementDummy (unlinked), $Bip01 linked to ParentDummy?, JumpDummy?
extIndex = findString MaxFilename ".max"
if ( extIndex != undefined ) then()
else
(
Throw("ERROR: Scene not saved, not exported!")
)

max hold
if (keyboard.shiftPressed) then ( bSilentMode = true ) else ( bSilentMode = false )

sliderTime = 0f -- do everything presuming time it at 0

R_hideUnwanted()
collectVisibleChildren $Bip01.children -- locally stored in arrVisibleBones
R_miscCS4Fixes()
R_setupPaths()
R_parentDummy()

ClearListener()

if ( (findString MaxFilename "ShootDodge") != undefined ) then ( animationType = "ShootDodge" ) else ( animationType = "Normal" )

-- this is ugly... but it works reliably for all my cases so far...
direction = findString MaxFilename "Forward"
if ( direction != undefined ) then
(
bDiagonal=false
bForward=true
bSideways=false
bLinearMovement = true
)

direction = findString MaxFilename "Backward"
if ( direction != undefined ) then
(
bDiagonal=false
bForward=true
bSideways=false
bLinearMovement = true
)

direction = findString MaxFilename "Left"
if ( direction != undefined ) then
(
bDiagonal=false
bForward=false
bSideways=true
bLinearMovement = true
)


direction = findString MaxFilename "Right"
if ( direction != undefined ) then
(
bDiagonal=false
bForward=false
bSideways=true
bLinearMovement = true
)

direction = findString MaxFilename "ForwardRight"
if ( direction != undefined ) then
(
bDiagonal=true
bForward=false
bSideways=false
bLinearMovement = true
)

direction = findString MaxFilename "ForwardLeft"
if ( direction != undefined ) then
(
bDiagonal=true
bForward=false
bSideways=false
bLinearMovement = true
)

direction = findString MaxFilename "BackwardRight"
if ( direction != undefined ) then
(
bDiagonal=true
bForward=false
bSideways=false
bLinearMovement = true
)

direction = findString MaxFilename "BackwardLeft"
if ( direction != undefined ) then
(
bDiagonal=true
bForward=false
bSideways=false
bLinearMovement = true
)
-- end kludge
format "linear: % diagonal: % forward: % sideways: %\n" bLinearMovement bDiagonal bForward bSideways


-- TODO: LINEARMOVEMENT

-- export base animation ------------------------------------------------------------
if ( animationType == "ShootDodge" ) then
(
format "Exporting Shootdodge Base Animation\n"
R_writeKFConfig strConfigFile 0.01 0.01 "false" 0f 50f 50f "false" "false" -- for ShootDodge_*.kf2
obj = dummy(); obj.position.controller = linear_position(); hide obj -- new helper object
with animate on; for i = 0f to 50f do at time i ( obj.position = $MovementDummy.position * -1 ); with animate off -- invert motion
$Bip01.parent.parent = obj -- we will ignore ParentDummy's parent called "JumpDummy"
exportFile (R_askForFilename (strExportPath + strExportBaseFilename + ".kf2"))
delete obj
)
else
(
-- normal
R_writeKFConfig strConfigFile $ExportDummy.positionDelta $ExportDummy.rotationDelta $ExportDummy.looping animationRange.start animationRange.end (($ExportDummy.loopToFrame) as time) $ExportDummy.loopInterpolation $ExportDummy.decreaseEndFrameByOne
exportBase animationRange.start animationRange.end
)

-- export movement ------------------------------------------------------------------
if ( animationType == "ShootDodge" ) then
(
format "Exporting Shootdodge Movement\n"
R_writeKFConfig strConfigFile 0.001 0.005 "false" 0f 50f 50f "false" "false" -- for Shootdodge_*_mov.kf2
hide $*
unhide $'MovementDummy'
exportFile (strExportPath + strExportBaseFilename + "_mov" + ".kf2")
)
else
(
if ($ExportDummy.exportMovement) do
(
R_writeKFConfig strConfigFile $ExportDummy.positionDelta $ExportDummy.rotationDelta "false" animationRange.start animationRange.end animationRange.end "false" "false"
exportMovement animationRange.start animationRange.end
)
)
-- export getup ---------------------------------------------------------------------
if ( animationType == "ShootDodge" ) then
(
R_writeKFConfig strConfigFile 0.001 0.001 "false" 50f 75f 75f "false" "false" -- for Shootdodge_*_Getup.kf2
exportGetup()
)

-- clean up -------------------------------------------------------------------------

deleteFile strConfigFile
--max fetch
resetMaxFile #noPrompt
)

CGTalk Moderation
01-03-2010, 08:13 PM
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.