[cgkit-commits] cgkit2/utilities/3dsmax cgkit_export.ms,NONE,1.1
Brought to you by:
mbaas
From: Matthias B. <mb...@us...> - 2005-09-01 15:40:19
|
Update of /cvsroot/cgkit/cgkit2/utilities/3dsmax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26734/utilities/3dsmax Added Files: cgkit_export.ms Log Message: Export curves from 3ds max --- NEW FILE: cgkit_export.ms --- ------------------------------------------------------------------------- -- Export objects as Python source code. -- (C) 2005 Matthias Baas (ba...@ir...) -- http://cgkit.sourceforge.net ------------------------------------------------------------------------- -- Convert an object name to a valid variable name function name2var name = ( return name ) -- Export a shape as cgkit BezierCurve function write_curve crv outfile = ( crvname = name2var crv.name -- Output the geom format "%_geom = BezierCurveGeom( pnts = [\n" crvname to:outfile for i=1 to (numKnots crv 1) do ( in coordsys local ( p = getKnotPoint crv 1 i invec = (getInVec crv 1 i) - p outvec = (getOutVec crv 1 i) - p ) -- format "Pnt %: % % %\n" i p invec outvec format " BezierPoint((%, %, %)" p.x p.y p.z to:outfile format ", intangent=(%, %, %)" invec.x invec.y invec.z to:outfile format ", outtangent=(%, %, %)),\n" outvec.x outvec.y outvec.z to:outfile ) format(" ],\n") to:outfile if (isClosed crv 1) then format(" closed = True\n") to:outfile else format(" closed = False\n") to:outfile format(")\n\n") to:outfile -- Output the WorldObject format "% = BezierCurve(\n" crvname to:outfile format " name = \"%\",\n" crvname to:outfile format " curvegeom = %_geom,\n" crvname to:outfile format " pos = (%, %, %),\n" crv.pos.x crv.pos.y crv.pos.z to:outfile e = crv.rotation as eulerAngles format " rot = mat3().fromEulerXYZ(radians(%), radians(%), radians(%)),\n" -e.x -e.y -e.z to:outfile format " scale = (%, %, %)\n" crv.scale.x crv.scale.y crv.scale.z to:outfile format ")\n\n" to:outfile ) ------------------------------------------------------------------ -- Export a shape object ------------------------------------------------------------------ function exportShape obj outfile = ( write_curve obj outfile ) ------------------------------------------------------------------ -- Export all selected objects. ------------------------------------------------------------------ function exportSelection outfile = ( for obj in selection do ( -- Is the object a shape? if (superClassOf obj==shape) do exportShape obj outfile ) ) ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- utility CGKitExport "cgkit export" ( button exportBtn "Export..." width:140 enabled:(selection.count==1) label aboutLabel1 "cgkit exporter" label aboutLabel2 "(C) 2005 Matthias Baas" hyperLink link1 "http://cgkit.sourceforge.net" address:"http://cgkit.sourceforge.net/" color:(color 50 50 230) hoverColor:(color 200 60 130) align:#center function selectionChangedCallBack = ( if (selection.count>0) then ( exportBtn.enabled = true ) else ( exportBtn.enabled = false ) ) on CGKitExport open do ( callbacks.removeScripts id:#mbCGKitExport callbacks.addScript #selectionSetChanged "CGKitExport.selectionChangedCallback()" id:#mbCGKitExport ) on CGKitExport close do ( callbacks.removeScripts id:#mbCGKitExport ) -- Export on exportBtn pressed do ( outname = getSaveFileName caption:"Export" filename:"objects.py" types:"Python (*.py)|*.py|All files (*.*)|*.*" if (outname!=undefined) do ( -- Open output file out = createFile outname if (out==undefined) then ( messagebox ("Could not create file \""+outname+"\".") title:"IO error" ) else ( format "# 3ds max objects\n" to:out format "# Generated at %\n" localTime to:out format "\n" to:out exportSelection out close out ) ) ) ) --write_curve $Kreis01 --write_curve $Linie01 |