import { Poly } from "@polygonjs/polygonjs/dist/src/engine/Poly";
import { PolyScene } from "@polygonjs/polygonjs/dist/src/engine/scene/PolyScene";
import { AllRegister } from "@polygonjs/polygonjs/dist/src/engine/poly/registers/All";
AllRegister.run();
import { polyPluginMapbox } from "./index";
import { token } from "./ExampleData";
polyPluginMapbox.setToken(token);
Poly.registerPlugin(polyPluginMapbox);
const scene = new PolyScene();
const root = scene.root();
const mapboxCamera = root.createNode("mapboxCamera");
mapboxCamera.p.lngLat.set([148.9819, -35.3981]);
function createText() {
  const geo = root.createNode("geo");
  const text = geo.createNode("text");
  text.p.text.set("Polygonjs + Mapbox");
  const boxTransform = geo.createNode("transform");
  boxTransform.setInput(0, text);
  boxTransform.p.scale.set(100);
  const add = geo.createNode("add");
  const addTransform = geo.createNode("transform");
  addTransform.setInput(0, add);
  addTransform.p.t.x.set(mapboxCamera.pv.lngLat.x);
  addTransform.p.t.z.set(mapboxCamera.pv.lngLat.y);
  const mapboxTransform = geo.createNode("mapboxTransform");
  mapboxTransform.setInput(0, addTransform);
  mapboxTransform.p.mapboxCamera.setNode(mapboxCamera);
  const copy = geo.createNode("copy");
  copy.setInput(0, boxTransform);
  copy.setInput(1, mapboxTransform);
  const MAT = root.createNode("materialsNetwork");
  const meshLambert = MAT.createNode("meshLambert");
  const material = geo.createNode("material");
  material.setInput(0, copy);
  material.p.material.setNode(meshLambert);
  material.flags.display.set(true);
  window.text = text;
  window.boxTransform = boxTransform;
  window.scene = scene;
}
function createLights() {
  root.createNode("hemisphereLight");
}
async function buildScene() {
  setTimeout(() => {
    createLights();
    createText();
  }, 1e3);
  mapboxCamera.createViewer(document.getElementById("app"));
}
buildScene();
