Skip to main content
Jongware
Community Expert
Community Expert
July 18, 2009
Question

[JS] 3D Extrude Object Script

  • July 18, 2009
  • 2 replies
  • 9220 views

Brought to the idea by dreamriverdesign's question of how to script a 3D box extrude from an image, I decided to try this for any object. It was a bit of a struggle, trying to get the curved lines just right, but I think I got it (almost

  • 😞
  • The script asks for the extrusion color and offsets, and can optionally combine the extrusion (making the black part above a single object) or leave it as numerous little objects, and/or group the extruded part together with the original.

    Download the script from http://www.jongware.com/binaries/extrude.zip

    It works on CS, I haven't been able to test on CS2, CS3, or CS4, so please report back if it doesn't work.

  • It's almost right, because tight curves appear 'copied' rather than extruded along the most extreme curved edge. But the math to get that right is horrible. You'll just have to live with that, correct by hand, or ... adjust the script (and in that case I'd love to hear from you!).
  • This topic has been closed for replies.

    2 replies

    Jongware
    Community Expert
    JongwareCommunity ExpertAuthor
    Community Expert
    July 23, 2009

    A week ago I said

    ... tight curves appear 'copied' rather than extruded along the most extreme curved edge. But the math to get that right is horrible.

    and I stand by that. The problem is how to calculate a tangent to a bezier curve at the precise angle (dx/dy), and I'm not that good in math.

    Fortunately, many roads lead to Rome (and if you happen to be a true Roman, many roads lead away from it as well). I chose the easier road: I added a piece of code to sub-divide each curve into straight segments and used that to add the drop box segments. Sub-dividing random curves into a fixed number of straight lines sometimes leads to unseemly angles, especially if the entire curve is rather large, or it bends around itself tightly. So I added the 'flatten path' box: a high number will lead to a more precise curve (because more segments are created), but will make the script run slower. Try a higher value if you are not satisfied.

    The subdivision code appears courtesy of Maxim Shemanarov, one of my heroes, as he singlehandedly programmed an entire low level antialiased graphics library! It seems he has no problems at all with the required maths... (Do visit www.antigrain.com if that sounds interesting!)

    The new script is downloadable from my site: http://www.jongware.com/binaries/extrude-1.02.zip

    Jongware
    Community Expert
    JongwareCommunity ExpertAuthor
    Community Expert
    July 23, 2009

    Ha -- I accidentally removed the 'widen' option. Restored (extrude-1.02.zip is updated).

    Here is an image. Note the flattened curves -- it's just visible in the wireframe.

    Inspiring
    July 18, 2009

    You are amazing!

    In CS3, the script choked on

    A quick look at Indesign CS3.chm showed that GraphicLines want a strokeType, so I replaced it with

    and it worked perfectly on polygons and outlined text. I haven't examined any curves too closely yet...

    Noel

    Jongware
    Community Expert
    JongwareCommunity ExpertAuthor
    Community Expert
    July 18, 2009

    Good catch, Noel. My home version is CS, and it seems that has been changed somewhere in time. I included a rather ad hoc fix -- it just might work.

    Meanwhile, I was wondering if it was possible to expand or contract the extrusion. Just guess ..

    The new version is http://www.jongware.com/binaries/extrude-1.01.zip

    By the way, both offsets set to 0 and both scaling to 100% will give you an error from the pathfinder. Well ... in that case you wouldn't get any extrusion anyway, so don't do it.

    Jongware
    Community Expert
    JongwareCommunity ExpertAuthor
    Community Expert
    July 18, 2009
    A quick look at Indesign CS3.chm ...

    *cough* (embarrassed)