React / AFrame 对象分配错误

React / AFrame object assign error

我试图在 react-native 中连接 Aframe,但在模拟器中启动时出现此错误:

One of the sources for assign has an enumerable key on the prototype chain. Are you trying to assign a prototype property? We don't allow it, as this is an edge case that we do not support. This error is a performance optimization and no spec compliant.

我正在使用 Aframe 0.5.0 和 React-Native 0.41.2

错误是从polyfills.js的第56行抛出的,与aframe的这一段有关-master.js:55729.

Object.assign( THREE.MTLLoader.prototype, THREE.EventDispatcher.prototype, {

有什么办法解决这个问题吗?我是否需要修改 aframe 以使用不同的分配,或者有什么方法可以解决这个问题?

我是 运行 一个非常简单的 hello world,它只是试图加载依赖项而失败。在其他相关问题中,人们表示他们已经通过使用 lodash.assign 或 Object.defineProperties 解决了这个问题 - 这是一个可行的解决方案吗?我可以同时恢复到旧版本的 react-native,但理想情况下我想使用最新的 a-frame。

https://github.com/facebook/react-native/issues/5507

https://github.com/facebook/react-native/issues/3634

** 更新 ** 好的,我尝试回滚,安装 react-native 0.36.1 并将我在 WebView 中加载的站点切换为使用 aframe 0.3.2。

我在 React 本机应用程序中的代码是这样的:

好的,我尝试回滚,使用 rninit 安装了 react-native 0.36.1,并将我在 WebView 中加载的站点切换为使用 aframe 0.3.2。

我在 React 本机应用程序中的代码是这样的:

import React, { Component } from 'react';
 // import ReactDOM from 'react-dom';
 import {
   AppRegistry,
   WebView
 } from 'react-native';

 export default class test4 extends Component {
   render() {
     return (
       <WebView source={{uri: 'http://[theurl]/test.html'}}/>
     );
   }
 }


 AppRegistry.registerComponent('test4', () => test4);

aframe 应用是这样的:

<!DOCTYPE html>
<html>
    <head>
        <title>A-Frame walkthrough (final)</title>
        <script src="/aframe.js"></script>

    </head>
<body>
  <a-scene>
    <a-assets>
      <img id="circle" src="circle.png"/>
    </a-assets>


      <a-sky src="Ephesus4_1.jpg" rotation="0 -130 0"></a-sky>
    </a-scene>

</html>

当我通过检查来自 chrome://inspect#devices 的 webview 打开调试器时,我得到了这个输出:

Mozilla/5.0 (Linux; Android 6.0; Android SDK built for x86_64 Build/MASTER; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/44.0.2403.119 Mobile Safari/537.36
aframe.js:54681 Recalculating device params.
aframe.js:54718 User agent: Mozilla/5.0 (Linux; Android 6.0; Android SDK built for x86_64 Build/MASTER; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/44.0.2403.119 Mobile Safari/537.36
aframe.js:54719 Pixel width: 2562
aframe.js:54720 Pixel height: 1442
aframe.js:54762 No DPDB device match.
aframe.js:54683 New device parameters:
aframe.js:54684 null
aframe.js:54692 Failed to recalculate device parameters.Dpdb.recalculateDeviceParams_ @ aframe.js:54692
aframe.js:54654 Fetching DPDB...
aframe.js:53106 Using fallback Android device measurements.
aframe.js:56388 Failed to load viewer profile: TypeError: Cannot read property 'getItem' of null
    at Emitter.ViewerSelector (http://ec2-52-62-186-186.ap-southeast-2.compute.amazonaws.com:8080/aframe.js:56386:36)
    at VRDisplay.CardboardVRDisplay (http://ec2-52-62-186-186.ap-southeast-2.compute.amazonaws.com:8080/aframe.js:52607:26)
    at WebVRPolyfill.populateDevices (http://ec2-52-62-186-186.ap-southeast-2.compute.amazonaws.com:8080/aframe.js:56694:17)
    at WebVRPolyfill.getVRDisplays (http://ec2-52-62-186-186.ap-southeast-2.compute.amazonaws.com:8080/aframe.js:56743:8)
    at new THREE.VRControls (http://ec2-52-62-186-186.ap-southeast-2.compute.amazonaws.com:8080/aframe.js:66848:13)
    at Object.119.../lib/three (http://ec2-52-62-186-186.ap-southeast-2.compute.amazonaws.com:8080/aframe.js:66227:16)
    at s (http://ec2-52-62-186-186.ap-southeast-2.compute.amazonaws.com:8080/aframe.js:1:620)
    at http://ec2-52-62-186-186.ap-southeast-2.compute.amazonaws.com:8080/aframe.js:1:671
    at Object.122../bind (http://ec2-52-62-186-186.ap-southeast-2.compute.amazonaws.com:8080/aframe.js:66358:25)
    at s (http://ec2-52-62-186-186.ap-southeast-2.compute.amazonaws.com:8080/aframe.js:1:620)ViewerSelector @ aframe.js:56388
aframe.js:53096 Uncaught TypeError: Cannot read property 'distortionCoefficients' of undefined
aframe.js:54662 Successfully loaded online DPDB.
aframe.js:54681 Recalculating device params.
aframe.js:54718 User agent: Mozilla/5.0 (Linux; Android 6.0; Android SDK built for x86_64 Build/MASTER; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/44.0.2403.119 Mobile Safari/537.36
aframe.js:54719 Pixel width: 2562
aframe.js:54720 Pixel height: 1442
aframe.js:54762 No DPDB device match.
aframe.js:54683 New device parameters:
aframe.js:54684 null
aframe.js:54692 Failed to recalculate device parameters.Dpdb.recalculateDeviceParams_ @ aframe.js:54692
http://ec2-52-62-186-186.ap-southeast-2.compute.amazonaws.com:8080/favicon.ico Failed to load resource: the server responded with a status of 404 (Not Found)

如有任何建议,我们将不胜感激!

我也在 android 模拟器中得到这个:

com.facebook.react.common.JavascriptException:{"stack":"Error: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false' failed to load.\n at executeApplicationScript (http://localhost:8081/ebuggerWorker.js:207)\n at onmessage (http://localhost:8081/debuggerWorker.js:38.5)"}

即使我切换到正在 webview 中加载的非 aframe 网站,我也会遇到同样的错误。

折腾了半天,发现我的很多问题都是在模拟器上测试的。

当 运行 在设备上时,我能够获得一个应用 运行 最新版本的 a-frame 与最新版本的 react-native 一起使用,但只能通过设置 react-native 以从源代码 java 重新编译 android 项目,从当前主控中提取。

我还必须在 Android.Manifest 中启用硬件加速。

感谢 Chris Chen 的协助