Spaces:
Running
Running
File size: 25,352 Bytes
03b7287 |
1 |
var sceneScaffolder=pc.createScript("sceneScaffolder");sceneScaffolder.prototype.initialize=function(){var e=this.app,t=e.root.findByName("Camera");t&&t.destroy();var o=e.root.findByName("Light");o&&o.destroy();var a=new pc.Entity("SurgeonCamera");a.addComponent("camera",{clearColor:new pc.Color(.95,.98,1),nearClip:.1,farClip:100,fov:60}),a.setPosition(0,1.7,6.5),a.addComponent("script"),a.script.create("cameraController"),a.script.create("interactionController"),e.root.addChild(a),this.createCrosshairUI(e);var n=new pc.Entity("MainSurgicalLight");n.addComponent("light",{type:"spot",color:new pc.Color(1,.98,.92),intensity:3,range:15,innerConeAngle:15,outerConeAngle:35,castShadows:!0,shadowBias:.1,shadowDistance:20,shadowResolution:2048}),n.addComponent("render",{type:"box"}),n.setLocalScale(.5,.2,.5),n.addComponent("collision",{type:"box"}),n.addComponent("rigidbody",{type:"static"}),n.setPosition(0,4,0),n.setEulerAngles(90,0,0),e.root.addChild(n);var d=new pc.Entity("SecondarySurgicalLight");d.addComponent("light",{type:"spot",color:new pc.Color(1,.98,.92),intensity:2.5,range:12,innerConeAngle:20,outerConeAngle:40,castShadows:!0,shadowBias:.1}),d.setPosition(-1.5,3.8,-.5),d.setEulerAngles(75,15,0),e.root.addChild(d);var i=new pc.Entity("AmbientRoomLight");i.addComponent("light",{type:"directional",color:new pc.Color(.9,.95,1),intensity:.4,castShadows:!1}),i.setEulerAngles(30,45,0),e.root.addChild(i);var s=new pc.Entity("SterileFloor"),r=new pc.StandardMaterial;r.diffuse=new pc.Color(.92,.95,.98),r.metalness=.1,r.gloss=.8,r.useMetalness=!0,r.update(),s.addComponent("render",{type:"plane",material:r,receiveShadows:!0,castShadows:!1}),s.setLocalScale(20,1,15),e.root.addChild(s),this.createWall(e,"BackWall",0,2.5,-7.5,20,5,.2,new pc.Color(.95,.97,1)),this.createWall(e,"FrontWall",0,2.5,7.5,20,5,.2,new pc.Color(.95,.97,1)),this.createWall(e,"LeftWall",-10,2.5,0,.2,5,15,new pc.Color(.95,.97,1)),this.createWall(e,"RightWall",10,2.5,0,.2,5,15,new pc.Color(.95,.97,1));var l=new pc.Entity("OperatingTableBase"),c=new pc.StandardMaterial;c.diffuse=new pc.Color(.8,.8,.85),c.metalness=.7,c.gloss=.6,c.useMetalness=!0,c.update(),l.addComponent("render",{type:"cylinder",material:c,castShadows:!0,receiveShadows:!0}),l.setLocalScale(.8,.7,.8),l.setPosition(0,.35,0),e.root.addChild(l);var p=new pc.Entity("OperatingTableSurface"),w=new pc.StandardMaterial;w.diffuse=new pc.Color(.9,.92,.95),w.metalness=.2,w.gloss=.9,w.useMetalness=!0,w.update(),p.addComponent("render",{type:"box",material:w,castShadows:!0,receiveShadows:!0}),p.setLocalScale(2.2,.1,.8),p.setPosition(0,.75,0),p.addComponent("collision",{type:"box",halfExtents:new pc.Vec3(1.1,.05,.4)}),p.addComponent("rigidbody",{type:"static"}),e.root.addChild(p);var C=new pc.Entity("AnesthesiaMachine"),h=new pc.StandardMaterial;h.diffuse=new pc.Color(.7,.75,.8),h.metalness=.8,h.useMetalness=!0,h.update(),C.addComponent("render",{type:"box",material:h,castShadows:!0,receiveShadows:!0}),C.setLocalScale(1.2,1.8,.8),C.setPosition(-4,.9,2),e.root.addChild(C);var m=new pc.Entity("InstrumentTable"),y=new pc.StandardMaterial;y.diffuse=new pc.Color(.85,.87,.9),y.metalness=.6,y.gloss=.8,y.useMetalness=!0,y.update(),m.addComponent("render",{type:"box",material:y,castShadows:!0,receiveShadows:!0}),m.setLocalScale(1.5,1.2,.8),m.setPosition(3,.6,-1),e.root.addChild(m);var S=new pc.Entity("XRayViewer"),u=new pc.StandardMaterial;u.diffuse=new pc.Color(.1,.1,.12),u.metalness=.9,u.useMetalness=!0,u.update(),S.addComponent("render",{type:"box",material:u,castShadows:!0,receiveShadows:!0}),S.setLocalScale(1.8,1.2,.1),S.setPosition(-4,2.5,-6),e.root.addChild(S);var g=new pc.Entity("XRayScreen"),f=new pc.StandardMaterial;f.diffuse=new pc.Color(.9,.95,1),f.emissive=new pc.Color(.3,.35,.4),f.update(),g.addComponent("render",{type:"box",material:f,castShadows:!1,receiveShadows:!1}),g.addComponent("collision",{type:"box"}),g.addComponent("rigidbody",{type:"static"}),g.setLocalScale(1.6,1,.05),g.setPosition(-4,2.5,-5.9),e.root.addChild(g);var v=new pc.Entity("SurgicalLightArm1"),M=new pc.StandardMaterial;M.diffuse=new pc.Color(.9,.9,.92),M.metalness=.8,M.useMetalness=!0,M.update(),v.addComponent("render",{type:"cylinder",material:M,castShadows:!0,receiveShadows:!0}),v.setLocalScale(.15,2,.15),v.setPosition(0,3,0),e.root.addChild(v);var E=new pc.Entity("PatientBody"),b=new pc.StandardMaterial;b.diffuse=new pc.Color(.95,.85,.75),b.metalness=.1,b.gloss=.2,b.useMetalness=!0,b.update(),E.addComponent("render",{type:"box",material:b,castShadows:!0,receiveShadows:!0}),E.addComponent("collision",{type:"box"}),E.addComponent("rigidbody",{type:"static"}),E.setLocalScale(.6,.3,1.8),E.setPosition(0,.95,0),e.root.addChild(E);var L=new pc.Entity("SurgicalDrape"),x=new pc.StandardMaterial;x.diffuse=new pc.Color(.8,.9,.95),x.metalness=0,x.gloss=.1,x.update(),L.addComponent("render",{type:"box",material:x,castShadows:!0,receiveShadows:!0}),L.setLocalScale(.8,.05,2),L.setPosition(0,1.15,0),e.root.addChild(L);var P=new pc.Entity("CArmXRayMachine"),A=new pc.StandardMaterial;A.diffuse=new pc.Color(.75,.78,.82),A.metalness=.7,A.useMetalness=!0,A.update(),P.addComponent("render",{type:"box",material:A,castShadows:!0,receiveShadows:!0}),P.setLocalScale(1,2.2,1.5),P.setPosition(5,1.1,3),P.addComponent("collision",{type:"box",halfExtents:new pc.Vec3(.5,1.1,.75)}),P.addComponent("rigidbody",{type:"static"}),e.root.addChild(P);var B=new pc.Entity("PowerToolsStation"),V=new pc.StandardMaterial;V.diffuse=new pc.Color(.6,.65,.7),V.metalness=.8,V.useMetalness=!0,V.update(),B.addComponent("render",{type:"box",material:V,castShadows:!0,receiveShadows:!0}),B.setLocalScale(.8,1.5,.6),B.setPosition(-3.5,.75,-2.5),e.root.addChild(B);var T=new pc.Entity("BoneCementMixer"),O=new pc.StandardMaterial;O.diffuse=new pc.Color(.85,.85,.88),O.metalness=.6,O.useMetalness=!0,O.update(),T.addComponent("render",{type:"cylinder",material:O,castShadows:!0,receiveShadows:!0}),T.setLocalScale(.4,.8,.4),T.setPosition(2.5,.4,2.5),e.root.addChild(T),this.createVitalSignsMonitor(e,new pc.Vec3(-2,0,3)),console.log("Orthopaedic Operating Theatre scaffolded successfully!"),console.log("Orthopaedic Operating Theatre scaffolded successfully!"),console.log("Environment includes:"),console.log("- Sterile room with clinical lighting"),console.log("- Central operating table with patient"),console.log("- Anesthesia machine and monitoring equipment"),console.log("- X-ray viewer and C-arm machine"),console.log("- Surgical instrument tables"),console.log("- Orthopaedic-specific equipment (drills, cement mixer)"),console.log("- Proper surgical lighting setup")},sceneScaffolder.prototype.createWall=function(e,t,o,a,n,d,i,s,r){var l=new pc.Entity(t),c=new pc.StandardMaterial;c.diffuse=r,c.metalness=.1,c.gloss=.3,c.useMetalness=!0,c.update(),l.addComponent("render",{type:"box",material:c,castShadows:!1,receiveShadows:!0}),l.setPosition(o,a,n),l.setLocalScale(d,i,s),e.root.addChild(l)},sceneScaffolder.prototype.createVitalSignsMonitor=function(e,t){var o=new pc.Entity("VitalSignsMonitor");o.setPosition(t);var a=new pc.Entity("MonitorCartBody"),n=new pc.StandardMaterial;n.diffuse=new pc.Color(.8,.82,.85),n.useMetalness=!0,n.metalness=.4,n.gloss=.5,n.update(),a.addComponent("render",{type:"box",material:n}),a.setLocalScale(.6,1,.5),a.setLocalPosition(0,.5,0),a.addComponent("collision",{type:"box"}),a.addComponent("rigidbody",{type:"static"}),o.addChild(a);var d=new pc.Entity("MonitorScreen"),i=new pc.StandardMaterial;i.diffuse.set(.05,.05,.1),i.emissive.set(.02,.02,.05),i.update(),d.addComponent("render",{type:"box",material:i}),d.setLocalScale(.58,.45,.03),d.setLocalPosition(0,.7,.27),d.addComponent("collision",{type:"box"}),d.addComponent("rigidbody",{type:"static"}),o.addChild(d);var s=new pc.Entity("MonitorBase");return s.addComponent("render",{type:"box",material:n}),s.setLocalScale(.7,.05,.7),s.setLocalPosition(0,.025,0),o.addChild(s),e.root.addChild(o),o},sceneScaffolder.prototype.createCrosshairUI=function(e){var t=new pc.Entity("UIScreen");t.addComponent("screen",{referenceResolution:new pc.Vec2(1280,720),scaleBlend:.5,scaleMode:pc.SCALEMODE_BLEND,screenSpace:!0}),e.root.addChild(t);var o=new pc.Entity("CrosshairOutline");o.addComponent("image",{type:pc.ELEMENTTYPE_IMAGE,anchor:new pc.Vec4(.5,.5,.5,.5),pivot:new pc.Vec2(.5,.5),width:6,height:6,color:new pc.Color(0,0,0,.5)}),t.addChild(o);var a=new pc.Entity("CrosshairDot");a.addComponent("image",{type:pc.ELEMENTTYPE_IMAGE,anchor:new pc.Vec4(.5,.5,.5,.5),pivot:new pc.Vec2(.5,.5),width:2,height:2,color:new pc.Color(1,1,1,.8)}),t.addChild(a),console.log("Compound Crosshair UI created.")};var CameraController=pc.createScript("cameraController");CameraController.attributes.add("mouseSensitivity",{type:"number",default:.5,title:"Mouse Sensitivity (Unused for Q/E)"}),CameraController.attributes.add("keyboardRotationSpeed",{type:"number",default:90,title:"Keyboard Rotation Speed"}),CameraController.attributes.add("movementSpeed",{type:"number",default:5,title:"Movement Speed"}),CameraController.attributes.add("pitchLimit",{type:"number",default:89,title:"Pitch Angle Limit"}),CameraController.prototype.initialize=function(){console.log("CameraController: Initializing script instance:",this),this.eulers=new pc.Vec3;var e=this.entity.getEulerAngles();this.eulers.set(e.x,e.y,e.z),this.pitch=this.eulers.x,this.yaw=this.eulers.y,this.moveDirection=new pc.Vec3,this.isPointerActuallyLocked=!1,console.log("CameraController initialized. Initial Pitch: "+this.pitch+", Initial Yaw: "+this.yaw),console.log("To control camera: WASD to move, Q/E to rotate left/right.")},CameraController.prototype.update=function(e){var t=this.app,i=this.movementSpeed,r=this.entity.forward,a=this.entity.right,o=0,s=0;if(t.keyboard.isPressed(pc.KEY_W)&&(s-=1),t.keyboard.isPressed(pc.KEY_S)&&(s+=1),t.keyboard.isPressed(pc.KEY_A)&&(o-=1),t.keyboard.isPressed(pc.KEY_D)&&(o+=1),0!==o||0!==s){this.moveDirection.set(0,0,0);var l=r.clone().mulScalar(-s),n=a.clone().mulScalar(o);this.moveDirection.add(l).add(n),this.moveDirection.lengthSq()>0&&(this.moveDirection.normalize().mulScalar(i*e),this.entity.translateLocal(this.moveDirection))}var c=0;t.keyboard.isPressed(pc.KEY_Q)&&(c=1),t.keyboard.isPressed(pc.KEY_E)&&(c=-1),this.yaw+=c*this.keyboardRotationSpeed*e;var d=0;t.keyboard.isPressed(pc.KEY_UP)&&(d=-1),t.keyboard.isPressed(pc.KEY_DOWN)&&(d=1),this.pitch+=d*this.keyboardRotationSpeed*e,this.pitch=pc.math.clamp(this.pitch,-this.pitchLimit,this.pitchLimit),this.entity.setLocalEulerAngles(this.pitch,this.yaw,0)};var SceneScaffolder=pc.createScript("sceneScaffolder");SceneScaffolder.prototype.initialize=function(){var e=this.app,a=e.root.findByName("Camera");a&&a.destroy();var o=e.root.findByName("Light");o&&o.destroy();var t=new pc.Entity("MyControllableCamera");t.addComponent("camera",{clearColor:new pc.Color(.1,.1,.1),nearClip:.1,farClip:1e3,fov:45}),t.setPosition(0,1.6,5),t.addComponent("script"),t.script.create("cameraController"),e.root.addChild(t);var n=new pc.Entity("MyLight");n.addComponent("light",{type:"directional",color:new pc.Color(1,1,1),intensity:1,castShadows:!0,shadowBias:.2,shadowDistance:50,normalOffsetBias:.05,shadowResolution:2048}),n.setEulerAngles(45,30,0),e.root.addChild(n);var r=new pc.Entity("GroundPlane"),d=new pc.StandardMaterial;d.diffuse=new pc.Color(.5,.5,.5),d.update(),r.addComponent("render",{type:"plane",material:d,castShadows:!1,receiveShadows:!0}),r.setLocalScale(50,1,50),e.root.addChild(r);var i=new pc.Entity("MyCube"),s=new pc.StandardMaterial;s.diffuse=new pc.Color(1,0,0),s.shininess=50,s.update(),i.addComponent("render",{type:"box",material:s,castShadows:!0,receiveShadows:!0}),i.setPosition(0,1,0),e.root.addChild(i);var l=new pc.Entity("MySphere"),c=new pc.StandardMaterial;c.diffuse=new pc.Color(0,0,1),c.shininess=70,c.metalness=.3,c.useMetalness=!0,c.update(),l.addComponent("render",{type:"sphere",material:c,castShadows:!0,receiveShadows:!0}),l.setPosition(3,1.5,2),e.root.addChild(l),console.log("Controllable 3D environment scaffolded from code!")};var OrthopaedicTheatreScaffolder=pc.createScript("orthopaedicTheatreScaffolder");OrthopaedicTheatreScaffolder.prototype.initialize=function(){var e=this.app,a=e.root.findByName("Camera");a&&a.destroy();var t=e.root.findByName("Light");t&&t.destroy();var o=new pc.Entity("SurgeonCamera");o.addComponent("camera",{clearColor:new pc.Color(.95,.98,1),nearClip:.1,farClip:100,fov:60}),o.setPosition(0,1.7,8),o.addComponent("script"),o.script.create("cameraController"),e.root.addChild(o);var n=new pc.Entity("MainSurgicalLight");n.addComponent("light",{type:"spot",color:new pc.Color(1,.98,.92),intensity:3,range:15,innerConeAngle:15,outerConeAngle:35,castShadows:!0,shadowBias:.1,shadowDistance:20,shadowResolution:2048}),n.setPosition(0,4,0),n.setEulerAngles(90,0,0),e.root.addChild(n);var s=new pc.Entity("SecondarySurgicalLight");s.addComponent("light",{type:"spot",color:new pc.Color(1,.98,.92),intensity:2.5,range:12,innerConeAngle:20,outerConeAngle:40,castShadows:!0,shadowBias:.1}),s.setPosition(-1.5,3.8,-.5),s.setEulerAngles(75,15,0),e.root.addChild(s);var r=new pc.Entity("AmbientRoomLight");r.addComponent("light",{type:"directional",color:new pc.Color(.9,.95,1),intensity:.4,castShadows:!1}),r.setEulerAngles(30,45,0),e.root.addChild(r);var d=new pc.Entity("SterileFloor"),l=new pc.StandardMaterial;l.diffuse=new pc.Color(.92,.95,.98),l.metalness=.1,l.gloss=.8,l.useMetalness=!0,l.update(),d.addComponent("render",{type:"plane",material:l,receiveShadows:!0,castShadows:!1}),d.setLocalScale(20,1,15),e.root.addChild(d),this.createWall(e,"BackWall",0,2.5,-7.5,20,5,.2,new pc.Color(.95,.97,1)),this.createWall(e,"FrontWall",0,2.5,7.5,20,5,.2,new pc.Color(.95,.97,1)),this.createWall(e,"LeftWall",-10,2.5,0,.2,5,15,new pc.Color(.95,.97,1)),this.createWall(e,"RightWall",10,2.5,0,.2,5,15,new pc.Color(.95,.97,1));var i=new pc.Entity("OperatingTableBase"),c=new pc.StandardMaterial;c.diffuse=new pc.Color(.8,.8,.85),c.metalness=.7,c.gloss=.6,c.useMetalness=!0,c.update(),i.addComponent("render",{type:"cylinder",material:c,castShadows:!0,receiveShadows:!0}),i.setLocalScale(.8,.7,.8),i.setPosition(0,.35,0),e.root.addChild(i);var p=new pc.Entity("OperatingTableSurface"),w=new pc.StandardMaterial;w.diffuse=new pc.Color(.9,.92,.95),w.metalness=.2,w.gloss=.9,w.useMetalness=!0,w.update(),p.addComponent("render",{type:"box",material:w,castShadows:!0,receiveShadows:!0}),p.setLocalScale(2.2,.1,.8),p.setPosition(0,.75,0),e.root.addChild(p);var h=new pc.Entity("AnesthesiaMachine"),S=new pc.StandardMaterial;S.diffuse=new pc.Color(.7,.75,.8),S.metalness=.8,S.useMetalness=!0,S.update(),h.addComponent("render",{type:"box",material:S,castShadows:!0,receiveShadows:!0}),h.setLocalScale(1.2,1.8,.8),h.setPosition(-4,.9,2),e.root.addChild(h);var C=new pc.Entity("InstrumentTable"),m=new pc.StandardMaterial;m.diffuse=new pc.Color(.85,.87,.9),m.metalness=.6,m.gloss=.8,m.useMetalness=!0,m.update(),C.addComponent("render",{type:"box",material:m,castShadows:!0,receiveShadows:!0}),C.setLocalScale(1.5,1.2,.8),C.setPosition(3,.6,-1),e.root.addChild(C);var u=new pc.Entity("XRayViewer"),y=new pc.StandardMaterial;y.diffuse=new pc.Color(.1,.1,.12),y.metalness=.9,y.useMetalness=!0,y.update(),u.addComponent("render",{type:"box",material:y,castShadows:!0,receiveShadows:!0}),u.setLocalScale(1.8,1.2,.1),u.setPosition(-4,2.5,-6),e.root.addChild(u);var g=new pc.Entity("XRayScreen"),f=new pc.StandardMaterial;f.diffuse=new pc.Color(.9,.95,1),f.emissive=new pc.Color(.3,.35,.4),f.update(),g.addComponent("render",{type:"box",material:f,castShadows:!1,receiveShadows:!1}),g.setLocalScale(1.6,1,.05),g.setPosition(-4,2.5,-5.9),e.root.addChild(g);var v=new pc.Entity("SurgicalLightArm1"),M=new pc.StandardMaterial;M.diffuse=new pc.Color(.9,.9,.92),M.metalness=.8,M.useMetalness=!0,M.update(),v.addComponent("render",{type:"cylinder",material:M,castShadows:!0,receiveShadows:!0}),v.setLocalScale(.15,2,.15),v.setPosition(0,3,0),e.root.addChild(v);var E=new pc.Entity("PatientBody"),L=new pc.StandardMaterial;L.diffuse=new pc.Color(.95,.85,.75),L.metalness=.1,L.gloss=.2,L.useMetalness=!0,L.update(),E.addComponent("render",{type:"box",material:L,castShadows:!0,receiveShadows:!0}),E.setLocalScale(.6,.3,1.8),E.setPosition(0,.95,0),e.root.addChild(E);var P=new pc.Entity("SurgicalDrape"),b=new pc.StandardMaterial;b.diffuse=new pc.Color(.8,.9,.95),b.metalness=0,b.gloss=.1,b.update(),P.addComponent("render",{type:"box",material:b,castShadows:!0,receiveShadows:!0}),P.setLocalScale(.8,.05,2),P.setPosition(0,1.15,0),e.root.addChild(P);var x=new pc.Entity("CArmXRayMachine"),A=new pc.StandardMaterial;A.diffuse=new pc.Color(.75,.78,.82),A.metalness=.7,A.useMetalness=!0,A.update(),x.addComponent("render",{type:"box",material:A,castShadows:!0,receiveShadows:!0}),x.setLocalScale(1,2.2,1.5),x.setPosition(5,1.1,3),e.root.addChild(x);var T=new pc.Entity("PowerToolsStation"),W=new pc.StandardMaterial;W.diffuse=new pc.Color(.6,.65,.7),W.metalness=.8,W.useMetalness=!0,W.update(),T.addComponent("render",{type:"box",material:W,castShadows:!0,receiveShadows:!0}),T.setLocalScale(.8,1.5,.6),T.setPosition(-3.5,.75,-2.5),e.root.addChild(T);var B=new pc.Entity("BoneCementMixer"),O=new pc.StandardMaterial;O.diffuse=new pc.Color(.85,.85,.88),O.metalness=.6,O.useMetalness=!0,O.update(),B.addComponent("render",{type:"cylinder",material:O,castShadows:!0,receiveShadows:!0}),B.setLocalScale(.4,.8,.4),B.setPosition(2.5,.4,2.5),e.root.addChild(B),console.log("Orthopaedic Operating Theatre scaffolded successfully!"),console.log("Environment includes:"),console.log("- Sterile room with clinical lighting"),console.log("- Central operating table with patient"),console.log("- Anesthesia machine and monitoring equipment"),console.log("- X-ray viewer and C-arm machine"),console.log("- Surgical instrument tables"),console.log("- Orthopaedic-specific equipment (drills, cement mixer)"),console.log("- Proper surgical lighting setup")},OrthopaedicTheatreScaffolder.prototype.createWall=function(e,a,t,o,n,s,r,d,l){var i=new pc.Entity(a),c=new pc.StandardMaterial;c.diffuse=l,c.metalness=.1,c.gloss=.3,c.useMetalness=!0,c.update(),i.addComponent("render",{type:"box",material:c,castShadows:!1,receiveShadows:!0}),i.setPosition(t,o,n),i.setLocalScale(s,r,d),e.root.addChild(i)};var InteractionController=pc.createScript("interactionController");InteractionController.attributes.add("interactionDistance",{type:"number",default:5,title:"Interaction Distance"}),InteractionController.attributes.add("highlightColor",{type:"rgba",default:[.4,.4,0,1],title:"Highlight Color (Emissive)"}),InteractionController.prototype.initialize=function(){this.highlightedEntity=null,this.originalEmissive=new pc.Color;const t=this.app.scene.layers.getLayerById(pc.LAYERID_IMMEDIATE),i=this.entity.camera,e=i.layers;-1===e.indexOf(t.id)&&(i.layers=e.concat(t.id)),console.log("Interaction Controller is active. Look at an object to highlight it, press 'F' to interact.")},InteractionController.prototype.update=function(t){if("undefined"!=typeof Ammo){var i=this.entity.getPosition(),e=(new pc.Vec3).copy(this.entity.forward).mulScalar(this.interactionDistance).add(i),n=this.app.systems.rigidbody.raycastFirst(i,e),o=n?n.entity:null;o!==this.highlightedEntity&&(this.highlightedEntity&&this.setHighlight(this.highlightedEntity,!1),o&&this.setHighlight(o,!0),this.highlightedEntity=o),this.app.keyboard.wasPressed(pc.KEY_F)&&this.highlightedEntity&&this.interactWith(this.highlightedEntity)}},InteractionController.prototype.interactWith=function(t){console.log("Interacting with:",t.name);var i=t;if(t.parent&&"VitalSignsMonitor"===t.parent.name&&(i=t.parent),"VitalSignsMonitor"===i.name){var e=i.findByName("MonitorScreen");if(e){void 0===e.isOn&&(e.isOn=!1),e.isOn=!e.isOn;var n=e.render.material;n.emissive.set(e.isOn?.5:0,e.isOn?.8:0,e.isOn?1:0),n.update(),console.log("Monitor screen state set to:",e.isOn?"ON":"OFF")}}else if("PatientBody"===t.name){var o=this.app.root.findByName("SurgicalDrape");o&&(o.enabled=!o.enabled,console.log("Surgical drape visibility set to:",o.enabled))}else if("MainSurgicalLight"===t.name)void 0===t.isAdjusted&&(t.isAdjusted=!1),t.isAdjusted=!t.isAdjusted,t.isAdjusted?(t.setEulerAngles(75,20,0),console.log("Surgical light adjusted.")):(t.setEulerAngles(90,0,0),console.log("Surgical light reset."));else if("XRayScreen"===t.name){void 0===t.colorIndex&&(t.colorIndex=0);var r=[new pc.Color(.9,.95,1),new pc.Color(.9,1,.9),new pc.Color(1,.9,.9)];t.colorIndex=(t.colorIndex+1)%r.length;var s=t.render.material;s.diffuse.copy(r[t.colorIndex]),s.update(),console.log("X-Ray screen color changed to index:",t.colorIndex)}},InteractionController.prototype.setHighlight=function(t,i){if((!t||"MonitorScreen"!==t.name)&&t&&t.render&&t.render.material){var e=t.render.material;i?(this.originalEmissive.copy(e.emissive),e.emissive.set(this.highlightColor.r,this.highlightColor.g,this.highlightColor.b)):e.emissive.copy(this.originalEmissive),e.update()}};var GameManager=pc.createScript("gameManager");GameManager.attributes.add("gameData",{type:"asset",assetType:"text",title:"Game Data JSON"}),GameManager.prototype.initialize=function(){this.storyData=null,this.currentLocation="tavern",this.currentRoom="start",this.isUiReady=!1,this.app.on("ui:choiceMade",this.onChoiceMade,this),this.app.on("ui:ready",this.onUiReady,this),this.gameData&&this.gameData.resource?(this.storyData=JSON.parse(this.gameData.resource),console.log("GameManager: Data loaded and parsed."),this.isUiReady&&this.displayCurrentState()):console.error("GameManager: Game Data JSON asset is not linked or has not loaded yet.")},GameManager.prototype.onUiReady=function(){console.log("GameManager: Received 'ui:ready' event."),this.isUiReady=!0,this.storyData&&this.displayCurrentState()},GameManager.prototype.displayCurrentState=function(){if(this.storyData&&this.isUiReady){var t=this.storyData[this.currentLocation][this.currentRoom];t?(console.log("GameManager: Firing 'story:display' event for room:",this.currentRoom),this.app.fire("story:display",{description:t.description,choices:t.choices})):console.error("GameManager: Could not find room data for:",this.currentLocation,this.currentRoom)}},GameManager.prototype.onChoiceMade=function(t){if(this.storyData){var a=this.storyData[this.currentLocation][this.currentRoom].transitions[t];if(a){if(a.includes("_")){var e=a.split("_");this.currentLocation=e[0],this.currentRoom=e[1]}else this.currentRoom=a;this.displayCurrentState()}else console.error("GameManager: No transition found for choice:",t)}};var UiController=pc.createScript("uiController");UiController.attributes.add("descriptionElement",{type:"entity",title:"Description Text Entity"}),UiController.attributes.add("choicesContainer",{type:"entity",title:"Choices Container Entity"}),UiController.attributes.add("choiceButtonTemplate",{type:"asset",assetType:"template",title:"Choice Button Template"}),UiController.prototype.initialize=function(){this.app.on("story:display",this.onDisplay,this),console.log("UiController: Initialized and listening for 'story:display' events."),this.validateSetup(),this.app.fire("ui:ready"),console.log("UiController: Fired 'ui:ready' event.")},UiController.prototype.validateSetup=function(){console.log("UiController: Validating setup..."),this.descriptionElement||console.error("UiController VALIDATION ERROR: 'Description Text Entity' is not assigned in the editor!"),this.choicesContainer||console.error("UiController VALIDATION ERROR: 'Choices Container Entity' is not assigned in the editor!"),this.choiceButtonTemplate?"template"!==this.choiceButtonTemplate.type&&console.error("UiController VALIDATION ERROR: The asset assigned to 'Choice Button Template' must be a Template asset."):console.error("UiController VALIDATION ERROR: 'Choice Button Template' asset is not assigned in the editor!")},UiController.prototype.onDisplay=function(t){console.log("UiController: Received 'story:display' event."),t?(this.updateDescription(t.description),this.updateChoices(t.choices)):console.error("UiController: Received event but data was null or undefined.")},UiController.prototype.updateDescription=function(t){this.descriptionElement&&this.descriptionElement.element&&(this.descriptionElement.element.text=t||"Description text is missing.")},UiController.prototype.updateChoices=function(t){if(this.choicesContainer){for(;this.choicesContainer.children.length>0;)this.choicesContainer.children[0].destroy();t&&t.length>0&&t.forEach((function(t,e){this.createChoiceButton(t,e)}),this)}},UiController.prototype.createChoiceButton=function(t,e){if(this.choiceButtonTemplate&&this.choiceButtonTemplate.resource){var i=this.choiceButtonTemplate.resource.instantiate();this.choicesContainer.addChild(i);var o=i.element,n=e%2==0,r=10+50*Math.floor(e/2);o.width=180,o.height=40,n?(o.anchor=new pc.Vec4(0,1,0,1),o.pivot=new pc.Vec2(0,1),i.setLocalPosition(10,-r,0)):(o.anchor=new pc.Vec4(1,1,1,1),o.pivot=new pc.Vec2(1,1),i.setLocalPosition(-10,-r,0));var s=i.findByName("ButtonText");s&&s.element&&(s.element.text=t),i.button&&i.button.on("click",(function(){this.app.fire("ui:choiceMade",t)}),this)}};var GameAutoLocationDatabase=pc.createScript("gameAutoLocationDatabase");GameAutoLocationDatabase.prototype.initialize=function(){},GameAutoLocationDatabase.prototype.update=function(a){}; |