UpdateMatrixWorld.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. (function() {
  2. THREE = Bench.THREE;
  3. var position = new THREE.Vector3(1, 1, 1);
  4. var scale = new THREE.Vector3(2, 1, 0.5);
  5. var rotation = new THREE.Quaternion();
  6. rotation.setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI / 8);
  7. var createLocallyOffsetChild = function() {
  8. var child = new THREE.Object3D();
  9. child.position.copy(position);
  10. child.scale.copy(scale);
  11. child.rotation.copy(rotation);
  12. return child;
  13. };
  14. var generateSceneGraph = function(root, depth, breadth, initObject) {
  15. if (depth > 0) {
  16. for (var i = 0; i < breadth; i++) {
  17. var child = initObject();
  18. root.add(child);
  19. generateSceneGraph(child, depth - 1, breadth, initObject);
  20. }
  21. }
  22. return root;
  23. };
  24. var nodeCount = function(root) {
  25. return root.children.reduce(function(acc, x) { return acc + nodeCount(x); }, 1);
  26. };
  27. var rootA = generateSceneGraph(new THREE.Object3D(), 100, 1, createLocallyOffsetChild);
  28. var rootB = generateSceneGraph(new THREE.Object3D(), 3, 10, createLocallyOffsetChild);
  29. var rootC = generateSceneGraph(new THREE.Object3D(), 9, 3, createLocallyOffsetChild);
  30. var s = Bench.newSuite("Update world transforms");
  31. s.add('Update graph depth=100, breadth=1 (' + nodeCount(rootA) + ' nodes)', function() {
  32. rootA.updateMatrixWorld(true);
  33. });
  34. s.add('Update graph depth=3, breadth=10 (' + nodeCount(rootB) + ' nodes)', function() {
  35. rootB.updateMatrixWorld(true);
  36. });
  37. s.add('Update graph depth=9, breadth=3 (' + nodeCount(rootC) + ' nodes)', function() {
  38. rootC.updateMatrixWorld(true);
  39. });
  40. })();