<commit_before>define(
    [
        'polygonjs/math/Matrix4',
        'polygonjs/math/Vector3'
    ],
    function (Matrix4, Vector3) {

        "use strict";

        var Renderer = function (opts) {
            opts = opts || {};
            this.surface = opts.surface;
            this.scene = opts.scene;
        };

        Renderer.create = function (opts) {
            return new Renderer(opts);
        };

        Renderer.prototype = {
            render: function (delta) {

                var scene = this.scene;
                var camera = scene.mainCamera;
                var cameraWorldPosition = camera.worldPosition;
                var viewTransform = camera.viewTransform;
                var projectionTransform = camera.projectionTransform;
                var models = scene.models, model;
                var polygons = scene.polygons, polygon;
                var worldVertices, worldVertex;
                var viewVertices, viewVertex;
                var screenVertices, screenVertex;
                var surface = this.surface;
                var surfaceWidth = surface.width;
                var surfaceHeight = surface.height;
                var worldNormal, viewNormal;
                var dp;
                var i, j, len;

                surface.clear();

                // Back-face cull
                i = polygons.length;
                while (--i >= 0) {
                    polygon = polygons[i];
                    dp = polygon.worldNormal.dotProduct(camera.forward);
                    polygon.isCulled = dp < 0;
                    polygon.distanceToCamera = polygon.worldPosition.distanceTo(cameraWorldPosition);
                }

                // Sort (slow!)
                // var count = 0;
                polygons.sort(function (a, b) {
                    // count++;
                    return a.distanceToCamera - b.distanceToCamera;
                });
                // console.log(count);

                // Project (view-space and clip-space)
                i = models.length, j;
                while (--i >= 0) {
                    model = models[i];
                    worldVertices = model.worldVertices;
                    viewVertices = model.viewVertices;
                    screenVertices = model.screenVertices;
                    j = worldVertices.length;
                    while (--j >= 0) {
                        worldVertex = worldVertices[j];
                        viewVertex = viewVertices[j];
                        screenVertex = screenVertices[j];

                        viewVertex.copy(worldVertex).applyProjection(viewTransform);
                        screenVertex.copy(viewVertex).applyProjection(projectionTransform);

                        // TODO: combine above?

                        screenVertex.x *= surfaceWidth;
                        screenVertex.y *= surfaceHeight;
                    }
                }

                // Render
                i = polygons.length;
                while (--i >= 0) {
                    polygon = polygons[i];
                    if (!polygon.isCulled)
                        surface.polygon(polygon.screenVertices, polygon.style);
                }

                surface.render();
            }
        };

        return Renderer;
    }
);<commit_msg>Render the polygon's material diffuse color (temp).<commit_after>define(
    [
        'polygonjs/math/Matrix4',
        'polygonjs/math/Vector3'
    ],
    function (Matrix4, Vector3) {

        "use strict";

        var Renderer = function (opts) {
            opts = opts || {};
            this.surface = opts.surface;
            this.scene = opts.scene;
        };

        Renderer.create = function (opts) {
            return new Renderer(opts);
        };

        Renderer.prototype = {
            render: function (delta) {

                var scene = this.scene;
                var camera = scene.mainCamera;
                var cameraWorldPosition = camera.worldPosition;
                var viewTransform = camera.viewTransform;
                var projectionTransform = camera.projectionTransform;
                var models = scene.models, model;
                var polygons = scene.polygons, polygon;
                var worldVertices, worldVertex;
                var viewVertices, viewVertex;
                var screenVertices, screenVertex;
                var surface = this.surface;
                var surfaceWidth = surface.width;
                var surfaceHeight = surface.height;
                var worldNormal, viewNormal;
                var dp;
                var i, j, len;

                surface.clear();

                // Back-face cull
                i = polygons.length;
                while (--i >= 0) {
                    polygon = polygons[i];
                    dp = polygon.worldNormal.dotProduct(camera.forward);
                    polygon.isCulled = dp < 0;
                    polygon.distanceToCamera = polygon.worldPosition.distanceTo(cameraWorldPosition);
                }

                // Sort (slow!)
                // var count = 0;
                polygons.sort(function (a, b) {
                    // count++;
                    return a.distanceToCamera - b.distanceToCamera;
                });
                // console.log(count);

                // Project (view-space and clip-space)
                i = models.length, j;
                while (--i >= 0) {
                    model = models[i];
                    worldVertices = model.worldVertices;
                    viewVertices = model.viewVertices;
                    screenVertices = model.screenVertices;
                    j = worldVertices.length;
                    while (--j >= 0) {
                        worldVertex = worldVertices[j];
                        viewVertex = viewVertices[j];
                        screenVertex = screenVertices[j];

                        viewVertex.copy(worldVertex).applyProjection(viewTransform);
                        screenVertex.copy(viewVertex).applyProjection(projectionTransform);

                        // TODO: combine above?

                        screenVertex.x *= surfaceWidth;
                        screenVertex.y *= surfaceHeight;
                    }
                }

                // Render
                i = polygons.length;
                while (--i >= 0) {
                    polygon = polygons[i];
                    if (!polygon.isCulled) {
                        surface.polygon(polygon.screenVertices, polygon.material.diffuse.getHex());
                    }
                }

                surface.render();
            }
        };

        return Renderer;
    }
);
{'fraction_non_alphanumeric': 0.08945022288261516, 'fraction_numerical': 0.0029717682020802376, 'mean_word_length': 1.1206679269061122, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '76603', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1507, 'n_words': 328}