Class: AmmoCollisionBuilder

mylib2020.AmmoCollisionBuilder()

Ammo の衝突検出形状や剛体(形状が変化しない物体)を生成する。

Constructor

new AmmoCollisionBuilder()

Source:

Methods

addBoundingBoxRigidBody(threeObject, params) → {Ammo.btRigidBody}

threeObject を包むような直方体の衝突検出範囲を生成し threeObject.userData.collisionShape に代入する。
さらに、その形状に基づく剛体を生成して threeObject.userData.rigidBody に代入する。
Parameters:
Name Type Default Description
threeObject THREE.Object3D Three.js の物体。
params Object null 次のようなキーでパラメータ指定する。null のとき、デフォルト値が使用される。
  • showCollision - boolean 衝突検知範囲を可視化するか (デフォルト: false)
  • scale - THREE.Vector3 衝突検知範囲の拡大縮小率 (デフォルト: x, y, z 全て 1.0)
  • offset - THREE.Vector3 衝突検知範囲の中心からのオフセット (デフォルト: x, y, z 全て 0.0)
  • movable - boolean ユーザが動かす予定がある物体は true にする。(デフォルト: false)
  • mass - number 重さ。単位は Kg (デフォルト: 1)
  • friction - number 面で接触する物体に対する摩擦。(デフォルト: 0.5)
  • rollingFriction - number 線や点で接触する、転がる物体に対する摩擦。(デフォルト: 0.1)
  • restitution - number 反発の程度。(デフォルト: 0)
  • freezeRotationX - boolean X 軸中心の回転をさせないかどうか。(デフォルト: false)
  • freezeRotationY - boolean Y 軸中心の回転をさせないかどうか。(デフォルト: false)
  • linearDamping - number 移動に対する空気抵抗。大きいほど減速しやすい。(デフォルト: 0)
  • angularDamping - number 回転に対する空気抵抗。大きいほど回転が止まりやすい。(デフォルト: 0)
  • margin - number 衝突検出範囲に余裕を持たせる場合の距離。(デフォルト: 0.01)
Source:
Returns:
生成された剛体。失敗した場合は null が返る。
Type
Ammo.btRigidBody

addBoundingBoxShape(threeObject, params) → {Ammo.btCompoundShape}

threeObject を包むような直方体の衝突検出範囲を生成し threeObject.userData.collisionShape に代入する。
Parameters:
Name Type Default Description
threeObject THREE.Object3D Three.js の物体。
params Object null 次のようなキーでパラメータ指定する。null のとき、デフォルト値が使用される。
  • showCollision - boolean 衝突検知範囲を可視化するか (デフォルト: false)
  • scale - THREE.Vector3 衝突検知範囲の拡大縮小率 (デフォルト: x, y, z 全て 1.0)
  • offset - THREE.Vector3 衝突検知範囲の中心からのオフセット (デフォルト: x, y, z 全て 0.0)
Source:
Returns:
Type
Ammo.btCompoundShape

addBoundingCylinderRigidBody(threeObject, params) → {Ammo.btRigidBody}

threeObject を包むような円柱の衝突検出範囲を生成し threeObject.userData.collisionShape に代入する。
※真円かつ、底面と上面が同じ大きさの円柱しか生成しない。
さらに、その形状に基づく剛体を生成して threeObject.userData.rigidBody に代入する。
Parameters:
Name Type Default Description
threeObject THREE.Object3D Three.js の物体。
params Object null 次のようなキーでパラメータ指定する。null のとき、デフォルト値が使用される。
  • showCollision - boolean 衝突検知範囲を可視化するか (デフォルト: false)
  • axis - string 円柱の中心軸 "x", "y", "z" のいずれか (デフォルト: y)
  • scale - THREE.Vector3 衝突検知範囲の拡大縮小率 (デフォルト: x, y, z 全て 1.0)
  • offset - THREE.Vector3 衝突検知範囲の中心からのオフセット (デフォルト: x, y, z 全て 0.0)
  • movable - boolean ユーザが動かす予定がある物体は true にする。(デフォルト: false)
  • mass - number 重さ。単位は Kg (デフォルト: 1)
  • friction - number 面で接触する物体に対する摩擦。(デフォルト: 0.5)
  • rollingFriction - number 線や点で接触する、転がる物体に対する摩擦。(デフォルト: 0.1)
  • restitution - number 反発の程度。(デフォルト: 0)
  • freezeRotationX - boolean X 軸中心の回転をさせないかどうか。(デフォルト: false)
  • freezeRotationY - boolean Y 軸中心の回転をさせないかどうか。(デフォルト: false)
  • linearDamping - number 移動に対する空気抵抗。大きいほど減速しやすい。(デフォルト: 0)
  • angularDamping - number 回転に対する空気抵抗。大きいほど回転が止まりやすい。(デフォルト: 0)
  • margin - number 衝突検出範囲に余裕を持たせる場合の距離。(デフォルト: 0.01)
Source:
Returns:
Type
Ammo.btRigidBody

addBoundingCylinderShape(threeObject, params) → {Ammo.btCompoundShape}

threeObject を包むような円柱の衝突検出範囲を生成し threeObject.userData.collisionShape に代入する。
※真円かつ、底面と上面が同じ大きさの円柱しか生成しない。
Parameters:
Name Type Default Description
threeObject THREE.Object3D Three.js の物体。
params Object null 次のようなキーでパラメータ指定する。null のとき、デフォルト値が使用される。
  • showCollision - boolean 衝突検知範囲を可視化するか (デフォルト: false)
  • axis - string 円柱の中心軸 "x", "y", "z" のいずれか (デフォルト: y)
  • scale - THREE.Vector3 衝突検知範囲の拡大縮小率 (デフォルト: x, y, z 全て 1.0)
  • offset - THREE.Vector3 衝突検知範囲の中心からのオフセット (デフォルト: x, y, z 全て 0.0)
Source:
Returns:
Type
Ammo.btCompoundShape

addBoundingSphereRigidBody(threeObject, params) → {Ammo.btRigidBody}

threeObject を包むような球体の衝突検出範囲を生成し threeObject.userData.collisionShape に代入する。
さらに、その形状に基づく剛体を生成して threeObject.userData.rigidBody に代入する。
Parameters:
Name Type Default Description
threeObject THREE.Object3D Three.js の物体。
params Object null 次のようなキーでパラメータ指定する。null のとき、デフォルト値が使用される。
  • showCollision - boolean 衝突検知範囲を可視化するか (デフォルト: false)
  • scale - THREE.Vector3 衝突検知範囲の拡大縮小率 (デフォルト: x, y, z 全て 1.0)
  • offset - THREE.Vector3 衝突検知範囲の中心からのオフセット (デフォルト: x, y, z 全て 0.0)
  • movable - boolean ユーザが動かす予定がある物体は true にする。(デフォルト: false)
  • mass - number 重さ。単位は Kg (デフォルト: 1)
  • friction - number 面で接触する物体に対する摩擦。(デフォルト: 0.5)
  • rollingFriction - number 線や点で接触する、転がる物体に対する摩擦。(デフォルト: 0.1)
  • restitution - number 反発の程度。(デフォルト: 0)
  • freezeRotationX - boolean X 軸中心の回転をさせないかどうか。(デフォルト: false)
  • freezeRotationY - boolean Y 軸中心の回転をさせないかどうか。(デフォルト: false)
  • linearDamping - number 移動に対する空気抵抗。大きいほど減速しやすい。(デフォルト: 0)
  • angularDamping - number 回転に対する空気抵抗。大きいほど回転が止まりやすい。(デフォルト: 0)
  • margin - number 衝突検出範囲に余裕を持たせる場合の距離。(デフォルト: 0.01)
Source:
Returns:
生成された剛体。失敗した場合は null が返る。
Type
Ammo.btRigidBody

addBoundingSphereShape(threeObject, params) → {Ammo.btCompoundShape}

threeObject を包むような球体の衝突検出範囲を生成し threeObject.userData.collisionShape に代入する。
Parameters:
Name Type Default Description
threeObject THREE.Object3D Three.js の物体。
params Object null 次のようなキーでパラメータ指定する。null のとき、デフォルト値が使用される。
  • showCollision - boolean 衝突検知範囲を可視化するか (デフォルト: false)
  • scale - THREE.Vector3 衝突検知範囲の拡大縮小率 (デフォルト: x, y, z 全て 1.0)
  • offset - THREE.Vector3 衝突検知範囲の中心からのオフセット (デフォルト: x, y, z 全て 0.0)
Source:
Returns:
Type
Ammo.btCompoundShape

addBoxShape(threeObject) → {Ammo.btBoxShape}

threeObject と同じ大きさの直方体の衝突検出範囲を生成し threeObject.userData.collisionShape に代入する。
Parameters:
Name Type Description
threeObject THREE.Mesh Three.js の物体。THREE.BoxGeometry を持つ必要がある。
Source:
Returns:
Type
Ammo.btBoxShape

addCompoundRigidBody(params) → {Ammo.btRigidBody}

threeObject とその子に対して衝突検出範囲を設定し、それらを結合ものを threeObject.userData.collisionShape に代入する。
さらに、その形状に基づく剛体を生成して threeObject.userData.rigidBody に代入する。
子が userData.collisionShape を既に持っていればそれを衝突検出範囲として使う。 無い場合、子に対し addPrimitiveShape が使用され、失敗した場合は範囲設定しない。また、子が geometry を持っていない場合も衝突検出範囲を生成しない。
Parameters:
Name Type Default Description
params Object null 次のようなキーでパラメータ指定する。null のとき、デフォルト値が使用される。
  • movable - boolean ユーザが動かす予定がある物体は true にする。(デフォルト: false)
  • mass - number 重さ。単位は Kg (デフォルト: 1)
  • friction - number 面で接触する物体に対する摩擦。(デフォルト: 0.5)
  • rollingFriction - number 線や点で接触する、転がる物体に対する摩擦。(デフォルト: 0.1)
  • restitution - number 反発の程度。(デフォルト: 0)
  • freezeRotationX - boolean X 軸中心の回転をさせないかどうか。(デフォルト: false)
  • freezeRotationY - boolean Y 軸中心の回転をさせないかどうか。(デフォルト: false)
  • linearDamping - number 移動に対する空気抵抗。大きいほど減速しやすい。(デフォルト: 0)
  • angularDamping - number 回転に対する空気抵抗。大きいほど回転が止まりやすい。(デフォルト: 0)
  • margin - number 衝突検出範囲に余裕を持たせる場合の距離。(デフォルト: 0.01)
Source:
Returns:
生成された剛体。失敗した場合は null が返る。
Type
Ammo.btRigidBody

addCompoundShape(threeObject) → {Ammo.btCompoundShape}

子を持つ threeObject に対し全ての子が持つ衝突検出範囲を結合して threeObject.userData.collisionShape に代入する。
子が userData.collisionShape を既に持っていればそれを衝突検出範囲として使う。 無い場合、子に対し addPrimitiveShape が使用され、失敗した場合は範囲設定はされない。 子が geometry を持っていない場合は衝突検出範囲を生成しない。
Parameters:
Name Type Description
threeObject THREE.Object3D 子を持つ Three.js の物体。
Source:
Returns:
Type
Ammo.btCompoundShape

addConeShape(threeObject) → {Ammo.btConeShape}

threeObject と同じ大きさの円錐の衝突検出範囲を生成し threeObject.userData.collisionShape に代入する。
※底面が真円の円錐しか対応していない。つまり、 x, z の scale が等しい必要がある。
Parameters:
Name Type Description
threeObject THREE.Mesh Three.js の物体。THREE.ConeGeometry を持つ必要がある。
Source:
Returns:
Type
Ammo.btConeShape

addConvexHullShape(threeObject, vertices, scale) → {Ammo.btConvexHullShape}

頂点を包む凸包の衝突検出範囲を生成し threeObject.userData.collisionShape に代入する。
Parameters:
Name Type Description
threeObject THREE.Mesh Three.js の物体。
vertices Array.<THREE.Vector3> 物体の頂点配列。
scale THREE.Vector3 検出範囲の拡大縮小率。
Source:
Returns:
Type
Ammo.btConvexHullShape

addCylinderShape(threeObject) → {Ammo.btCylinderShape}

threeObject と同じ大きさの円柱の衝突検出範囲を生成し threeObject.userData.collisionShape に代入する。
※真円かつ、底面と上面が同じ大きさの円柱しか対応していない。つまり、 x, z の scale が等しい必要がある。
Parameters:
Name Type Description
threeObject THREE.Mesh Three.js の物体。THREE.CylinderGeometry を持つ必要がある。
Source:
Returns:
Type
Ammo.btCylinderShape

addPlaneShape(threeObject) → {Ammo.btConvexHullShape}

threeObject と同じ大きさの平面の衝突検出範囲を生成し threeObject.userData.collisionShape に代入する。
Parameters:
Name Type Description
threeObject THREE.Mesh Three.js の物体。THREE.PlaneGeometry を持つ必要がある。
Source:
Returns:
Type
Ammo.btConvexHullShape

addPrimitiveRigidBody(threeObject, params) → {Ammo.btRigidBody}

基本的な形状を geometry に持つ threeObject に対して同じ大きさの衝突検出範囲を生成し、threeObject.userData.collisionShape に代入する。
さらに、その形状に基づく剛体を生成して threeObject.userData.rigidBody に代入する。
Parameters:
Name Type Default Description
threeObject THREE.Object3D Three.js の物体。 対応する形状は次の通り。 threeObject.geometry が下記のいずれかでなければならない。
  • THREE.PlaneGeometry
  • THREE.BoxGeometry
  • THREE.SphereGeometry
  • THREE.CylinderGeometry
    ※真円かつ、底面と上面が同じ大きさの円柱しか対応していない。つまり、 x, z の scale が等しい必要がある。
  • THREE.ConeGeometry
    ※底面が真円の円錐しか対応していない。つまり、 x, z の scale が等しい必要がある。
params Object null 次のようなキーでパラメータ指定する。null のとき、デフォルト値が使用される。
  • movable - boolean ユーザが動かす予定がある物体は true にする。(デフォルト: false)
  • mass - number 重さ。単位は Kg (デフォルト: 1)
  • friction - number 面で接触する物体に対する摩擦。(デフォルト: 0.5)
  • rollingFriction - number 線や点で接触する、転がる物体に対する摩擦。(デフォルト: 0.1)
  • restitution - number 反発の程度。(デフォルト: 0)
  • freezeRotationX - boolean X 軸中心の回転をさせないかどうか。(デフォルト: false)
  • freezeRotationY - boolean Y 軸中心の回転をさせないかどうか。(デフォルト: false)
  • linearDamping - number 移動に対する空気抵抗。大きいほど減速しやすい。(デフォルト: 0)
  • angularDamping - number 回転に対する空気抵抗。大きいほど回転が止まりやすい。(デフォルト: 0)
  • margin - number 衝突検出範囲に余裕を持たせる場合の距離。(デフォルト: 0.01)
Source:
Returns:
生成された剛体。失敗した場合は null が返る。
Type
Ammo.btRigidBody

addPrimitiveShape(threeObject) → {any}

Three.js の基本的な形状と同じ大きさの衝突検出範囲を生成し、threeObject.userData.collisionShape に代入する。
対応する形状は次の通り。 threeObject.geometry が下記のいずれかでなければならない。
  • THREE.PlaneGeometry
  • THREE.BoxGeometry
  • THREE.SphereGeometry
  • THREE.CylinderGeometry
    ※真円かつ、底面と上面が同じ大きさの円柱しか対応していない。つまり、 x, z の scale が等しい必要がある。
  • THREE.ConeGeometry
    ※底面が真円の円錐しか対応していない。つまり、 x, z の scale が等しい必要がある。
Parameters:
Name Type Description
threeObject THREE.Mesh
Author:
  • (Set the text for this tag by adding docthis.authorName to your settings file.)
Source:
Returns:
成功した場合、threeObject.geometry に対応する生成された衝突検出範囲の形状が返る。次のいずれかである。
  • THREE.PlaneGeometry -> Ammo.btConvexHullShape
  • THREE.BoxGeometry -> Ammo.btBoxShape
  • THREE.SphereGeometry -> Ammo.btMultiSphereShape
  • THREE.CylinderGeometry -> Ammo.btCylinderShape
  • THREE.ConeGeometry -> Ammo.btConeShape
失敗した場合、 null が返る。
Type
any

addRigidBody(threeObject, params) → {Ammo.btRigidBody}

threeObject.userData.collisionShape に衝突検出範囲を持つ threeObject に対し剛体を生成して threeObject.userData.rigidBody に代入する。
threeObject が threeObject.userData.collisionShape に衝突検出範囲を持っていなければ何もしない。
Parameters:
Name Type Default Description
threeObject THREE.Object3D Three.js の物体。
params Object null 次のようなキーでパラメータ指定する。null のとき、デフォルト値が使用される。
  • movable - boolean ユーザが動かす予定がある物体は true にする。(デフォルト: false)
  • mass - number 重さ。単位は Kg (デフォルト: 1)
  • friction - number 面で接触する物体に対する摩擦。(デフォルト: 0.5)
  • rollingFriction - number 線や点で接触する、転がる物体に対する摩擦。(デフォルト: 0.1)
  • restitution - number 反発の程度。(デフォルト: 0)
  • freezeRotationX - boolean X 軸中心の回転をさせないかどうか。(デフォルト: false)
  • freezeRotationY - boolean Y 軸中心の回転をさせないかどうか。(デフォルト: false)
  • linearDamping - number 移動に対する空気抵抗。大きいほど減速しやすい。(デフォルト: 0)
  • angularDamping - number 回転に対する空気抵抗。大きいほど回転が止まりやすい。(デフォルト: 0)
  • margin - number 衝突検出範囲に余裕を持たせる場合の距離。(デフォルト: 0.01)
Source:
Returns:
生成された剛体。失敗した場合は null が返る。
Type
Ammo.btRigidBody

addSphereShape(threeObject) → {Ammo.btMultiSphereShape}

threeObject と同じ大きさの球体の衝突検出範囲を生成し threeObject.userData.collisionShape に代入する。
Parameters:
Name Type Description
threeObject THREE.Mesh Three.js の物体。THREE.SphereGeometry を持つ必要がある。
Source:
Returns:
Type
Ammo.btMultiSphereShape

calcBoundingBox(threeObject, scale, offset) → {Object}

threeObject を包むような直方体の大きさとローカル中心座標を計算する。
Parameters:
Name Type Description
threeObject THREE.Object3D Three.js の物体。
scale THREE.Vector3 直方体の拡大縮小率。
offset THREE.Vector3 直方体の中心に加算する値。
Source:
Returns:
  • size - 大きさ {x, y, z}
  • center - THREE.Vector3
Type
Object