diff --git a/README.md b/README.md index 3595226..71d79b3 100644 --- a/README.md +++ b/README.md @@ -233,17 +233,11 @@ For example, here we have 4 faces colliding with the bottom of our object: ### Textures -Loading textures creates multiple "materials". +Loading textures onto the texture atlas. -```var materials = game.materials.load(['obsidian', 'dirt'])``` +```game.materials.load(['obsidian', 'dirt'], function(textures) { })``` -Both of these textures come with 6 materials, one for each side of a cube, giving a total of 12 materials. By default, faces 1 to 6 are assigned materials 1 to 6. You can assign materials to faces in however you want. For example, we could load materials 7 to 12 (e.g. the dirt materials) like so: - -```js -mesh.geometry.faces.forEach(function (face, index) { - face.materialIndex = index + 6 // obsidian texture indices 0 - 5, dirt 6 - 11 -}) -``` +Both of these textures will be loaded into the texture atlas and expanded creating 2 voxel block types. ### Items @@ -255,15 +249,15 @@ mesh.geometry.faces.forEach(function (face, index) { #### Example: Creating an Item ```js -// get a previously loaded texture by name -var material = game.materials.get('obsidian'); - -// create a mesh and set the matertial +// create a mesh and set the matertial of the texture atlas var mesh = new game.THREE.Mesh( new game.THREE.CubeGeometry(10, 30, 10), // width, height, depth - new game.THREE.MeshFaceMaterial(material) + game.materials.material ); +// paint the mesh with a previously loaded texture +game.materials.paint(mesh, 'obsidian') + // move item to some location mesh.translateX(87.5) mesh.translateY(420) diff --git a/index.js b/index.js index 4821a06..918756e 100644 --- a/index.js +++ b/index.js @@ -50,7 +50,7 @@ function Game(opts) { this.playerHeight = opts.playerHeight || 1.62 this.meshType = opts.meshType || 'surfaceMesh' - this.mesher = opts.mesher || voxel.meshers.greedy + this.mesher = opts.mesher || voxel.meshers.culled this.materialType = opts.materialType || THREE.MeshLambertMaterial this.materialParams = opts.materialParams || {} this.items = [] @@ -88,7 +88,7 @@ function Game(opts) { this.pendingChunks = [] this.materials = texture({ - THREE: THREE, + game: this, texturePath: opts.texturePath || './textures/', materialType: opts.materialType || THREE.MeshLambertMaterial, materialParams: opts.materialParams || {} @@ -219,7 +219,7 @@ Game.prototype.canCreateBlock = function(pos) { } Game.prototype.createBlock = function(pos, val) { - if (typeof val === 'string') val = this.materials.findIndex(val) + if (typeof val === 'string') val = this.materials.find(val) if (pos.chunkMatrix) return this.chunkGroups.createBlock(pos, val) if (!this.canCreateBlock(pos)) return false this.setBlock(pos, val) @@ -227,7 +227,7 @@ Game.prototype.createBlock = function(pos, val) { } Game.prototype.setBlock = function(pos, val) { - if (typeof val === 'string') val = this.materials.findIndex(val) + if (typeof val === 'string') val = this.materials.find(val) if (pos.chunkMatrix) return this.chunkGroups.setBlock(pos, val) var old = this.voxels.voxelAtPosition(pos, val) var c = this.voxels.chunkAtPosition(pos) @@ -533,8 +533,8 @@ Game.prototype.showChunk = function(chunk) { this.voxels.meshes[chunkIndex] = mesh if (process.browser) { if (this.meshType === 'wireMesh') mesh.createWireMesh() - else mesh.createSurfaceMesh(new THREE.MeshFaceMaterial(this.materials.get())) - this.materials.paint(mesh.geometry) + else mesh.createSurfaceMesh(this.materials.material) + this.materials.paint(mesh) } mesh.setPosition(bounds[0][0], bounds[0][1], bounds[0][2]) mesh.addToScene(this.scene) @@ -595,7 +595,7 @@ Game.prototype.tick = function(delta) { this.items[i].tick(delta) } - if (this.materials) this.materials.tick() + if (this.materials) this.materials.tick(delta) if (this.pendingChunks.length) this.loadPendingChunks() if (Object.keys(this.chunksNeedsUpdate).length > 0) this.updateDirtyChunks() diff --git a/package.json b/package.json index 96a9e7c..d40ca06 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "voxel-engine", "description": "make games with voxel.js", - "version": "0.16.3", + "version": "0.17.0", "repository": { "type": "git", "url": "git@github.com:maxogden/voxel-engine.git" @@ -13,7 +13,7 @@ "voxel-chunks": "0.0.2", "voxel-raycast": "0.2.1", "voxel-control": "0.0.7", - "voxel-texture": "0.4.0", + "voxel-texture": "0.5.0", "voxel-physical": "0.0.8", "voxel-region-change": "0.1.0", "raf": "0.0.1",