<commit_before><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	 "http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>

	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<script type="text/javascript" src="../build/three.min.js"></script>
<!-- JSModeler includes start -->
	<script type="text/javascript" src="../src/core/jsm.js"></script>
	<script type="text/javascript" src="../src/core/timer.js"></script>
	<script type="text/javascript" src="../src/core/algorithm.js"></script>
	<script type="text/javascript" src="../src/core/async.js"></script>
	<script type="text/javascript" src="../src/core/check.js"></script>
	<script type="text/javascript" src="../src/core/jsonloader.js"></script>
	<script type="text/javascript" src="../src/geometry/definitions.js"></script>
	<script type="text/javascript" src="../src/geometry/coord2d.js"></script>
	<script type="text/javascript" src="../src/geometry/coord.js"></script>
	<script type="text/javascript" src="../src/geometry/determinant.js"></script>
	<script type="text/javascript" src="../src/geometry/coordutils.js"></script>
	<script type="text/javascript" src="../src/geometry/matrix.js"></script>
	<script type="text/javascript" src="../src/geometry/coordsystem.js"></script>
	<script type="text/javascript" src="../src/geometry/sector.js"></script>
	<script type="text/javascript" src="../src/geometry/line.js"></script>
	<script type="text/javascript" src="../src/geometry/box.js"></script>
	<script type="text/javascript" src="../src/geometry/sphere.js"></script>
	<script type="text/javascript" src="../src/geometry/transformation.js"></script>
	<script type="text/javascript" src="../src/geometry/plane.js"></script>
	<script type="text/javascript" src="../src/geometry/projection.js"></script>
	<script type="text/javascript" src="../src/geometry/convexhull.js"></script>
	<script type="text/javascript" src="../src/geometry/polygon2d.js"></script>
	<script type="text/javascript" src="../src/geometry/polygon.js"></script>
	<script type="text/javascript" src="../src/geometry/cutpolygon.js"></script>
	<script type="text/javascript" src="../src/geometry/triangulation.js"></script>
	<script type="text/javascript" src="../src/geometry/octree.js"></script>
	<script type="text/javascript" src="../src/geometry/bsptree.js"></script>
	<script type="text/javascript" src="../src/geometry/utilities.js"></script>
	<script type="text/javascript" src="../src/geometry/ray.js"></script>
	<script type="text/javascript" src="../src/modeler/body.js"></script>
	<script type="text/javascript" src="../src/modeler/model.js"></script>
	<script type="text/javascript" src="../src/modeler/color.js"></script>
	<script type="text/javascript" src="../src/modeler/material.js"></script>
	<script type="text/javascript" src="../src/modeler/adjacencyinfo.js"></script>
	<script type="text/javascript" src="../src/modeler/bodyutils.js"></script>
	<script type="text/javascript" src="../src/modeler/textureutils.js"></script>
	<script type="text/javascript" src="../src/modeler/cututils.js"></script>
	<script type="text/javascript" src="../src/modeler/generator.js"></script>
	<script type="text/javascript" src="../src/modeler/camera.js"></script>
	<script type="text/javascript" src="../src/modeler/explode.js"></script>
	<script type="text/javascript" src="../src/modeler/exporter.js"></script>
	<script type="text/javascript" src="../src/modeler/trianglebody.js"></script>
	<script type="text/javascript" src="../src/modeler/trianglemodel.js"></script>
	<script type="text/javascript" src="../src/modeler/converter.js"></script>
	<script type="text/javascript" src="../src/modeler/rayutils.js"></script>
	<script type="text/javascript" src="../src/import/binaryreader.js"></script>
	<script type="text/javascript" src="../src/import/importer.js"></script>
	<script type="text/javascript" src="../src/import/importer3ds.js"></script>
	<script type="text/javascript" src="../src/import/importerobj.js"></script>
	<script type="text/javascript" src="../src/import/importerstl.js"></script>
	<script type="text/javascript" src="../src/import/importercommon.js"></script>
	<script type="text/javascript" src="../src/renderer/webglutils.js"></script>
	<script type="text/javascript" src="../src/renderer/renderlight.js"></script>
	<script type="text/javascript" src="../src/renderer/rendermaterial.js"></script>
	<script type="text/javascript" src="../src/renderer/rendermesh.js"></script>
	<script type="text/javascript" src="../src/renderer/renderbody.js"></script>
	<script type="text/javascript" src="../src/renderer/shaderprogram.js"></script>
	<script type="text/javascript" src="../src/renderer/renderer.js"></script>
	<script type="text/javascript" src="../src/renderer/pointcloudrenderer.js"></script>
	<script type="text/javascript" src="../src/renderer/renderconverter.js"></script>
	<script type="text/javascript" src="../src/viewer/mouse.js"></script>
	<script type="text/javascript" src="../src/viewer/touch.js"></script>
	<script type="text/javascript" src="../src/viewer/painter.js"></script>
	<script type="text/javascript" src="../src/viewer/drawing.js"></script>
	<script type="text/javascript" src="../src/viewer/navigation.js"></script>
	<script type="text/javascript" src="../src/viewer/softwareviewer.js"></script>
	<script type="text/javascript" src="../src/viewer/spriteviewer.js"></script>
	<script type="text/javascript" src="../src/viewer/viewer.js"></script>
	<script type="text/javascript" src="../src/viewer/pointcloudviewer.js"></script>
	<script type="text/javascript" src="../src/extras/solidgenerator.js"></script>
	<script type="text/javascript" src="../src/extras/extgenerator.js"></script>
	<script type="text/javascript" src="../src/extras/subdivision.js"></script>
	<script type="text/javascript" src="../src/extras/csg.js"></script>
	<script type="text/javascript" src="../src/extras/curves.js"></script>
	<script type="text/javascript" src="../src/extensions/svgtomodel/svgtomodel.js"></script>
	<script type="text/javascript" src="../src/extensions/threeviewer/threeconverter.js"></script>
	<script type="text/javascript" src="../src/extensions/threeviewer/threeviewer.js"></script>
<!-- JSModeler includes end -->
	<title>Example</title>

	<script type="text/javascript">
		TerrainGenerator = function (xCount, yCount, parameters)
		{
			this.xCount = xCount;
			this.yCount = yCount;
			this.parameters = parameters;
			this.body = null;
		};

		TerrainGenerator.prototype.Generate = function ()
		{
			this.body = new JSM.Body ();

			this.GenerateGridPoints ();
			this.GenerateGridPolygons ();
			this.RandomizeGridHeight ();			
			
			return this.body;
		};

		TerrainGenerator.prototype.GenerateGridPoints = function ()
		{
			var myThis = this;
			this.EnumerateGridPoints (this.xCount, this.yCount, function (xIndex, yIndex) {
				JSM.AddVertexToBody (myThis.body, xIndex * myThis.parameters.gridSize, yIndex * myThis.parameters.gridSize, 0);
				//JSM.AddPointToBody (myThis.body, myThis.body.VertexCount () - 1);
			});
		}
		
		TerrainGenerator.prototype.GenerateGridPolygons = function ()
		{
			function AddRectangleToBody (body, v1, v2, v3, v4)
			{
				var reverse = JSM.RandomBoolean ();
				if (reverse) {
					JSM.AddPolygonToBody (body, [v1, v2, v3]);
					JSM.AddPolygonToBody (body, [v1, v3, v4]);
				} else {
					JSM.AddPolygonToBody (body, [v1, v2, v4]);
					JSM.AddPolygonToBody (body, [v2, v3, v4]);
				}
			}
		
			var myThis = this;
			this.EnumerateGridPoints (this.xCount - 1, this.yCount - 1, function (xIndex, yIndex) {
				var curr = yIndex * myThis.xCount + xIndex;
				var next = curr + 1;
				var top = curr + myThis.xCount;
				var ntop = top + 1;
				AddRectangleToBody (myThis.body, curr, next, ntop, top);
			});
		}
	
		TerrainGenerator.prototype.RandomizeGridHeight = function ()
		{
			var myThis = this;
			this.EnumerateGridPoints (this.xCount, this.yCount, function (xIndex, yIndex) {
				var curr = yIndex * myThis.xCount + xIndex;
				var vertex = myThis.body.GetVertex (curr);
				vertex.position.z = JSM.RandomNumber (0.0, myThis.parameters.baseHeightDifference);
			});
		}		
		
		TerrainGenerator.prototype.EnumerateGridPoints = function (xCount, yCount, callback)
		{
			var xIndex, yIndex;
			for (yIndex = 0; yIndex < yCount; yIndex++) {
				for (xIndex = 0; xIndex < xCount; xIndex++) {
					callback (xIndex, yIndex);
				}
			}
		};

		function Load ()
		{
			var camera = new JSM.Camera (
				new JSM.Coord (1.0, 3.0, 2.0),
				new JSM.Coord (0.0, 0.0, 0.0),
				new JSM.Vector (0.0, 0.0, 1.0)
			);
			
			viewer = new JSM.Viewer ();
			if (!viewer.Init (document.getElementById ('example'), camera)) {
				alert ('error');
			}
			
			var terrainGenerator = new TerrainGenerator (10, 20, {
				gridSize : 0.1,
				baseHeightDifference : 0.1
			});
			var terrain = terrainGenerator.Generate ();

			var renderTerrain = JSM.ConvertBodyToRenderBody (terrain);
			viewer.AddBody (renderTerrain);
			
			viewer.FitInWindow ();
			viewer.Draw ();
		}
	
	    window.onload = function ()
		{
			Load ();
		}
	</script>
<commit_msg>Generate side and bottom polygons.<commit_after><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	 "http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>

	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<script type="text/javascript" src="../build/three.min.js"></script>
<!-- JSModeler includes start -->
	<script type="text/javascript" src="../src/core/jsm.js"></script>
	<script type="text/javascript" src="../src/core/timer.js"></script>
	<script type="text/javascript" src="../src/core/algorithm.js"></script>
	<script type="text/javascript" src="../src/core/async.js"></script>
	<script type="text/javascript" src="../src/core/check.js"></script>
	<script type="text/javascript" src="../src/core/jsonloader.js"></script>
	<script type="text/javascript" src="../src/geometry/definitions.js"></script>
	<script type="text/javascript" src="../src/geometry/coord2d.js"></script>
	<script type="text/javascript" src="../src/geometry/coord.js"></script>
	<script type="text/javascript" src="../src/geometry/determinant.js"></script>
	<script type="text/javascript" src="../src/geometry/coordutils.js"></script>
	<script type="text/javascript" src="../src/geometry/matrix.js"></script>
	<script type="text/javascript" src="../src/geometry/coordsystem.js"></script>
	<script type="text/javascript" src="../src/geometry/sector.js"></script>
	<script type="text/javascript" src="../src/geometry/line.js"></script>
	<script type="text/javascript" src="../src/geometry/box.js"></script>
	<script type="text/javascript" src="../src/geometry/sphere.js"></script>
	<script type="text/javascript" src="../src/geometry/transformation.js"></script>
	<script type="text/javascript" src="../src/geometry/plane.js"></script>
	<script type="text/javascript" src="../src/geometry/projection.js"></script>
	<script type="text/javascript" src="../src/geometry/convexhull.js"></script>
	<script type="text/javascript" src="../src/geometry/polygon2d.js"></script>
	<script type="text/javascript" src="../src/geometry/polygon.js"></script>
	<script type="text/javascript" src="../src/geometry/cutpolygon.js"></script>
	<script type="text/javascript" src="../src/geometry/triangulation.js"></script>
	<script type="text/javascript" src="../src/geometry/octree.js"></script>
	<script type="text/javascript" src="../src/geometry/bsptree.js"></script>
	<script type="text/javascript" src="../src/geometry/utilities.js"></script>
	<script type="text/javascript" src="../src/geometry/ray.js"></script>
	<script type="text/javascript" src="../src/modeler/body.js"></script>
	<script type="text/javascript" src="../src/modeler/model.js"></script>
	<script type="text/javascript" src="../src/modeler/color.js"></script>
	<script type="text/javascript" src="../src/modeler/material.js"></script>
	<script type="text/javascript" src="../src/modeler/adjacencyinfo.js"></script>
	<script type="text/javascript" src="../src/modeler/bodyutils.js"></script>
	<script type="text/javascript" src="../src/modeler/textureutils.js"></script>
	<script type="text/javascript" src="../src/modeler/cututils.js"></script>
	<script type="text/javascript" src="../src/modeler/generator.js"></script>
	<script type="text/javascript" src="../src/modeler/camera.js"></script>
	<script type="text/javascript" src="../src/modeler/explode.js"></script>
	<script type="text/javascript" src="../src/modeler/exporter.js"></script>
	<script type="text/javascript" src="../src/modeler/trianglebody.js"></script>
	<script type="text/javascript" src="../src/modeler/trianglemodel.js"></script>
	<script type="text/javascript" src="../src/modeler/converter.js"></script>
	<script type="text/javascript" src="../src/modeler/rayutils.js"></script>
	<script type="text/javascript" src="../src/import/binaryreader.js"></script>
	<script type="text/javascript" src="../src/import/importer.js"></script>
	<script type="text/javascript" src="../src/import/importer3ds.js"></script>
	<script type="text/javascript" src="../src/import/importerobj.js"></script>
	<script type="text/javascript" src="../src/import/importerstl.js"></script>
	<script type="text/javascript" src="../src/import/importercommon.js"></script>
	<script type="text/javascript" src="../src/renderer/webglutils.js"></script>
	<script type="text/javascript" src="../src/renderer/renderlight.js"></script>
	<script type="text/javascript" src="../src/renderer/rendermaterial.js"></script>
	<script type="text/javascript" src="../src/renderer/rendermesh.js"></script>
	<script type="text/javascript" src="../src/renderer/renderbody.js"></script>
	<script type="text/javascript" src="../src/renderer/shaderprogram.js"></script>
	<script type="text/javascript" src="../src/renderer/renderer.js"></script>
	<script type="text/javascript" src="../src/renderer/pointcloudrenderer.js"></script>
	<script type="text/javascript" src="../src/renderer/renderconverter.js"></script>
	<script type="text/javascript" src="../src/viewer/mouse.js"></script>
	<script type="text/javascript" src="../src/viewer/touch.js"></script>
	<script type="text/javascript" src="../src/viewer/painter.js"></script>
	<script type="text/javascript" src="../src/viewer/drawing.js"></script>
	<script type="text/javascript" src="../src/viewer/navigation.js"></script>
	<script type="text/javascript" src="../src/viewer/softwareviewer.js"></script>
	<script type="text/javascript" src="../src/viewer/spriteviewer.js"></script>
	<script type="text/javascript" src="../src/viewer/viewer.js"></script>
	<script type="text/javascript" src="../src/viewer/pointcloudviewer.js"></script>
	<script type="text/javascript" src="../src/extras/solidgenerator.js"></script>
	<script type="text/javascript" src="../src/extras/extgenerator.js"></script>
	<script type="text/javascript" src="../src/extras/subdivision.js"></script>
	<script type="text/javascript" src="../src/extras/csg.js"></script>
	<script type="text/javascript" src="../src/extras/curves.js"></script>
	<script type="text/javascript" src="../src/extensions/svgtomodel/svgtomodel.js"></script>
	<script type="text/javascript" src="../src/extensions/threeviewer/threeconverter.js"></script>
	<script type="text/javascript" src="../src/extensions/threeviewer/threeviewer.js"></script>
<!-- JSModeler includes end -->
	<title>Example</title>

	<script type="text/javascript">
		TerrainGenerator = function (xCount, yCount, parameters)
		{
			this.xCount = xCount;
			this.yCount = yCount;
			this.parameters = parameters;
			this.model = null;
			this.materials = null;
			this.terrain = null;
		};

		TerrainGenerator.prototype.Generate = function ()
		{
			this.model = new JSM.Model ();
			this.terrain = new JSM.Body ();
			this.materials = new JSM.Materials ();
			this.materials.AddMaterial (new JSM.Material ({ambient : 0x00cc00, diffuse : 0x00cc00, singleSided : true}));
			
			this.GenerateTerrainPoints ();
			this.GenerateTerrainPolygons ();
			this.RandomizeGridHeight ();			
			
			this.terrain.SetPolygonsMaterialIndex (0);
			this.model.AddBody (this.terrain);
			return {
				model : this.model,
				materials : this.materials
			};
		};

		TerrainGenerator.prototype.GenerateTerrainPoints = function ()
		{
			function AddVertex (body, x, y, z)
			{
				var index = JSM.AddVertexToBody (body, x, y, z);
				//JSM.AddPointToBody (body, index);
				return index;
			}
		
			var myThis = this;
			this.EnumerateGridPoints (this.xCount, this.yCount, function (xIndex, yIndex) {
				AddVertex (myThis.terrain, xIndex * myThis.parameters.gridSize, yIndex * myThis.parameters.gridSize, 0);
			});
			
			AddVertex (this.terrain, 0, 0, -this.parameters.terrainHeight);
			AddVertex (this.terrain, (this.xCount - 1) * this.parameters.gridSize, 0, -this.parameters.terrainHeight);
			AddVertex (this.terrain, (this.xCount - 1) * this.parameters.gridSize, (this.yCount - 1) * this.parameters.gridSize, -this.parameters.terrainHeight);
			AddVertex (this.terrain, 0, (this.yCount - 1) * this.parameters.gridSize, -this.parameters.terrainHeight);
		}
		
		TerrainGenerator.prototype.GenerateTerrainPolygons = function ()
		{
			function AddRectangleToBody (body, v1, v2, v3, v4)
			{
				var reverse = JSM.RandomBoolean ();
				if (reverse) {
					JSM.AddPolygonToBody (body, [v1, v2, v3]);
					JSM.AddPolygonToBody (body, [v1, v3, v4]);
				} else {
					JSM.AddPolygonToBody (body, [v1, v2, v4]);
					JSM.AddPolygonToBody (body, [v2, v3, v4]);
				}
			}
		
			var myThis = this;
			this.EnumerateGridPoints (this.xCount - 1, this.yCount - 1, function (xIndex, yIndex) {
				var curr = yIndex * myThis.xCount + xIndex;
				var next = curr + 1;
				var top = curr + myThis.xCount;
				var ntop = top + 1;
				AddRectangleToBody (myThis.terrain, curr, next, ntop, top);
			});
			
			var i;

			var firstBottomVertex = this.terrain.VertexCount () - 4;
			
			var sidePolygon1 = [firstBottomVertex + 2, firstBottomVertex + 3];
			for (i = 0; i < this.xCount; i++) {
				sidePolygon1.push ((this.yCount - 1) * this.xCount + i);
			}

			var sidePolygon2 = [firstBottomVertex + 3, firstBottomVertex];
			for (i = 0; i < this.yCount; i++) {
				sidePolygon2.push (i * this.xCount);
			}

			var sidePolygon3 = [firstBottomVertex, firstBottomVertex + 1];
			for (i = this.xCount - 1; i >= 0 ; i--) {
				sidePolygon3.push (i);
			}
			
			var sidePolygon4 = [firstBottomVertex + 1, firstBottomVertex + 2];
			for (i = this.yCount - 1; i >= 0 ; i--) {
				sidePolygon4.push ((i + 1) * this.xCount - 1);
			}

			JSM.AddPolygonToBody (this.terrain, sidePolygon1);
			JSM.AddPolygonToBody (this.terrain, sidePolygon2);
			JSM.AddPolygonToBody (this.terrain, sidePolygon3);
			JSM.AddPolygonToBody (this.terrain, sidePolygon4);
			JSM.AddPolygonToBody (this.terrain, [firstBottomVertex + 3, firstBottomVertex + 2, firstBottomVertex + 1, firstBottomVertex]);
		}
	
		TerrainGenerator.prototype.RandomizeGridHeight = function ()
		{
			var myThis = this;
			this.EnumerateGridPoints (this.xCount, this.yCount, function (xIndex, yIndex) {
				var curr = yIndex * myThis.xCount + xIndex;
				var vertex = myThis.terrain.GetVertex (curr);
				vertex.position.z = JSM.RandomNumber (0.0, myThis.parameters.baseHeightDifference);
			});
		}		
		
		TerrainGenerator.prototype.EnumerateGridPoints = function (xCount, yCount, callback)
		{
			var xIndex, yIndex;
			for (yIndex = 0; yIndex < yCount; yIndex++) {
				for (xIndex = 0; xIndex < xCount; xIndex++) {
					callback (xIndex, yIndex);
				}
			}
		};

		function Load ()
		{
			var camera = new JSM.Camera (
				new JSM.Coord (1.0, 3.0, 2.0),
				new JSM.Coord (0.0, 0.0, 0.0),
				new JSM.Vector (0.0, 0.0, 1.0)
			);
			
			viewer = new JSM.Viewer ();
			if (!viewer.Init (document.getElementById ('example'), camera)) {
				alert ('error');
			}
			
			var terrainGenerator = new TerrainGenerator (30, 20, {
				gridSize : 0.1,
				terrainHeight : 0.2,
				baseHeightDifference : 0.1
			});
			var terrain = terrainGenerator.Generate ();
			var renderTerrain = JSM.ConvertModelToRenderBodies (terrain.model, terrain.materials);
			viewer.AddBodies (renderTerrain);
			
			viewer.FitInWindow ();
			viewer.Draw ();
		}
	
	    window.onload = function ()
		{
			Load ();
		}
	</script>

{'fraction_non_alphanumeric': 0.19783853138570864, 'fraction_numerical': 0.008636004737465456, 'mean_word_length': 4.170961980096964, 'pattern_counts': {'":': 0, '<': 341, '<?xml version=': 0, '>': 337, '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': '5963033', 'n_tokens_mistral': 7354, 'n_tokens_neox': 6665, 'n_words': 1109}