Three.js: Issue when setting camera.position to Vector3

Created on 21 May 2017  ·  2Comments  ·  Source: mrdoob/three.js

Description of the problem

I noticed that when setting the position for PerspectiveCamera to a THREE.Vector3 nothing is displayed, but when I directly set the values, it works just fine.

camera.position.set( 0, 0, 0 );

works, but

var newVector = new THREE.Vector3(0, 0, 0)
camera.position.set(newVector);

doesn't. I was wondering if this is a bug?

See the following two JSFiddle:
L8-10: https://jsfiddle.net/4zqkn7yw/5/
L9: https://jsfiddle.net/4zqkn7yw/4/

Three.js version
  • [x] r82
Browser
  • [x] All of them
  • [ ] Chrome
  • [ ] Firefox
  • [ ] Internet Explorer
OS
  • [x] All of them
  • [ ] Windows
  • [ ] macOS
  • [ ] Linux
  • [ ] Android
  • [ ] iOS
Hardware Requirements (graphics card, VR Device, ...)
Question

Most helpful comment

Object3D's position, rotation, quaternion and scale properties are immutable.

The following pattern is invalid:

object.position = vector;

Instead, you must use either

object.position.set( x, y, z );

or

object.position.copy( vector );

See Object3D.js.

All 2 comments

That's not a bug. Try this:

var newVector = new THREE.Vector3( 0, 0, 0 )
camera.position.copy( newVector );

Have a look at the docs of Vector3 in order to understand the API.

Object3D's position, rotation, quaternion and scale properties are immutable.

The following pattern is invalid:

object.position = vector;

Instead, you must use either

object.position.set( x, y, z );

or

object.position.copy( vector );

See Object3D.js.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

manthrax picture manthrax  ·  3Comments

cnsdato picture cnsdato  ·  4Comments

ekatzenstein picture ekatzenstein  ·  5Comments

Julz666 picture Julz666  ·  5Comments

hjlld picture hjlld  ·  3Comments