# CoalFlow组件

使用CoalFlow组件可以创建煤流效果,由 @tx3d/extension 包提供。

import { Vector3 } from 'three';
import { CoalFlow } from '@tx3d/extension';

const beltWidthArr = [ 1.2, 1.8, 1.2, 1.6, 1.2, 1.2, 1.2 ];
const pathArr = [
    
    [
        new Vector3( -50, 1.5, 0 ),
        new Vector3( -40, 1.5, 0 ),
        new Vector3( -30, 5.5, 0 ),
        new Vector3( -20, 5.5, 0 ),
        new Vector3( -10, 1.5, 0 ),
        new Vector3( 0, 1.5, 0 )
    ],
    [ [ 0, 1.5, 0 ], [ 15, 1.5, 0 ] ],
    [ [ 30, 1.5, -5 ], [ 15, 1.5, -5 ] ],
    [ [ 15, 0, -10 ], [ 15, 0, 15 ] ],
    [ [ 25, -1.5, 15 ], [ 0, -4, 15 ] ],
    [ [ 0, -5.5, 15 ], [ 0, -5.5, -20 ] ]

];

// !!点和点直接的距离不能小于机尾或机头自带的皮带长度,目前大约是3米。

const coalFlowArr = [];
for ( let i = 0, il = pathArr.length; i < il; i++ ) {

    const params = {

        path: pathArr[ i ],
        briquetteList: [ 
            
            '../assets/models/皮带机/煤块/煤块1.glb', 
            '../assets/models/皮带机/煤块/煤块2.glb', 
            '../assets/models/皮带机/煤块/煤块3.glb',
            '../assets/models/皮带机/煤块/煤块4.glb', 
            '../assets/models/皮带机/煤块/煤块5.glb', 
            '../assets/models/皮带机/煤块/煤块6.glb',
            '../assets/models/皮带机/煤块/煤块7.glb', 
            '../assets/models/皮带机/煤块/煤块8.glb', 
            '../assets/models/皮带机/煤块/煤块9.glb',
            '../assets/models/皮带机/煤块/煤块10.glb', 
            '../assets/models/皮带机/煤块/煤块11.glb'
        
        ],
        beltSpeed: 2.5,                 // 皮带转动速度,单位:米每秒
        beltWidth: beltWidthArr[i],     // 皮带的宽度
        startup: true,                  // 皮带开关
        briquetteLoad: 25,              // 煤流量
        isLoad: false,                  // 是否按照煤流量填满煤
        scaleMax: 2,                    // 煤块缩放的最大值
        scaleMin: 1                     // 煤块缩放的最小值

    };

    // 煤块第一次移动到末端触发
    params.firstEndCall = () => {

        console.log("煤块第一次移动到末端");

    };

    if ( i == 0 || i == 2 || i == 3 || i == 4 ) {

        // 产生煤块
        params.generateBriquette = true;

    }

    // 创建煤流
    const entity = engine.createEntity( { transform: { position: [ 0, 0, 0 ] } } );
    const lastBelt = entity.addComponent( CoalFlow, params );

    coalFlowArr.push( lastBelt );

};

// 设置皮带搭接关系
coalFlowArr[1].receiveBriquette = coalFlowArr[0];
coalFlowArr[3].receiveBriquette = coalFlowArr[1];
coalFlowArr[3].receiveBriquette = coalFlowArr[2];
coalFlowArr[4].receiveBriquette = coalFlowArr[3];
coalFlowArr[5].receiveBriquette = coalFlowArr[4];

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

提示

CoalFlow组件初始化参数,详见CoalFlowParameters

# 属性

🌏 receiveBriquette 接收其他煤块

//数组中第一个煤流 接收 第零个煤流 生产的煤块
coalFlowArr[1].receiveBriquette = coalFlowArr[0];
1
2

🌏 flowSpeed 煤流速度

// 获取煤流速度
const speed = coalFlow.flowSpeed;

// 设置煤流速度
coalFlow.flowSpeed = 2.5;
1
2
3
4
5

🌏 startup 煤流开关

// 开启煤流
coalFlow.startup = true;
1
2

🌏 briquetteLoad 煤流量

// 获取煤流量
const briquetteLoad = coalFlow.briquetteLoad;

// 设置煤流量
coalFlow.briquetteLoad = 25;
1
2
3
4
5

🌏 generateBriquette 生产煤块

// 设置生产煤块
coalFlow.generateBriquette = true;
1
2

# 接口

🌏 addCoals 添加煤块


let position = [Math.random() * 50, 0, 0];
coalFlow.addCoals({ position: position, count: 10,width:1.2, length: 2 });

1
2
3
4
Last Updated: 8/30/2023, 9:51:49 AM