mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-05-09 11:55:52 +08:00
36 lines
1013 B
TypeScript
36 lines
1013 B
TypeScript
import { _decorator, Camera, Component, gfx, MeshRenderer, RenderTexture, view } from 'cc';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 三维摄像机内容显示到模型上 */
|
|
@ccclass('RtToModel')
|
|
export class RtToModel extends Component {
|
|
@property(Camera)
|
|
camara: Camera = null!;
|
|
|
|
@property(MeshRenderer)
|
|
model: MeshRenderer = null!;
|
|
|
|
private rt: RenderTexture = new RenderTexture();
|
|
|
|
start() {
|
|
const size = view.getVisibleSize();
|
|
const colorAttachment = new gfx.ColorAttachment();
|
|
const depthStencilAttachment = new gfx.DepthStencilAttachment();
|
|
const pi = new gfx.RenderPassInfo([colorAttachment], depthStencilAttachment);
|
|
|
|
this.rt.reset({
|
|
width: size.width,
|
|
height: size.height,
|
|
passInfo: pi
|
|
});
|
|
|
|
this.camara.targetTexture = this.rt;
|
|
const mat = this.model.material!;
|
|
mat.setProperty('mainTexture', this.rt);
|
|
}
|
|
|
|
onDestroy() {
|
|
this.rt.destroy();
|
|
}
|
|
}
|