如何通过移动或拖动鼠标在 A-Frame 中旋转 3d 模型?

How do I rotate a 3d model in A-Frame by moving or dragging the mouse?

基于此

我如何使用 3d 模型完成它?我需要在视图中旋转 3d model/object

我试过这段代码,但不起作用

<html>
<head>
  <title>Rotation</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://aframe.io/releases/0.4.0/aframe.min.js"></script>
</head>
<body>
<script type="text/javascript">
    AFRAME.registerComponent('drag-rotate-component',{
      schema : { speed : {default:1}},
      init : function(){
        this.ifMouseDown = false;
        this.x_cord = 0;
        this.y_cord = 0;
        document.addEventListener('mousedown',this.OnDocumentMouseDown.bind(this));
        document.addEventListener('mouseup',this.OnDocumentMouseUp.bind(this));
        document.addEventListener('mousemove',this.OnDocumentMouseMove.bind(this));
      },
      OnDocumentMouseDown : function(event){
        this.ifMouseDown = true;
        this.x_cord = event.clientX;
        this.y_cord = event.clientY;
      },
      OnDocumentMouseUp : function(){
        this.ifMouseDown = false;
      },
      OnDocumentMouseMove : function(event)
      {
        if(this.ifMouseDown)
        {
          var temp_x = event.clientX-this.x_cord;
          var temp_y = event.clientY-this.y_cord;
          if(Math.abs(temp_y)<Math.abs(temp_x))
          {
            this.el.object3D.rotateY(temp_x*this.data.speed/1000);
          }
          else
          {
            this.el.object3D.rotateX(temp_y*this.data.speed/1000);
          }
          this.x_cord = event.clientX;
          this.y_cord = event.clientY;
        }
      }
    });
  </script>
  <a-scene>
   <a-assets>
      <a-asset-item id="man" src="./assets/models/man/man.dae"></a-asset-item>
   </a-assets>
   <a-collada-model src="#man" rotation="0 45 0"></a-model>
   <a-sky color="#ECECEC"></a-sky>
   <a-entity position="0 -0.5 1">
     <a-camera look-controls="enabled:false"></a-camera>
   </a-entity>
  </a-scene>
</body>
</html>

提前致谢!

这个也试过,可惜运气不好

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title - Demo 3D Model</title>
    <meta name="description" content="Inlabs demo - 3D Model">
        <script src="../../../dist/aframe-master.js"></script>

  </head>
  <body>
    <a-scene>
      <a-assets>
        <a-asset-item id="man" src="./assets/models/man/man.dae"></a-asset-item>
      </a-assets>

      <a-collada-model src="#man" rotation="0 45 0"></a-model>
      <a-sky color="#ECECEC"></a-sky>
      <a-entity position="0 -0.5 1">
        <a-camera drag-rotate-component look-controls="enabled:false"></a-camera>
      </a-entity>
    </a-scene>
  </body>
</html>

编辑:对不起,不好意思,这不正确,因为它没有回答问题。

我认为您只是忘记将组件的名称 drag-rotate-component 作为属性附加到相机实体。看到这个 pen.

<a-camera drag-rotate-component look-controls="enabled:false"></a-camera>

drag-rotate-component 附加到模型而不是相机。

<a-collada-model drag-rotate-component>

此外,您不需要在组件名称中添加 -component