Skip to content

Commit

Permalink
Merge pull request #463 from guycalledfrank/optimizeskinaabb4
Browse files Browse the repository at this point in the history
Optimize skinned AABB generation 4
  • Loading branch information
guycalledfrank committed Dec 3, 2015
2 parents a65040a + 5896078 commit 4640586
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/scene/scene_mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,39 @@ pc.extend(pc, function () {
var offsetWF = offsetW / 4;
var vertSizeF = vertSize / 4;

var boneVertsArray = [];
var x, y, z;
var boneMin = [];
var boneMax = [];
for(i=0; i<numBones; i++) {
boneVertsArray[i] = [];
boneMin[i] = new pc.Vec3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
boneMax[i] = new pc.Vec3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
}

for(j=0; j<numVerts; j++) {
for(k=0; k<4; k++) {
if (dataF[j * vertSizeF + offsetWF + k] > 0) {
index = data8[j * vertSize + offsetI + k];
// Vertex j is affected by bone index
boneVertsArray[index].push( dataF[j * vertSizeF + offsetPF] );
boneVertsArray[index].push( dataF[j * vertSizeF + offsetPF + 1] );
boneVertsArray[index].push( dataF[j * vertSizeF + offsetPF + 2] );
x = dataF[j * vertSizeF + offsetPF];
y = dataF[j * vertSizeF + offsetPF + 1];
z = dataF[j * vertSizeF + offsetPF + 2];

boneMin[index].x = Math.min(boneMin[index].x, x);
boneMin[index].y = Math.min(boneMin[index].y, y);
boneMin[index].z = Math.min(boneMin[index].z, z);

boneMax[index].x = Math.max(boneMax[index].x, x);
boneMax[index].y = Math.max(boneMax[index].y, y);
boneMax[index].z = Math.max(boneMax[index].z, z);
}
}
}

var aabb;
for(i=0; i<numBones; i++) {
this.mesh.boneAabb.push(new pc.BoundingBox());
this.mesh.boneAabb[i].compute(boneVertsArray[i]);
aabb = new pc.BoundingBox();
aabb.setMinMax(boneMin[i], boneMax[i]);
this.mesh.boneAabb.push(aabb);
}
}

Expand Down

0 comments on commit 4640586

Please sign in to comment.