引擎版本: 1.1.1
實現的效果
可以在模型上添加自定義文本
思路
1.建立一個畫布 渲染模式 -> intersperse
2.畫布的渲染優先級 低於 3d 攝像機
3.畫布的 ClearFlag 為 Solid_Color
4.新建一張渲染紋理, 給畫布的 TargetTexture 屬性賦值, 讓畫布看到的內容渲染到這個RenderTexture上
5.找到你想要更換模型的材質, 找到他應用的紋理,
6.將這張紋理在畫布里放置一張,再新建一個Lable在這個紋理上面寫你想要的字體
7.給模型更換為你這個在原有模型紋理的基礎上 加上文本的的紋理.
這個是畫布的配置
3d 攝像機的配置
做法
我這里說一下里面的核心代碼,剩下的靠你自己動手了,不在多闡述.
自定義 RenderTexture 實例
const renderTex = new RenderTexture();
renderTex.reset({
width: 512,
height: 512,
colorFormat: RenderTexture.PixelFormat.RGBA8888,
depthStencilFormat: RenderTexture.DepthStencilFormat.DEPTH_24_STENCIL_8,
});
給畫布賦值
this.canvas.targetTexture = renderTex;
給模型更換紋理
// 這一段代碼是官方提供的
// 自己使用 material 的設置屬性的方法更新紋理會報錯.
// 所以就用官方提供的這個方法.
const pass = this.modle.material.passes[0];
const binding = pass.getBinding('mainTexture');
pass.bindTextureView(binding, renderTex.getGFXTextureView());
注意
后續在畫布上的任何操作都會將操作后的內容渲染下來給你更換的模型換紋理.
再見.