<commit_before><!DOCTYPE html>
<html lang="en">
<head>
<title>Oimo.js Basic</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=11" />

<style>
    * {  margin: 0; padding: 0; border: 0;}
    body { background-color: #585858; overflow: hidden; color: #eeeeee; font-family: monospace; font-size: 12px; }
    input{ margin:0; padding:4px; }
    #interface{ position: absolute; left:10px; top:10px; width:456px; height:20px; }
    #info{ pointer-events:none; position: absolute; left:10px; top:50px; width: 400px; height: 400px; }
</style>

<script src="js/three.min.js"></script>
<script src="build/Oimo.min.js"></script>
<!--<script src="build/Oimo.rev.js"></script>-->

</head>
<body>
<div id='container'></div>
<div id='interface'>
    <input type="button" value="sphere" onClick=populate(1)>
    <input type="button" value="boxe" onClick=populate(2)>
    <input type="button" value="mix" onClick=populate(3)>
    <input type="number" name="quantity" min="10" max="2000" value="500"  id='MaxNumber'>
    <input type="submit" onClick=populate()>
    <input type="number" name="gravity" min="-20" max="20" value="-10" id='gravity' onChange=gravity() >
</div>
<div id='info'></div>
<a href="https://github.com/lo-th/Oimo.js"><img style="position: absolute; top: 0; right: 0; border: 0;" src="images/ribbon.png" alt="Fork me on GitHub"></a>

</body>        
<script>

    // three var
    var camera, scene, light, renderer, container, center;
    var meshs = [];
    var geoBox, geoSphere;
    var matBox, matSphere, matBoxSleep, matSphereSleep;

    // navigation var 
    var camPos = { horizontal: 90, vertical: 60, distance: 400, automove: false };
    var mouse = { ox:0, oy:0, h:0, v:0, mx:0, my:0, down:false, over:false, moving:true };
    var ToRad = Math.PI / 180;

    //oimo var
    var world;
    var bodys = [];

    var fps=0, time, time_prev=0, fpsint = 0;

    var type=1;

    init();
    loop();

    function init() {

        // three init
        renderer = new THREE.WebGLRenderer({precision: "mediump", antialias:false});
        renderer.setSize( window.innerWidth, window.innerHeight );
        renderer.setClearColor( 0x585858, 1 );

        container = document.getElementById("container");
        container.appendChild( renderer.domElement );

        camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 10000 );
        camera.position.set( 0, 100, 400 );
        center = new THREE.Vector3();
        moveCamera();

        scene = new THREE.Scene();

        scene.add( new THREE.AmbientLight( 0x383838 ) );

        light = new THREE.DirectionalLight( 0xffffff , 1.3);
        light.position.set( 0.3, 1, 0.5 ).normalize();
        scene.add( light );

        //add ground mesh
        var mat = new THREE.MeshLambertMaterial( { color: 0x151515 } );
        var geo0 = new THREE.CubeGeometry( 100, 40, 400 );
        var geo1 = new THREE.CubeGeometry( 400, 40, 400 );
        
        var mground0 = new THREE.Mesh( geo0, mat );
        mground0.position.y = -20;
        scene.add( mground0 );
        var mground1 = new THREE.Mesh( geo1, mat );
        mground1.position.y = -50;
        scene.add( mground1 );

        geoSphere = new THREE.SphereGeometry( 1 , 20, 10 );
        geoBox = new THREE.CubeGeometry( 1, 1, 1 );

        matSphere = new THREE.MeshLambertMaterial( { map: basicTexture(0), name:'sph' } );
        matBox = new THREE.MeshLambertMaterial( {  map: basicTexture(2), name:'box' } );
        matSphereSleep = new THREE.MeshLambertMaterial( { map: basicTexture(1), name:'ssph' } );
        matBoxSleep = new THREE.MeshLambertMaterial( {  map: basicTexture(3), name:'sbox' } );

        // oimo init
        world = new OIMO.World();

        populate(1);

        //

        window.addEventListener( 'resize', onWindowResize, false );
        container.addEventListener( 'mousemove', onMouseMove, false );
        container.addEventListener( 'mousedown', onMouseDown, false );
        container.addEventListener( 'mouseout', onMouseUp, false );
        container.addEventListener( 'mouseup', onMouseUp, false );
        container.addEventListener( 'mousewheel', onMouseWheel, false );
        container.addEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox
    }

    function populate(n) {

        var max = document.getElementById("MaxNumber").value;

        if(n===1) type = 1
        else if(n===2) type = 2;
        else if(n===3) type = 3;

        // reset old
        clearMesh();
        world.clear();

        //add ground
        var ground = new OIMO.Body({size:[100, 40, 400], pos:[0,-20,0], world:world});
        var ground2 = new OIMO.Body({size:[400, 40, 400], pos:[0,-50,0], world:world});

        //add object
        var x, y, z, w, h, d;
        var i = max;

        while (i--){
            if(type===3) t = Math.floor(Math.random()*2)+1;
            else t = type;
            x = -100 + Math.random()*200;
            z = -100 + Math.random()*200;
            y = 100 + Math.random()*1000;
            w = 10 + Math.random()*10;
            h = 10 + Math.random()*10;
            d = 10 + Math.random()*10;

            if(t===1){
                bodys[i] = new OIMO.Body({type:'sphere', size:[w*0.5], pos:[x,y,z], move:true, world:world});
                meshs[i] = new THREE.Mesh( geoSphere, matSphere );
                meshs[i].scale.set( w*0.5, w*0.5, w*0.5 );
            } else if(t===2){
                bodys[i] = new OIMO.Body({type:'box', size:[w,h,d], pos:[x,y,z], move:true, world:world});
                meshs[i] = new THREE.Mesh( geoBox, matBox );
                meshs[i].scale.set( w, h, d );
            }
            scene.add( meshs[i] );
        }
    }

    function clearMesh(){

        var i=meshs.length;
        while (i--)scene.remove(meshs[ i ]);

    }

    function onWindowResize() {

        camera.aspect = window.innerWidth / window.innerHeight;
        camera.updateProjectionMatrix();
        renderer.setSize( window.innerWidth, window.innerHeight );

    }

    function loop() {

        requestAnimationFrame( loop );
        
        world.step();

        var p, r, m, x, y, z;
        var mtx = new THREE.Matrix4();
        var i = bodys.length;
        var mesh;

        while (i--){

            mesh = meshs[i];

            if(!bodys[i].sleep()){
                m = bodys[i].getMatrix();
                mtx.fromArray(m);
                mesh.position.setFromMatrixPosition( mtx );
                mesh.rotation.setFromRotationMatrix( mtx );

                // change material
                if(mesh.material.name === 'sbox') mesh.material = matBox;
                if(mesh.material.name === 'ssph') mesh.material = matSphere; 

                // reset position
                if(m[13]<-100){
                    x = -100 + Math.random()*200;
                    z = -100 + Math.random()*200;
                    y = 100 + Math.random()*1000;
                    bodys[i].setPosition(x,y,z);
                }
            } else {
                if(mesh.material.name === 'box') mesh.material = matBoxSleep;
                if(mesh.material.name === 'sph') mesh.material = matSphereSleep;
            }
        }

        renderer.render( scene, camera );

        displayInfo();

    }

    function gravity(g){
        nG = document.getElementById("gravity").value
        world.gravity = new OIMO.Vec3(0, nG, 0);
    }

    function displayInfo(){

        time = Date.now();
        if (time - 1000 > time_prev) {
            time_prev = time; fpsint = fps; fps = 0;
        } fps++;
<commit_msg>Fixing body reference<commit_after><!DOCTYPE html>
<html lang="en">
<head>
<title>Oimo.js Basic</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=11" />

<style>
    * {  margin: 0; padding: 0; border: 0;}
    body { background-color: #585858; overflow: hidden; color: #eeeeee; font-family: monospace; font-size: 12px; }
    input{ margin:0; padding:4px; }
    #interface{ position: absolute; left:10px; top:10px; width:456px; height:20px; }
    #info{ pointer-events:none; position: absolute; left:10px; top:50px; width: 400px; height: 400px; }
</style>

<script src="js/three.min.js"></script>
<script src="build/Oimo.min.js"></script>
<!--<script src="build/Oimo.rev.js"></script>-->

</head>
<body>
<div id='container'></div>
<div id='interface'>
    <input type="button" value="sphere" onClick=populate(1)>
    <input type="button" value="boxe" onClick=populate(2)>
    <input type="button" value="mix" onClick=populate(3)>
    <input type="number" name="quantity" min="10" max="2000" value="500"  id='MaxNumber'>
    <input type="submit" onClick=populate()>
    <input type="number" name="gravity" min="-20" max="20" value="-10" id='gravity' onChange=gravity() >
</div>
<div id='info'></div>
<a href="https://github.com/lo-th/Oimo.js"><img style="position: absolute; top: 0; right: 0; border: 0;" src="images/ribbon.png" alt="Fork me on GitHub"></a>

</body>        
<script>

    // three var
    var camera, scene, light, renderer, container, center;
    var meshs = [];
    var geoBox, geoSphere;
    var matBox, matSphere, matBoxSleep, matSphereSleep;

    // navigation var 
    var camPos = { horizontal: 90, vertical: 60, distance: 400, automove: false };
    var mouse = { ox:0, oy:0, h:0, v:0, mx:0, my:0, down:false, over:false, moving:true };
    var ToRad = Math.PI / 180;

    //oimo var
    var world;
    var bodys = [];

    var fps=0, time, time_prev=0, fpsint = 0;

    var type=1;

    init();
    loop();

    function init() {

        // three init
        renderer = new THREE.WebGLRenderer({precision: "mediump", antialias:false});
        renderer.setSize( window.innerWidth, window.innerHeight );
        renderer.setClearColor( 0x585858, 1 );

        container = document.getElementById("container");
        container.appendChild( renderer.domElement );

        camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 10000 );
        camera.position.set( 0, 100, 400 );
        center = new THREE.Vector3();
        moveCamera();

        scene = new THREE.Scene();

        scene.add( new THREE.AmbientLight( 0x383838 ) );

        light = new THREE.DirectionalLight( 0xffffff , 1.3);
        light.position.set( 0.3, 1, 0.5 ).normalize();
        scene.add( light );

        //add ground mesh
        var mat = new THREE.MeshLambertMaterial( { color: 0x151515 } );
        var geo0 = new THREE.CubeGeometry( 100, 40, 400 );
        var geo1 = new THREE.CubeGeometry( 400, 40, 400 );
        
        var mground0 = new THREE.Mesh( geo0, mat );
        mground0.position.y = -20;
        scene.add( mground0 );
        var mground1 = new THREE.Mesh( geo1, mat );
        mground1.position.y = -50;
        scene.add( mground1 );

        geoSphere = new THREE.SphereGeometry( 1 , 20, 10 );
        geoBox = new THREE.CubeGeometry( 1, 1, 1 );

        matSphere = new THREE.MeshLambertMaterial( { map: basicTexture(0), name:'sph' } );
        matBox = new THREE.MeshLambertMaterial( {  map: basicTexture(2), name:'box' } );
        matSphereSleep = new THREE.MeshLambertMaterial( { map: basicTexture(1), name:'ssph' } );
        matBoxSleep = new THREE.MeshLambertMaterial( {  map: basicTexture(3), name:'sbox' } );

        // oimo init
        world = new OIMO.World();

        populate(1);

        //

        window.addEventListener( 'resize', onWindowResize, false );
        container.addEventListener( 'mousemove', onMouseMove, false );
        container.addEventListener( 'mousedown', onMouseDown, false );
        container.addEventListener( 'mouseout', onMouseUp, false );
        container.addEventListener( 'mouseup', onMouseUp, false );
        container.addEventListener( 'mousewheel', onMouseWheel, false );
        container.addEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox
    }

    function populate(n) {

        var max = document.getElementById("MaxNumber").value;

        if(n===1) type = 1
        else if(n===2) type = 2;
        else if(n===3) type = 3;

        // reset old
        clearMesh();
        world.clear();

        //add ground
        var ground = new OIMO.Body({size:[100, 40, 400], pos:[0,-20,0], world:world});
        var ground2 = new OIMO.Body({size:[400, 40, 400], pos:[0,-50,0], world:world});

        //add object
        var x, y, z, w, h, d;
        var i = max;

        while (i--){
            if(type===3) t = Math.floor(Math.random()*2)+1;
            else t = type;
            x = -100 + Math.random()*200;
            z = -100 + Math.random()*200;
            y = 100 + Math.random()*1000;
            w = 10 + Math.random()*10;
            h = 10 + Math.random()*10;
            d = 10 + Math.random()*10;

            if(t===1){
                bodys[i] = new OIMO.Body({type:'sphere', size:[w*0.5], pos:[x,y,z], move:true, world:world});
                meshs[i] = new THREE.Mesh( geoSphere, matSphere );
                meshs[i].scale.set( w*0.5, w*0.5, w*0.5 );
            } else if(t===2){
                bodys[i] = new OIMO.Body({type:'box', size:[w,h,d], pos:[x,y,z], move:true, world:world});
                meshs[i] = new THREE.Mesh( geoBox, matBox );
                meshs[i].scale.set( w, h, d );
            }
            scene.add( meshs[i] );
        }
    }

    function clearMesh(){

        var i=meshs.length;
        while (i--)scene.remove(meshs[ i ]);

    }

    function onWindowResize() {

        camera.aspect = window.innerWidth / window.innerHeight;
        camera.updateProjectionMatrix();
        renderer.setSize( window.innerWidth, window.innerHeight );

    }

    function loop() {

        requestAnimationFrame( loop );
        
        world.step();

        var p, r, m, x, y, z;
        var mtx = new THREE.Matrix4();
        var i = bodys.length;
        var mesh;

        while (i--){
            var body = bodys[i].body;
            mesh = meshs[i];

            if(!body.sleep()){
                m = body.getMatrix();
                mtx.fromArray(m);
                mesh.position.setFromMatrixPosition( mtx );
                mesh.rotation.setFromRotationMatrix( mtx );

                // change material
                if(mesh.material.name === 'sbox') mesh.material = matBox;
                if(mesh.material.name === 'ssph') mesh.material = matSphere; 

                // reset position
                if(m[13]<-100){
                    x = -100 + Math.random()*200;
                    z = -100 + Math.random()*200;
                    y = 100 + Math.random()*1000;
                    body.setPosition(x,y,z);
                }
            } else {
                if(mesh.material.name === 'box') mesh.material = matBoxSleep;
                if(mesh.material.name === 'sph') mesh.material = matSphereSleep;
            }
        }

        renderer.render( scene, camera );

        displayInfo();

    }

    function gravity(g){
        nG = document.getElementById("gravity").value
        world.gravity = new OIMO.Vec3(0, nG, 0);
    }

    function displayInfo(){

        time = Date.now();
        if (time - 1000 > time_prev) {
            time_prev = time; fpsint = fps; fps = 0;
        } fps++;

{'fraction_non_alphanumeric': 0.15791513272621585, 'fraction_numerical': 0.03578117935800555, 'mean_word_length': 2.2224765868886576, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 77, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '570671', 'n_tokens_mistral': 5503, 'n_tokens_neox': 4878, 'n_words': 1147}