1
0

SVGLoader.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. [page:Loader] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">用于加载`.svg`资源的加载器<br >
  13. [link:https://en.wikipedia.org/wiki/Scalable_Vector_Graphics 可伸缩向量图形]是XML形式的矢量图形格式,用来描述二维矢量图形并支持交互和动画。
  14. </p>
  15. <h2>导入</h2>
  16. <p>
  17. [name]是附加功能,必须显示引用。
  18. 请参考[link:#manual/introduction/Installation Installation / Addons].
  19. </p>
  20. <code>
  21. import { SVGLoader } from 'three/addons/loaders/SVGLoader.js';
  22. </code>
  23. <h2>代码示例</h2>
  24. <code>
  25. // instantiate a loader
  26. const loader = new SVGLoader();
  27. // load a SVG resource
  28. loader.load(
  29. // resource URL
  30. 'data/svgSample.svg',
  31. // called when the resource is loaded
  32. function ( data ) {
  33. const paths = data.paths;
  34. const group = new THREE.Group();
  35. for ( let i = 0; i < paths.length; i ++ ) {
  36. const path = paths[ i ];
  37. const material = new THREE.MeshBasicMaterial( {
  38. color: path.color,
  39. side: THREE.DoubleSide,
  40. depthWrite: false
  41. } );
  42. const shapes = SVGLoader.createShapes( path );
  43. for ( let j = 0; j < shapes.length; j ++ ) {
  44. const shape = shapes[ j ];
  45. const geometry = new THREE.ShapeGeometry( shape );
  46. const mesh = new THREE.Mesh( geometry, material );
  47. group.add( mesh );
  48. }
  49. }
  50. scene.add( group );
  51. },
  52. // called when loading is in progresses
  53. function ( xhr ) {
  54. console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
  55. },
  56. // called when loading has errors
  57. function ( error ) {
  58. console.log( 'An error happened' );
  59. }
  60. );
  61. </code>
  62. <h2>示例</h2>
  63. <p>
  64. [example:webgl_loader_svg]
  65. </p>
  66. <h2>构造函数</h2>
  67. <h3>[name]( [param:LoadingManager manager] )</h3>
  68. <p>
  69. [page:LoadingManager manager] — 加载器使用的[page:LoadingManager 加载器管理]。默认值为[page:LoadingManager THREE.DefaultLoadingManager]。
  70. </p>
  71. <p>
  72. 创建一个新的[name]。
  73. </p>
  74. <h2>属性</h2>
  75. <p>查看公共属性请参考基类[page:Loader]。</p>
  76. <h2>方法</h2>
  77. <p>查看公共方法请参考基类[page:Loader]。</p>
  78. <h3>[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  79. <p>
  80. [page:String url] — 一个`.svg`文件的路径或者网络地址。<br />
  81. [page:Function onLoad] — (可选的)加载成功之后调用的函数。该函数以[page:ShapePath]为参数。<br />
  82. [page:Function onProgress] — (可选的)正在加载时调用的函数。参数为XMLHttpRequest实例,包含[page:Integer total]和[page:Integer loaded]。
  83. 如果服务没有设置Content-Length头,.[page:Integer total]的值为0。<br />
  84. [page:Function onError] — (可选的)加载出现错误时调用的函数。该函将错误信息作为参数。<br />
  85. </p>
  86. <p>
  87. 根据请求的URL开始加载并根据返回内容调用onLoad。
  88. </p>
  89. <h2>静态方法</h2>
  90. <h3>[method:Array createShapes]( [param:ShapePath shape] )</h3>
  91. <p>
  92. [page:ShapePath shape] — 一个[page:ShapePath]的矢量图形数组,指定[page:SVGLoader]的onLoad函数的参数。<br />
  93. </p>
  94. <p>
  95. 返回一个或多个基于[param:ShapePath shape]的[page:Shape]对象,并作为该函数的一个参数返回。
  96. </p>
  97. <h2>源代码</h2>
  98. <p>
  99. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/SVGLoader.js examples/jsm/loaders/SVGLoader.js]
  100. </p>
  101. </body>
  102. </html>