Add display object module
This commit is contained in:
parent
2a9268567c
commit
3efb691601
@ -1,7 +1,7 @@
|
|||||||
import { BasicsShader } from "./BasicShader";
|
import { BasicsShader } from "./BasicShader";
|
||||||
import { GLContextObject } from "./GLContext";
|
import { DisplayObject } from "./DisplayObject";
|
||||||
|
|
||||||
class Axis extends GLContextObject{
|
class Axis extends DisplayObject{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 坐标轴数据
|
* 坐标轴数据
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { GLContextObject } from "./GLContext";
|
import { DisplayObject } from "./DisplayObject";
|
||||||
import { BasicsShader } from "./BasicShader";
|
import { BasicsShader } from "./BasicShader";
|
||||||
|
|
||||||
class BaseCube extends GLContextObject{
|
class BaseCube extends DisplayObject{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 立方体数据
|
* 立方体数据
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { GLContextObject } from "./GLContext";
|
import { DisplayObject } from "./DisplayObject";
|
||||||
import { GroupShader } from "./GroupShader";
|
import { GroupShader } from "./GroupShader";
|
||||||
import { ObjectData } from "@Model/Renderer";
|
import { ObjectData } from "@Model/Renderer";
|
||||||
|
|
||||||
class BasicGroup extends GLContextObject{
|
class BasicGroup extends DisplayObject{
|
||||||
|
|
||||||
private pointVertexBuffer: WebGLBuffer | null = null;
|
private pointVertexBuffer: WebGLBuffer | null = null;
|
||||||
private pointVecMaxCount: number = 100 * 3;
|
private pointVecMaxCount: number = 100 * 3;
|
||||||
|
@ -12,9 +12,7 @@ class ClassicRenderer extends BasicRenderer<{}, IClassicRendererParams> {
|
|||||||
|
|
||||||
private basicShader: BasicsShader = undefined as any;
|
private basicShader: BasicsShader = undefined as any;
|
||||||
private axisObject: Axis = undefined as any;
|
private axisObject: Axis = undefined as any;
|
||||||
private cubeObject: BaseCube = undefined as any;
|
|
||||||
private groupShader: GroupShader = 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 cubeRadius = 2**.5;
|
||||||
private readonly farFogLine = 2.5;
|
private readonly farFogLine = 2.5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点存储池数组
|
||||||
|
*/
|
||||||
|
private groupPool = new Map<ObjectID, BasicGroup>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 立方体储池数组
|
||||||
|
*/
|
||||||
|
private cubePool = new Map<ObjectID, BaseCube>();
|
||||||
|
|
||||||
public onLoad(): void {
|
public onLoad(): void {
|
||||||
|
|
||||||
// 自动调节分辨率
|
// 自动调节分辨率
|
||||||
this.autoResize();
|
this.autoResize();
|
||||||
|
|
||||||
this.basicShader = new BasicsShader().bindRenderer(this);
|
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.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", () => {
|
this.canvas.on("mousemove", () => {
|
||||||
|
|
||||||
@ -84,8 +99,17 @@ class ClassicRenderer extends BasicRenderer<{}, IClassicRendererParams> {
|
|||||||
|
|
||||||
this.cleanCanvas();
|
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;
|
const position = 120;
|
||||||
|
20
source/GLRender/DisplayObject.ts
Normal file
20
source/GLRender/DisplayObject.ts
Normal 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;
|
Loading…
Reference in New Issue
Block a user