<commit_before>/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package mapviewer.model;
import js.html.Float32Array;
import mapviewer.block.Block;
import mapviewer.block.Face;
import mapviewer.model.ModelFace;
import mapviewer.model.ModelVertex;
import mapviewer.renderer.LightInfo;
import mapviewer.renderer.webgl.BlockBuilder;
import mapviewer.renderer.webgl.glmatrix.Quat;
import mapviewer.utils.Chainable;
import mapviewer.world.Chunk;
import mapviewer.world.World;

class Model {
	public var faces : Array<ModelFace>;
	
	private var isOptimized : Bool = false;
	
	public function new() {
		faces = new Array();
	}
	
	private static function alwaysRenderAgainst(block : Block) : Bool return true;
	
	public function render(builder : BlockBuilder, x : Int, y : Int, z : Int, chunk : Chunk, ?shouldRenderAgainst : Block -> Bool) {
		if (shouldRenderAgainst == null) shouldRenderAgainst = alwaysRenderAgainst;
		
		for (face in faces) {
			if (face.cullable) {
				// This is actually faster than a look up map
				if (face.face == Face.TOP && !shouldRenderAgainst(chunk.world.getBlock((chunk.x << 4) + x, y + 1, (chunk.z << 4) + z))) continue;
				if (face.face == Face.BOTTOM && !shouldRenderAgainst(chunk.world.getBlock((chunk.x << 4) + x, y - 1, (chunk.z << 4) + z))) continue;
				if (face.face == Face.LEFT && !shouldRenderAgainst(chunk.world.getBlock((chunk.x << 4) + x + 1, y, (chunk.z << 4) + z))) continue;
				if (face.face == Face.RIGHT && !shouldRenderAgainst(chunk.world.getBlock((chunk.x << 4) + x - 1, y, (chunk.z << 4) + z))) continue;
				if (face.face == Face.FRONT && !shouldRenderAgainst(chunk.world.getBlock((chunk.x << 4) + x, y, (chunk.z << 4) + z + 1))) continue;
				if (face.face == Face.BACK && !shouldRenderAgainst(chunk.world.getBlock((chunk.x << 4) + x, y, (chunk.z << 4) + z - 1))) continue;
			}
			var texture = Main.blockTextureInfo[face.texture];
			for (i in 0 ... 3) {
				var vert = face.vertices[2 - i];
				var light = calcLight(chunk.world, (chunk.x << 4) + x + vert.x, y + vert.y, (chunk.z << 4) + z + vert.z, face.face);
				builder
					.position(x + vert.x, y + vert.y, z + vert.z)
					.colour(face.r, face.g, face.b)
					.tex(vert.textureX, vert.textureY)
					.texId(texture.start, texture.end)
					.lighting(light.light, light.sky);
			}
			for (i in 0 ... 3) {				
				var vert = face.vertices[1 + i];
				var light = calcLight(chunk.world, (chunk.x << 4) + x + vert.x, y + vert.y, (chunk.z << 4) + z + vert.z, face.face);
				builder
					.position(x + vert.x, y + vert.y, z + vert.z)
					.colour(face.r, face.g, face.b)
					.tex(vert.textureX, vert.textureY)
					.texId(texture.start, texture.end)
					.lighting(light.light, light.sky);
			}
		}
	}
	
	public static var dumbLight : Bool = false;
	
	private static function calcLight(world : World, x : Float, y : Float, z : Float, face : Face) : LightInfo {<commit_msg>Log about missing textures<commit_after>/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package mapviewer.model;
import js.html.Float32Array;
import mapviewer.block.Block;
import mapviewer.block.Face;
import mapviewer.model.ModelFace;
import mapviewer.model.ModelVertex;
import mapviewer.renderer.LightInfo;
import mapviewer.renderer.webgl.BlockBuilder;
import mapviewer.renderer.webgl.glmatrix.Quat;
import mapviewer.utils.Chainable;
import mapviewer.world.Chunk;
import mapviewer.world.World;

class Model {
	public var faces : Array<ModelFace>;
	
	private var isOptimized : Bool = false;
	
	public function new() {
		faces = new Array();
	}
	
	private static function alwaysRenderAgainst(block : Block) : Bool return true;
	
	public function render(builder : BlockBuilder, x : Int, y : Int, z : Int, chunk : Chunk, ?shouldRenderAgainst : Block -> Bool) {
		if (shouldRenderAgainst == null) shouldRenderAgainst = alwaysRenderAgainst;
		
		for (face in faces) {
			if (face.cullable) {
				// This is actually faster than a look up map
				if (face.face == Face.TOP && !shouldRenderAgainst(chunk.world.getBlock((chunk.x << 4) + x, y + 1, (chunk.z << 4) + z))) continue;
				if (face.face == Face.BOTTOM && !shouldRenderAgainst(chunk.world.getBlock((chunk.x << 4) + x, y - 1, (chunk.z << 4) + z))) continue;
				if (face.face == Face.LEFT && !shouldRenderAgainst(chunk.world.getBlock((chunk.x << 4) + x + 1, y, (chunk.z << 4) + z))) continue;
				if (face.face == Face.RIGHT && !shouldRenderAgainst(chunk.world.getBlock((chunk.x << 4) + x - 1, y, (chunk.z << 4) + z))) continue;
				if (face.face == Face.FRONT && !shouldRenderAgainst(chunk.world.getBlock((chunk.x << 4) + x, y, (chunk.z << 4) + z + 1))) continue;
				if (face.face == Face.BACK && !shouldRenderAgainst(chunk.world.getBlock((chunk.x << 4) + x, y, (chunk.z << 4) + z - 1))) continue;
			}
			var texture = Main.blockTextureInfo[face.texture];
			if (texture == null) {
				trace("Missing texture: " + face.texture);
			}
			for (i in 0 ... 3) {
				var vert = face.vertices[2 - i];
				var light = calcLight(chunk.world, (chunk.x << 4) + x + vert.x, y + vert.y, (chunk.z << 4) + z + vert.z, face.face);
				builder
					.position(x + vert.x, y + vert.y, z + vert.z)
					.colour(face.r, face.g, face.b)
					.tex(vert.textureX, vert.textureY)
					.texId(texture.start, texture.end)
					.lighting(light.light, light.sky);
			}
			for (i in 0 ... 3) {				
				var vert = face.vertices[1 + i];
				var light = calcLight(chunk.world, (chunk.x << 4) + x + vert.x, y + vert.y, (chunk.z << 4) + z + vert.z, face.face);
				builder
					.position(x + vert.x, y + vert.y, z + vert.z)
					.colour(face.r, face.g, face.b)
					.tex(vert.textureX, vert.textureY)
					.texId(texture.start, texture.end)
					.lighting(light.light, light.sky);
			}
		}
	}
	
	public static var dumbLight : Bool = false;
	
	private static function calcLight(world : World, x : Float, y : Float, z : Float, face : Face) : LightInfo {
{'fraction_non_alphanumeric': 0.1479878840328862, 'fraction_numerical': 0.010962065483917496, 'mean_word_length': 3.366498740554156, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3936918', 'n_tokens_mistral': 2643, 'n_tokens_neox': 2312, 'n_words': 687}