AFrame-反应如何注册和使用自定义组件? [英] Aframe-react how to register and use custom component?
本文介绍了AFrame-反应如何注册和使用自定义组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
该应用程序是通过create-action-app启动的,我仔细阅读发现可能是关于webpack的bundle.js如果不弹出就无法访问。
在Chrome检查器中:
App.js:4 Uncaught Error: Cannot find module "./viz"
at webpackMissingModule (App.js:4)
at Object.<anonymous> (App.js:4)
at __webpack_require__ (bootstrap b7779078638c88d24628:555)
at fn (bootstrap b7779078638c88d24628:86)
at Object.<anonymous> (index.js:4)
at __webpack_require__ (bootstrap b7779078638c88d24628:555)
at fn (bootstrap b7779078638c88d24628:86)
at Object.<anonymous> (bootstrap b7779078638c88d24628:578)
at __webpack_require__ (bootstrap b7779078638c88d24628:555)
at bootstrap b7779078638c88d24628:578
在AFrame Discord频道上,ngoKevin告诉我只需要组件。
这是组件,我希望能够在侧边栏中看到4个摄像头作为观众加上主活动摄像头,这个代码是只针对一个摄像头的,左边的
const AFRAME = window.AFRAME;
const THREE = require('aframe/src/lib/three');
/*register left camera component */
AFRAME.registerComponent('leftcamera',{
'schema': {
canvas: {
type: 'string',
default: '#cameraleft;'
},
// desired FPS of spectator display
fps: {
type: 'number',
default: '10.0'
}
},
'init': function() {
var targetEl = document.querySelector(this.data.canvas)
this.counter = 0;
this.renderer = new THREE.WebGLRenderer( { antialias: true } );
this.renderer.setPixelRatio( window.devicePixelRatio );
this.renderer.setSize( targetEl.offsetWidth, targetEl.offsetHeight );
// creates spectator canvas
targetEl.appendChild(this.renderer.domElement);
},
'tick': function(time, timeDelta) {
var loopFPS = 1000.0 / timeDelta;
var hmdIsXFasterThanDesiredFPS = loopFPS / this.data.fps;
var renderEveryNthFrame = Math.round(hmdIsXFasterThanDesiredFPS);
if(this.counter % renderEveryNthFrame === 0){
this.render(timeDelta);
}
this.counter += 1;
},
'render': function(){
this.renderer.render( this.el.sceneEl.object3D , this.el.object3DMap.camera );
console.log('====================================');
console.log('here &');
console.log('====================================');
}
}
);
如果您想看一下
,我将代码发布在GLITCH上->https://aframe-spectator-sideview.glitch.me
这个从js文件导入并在一个HTML上使用它(尝试直接从html理解,从Reaction-AFrame也可以工作obvs)
-导入并注册
import leftcamera from './leftCamera.js';
register leftcamera(AFRAME);
import 'aframe';
import aframe from 'aframe';
import {Entity, Scene} from 'aframe-react';
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
如有任何提示或帮助,不胜感激!
提前感谢!
推荐答案
感谢您的详细代码和故障!
require('aframe');
require('./yourAframeComponent');
其中yourAframeComponent.js
本地将包含:
AFRAME.registerComponent('...', {});
并注意,需要在附加之前注册组件。如果是通过REACT,那么就意味着在REACT呈现之前。如果是静态的HTML,这意味着脚本标记需要放在HTML之前,或者等待DOM就绪。
A-Frame Reaction样板显示需要的组件。在您的情况下,本地需要该组件;https://github.com/ngokevin/aframe-react-boilerplate/blob/master/src/index.js这篇关于AFrame-反应如何注册和使用自定义组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文