Skip to content

Commit

Permalink
Fix various code issues pointed out by @jbmonroe.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tribex committed Nov 20, 2015
1 parent 096c28c commit acad715
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 48 deletions.
1 change: 0 additions & 1 deletion dist/CEWBS-0.2.5.js

This file was deleted.

24 changes: 12 additions & 12 deletions dist/CEWBS-0.2.5-commonjs.js → dist/CEWBS-0.2.6-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var meshers = {
var CEWBS = {};
CEWBS.Util = require('./helpers/util.js');

CEWBS.version = '0.2.5';
CEWBS.version = '0.2.6';

CEWBS.VoxelMesh = function(name, scene) {
BABYLON.Mesh.call(this, name, scene);
Expand Down Expand Up @@ -51,7 +51,7 @@ CEWBS.VoxelMesh.prototype.setVoxelAt = function(pos, id, meta) {

CEWBS.VoxelMesh.prototype.setMetaAt = function(pos, meta) {
if(this.voxelData.voxels != null) {
if(Array.isArray(x)) {
if(Array.isArray(pos)) {
var index = this.positionToIndex(pos);
if(Array.isArray(this.voxelData.voxels[index])) {
this.voxelData.voxels[this.positionToIndex(pos)][1] = meta;
Expand Down Expand Up @@ -104,7 +104,7 @@ CEWBS.VoxelMesh.prototype.getVoxelData = function() {

//Sets the dimensions of the voxel volume. Input should be ([x,y,z]);
CEWBS.VoxelMesh.prototype.setDimensions = function(dims) {
if (Array.isArray(dims) && dims.length == 3) {
if (Array.isArray(dims) && dims.length === 3) {
if(this.voxelData == null) {
this.voxelData = {};
}
Expand Down Expand Up @@ -143,7 +143,7 @@ CEWBS.VoxelMesh.prototype.updateMesh = function(passID) {
var color = this.coloringFunction(q[3], q[4]);
if(color == null || color.length < 3) {
color = [300,75,300,255];
} else if (color.length == 3) {
} else if (color.length === 3) {
color.push(255);
}

Expand All @@ -164,7 +164,7 @@ CEWBS.VoxelMesh.prototype.updateMesh = function(passID) {

if(!passID) {
if(vertexData.positions.length > 0) {
if(this.noVoxels = true) {
if(this.noVoxels === true) {
this.isVisible = this.oldVisibility;
this.noVoxels = false;
}
Expand All @@ -180,9 +180,9 @@ CEWBS.VoxelMesh.prototype.updateMesh = function(passID) {
this.oldVisibility = this.isVisible;
this.isVisible = false;
}
} else if (passID == 1) {
} else if (passID === 1) {
if(vertexData.positions.length > 0) {
if(this.transparentMesh.noVoxels = true) {
if(this.transparentMesh.noVoxels === true) {
this.transparentMesh.isVisible = this.transparentMesh.oldVisibility;
this.transparentMesh.noVoxels = false;
}
Expand Down Expand Up @@ -216,9 +216,9 @@ CEWBS.VoxelMesh.prototype.originToCenterOfBounds = function(ignoreY) {

//Sets the origin (pivot point) of the mesh.
CEWBS.VoxelMesh.prototype.setPivot = function(pivot) {
var pivot = BABYLON.Matrix.Translation(pivot[0],pivot[1],pivot[2]);
var babylonPivot = BABYLON.Matrix.Translation(pivot[0],pivot[1],pivot[2]);

this.setPivotMatrix(pivot);
this.setPivotMatrix(babylonPivot);
}

/*Exports the voxel data to a more portable form which is dimension-independent and can be more compact.
Expand Down Expand Up @@ -304,23 +304,23 @@ CEWBS.VoxelMesh.handlePick = function(pickResult) {
var offsetY = +(v.y-v.y.toFixed(0)).toFixed(4);
var offsetZ = +(v.z-v.z.toFixed(0)).toFixed(4);

if(offsetX == 0) {
if(offsetX === 0) {
x = Math.round(v.x);
y = Math.floor(v.y);
z = Math.floor(v.z);
if(x>=mesh.voxelData.dimensions[0]) x=mesh.voxelData.dimensions[0]-1;

voxel1 = [x,y,z];
voxel2 = [x-1,y,z];
} else if (offsetY == 0) {
} else if (offsetY === 0) {
x = Math.floor(v.x);
y = Math.round(v.y);
z = Math.floor(v.z);
if(y>=mesh.voxelData.dimensions[1]) y=mesh.voxelData.dimensions[1]-1;

voxel1 = [x,y,z];
voxel2 = [x,y-1,z];
} else if (offsetZ == 0) {
} else if (offsetZ === 0) {
x = Math.floor(v.x);
y = Math.floor(v.y);
z = Math.round(v.z);
Expand Down
24 changes: 12 additions & 12 deletions dist/CEWBS-0.2.5-debug.js → dist/CEWBS-0.2.6-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var meshers = {
var CEWBS = window.CEWBS = {};
CEWBS.Util = require('./helpers/util.js');

CEWBS.version = '0.2.5';
CEWBS.version = '0.2.6';

CEWBS.VoxelMesh = function(name, scene) {
BABYLON.Mesh.call(this, name, scene);
Expand Down Expand Up @@ -52,7 +52,7 @@ CEWBS.VoxelMesh.prototype.setVoxelAt = function(pos, id, meta) {

CEWBS.VoxelMesh.prototype.setMetaAt = function(pos, meta) {
if(this.voxelData.voxels != null) {
if(Array.isArray(x)) {
if(Array.isArray(pos)) {
var index = this.positionToIndex(pos);
if(Array.isArray(this.voxelData.voxels[index])) {
this.voxelData.voxels[this.positionToIndex(pos)][1] = meta;
Expand Down Expand Up @@ -105,7 +105,7 @@ CEWBS.VoxelMesh.prototype.getVoxelData = function() {

//Sets the dimensions of the voxel volume. Input should be ([x,y,z]);
CEWBS.VoxelMesh.prototype.setDimensions = function(dims) {
if (Array.isArray(dims) && dims.length == 3) {
if (Array.isArray(dims) && dims.length === 3) {
if(this.voxelData == null) {
this.voxelData = {};
}
Expand Down Expand Up @@ -144,7 +144,7 @@ CEWBS.VoxelMesh.prototype.updateMesh = function(passID) {
var color = this.coloringFunction(q[3], q[4]);
if(color == null || color.length < 3) {
color = [300,75,300,255];
} else if (color.length == 3) {
} else if (color.length === 3) {
color.push(255);
}

Expand All @@ -165,7 +165,7 @@ CEWBS.VoxelMesh.prototype.updateMesh = function(passID) {

if(!passID) {
if(vertexData.positions.length > 0) {
if(this.noVoxels = true) {
if(this.noVoxels === true) {
this.isVisible = this.oldVisibility;
this.noVoxels = false;
}
Expand All @@ -181,9 +181,9 @@ CEWBS.VoxelMesh.prototype.updateMesh = function(passID) {
this.oldVisibility = this.isVisible;
this.isVisible = false;
}
} else if (passID == 1) {
} else if (passID === 1) {
if(vertexData.positions.length > 0) {
if(this.transparentMesh.noVoxels = true) {
if(this.transparentMesh.noVoxels === true) {
this.transparentMesh.isVisible = this.transparentMesh.oldVisibility;
this.transparentMesh.noVoxels = false;
}
Expand Down Expand Up @@ -217,9 +217,9 @@ CEWBS.VoxelMesh.prototype.originToCenterOfBounds = function(ignoreY) {

//Sets the origin (pivot point) of the mesh.
CEWBS.VoxelMesh.prototype.setPivot = function(pivot) {
var pivot = BABYLON.Matrix.Translation(pivot[0],pivot[1],pivot[2]);
var babylonPivot = BABYLON.Matrix.Translation(pivot[0],pivot[1],pivot[2]);

this.setPivotMatrix(pivot);
this.setPivotMatrix(babylonPivot);
}

/*Exports the voxel data to a more portable form which is dimension-independent and can be more compact.
Expand Down Expand Up @@ -305,23 +305,23 @@ CEWBS.VoxelMesh.handlePick = function(pickResult) {
var offsetY = +(v.y-v.y.toFixed(0)).toFixed(4);
var offsetZ = +(v.z-v.z.toFixed(0)).toFixed(4);

if(offsetX == 0) {
if(offsetX === 0) {
x = Math.round(v.x);
y = Math.floor(v.y);
z = Math.floor(v.z);
if(x>=mesh.voxelData.dimensions[0]) x=mesh.voxelData.dimensions[0]-1;

voxel1 = [x,y,z];
voxel2 = [x-1,y,z];
} else if (offsetY == 0) {
} else if (offsetY === 0) {
x = Math.floor(v.x);
y = Math.round(v.y);
z = Math.floor(v.z);
if(y>=mesh.voxelData.dimensions[1]) y=mesh.voxelData.dimensions[1]-1;

voxel1 = [x,y,z];
voxel2 = [x,y-1,z];
} else if (offsetZ == 0) {
} else if (offsetZ === 0) {
x = Math.floor(v.x);
y = Math.floor(v.y);
z = Math.round(v.z);
Expand Down
Loading

0 comments on commit acad715

Please sign in to comment.