From 431eb69b42a64c74c117eb7f5715239d8c4c137d Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 15 Sep 2020 18:07:51 +0100 Subject: [PATCH] Much cleaner rendering function, skipping invalid faces --- src/gameobjects/mesh/MeshWebGLRenderer.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/gameobjects/mesh/MeshWebGLRenderer.js b/src/gameobjects/mesh/MeshWebGLRenderer.js index c9ce5ceb9..d6442d264 100644 --- a/src/gameobjects/mesh/MeshWebGLRenderer.js +++ b/src/gameobjects/mesh/MeshWebGLRenderer.js @@ -22,7 +22,15 @@ var GetCalcMatrix = require('../GetCalcMatrix'); */ var MeshWebGLRenderer = function (renderer, src, camera, parentMatrix) { - var pipeline = renderer.pipelines.set(this.pipeline, src); + var faces = src.faces; + var totalFaces = faces.length; + + if (totalFaces === 0) + { + return; + } + + var pipeline = renderer.pipelines.set(src.pipeline, src); var calcMatrix = GetCalcMatrix(src, camera, parentMatrix).calc; @@ -33,7 +41,6 @@ var MeshWebGLRenderer = function (renderer, src, camera, parentMatrix) var vertexOffset = (pipeline.vertexCount * pipeline.vertexComponentCount) - 1; - var faces = src.faces; var tintEffect = src.tintFill; var debugCallback = src.debugCallback; @@ -48,9 +55,17 @@ var MeshWebGLRenderer = function (renderer, src, camera, parentMatrix) var roundPixels = camera.roundPixels; var alpha = camera.alpha * src.alpha; + var hideCCW = src.hideCCW; - for (var i = 0; i < faces.length; i++) + for (var i = 0; i < totalFaces; i++) { + var face = faces[i]; + + if (hideCCW && !face.isCounterClockwise()) + { + continue; + } + if (pipeline.shouldFlush(3)) { pipeline.flush(); @@ -58,8 +73,6 @@ var MeshWebGLRenderer = function (renderer, src, camera, parentMatrix) vertexOffset = 0; } - var face = faces[i]; - vertexOffset = face.vertex1.load(F32, U32, vertexOffset, textureUnit, tintEffect, alpha, a, b, c, d, e, f, roundPixels); vertexOffset = face.vertex2.load(F32, U32, vertexOffset, textureUnit, tintEffect, alpha, a, b, c, d, e, f, roundPixels); vertexOffset = face.vertex3.load(F32, U32, vertexOffset, textureUnit, tintEffect, alpha, a, b, c, d, e, f, roundPixels);