Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/benchmark/benchmarks.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<script src="core/Vector3Storage.js"></script>
<script src="core/Vector3Length.js"></script>
<script src="core/Float32Array.js"></script>
<script src="core/UpdateMatrixWorld.js"></script>
</head>
<body>
<header>
Expand Down
48 changes: 48 additions & 0 deletions test/benchmark/core/UpdateMatrixWorld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
(function() {

THREE = Bench.THREE;

var position = new THREE.Vector3(1, 1, 1);
var scale = new THREE.Vector3(2, 1, 0.5);
var rotation = new THREE.Quaternion();
rotation.setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI / 8);
var createLocallyOffsetChild = function() {
var child = new THREE.Object3D();
child.position = position;
child.scale = scale;
child.rotation = rotation;
return child;
};

var generateSceneGraph = function(root, depth, breadth, initObject) {
if (depth > 0) {
for (var i = 0; i < breadth; i++) {
var child = initObject();
root.add(child);
generateSceneGraph(child, depth - 1, breadth, initObject);
}
}
return root;
};

var nodeCount = function(root) {
return root.children.reduce(function(acc, x) { return acc + nodeCount(x); }, 1);
};

var rootA = generateSceneGraph(new THREE.Object3D(), 100, 1, createLocallyOffsetChild);
var rootB = generateSceneGraph(new THREE.Object3D(), 3, 10, createLocallyOffsetChild);
var rootC = generateSceneGraph(new THREE.Object3D(), 9, 3, createLocallyOffsetChild);

var s = Bench.newSuite("Update world transforms");

s.add('Update graph depth=100, breadth=1 (' + nodeCount(rootA) + ' nodes)', function() {
rootA.updateMatrixWorld(true);
});
s.add('Update graph depth=3, breadth=10 (' + nodeCount(rootB) + ' nodes)', function() {
rootB.updateMatrixWorld(true);
});
s.add('Update graph depth=9, breadth=3 (' + nodeCount(rootC) + ' nodes)', function() {
rootC.updateMatrixWorld(true);
});

})();