improved collisions for floor

This commit is contained in:
Leon van Kammen 2023-11-29 19:39:31 +01:00
parent 1291763409
commit e38eea1859
3 changed files with 15 additions and 10 deletions

View file

@ -33,17 +33,16 @@
<a-scene renderer="colorManagement: true; highRefreshRate:true" light="defaultLightsEnabled: false"> <a-scene renderer="colorManagement: true; highRefreshRate:true" light="defaultLightsEnabled: false">
<a-entity id="player"> <a-entity id="player">
<a-entity camera="fov:90" position="0 1.6 0" wasd-controls look-controls id="camera"></a-entity> <a-entity camera="fov:90" position="0 1.6 0" wasd-controls look-controls id="camera"></a-entity>
<a-entity id="left-hand" laser-controls="hand: left" raycaster="objects:.ray" blink-controls="cameraRig:#player; teleportOrigin: #camera; collisionEntities: #floor"> <a-entity id="left-hand" laser-controls="hand: left" raycaster="objects:.ray" blink-controls="cameraRig:#player; teleportOrigin: #camera; collisionEntities: .floor">
<a-entity rotation="-35 0 0" position="0 0.1 0" id="navigator"> <a-entity rotation="-35 0 0" position="0 0.1 0" id="navigator">
<a-entity id="back" xrf-button="label: <; width:0.05; action: history.back()" position="-0.025 0 0" class="ray"></a-entity> <a-entity id="back" xrf-button="label: <; width:0.05; action: history.back()" position="-0.025 0 0" class="ray"></a-entity>
<a-entity id="next" xrf-button="label: >; width:0.05; action: history.forward()" position=" 0.025 0 0" class="ray"></a-entity> <a-entity id="next" xrf-button="label: >; width:0.05; action: history.forward()" position=" 0.025 0 0" class="ray"></a-entity>
</a-entity> </a-entity>
</a-entity> </a-entity>
<a-entity id="right-hand" laser-controls="hand: right" raycaster="objects:.ray" blink-controls="cameraRig:#player; teleportOrigin: #camera; collisionEntities: #floor"></a-entity> <a-entity id="right-hand" laser-controls="hand: right" raycaster="objects:.ray" blink-controls="cameraRig:#player; teleportOrigin: #camera; collisionEntities: .floor"></a-entity>
</a-entity> </a-entity>
<a-entity id="home" xrf="index.glb"></a-entity> <a-entity id="home" xrf="index.glb"></a-entity>
<a-plane id="floor" position="0 0 0" rotation="-90 0 0" width="1000" height="1000" material="visible:false"></a-plane>
</a-scene> </a-scene>
<script> <script>

View file

@ -33,9 +33,15 @@ window.AFRAME.registerComponent('xrf', {
// *TODO* this does not really belong here perhaps // *TODO* this does not really belong here perhaps
let blinkControls = document.querySelector('[blink-controls]') let blinkControls = document.querySelector('[blink-controls]')
if( blinkControls ){ if( blinkControls ){
blinkControls = blinkControls.components['blink-controls'] let els = xrf.getCollisionMeshes()
blinkControls.defaultCollisionMeshes = xrf.getCollisionMeshes() els.map( (mesh) => {
blinkControls.update() mesh.material.visible = false
let el = document.createElement("a-entity")
el.setAttribute("xrf-get", `name: ${mesh.name};reparent:true` )
el.setAttribute("class","floor ray")
$('a-scene').appendChild(el)
})
blinkControls = blinkControls.components['blink-controls'].queryCollisionEntities()
} }
}) })

View file

@ -14,7 +14,7 @@ window.AFRAME.registerComponent('xrf-get', {
setTimeout( () => { setTimeout( () => {
if( !this.mesh && this.el.className == "ray" ){ if( !this.mesh && this.el.className.match(/ray/) ){
let scene = AFRAME.XRF.scene let scene = AFRAME.XRF.scene
let mesh = this.mesh = scene.getObjectByName(meshname); let mesh = this.mesh = scene.getObjectByName(meshname);
if (!mesh){ if (!mesh){
@ -41,12 +41,12 @@ window.AFRAME.registerComponent('xrf-get', {
} }
this.el.setObject3D('mesh',mesh) this.el.setObject3D('mesh',mesh)
if( !this.el.id ) this.el.setAttribute("id",`xrf-${mesh.name}`) if( !this.el.id ) this.el.setAttribute("id",`xrf-${mesh.name}`)
} }else console.warn("xrf-get ignore: "+JSON.stringify(this.data))
},500) }, evt && evt.timeout ? evt.timeout: 500)
}) })
this.el.emit("update") this.el.emit("update",{timeout:0})
} }