---
agentTools:
  projectIndex: https://whsjs.readme.io/llms.txt
---

# 3D transforms

[block:api-header]
{
  "type": "get",
  "title": ".position"
}
[/block]

[block:callout]
{
  "type": "success",
  "title": "Is used in:",
  "body": "- `MeshComponent`\n- `LightComponent`\n- `CameraComponent`"
}
[/block]

**position** is a 3D vector ([`THREE.Vector3`](https://threejs.org/docs/index.html#Reference/Math/Vector3)) object that defines where mesh is located in space.

[block:code]
{
  "codes": [
    {
      "code": "ball.position.set(10, 20, 45);\n\nball.position.x // -> 10\nball.position.y // -> 20\nball.position.z // -> 45\n",
      "language": "javascript"
    }
  ]
}
[/block]

## Modifying values and methods

That's several examples of how you can modify positon:

* `ball.position.set( x, y, z )`
* `ball.position.setX( x )`, (`.setX()`, `.setY()`, `.setZ()` methods).
* `ball.position = new THREE.Vector3( x, y, z )`

There are a lot of other methods that `.position` handles as a `THREE.Vector3`. You may see the [list of methods](https://threejs.org/docs/index.html#Reference/Math/Vector3.set) at Three.js documentation.

[block:callout]
{
  "type": "info",
  "body": "`.position` is automatically applied to physics object if you use a Physics version [Todo: add link]."
}
[/block]

[block:api-header]
{
  "type": "get",
  "title": ".rotation"
}
[/block]

[block:callout]
{
  "type": "success",
  "title": "Is used in:",
  "body": "- `MeshComponent`\n- `LightComponent`\n- `CameraComponent`"
}
[/block]

> Used in: `MeshComponent`, `LightComponent`, `CameraComponent`

**rotation** is a [`THREE.Euler`](https://threejs.org/docs/index.html#Reference/Math/Euler) with *x, y and z* values and has almost same methods as a `.position`. It defines a rotation regarding object position.

[block:code]
{
  "codes": [
    {
      "code": "ball.rotation.set(10, 20, 45);\n\nball.rotation.x // -> 10\nball.rotation.y // -> 20\nball.rotation.z // -> 45",
      "language": "javascript"
    }
  ]
}
[/block]

## Modifying values and methods

Commonly used:

* `ball.rotation.set( x, y, z )`
* `ball.rotation.setX( x )`, (`.setX()`, `.setY()`, `.setZ()` methods).
* `ball.rotation = new THREE.Euler( x, y, z )`

See [list of THREE.Euler methods](https://threejs.org/docs/index.html#Reference/Math/Euler.set) at Three.js documentation.

[block:callout]
{
  "type": "info",
  "body": "`.rotation` will be converted to a _quaternion_ and applied to it's physics object linked to the component. (Only if you use a Physics version [Todo: add link])."
}
[/block]

[block:api-header]
{
  "type": "get",
  "title": ".quaternion"
}
[/block]

[block:callout]
{
  "type": "success",
  "title": "Is used in:",
  "body": "- `MeshComponent` \n- `LightComponent`\n- `CameraComponent`"
}
[/block]

**quaternion**, [`THREE.Quaternion`](https://threejs.org/docs/index.html#Reference/Math/Quaternion) is another way to rotate 3D object in space. It has *x, y, z and w* values.

[block:code]
{
  "codes": [
    {
      "code": "// Convert euler to quaternion.\nball.quaternion.setFromEuler(new THREE.Euler(Math.PI / 2, 0, 0));\n// Set values.\nball.quaternion.set(10, 20, 45, 60);\n\nball.quaternion.x // -> 10\nball.quaternion.y // -> 20\nball.quaternion.z // -> 45\nball.quaternion.w // -> 60",
      "language": "javascript"
    }
  ]
}
[/block]

## Modifying values and methods

Commonly used:

* `ball.quaternion.set( x, y, z, w )`
* `ball.quaternion.setX( x )`, (`.setX()`, `.setY()`, `.setZ()`, `.setW()` methods).
* `ball.quaternion = new THREE.Quaternion( x, y, z, w )`
* `ball.quaternion.setFromEuler(new THREE.Euler( x, y, z ))`

See [list of THREE.Quaternion methods](https://threejs.org/docs/index.html#Reference/Math/Quaternion.set) at Three.js documentation.

[block:api-header]
{
  "type": "get",
  "title": ".scale"
}
[/block]

[block:callout]
{
  "type": "success",
  "title": "Is used in:",
  "body": "- `MeshComponent`"
}
[/block]

**scale**, [`THREE.Vector3`](https://threejs.org/docs/index.html#Reference/Math/Vector3) is a vector that defines mesh scale.

[block:code]
{
  "codes": [
    {
      "code": "ball.scale.set(2, 2, 2)\n\nball.scale.x // -> 2\nball.scale.y // -> 2\nball.scale.z // -> 2",
      "language": "javascript"
    }
  ]
}
[/block]

## Modifying values and methods

Commonly used:

* `ball.scale.set( x, y, z )`
* `ball.scale.setX( x )`, (`.setX()`, `.setY()`, `.setZ()` methods).
* `ball.scale= new THREE.Vector3( x, y, z )`

See [list of THREE.Vector3 methods](https://threejs.org/docs/index.html#Reference/Math/Vector3.set) at Three.js documentation.