• LayaBox 摄像机Unit8Array数据获取、截图


    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 }
    View Code

    但是如果需要获取相机数据的话,则调用它自带的函数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);
    }
  • 相关阅读:
    数组相关操作
    控制结构和函数
    调用函数和方法
    常用类型、算术和操作符重载
    函数式 CSS (FCSS)
    Javascript 封装问题
    认识javascript中的作用域和上下文
    Javascript 继承-原型的陷阱
    解耦你的HTML,CSS和JAVASRIPT
    网格如此简单
  • 原文地址:https://www.cnblogs.com/huojiaoqingchun0123/p/15419906.html
Copyright © 2020-2023  润新知