PageSourceSearch

https://www.robotmesh.com/studio/content/jsx/robotmesh/tsjs/flowol/mimics/ClawMachine.js

js robotmesh.com collected 2026-09-24 12:53:29 UTC 8,181 bytes, 1 lines download raw bytes

1import{vexiq_state}from"../../interfaces/vexiq_state.js";import{three_dimensional_mimic as m3d}from"../three_dimensional_mimic.js";import{ClawMachineScene}from"./ClawMachineScene.js";const ButtonTimeout=500;var BearState;!function(e){e[e.Available=0]="Available",e[e.Grabbed=1]="Grabbed",e[e.Falling=2]="Falling",e[e.Waiting=3]="Waiting",e[e.Vanished=4]="Vanished"}(BearState||(BearState={}));class TeddyBear{constructor(e,t,i){this._eBearState=BearState.Available,this._eBearState=BearState.Available,this._model=i,this._flFallVelocity=0,this._flFallRotation=0,this._flAvailableRotation=0,this._flInitialX=e,this._flInitialZ=t,this._dwWaitTime=0,this.Reset()}Reset(){this._eBearState=BearState.Available,this._flAvailableRotation=0,this._flX=this._flInitialX,this._flZ=this._flInitialZ}OnTick(e,t,i,s,a){e*=.1,t*=.1;var h=!1;switch(this._eBearState){case BearState.Vanished:return!1;case BearState.Available:s>=-10&&i>=2.3&&(t-this._flX)*(t-this._flX)+(e-this._flZ)*(e-this._flZ)<.01&&(this._eBearState=BearState.Grabbed,h=!0,null!=a&&a.setValue(!0));break;case BearState.Grabbed:s<-10&&(this._eBearState=BearState.Falling,this._flXFall=t,this._flYFall=1.44-.54*i-.15,this._flZFall=e,this._flFallVelocity=0,this._flFallRotation=30*i-72+this._flAvailableRotation,h=!0,null!=a&&a.setValue(!1));break;case BearState.Falling:this._flYFall-=this._flFallVelocity,this._flFallVelocity+=5e-4,this._flYFall<=0&&(this._flXFall>-.3||this._flZFall<.28)&&(this._eBearState=BearState.Available,this._flAvailableRotation=this._flFallRotation,this._flX=this._flXFall,this._flZ=this._flZFall),this._flYFall<-.48&&(this._flYFall=-.48,this._eBearState=BearState.Waiting,this._dwWaitTime=performance.now()),h=!0;break;case BearState.Waiting:performance.now()-this._dwWaitTime>4e3&&(this._eBearState=BearState.Vanished,h=!0)}return h}BeforeRender(e,t){void 0!==this._model&&(this._eBearState==BearState.Grabbed?(this._model.parent!=e&&(null!=this._model.parent&&this._model.parent.remove(this._model),e.add(this._model)),this._model.position.set(0,0,0),this._model.setRotationFromAxisAngle(new THREE.Vector3(0,1,0),m3d.deg_to_rad(this._flAvailableRotation))):this._eBearState==BearState.Vanished?null!=this._model.parent&&this._model.parent.remove(this._model):(this._model.parent!=t&&(null!=this._model.parent&&this._model.parent.remove(this._model),t.add(this._model)),this._eBearState==BearState.Available?(this._model.position.set(this._flX,0,this._flZ),this._model.setRotationFromAxisAngle(new THREE.Vector3(0,1,0),m3d.deg_to_rad(this._flAvailableRotation))):this._eBearState!=BearState.Falling&&this._eBearState!=BearState.Waiting||(this._model.position.set(this._flXFall,this._flYFall,this._flZFall),this._model.setRotationFromAxisAngle(new THREE.Vector3(0,1,0),m3d.deg_to_rad(this._flFallRotation)))))}}export class ClawMachine extends m3d.Flowol3DMimic{constructor(e){super(e),this._teddyBears=[],this._inputClicked=null,this.scene=new ClawMachineScene}Initialize(e){var t=super.Initialize(e);this._backwards=this.MakeWidget(vexiq_state.VexDeviceType.bumper,"Forwards",(e,t,i)=>{this.scene.SetAnchorLit(this.scene.ButtonBack,"buttonback",i),this.scene.SetAnchorLit(this.scene.BigButtonBack,"bigbuttonback",i),this.animate_frame=!0}),this._forwards=this.MakeWidget(vexiq_state.VexDeviceType.bumper,"Backwards",(e,t,i)=>
1{this.scene.SetAnchorLit(this.scene.ButtonFore,"buttonfore",i),this.animate_frame=!0}),this._left=this.MakeWidget(vexiq_state.VexDeviceType.bumper,"Left",(e,t,i)=>{this.scene.SetAnchorLit(this.scene.ButtonLeft,"buttonleft",i),this.animate_frame=!0}),this._right=this.MakeWidget(vexiq_state.VexDeviceType.bumper,"Right",(e,t,i)=>{this.scene.SetAnchorLit(this.scene.ButtonRight,"buttonright",i),this.scene.SetAnchorLit(this.scene.BigButtonRight,"bigbuttonright",i),this.animate_frame=!0}),this._coinSlot=this.MakeWidget(vexiq_state.VexDeviceType.bumper,"CoinSlot",(e,t,i)=>{this.scene.SetAnchorLit(this.scene.Model_CoinSlot,"CoinSlot",i),this.animate_frame=!0,i&&setTimeout(()=>{this._coinSlot.setValue(!1)},500)}),this._grab=this.MakeWidget(vexiq_state.VexDeviceType.bumper,"Grab",(e,t,i)=>{this.scene.SetAnchorLit(this.scene.Model_Hand,"Hand",i),this.animate_frame=!0}),this._axis1=this.MakeWidget(vexiq_state.VexDeviceType.motor,"MoveY"),this._axis2=this.MakeWidget(vexiq_state.VexDeviceType.motor,"MoveX"),this._axis3=this.MakeWidget(vexiq_state.VexDeviceType.motor,"Extension"),this._claw=this.MakeWidget(vexiq_state.VexDeviceType.motor,"Claw"),this.EndMakeWidget();var i=(e,t)=>{switch(e.keyCode){case 38:this._backwards.setValue(t);break;case 40:this._forwards.setValue(t);break;case 37:this._left.setValue(t);break;case 39:this._right.setValue(t)}};this.dom.addEventListener("keydown",e=>i(e,!0)),this.dom.addEventListener("keyup",e=>i(e,!1)),this.dom.addEventListener("blur",e=>{this._backwards.setValue(!1),this._forwards.setValue(!1),this._left.setValue(!1),this._right.setValue(!1)});var s=this;return jQuery("#lbFlowolMimicOption").show(),jQuery("#txtFlowolMimicOption").text("Use four buttons"),jQuery("#cbFlowolMimicOption").change((function(){this.checked?(s.UseFourButtons(),s.Options="four"):(s.UseTwoButtons(),s.Options="two"),s.scene.UpdateClickableObjects(),s.animate_frame=!0})),t.then(()=>{this._teddyBears[0]=new TeddyBear(.35,.3,this.scene.Model_BlueBear),this._teddyBears[1]=new TeddyBear(-.36,-.25,this.scene.Model_BrownBear),this._teddyBears[2]=new TeddyBear(.45,-.4,this.scene.Model_PinkBear),this._teddyBears[3]=new TeddyBear(-.1,-.1,this.scene.Model_GreenBear),this._teddyBears[4]=new TeddyBear(0,-.35,this.scene.Model_YellowBear),this.HookupLabel(this.scene.In1,this._backwards),this.HookupLabel(this.scene.In2,this._forwards),this.HookupLabel(this.scene.In3,this._left),this.HookupLabel(this.scene.In4,this._right),this.HookupLabel(this.scene.In5,this._coinSlot),this.HookupLabel(this.scene.In6,this._grab),this.HookupLabel(this.scene.MotA,this._axis1),this.HookupLabel(this.scene.MotB,this._axis2),this.HookupLabel(this.scene.MotC,this._axis3),this.HookupLabel(this.scene.MotD,this._claw),"four"==this.Options?(this.UseFourButtons(),jQuery("#cbFlowolMimicOption").prop("checked",!0)):this.UseTwoButtons()})}UseTwoButtons(){this._forwards.hidden=!0,this._left.hidden=!0,this.scene.ButtonBack.visible=!1,this.scene.ButtonF
1ore.visible=!1,this.scene.ButtonLeft.visible=!1,this.scene.ButtonRight.visible=!1,this.scene.ExtraLabelContainer.visible=!1,this.scene.BigButtonBack.visible=!0,this.scene.BigButtonRight.visible=!0}UseFourButtons(){this._forwards.hidden=!1,this._left.hidden=!1,this.scene.ButtonBack.visible=!0,this.scene.ButtonFore.visible=!0,this.scene.ButtonLeft.visible=!0,this.scene.ButtonRight.visible=!0,this.scene.ExtraLabelContainer.visible=!0,this.scene.BigButtonBack.visible=!1,this.scene.BigButtonRight.visible=!1}Reset(){super.Reset(),this._backwards.setValue(!1),this._forwards.setValue(!1),this._left.setValue(!1),this._right.setValue(!1),this._coinSlot.setValue(!1),this._grab.setValue(!1),this._teddyBears.forEach(e=>{e.Reset()})}mouseDownHandler(e,t,i,s){i==this.scene.ButtonBack||i==this.scene.BigButtonBack?(this._backwards.setValue(!0),this._inputClicked=this._backwards):i==this.scene.ButtonFore?(this._forwards.setValue(!0),this._inputClicked=this._forwards):i==this.scene.ButtonLeft?(this._left.setValue(!0),this._inputClicked=this._left):i==this.scene.ButtonRight||i==this.scene.BigButtonRight?(this._right.setValue(!0),this._inputClicked=this._right):i==this.scene.CoinSlot&&this._coinSlot.setValue(!0)}mouseUpHandler(e,t){null!=this._inputClicked&&(this._inputClicked.setValue(!1),this._inputClicked=null)}MimicMillisecondTick(){this.TickLimitedMotor(this._axis1,"JibZ",-1/15,-3.3,4.3),this.TickLimitedMotor(this._axis2,"JibX",1/15,-4.5,5),this.TickLimitedMotor(this._axis3,"Extension",.015,.7,2.4),this.TickLimitedMotor(this._claw,"Gripper",.45,-19.2,-9),this.ProcessBears()&&(this.animate_frame=!0)}ProcessBears(){var e=!1;return this._teddyBears.forEach(t=>{null!=t&&t.OnTick(this.scene.JibZ,this.scene.JibX,this.scene.Extension,this.scene.Gripper,this._grab)&&(e=!0)}),e}render(){this._teddyBears.forEach(e=>{null!=e&&e.BeforeRender(this.scene.DrawGrabbedBear,this.scene.DrawAvailableBears)}),super.render()}}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.