{"size": 1295, "ext": "js", "max_stars_repo_path": "src/javascripts/week12-physics.js", "max_stars_repo_name": "WSU-FALL-2020/cs4280-inclass", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/javascripts/week12-physics.js", "max_issues_repo_name": "WSU-FALL-2020/cs4280-inclass", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/javascripts/week12-physics.js", "max_forks_repo_name": "WSU-FALL-2020/cs4280-inclass", "max_forks_repo_forks_event_min_datetime": "2020-09-21T20:16:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-21T20:16:26.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 25.9, "max_line_length": 97, "alphanum_fraction": 0.7111969112}
import * as THREE from 'three'
window.THREE = THREE
require('./physi')
Physijs.scripts.worker = '/models/physijs_worker.js'
Physijs.scripts.ammo = '/models/ammo.js'

function getBoard(){
  let material = new Physijs.createMaterial(
    new THREE.MeshPhongMaterial({
      map: new THREE.TextureLoader().load('./images/floor.jpg')
    }), .9, .1)

  let floor = new Physijs.BoxMesh(new THREE.BoxGeometry(60, 1, 60), material, 0)
  let left = new Physijs.BoxMesh(new THREE.BoxGeometry(2, 3, 60), material, 0)
  left.position.x = -31
  left.position.y = 2
  floor.add(left)


  return floor
}

export function displayScene(){
  let canvas = document.querySelector('#webgl-scene')
  let scene = new Physijs.Scene()
  scene.setGravity(new THREE.Vector3(0, -50, 0))

  let renderer = new THREE.WebGLRenderer({canvas})
  let camera = new THREE.PerspectiveCamera(45, canvas.clientWidth / canvas.clientWidth, .1, 1000)

  renderer.setSize(canvas.clientWidth, canvas.clientHeight)
  renderer.setClearColor(0x000000)

  let spotLight = new THREE.SpotLight(0xFFFFFF)
  spotLight.position.set(20, 100, 50)
  scene.add(spotLight)

  let board = getBoard()
  scene.add(board)

  function animate(){
    scene.simulate()

    renderer.render(scene, camera)
    requestAnimationFrame(animate)
  }

  animate()
}
