Skip to content

Commit

Permalink
Update to voxel-texture v0.5.0 which uses texture atlases. Bump v0.17.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
shama committed Apr 15, 2013
1 parent e1d1f63 commit 6b5e5e8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
22 changes: 8 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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 || {}
Expand Down Expand Up @@ -219,15 +219,15 @@ 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)
return true
}

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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]:maxogden/voxel-engine.git"
Expand All @@ -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",
Expand Down

0 comments on commit 6b5e5e8

Please sign in to comment.