~ aFalcon: Deep~Dives

Introducing: TEN-KEY-CONTROLLER

  • have a look. A powerful concept to use 10key in 3D, in multiple MODES. :slight_smile:
    /***********************************- TEN-KEY-CTRL -***********************************\
    - use 10 Key ui to give yourself super powers in BABYLON!!! 
    - use the 5 key to toggle between MODES
    - the MODES (below) are: 'cam','edit','anm', also 'game'  
    - extensible in many ways.
    - example: Alt key changes magnitude of movement, OR direction of rotations, etc-.
    \**************************************************************************************/
    nx.tenKey={mode:'cam'};
    nx.ui.ctrl = {fwd:0,bwd:0,lft:0,rgt:0,up:0,dwn:0,MAGNITUDE:1}
    nx.tenKeyCtrl = function(){
        if(nx.tenKey.nextmode){  //MODE-ITERATOR-.
                if(!nx.tenKey.mode){ 
                    nx.tenKey.mode='cam'
                }else if(nx.tenKey.mode === 'cam' ){
                    nx.tenKey.mode='edit'
                }else if(nx.tenKey.mode === 'edit' ){
                    nx.tenKey.mode='anm'
                }else if(nx.tenKey.mode === 'anm' ){
                    nx.tenKey.mode='cam'
                }
                nx.ui.tenKeyTxt.html(nx.tenKey.mode)
                nx.tenKey.nextmode = 0;
            return;
        }
        //METHOD:-INTERPRET-the-move-by-the-MODE-.
        if(nx.tenKey.mode==='cam'){ //--------------------------------------CAM-.
            //Call cam move on Active-Camera-. //Move-ActiveCam: UP, DWN, LFT, RGT, FWD, BWD.
            var direction = (nx.ui.ctrl.fwd || nx.ui.ctrl.rgt || nx.ui.ctrl.up || nx.ui.ctrl.lookdwn) ? 1 : (nx.ui.ctrl.lft || nx.ui.ctrl.bwd || nx.ui.ctrl.dwn || nx.ui.ctrl.lookup) ? -1 : 0;
            nx.ui.ctrl.MAGNITUDE = (nx.ui.ctrl.alt)? 1 : 10;
            var moveAmount = nx.ui.ctrl.MAGNITUDE * direction;
            var curPos = nx.scene.activeCamera.position;
            nx.scene.activeCamera = nx.cams.freeCam;
            nx.scene.activeCamera.position.copyFrom(curPos); //CAM-MAINTAIN-POS //todo cam maintain frustum
            if(nx.ui.ctrl.fwd || nx.ui.ctrl.bwd){ nx.scene.activeCamera.position.z+=moveAmount; }
            if(nx.ui.ctrl.lft || nx.ui.ctrl.rgt){ nx.scene.activeCamera.position.x+=moveAmount; }
            if(nx.ui.ctrl.up || nx.ui.ctrl.dwn){ nx.scene.activeCamera.position.y+=moveAmount; }
            if(nx.ui.ctrl.lookup || nx.ui.ctrl.lookdwn){ //todo consider turning off state (redundantly) at this level not before or after-.
                moveAmount = 0.1 * direction;
                if(nx.ui.ctrl.alt){ //rotate camera left or right
                    nx.scene.activeCamera.noRotationConstraint=true; //required to rotate cam
                    nx.scene.activeCamera.rotation.y+=moveAmount;
                } else { //rotate camera up or down
                    nx.scene.activeCamera.noRotationConstraint=true; //required to rotate cam
                    nx.scene.activeCamera.rotation.x+=moveAmount;
                }
            }
        } else if (nx.tenKey.mode==='edit') { //EDIT-. //Call edit move on active edit nodes-.
            for(var i = 0; i< nx.activeEditNodes.length; i++){
                var editNode = nx.activeEditNodes[i];
                editNode.editFn(); //Call-Edits-.
            }
        } else if (nx.tenKey.mode==='anm') { //---ANM-.
            if(nx.ui.ctrl.lookup){ nx.ui.ctrl.lookup=0; //call many anm sequences-.
                runSequence("CrashSequence")
            }
        }
    }

Trigger tenKeyCtrl like this:


                //------------------------------------10-KEY-CONTROLS-.
                case 101: //numpad 5KEY - MODEKEY
                    nx.tenKey.nextmode=1; nx.tenKeyCtrl();
                    break;
                //------------------------------------10-KEY-EDITING-.
                case 104://numpad 8FWD
                    nx.ui.ctrl.fwd=1; nx.tenKeyCtrl(); 
                    break;
                case 102://numpad 6RIGHT
                    nx.ui.ctrl.rgt=1; nx.tenKeyCtrl();
                    break;
                case 98://numpad 2BACK
                    nx.ui.ctrl.bwd=1; nx.tenKeyCtrl();
                    break;
                case 100://numpad 4LEFT
                    nx.ui.ctrl.lft=1; nx.tenKeyCtrl();
                    break;
                case 103://numpad 7UP
                    nx.ui.ctrl.up=1; nx.tenKeyCtrl();
                    break;
                case 105://numpad2 9DOWN
                    nx.ui.ctrl.dwn=1; nx.tenKeyCtrl();
                    break;
                case 97://numpad1 
                    // runSequence("CrashSequence")
                    nx.ui.ctrl.lookup=1; nx.tenKeyCtrl();
                    break;
                case 99://numpad3 
                    nx.ui.ctrl.lookdwn=1; nx.tenKeyCtrl();
                    break;
            }    

            if(e.altKey) { nx.ui.ctrl.alt = 1 }
            else { nx.ui.ctrl.alt =  0}

If someone asks, I try PG. :eagle:

Moving on… :heavy_check_mark:

  • With TenKeyCAM, can finish the bounce animation, switching between: anm, cam, and edit - without ever leaving the keyboard!!!

  • The TenKeyCam was needed to precisely make EDITS from many angles: freecam with rotation.

NOTE: publishing the PATH is done with the P key and the code is a STRINGIFY!!!:

    var printRecordedPath = function(){
        console.log('PUBLISH:'); //PUBLISH-RECORD-.
        console.log(JSON.stringify(nx.bouncePath)); //PUBLISH-RECORD-.  
}

Then the EDITED PATH array can be copied from devtools and saved into the member variables…

:black_heart: