我想注册一个Aframe--在Aframe中的组件-- react;我通常使用它AFRAME.registerComponent(‘左侧摄像机’,{.});然后立即在Html中使用它,但是不能真正理解如何以正确的反应方式来实现它。
这个应用程序是用创建-反应-应用程序引导的,我在阅读时发现,如果没有弹出,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不和谐频道上,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('====================================');
}
}
);如果你想看一看的话,我把代码贴在了小故障上。
-> https://aframe-spectator-sideview.glitch.me
从js文件导入并在HTML上使用它(尝试直接使用html来理解,从react aframe也可以使用obv)。
-import和寄存器
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';任何提示或帮助都将不胜感激!
提前谢谢你!
发布于 2018-12-09 06:07:37
谢谢您的详细代码和故障!
require('aframe');
require('./yourAframeComponent');其中,yourAframeComponent.js本地将包含:
AFRAME.registerComponent('...', {});并注意,在附加HTML之前,需要注册组件。如果这是via React,那么这意味着在React呈现之前。如果是静态HTML,这意味着脚本标记需要放在HTML之前,或者等待DOM就绪。
一个框架反应样板显示需要组件。在您的示例中,组件将是本地所需的;https://github.com/ngokevin/aframe-react-boilerplate/blob/master/src/index.js
https://stackoverflow.com/questions/53682445
复制相似问题