最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小游戲中three.js離屏畫(huà)布的示例代碼

 更新時(shí)間:2020年10月12日 10:54:23   作者:火星牛  
這篇文章主要介紹了微信小游戲中three.js離屏畫(huà)布的示例代碼,主要是用three.js結(jié)合cannon.js寫(xiě)個(gè)3D小游戲,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下

國(guó)慶8天長(zhǎng)假,重慶之行因故未成,偶得閑,用three.js結(jié)合cannon.js寫(xiě)個(gè)3D小游戲耍耍。

在微信小游戲中,把three.js的3D內(nèi)容在離屏畫(huà)布處理,然后復(fù)制到在屏畫(huà)布,方法是:

let c_toolbarHeight=140;
 
let sysInfo=wx.getSystemInfoSync();
require('./js/libs/weapp-adapter.js');
var canvas_webGL=window.canvas;
canvas_webGL.width = sysInfo.screenWidth * sysInfo.pixelRatio;
canvas_webGL.height = (sysInfo.screenHeight-c_toolbarHeight) * sysInfo.pixelRatio;
var ctx_webGL=canvas_webGL.getContext('webgl');
 
let options={context: ctx_webGL}
let renderer = new THREE.WebGLRenderer(options);
renderer.setSize(sysInfo.screenWidth, sysInfo.screenHeight-c_toolbarHeight);
renderer.setPixelRatio(sysInfo.pixelRatio);
 
function render(){
  //清除canvas_bkg的3D區(qū)域
  wx.tmGlobal.eraseZone(0,
    c_toolbarHeight,
    sysInfo.screenWidth,
    sysInfo.screenHeight);
  renderer.render(scene, camera);
  wx.tmGlobal.ctx_bkg.drawImage(canvas_webGL,
    0,c_toolbarHeight*sysInfo.pixelRatio);
  //畫(huà)一條橫的紅線(xiàn)
  wx.tmGlobal.ctx_bkg.strokeStyle = '#FF8C00';
  wx.tmGlobal.ctx_bkg.lineWidth = 2;
  wx.tmGlobal.ctx_bkg.beginPath();
  wx.tmGlobal.ctx_bkg.moveTo(0,
    (c_toolbarHeight)*sysInfo.pixelRatio);
  wx.tmGlobal.ctx_bkg.lineTo(
    sysInfo.screenWidth*sysInfo.pixelRatio,
    (c_toolbarHeight)*sysInfo.pixelRatio);
  //畫(huà)游戲結(jié)束臨界線(xiàn)
  wx.tmGlobal.ctx_bkg.moveTo(0,
    (c_toolbarHeight+c_yugaoHeight)*sysInfo.pixelRatio);
  wx.tmGlobal.ctx_bkg.lineTo(
    sysInfo.screenWidth*sysInfo.pixelRatio,
    (c_toolbarHeight+c_yugaoHeight)*sysInfo.pixelRatio);
  wx.tmGlobal.ctx_bkg.stroke();
  //把canvas_bkg畫(huà)到在屏畫(huà)布
  wx.tmGlobal.ctx_main.clearRect(0,0,
    wx.tmGlobal.canvas_main.width,wx.tmGlobal.canvas_main.height);
    wx.tmGlobal.ctx_main.drawImage(wx.tmGlobal.canvas_bkg,0,0);
}

在vivo和iphone手機(jī)都表現(xiàn)正常,但是,華為手機(jī)顯示不出來(lái):

https://developers.weixin.qq.com/community/develop/doc/00026c3c1c8eb010de384a82d51000?jumpto=

其它用戶(hù)也提了好久了,騰訊或華為都沒(méi)有解決,試來(lái)試去,終于找到了另一種寫(xiě)法:

renderer = new THREE.WebGLRenderer();
let target = new THREE.WebGLRenderTarget(
  sysInfo.screenWidth*sysInfo.pixelRatio, 
  (sysInfo.screenHeight-c_toolbarHeight)*sysInfo.pixelRatio);
renderer.setRenderTarget(target);
gl=renderer.getContext();
​
var canvas_huawei=wx.createCanvas();
canvas_huawei.width=sysInfo.screenWidth*sysInfo.pixelRatio;
canvas_huawei.height=(sysInfo.screenHeight-c_toolbarHeight)*sysInfo.pixelRatio;
var ctx_huawei=canvas_huawei.getContext('2d');
​
var canvas_huawei2=wx.createCanvas();
canvas_huawei2.width=sysInfo.screenWidth*sysInfo.pixelRatio;
canvas_huawei2.height=(sysInfo.screenHeight-c_toolbarHeight)*sysInfo.pixelRatio;
var ctx_huawei2=canvas_huawei2.getContext('2d');
​
var imageData = ctx_huawei.createImageData(
  sysInfo.screenWidth*sysInfo.pixelRatio,
  (sysInfo.screenHeight-c_toolbarHeight)*sysInfo.pixelRatio);
var pixels = new Uint8Array(imageData.data.length);
​
function render(){
  //擦除背景畫(huà)布的webGL區(qū)域(因?yàn)閣ebGL是用的透明繪制)
  wx.tmGlobal.eraseZone(0,
    c_toolbarHeight,
    sysInfo.screenWidth,
    sysInfo.screenHeight);
  renderer.render(scene, camera);
  gl.readPixels(
      0,
      0,
      gl.drawingBufferWidth,
      gl.drawingBufferHeight,
      gl.RGBA,gl.UNSIGNED_BYTE,pixels);
  imageData.data.set(pixels);
  ctx_huawei.putImageData(imageData,0,0);
  //清除   
  ctx_huawei2.clearRect(0,0,canvas_huawei2.width,canvas_huawei2.height);
  //上下鏡像翻轉(zhuǎn)
  ctx_huawei2.translate(0,canvas_huawei2.height);
  ctx_huawei2.scale(1, -1);
  ctx_huawei2.drawImage(canvas_huawei,0,0);
  //恢復(fù)
  ctx_huawei2.translate(0,canvas_huawei2.height);
  ctx_huawei2.scale(1, -1);
  wx.tmGlobal.ctx_bkg.drawImage(canvas_huawei2,
      0,c_toolbarHeight*sysInfo.pixelRatio);
  ......
}

到此這篇關(guān)于微信小游戲中three.js離屏畫(huà)布的示例代碼的文章就介紹到這了,更多相關(guān)微信小游戲three.js離屏畫(huà)布內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

抚顺县| 浦北县| 静海县| 泸溪县| 吉木萨尔县| 舟曲县| 韶关市| 河东区| 新安县| 斗六市| 阿拉善左旗| 昌江| 巴林左旗| 临江市| 呼玛县| 三门峡市| 屏边| 琼中| 大兴区| 邯郸县| 南丹县| 慈利县| 涟源市| 西安市| 汉中市| 宝山区| 错那县| 九江市| 阳高县| 凉山| 安图县| 高邮市| 万州区| 上思县| 仁怀市| 惠安县| 黄骅市| 什邡市| 利辛县| 田东县| 滕州市|