最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Extrude, or, make 2d SVG path into 3d - Stack Overflow

programmeradmin3浏览0评论

I am wondering if anyone has heard of some javascript which can take a simple SVG path that took maybe 30 seconds to create in illustrator or something and convert it into something that looks 3d. There is an extrude function in illustrator which does this. It is also called polling in sketchUp.

I am using Raphael.js now, but am open to other suggestions. A simple solution would be to make a copy of the path and move it a couple pixels down and to the right and give it a darker color behind the original path, but I am looking for something that might have a little more shading.

Thanks!

I am wondering if anyone has heard of some javascript which can take a simple SVG path that took maybe 30 seconds to create in illustrator or something and convert it into something that looks 3d. There is an extrude function in illustrator which does this. It is also called polling in sketchUp.

I am using Raphael.js now, but am open to other suggestions. A simple solution would be to make a copy of the path and move it a couple pixels down and to the right and give it a darker color behind the original path, but I am looking for something that might have a little more shading.

Thanks!

Share Improve this question asked Apr 23, 2013 at 21:29 dezmandezman 19.4k12 gold badges57 silver badges92 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

There is always a possibility to use three.js for extruding the path for use in webGL in browser:

http://alteredqualia./three/examples/webgl_text.html#D81F0A21010#23a

(More samples here:http://stemkoski.github.io/Three.js/)

It uses js-fonts and parses the path mands on them, extrudes the paths and renders the scene. In the same way it should be possible to take an SVG path and extrude it. Raphael has Raphael.parsePathString() which gives you the path segments as an array of individual segments. If you first convert the path mands to cubic curves using Raphael.path2curve() and Raphael._pathToabsolute(), you have only only one segment type so you can use three.js:s BEZIER_CURVE_TO mand. If you have transformations applied on the path (which is usually the case in Illustrator export) you can flatten them using function from here: https://stackoverflow./a/13102801/1691517.

One possible starting point is here (click the fiddle of the answer): Extruding multiple polygons with multiple holes and texturing the bined shape

Three.js supports few path mands, but have not tested all of them ( http://threejsdoc.appspot./doc/three.js/src.source/extras/core/Path.js.html, see below).


THREE.PathActions = {

    MOVE_TO: 'moveTo',
    LINE_TO: 'lineTo',
    QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
    BEZIER_CURVE_TO: 'bezierCurveTo',       // Bezier cubic curve
    CSPLINE_THRU: 'splineThru',             // Catmull-rom spline
    ARC: 'arc'                              // Circle

};

I have used a custom rather plex function to polygonize SVG path, so was no need to rely to other mands than moveto and lineto.

The downside is of course rather low support level for webGL, 31-53%: http://caniuse./webgl


Other more cross-browser solution is this SVG3d library if lesser quality and slowness is not an issue:

http://debeissat.nicolas.free.fr/svg3d.php https://code.google./p/svg3d/

I think this resource could be helpful to you, he uses d3 to generate 2D visualization and then uses d3-threeD to extrude.

Sounds like you want to use svg filters. Webplatform has a pretty good tutorial about that. Scroll down a bit and you'll find some lighting filters that looks like 3d.

Raphaël doesn't support filters though, so either you'll need to extend it, or just use svg directly.

发布评论

评论列表(0)

  1. 暂无评论