# 使用

Tx3d Engine物理引擎相关功能由 @tx3d/physics 包提供。Tx3d Engine目前提供LiteAmmo两种物理引擎:

🌏 Lite:内置物理引擎,提供的功能有限,目前仅支持碰撞体(CollisionBody)且仅支持立方体(BoxShape)和球体(SphereShape)两种碰撞外形。

🌏 Ammo:通过引入Ammo物理引擎库实现碰撞体、刚体、柔体、约束等物理功能。

# 初始化

使用引擎(Engine)的physicsManager属性的initialize接口初始化物理引擎。

注意

物理引擎初始化是一个异步操作。

初始化Lite物理引擎

import { LitePhysicsEngine } from '@tx3d/physics';

// 设置每一帧物理更新次数上限
engine.physicsManager.maxSubSteps = 10.0; 
// 设置每次物理更新时长,单位:秒
engine.physicsManager.fixedTimeStep = 1.0 / 120.0; 
// 初始化Lite物理引擎
engine.physicsManager.initialize( LitePhysicsEngine ).then( () => {

    // TODO:物理操作

} );
1
2
3
4
5
6
7
8
9
10
11
12

初始化Ammo物理引擎

import { AmmoPhysicsEngine } from '@tx3d/physics';

// 设置每一帧物理更新次数上限
engine.physicsManager.maxSubSteps = 10.0; 
// 设置每次物理更新时长,单位:秒
engine.physicsManager.fixedTimeStep = 1.0 / 120.0; 
// 初始化Ammo物理引擎
engine.physicsManager.initialize( AmmoPhysicsEngine, { ammoPath: './js/libs/ammo/' } ).then( () => {

    // TODO:物理操作

} );
1
2
3
4
5
6
7
8
9
10
11
12

提示

AmmoPhysicsEngine初始化参数详见AmmoPhysicsParameters

# 碰撞检测

通过为实体添加碰撞体(CollisionBody)、刚体(RigidBody)、柔体(SoftBody)实现碰撞检测,通过添加脚本(Script)组件响应触发事件碰撞事件

# 添加碰撞体

🌏 添加常规碰撞体(CollisionBody)

点击查看代码
import { BoxGeometry, Mesh, MeshPhongMaterial } from 'three';
import { BoxShape, CollisionBody, MeshProxy } from '@tx3d/core';
import { LitePhysicsEngine } from '@tx3d/physics';

// 设置每一帧物理更新次数上限
engine.physicsManager.maxSubSteps = 10.0; 
// 设置每次物理更新时长,单位:秒
engine.physicsManager.fixedTimeStep = 1.0 / 120.0; 
// 初始化Lite物理引擎
engine.physicsManager.initialize( LitePhysicsEngine ).then( () => {

    // 创建盒子实体
    const box = engine.createEntity( { transform: { position: [ 0.0, 0.5, 0.0 ] } } );

    // 创建盒子Mesh
    const mesh = new Mesh( new BoxGeometry( 1.0, 1.0, 1.0 ), new MeshPhongMaterial{ color: '#00ff00' } );

    // 添加一个Mesh组件
    box.addComponent( MeshProxy, { mesh: mesh } );

    // 添加一个碰撞体
    const body = box.addComponent( CollisionBody );

    // 添加一个Box碰撞外形
    body.addShape( new BoxShape( { size: [ 1.0, 1.0, 1.0 ] } ) );

} );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

🌏 添加实例化碰撞(InstancedCollisionBody)

点击查看代码
import { BoxGeometry, Color, DynamicDrawUsage, BoxGeometry, InstancedMesh, MathUtils, Matrix4, MeshPhongMaterial, Quaternion } from 'three';
import { BoxShape, InstancedCollisionBody, MeshProxy } from '@tx3d/core';
import { AmmoPhysicsEngine } from '@tx3d/physics';

// 设置每一帧物理更新次数上限
engine.physicsManager.maxSubSteps = 10.0; 
// 设置每次物理更新时长,单位:秒
engine.physicsManager.fixedTimeStep = 1.0 / 120.0; 
// 初始化Ammo物理引擎
engine.physicsManager.initialize( AmmoPhysicsEngine, { ammoPath: './js/libs/ammo/' } ).then( () => {

    // 创建实例化盒子实体
    const box = engine.createEntity();

    // 创建100实例化盒子Mesh
    const instancedMesh = new InstancedMesh(

        new BoxGeometry( 1.0, 1.0, 1.0 ),
        new MeshPhongMaterial(),
        100

    );
    instancedMesh.instanceMatrix.setUsage( DynamicDrawUsage );
    instancedMesh.name = 'Box'; // 注:必须设置Mesh名称

    // 随机初始化盒子位置&颜色
    const matrix = new Matrix4();
    const color = new Color();
    const position = new Vector3();
    const scale = new Vector3( 1.0, 1.0, 1.0 );
    const quaternion = new Quaternion( 0.0, 0.0, 0.0, 1.0 );

    for ( let i = 0; i < 100; i++ ) {

        const s = MathUtils.randFloat( 1.0, 2.0 );
        
        scale.set( s, s, s );

        position.set( MathUtils.randFloat( -40.0, 40.0 ), 0.5 * s, MathUtils.randFloat( -40.0, 40.0 ) );
        matrix.compose( position, quaternion, scale );

        instancedMesh.setMatrixAt( i, matrix );
        instancedMesh.setColorAt( i, color.setHex( 0xff0000 ) );

    }

    // 添加一个MeshProxy组件
    box.addComponent( MeshProxy, { mesh: instancedMesh } );

    // 添加一个实例化碰撞体组件
    const body = box.addComponent( InstancedCollisionBody, { mesh: 'Box' } );

    // 添加一个Box外形
    body.addShape( new BoxShape( { size: [ 1.0, 1.0, 1.0 ] } ) );

} );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

注意

LitePhysicsEngine不支持InstancedCollisionBody!

# 添加刚体

🌏 添加常规刚体(RigidBody)

点击查看代码
import { BoxeGeometry, Mesh, MeshPhongMaterial, SphereGeometry } from 'three';
import { BoxShape, MeshProxy, RigidBody, SphereShape } from '@tx3d/core';
import { AmmoPhysicsEngine } from '@tx3d/physics';

// 设置每一帧物理更新次数上限
engine.physicsManager.maxSubSteps = 10.0; 
// 设置每次物理更新时长,单位:秒
engine.physicsManager.fixedTimeStep = 1.0 / 120.0; 
// 初始化Ammo物理引擎
engine.physicsManager.initialize( AmmoPhysicsEngine, { ammoPath: './js/libs/ammo/' } ).then( () => {

    // 创建地面实体
    const plane = engine.createEntity( { transform: { position: [ 0.0, -0.5, 0.0 ] } } );

    // 创建地面Mesh
    const planeMesh = new Mesh( 

        new BoxGeometry( 100, 1.0, 100 ),
        new MeshPhongMaterial( { color: '#aaaaaa' } )

    );

    // 添加MeshProxy组件
    plane.addComponent( MeshProxy, { static: true, mesh: planeMesh } );

    // 添加静态刚体
    let body = plane.addComponent( RigidBody );

    // 添加Box碰撞外形
    body.addShape( new BoxShape( { size: [ 100, 1.0, 100 ] } ) );

    // 创建球实体
    const sphere = engine.createEntity( { transform: { position: [ 0.0, 50.0, 0.0 ] } } );

    // 创建球Mesh
    const sphereMesh = new Mesh(

        new SphereGeometry( 2.0, 64, 64 ),
        new MeshPhongMaterial( { color: '#ff0000' } )

    );

    // 添加MeshProxy组件
    sphere.addComponent( MeshProxy, { mesh: sphereMesh } ); 

    // 添加动态刚体
    body = sphere.addComponent( RigidBody, { static: false, mass: 5.0 } );

    // 添加Sphere碰撞外形
    body.addShape( new SphereShape( { radius: 2.0 } ) );

} );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

注意

LitePhysicsEngine不支持RigidBody!

🌏 添加实例化刚体(InstancedRigidBody)

点击查看代码
import { BoxGeometry, Color, DynamicDrawUsage, InstancedMesh, Matrix4, Mesh, MeshPhongMaterial, Quaternion, SphereGeometry, Vector3 } from 'three';
import { BoxShape, InstancedRigidBody, MeshProxy, RigidBody, SphereShape } from '@tx3d/core';
import { AmmoPhysicsEngine } from '@tx3d/physics';

// 设置每一帧物理更新次数上限
engine.physicsManager.maxSubSteps = 10.0; 
// 设置每次物理更新时长,单位:秒
engine.physicsManager.fixedTimeStep = 1.0 / 120.0; 
// 初始化Ammo物理引擎
engine.physicsManager.initialize( AmmoPhysicsEngine, { ammoPath: './js/libs/ammo/' } ).then( () => {

    // 创建地面实体
    const plane = engine.createEntity( { transform: { position: [ 0.0, -0.5, 0.0 ] } } );

    // 创建地面Mesh
    const planeMesh = new Mesh( 

        new BoxGeometry( 100, 1.0, 100 ),
        new MeshPhongMaterial( { color: '#aaaaaa' } )

    );

    // 添加MeshProxy组件
    plane.addComponent( MeshProxy, { mesh: planeMesh } );

    // 添加静态刚体
    const body = plane.addComponent( RigidBody, { static: true } );

    // 添加Box碰撞外形
    body.addShape( new BoxShape( { size: [ 100, 1.0, 100 ] } ) );

    // 创建实例化盒子实体
    const box = engine.createEntity( { transform: { position: [ 0.0, 15.0, 0.0 ] } } );

    // 创建100实例化盒子Mesh
    const boxInstancedMesh = new InstancedMesh(

        new BoxGeometry( 1.0, 1.0, 1.0 ),
        new MeshPhongMaterial(),
        100

    );
    boxInstancedMesh.instanceMatrix.setUsage( DynamicDrawUsage );
    boxInstancedMesh.name = 'Box'; // 注:必须设置名称

    const matrix = new Matrix4();
    const color = new Color();
    const position = new Vector3();
    const scale = new Vector3( 1.0, 1.0, 1.0 );
    const quaternion = new Quaternion( 0.0, 0.0, 0.0, 1.0 );

    // 随机初始化盒子位置&颜色
    for ( let i = 0; i < 100; i++ ) {

        position.set( Math.random() - 0.5, Math.random() * 2.0, Math.random() + 0.5 );
        matrix.compose( position, quaternion, scale );

        boxInstancedMesh.setMatrixAt( i, matrix );
        boxInstancedMesh.setColorAt( i, color.setHex( 0xffffff * Math.random() ) );

    }

    // 添加Mesh组件
    box.addComponent( MeshProxy, { mesh: boxInstancedMesh } );

    // 添加动态实例化刚体
    const boxBody = box.addComponent( InstancedRigidBody,{ static: false, mesh: 'Box', mass: 5.0 } );

    // 添加Box碰撞外形
    boxBody.addShape( new BoxShape( { size: [ 1.0, 1.0, 1.0 ] } ) ); 

    // 创建实例化球实体
    const sphere = engine.createEntity( { transform: { position: [ 0.0, 15.0, 0.0 ] } } );

    // 创建100个实例化球Mesh
    const sphereInstancedMesh = new InstancedMesh(

        new SphereGeometry( 0.5, 64, 64 ),
        new MeshPhongMaterial(),
        100

    );

    sphereInstancedMesh.instanceMatrix.setUsage( DynamicDrawUsage );
    sphereInstancedMesh.name = 'Sphere'; // 注:必须设置名称

    // 随机初始化球位置&颜色
    for ( let i = 0; i < 100; i++ ) {

        position.set( Math.random() - 0.5, Math.random() * 2.0, Math.random() + 0.5 );
        matrix.compose( position, quaternion, scale );

        sphereInstancedMesh.setMatrixAt( i, matrix );
        sphereInstancedMesh.setColorAt( i, color.setHex( 0xffffff * Math.random() ) );

    }

    // 添加MeshProxy组件
    sphere.addComponent( MeshProxy, { mesh: sphereInstancedMesh } );

    // 添加动态实例化刚体
    const sphereBody = sphere.addComponent( InstancedRigidBody,{ static: false, mesh: 'Sphere', mass: 5.0 } );

    // 添加Sphere碰撞外形
    sphereBody.addShape( new SphereShape( { radius: 0.5 } ) );

    // 间隔6秒随机更新实例化盒子和球位置
    setInterval( () => {

        position.set( 0.0, Math.random() + 1.0, 0.0 );

        boxBody.setInstanceTransform( { position: position }, Math.floor( Math.random() * 100 ) );

        position.set( 0.0, Math.random() + 1.0, 0.0 );

        sphereBody.setInstanceTransform( { position: position }, Math.floor( Math.random() * 100 ) );

    }, 1000 / 60 );    

} );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

注意

LitePhysicsEngine不支持InstancedRigidBody!

# 添加柔体

🌏 添加柔体(SoftBody)

点击查看代码
import { BufferGeometry, DoubleSide, Line, LineBasicMaterial, Mesh, MeshLambertMaterial, PlaneGeometry, Vector3 } from 'three';
import { BoxShape, MeshProxy, RigidBody, SoftBody, SphereShape } from '@tx3d/core';
import { AmmoPhysicsEngine } from '@tx3d/physics';

// 设置每一帧物理更新次数上限
engine.physicsManager.maxSubSteps = 10.0; 
// 设置每次物理更新时长,单位:秒
engine.physicsManager.fixedTimeStep = 1.0 / 120.0; 
// 初始化Ammo物理引擎
engine.physicsManager.initialize( AmmoPhysicsEngine, { ammoPath: './js/libs/ammo/' } ).then( () => {

    // 创建柔体(绳索)
    const ropeNumSegments = 10, ropeLength = 5.0, ropeMass = 3;
    const ropePos = new Vector3(1.0, 3.8, -1.0);
    const ropePositions = [], ropeIndices = [];

    // 创建绳索实体
    const rope = engine.createEntity({ transform: { position: ropePos } });

    const segmentLength = ropeLength / ropeNumSegments;
    
    for (var i = 0; i < ropeNumSegments + 1; i++) {

        ropePositions.push(new Vector3(ropePos.x, ropePos.y + i * segmentLength, ropePos.z));

    }

    // 创建绳索line
    const ropeGeometry = new BufferGeometry().setFromPoints(ropePositions);
    const ropeMaterial = new LineBasicMaterial({ color: 0x000000 });
    const line = new Line(ropeGeometry, ropeMaterial);
    line.name = 'rope';
    line.castShadow = true;
    line.receiveShadow = true;

    // 添加到实体场景结点
    rope.transform.addObject3D(line);

    // 添加柔体(绳索)
    const ropeSoftBody = rope.addComponent(SoftBody, {

        type: 'Rope',   //  柔体类型
        margin: 0.2,
        mesh: {

            name: 'rope',                       // line名称
            ropeLength: ropeLength,             // 绳索长度
            ropeNumSegments: ropeNumSegments,   // 绳索分段

        }

    })

    // 柔体添加锚点
    const influence = 1.0;
    ropeSoftBody.appendAnchor(0, ballBody, true, influence);
    ropeSoftBody.appendAnchor(ropeNumSegments, armBody, true, influence);

     // 创建柔体(布料)
    const clothWidth = 40;
    const clothHeight = 30;
    const clothNumSegmentsZ = clothWidth * 10;
    const clothNumSegmentsY = clothHeight * 10;

    // 创建布料实体
    const cloth = engine.createEntity({

        transform: {

            position: [0.0, 20, 0.0],
            rotation: [Math.PI * 0.5, 0, 0]

        }
        
    });

    // 创建布料mesh
    clothMesh = new Mesh(

        new PlaneGeometry(clothWidth, clothHeight, clothNumSegmentsZ, clothNumSegmentsY),
        new MeshLambertMaterial({ color: '#e43f31', side: DoubleSide }),

    );
    clothMesh.name = 'clothMesh';
    clothMesh.castShadow = true;
    clothMesh.receiveShadow = false;

    // 添加MeshProxy组件
    cloth.addComponent(MeshProxy, { mesh: clothMesh });

    // 添加柔体(布料)
    const clothSoftBody = cloth.addComponent(SoftBody, {

        type: 'Cloth',
        margin: 0.08,
        mesh: {

            name: 'clothMesh',              // cloth名称
            clothWidth: clothWidth,         // cloth宽
            clothHeight: clothHeight,       // cloth高
            clothNumSegmentsZ: clothNumSegmentsZ,   // cloth Z方向分段
            clothNumSegmentsY: clothNumSegmentsY,   // cloth Y方向分段

        }

    });

    // 柔体设置质量
    clothSoftBody.setTotalMass(1.0, false);
    // 柔体设置配置
    clothSoftBody.setConfig({ viterations: 10, piterations: 10 });

    // 创建柔体(软体)
    const sphere = engine.createEntity({ transform: { position: [0.0, 1.5, 0.0] } });

    // 创建mesh
    const sphereGeometry = new SphereGeometry(1.5, 32, 16);
    sphereGeometry.translate(0, 2, -5);
    const sphereMesh = new Mesh(sphereGeometry, new MeshLambertMaterial({ color: '#e43f31' }));
    sphereMesh.name = 'Sphere';
    sphereMesh.castShadow = true;
    sphereMesh.receiveShadow = true;
    sphereMesh.frustumCulled = false;

    // 添加mesh组件
    sphere.addComponent(MeshProxy, { mesh: sphereMesh });

    // 添加柔体(软体)
    const sphereSoftBody = sphere.addComponent(SoftBody, {

        type: 'Volume',
        margin: 0.005,
        randomizeConstraints: false,
        mesh: { name: 'Sphere' }

    });

    // 柔体设置总质量
    sphereSoftBody.setTotalMass(15.0, false);

    // 柔体设置配置
    sphereSoftBody.setConfig({

        viterations: 40,
        piterations: 40,
        kDF: 1.0,
        kDP: 0.1,
        collisions: 0x11,
        kPR: 120,
    })

} );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

注意

LitePhysicsEngine不支持SoftBody!

# 事件响应

点击查看代码
import { BoxGeometry, Mesh, MeshPhongMaterial, SphereGeometry } from 'three';
import { BoxShape, Collision, CollisionBody, MeshProxy, RigidBody, Script, SphereShape } from '@tx3d/core';
import { AmmoPhysicsEngine } from '@tx3d/physics';

/**
 * 碰撞接触脚本 
 */
class Contact extends Script {

    onTriggrEnter( collision: Collision ): void {

        console.log( 'Trigger Enter' );

    }

    onTriggerStay( collision: Collision ): void {

        console.log( 'Trigger Stay' );

    }

    onTriggerExit( collision: Collision ): void {

        console.log( 'Trigger Exit' );

    }

    onCollisionEnter( collision: Collision ): void {

        console.log( 'Collision Enter' );

    }

    onCollisionStay( collision: Collision ): void {

        console.log( 'Collision Stay' );

    }

    onCollisionExit( collision: Collision ): void {

        console.log( 'Collision Exit' );

    }

}

// 设置每一帧物理更新次数上限
engine.physicsManager.maxSubSteps = 10.0; 
// 设置每次物理更新时长,单位:秒
engine.physicsManager.fixedTimeStep = 1.0 / 120.0; 
// 初始化Ammo物理引擎
engine.physicsManager.initialize( AmmoPhysicsEngine, { ammoPath: './js/libs/ammo/' } ).then( () => {

    // 创建地面实体
    const plane = engine.createEntity( { transform: { position: [ 0.0, -0.5, 0.0 ] } } );

    // 创建地面Mesh
    const planeMesh = new Mesh( 

        new BoxGeometry( 100, 1.0, 100 ),
        new MeshPhongMaterial( { color: '#aaaaaa' } )

    );

    // 添加MeshProxy组件
    plane.addComponent( MeshProxy, { mesh: planeMesh } );

    // 添加脚本组件
    plane.addComponent( Contact );

    // 添加静态刚体
    let body = plane.addComponent( RigidBody );

    // 添加Box碰撞外形
    body.addShape( new BoxShape( { size: [ 100, 1.0, 100 ] } ) );

    // 创建盒子实体
    const box = engine.createEntity( { transform: { position: [ 0.0, 2.0, 0.0 ] } } );

    // 创建盒子Mesh
    const boxMesh = new Mesh(

        new BoxGeometry( 4.0, 4.0, 4.0 ),
        new MeshPhongMaterial( { color: '#00ff00' } )

    );

    // 添加MeshProxy组件
    box.addComponent( MeshProxy, { mesh: boxMesh } );

    // 添加脚本组件
    box.addComponent( Contact );

    // 添加碰撞体
    body = box.addComponent( CollisionBody );

    // 添加Box碰撞外形
    body.addShape( new BoxShape( { size: [ 4.0, 4.0, 4.0 ] } ) );

    // 创建球实体
    const sphere = engine.createEntity( { transform: { position: [ 0.0, 50.0, 0.0 ] } } );

    // 创建球Mesh
    const sphereMesh = new Mesh(

        new SphereGeometry( 2.0, 64, 64 ),
        new MeshPhongMaterial( { color: '#ff0000' } )

    );

    // 添加MeshProxy组件
    sphere.addComponent( MeshProxy, { mesh: sphereMesh } );
    
    // 添加脚本组件
    sphere.addComponent( Contact ); 

    // 添加动态刚体
    body = sphere.addComponent( RigidBody, { static: false, mass: 5.0 } );

    // 添加Sphere碰撞外形
    body.addShape( new SphereShape( { radius: 2.0 } ) );

} );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

提示

  1. 碰撞体与碰撞体、碰撞体与刚体碰撞时会触发onTriggerXXX事件。
  2. 刚体与刚体碰撞时会触发onCollisionXXX事件。

注意

由于Ammo引擎自身的原因,目前碰撞体与柔体、刚体与柔体、柔体与柔体碰撞无法触发事件!!!

# 碰撞外形

当前物理引擎支持的碰撞外形如下所示:

🌏 BoxShape 盒子碰撞外形

提示

BoxShape初始化参数详见BoxShapeParameters

🌏 CapsuleShape 胶囊体碰撞外形

提示

CapsuleShape初始化参数详见CapsuleShapeParameters

注意

LitePhysicsEngine不支持CapsuleShape!

🌏 ConeShape 圆椎体碰撞外形

提示

ConeShape初始化参数详见ConeShapeParameters

注意

LitePhysicsEngine不支持ConeShape!

🌏 CylinderShape 圆柱体碰撞外形

提示

CylinderShape初始化参数详见CylinderShapeParameters

注意

LitePhysicsEngine不支持CylinderShape!

🌏 PlaneShape 平面碰撞外形

提示

PlaneShape初始化参数详见PlaneShapeParameters

注意

LitePhysicsEngine不支持PlaneShape!

🌏 SphereShape 球体碰撞外形

提示

SphereShape初始化参数详见SphereShapeParameters

🌏 TriangleMeshShape 三角网格碰撞外形

提示

TriangleMeshShape初始化参数详见TriangleMeshShapeParameters

注意

LitePhysicsEngine不支持TriangleMeshShape!

# 约束

# 创建约束

🌏 创建点到点约束:使用引擎(Engine)的physicsManager属性的createPoint2PointConstraint创建点到点约束。

🌏 创建铰链约束:使用引擎(Engine)的physicsManager属性的createHingeConstraint创建铰链约束。

🌏 创建滑块约束:使用引擎(Engine)的physicsManager属性的createSliderConstraint创建滑块约束。

🌏 椎体扭曲约束:使用引擎(Engine)的physicsManager属性的createConeTwistConstraint创建椎体扭曲约束。

Last Updated: 6/18/2024, 1:38:19 PM