Skip to content

Commit

Permalink
reset the bounding volumes if there is no mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
schteppe committed May 18, 2016
1 parent 5f5cad4 commit ac4f7fd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/goo/entities/components/MeshDataComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,17 @@ MeshDataComponent.prototype.setModelBound = function (modelBound, autoCompute) {
* Compute bounding center and bounds for this mesh.
*/
MeshDataComponent.prototype.computeBoundFromPoints = function () {
if (this.autoCompute && this.modelBound !== null && this.meshData) {
if (!this.autoCompute) {
return;
}
if (this.modelBound !== null && this.meshData) {
var verts = this.meshData.getAttributeBuffer('POSITION');
if (verts !== undefined) {
this.modelBound.computeFromPoints(verts);
this.autoCompute = false;
}
} else {
this.modelBound.reset();
}
};

Expand Down
15 changes: 6 additions & 9 deletions src/goo/loaders/handlers/MeshDataComponentHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var ShapeCreatorMemoized = require('../../util/ShapeCreatorMemoized');
var RSVP = require('../../util/rsvp');
var ObjectUtils = require('../../util/ObjectUtils');
var StringUtils = require('../../util/StringUtils');
var Vector3 = require('../../math/Vector3');

/**
* For handling loading of meshdatacomponents
Expand Down Expand Up @@ -82,14 +83,9 @@ MeshDataComponentHandler.prototype.update = function (entity, config, options) {
var min = meshData.boundingBox.min;
var max = meshData.boundingBox.max;
var size = [max[0] - min[0], max[1] - min[1], max[2] - min[2]];
var center = [(max[0] + min[0]) * 0.5, (max[1] + min[1]) * 0.5, (max[2] + min[2]) * 0.5];
var bounding = new BoundingBox();
bounding.xExtent = size[0] / 2;
bounding.yExtent = size[1] / 2;
bounding.zExtent = size[2] / 2;
bounding.center.setDirect(center[0], center[1], center[2]);
component.modelBound = bounding;
component.autoCompute = false;
var center = new Vector3(max[0] + min[0], max[1] + min[1], max[2] + min[2]).scale(0.5);
var bounding = new BoundingBox(center, size[0] / 2, size[1] / 2, size[2] / 2);
component.setModelBound(bounding, false);
}
}));
// Skeleton pose
Expand All @@ -105,8 +101,9 @@ MeshDataComponentHandler.prototype.update = function (entity, config, options) {
});
} else {
component.meshData = null;
component.autoCompute = true;
}
});
};

module.exports = MeshDataComponentHandler;
module.exports = MeshDataComponentHandler;
7 changes: 7 additions & 0 deletions src/goo/renderer/bounds/BoundingBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ for (var i = 0; i < 8; i++) {
BoundingBox.prototype = Object.create(BoundingVolume.prototype);
BoundingBox.prototype.constructor = BoundingBox;

BoundingBox.prototype.reset = function () {
this.xExtent = 1;
this.yExtent = 1;
this.zExtent = 1;
BoundingVolume.prototype.reset.call(this);
};

BoundingBox.prototype.computeFromPoints = function (verts) {
var l = verts.length;
if (l < 3) {
Expand Down
5 changes: 5 additions & 0 deletions src/goo/renderer/bounds/BoundingSphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ var tmpVec = new Vector3();
BoundingSphere.prototype = Object.create(BoundingVolume.prototype);
BoundingSphere.prototype.constructor = BoundingSphere;

BoundingSphere.prototype.reset = function () {
this.radius = 1;
BoundingVolume.prototype.reset.call(this);
};

BoundingSphere.prototype.computeFromPoints = function (verts) {
var l = verts.length;
if (l < 3) {
Expand Down
11 changes: 11 additions & 0 deletions src/goo/renderer/bounds/BoundingVolume.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ function BoundingVolume(center) {
this.max = new Vector3(-Infinity, -Infinity, -Infinity);
}

/**
* Sets the state to its initial value.
* @returns {BoundingVolume}
*/
BoundingVolume.prototype.reset = function () {
this.center.setDirect(0,0,0);
this.min.setDirect(Infinity, Infinity, Infinity);
this.max.setDirect(-Infinity, -Infinity, -Infinity);
return this;
};

/**
* Copies data from another bounding volume
* @param {BoundingVolume} source
Expand Down

0 comments on commit ac4f7fd

Please sign in to comment.