voxel / voxel-mesher

voxel mesher with ambient occulusion, transparency, translucency, custom block models
MIT License
21 stars 2 forks source link

[cwise-compiler >1.1.0] cwise: Arrays do not all have the same shape (ao 34**3 but array 36**3) #11

Open deathcap opened 8 years ago

deathcap commented 8 years ago
Uncaught Error: cwise: Arrays do not all have the same shape!
calcAO_cwise_thunk @ VM8501:8
computeMesh @ mesh.js:502
createVoxelMesh @ mesh-buffer.js:13
MesherPlugin.createVoxelMesh @ mesh-plugin.js:41
Game.showChunk @ index.js:645(anonymous function) @ land.js:134

on vmv with dev versions of voxel-decals, voxel-engine-stackgl, voxel-webview.

// cwise:
if (!(array1.shape[shapeIndex+0]===array2.shape[shapeIndex+0] && array1.shape[shapeIndex+0]===array3.shape[shapeIndex+0] && array1.shape[shapeIndex+0]===array4.shape[shapeIndex+0])) throw new Error('cwise: Arrays do not all have the same shape!')

//voxel-mesher mesh.js
  //Calculate ao fields
  surfaceStencil(ao0, ao1, ao2, array)

ao0, ao1, ao2 are all Int32Array[39304] (34^3 = 39304, chunk size 32x32x32 + 2 for padding) but array is Uint16Array[46656] (36^3 = 46656), passed in from:

//voxel-mesher mesh-buffer.js:

//Creates a mesh from a set of voxels
function createVoxelMesh(gl, voxels, voxelSideTextureIDs, voxelSideTextureSizes, position, pad, that) {
  //Create mesh
  var vert_data = createAOMesh(voxels, voxelSideTextureIDs, voxelSideTextureSizes)

//voxel-mesher mesh-plugin.js
MesherPlugin.prototype.createVoxelMesh = function(gl, voxels, voxelSideTextureIDs, voxelSideTextureSizes, position, pad) {
  var porousMesh = this.splitVoxelArray(voxels);

  var mesh = createVoxelMesh(gl, this.solidVoxels, voxelSideTextureIDs, voxelSideTextureSizes, position, pad, this);

//voxel-engine-stackgl
  var voxelArray = isndarray(chunk) ? chunk : ndarray(chunk.voxels, chunk.dims) 
 // voxelArray = View3duint16 {data: Uint16Array[46656], shape: Array[3], stride: Array[3], offset: 0, position: Array[3]}, chunk = View3duint16  ...
  var mesh = this.mesherPlugin.createVoxelMesh(this.shell.gl, voxelArray, this.stitcher.voxelSideTextureIDs, this.stitcher.voxelSideTextureSizes, chunk.position, this.chunkPad)
deathcap commented 8 years ago

Reproduced with isolated voxel-example: https://github.com/deathcap/voxel-example/tree/5e8ed535f8418e816001c8f14d4f3dcb858360aa

previously was using cwise 1.0.4 circa 2014, https://github.com/scijs/cwise/commits/master - https://github.com/scijs/cwise#notes documents "All input arrays must have the same shape. If not, then the library will throw an error". Exception is thrown in generated code: https://github.com/scijs/cwise-compiler/blob/master/lib/thunk.js#L61

   code.push("if (!(" + shapeConditions.join(" && ") + ")) throw new Error('cwise: Arrays do not all have the same shape!')")

this is a recent message, changed in https://github.com/scijs/cwise-compiler/commit/8f881ce54182581f88ffc30a4a9a6dd8b098a00d from "Generic arrays not supported in combination with blocks" which was added Jun 20th 2015 in https://github.com/scijs/cwise-compiler/commit/77fc9256152d2e95203437d5849501c9f5bcafc9 "Implemented array shape equality test.". Using cwise-compiler 1.0.0, also 1.1.0 does not have this check, but 1.1.2 does.

deathcap commented 8 years ago

Pinning cwise-compiler to 1.0.0 (package.json: "cwise-compiler": "1.0.0" — instead of "^1.0.0") gets past this error, but then the same problem occurs in ops.assign() in voxel-mesher splitVoxelArray(). ndarray-ops 1.2.2, but then ndarray-fill 1.0.1 depends on cwise-compiler, rolling back to ^0.1.0 hits the esprima-six unpublishing issue (https://github.com/deathcap/voxelmetaverse/issues/60)

--- a/package.json
+++ b/package.json
@@ -8,18 +8,18 @@
   },
   "dependencies": {
     "block-models": "^0.1.0",
-    "cwise-compiler": "^1.0.0",
+    "cwise-compiler": "1.0.0",
     "gl-buffer": "^2.0.8",
     "gl-mat4": "^1.1.2",
     "gl-vao": "^1.1.3",
     "greedy-mesher": "^1.0.2",
     "inherits": "^2.0.1",
     "ndarray": "^1.0.15",
-    "ndarray-ops": "^1.2.2",
+    "ndarray-ops": "1.2.2",
     "typedarray-pool": "^1.0.2"
   },
   "devDependencies": {
-    "ndarray-fill": "^1.0.1",
+    "ndarray-fill": "1.0.1",
     "ndarray-segment": "0.0.0",
     "tap": "^0.6.0",
     "voxel": "^0.5.0"
deathcap commented 8 years ago

cwise-compiler 1.1.0 is compatible, sticking on it for now (voxel-mesher 0.14.3 bugfix release), but may want to revisit to upgrade to a newer version. The problem is voxel-mesher relies on unequal array sizes in order to add padding between the chunks, maybe could instead use .subarray() to get an equally-sized ndarray before passing to cwise. @jaspervdg any possibility the check added in https://github.com/scijs/cwise-compiler/commit/77fc9256152d2e95203437d5849501c9f5bcafc9 could be made optional?