На основе этого Как повернуть рамку в рамке A, перемещая или перетаскивая мышь?
как это сделать с 3d моделью? мне нужно повернуть 3d модель / объект в виде
я пробовал этот код, но не работает
<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>