0

对于我的 react 360 项目,我的client.js文件中有以下代码:

import { ReactInstance } from 'react-360-web';
import AsteroidsModule from './AsteroidsModule';
import * as THREE from 'three';

function init(bundle, parent, options = {}) {
  const scene = new THREE.Scene();
  const r360 = new ReactInstance(bundle, parent, {
    // Add custom options here
    fullScreen: true,
    nativeModules: [
      new AsteroidsModule(scene),
    ],

                  Problem
    ***************************************
    frame: () => {
      AsteroidsModule.printOut('hello');
    },
    ***************************************

    ...options,
  });

  ........code...

AsteroidsModule接下来,我在一个单独的文件中有以下代码。该代码来自 reactvr 上的演示文稿,内容如下:

import { Module } from 'react-360-web';
import * as THREE from 'three';

export default class AsteroidsModule extends Module {
  constructor(scene) {
    // The name of the module in NativeModules
    super('AsteroidsModule');

    this.scene = scene;
    this.time = 0;
    this.meshes = [];
  }

  printOut(string) {
    console.log(string);
  }

  populate() {
   ....code....
  }

  render() {
   ....code......
  }
}

初始化时的 React 360 有一个frame:选项,允许我在每一帧渲染上执行代码。在这种情况下,出于测试目的,我要执行的代码是AsteroidsModule.printOut('hello')方法调用。在控制台中,这会导致错误:

Uncaught TypeError: _AsteroidsModule2.default.printOut is not a function

我不明白为什么我会收到这个错误。我已经在文件顶部导入了所需的模块。我试图一块一块地挑选这个分开的,但我不知道为什么它没有渲染。有人可以帮助我解决可能的问题吗?

4

0 回答 0