小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Threejs 文字貼圖

 花心的程序員 2019-11-14

關(guān)于材質(zhì),threejs的官方文檔(https:///docs/index.html?q=material)講解比...

介紹完材質(zhì)后,我們來簡(jiǎn)單看看紋理貼圖。如果我們想在材質(zhì)上實(shí)現(xiàn)更加逼真的效果的話我們就要用到紋理貼圖了,例如墻磚,地板等。

加載紋理圖片我們使用TextureLoader

var texture = new THREE.TextureLoader().load("images/f2.jpg");

紋理可以設(shè)置水平和豎直方向的重復(fù)

texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;

可以設(shè)置重復(fù)的次數(shù)

texture.repeat.set(20, 20);

效果圖如下


下面介紹幾個(gè)特別的場(chǎng)景

1.要在立方體的不同面上貼上不同的圖片

這個(gè)時(shí)候我們需要使用MultiMaterial來當(dāng)作材質(zhì),指定不同面的紋理,每個(gè)面都是一個(gè)Material

var materials = [ 
 new THREE.MeshBasicMaterial( { map:new THREE.TextureLoader().load("images/right.jpg") } ), // right
 new THREE.MeshBasicMaterial( { map:new THREE.TextureLoader().load("images/left.jpg") } ), // left
 new THREE.MeshBasicMaterial( { map:new THREE.TextureLoader().load("images/top.jpg") } ), // top
 new THREE.MeshBasicMaterial( { map:new THREE.TextureLoader().load("images/bottom.jpg") } ), // bottom 
 new THREE.MeshBasicMaterial( { map:new THREE.TextureLoader().load("images/front.jpg") } ) // front 
 new THREE.MeshBasicMaterial( { map:new THREE.TextureLoader().load("images/back.jpg") } ), // back
]; 
var cubeSidesMaterial = new THREE.MultiMaterial( materials );

2.很多時(shí)候我們想動(dòng)態(tài)生成圖片或文字,當(dāng)作材質(zhì)紋理

這里可以使用canvas作為紋理貼圖,Three為我們提供里CanvasTexture

function getTextCanvas(text){ 
 var width=512, height=256; 
 var canvas = document.createElement('canvas');
 canvas.width = width;
 canvas.height = height;
 var ctx = canvas.getContext('2d');
 ctx.fillStyle = '#C3C3C3';
 ctx.fillRect(0, 0, width, height);
 ctx.font = 50+'px " bold';
 ctx.fillStyle = '#2891FF';
 ctx.textAlign = 'center';
 ctx.textBaseline = 'middle';
 ctx.fillText(text, width/2,height/2); 
 return canvas;
 }
var materials = [ 
 new THREE.MeshBasicMaterial( { color: 'blue' } ), // right
 new THREE.MeshBasicMaterial( { color: 'yellow' } ), // left
 new THREE.MeshBasicMaterial( { map: new THREE.CanvasTexture(getTextCanvas('Leo Test Label')) } ), // top
 new THREE.MeshBasicMaterial( { color: 'black' } ), // bottom
 new THREE.MeshBasicMaterial( { color: 'green' } ), // back
 new THREE.MeshBasicMaterial( { color: 'red' } ) // front 
 ];

這樣我們就可以利用canvas畫上文字或者圖形,用來填充紋理貼圖。

在線demo

本文由 Leo's Blog 創(chuàng)作,采用 署名-非商業(yè)性使用 2.5 中國(guó)大陸 進(jìn)行許可。
如需轉(zhuǎn)載、引用請(qǐng)署名作者且注明文章出處。             

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多