Skip to content

Commit

Permalink
Optimizations for depth sortin
Browse files Browse the repository at this point in the history
  • Loading branch information
tsherif committed Apr 25, 2016
1 parent 1eda205 commit cab02b9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 37 deletions.
4 changes: 2 additions & 2 deletions examples/benchmarks_40000boxes.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</style>

<script src="libs/stats.min.js"></script>
<script src="../api/latest/scenejs.min.js"></script>
<script src="../api/latest/scenejs.js"></script>

</head>
<body>
Expand Down Expand Up @@ -82,4 +82,4 @@

</script>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions examples/benchmarks_5000boxes.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</style>

<script src="libs/stats.min.js"></script>
<script src="../api/latest/scenejs.min.js"></script>
<script src="../api/latest/scenejs.js"></script>
<link href="css/styles.css" rel="stylesheet"/>

</head>
Expand Down Expand Up @@ -81,4 +81,4 @@

</script>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions examples/transforms_modelling_translate.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
-webkit-user-select: none;
}
</style>
<script src="../api/latest/scenejs.min.js"></script>
<script src="../api/latest/scenejs.js"></script>
<link href="css/styles.css" rel="stylesheet"/>

<body>
Expand Down Expand Up @@ -91,4 +91,4 @@

</script>
</body>
</html>
</html>
11 changes: 4 additions & 7 deletions src/core/display/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,19 @@ var SceneJS_Object = function(id) {
};

(function() {
var tempVec4 = SceneJS_math_vec4();
var tempMat4 = SceneJS_math_mat4();
var tempVec4 = new SceneJS_math_vec4();

SceneJS_Object.prototype.getDepth = function() {
if (!this.centroid) {
this.centroid = this._calculateCentroid(this);
}

this.modelTransform.build();
this.viewTransform.rebuild();

var modelMatrix = this.modelTransform.mat;
var viewMatrix = this.viewTransform.mat;

var mvMatrix = SceneJS_math_mulMat4(viewMatrix, modelMatrix, tempMat4);
var viewCentroid = SceneJS_math_transformVector4(mvMatrix, this.centroid, tempVec4);
var viewCentroid = SceneJS_math_transformVector4(modelMatrix, this.centroid, tempVec4);

SceneJS_math_transformVector4(viewMatrix, viewCentroid, viewCentroid);

return -viewCentroid[2];
};
Expand Down
14 changes: 2 additions & 12 deletions src/core/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,22 +616,12 @@
return SceneJS_math_mulVec3Scalar(v, f, dest);
};

// @private
// @private
window.SceneJS_math_normalizeVec2 = function (v, dest) {
var f = 1.0 / SceneJS_math_lenVec2(v);
return SceneJS_math_mulVec2Scalar(v, f, dest);
};

/** @private */
window.SceneJS_math_mat4 = function () {
return new Array(16);
};

/** @private */
window.SceneJS_math_dupMat4 = function (m) {
return m.slice(0, 16);
};

/** @private */
window.SceneJS_math_getCellMat4 = function (m, row, col) {
return m[row + col * 4];
Expand Down Expand Up @@ -2616,4 +2606,4 @@
return tangents;
}

})();
})();
22 changes: 10 additions & 12 deletions src/core/scene/modelXFormStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ var SceneJS_modelXFormStack = new (function () {
/**
* Pre-multiply matrices at cores on path up to root into matrix at this core
*/

var matrix = new SceneJS_math_mat4();

core.build = function () {

if (core.matrixDirty) {
Expand All @@ -130,11 +133,9 @@ var SceneJS_modelXFormStack = new (function () {

var parent = core.parent;

var matrix;

if (parent) {

matrix = core.matrix.slice(0);
matrix.set(core.matrix);

while (parent) {

Expand All @@ -144,9 +145,8 @@ var SceneJS_modelXFormStack = new (function () {
parent.buildMatrix();
}
parent.mat.set(parent.matrix);
parent.normalMat.set(
SceneJS_math_transposeMat4(
SceneJS_math_inverseMat4(parent.matrix, SceneJS_math_mat4())));
SceneJS_math_inverseMat4(parent.matrix, parent.normalMat);
SceneJS_math_transposeMat4(parent.normalMat, parent.normalMat);

parent.matrixDirty = false;
}
Expand All @@ -164,7 +164,7 @@ var SceneJS_modelXFormStack = new (function () {

} else {

matrix = core.matrix;
matrix.set(core.matrix);
}

// if (!core.mat) {
Expand All @@ -178,12 +178,10 @@ var SceneJS_modelXFormStack = new (function () {

core.mat.set(matrix);

core.normalMat.set(
SceneJS_math_transposeMat4(
SceneJS_math_inverseMat4(matrix, SceneJS_math_mat4())));
//}
SceneJS_math_inverseMat4(matrix, core.normalMat);
SceneJS_math_transposeMat4(core.normalMat, core.normalMat);

core.dirty = false;
core.dirty = false;
};
};

Expand Down

0 comments on commit cab02b9

Please sign in to comment.