Add display object module

This commit is contained in:
MrKBear 2022-02-16 14:17:54 +08:00
parent 2a9268567c
commit 3efb691601
5 changed files with 59 additions and 15 deletions

View File

@ -1,7 +1,7 @@
import { BasicsShader } from "./BasicShader";
import { GLContextObject } from "./GLContext";
import { DisplayObject } from "./DisplayObject";
class Axis extends GLContextObject{
class Axis extends DisplayObject{
/**
*

View File

@ -1,7 +1,7 @@
import { GLContextObject } from "./GLContext";
import { DisplayObject } from "./DisplayObject";
import { BasicsShader } from "./BasicShader";
class BaseCube extends GLContextObject{
class BaseCube extends DisplayObject{
/**
*

View File

@ -1,8 +1,8 @@
import { GLContextObject } from "./GLContext";
import { DisplayObject } from "./DisplayObject";
import { GroupShader } from "./GroupShader";
import { ObjectData } from "@Model/Renderer";
class BasicGroup extends GLContextObject{
class BasicGroup extends DisplayObject{
private pointVertexBuffer: WebGLBuffer | null = null;
private pointVecMaxCount: number = 100 * 3;

View File

@ -12,9 +12,7 @@ class ClassicRenderer extends BasicRenderer<{}, IClassicRendererParams> {
private basicShader: BasicsShader = undefined as any;
private axisObject: Axis = undefined as any;
private cubeObject: BaseCube = undefined as any;
private groupShader: GroupShader = undefined as any;
private basicGroup: BasicGroup = undefined as any;
/**
*
@ -23,19 +21,36 @@ class ClassicRenderer extends BasicRenderer<{}, IClassicRendererParams> {
private readonly cubeRadius = 2**.5;
private readonly farFogLine = 2.5;
/**
*
*/
private groupPool = new Map<ObjectID, BasicGroup>();
/**
*
*/
private cubePool = new Map<ObjectID, BaseCube>();
public onLoad(): void {
// 自动调节分辨率
this.autoResize();
this.basicShader = new BasicsShader().bindRenderer(this);
this.axisObject = new Axis().bindRenderer(this);
this.cubeObject = new BaseCube().bindRenderer(this);
this.groupShader = new GroupShader().bindRenderer(this);
this.basicGroup = new BasicGroup().bindRenderer(this);
this.axisObject = new Axis().bindRenderer(this);
// 测试渲染器
if (true) {
let cubeObject = new BaseCube().bindRenderer(this);
let basicGroup = new BasicGroup().bindRenderer(this);
// 生成随机数据测试
this.basicGroup.upLoadData(new Array(1000 * 3).fill(0).map(() => (Math.random() - .5) * 2));
// 生成随机数据测试
basicGroup.upLoadData(new Array(1000 * 3).fill(0).map(() => (Math.random() - .5) * 2));
this.cubePool.set("1", cubeObject);
this.groupPool.set("1", basicGroup);
}
this.canvas.on("mousemove", () => {
@ -84,8 +99,17 @@ class ClassicRenderer extends BasicRenderer<{}, IClassicRendererParams> {
this.cleanCanvas();
this.cubeObject.draw(this.basicShader);
this.basicGroup.draw(this.groupShader);
// 绘制全部立方体
this.cubePool.forEach((cube) => {
if (cube.isDraw) cube.draw(this.basicShader);
else cube.drawEmptyFrame ++;
});
// 绘制全部点
this.groupPool.forEach((group) => {
if (group.isDraw) group.draw(this.groupShader);
else group.drawEmptyFrame ++;
});
// 右上角绘制坐标轴
const position = 120;

View File

@ -0,0 +1,20 @@
import { EventType } from "@Model/Emitter";
import { GLContextObject } from "./GLContext";
abstract class DisplayObject<
E extends Record<EventType, any> = {}
> extends GLContextObject<E> {
/**
*
*/
public isDraw: boolean = true;
/**
*
*/
public drawEmptyFrame: number = 0;
}
export { DisplayObject }
export default DisplayObject;