Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmarks: Update world transforms / updateMatrixWorld() - improve benchmark realism #25113

Closed
Closed
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
99 changes: 88 additions & 11 deletions test/benchmark/core/UpdateMatrixWorld.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,78 @@
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 createLocallyOffsetChild = function (type) {

let child;
let choice;

switch (type) {
case "Object3D":
child = new THREE.Object3D();
break;

case "Polymorphic":
child = new THREE.Object3D();
choice = Math.random();
if (choice < 0.2) {
child.extra1 = "test-polymorphism";
}
else if (choice < 0.4) {
child.extra2 = "test-polymorphism";
}
else if (choice < 0.6) {
child.extra3 = "test-polymorphism";
}
else if (choice < 0.8) {
child.extra4 = "test-polymorphism";
}
break;

case "Mesh":
child = new THREE.Mesh();
break;

case "Skinned":
child = new THREE.SkinnedMesh();
break;

case "Realistic":
choice = Math.random();
if (choice < 0.05) {
child = new THREE.InstancedMesh();
}
else if (choice < 0.1) {
child = new THREE.SkinnedMesh();
}
else if (choice < 0.6) {
child = new THREE.Mesh();
}
else {
child = new THREE.Group();
}
break;

default:
console.error("Unexpected test type:", type)
break;
}

var child = new THREE.Object3D();
child.position.copy( position );
child.scale.copy( scale );
child.rotation.copy( rotation );
return child;

};

var generateSceneGraph = function ( root, depth, breadth, initObject ) {
var generateSceneGraph = function ( root, depth, breadth, initObject, type ) {

if ( depth > 0 ) {

for ( var i = 0; i < breadth; i ++ ) {

var child = initObject();
var child = initObject(type);
root.add( child );
generateSceneGraph( child, depth - 1, breadth, initObject );
generateSceneGraph( child, depth - 1, breadth, initObject, type );

}

Expand All @@ -44,26 +97,50 @@

};

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 rootA = generateSceneGraph( new THREE.Object3D(), 100, 1, createLocallyOffsetChild, "Object3D" );
var rootB = generateSceneGraph( new THREE.Object3D(), 3, 10, createLocallyOffsetChild, "Object3D" );
var rootC = generateSceneGraph( new THREE.Object3D(), 9, 3, createLocallyOffsetChild, "Object3D" );
var rootD = generateSceneGraph( new THREE.Object3D(), 9, 3, createLocallyOffsetChild, "Polymorphic" );
var rootE = generateSceneGraph( new THREE.Object3D(), 9, 3, createLocallyOffsetChild, "Mesh" );
var rootF = generateSceneGraph( new THREE.Object3D(), 9, 3, createLocallyOffsetChild, "Skinned" );
var rootG = generateSceneGraph( new THREE.Object3D(), 9, 3, createLocallyOffsetChild, "Realistic" );

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

s.add( 'Update graph depth=100, breadth=1 (' + nodeCount( rootA ) + ' nodes)', function () {
s.add( 'Update graph depth=100, breadth=1, monomorphic Object3D (' + nodeCount( rootA ) + ' nodes)', function () {

rootA.updateMatrixWorld( true );

} );
s.add( 'Update graph depth=3, breadth=10 (' + nodeCount( rootB ) + ' nodes)', function () {
s.add( 'Update graph depth=3, breadth=10, monomorphic Object3D (' + nodeCount( rootB ) + ' nodes)', function () {

rootB.updateMatrixWorld( true );

} );
s.add( 'Update graph depth=9, breadth=3 (' + nodeCount( rootC ) + ' nodes)', function () {
s.add( 'Update graph depth=9, breadth=3, monomorphic Object3D (' + nodeCount( rootC ) + ' nodes)', function () {

rootC.updateMatrixWorld( true );

} );
s.add( 'Update graph depth=9, breadth=3, polymorphic (' + nodeCount( rootD ) + ' nodes)', function () {

rootD.updateMatrixWorld( true );

} );
s.add( 'Update graph depth=9, breadth=3, monomorphic Mesh (' + nodeCount( rootE ) + ' nodes)', function () {

rootE.updateMatrixWorld( true );

} );
s.add( 'Update graph depth=9, breadth=3, monomorphic SkinnedMesh (' + nodeCount( rootF ) + ' nodes)', function () {

rootF.updateMatrixWorld( true );

} );
s.add( 'Update graph depth=9, breadth=3, realistic blend (' + nodeCount( rootG ) + ' nodes)', function () {

rootG.updateMatrixWorld( true );

} );

} )();