three-js-raysystem-r50

Benchmark created on


Preparation HTML

<script src="https://raw.github.com/mrdoob/three.js/master/build/three.min.js"></script>
<script>
var THREEr50 = THREE;
</script>
<script>
            var camera = new THREEr50.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 10000 );
                camera.position.set( 0, 300, 50 );
                scene = new THREEr50.Scene();
            var cubes = new THREEr50.Object3D();
            scene.add(cubes);
    
                var geometry = new THREEr50.CubeGeometry( 20, 20, 20 );
    
                for ( var i = 0; i < 50; i ++ ) {
    
                        var object = new THREEr50.Mesh( geometry, new THREEr50.MeshLambertMaterial( { color: (i/50) * 0xffffff } ) );
    
                        object.position.x = (i/50) * 800 - 400;
                        object.position.y = (i/50) * 800 - 400;
                        object.position.z = (i/50) * 800 - 400;
    
                        object.rotation.x = ( (i/50) * 360 ) * Math.PI / 180;
                        object.rotation.y = ( (i/50) * 360 ) * Math.PI / 180;
                        object.rotation.z = ( (i/50) * 360 ) * Math.PI / 180;
    
                        object.scale.x = (i/50) * 2 + 1;
                        object.scale.y = (i/50) * 2 + 1;
                        object.scale.z = (i/50) * 2 + 1;
    
                        cubes.add( object );
                        object.updateMatrixWorld();
                }
    
            var planes = new THREEr50.Object3D();
            scene.add(planes);
    
                var geometry = new THREEr50.PlaneGeometry( 20, 20);
    
                for ( var i = 0; i < 50; i ++ ) {
    
                        var object = new THREEr50.Mesh( geometry, new THREEr50.MeshLambertMaterial( { color: (i/50) * 0xffffff } ) );
    
                        object.position.x = (i/50) * 800 - 400;
                        object.position.y = (i/50) * 800 - 400;
                        object.position.z = (i/50) * 800 - 400;
    
                        object.rotation.x = ( (i/50) * 360 ) * Math.PI / 180;
                        object.rotation.y = ( (i/50) * 360 ) * Math.PI / 180;
                        object.rotation.z = ( (i/50) * 360 ) * Math.PI / 180;
    
                        object.scale.x = (i/50) * 2 + 1;
                        object.scale.y = (i/50) * 2 + 1;
                        object.scale.z = (i/50) * 2 + 1;
    
                        planes.add( object );
                        object.updateMatrixWorld();
                }
    
            var combined = new THREEr50.Object3D();
            scene.add(combined);
    
                var geometry = new THREEr50.CubeGeometry( 20, 20,20);
            var combGeometry = new THREEr50.CubeGeometry( 20, 20,20);
                for ( var i = 0; i < 50; i ++ ) {
    
                        var object = new THREEr50.Mesh( geometry, new THREEr50.MeshLambertMaterial( { color: (i/50) * 0xffffff } ) );
    
                        object.position.x = (i/50) * 800 - 400;
                        object.position.y = (i/50) * 800 - 400;
                        object.position.z = (i/50) * 800 - 400;
    
                        object.rotation.x = ( (i/50) * 360 ) * Math.PI / 180;
                        object.rotation.y = ( (i/50) * 360 ) * Math.PI / 180;
                        object.rotation.z = ( (i/50) * 360 ) * Math.PI / 180;
    
                        object.scale.x = (i/50) * 2 + 1;
                        object.scale.y = (i/50) * 2 + 1;
                        object.scale.z = (i/50) * 2 + 1;
    
                        THREEr50.GeometryUtils.merge(combGeometry, object );
    
                }
            var object = new THREEr50.Mesh( combGeometry, new THREEr50.MeshLambertMaterial( { color: 0.5 * 0xffffff } ) );
            combined.add(object);
    
            object.updateMatrixWorld();
    
    
                var vector = new THREEr50.Vector3( 0, 0, 0 );
                projector = new THREEr50.Projector();
                projector.unprojectVector( vector, camera );
    
                var ray= new THREEr50.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
    
    
            var spheres = new THREEr50.Object3D();
            scene.add(cubes);
    
                var geometry = new THREEr50.SphereGeometry( 20, 20, 20 );
    
                for ( var i = 0; i < 50; i ++ ) {
    
                        var object = new THREEr50.Mesh( geometry, new THREEr50.MeshLambertMaterial( { color: (i/50) * 0xffffff } ) );
    
                        object.position.x = (i/50) * 800 - 400;
                        object.position.y = (i/50) * 800 - 400;
                        object.position.z = (i/50) * 800 - 400;
    
                        object.rotation.x = ( (i/50) * 360 ) * Math.PI / 180;
                        object.rotation.y = ( (i/50) * 360 ) * Math.PI / 180;
                        object.rotation.z = ( (i/50) * 360 ) * Math.PI / 180;
    
                        object.scale.x = (i/50) * 2 + 1;
                        object.scale.y = (i/50) * 2 + 1;
                        object.scale.z = (i/50) * 2 + 1;
    
                        spheres.add( object );
                        object.updateMatrixWorld();
                }
                
                var rayr50 = ray;
                var cubesr50 = cubes;
                var planesr50 = planes;
                var spheresr50 = spheres;
                var combinedr50 = combined;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
cubes r50
var intersects = rayr50.intersectObjects( cubesr50.children )
ready
planes r50
var intersects = rayr50.intersectObjects( planesr50.children )
ready
combined r50
var intersects = rayr50.intersectObjects( combinedr50.children )
ready
spheres r50
var intersects = rayr50.intersectObjects( spheresr50.children )
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.