|
@@ -30,8 +30,8 @@
|
|
</head>
|
|
</head>
|
|
<body>
|
|
<body>
|
|
|
|
|
|
- <div id="container"><br /><br /><br /><br /><br />Generating world...</div>
|
|
|
|
- <div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - <a href="http://www.minecraft.net/" target="_blank">minecraft</a> demo. featuring <a href="http://painterlypack.net/" target="_blank">painterly pack</a><br />(left click: forward, right click: backward)</div>
|
|
|
|
|
|
+ <div id="container"><br /><br /><br /><br /><br />Generating world...</div>
|
|
|
|
+ <div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - <a href="http://www.minecraft.net/" target="_blank">minecraft</a> demo. featuring <a href="http://painterlypack.net/" target="_blank">painterly pack</a><br />(left click: forward, right click: backward)</div>
|
|
|
|
|
|
<script type="text/javascript" src="js/Stats.js"></script>
|
|
<script type="text/javascript" src="js/Stats.js"></script>
|
|
<script type="text/javascript" src="js/ImprovedNoise.js"></script>
|
|
<script type="text/javascript" src="js/ImprovedNoise.js"></script>
|
|
@@ -78,7 +78,7 @@
|
|
var grass_dirt = loadTexture( 'textures/minecraft/grass_dirt.png' ),
|
|
var grass_dirt = loadTexture( 'textures/minecraft/grass_dirt.png' ),
|
|
grass = loadTexture( 'textures/minecraft/grass.png' ),
|
|
grass = loadTexture( 'textures/minecraft/grass.png' ),
|
|
dirt = loadTexture( 'textures/minecraft/dirt.png' );
|
|
dirt = loadTexture( 'textures/minecraft/dirt.png' );
|
|
-
|
|
|
|
|
|
+
|
|
var materials = [
|
|
var materials = [
|
|
|
|
|
|
grass_dirt, // right
|
|
grass_dirt, // right
|
|
@@ -90,45 +90,51 @@
|
|
|
|
|
|
];
|
|
];
|
|
|
|
|
|
- var h, px, nx, pz, nz, cubes = [];
|
|
|
|
-
|
|
|
|
|
|
+ var h, h2, px, nx, pz, nz, cubes = [];
|
|
|
|
+
|
|
for ( var i = 0; i < 16; i++ ) {
|
|
for ( var i = 0; i < 16; i++ ) {
|
|
-
|
|
|
|
|
|
+
|
|
px = (i & 8) == 8;
|
|
px = (i & 8) == 8;
|
|
nx = (i & 4) == 4;
|
|
nx = (i & 4) == 4;
|
|
pz = (i & 2) == 2;
|
|
pz = (i & 2) == 2;
|
|
nz = (i & 1) == 1;
|
|
nz = (i & 1) == 1;
|
|
cubes[ i ] = new Cube( 100, 100, 100, 1, 1, materials, false, { px: px, nx: nx, py: true, ny: false, pz: pz, nz: nz } );
|
|
cubes[ i ] = new Cube( 100, 100, 100, 1, 1, materials, false, { px: px, nx: nx, py: true, ny: false, pz: pz, nz: nz } );
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
var geometry = new THREE.Geometry();
|
|
var geometry = new THREE.Geometry();
|
|
|
|
|
|
- camera.position.y = getY( worldHalfWidth, worldHalfDepth ) + 100;
|
|
|
|
|
|
+ camera.position.y = getY( worldHalfWidth, worldHalfDepth ) * 100 + 100;
|
|
camera.target.position.y = camera.position.y;
|
|
camera.target.position.y = camera.position.y;
|
|
-
|
|
|
|
|
|
+
|
|
for ( var z = 0; z < worldDepth; z ++ ) {
|
|
for ( var z = 0; z < worldDepth; z ++ ) {
|
|
|
|
|
|
for ( var x = 0; x < worldWidth; x ++ ) {
|
|
for ( var x = 0; x < worldWidth; x ++ ) {
|
|
|
|
|
|
px = nx = pz = nz = 0;
|
|
px = nx = pz = nz = 0;
|
|
-
|
|
|
|
|
|
+
|
|
h = getY( x, z );
|
|
h = getY( x, z );
|
|
-
|
|
|
|
- px = (getY( x - 1, z ) != h) || x == 0 ? 1 : 0;
|
|
|
|
- nx = (getY( x + 1, z ) != h) || x == worldWidth - 1 ? 1 : 0;
|
|
|
|
-
|
|
|
|
- pz = (getY( x, z + 1 ) != h) || z == worldDepth - 1 ? 1 : 0;
|
|
|
|
- nz = (getY( x, z - 1 ) != h) || z == 0 ? 1 : 0;
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ h2 = getY( x - 1, z );
|
|
|
|
+ px = ( h2 != h && h2 != h + 1 ) || x == 0 ? 1 : 0;
|
|
|
|
+
|
|
|
|
+ h2 = getY( x + 1, z );
|
|
|
|
+ nx = ( h2 != h && h2 != h + 1 ) || x == worldWidth - 1 ? 1 : 0;
|
|
|
|
+
|
|
|
|
+ h2 = getY( x, z + 1 );
|
|
|
|
+ pz = ( h2 != h && h2 != h + 1 ) || z == worldDepth - 1 ? 1 : 0;
|
|
|
|
+
|
|
|
|
+ h2 = getY( x, z - 1 );
|
|
|
|
+ nz = ( h2 != h && h2 != h + 1 ) || z == 0 ? 1 : 0;
|
|
|
|
+
|
|
mesh = new THREE.Mesh( cubes[ px * 8 + nx * 4 + pz * 2 + nz ] );
|
|
mesh = new THREE.Mesh( cubes[ px * 8 + nx * 4 + pz * 2 + nz ] );
|
|
-
|
|
|
|
|
|
+
|
|
mesh.position.x = x * 100 - worldHalfWidth * 100;
|
|
mesh.position.x = x * 100 - worldHalfWidth * 100;
|
|
- mesh.position.y = h;
|
|
|
|
|
|
+ mesh.position.y = h * 100;
|
|
mesh.position.z = z * 100 - worldHalfDepth * 100;
|
|
mesh.position.z = z * 100 - worldHalfDepth * 100;
|
|
|
|
|
|
GeometryUtils.merge( geometry, mesh );
|
|
GeometryUtils.merge( geometry, mesh );
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -171,16 +177,16 @@
|
|
}
|
|
}
|
|
|
|
|
|
function generateAO( image, sides ) {
|
|
function generateAO( image, sides ) {
|
|
-
|
|
|
|
|
|
+
|
|
var c = document.createElement('canvas');
|
|
var c = document.createElement('canvas');
|
|
c.width = image.width;
|
|
c.width = image.width;
|
|
c.height = image.height;
|
|
c.height = image.height;
|
|
c.getContext( "2d" ).drawImage( image, 0, 0 );
|
|
c.getContext( "2d" ).drawImage( image, 0, 0 );
|
|
-
|
|
|
|
|
|
+
|
|
return c;
|
|
return c;
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function loadTexture( path ) {
|
|
function loadTexture( path ) {
|
|
|
|
|
|
var image = new Image();
|
|
var image = new Image();
|
|
@@ -218,7 +224,7 @@
|
|
|
|
|
|
function getY( x, z ) {
|
|
function getY( x, z ) {
|
|
|
|
|
|
- return ~~( data[ x + z * worldWidth ] * 0.2 ) * 100;
|
|
|
|
|
|
+ return ~~( data[ x + z * worldWidth ] * 0.2 );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|