fixes from kevin comments

This commit is contained in:
Diego F. Goberna
2018-11-12 21:13:43 +01:00
parent 97dd2c02a7
commit 652ed0fa7f
6 changed files with 23 additions and 20 deletions

View File

@@ -1,4 +1,4 @@
AFRAME.registerShader('floor-shader', {
AFRAME.registerShader('floorShader', {
schema: {
src: {type: 'map', is: 'uniform'},
normalMap: {type: 'map', is: 'uniform'},

View File

@@ -1,26 +1,29 @@
AFRAME.registerComponent('saber-intersection', {
dependencies: ['raycaster__game'],
init: function () {
this.hiddenIntersection = {x: 999, y: 0, z: 0};
this.saberHit = {
'rightHand': {active: false, position: null, raycaster: null},
'leftHand': {active: false, position: null, raycaster: null}
rightHand: {active: false, position: null, raycaster: null},
leftHand: {active: false, position: null, raycaster: null}
};
this.intersecting = false;
this.saberEnterFunc = this.saberEnter.bind(this);
this.saberLeaveFunc = this.saberLeave.bind(this);
},
pause: function () {
this.el.removeAttribute('raycastable-game');
this.el.removeEventListener('mouseenter', this.saberEnter);
this.el.removeEventListener('mouseleave', this.saberLeave);
this.el.removeEventListener('mouseenter', this.saberEnterFunc);
this.el.removeEventListener('mouseleave', this.saberLeaveFunc);
},
play: function () {
this.el.setAttribute('raycastable-game', '');
this.el.addEventListener('mouseenter', this.saberEnter.bind(this));
this.el.addEventListener('mouseleave', this.saberLeave.bind(this));
this.material = this.el.object3D.children[0].material;
this.saberHit['rightHand'].raycaster = document.getElementById('rightHand').components['raycaster__game'];
this.saberHit['leftHand'].raycaster = document.getElementById('leftHand').components['raycaster__game'];
this.el.addEventListener('mouseenter', this.saberEnterFunc);
this.el.addEventListener('mouseleave', this.saberLeaveFunc);
this.material = this.el.getObject3D('mesh').material;
this.saberHit.rightHand.raycaster = document.getElementById('rightHand').components.raycaster__game;
this.saberHit.leftHand.raycaster = document.getElementById('leftHand').components.raycaster__game;
},
saberEnter: function (evt) {
@@ -31,19 +34,19 @@ AFRAME.registerComponent('saber-intersection', {
saberLeave: function (evt) {
const hand = evt.detail.cursorEl.id;
this.saberHit[hand].active = false;
this.material.uniforms[hand == 'rightHand' ? 'hitRight' : 'hitLeft'].value = {x: 999, y: 0, z: 0};
this.intersecting = this.saberHit['rightHand'].active || this.saberHit['leftHand'].active;
this.material.uniforms[hand == 'rightHand' ? 'hitRight' : 'hitLeft'].value = this.hiddenIntersection;
this.intersecting = this.saberHit.rightHand.active || this.saberHit.leftHand.active;
},
tick: function (time, delta) {
if (this.intersecting) {
var int;
if (this.saberHit['rightHand'].active) {
int = this.saberHit['rightHand'].raycaster.getIntersection(this.el);
if (this.saberHit.rightHand.active) {
int = this.saberHit.rightHand.raycaster.getIntersection(this.el);
if (int) { this.material.uniforms.hitRight.value = int.point; }
}
if (this.saberHit['leftHand'].active) {
int = this.saberHit['leftHand'].raycaster.getIntersection(this.el);
if (this.saberHit.leftHand.active) {
int = this.saberHit.leftHand.raycaster.getIntersection(this.el);
if (int) { this.material.uniforms.hitLeft.value = int.point; }
}
}

View File

@@ -1,5 +1,5 @@
AFRAME.registerShader('wall-shader', {
AFRAME.registerShader('wallShader', {
schema: {
iTime: {type: 'time', is: 'uniform'},
tex: {type: 'map', is: 'uniform'},