max-mapper / voxel-engine Goto Github PK
View Code? Open in Web Editor NEW3D HTML5 voxel game engine
Home Page: http://maxogden.github.com/voxel-engine
License: BSD 3-Clause "New" or "Revised" License
3D HTML5 voxel game engine
Home Page: http://maxogden.github.com/voxel-engine
License: BSD 3-Clause "New" or "Revised" License
Currently, items are quite happy to be swallowed by blocks placed over them:
e.g.
game.setBlock(item.mesh.position, 1)
In minecraft, collided objects will be destroyed/turned to debris, or you're simply prevented from placing the blocks entirely, depending on the type of item. Perhaps selecting between these behaviours should be an item flag.
the documentation provides information about a function named getCollisions
, which is undefined - am i completely failing or is the documentation outdated? is there currently an alternative?
thank you for initiating this project - coderect
when looking at the draw call previews in the WebGL inspector in newer Chrome i'm seeing a lot of draw calls for things that aren't in the view frustum.
apparently three.js has built in frustum culling but I imagine we could do it better if we did it manually?
I went a head and created a wiki where we can start working and putting up more collective documentation. Its only a start and we can totally disregard it if you wish. Also, the domain name should probably be changed to something like voxeljs.io etc. or something but it costs to get a better domain name, also we should discuss what it should actually be called, 'voxelwiki' doesnt sound too nice. Once you have made accounts on the wiki I will bump you up to admins so you have unrestricted powers ๐
when you're falling and hit forward you continue falling forward... rather than just when you're holding forward
.dims
is abbreviated, yet .position
and .voxels
is not. Should probably abbreviate them all or spell them all out.
dims: Array[3]
position: Array[3]
voxels: Int8Array[64]
Cannot use game.setBlock(...)
to create blocks outside of visible chunk range.
Game config:
{
chunkDistance: 1,
chunkSize: 16,
...
}
To reproduce:
// tower with different textures
var tower = [
1, 2, 1, 3, 1, 2, 3, 1, 2, 1, 2, 3, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1,
1, 2, 1, 3, 1, 2, 3, 1, 2, 1, 2, 3, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1,
1, 2, 1, 3, 1, 2, 3, 1, 2, 1, 2, 3, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1,
1, 2, 1, 3, 1, 2, 3, 1, 2, 1, 2, 3, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1
]
tower.forEach(function (item, i) {
var pos = [1,i,2]
console.log(pos)
game.setBlock(pos, item)
})
The last log prints [1, 16, 2]
, then error:
TypeError: Cannot read property 'position' of undefined
This can also be reproduced via the console after the game has been fully initialized.
See https://github.com/vladikoff/voxel-test-playground for an example of this issue.
There seems to be no way to detect the right mouse button..
The internal texture faces are not visible even when the outer blocks are transparent.
There is also a flicker that occurs between transparent texture, air, and transparent texture, where the second transparent texture sometimes turn on and off.
would it be a smart thing to code a 2d mode plugin for voxel and use that to create a 2d game while still using the awesome voxel ecosystem?
Or is that a huge waste of cpu and browser compatibility and causes unnecessary complexity?
Using the line:
mesher: voxel.meshers.culled,
causes the world to not appear. Just a white screen, no FPS indicator either.
How would I make a keybinding for if the right mouse button is pressed the following happens.
position = block;
console.log("Position: " + position);
var blockType = game.getBlock(position);
console.log("Checked: " + blockType);
I can get it working with the left button only.
game.on('fire', function (pos){
position = block;
console.log("Position: " + position);
var blockType = game.getBlock(position);
console.log("Checked: " + blockType);
})
I cannot seem to figure out how to break a block...
As a bit of background, or context.
What I'm hoping to achieve is a world/level where the physics is handled by voxel-engine but the visuals are actually just 2d painted sprites layered over transparent voxels/meashes.
The issue im comming up against seems similar to the issue mentioned in: Issue #34 but in my case the voxels behind the transparent voxel Are visible as well as the player meshes when walking behind the transparent voxel, BUT sprites rendered at the same position as the transparent voxel are being covered by the voxel.
example: http://christopherdebeer.com/sandbox/voxeljs/
Any ideas?
@shama or @vogonistic, @mbalho mentioned that you might have some insights, if you do, it would be much appreciated.
can you please update voxel-engine
in both npm and package.json for following updated dependencies?
voxel-mesh
to 0.2.1
voxel-texture
to 0.3.3
thanks,
Following the instructions at http://voxeljs.com/#how (modifying only the script name - mygamename
became howgame1
), after running browserify, including builtgame.js in an HTML document and loading it in a browser (Chrome 21 & 24, FF19 Beta on Win7-64, Ubuntu 12.04) nothing is displayed except the following stack trace in Chrome's devtools console:
Uncaught TypeError: Object #<Object> has no method 'relative' builtgame.js:44380
module.exports builtgame.js:44380
(anonymous function) builtgame.js:44386
require.modules.(anonymous function) builtgame.js:182
require builtgame.js:8
(anonymous function) builtgame.js:44395
(anonymous function) builtgame.js:44396
(Edit: originally posted incorrect line #'s that included some debugging lines)
Dumping the path object shows the following methods: basename
, dirname
, extname
, join
, normalize
& resolve
.
Firefox simply says path.relative is not a function
I tried updating the package.json to use voxel-engine 0.5.1 and running npm install
again, but to no effect.
Edit: build environment: Ubuntu 12.04, node 0.8.14, npm 1.1.6
A good discussion is here: https://gist.github.com/maxogden/5009821
Many of those points are still valid, e.g. I'd like to have better streams support
This is b/c it sees that its in a browser, but doesn't have webgl support.
Solution: don't check for webgl support if isClient
is false
Sorry to post this here, but the three questions on stackoverflow about voxel.js have 0 responses, so I'm hoping I can get help here. I'm doing a really basic setup, with the texture folder there, and I can't get the world to show up. The blue screen of the game is there, but no voxels are rendered. No JS errors and the console just has THREE.WebGLRenderer 56, which from the code, is just the revision number for three.js. bundle.js seems to be bundling correctly (I tested by calling a function that didn't exist, then refreshing, which correctly threw errors). When I paste the code in voxel creator, it works just fine. But of course, I'd love to use it on my own system. WebGL seems to be working fine. Running it on mountain lion. Here is the code:
var createGame = require('voxel-engine');
var game = createGame({
texturePath: 'textures/'
});
var container = document.body;
game.appendTo(container);
// create a player
var createPlayer = require('voxel-player')(game);
var player = createPlayer('textures/shama.png');
player.yaw.position.set(0, 100, 0);
player.possess();
Super basic. Here is my package.json. Is there some dependency I'm missing?
{
"name": "voxel-test",
"version": "0.0.0",
"description": "ERROR: No README.md file found!",
"main": "index.js",
"scripts": {
"start": "echo \"open localhost:8080/\" && ./node_modules/.bin/browservefy index.js 8080 -- -d"
},
"repository": "",
"author": "",
"license": "BSD",
"devDependencies": {
"voxel-engine": "~0.18.2",
"voxel-player": "~0.1.0",
"browservefy": "0.0.10",
"voxel-texture": "~0.5.6",
"three": "~0.58.9"
}
}
Should I use an older version of the engine? I know that this isn't the usual way to submit questions, but I don't really know how else to reach out to someone about it. But I must say, I love this project, and I can't wait to get cranking on it. You guys are doing some awesome work!
I opened this ticket because my other ticket #120 seems to be unsolvable, due to shader problems im not experienced with.
My problem is that my project has to have transparent blocks, or partially transparent, my question is, where does the master branch determines if a block should be rendered or not? I'm guessing it has to be somewhere at raycasting but im not feeling sure..
To reproduce, simply create a flat world at world origin [1341084,0,3242971] with the player at [1341084,64,3242971]
Anyone else noticed the undeletable block in the demo?
Its the second block down, underneath the Viking his right or your left side (if you're looking at him face on).
Haven't discovered the cause.
shouldn't be tooooo hard if we implement water as a new kind of chunk that draws on it's own
Rounding causes the adjacent block to be skipped. I am not sure what do do about it beside manually checking the resulting block positions (Math.floor) for each of 6 directions.
1.9999999999999998 + 1 === 3 // true
Failed test:
gameTest(function raycastVoxels(game, t) {
var pos = [1, 1, 1]
game.setBlock(pos, 1)
var start = [1.994133710861206, 3.1129817962646484, 3.9677624702453613]
var direction = [-0.16332358934799918, -0.4095857816495397, -0.8975326693959512]
var hit = game.raycast(start, direction, 10)
console.log(hit)
t.equal(hit.adjacent[1], 2)
})
Test output:
TAP version 13
# raycastVoxels
{ position: [ 1.5503287987061696, 1.9999999999999998, 1.5288654983645178 ],
direction:
[ -0.16332358934799918,
-0.4095857816495397,
-0.8975326693959512 ],
value: 1,
normal: [ 0, 1, 0 ],
adjacent: [ 1.5503287987061696, 3, 1.5288654983645178 ] }
not ok 1 should be equal
---
operator: equal
expected: 2
actual: 3
at: raycastVoxels (/var/lib/stickshift/5121adb5e0b8cde61e00007f/app-root/data/409279/node_modules/voxel-engi
ne/test_raycast_skip.js:23:5)
...
1..1
# tests 1
# pass 0
# fail 1
chrome 26.0.1384.2 dev, on ubuntu 11.10
fails to load. console shows error:
Uncaught TypeError: Cannot read property 'Texture' of undefined browserify-bundle.js:40705
function in question:
Skin.prototype.getMaterial = function(img, transparent) {
var texture = new THREE.Texture(img);
Uncaught TypeError: Cannot read property 'Texture' of undefined
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.NearestFilter;
texture.format = transparent ? THREE.RGBAFormat : THREE.RGBFormat;
texture.needsUpdate = true;
var material = new THREE.MeshBasicMaterial({
map : texture,
transparent : transparent ? true : false
});
return material;
}
I wrote some code for a free camera movement without a player. The voxel-engine code states that if there is no player voxel.js will take the position of the camera to find chunks that are far away and remove them.
So far everything is working fine BUT the chunks won't load when the camera gets close to them again. I tried to force voxel.js to show them but that won't work too.
cp = game.camera.position.toArray();
var chunkX = Math.floor(cp[0]/32);
var chunkY = Math.floor(cp[1]/32);
var chunkZ = Math.floor(cp[2]/32);
console.debug("Update Map around: " + [chunkX, chunkY, chunkZ].toString());
game.showChunk(game.getChunkAtPosition([chunkX, chunkY, chunkZ]));
game.showChunk(game.getChunkAtPosition([chunkX + 1, chunkY, chunkZ]));
game.showChunk(game.getChunkAtPosition([chunkX + 1, chunkY , chunkZ - 1]));
game.showChunk(game.getChunkAtPosition([chunkX, chunkY, chunkZ -1]));
game.showChunk(game.getChunkAtPosition([chunkX + 1, chunkY, chunkZ + 1]));
game.showChunk(game.getChunkAtPosition([chunkX -1, chunkY, chunkZ - 1]));
game.showChunk(game.getChunkAtPosition([chunkX -1, chunkY, chunkZ]));
game.showChunk(game.getChunkAtPosition([chunkX -1, chunkY, chunkZ + 1]));
game.showChunk(game.getChunkAtPosition([chunkX, chunkY, chunkZ + 1]));
I used game.setBlock([msg["x"],1 ,msg["y"]], c) to create the blocks. Is this the right way or will it just display the blocks until the chunk is hidden the first time?
I would like to model large3d bodies seamlessly. The world coordinates seem to be able to go infintely in all directions. I'd like to be able to define a boundary where the world "wraps around".
Is there a relatively easy way to do this?
Take the code below, it will function fine. However, if you were to change "largenumber" to -12345678 then dude falls through the world, or if you move while falling, and happen to not fall through the world, camera movement/movement in general is strange. if you change "largenumber" to -123456789 the world does not render at all.
var largenumber = -1234567
var createGame = require('voxel-engine')
var game = createGame({
textures : './textures/',
materials: [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt'],
materialFlatColor: false,
generate: function(x, y, z) {
return y === 1 ? 1 : 0
},
worldOrigin: [largenumber, 0, 0],
container : document.querySelector('#container')
})
game.appendTo(container)
game.createBlock([largenumber, 10, 0], 2)
var createplayer = require('voxel-player')(game)
var dude = createplayer()
dude.possess()
dude.yaw.position.set(largenumber, 100, 0)
AFAIK function name is true only if set of all meshes does not also include game.items
.
Perhaps consider a rename to indicate this is only for block/voxel meshes.
Minor issue.
I'm opening this up as an issue, but in reality it's something I'm going to start working on.
Not sure that its the right place (as in the spirit of the project it would be a module) but I figured it would be a good place to store discussion and opinions if other people are interested or working on something similar.
(feel free to delete this issue or tell me to bugger off if appropriate)
The world generator takes x,y,z parameters instead of a Vector3 object. Since a vector can define a point, it makes sense just to use vectors everywhere, at least to me. This will make the API more consistent.
It would seem that you've declared var substack
twice in the hello world example, I'd imagine this could be quite confusing to 'some' people looking to figure out how voxel-engine work.
lines: 40 & 49 of index.js in the gh-pages branch.
chris
I try to install ndarray branch, because of the "plugins" and transparency, and i get an error saying "esprima-six" is not maintend anymore. Any ideas?
for mobile controls there have been a few experimental modules written:
https://github.com/DamonOehlman/voxel-touch-hello-world
https://github.com/DamonOehlman/voxel-touchy
https://github.com/maxogden/fps-touch-controls
voxel-touchcontrols on npm
the main focus has been making voxel-engine fast, but not much work has been done to find out settings configurations that work well on mobile.
in voxel-engine you can pass some options that help with rendering:
chunkDistance
: this controls how much of a radius around the player to draw at a given time, e.g. setting it at 1 draws 1 chunk in each direction. the lower this is the faster the game will run but the less of the world you'll be able to see
materialFlatColor
: if set to true the game will use flat colored materials instead of textured materials which should render faster
Jumping is typically inconsistent. One manages to jump once out of ever five or so attempts.
When the
controlOptions: {
jump: 15
}
Is set to something high enough, you can jump against something above you. It will press you against block and hold you there. If you strafe out from under the block above your head. You may still have +Y velocity and go up.
gitter chat for voxel,and have the badge in the readme
I haven't looked too deeply into the code yet, but I noticed there are several places trying to access a stream.Stream object from require('stream'), but the module seems to just be blank...
require.define("stream", function (require, module, exports, __dirname, __filename) {
// todo
});
This may also be something up with browserify. I'm assuming this is supposed to be the built-in stream module in node?
It entirely possible I just did something stupid when trying to run it...
I don't know if it's just me, but suddenly it feels harder to jump up onto a block.
Haven't had the chance to investigate properly, will check out tomorrow, if I get a chance.
Has anyone else noticed this? Or is it my own illusion?
After searching, I already found that AZERTY layout support was added via #23.
Now I'm wondering if I just want hard-coded support for Dvorak as well, or if keybindings makes sense as either a configurable option, or a separate module altogether. I'd like to make these changes myself and submit it as a PR, but not before asking what the preferred direction should be.
Cheers
Whenever I try to create a flat world with code I copied off of the voxel.js engine page but nothing shows up. Whenever I tried to use the voxel-perlin-terrain generator i see flashes of the generated world. I also tried to create a sphere with the given code and still nothing. I thought maybe i needed to move the player up with the "player.yaw.postion(x,y,z)" function. The console then gave me an error saying "Object is not a function". I am an amateur programmer so if this is something simple I don't see it.
I'd like to have block types whose geometry only takes up part of a voxel - like the glass panes, slabs, and stairs in Minecraft.
That's my main question, but here are some bonus questions if you're feeling generous:
Basically, I'd like to create a game world that allows you to move from lower locations to higher ones without having to jump constantly.
Should the whole Voxel-* project just use GLPv3?
Hi!
The raf
module has introduced breaking changes in v1.0.0. The event emitter logic has been moved into raf-stream
, while raf
retains the actual polyfill logic.
Let me know if you need any help migrating.
I've been trying to get the voxel-engine to accept a custom camera (ie: OrthographicCamera )
and it would seem that the Game prototype needs something like this:
this.camera = this.createCamera( opts.camera || false )
and createCamera needs changing like so:
Game.prototype.createCamera = function( customCamera ) {
camera = customCamera || new THREE.PerspectiveCamera(60, this.width / this.height, 1, 10000)
camera.lookAt(new THREE.Vector3(0, 0, 0))
this.scene.add(camera)
return camera
}
Does this seem like a good idea, or am I being stupid? If not then pull request to follow.
Any chance to display and collision-mesh voxels with one longer axis?
I have here a sampled object (by slices), but the distance between the slices is about 1.5 "length of pixel".
To have this voxel space displayed at the right ratio I would have to stretch the cubes of all voxels.
Is this possible with the engine at this time? if not: is it hard to change?
Hello,
i have a quick and simple question. Sorry if that's a duplicate but i was not able to find anything helpfull on the internet. So, the thing is: is there any way to store the world as array or JSON ?
All the examples i had browsed have some kind of world-generating algorithm.
Thanks in advance for your help. Keep up the great work! :)
I have a package that handle operations (getting blocks, setting blocks, loading from files, saving from files) on a minecraft world.
It is designed to be async to handle easily IO backends.
It's currently only used on a minecraft server but it works fairly well so I'm investigating ways to visualize World instance with voxeljs.
The most used interface to get blocks in voxel seems to be the generate(x,y,z) function but that is completely sync hence I can't use it.
I found in a few modules the use of generateVoxelChunk and emitting "missingChunk" event to handle async chunk loading, but that seems a bit hacky and it's a bit hard to make it work, because I can't find any documentation on generateVoxelChunk.
Does anyone have a clue what would be the best way to render the chunk asyncly ?
prismarine-world provide a getColumn async function, and it should be called when voxeljs decide it's time to render such and such chunks.
I'll keep testing things but I'd appreciate any info about this !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.