diff --git a/src/components/trail.js b/src/components/trail.js index 0aca8bc..6f7c64e 100644 --- a/src/components/trail.js +++ b/src/components/trail.js @@ -1,13 +1,14 @@ AFRAME.registerComponent('trail', { schema: { - color: {type: 'color'} + color: {type: 'color'}, + enabled: {default: false} }, init: function () { var geometry = this.geometry = new THREE.BufferGeometry(); var steps = 10; var maxPoints = this.maxPoints = 12; - var vertices = this.vertices = new Float32Array(36 * maxPoints); + var vertices = this.vertices = new Float32Array(36 * maxPoints); var colors = this.colors = new Float32Array(48 * maxPoints); var bladeColor = this.bladeColor = new THREE.Color(this.data.color); this.bladeColor = { @@ -20,15 +21,15 @@ AFRAME.registerComponent('trail', { this.layers = 0; this.saberTrajectory = [ - {top: {x:-0.5, y: 0, z: 0}, center: {x: 0, y: 0, z: 0}, bottom: {x: 0.5, y: 0, z: 0}}, - {top: {x:-0.5, y: 0.5, z: 0}, center: {x:0, y: 0.5, z: 0}, bottom: {x: 0.5, y: 0.5, z: 0}}, - {top: {x:-0.5, y: 1.0, z: 0}, center: {x:0, y: 1.0, z: 0}, bottom: {x: 0.5, y: 1.0, z: 0}} + {top: new THREE.Vector3(-0.5, 0, 0), center: new THREE.Vector3(0, 0, 0), bottom: new THREE.Vector3(0.5, 0, 0)}, + {top: new THREE.Vector3(-0.5, 0.5, 0), center: new THREE.Vector3(0, 0.5, 0), bottom: new THREE.Vector3(0.5, 0.5, 0)}, + {top: new THREE.Vector3(-0.5, 1.0, 0), center: new THREE.Vector3(0, 1.0, 0), bottom: new THREE.Vector3(0.5, 1.0, 0)} ]; //geometry.setDrawRange(0, 0); geometry.addAttribute('position', new THREE.BufferAttribute(vertices, 3).setDynamic(true)); geometry.addAttribute('vertexColor', new THREE.BufferAttribute(colors, 4).setDynamic(true)); - + var material = new THREE.ShaderMaterial({ side: THREE.DoubleSide, vertexColors: THREE.VertexColors, @@ -295,6 +296,7 @@ AFRAME.registerComponent('trail', { }, tock: function (time, delta) { + if (!this.data.enabled) { return; } this.sampleSaberPosition(); }, @@ -310,7 +312,7 @@ AFRAME.registerComponent('trail', { sample = this.saberTrajectory.shift(); sample.top.set(0, -0.4, 0); sample.center.set(0, 0, 0); - sample.bottom.set(0, 0.4, 0) + sample.bottom.set(0, 0.4, 0); } else { sample = { top: new THREE.Vector3(0, -0.4, 0), @@ -330,4 +332,4 @@ AFRAME.registerComponent('trail', { this.initGeometry(); } -}); \ No newline at end of file +}); diff --git a/src/index.html b/src/index.html index cdd6278..76b6e4a 100644 --- a/src/index.html +++ b/src/index.html @@ -76,6 +76,7 @@ bind__pauser="enabled: !menu.active" bind__raycaster="enabled: {{ hand }}RaycasterActive" bind__saber-controls="bladeEnabled: !menu.active" + bind__trail="enabled: !menu.active" haptics="events: mouseenter; dur: 35; force: 0.075" saber-controls="hand: {{ hand }}" trail="color: {{ bladeColor }}">