ポジションコンポーネントは、3D空間の特定の場所にエンティティを配置します。位置は空間的に区切られた3つの数値で座標値をとります。
すべてのエンティティは、本質的に位置情報を持ちます。
# 例
<a-entity position="0 1 -1"></a-entity>
# Value
A-Frame uses a right-handed coordinate system where the negative Z axis extends into the screen. The table below assumes looking down the negative Z axis from the origin.
A-Frameは、マイナスZ軸が画面奥に伸びる右手座標系を採用しています。下表は、原点からマイナスのZ軸を見下ろした場合を想定しています。
Axis | Description | Default Value |
---|---|---|
x | マイナスのX軸はは左に伸びていきます プラスのX軸は右に伸びていきます | 0 |
y | マイナスのY軸は下に伸びていきます。プラスのY軸は上に伸びていきます | 0 |
z | マイナスのZ軸は画面奥に伸びていきます。プラスのY軸は画面手前に伸びていきます | 0 |
# 相対的なポジショニング
子エンティティの世界空間位置は、親となっているエンティティから継承されます。このような場面を考えてみましょう。
<a-entity id="parent" position="1 2 3">
<a-entity id="child1"></a-entity>
<a-entity id="child2" position="2 3 4"></a-entity>
</a-entity>
The world-space position of #child1
would be 1 2 3
as inherited by the
entity. In the local parent's space, #child1
's position would be 0 0 0
.
The world-space position of #child2
would be 3 5 7
, by combining the
position with the parent entity. In the parent's local space, #child2
's
position would be 2 3 4
.
Child1
のシーンでの位置は、parent
エンティティに継承された1 2 3
となります。parent
空間の中では、child1
の位置は 0 0 0
となります。
child2
のシーンでの位置は、parent
エンティティとの位置の合成により、3 5 7
となります。parent
空間の中では、child2
の位置は 2 3 4
となります。
# Updating Position
パフォーマンスと人間工学の観点から、three.js
Object3D
(opens new window) .position
Vector3
(opens new window) と .setAttribute
を使って直接位置を更新することをお勧めします。
この方法は、すべてのVector3ユーティリティ
(opens new window)にアクセスできるので簡単で、.setAttribute
のオーバーヘッドをスキップし、位置を設定するためにオブジェクトを作成する必要がないため、より高速です。
// With three.js
el.object3D.position.set(1, 2, 3);
// With .setAttribute (less recommended).
el.setAttribute('position', {x: 1, y: 2, z: 3});
また、インクリメンタルアップデート(これは単に数値を修正することです)を行ったり、Vector3 (opens new window)ユーティリティを使用したりすることもできます。
el.object3D.position.x += 1;
el.object3D.position.multiplyScalar(2);
el.object3D.position.sub(someOtherVector);
# 位置を取得する
three.js
レベルでの更新を反映させるため、A-Frameでは、.getAttribute('position')
の際に、実際のObject3D.position
ベクターオブジェクトを返します。戻り値を変更すると、エンティティ自体も変更されることに注意してください。
カメラの位置と回転の読み込みも参照してください。
# 変形の順序
変換は、この順序でエンティティに適用されます。