EviaEarth6.0网页版接口说明(1)

如何在网页里创建EviaEarth

JS调用方法

第一步:页面引入qtloader.js,定义canvas标签id为qtcanvas

第二步:执行以下js代码:

let qtLoader = QtLoader({

canvasElements: [document.querySelector(“#qtcanvas”)],

showCanvas: function () {

setTimeout(() => {

window.Module.asm.fun()

}, 100);

},

});

qtLoader.loadEmscriptenModule(‘./static/EviaEarth’);

其中“#qtcanvas”为之前定义的canvas的id,“./static/EviaEarth”为存放EviaEarth.wasm文件的相对路径(不包含.wasm后缀)

第三步:调用接口函数

上述代码中window.Module.asm.fun(),fun为接口函数名,

  • 无参数接口使用,如Version:

window.Module.asm. Version ()

  • 参数为数字类型接口使用,如add:

window.Module.asm. add(1,2)

  • 参数为字符串类型接口使用,如Scene_Navigate函数,参数为‘http://localhost/ getEVG?scene=earth’:

let ptr = allocate(

intArrayFromString(“http://localhost/getEVG?scene=earth” ),

“i8”,

ALLOC_NORMAL

);

window.Module.asm. Scene_Navigate(ptr)