www.ssontech.com Forum Index www.ssontech.com
SynthEyes Camera Tracker Forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Exporting Tracker Color to your 3d App

 
Post new topic   Reply to topic    www.ssontech.com Forum Index -> Sizzle Scripting (NOT TECH SUPPORT)
View previous topic :: View next topic  
Author Message
damian_d3



Joined: 16 Apr 2008
Posts: 61

PostPosted: Thu Dec 11, 2008 8:36 am    Post subject: Exporting Tracker Color to your 3d App Reply with quote

Hi everyone,

I find it extremely useful, when my 3d locators in my 3d app (in my case 3ds Max) have the same color as the trackers in Syntheyes.
And as the standard SynthEyes exporters do not export tracker colors, I thought it could be helpful to share the way how to do it yourself Wink
It just needs a little tweaking of the exporter scripts.
But... it can be a little tricky depending on your 3d app and the way it handles colors of locators.

For 3ds Max its kinda straight forward, as you can assign every helper a individual RGB color.

This is how you convert sizzle's 24bit color to RGB. (I think most 3d apps use RGB)


Code:
 
      rgb_r = (tk.color & 255)
      rgb_g = (tk.color >> 8 & 255)
      rgb_b = (tk.color >> 16 )
      


then, after the tracker has been created, change its wire color to the 2d trackers color

Here a example for 3ds max:

Code:

// This is the creation of the helper in the original script
//////////////////////////////////////////////////////////////////////////////
printf("newtk = Point name:\"%s\" pos:[%lf,%lf,%lf] size:%lf "
      "axistripod:off centermarker:on isSelected:on\n",
      tk.nm, tk.wx, tk.wy, tk.wz, trackerSize*wsize)
//////////////////////////////////////////////////////////////////////////////

//Convert its color to RGB

      rgb_r = (tk.color & 255)
      rgb_g = (tk.color >> 8 & 255)
      rgb_b = (tk.color >> 16 )

//Change locator's color to the color of 2d tracker form SynthEyes.

      printf("$.wirecolor = [%ld ,%ld ,%ld] \n",rgb_r ,rgb_g ,rgb_b )



I guess it gets kinda tricky for Maya, as Maya's locators do not have individual colors.

Just 8 predefined colors can be assigned. As far as i know.

If someone knows a cool way to work around this problem please let me know.

I hope this helps a little,

Damian
Back to top
View user's profile Send private message Visit poster's website
damian_d3



Joined: 16 Apr 2008
Posts: 61

PostPosted: Thu Dec 11, 2008 8:39 am    Post subject: Reply with quote

Here is the complete 3ds max exporter with colored locators.
Code:

//SIZZLEX .ms Max exporter with colors
@[

// (c)2003 Andersson Technologies LLC
//
// Maxscript export script.
// Set the following value to your version of MAX (5, 6)
MaxVersion = 6
trackerSize = 0.001   // relative to world size
bias = Scene.startFrame   // frame bias: starting max frame # (frame 0 in SE)
if(1)
    dlg = NewDialog("max3ds")
    dlg.StartRadio("MaxVersion", "3dsmax Version")
    dlg.Radio("max_5", "V5 or earlier", (MaxVersion <= 5))
    dlg.Radio("max_6", "V6 or later", (MaxVersion >= 6))
    dlg.Check("bias", "Starting at Frame 1", bias)
    dlg.Float("trackerSize", "Relative tracker size", 0.0001, trackerSize, 0.01)
    dlg.Show()
    MaxVersion = (dlg.max_6 ? 6 : 5);
    bias = dlg.bias
    trackerSize = dlg.trackerSize
end

axisMode = 0      // ALWAYS Z Up
maincam = Scene.activeObj.cam
Header(maincam)

"DisableSceneRedraw()\n"

for (ob in Obj)
    if (ob.cam == maincam)
   OutObj(ob)
    end
end

for (lite in Lite)
    OutLite(lite)
end

for (msh in Mesh)
    OutMesh(msh)
end

"EnableSceneRedraw()\n"
")"

return      // exit

// Functions

// Output scene-wide parameters, and shot background

function Header(ob)
    shot = ob.shot

    "-- MaxScript Exporter: " Scene.sourceFile "\n"
    DateTime("-- Exported %a, %b %d, %Y %I:%M:%S %p\n")
    "-- Intended for 3ds max Version "
       (MaxVersion>=6 ? "6 or later" : MaxVersion) "\n"

// Very important: frameRate must be set BEFORE the paren, so that
// 3ds max interprets the frame range correctly.
    "frameRate = " shot.rate "\n"
    "(\n"      // make it all one big block

    if (MaxVersion >= 6)
   if (Scene.exportUnits == "in")
       unflg = "#Inches"
   elseif (Scene.exportUnits == "ft")
       unflg = "#Feet"
   elseif (Scene.exportUnits == "yd")
       MessageBox("3ds max does not support yards, using meters instead")
       unflg = "#Meters"
   elseif (Scene.exportUnits == "mi")
       unflg = "#Miles"
   elseif (Scene.exportUnits == "mm")
       unflg = "#Millimeters"
   elseif (Scene.exportUnits == "cm")
       unflg = "#Centimeters"
   elseif (Scene.exportUnits == "m")
       unflg = "#Meters"
   elseif (Scene.exportUnits == "km")
       unflg = "#Kilometers"
   end
   "units.SystemType = " unflg "\n"
    end

    firstFrame = shot.start
    lastFrame = shot.stop
    "animationRange = interval " firstFrame+bias "f " lastFrame+bias "f\n"

    if (MaxVersion < 6)
   "setUseDraftRenderer true\n"
    end
    "renderWidth = " shot.width "\n"
    "renderHeight = " shot.height "\n"
    "renderPixelAspect = " shot.aspect*shot.height/shot.width "\n"

    if (MaxVersion < 6)
   "setUseDraftRenderer false\n"
   "renderWidth = " shot.width "\n"
   "renderHeight = " shot.height "\n"
   "renderPixelAspect = " shot.aspect*shot.height/shot.width "\n"
    end

    shnm = fix_slashes(shot.nm)
    if (substr(shnm, 1, 2) == "//")
   shnm = ("/" shnm)
    end
    "backgroundImageFileName = \"" shnm "\"\n"
    "setBkgFrameRange [" firstFrame+bias ", " lastFrame+bias ", 1]\n"
    "setBkgImageAspect #output\n"
    "setBkgImageAnimate true\n"
    "max grid toggle\n"
    "realTimePlayback = false\n"
end

// Output the information for a camera or moving object

function OutObj(ob)
    onm = ob.nm
    basecam = ob.cam
    wsize = ob.worldSize
    pathChange = DoesTransformChange(ob)
    fixedLens = IsLensFixed(basecam)

// Set up the base object in MAX

    frame = firstFrame
    "set animate off\n"
    if (!ob.isCamera)
   "newobj = Box widthsegs:1 heightsegs:1 lengthsegs:1"
   " name:\"" onm "\" length:" wsize/20 " width:" wsize/20
   " height:" wsize/20
   " isSelected:on \n"
   "newobj.transform = matrix3" OutMatrix(ob.trans) "\n"
    else
   "newobj = Freecamera name:\"" onm "\" fov:" basecam.fov
      " targetDistance:160 nearclip:1"
      " farclip:1000 nearrange:0 farrange:1000" " isSelected:on\n"
   "newobj.transform = matrix3" OutMatrix(ob.trans) "\n"
//   "viewport.setCamera $" onm "\n"
   "viewport.setCamera newobj\n"
    end
    "newobj.showTrajectory = on\n"

// Whale out the output trajectory.

    if (pathChange || ob.isCamera && !fixedLens)
   "set animate on\n"
   for (frame = firstFrame; frame <= lastFrame; frame++)
//       "sliderTime = " frame+bias "f\n"
       "at time " frame+bias "f (\n"
       if (pathChange)
      "newobj.transform = matrix3" OutMatrix(ob.trans) "\n"
       end

       if (ob.isCamera && !fixedLens)
      "newobj.fov = " basecam.fov "\n"
       end
       ")\n"
   end
   "set animate off\n"
    end
    "sliderTime = " firstFrame+bias "f\n"

// The trackers

    frame = firstFrame
    for (tk in ob.trk)
   if (!tk.isSolved || !tk.isExported)
       continue
   end

// Special handling for individual trackers

   if (tk.isSolved == 2)
       frame = firstFrame
       printf("newtk = Point name:\"%s\" pos:[%lf,%lf,%lf] size:%lf "
      "axistripod:off centermarker:on isSelected:on\n",
      tk.nm, tk.wx, tk.wy, tk.wz, trackerSize*wsize)
      rgb_r = (tk.color & 255)
      rgb_g = (tk.color >> 8 & 255)
      rgb_b = (tk.color >> 16 )
      printf("$.wirecolor = [%ld ,%ld ,%ld] \n",rgb_r ,rgb_g ,rgb_b )
       "set animate on\n"
       for (frame = firstFrame; frame <= lastFrame; frame++)
      "at time " frame+bias "f (\n"
          printf("newtk.pos = [%lf,%lf,%lf]\n",
         tk.wx, tk.wy, tk.wz)
      ")\n"
       end
       "set animate off\n"
       "sliderTime = " firstFrame+bias "f\n"
       continue
   end

// Always output wvec, not ovec. Are same if isCamera. If isObject,
//   need to output world anyway, so that when parent is changed,
//   the right spot results.
// Must output ovec for far points, however, so that the position_list
//   stuff works right.

   if (tk.isFar)
       printf("Point name:\"%s\" pos:[%lf,%lf,%lf] size:%lf "
      "axistripod:off centermarker:on isSelected:on\n",
      tk.nm, tk.ovec.x, tk.ovec.y, tk.ovec.z, trackerSize*wsize)
      rgb_r = (tk.color & 255)
      rgb_g = (tk.color >> 8 & 255)
      rgb_b = (tk.color >> 16 )
      printf("$.wirecolor = [%ld ,%ld ,%ld] \n",rgb_r ,rgb_g ,rgb_b )
   else
       printf("Point name:\"%s\" pos:[%lf,%lf,%lf] size:%lf "
      "axistripod:off centermarker:on isSelected:on\n",
      tk.nm, tk.wvec.x, tk.wvec.y, tk.wvec.z, trackerSize*wsize)
      rgb_r = (tk.color & 255)
      rgb_g = (tk.color >> 8 & 255)
      rgb_b = (tk.color >> 16 )
      printf("$.wirecolor =[%ld ,%ld ,%ld] \n",rgb_r ,rgb_g ,rgb_b )

   end

   if (!ob.isCamera)       // keep in parent system!
       "$.parent = $" onm "\n"
   end

// Need special fun and games for far points

   if (tk.isFar)
       "nctl = position_list()\n"
       "nctl.available.controller = $" onm ".pos.controller\n"
       "nctl.available.controller = $.pos.controller\n"
       "$.pos.controller = nctl\n"
   end
    end
end

// Build a light to correspond to SynthEyes lights.

function OutLite(lite)

    lightChange = DoesTransformChange(lite)
    "set animate off\n"

    if (lite.kind == "omni")
   "omniLight name:\"" lite.nm "\""
    else
   "directionalLight name:\"" lite.nm "\""
    end
    " isSelected:on \n"

    frame = firstFrame
    "$.transform = matrix3" OutMatrix(lite.trans) "\n"

    if (lightChange)
   "$.showTrajectory = on\n"
   "set animate on\n"
   for (frame = firstFrame; frame <= lastFrame; frame++)
       "sliderTime = " frame+bias "f\n"
       "$.transform = matrix3" OutMatrix(lite.trans) "\n"
   end
   "set animate off\n"
   "sliderTime = " firstFrame+bias "f\n"
    end
end

// This is just a quick test at this.
// Also probably need to modify transform, challenging at present.
// Scaling may need adjustment
// Custom (imported) meshes would require mesh access from Sizzle,
// and a way to create the mesh in maxscript. Stay tuned.

function OutMesh(mesh)

    meshChange = DoesMeshTransformChange(mesh)

    "set animate off\n"

    frame = firstFrame
    actkind = mesh.kind      // probably need to remap names
    if (actkind == "Guy" || actkind == "TrackerMesh" || actkind == "Custom")
   actkind = "Box"
    end
    actkind " name:\"" mesh.nm "\""

    if (actkind == "Box" || actkind == "Guy")
   " width:" mesh.sx " length:" mesh.sy " height:" mesh.sz
    elseif (actkind == "Plane")
   " width:" mesh.sx " length:" mesh.sy " height:" mesh.sz
    elseif (actkind == "Pyramid")
   " width:" mesh.sx " depth:" mesh.sy " height:" mesh.sz
    elseif (actkind == "Sphere")
   " radius:" 0.5*mesh.sx
   printf(" pos:[%lg,%lg,%lg]",
       mesh.wtrans.px + mesh.sx*0.5*mesh.wtrans.cx,
       mesh.wtrans.py + mesh.sx*0.5*mesh.wtrans.cy,
       mesh.wtrans.pz + mesh.sx*0.5*mesh.wtrans.cz)
    elseif (actkind == "Cylinder")
   " radius:" 0.5*mesh.sx " height:" mesh.sz
    elseif (actkind == "Cone")
   " radius1:" 0.5*mesh.sx " radius2:" 0 " height:" mesh.sz
    end

    if (actkind != "Sphere")
   " transform:(matrix3" OutMatrix(mesh.wtrans) ")"
    end
    " isSelected:on\n"

    if (meshChange)
   "$.showTrajectory = on\n"
   "set animate on\n"
   for (frame = firstFrame; frame <= lastFrame; frame++)
       "sliderTime = " frame+bias "f\n"
       "$.transform = matrix3" OutMatrix(mesh.wtrans) "\n"
   end
   "set animate off\n"
   "sliderTime = " firstFrame+bias "f\n"
    end
end

// Support routines.

function OutMatrix(mmat)
    printf(" \\\n\t[%lf,%lf,%lf]\\\n\t[%lf,%lf,%lf]"
   "\\\n\t[%lf,%lf,%lf]\\\n\t[%lf,%lf,%lf]",
   mmat.ax, mmat.ay, mmat.az,
   mmat.bx, mmat.by, mmat.bz,
   mmat.cx, mmat.cy, mmat.cz,
   mmat.px, mmat.py, mmat.pz)
end

// returns 2: rot changes, 1: pos changes, 0: both stationary (3:both chg)

function DoesTransformChange(ob)
    frame = firstFrame
    tr0 = ob.trans
    pos0 = ob.rowP
    rv = 0;
    for (frame = firstFrame+1; frame <= lastFrame; frame++)
   tr = ob.trans
   rv |= ((tr.rowP != pos0) ? 1 : 0)
   rv |= ((tr != tr0) ? 2 : 0)
    end
    return rv;
end

function DoesMeshTransformChange(ob)
    frame = firstFrame
    tr0 = ob.wtrans
    pos0 = ob.rowP
    rv = 0;
    for (frame = firstFrame+1; frame <= lastFrame; frame++)
   tr = ob.wtrans
   rv |= ((tr.rowP != pos0) ? 1 : 0)
   rv |= ((tr != tr0) ? 2 : 0)
    end
    return rv;
end


// Check to see if the lens fov is fixed, indep of mode

function IsLensFixed(cam)
    frame = firstFrame
    fov0 = cam.fov //+ 0
    for (frame = firstFrame+1; frame <= lastFrame; frame++)
   if (cam.fov != fov0)
       return 0
   end
    end
    return 1
end

function fix_slashes(slname)
    newname = ""
    for (chno = 1; chno <= length(slname); chno++)
   chr = substr(slname, chno, 1)
   if (chr == "\\")
       chr = "\\\\"
   end
   newname = (newname chr)
    end
    return newname
end
Back to top
View user's profile Send private message Visit poster's website
rtep



Joined: 12 Mar 2008
Posts: 142
Location: at the moment its Munich

PostPosted: Wed Feb 17, 2010 8:07 am    Post subject: Reply with quote

heh, about colors

I was always wondering how sizzle's 24bit color value relates to RGB values.
I'm everything but a coding or scripting type of guy and the sizzle's color value was something totally mysterious for me and far beyond my understanding... I didn't ask anyone, asking's lame, nothing beats the feeling after figuring out some crap yourself hehe Very Happy

And today I finally cracked it!
tk.color = red+green*256+blue*65536
I still don't have a clue why is it so, I just figured it out by scrutinizing the values that sizzle gives me after manually assigning various RGB values to trackers on tracker panel....

Very Happy
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.ssontech.com Forum Index -> Sizzle Scripting (NOT TECH SUPPORT) All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group