首页 > 解决方案 > 如何在反应中获得带有a-frame的旋转度数

问题描述

我正在使用 A 帧来可视化 VR,并且我正在尝试从相机中获取旋转度数,因为我需要向观众展示视角。我看到了这个命令:

Ent.object3D.rotation.set(
  THREE.Math.degToRad(15),
  THREE.Math.degToRad(30),
  THREE.Math.degToRad(90)
);
Ent.object3D.rotation.x += Math.PI;

Ent.el.getAttribute("rotation")
console.log(THREE)

THREE但是当我 console.log 它时,反应似乎不可能得到。

我的组件是这样的:

    import "aframe";
import { Entity, Scene } from "aframe-react";
import React, { useState, useEffect, useRef } from "react";

import * as THREE from "three";
require("aframe");
require("aframe-video-controls");

const VRphoto = ({ BackgroundVR, config, rotation }) => {
  // With three.js
  const Ent = useRef(null)



  const A = (
    <Entity
      ref={Ent}
      primitive="a-sky"
      scale={{ x: -0.9 }}
      src={require(`../assets/images/vr/${BackgroundVR}`)}
      enabled
      camera
      look-controls
      rotation={rotation}
      // rotation="0 0 0"
    />
  );
Ent.object3D.rotation.set(
  THREE.Math.degToRad(15),
  THREE.Math.degToRad(30),
  THREE.Math.degToRad(90)
);
Ent.object3D.rotation.x += Math.PI;

Ent.el.getAttribute("rotation")
console.log(THREE)

return (
    <Scene loading-screen="dotsColor: #ef2d5e; backgroundColor: #000000;">
      {A}
    </Scene>
  );

};

export default VRphoto;

这是 A-frame (vanilla, not eact) 文档中的两个链接 第一个链接 第二个链接

标签: javascriptreactjsthree.jsaframewebvr

解决方案


推荐阅读