W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
用于加載 .svg 資源的加載程序。
可縮放矢量圖形是一種基于 XML 的矢量圖像格式,用于支持交互性和動(dòng)畫的二維圖形。
// instantiate a loader
const loader = new SVGLoader();
// load a SVG resource
loader.load(
// resource URL
'data/svgSample.svg',
// called when the resource is loaded
function ( data ) {
const paths = data.paths;
const group = new THREE.Group();
for ( let i = 0; i < paths.length; i ++ ) {
const path = paths[ i ];
const material = new THREE.MeshBasicMaterial( {
color: path.color,
side: THREE.DoubleSide,
depthWrite: false
} );
const shapes = SVGLoader.createShapes( path );
for ( let j = 0; j < shapes.length; j ++ ) {
const shape = shapes[ j ];
const geometry = new THREE.ShapeGeometry( shape );
const mesh = new THREE.Mesh( geometry, material );
group.add( mesh );
}
}
scene.add( group );
},
// called when loading is in progresses
function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
// called when loading has errors
function ( error ) {
console.log( 'An error happened' );
}
);
manager — 供加載器使用的 loadingManager。默認(rèn)值為 THREE.DefaultLoadingManager。
創(chuàng)建一個(gè)新的 SVGLoader。
請(qǐng)參閱基本 Loader 類以了解公共屬性。
常用方法見(jiàn) Loader 基類。
url — 包含 .svg 文件的路徑/URL 的字符串。
onLoad — (可選)加載成功完成后要調(diào)用的函數(shù)。該函數(shù)接收一個(gè) ShapePath 數(shù)組作為參數(shù)。
onProgress — (可選)在加載過(guò)程中調(diào)用的函數(shù)。參數(shù)將是 XMLHttpRequest 實(shí)例,它包含總字節(jié)數(shù)和加載字節(jié)數(shù)。
onError — (可選)加載期間發(fā)生錯(cuò)誤時(shí)調(diào)用的函數(shù)。該函數(shù)接收錯(cuò)誤作為參數(shù)。
從 url 開始加載并使用響應(yīng)內(nèi)容調(diào)用 onLoad。
靜態(tài)方法
shape — 來(lái)自 ShapePath 數(shù)組的 ShapePath,作為 SVGLoader 加載函數(shù)的 onLoad 函數(shù)中的參數(shù)給出。
返回一個(gè)或多個(gè)從 shape 創(chuàng)建的 Shape 對(duì)象:ShapePath 在此函數(shù)中作為參數(shù)提供。
examples/jsm/loaders/SVGLoader.js
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: