LayaBox 本身可以直接利用数据渲染
1 { 2 let renderTextureWidth = 512; 3 let renderTextureHeight = 512; 4 let camera = this.scene.addChild(new Laya.Camera(0, 0.01, 500)); 5 camera.renderTarget = new Laya.RenderTexture(renderTextureWidth, renderTextureHeight); 6 camera.renderingOrder = 0; 7 camera.clearFlag = Laya.BaseCamera.CLEARFLAG_SOLIDCOLOR; 8 this.scene3DImage = new Laya.Image(); 9 this.scene3DImage.source = new Laya.Texture(camera.renderTarget); 10 Laya.stage.addChild(this.scene3DImage); 11 }
但是如果需要获取相机数据的话,则调用它自带的函数getData()即可,如下
{ let renderTextureWidth = 512; let renderTextureHeight = 512; let camera = this.scene.addChild(new Laya.Camera(0, 0.01, 500)); camera.renderTarget = new Laya.RenderTexture(renderTextureWidth, renderTextureHeight); camera.renderingOrder = 0; camera.clearFlag = Laya.BaseCamera.CLEARFLAG_SOLIDCOLOR; this.scene3DImage = new Laya.Image(); this.scene3DImage.source = new Laya.Texture(camera.renderTarget); Laya.stage.addChild(this.scene3DImage); let pixels = new Uint8Array(renderTextureWidth * renderTextureHeight * 4); this.camera.renderTarget.getData(0, 0, renderTextureWidth, renderTextureHeight, pixels); console.log(pixels); }