[three.js] 解決貼圖無法重複的問題 Solving with Texture RepeatWrapping Fail Issue

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   width   

有些東西,你想找的時侯,怎麼也找不到,

而有些東西,不經意間,隨處可見;

本以為這是生活中常見的事情,

然而在浩瀚的互聯大海中,也是如此。

平時的積累是為了一時之需,

幾分鐘的投入,

積累起來,

也會成為汪洋大海,

載起一帆小舟,

不至擱淺。

平時注一入滴水,

需時擁有太平洋,

廣告詞很好,

然而它真正的意義又有幾人能真正領悟呢!


附一個不錯的 threejs 開源連結:

https://github.com/rmx/threejs-collada


[three.js] 解決貼圖無法重複的問題 Solving with Texture RepeatWrapping Fail Issue

今天開發three.js專案的時候遇到了一個該死的問題,就是模型上的貼圖一直無法如願的作Repeating,不管我怎麼改,不管我怎麼貼,就是無法重複貼圖。

(正常的重複貼圖應該要是這樣)

(但結果一直是這樣,Mesh的兩端一直無法重複做貼圖)

所以我就拚命地對Texture改參數、查Document,總共耗了約4個多小時還是徒勞無功之後,我才認命地開始Google相關Issue。而這個Issue也真不好找,用了好多種關鍵字才找到最後的答案。

以下是相同Issue:

https://github.com/rmx/threejs-collada/issues/16

 

最後是three.js中的共同作者在文中回答:

About the texture repeat problem: WebGL only supports the repeat wrapping mode for power-of-two textures. Your ground texture is 401×401. You’ll need to resize it to 256×256 or 512×512 to get the desired effect. Three.js silently overrides the wrapping mode to clamp to edge if the texture is not power-of-two.

 

重重地往我臉上揍了一拳,才讓我想起當年在寫OpenGL ES的時候也遇過這個問題。也就是說,在這種輕量級的3D Rendering當中,WebGL為了讓圖形的處理可以保持在一定的效能,而無法支援NPOT Texture (Non-Power-of-Two),也就是貼圖的單邊解析度,必須是二的次方才行,比如 (64×64), (256×256) 或 (512×256), (32×64)。

 

While OpenGL 2.0 and later for the desktop offer full support for non-power-of-two (NPOT) textures, OpenGL ES 2.0 and WebGL have only limited NPOT support.

原因是為什麼呢?依照官方的檔案,應是Mipmap Generation以及Shader Execution的關係。

而官方也提出了相對應的方法:

However, if your application requires the REPEAT wrap mode for correctness, you can easily resize the image to the next largest power of two dimensions using DOM APIs. Here is an example of how to do this. image is an HTML image object that has been fully loaded; its onload handler has already been called.

也就是你可以用API將圖形調整為最接近的二的次方數,所以現在我們就可以漂亮地將該死的重複貼圖貼在我們該死的模型上啦~!



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.