【cocos creator】【sharder】渲染相机图像到指定图片上,可对图片进行shardr操作


@ccclass
@executionOrder(-1)
export default class RenderingGroup extends cc.Component {
    //输入的相机,不能为主相机,要新建一个
    @property(cc.Camera)
    protected inputCamera: cc.Camera = null;
    //输出的图像
    @property(cc.Sprite)
    protected outputSprite: cc.Sprite = null;

    //输出纹理
    protected renderTexture: cc.RenderTexture = null;

    /**
     * 生命周期:加载
     */
    protected onLoad() {
        this.init();
        this.registerEvent();
    }

    /**
     * 生命周期:销毁
     */
    protected onDestroy() {
        this.unregisterEvent();
        this.release();
    }

    /**
     * 注册事件
     */
    protected registerEvent() {
        cc.Canvas.instance.node.on(cc.Node.EventType.SIZE_CHANGED, this.onCanvasSizeChanged, this);
    }

    /**
     * 关闭注册事件
     */
    protected unregisterEvent() {
        cc.Canvas.instance.node.off(cc.Node.EventType.SIZE_CHANGED, this.onCanvasSizeChanged, this);
    }
    /**
     * 初始化
     */
    protected init() {
        this.getCameraTexture(this.node)

        // 新建一个 RenderTexture,并且设置 camera 的 targetTexture 为新建的 RenderTexture,
        // 这样 camera 的内容将会渲染到新建的 RenderTexture 中。
        const renderTexture = this.renderTexture = new cc.RenderTexture(),
            screenSize = cc.view.getVisibleSizeInPixel();
        renderTexture.initWithSize(screenSize.width, screenSize.height);
        // 将摄像机的内容渲染到目标纹理上
        this.inputCamera.targetTexture = renderTexture;
        // 使用目标纹理生成精灵帧并设置到精灵上
        this.outputSprite.spriteFrame = new cc.SpriteFrame(renderTexture);
        this.outputSprite.node.scaleY = -Math.abs(this.outputSprite.node.scaleY);
    }

    /**
     * 释放
     */
    protected release() {
        this.renderTexture.destroy();
    }

    /**
     * 画布尺寸变化回调
     */
    protected onCanvasSizeChanged() {
        const screenSize = cc.view.getVisibleSizeInPixel();
        this.renderTexture.initWithSize(screenSize.width, screenSize.height);
    }

    /**
     * 获取节点整体图像
     * @param node 
     * @returns 
     */
    public getCameraTexture(node: cc.Node): cc.Camera {
        if (this.inputCamera) return this.inputCamera
        let camera = node.addComponent(cc.Camera);
        // 设置你想要的截图内容的 cullingMask
        camera.cullingMask = 0;
        camera.cullingMask |= (1 << 3);//group所在的分组
        // // 当相机everything 时,cullingMask 为 -1,即32个1,0xffffffff;
        // // 当相机nothing 时,cullingMask 等于 0;

        // // 渲染除去层x的所有层
        // camera.cullingMask = ~(1 << x);            
        // // 关闭(减掉)层 x      
        // camera.cullingMask &= ~(1 << x);  
        // // 打开(增加)层 x      
        // camera.cullingMask |= (1 << x);  
        // // 摄像机只显示第x层, y层, z层.
        // camera.cullingMask = (1 << x) + (1 << y)  + (1 << z); 
        camera.clearFlags = cc.Camera.ClearFlags.STENCIL | cc.Camera.ClearFlags.DEPTH;
        camera.depth = 0;
        camera.rect = cc.rect(0, 0, 1, 1);
        camera.zoomRatio = Math.min(cc.winSize.height / node.height, cc.winSize.width / node.width)
        this.inputCamera = camera
        return camera;
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
信息数据从传统到当代,是一直在变革当中,突如其来的互联网让传统的信息管理看到了革命性的曙光,因为传统信息管理从时效性,还是安全性,还是可操作性等各个方面来讲,遇到了互联网时代才发现能补上自古以来的短板,有效的提升管理的效率和业务水平。传统的管理模式,时间越久管理的内容越多,也需要更多的人来对数据进行整理,并且数据的汇总查询方面效率也是极其的低下,并且数据安全方面永远不会保证安全性能。结合数据内容管理的种种缺点,在互联网时代都可以得到有效的补充。结合先进的互联网技术,开发符合需求的软件,让数据内容管理不管是从录入的及时性,查看的及时性还是汇总分析的及时性,都能让正确率达到最高,管理更加的科学和便捷。本次开发的高校科研信息管理系统实现了操作日志管理、字典管理、反馈管理、公告管理、科研成果管理、科研项目管理、通知管理、学术活动管理、学院部门管理、科研人员管理、管理员管理等功能。系统用到了关系型数据库中王者MySql作为系统的数据库,有效的对数据进行安全的存储,有效的备份,对数据可靠性方面得到了保证。并且程序也具备程序需求的所有功能,使得操作性还是安全性都大大提高,让高校科研信息管理系统更能从理念走到现实,确确实实的让人们提升信息处理效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

烧仙草奶茶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值