Skip to content

Bvh animation

Nikola edited this page Jun 15, 2022 · 1 revision
import * as matrixEngine from "https://cdn.skypack.dev/matrix-engine@1.5.1";

var world;
var App = matrixEngine.App;

if ("serviceWorker" in navigator) {
  window.addEventListener("load", function () {
    navigator.serviceWorker.register("worker.js");
  });
} else {
  console.warn("Matrix Engine: No support for web workers in this browser.");
}

function webGLStart() {
  world = matrixEngine.matrixWorld.defineworld(canvas);
  world.callReDraw();

  // from here you can put code from examples
  // need to be removed from bvh-loader npm package!
  var logHTML = document.createElement('div');
  logHTML.id = 'log';
  document.body.appendChild(logHTML)

  const options = {
    world: world,
    autoPlay: true,
    showOnLoad: false, // if autoPLay is true then showOnLoad is inactive.
    type: 'ANIMATION', // "TPOSE' | 'ANIMATION'
    loop: 'playInverse', // true | 'stopOnEnd' | 'playInverse' | 'stopAndReset'
    globalOffset: [-10, -10, -45],
    skeletalBoneScale: 0.55,
    skeletalBlend: { paramDest: 1, paramSrc: 1 } // remove arg for no blend
  };

  const filePath = "https://raw.githubusercontent.com/zlatnaspirala/Matrix-Engine-BVH-test/main/javascript-bvh/example.bvh";
  var myFirstBvhAnimation = new matrixEngine.MEBvhAnimation(filePath, options);
  //window.myFirstBvhAnimation= myFirstBvhAnimation;

  canvas.addEventListener('mousedown', (ev) => {
    matrixEngine.raycaster.checkingProcedure(ev);
  });

  addEventListener('ray.hit.event', function (e) {
    console.info(e.detail.hitObject);
    e.detail.hitObject.glBlend.blendParamSrc = matrixEngine.utility.ENUMERATORS.glBlend.param[2];
    e.detail.hitObject.glBlend.blendParamDest = matrixEngine.utility.ENUMERATORS.glBlend.param[7];
  });

  window.App = App;
}

matrixEngine.Engine.load_shaders("shaders/shaders.html");
window.matrixEngine = matrixEngine;

window.addEventListener("load", () => {
  matrixEngine.Engine.initApp(webGLStart);
}, false);

// var App = matrixEngine.App;