# A-Frame & VWF simple scene
# Copyright 2017 Krestianstvo.org project
---
extends: http://vwf.example.com/aframe/ascene.vwf
properties:
  transparent: true
children:
  fog:
    extends: http://vwf.example.com/aframe/aSceneFogComponent.vwf
    type: "component"
    properties:
      fogType: "linear"
      fogColor: "#ECECEC"
      far: 9
      near: 0
  sky:
    extends: http://vwf.example.com/aframe/asky.vwf
    properties:
    children:
      material:
        extends: http://vwf.example.com/aframe/aMaterialComponent.vwf
        properties:
          color: "#ECECEC"
          side: "back"
          fog: false
  spaceText:
    extends: http://vwf.example.com/aframe/atext.vwf
    properties:
      value: "Virtual World Framework & A-Frame"
      color: "#b74217"
      position: "-2 2.5 -2"
  spaceText2:
    extends: http://vwf.example.com/aframe/atext.vwf
    properties:
      value: "Project by Krestianstvo.org"
      color: "#305b32"
      position: "1 3 -4"
  box:
    extends: http://vwf.example.com/aframe/abox.vwf
    properties:
      position: "-1 0.5 -3"
      rotation: "0 -30 0"
      depth: 2
      height: 1
      width: 1
      clickable: true
    children:
      material:
        extends: http://vwf.example.com/aframe/aMaterialComponent.vwf
        properties:
          color: "#3c7249"
      raycaster-listener:
        extends: http://vwf.example.com/aframe/app-raycaster-listener-component.vwf
        type: "component"
      cursor-listener:
        extends: http://vwf.example.com/aframe/app-cursor-listener-component.vwf
        type: "component"
    events:
      clickEvent:
      intersectEvent:
      clearIntersectEvent:
    methods:
      clickEventMethod:
        body: |
          if (this.clickable) {
          let genColor = this.generateColor();
          this.material.color = genColor 
            }
      intersectEventMethod:
        body: |
          if (this.clickable) {
          this.rotation = "0 -90 0"
            }
      clearIntersectEventMethod:
        body: |
          if (this.clickable) {
          this.rotation = "0 -30 0"
            }
      generateColor:
        body: |
          var letters = '0123456789ABCDEF';
          var color = '#';
          for (var i = 0; i < 6; i++) {
          color += letters[Math.floor(this.random() * 16)];
          } return color 
    scripts:
      - |
        this.clickEvent = function(){
          this.clickEventMethod();
         }
         this.intersectEvent = function(){
          this.intersectEventMethod();
         }
         this.clearIntersectEvent = function(){
          this.clearIntersectEventMethod();
         }
  sphere:
    extends: http://vwf.example.com/aframe/asphere.vwf
    properties:
      position: "1 1.25 -4"
      radius: 1
    children:
      material:
        extends: http://vwf.example.com/aframe/aMaterialComponent.vwf
        properties:
          color: "#e0e014"
          wireframe: true
      box2:
        extends: http://vwf.example.com/aframe/abox.vwf
        properties:
          position: "2 -0.75 0"
          depth: 1
        children:
          material:
            extends: http://vwf.example.com/aframe/aMaterialComponent.vwf
            properties:
              color: "#2167a5"
          interpolation:
            extends: http://vwf.example.com/aframe/interpolation-component.vwf
            properties:
              enabled: true
        methods:
          run:
            body: |
              var time = vwf.now;
              let rot = AFRAME.utils.coordinates.parse(this.rotation);
              let pos = AFRAME.utils.coordinates.parse(this.position);
              this.position = [pos.x, pos.y, Math.sin(time)];
              this.rotation = [rot.x, rot.y, Math.sin(time)*100];
              this.future( 0.01 ).run();  // schedule the next step
methods:
  initialize:
    body: |
      var runBox = vwf_view.kernel.find("", "/sphere/box2")[0];
      console.log(runBox);
      vwf_view.kernel.callMethod(runBox, "run");