UpdateMatrixWorld.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.quaternion.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 ) {
  26. return acc + nodeCount( x );
  27. }, 1 );
  28. };
  29. var rootA = generateSceneGraph( new THREE.Object3D(), 100, 1, createLocallyOffsetChild );
  30. var rootB = generateSceneGraph( new THREE.Object3D(), 3, 10, createLocallyOffsetChild );
  31. var rootC = generateSceneGraph( new THREE.Object3D(), 9, 3, createLocallyOffsetChild );
  32. var s = Bench.newSuite( 'Update world transforms' );
  33. s.add( 'Update graph depth=100, breadth=1 (' + nodeCount( rootA ) + ' nodes)', function () {
  34. rootA.updateMatrixWorld( true );
  35. } );
  36. s.add( 'Update graph depth=3, breadth=10 (' + nodeCount( rootB ) + ' nodes)', function () {
  37. rootB.updateMatrixWorld( true );
  38. } );
  39. s.add( 'Update graph depth=9, breadth=3 (' + nodeCount( rootC ) + ' nodes)', function () {
  40. rootC.updateMatrixWorld( true );
  41. } );
  42. } )();