浏览代码

babylon.js plugin: adjust pointers and fix the initial size of the canvas

customisations
alemart 9 个月前
父节点
当前提交
6d4ddd58e0
共有 1 个文件被更改,包括 17 次插入6 次删除
  1. 17
    6
      plugins/babylon-with-encantar.js

+ 17
- 6
plugins/babylon-with-encantar.js 查看文件

7
 /* Usage of the indicated versions is encouraged */
7
 /* Usage of the indicated versions is encouraged */
8
 __THIS_PLUGIN_HAS_BEEN_TESTED_WITH__({
8
 __THIS_PLUGIN_HAS_BEEN_TESTED_WITH__({
9
     'encantar.js': { version: '0.4.0' },
9
     'encantar.js': { version: '0.4.0' },
10
-     'babylon.js': { version: '7.29.0' }
10
+     'babylon.js': { version: '7.38.0' }
11
 });
11
 });
12
 
12
 
13
 /**
13
 /**
325
 
325
 
326
         ar._session = session;
326
         ar._session = session;
327
 
327
 
328
-        ar._engine = new BABYLON.Engine(session.viewport.canvas, false, {
329
-            premultipliedAlpha: true
330
-        });
331
-        ar._engine.resize = function(forceSetSize = false) {
328
+        BABYLON.Engine.prototype.resize = function(forceSetSize = false) {
332
             // make babylon.js respect the resolution of the viewport
329
             // make babylon.js respect the resolution of the viewport
333
             const size = session.viewport.virtualSize;
330
             const size = session.viewport.virtualSize;
334
             this.setSize(size.width, size.height, forceSetSize);
331
             this.setSize(size.width, size.height, forceSetSize);
335
         };
332
         };
333
+        ar._engine = new BABYLON.Engine(session.viewport.canvas, false, {
334
+            premultipliedAlpha: true
335
+        });
336
 
336
 
337
         ar._scene = new BABYLON.Scene(ar._engine);
337
         ar._scene = new BABYLON.Scene(ar._engine);
338
         ar._scene.useRightHandedSystem = true;
338
         ar._scene.useRightHandedSystem = true;
339
-        ar._scene.clearColor.set(0, 0, 0, 0);
339
+        ar._scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);
340
+        ar._scene._inputManager._updatePointerPosition = function(evt) {
341
+            // adjust babylon.js pointers to the resolution of the viewport
342
+            const engine = this._scene.getEngine();
343
+            const canvasRect = engine.getInputElementClientRect();
344
+            if(!canvasRect)
345
+                return;
346
+            this._pointerX = (evt.clientX - canvasRect.left) * (engine.getRenderWidth() / canvasRect.width);
347
+            this._pointerY = (evt.clientY - canvasRect.top) * (engine.getRenderHeight() / canvasRect.height);
348
+            this._unTranslatedPointerX = this._pointerX;
349
+            this._unTranslatedPointerY = this._pointerY;
350
+        };
340
 
351
 
341
         ar._origin = new BABYLON.TransformNode('ar-origin', ar._scene);
352
         ar._origin = new BABYLON.TransformNode('ar-origin', ar._scene);
342
         ar._root = new BABYLON.TransformNode('ar-root', ar._scene);
353
         ar._root = new BABYLON.TransformNode('ar-root', ar._scene);

正在加载...
取消
保存