import {Poly as Poly2} from "@polygonjs/polygonjs/dist/src/engine/Poly";
import {PolyScene as PolyScene2} from "@polygonjs/polygonjs/dist/src/engine/scene/PolyScene";
import {AllRegister} from "@polygonjs/polygonjs/dist/src/engine/poly/registers/All";
AllRegister.run();
import {polyPluginPhysics} from "./index";
Poly2.registerPlugin(polyPluginPhysics);
const scene = new PolyScene2();
const geo = scene.root().createNode("geo");
const box = geo.createNode("roundedBox");
box.p.size.set(0.63);
const plane = geo.createNode("plane");
plane.p.size.set([4, 4]);
const planeTransform = geo.createNode("transform");
planeTransform.setInput(0, plane);
planeTransform.p.t.y.set(3);
const jitter = geo.createNode("jitter");
jitter.setInput(0, planeTransform);
jitter.p.amount.set(2.8);
const copy = geo.createNode("copy");
copy.setInput(0, box);
copy.setInput(1, jitter);
const boxTransformReset = geo.createNode("transformReset");
boxTransformReset.setInput(0, copy);
boxTransformReset.p.mode.set(2);
const boxPhysicsAttributes = geo.createNode("physicsRbdAttributes");
boxPhysicsAttributes.setInput(0, boxTransformReset);
const boxAttribCreateRestitution = geo.createNode("attribCreate");
boxAttribCreateRestitution.setInput(0, boxPhysicsAttributes);
boxAttribCreateRestitution.p.name.set("restitution");
boxAttribCreateRestitution.p.value1.set("rand(@ptnum+254)");
const boxTransform = geo.createNode("transform");
boxTransform.setInput(0, boxAttribCreateRestitution);
boxTransform.p.applyOn.set(1);
boxTransform.p.r.x.set(35);
const boxGround = geo.createNode("box");
const boxGroundTransform = geo.createNode("transform");
boxGroundTransform.setInput(0, boxGround);
boxGroundTransform.p.t.y.set(-2);
boxGroundTransform.p.s.set([5, 1, 10]);
const boxGroundTransformReset = geo.createNode("transformReset");
boxGroundTransformReset.setInput(0, boxGroundTransform);
boxGroundTransformReset.p.mode.set(2);
const groundPhysicsAttributes = geo.createNode("physicsRbdAttributes");
groundPhysicsAttributes.setInput(0, boxGroundTransformReset);
groundPhysicsAttributes.p.active.set(0);
groundPhysicsAttributes.p.mass.set(1e5);
const merge = geo.createNode("merge");
merge.p.compact.set(0);
merge.setInput(0, groundPhysicsAttributes);
merge.setInput(1, boxTransform);
const physicsSolver = geo.createNode("physicsSolver");
physicsSolver.setInput(0, merge);
physicsSolver.flags.display.set(true);
scene.root().createNode("hemisphereLight");
const perspectiveCamera1 = scene.root().createNode("perspectiveCamera");
perspectiveCamera1.p.t.set([5, 5, 5]);
const events1 = perspectiveCamera1.createNode("events");
const orbitsControls = events1.createNode("cameraOrbitControls");
perspectiveCamera1.p.controls.setNode(orbitsControls);
perspectiveCamera1.createViewer(document.getElementById("app"));
scene.play();
window.scene = scene;
window.plane = plane;
