SVGLoader.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. [page:Loader] &rarr;
  12. <h1>[name]</h1>
  13. <p class="desc">A loader for loading a <em>.svg</em> resource.<br >
  14. <a href="https://en.wikipedia.org/wiki/Scalable_Vector_Graphics">Scalable Vector Graphics</a> is an XML-based vector image format for two-dimensional graphics with support for interactivity and animation.
  15. </p>
  16. <h2>Example</h2>
  17. <code>
  18. // instantiate a loader
  19. var loader = new THREE.SVGLoader();
  20. // load a SVG resource
  21. loader.load(
  22. // resource URL
  23. 'data/svgSample.svg',
  24. // called when the resource is loaded
  25. function ( data ) {
  26. var paths = data.paths;
  27. var group = new THREE.Group();
  28. for ( var i = 0; i < paths.length; i ++ ) {
  29. var path = paths[ i ];
  30. var material = new THREE.MeshBasicMaterial( {
  31. color: path.color,
  32. side: THREE.DoubleSide,
  33. depthWrite: false
  34. } );
  35. var shapes = path.toShapes( true );
  36. for ( var j = 0; j < shapes.length; j ++ ) {
  37. var shape = shapes[ j ];
  38. var geometry = new THREE.ShapeBufferGeometry( shape );
  39. var mesh = new THREE.Mesh( geometry, material );
  40. group.add( mesh );
  41. }
  42. }
  43. scene.add( group );
  44. },
  45. // called when loading is in progresses
  46. function ( xhr ) {
  47. console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
  48. },
  49. // called when loading has errors
  50. function ( error ) {
  51. console.log( 'An error happened' );
  52. }
  53. );
  54. </code>
  55. [example:webgl_loader_svg]
  56. <h2>Constructor</h2>
  57. <h3>[name]( [param:LoadingManager manager] )</h3>
  58. <p>
  59. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
  60. </p>
  61. <p>
  62. Creates a new [name].
  63. </p>
  64. <h2>Properties</h2>
  65. <p>See the base [page:Loader] class for common properties.</p>
  66. <h2>Methods</h2>
  67. <p>See the base [page:Loader] class for common methods.</p>
  68. <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  69. <p>
  70. [page:String url] — A string containing the path/URL of the <em>.svg</em> file.<br />
  71. [page:Function onLoad] — (optional) A function to be called after loading is successfully completed. The function receives an array of [page:ShapePath] as an argument.<br />
  72. [page:Function onProgress] — (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, which contains [page:Integer total] and [page:Integer loaded] bytes.<br />
  73. [page:Function onError] — (optional) A function to be called if an error occurs during loading. The function receives the error as an argument.<br />
  74. </p>
  75. <p>
  76. Begin loading from url and call onLoad with the response content.
  77. </p>
  78. <h2>Source</h2>
  79. <p>
  80. [link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/SVGLoader.js examples/js/loaders/SVGLoader.js]
  81. </p>
  82. </body>
  83. </html>