From 4f6aa66d5cfb4edb9dfe9826fe22e15ea5f4a76e Mon Sep 17 00:00:00 2001 From: Lucas Dower Date: Sat, 14 May 2022 15:48:36 +0100 Subject: [PATCH] Minor changes to axes rendering --- src/geometry.ts | 33 ++------------------------------- src/renderer.ts | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/geometry.ts b/src/geometry.ts index eec02b2..b58db60 100644 --- a/src/geometry.ts +++ b/src/geometry.ts @@ -210,8 +210,8 @@ export class DebugGeometryTemplates { public static arrow(start: Vector3, end: Vector3, colour: RGB): AttributeData { const line = DebugGeometryTemplates.line(start, end, colour); const lineLength = Vector3.sub(end, start).magnitude(); - const coneHeight = 0.1 * lineLength; - const coneRadius = 0.1 * coneHeight; + const coneHeight = 0.15 * lineLength; + const coneRadius = 0.15 * coneHeight; const normal = Vector3.sub(end, start).normalise(); const cone = DebugGeometryTemplates.cone(end, coneHeight, normal, coneRadius, colour, 1); @@ -229,35 +229,6 @@ export class DebugGeometryTemplates { const gridColourMinor = new RGB(0.15, 0.15, 0.15); const gridColourMajor = new RGB(0.3, 0.3, 0.3); - if (axes) { - buffer.add(DebugGeometryTemplates.line( - new Vector3(-gridRadius, 0, 0), - new Vector3(gridRadius, 0, 0), - new RGB(0.44, 0.64, 0.11), - )); - buffer.add(DebugGeometryTemplates.cone( - new Vector3(gridRadius, 0, 0), - 0.5, - new Vector3(1, 0, 0), - 0.1, - new RGB(0.44, 0.64, 0.11), - 8, - )); - buffer.add(DebugGeometryTemplates.line( - new Vector3(0, 0, -gridRadius), - new Vector3(0, 0, gridRadius), - new RGB(0.96, 0.21, 0.32)), - ); - buffer.add(DebugGeometryTemplates.cone( - new Vector3(0, 0, gridRadius), - 0.5, - new Vector3(0, 0, 1), - 0.1, - new RGB(0.96, 0.21, 0.32), - 8, - )); - } - if (bounds) { buffer.add(DebugGeometryTemplates.line( new Vector3(-gridRadius, 0, -gridRadius), diff --git a/src/renderer.ts b/src/renderer.ts index 8da6258..7f8d14d 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -52,6 +52,7 @@ export class Renderer { public _voxelBufferRaw?: any; private _blockBuffer?: twgl.BufferInfo; private _debugBuffers: { [meshType: string]: { [bufferComponent: string]: RenderBuffer } }; + private _axisBuffer: RenderBuffer; private _isGridComponentEnabled: { [bufferComponent: string]: boolean }; @@ -78,6 +79,14 @@ export class Renderer { this._isGridComponentEnabled = {}; this._isGridComponentEnabled[EDebugBufferComponents.Grid] = false; + + this._axisBuffer = new RenderBuffer([ + { name: 'position', numComponents: 3 }, + { name: 'colour', numComponents: 3 }, + ]); + this._axisBuffer.add(DebugGeometryTemplates.arrow(new Vector3(0, 0, 0), new Vector3(1, 0, 0), new RGB(0.96, 0.21, 0.32))); + this._axisBuffer.add(DebugGeometryTemplates.arrow(new Vector3(0, 0, 0), new Vector3(0, 1, 0), new RGB(0.44, 0.64, 0.11))); + this._axisBuffer.add(DebugGeometryTemplates.arrow(new Vector3(0, 0, 0), new Vector3(0, 0, 1), new RGB(0.18, 0.52, 0.89))); } public update() { @@ -202,7 +211,7 @@ export class Renderer { dimensions.z % 2 === 0 ? 0 : -0.5, ); - this._debugBuffers[MeshType.VoxelMesh][EDebugBufferComponents.Grid] = DebugGeometryTemplates.grid(true, true, true, this._voxelSize); + this._debugBuffers[MeshType.VoxelMesh][EDebugBufferComponents.Grid] = DebugGeometryTemplates.grid(true, true, true, this._voxelSize, this._gridOffset.x === 0, this._gridOffset.z === 0); this._debugBuffers[MeshType.VoxelMesh][EDebugBufferComponents.Wireframe] = DebugGeometryTemplates.voxelMeshWireframe(voxelMesh, new RGB(0.18, 0.52, 0.89), this._voxelSize); this._modelsAvailable = 2; @@ -223,7 +232,7 @@ export class Renderer { mag: this._gl.NEAREST, }); - this._debugBuffers[MeshType.BlockMesh][EDebugBufferComponents.Grid] = DebugGeometryTemplates.grid(true, true, true, this._voxelSize); + this._debugBuffers[MeshType.BlockMesh][EDebugBufferComponents.Grid] = DebugGeometryTemplates.grid(true, true, true, this._voxelSize, this._gridOffset.x === 0, this._gridOffset.z === 0); this._modelsAvailable = 3; this.setModelToUse(MeshType.BlockMesh); @@ -250,6 +259,12 @@ export class Renderer { } } } + // Draw axis + this._gl.disable(this._gl.DEPTH_TEST); + this._drawBuffer(this._gl.LINES, this._axisBuffer.getWebGLBuffer(), ShaderManager.Get.debugProgram, { + u_worldViewProjection: ArcballCamera.Get.getWorldViewProjection(), + }); + this._gl.enable(this._gl.DEPTH_TEST); } private _drawMesh() {