Giter Club home page Giter Club logo

aframe-orbit-controls-component's Introduction

aframe-orbit-controls-component


Please use this more performant component instead: https://github.com/ngokevin/kframe/tree/master/components/orbit-controls


A (almost) direct port of the ThreeJS Orbit Controls for A-Frame. It allows users to rotate the camera around an object. Might be useful as a fallback to VR mode. Automatically switches to look-controls in VR mode.

Have a look at the examples

API

Property Description Default Value
enabled Boolean – defines if the Orbit Controls are used false
target String – the object the camera is looking at and orbits around ''
distance Number – the distance of the camera to the target 1
enableRotate Boolean – defines if the camera can be rotated true
rotateSpeed Number – rotation speed 1
enableZoom Boolean – defines if the camera can be zoomed in or out true
invertZoom Boolean – defines if zooming is inverted false
zoomSpeed Number – zoom speed 1
enablePan Boolean – defines if the camera can be panned (using the arrow keys) true
keyPanSpeed Number – panning speed 7
enableDamping Boolean – defines if the rotational movement of the camera is damped / eased false
dampingFactor Number – damping factor 0.25
autoRotate Boolean – defines if the camera automatically rotates around the target false
autoRotateSpeed Number – speed of the automatic rotation 2
enableKeys Boolean – defines if the keyboard can be used true
minAzimuthAngle Number – minimum azimuth angle – Defines how far you can orbit horizontally, lower limit -Infinity
maxAzimuthAngle Number – maximum azimuth angle – Defines how far you can orbit horizontally, upper limit Infinity
minPolarAngle Number – minimum polar angle – Defines how far you can orbit vertically, lower limit 0
maxPolarAngle Number – maximum polar angle – Defines how far you can orbit vertically, upper limit Math.PI
minZoom Number – minimum zoom value – Defines how far you can zoom out for Orthographic Cameras 0
maxZoom Number – maximum zoom value – Defines how far you can zoom in for Orthographic Cameras Infinity
minDistance Number – minimum distance – Defines how far you can zoom in for Perspective Cameras 0
maxDistance Number – maximum distance – Defines how far you can zoom out for Perspective Cameras Infinity
rotateTo Vector3 – position to rotate automatically to {x:0,y:0,z:0}
rotateToSpeed Number – rotateTo speed 0.05
logPosition Boolean – prints out camera position to console.log() when rotating true
autoVRLookCam Boolean - automatically switch over to look-controls in VR mode? true

Installation

Browser

Install and use by directly including the browser files:

<head>
  <title>A-Frame using a Camera with Orbit Controls</title>
  <script src="https://aframe.io/releases/0.5.0/aframe.min.js"></script>
  <script src="https://cdn.rawgit.com/tizzle/aframe-orbit-controls-component/v0.1.14/dist/aframe-orbit-controls-component.min.js"></script>
</head>

<body>
    <a-scene>

      <a-entity
          id="camera"
          camera="fov: 80; zoom: 1;"
          position="0 2 5"
          orbit-controls="
              autoRotate: false;
              target: #target;
              enableDamping: true;
              dampingFactor: 0.125;
              rotateSpeed:0.25;
              minDistance:3;
              maxDistance:100;
              "
          mouse-cursor="">
          <a-entity geometry="primitive:cone; radius-bottom:1; radius-top:0" scale=".33 1 .33" position="0 0 0" rotation="90 0 0" material="color: #0099ff; transparent: true; opacity:0.5"></a-entity>
      </a-entity>

      <a-entity id="target">
          <a-box id="box" position="-1 0.5 1" rotation="0 45 0" color="#4CC3D9"></a-box>
          <a-sphere id="sphere" position="0 1.25 -1" radius="1.25" color="#EF2D5E"></a-sphere>
          <a-cylinder id="cylinder" position="1 0.75 1" radius="0.5" height="1.5" color="#FFC65D"></a-cylinder>
          <a-plane position="0 0 0" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
      </a-entity>

      <a-sky color="#ECECEC"></a-sky>

    </a-scene>
</body>

npm

Install via npm:

npm install aframe-orbit-controls-component-2

Then register and use.

require('aframe');
require('aframe-orbit-controls-component-2');

Alternatively, include as a <script> tag:

<script src="https://cdn.rawgit.com/tizzle/aframe-orbit-controls-component/v0.1.14/dist/aframe-orbit-controls-component.min.js"></script>

When the user enters VR mode, orbit-controls will pause itself and switch to the look-controls attached to the same camera. If no look-controls is specified on the current camera, one will be created with the default settings (this usually works fine). If you do not want this behaviour (probably becuase you want to control the camera juggling behaviour yourself) just specify autoVRLookCam:false.

aframe-orbit-controls-component's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aframe-orbit-controls-component's Issues

Check for already at desiredPosition returns false positives sometimes

The below snippet in the update() method causes camera rotations near the desiredPosition to incorrectly match, preventing rotateTo() from firing:

if (!this.desiredPosition.equals(rotateToVec3)) {
        this.desiredPosition.copy(rotateToVec3);
        this.rotateTo(this.desiredPosition);
}

removing the !this.desiredPosition.equals(rotateToVec3) check results in more consistent behavior, with the exception that the camera will automatically rotate to face the very top of the model on load if rotateTo is not set.

panning only works in two axes

Panning in the z-axis seems to have broken. Panning horizontally will only work in the x-axis.

Thanks for your efforts.

Orbit controls break if using an <a-assets> container

I just confirmed this happens on the example code as well. To replicated, just drop an element into the top of your scene, with individual nested assets or not. The orbit controls will no longer work, and no error messages are thrown in the console. Very strange, any ideas where to look for causes?

[Sorry the gif is in slowmo for some reason]

orbit-controls-bug

DollyDelta on Pan?

Hello, great component.

I'm unable to pan with my mouse. I get an error that says "Can't find variable: dollyDelta".

Thanks!

minPolarAngle/maxPolarAngle Infinity possible?

First of all: thanks for this plugin!

Then: I try to disable the Azimuth lock, to be able to freely rotate an object. I expected this to work, but it didn't:

          minPolarAngle: -Infinity;
          maxPolarAngle: Infinity;

Any ideas?

Feature request for deskop and mobile a-sky zoom-in and zoom-out

First off, thank you author for the aframe-orbit-controls-component repo.

My feature request is for desktop and mobile browser mousewheel and pinch and zoom support for zooming on the <a-sky> element.

Example:
I want to be able center <a-camera position=" 0 0 0" zoom="[value_here]"></a-camera>
This way I can zoom-in or zoom-out on any area of say a room that is set on the <a-sky src=""></a-sky>.

Thank you.

Listen to zoom event

Hi there!
I'm glad I found this component. I have seen there are events corresponding to the start and the end of a drag. Is there a similar event emitted when the zoom changes?
I want to adjust my target once a certain zoom level is reached but couldn't make it run so far.
Thanks in advance
Florian

Forcing the camera to go back behind the object quickly

Hello,

We are using this aframe component in a proof of concept game that we’re working on, in which you control a spaceship in space, land on a planet and control a drone on the planet’s surface. You can check it out here: http://exoplanets.cc

We have an issue that we can’t figure out the solution for.
When the object is moving slowly (e.g. the spaceship or the drone), the camera takes a very long time to position itself behind it so the player can see what he is pointing at.

The best example for it is the spaceship controls. When you are moving slowly and point the spaceship somewhere, it takes time for the camera to position itself behind the spaceship. But when you press “Space” and fly fast, then the camera is quick and responsive and it feels right. The movement of the object directly affects the speed of the camera's position around it.

In order to solve this when you land on a planet and control the drone, we currently just locked the camera behind the drone, but it doesn’t feel right. It feels forced and the movement is too sharp.

Is there a way to speed up the camera’s movement to return to a certain position (in this case, behind the object) even if the object is moving slow or not moving at all?

Thank you.

pointerevents for touch devices

@tizzle - I've been using a touchscreen laptop recently and touch events on the screen need to be handled differently. I think the correct way is to set the CSS attribute touchAction=none on the Aframe canvas (so that the canvas el doesn't use the OS-defined touch gestures) then change the listeners from mousedown, mouseup to pointerdown, pointerup.

This can all be wrapped in if (window.PointerEvent) for backwards compatibility, though basically all current browsers support pointer events.

I have this as a lower-priority item to do. Just wanted to flag it here.

I can't load the component dynamically

I would like to enable the orbit-controls component only when I click on a 3D object, but if I use setAttribute ‘orbital-controls’ on camera, the component is not working. The component it works if I add it on camera from the beginning, but I can’t set it disable and to activate it only when I click on an object. Can you help me please with a solution? Thank you!

rawgit CDN URL should use Tags

BTW, as far as I understood the RawGit CDN, files are cached permanently based on their URL, and are never refreshed. I think this means that any web user who visits an AFrame page that uses the CDN hosted version of your orbit-controls with this URL
cdn.rawgit.com/tizzle/aframe-orbit-controls-component/master/dist/aframe-orbit-controls-component.min.js

will never see an updated ".min.js" file, since even if the file changes upstream it is permanently cached on the CDN edge nodes.

I believe the solution is to add tags to your repo then use "/vX.Y.Z/" instead of "/master" in the URL for the CDN.

Other CDNs have a mechanism to invalidate the edge node caches, but rawgit does not offer this.

To introduce versioning you can use git tags

by default git push does not upload tags, so to get tags to GitHub you must also do:
git push origin --tags

health warning: I am not 100% sure about all this.

Cant rotate around object in VR mode (Cardboard)

When I switch to VR mode my cam wont around the object anymore when looking around. Is that the right behaviour? I need to be able to look around an object in vr mode.
I tried it with: autoVRLookCam:false. Does not work when looking around. If i touch the screen with fingers it is working.

Model pivot changed after using orbit controls. And model and camera's position changing affects its z and not x and y position.

Hi, I am a beginner using A frame, JS and HTML. I need to load a 3D model on a webpage using JS(as the path for loading the model will come from an XML) and the 3D model cab be rotated, panned and zoomed. Trying to achieve this using orbit controls.

I had set the 3D models position so that the model is on the center of the webpage. That was working fine until I added orbit controls. Now changing camera's or model's position affects its distance from screen rather than x-y position.

Also, my model's pivot is in center, but when I use orbit controls its pivot is at the bottom.

Here's my JS code:

var scene = document.createElement("a-scene");
scene.setAttribute("id","scene1");
scene.setAttribute("cursor","rayOrigin: mouse");
scene.setAttribute("vr-mode-ui","enabled:false");
scene.setAttribute("embedded","true");
document.body.append(scene);

var entity_3dModel = document.createElement("a-entity");
entity_3dModel.setAttribute("gltf-model",'url('+path[0].innerHTML+')');
entity_3dModel.setAttribute('scale', "3 3 3" );
entity_3dModel.setAttribute("id", "Model");
entity_3dModel.setAttribute("modify-materials", "");
entity_3dModel.setAttribute("click", "");
entity_3dModel.setAttribute("position","0 -3 0");
entity_3dModel.setAttribute("rotation","-30 180 0");
scene.appendChild(entity_3dModel);

var entity_camera = document.createElement("a-entity");
scene.appendChild(entity_camera);
entity_camera.setAttribute("id","camera");
entity_camera.setAttribute("camera","active","true");
entity_camera.setAttribute("camera","fov","100");
entity_camera.setAttribute("camera","zoom","0.5");
entity_camera.setAttribute("camera","far","1000");
entity_camera.setAttribute("camera","near","0.005");
entity_camera.setAttribute("orbit-controls","enabled: false");
entity_camera.setAttribute("position","0 3 -2");

        entity_camera.setAttribute("orbit-controls","enabled: true");
        entity_camera.setAttribute("orbit-controls","autoRotate: false");
        entity_camera.setAttribute("orbit-controls","target: #Model");

And HTML code:

#scene1{
position:absolute;
left:0%;
top:0%;
height: 100%;
width: 100%;
}*/

Kindly help.

Zoom need click

I run an embeded a-frame scene using orbit controls. I am facing an interaction issue reagrding zoom:
Once the scene is loaded a user has to click on the scene to make zoom (mouse weel) work. I would like to get the zoom function without the initial click.
I tried to programmatically dispatch a click event – no luck with this approach. For comparison I attached the wsad-controls component. This one recognizes the key inputs without the initial click event.

Any idea on how to make this work?

Distance property does not seem to be working

HI, I'm trying add zoom buttons to my scene with orbit controls, so I need to programmatically increase/decrease the distance of the orbitcontrols camera.

The issue is that the distance property doesn't seem to do anything, not the initial value, nor the programmatically updated value.

I've created a codepen to illustrate the issue.
https://codepen.io/anon/pen/zpqqEQ

Is there something I overlooked, or is the distance property malfunctioning?

dynamically changing camera position

I have a use case where I dynamically set the position of the camera after the scene and a model is loaded. I realised that the orbit controls component still thinks that the camera is at the original position when the component was initialised. So the camera jumps back to its original position because of
this.dolly.position.copy(this.object.position);
in the init function.

I did a workaround and added this line of code to the update function and trigger an update event by calling camera.setAttribute('orbit-controls', 'distance', '2'); in order to get the dolly position updated with the new values.

Would you consider putting this.dolly.position.copy(this.object.position); into the update function or do you have a better solution?

Thanks!

Unable to zoom in and out in PC or Mobile browsers

I copy and pasted the code on this package's main screen, at the bottom. And then added my cursor animations in (they work on my original code I have commented out, while trying this package out).

Zoom-in
Zoom-out

Both do not work on the latest builds of supported Windows PC and Samsung Smartphone browsers.

  <a-entity id="camera"
          camera="fov: 80; zoom: 1;"
          position="0 0 0"
          orbit-controls="
			  invertZoom: true;
			  autoRotate: false;
			  target: #target;
			  enableDamping: true;
			  dampingFactor: 0.125;
			  rotateSpeed:0.25;
			  minDistance:3;
			  maxDistance:100;"
          mouse-cursor="" 
          rotation="" 
          scale="" 
          visible="" 
          look-controls="">
			<a-entity cursor="fuse: true; fuseTimeout: 500"				  	  
			  position="0 0 -50"
			  geometry="primitive: ring"
			  material="color: white; shader: flat"
			  scale="1 1 1">
				<a-animation begin="mouseenter" easing="ease-bounce" attribute="scale"
				fill="backwards" from="0.5 0.5 0.5" to="0.5 0.5 0.5"></a-animation>
					<a-animation begin="cursor-fusing" easing="ease-bounce" attribute="scale"
					fill="forwards" from="0.5 0.5 0.5" to="0.5 0.5 0.5"></a-animation>
						<a-animation begin="mouseleave" easing="ease-bounce" attribute="scale"
						fill="forwards" from="0.5 0.5 0.5" to="1 1 1"></a-animation>
			</a-entity>
		</a-entity>
       <!-- Camera -->

Event listeners are not re-enabled on play()

This is a bug that happens when you toggle between two cameras. Once the orbital camera is paused and played again, you lose the ability to pan, zoom, etc, because the event listeners are not added on play.

Unknown camera type when sound entity added

When you add a sound to the scene, the ability to dollyIn/Out breaks. Using A-Frame 0.3.2.

Trying to dolly out: WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.

Issue when play is triggered after sceneEl renderstart event

Thanks for your work, really appreciated :)

in the component play function, one can find the following code

this.sceneEl.addEventListener('renderstart', this.onRenderTargetLoaded, false);
// ...
// and later ...
onRenderTargetLoaded: function () {
	console.log('component onRenderTargetLoaded')
	this.sceneEl.removeEventListener('renderstart', this.onRenderTargetLoaded, false);
	this.canvasEl = this.sceneEl.canvas;
	this.addEventListeners();
},

But if play is called after renderstart is triggered, then onRenderTargetLoaded is never called, and .addEventListeners either.

this.sceneEl.addEventListener('renderstart', this.onRenderTargetLoaded, false);
// test if renderstart has already been triggered
if( this.sceneEl.renderStarted ){
	this.onRenderTargetLoaded()
}

Thanks

camera FOV

Hi. Two possibly related questions.

  1. How can I set a camera FOV when using orbit-controls-component?
  2. What is minZoom and maxZoom for? The term zoom is used in enableZoom and zoomSpeed, but I can't get minZoom and maxZoom to do anything, since mouse-scroll is actually dolly-ing the camera. In the code, it seems all zoom-related actions (by mouse and by touch) are handled via dolly-ing. The limits minDistance and maxDistance are working fine here, but I need actual zoom.

Am I missing something? Thanks.

look-cam in VR mode

Hi,

I'd like to make an addition to this, that this controller morphs into a look-control on the enter-vr event.

Currently I have written a camera juggler component to handle this switchover:
https://github.com/morandd/dans-aframe-camera-juggler/issues

Since look-control is built in to AFrame, I think it should be safe that orbit-controls morphs itself into look-controls when entering VR. I think I can code that up and submit a PR. Any thoughts/reactions before I begin?

Gyroscope while in VR

On a current project we are trying to implement the view of an object inside of VR using the orbit camera. The problem is on a mobile device the gyroscope doesn't work or is not implemented. If there is a fix for this we have not found one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.