aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/shape-primitive.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/shape-primitive.js')
-rw-r--r--js/lib/geom/shape-primitive.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/js/lib/geom/shape-primitive.js b/js/lib/geom/shape-primitive.js
index 97873d32..9864a8e9 100644
--- a/js/lib/geom/shape-primitive.js
+++ b/js/lib/geom/shape-primitive.js
@@ -49,6 +49,33 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver
49 return prim; 49 return prim;
50}; 50};
51 51
52ShapePrimitive.getBounds = function( prim )
53{
54 var verts = prim.bufferStreams[0];
55 var nVerts = verts.length;
56 var xMin = verts[0], xMax = verts[0],
57 yMin = verts[1], yMax = verts[1],
58 zMin = verts[2], zMax = verts[2];
59
60 for (var index=3; index<verts.length; )
61 {
62 if (verts[index] < xMin) xMin = verts[index];
63 else if (verts[index] > xMax) xMax = verts[index];
64
65 index++;
66 if (verts[index] < yMin) yMin = verts[index];
67 else if (verts[index] > yMax) yMax = verts[index];
68
69 index++;
70 if (verts[index] < zMin) zMin = verts[index];
71 else if (verts[index] > zMax) zMax = verts[index];
72
73 index++;
74 }
75
76 return [xMin, yMin, zMin, xMax, yMax, zMax];
77};
78
52if (typeof exports === "object") { 79if (typeof exports === "object") {
53 exports.ShapePrimitive = ShapePrimitive; 80 exports.ShapePrimitive = ShapePrimitive;
54} \ No newline at end of file 81} \ No newline at end of file