# Heatmap2D组件
使用Heatmap2D组件可以为实体添加2D热力图。
import { MathUtils } from 'three';
import { Heatmap2D, RenderOrder } from '@tx3d/core';
// 随机生成特征点数据
const featurePoints = [];
for ( let i = 0; i < 500; i++ ) {
const x = MathUtils.randFloat( -5000.0, 5000.0 );
const z = MathUtils.randFloat( -5000.0, 5000.0 );
const v = MathUtils.randFloat( 0.0, 1.0 );
featurePoints.push( {
point: [ x, 0.0, y ],
value: v
} );
}
// 创建一个实体
const entity = engine.createEntity();
// 添加一个2D热力图组件
const heatmap2D = entity.addComponent( Heatmap2D, {
renderOrder: RenderOrder.Overlay,
featurePoints: featurePoints
} );
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
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
提示
Heatmap2D组件初始化参数,详见Heatmap2DParameters。
# 接口
🌏 updateHeatmap 更新热力图
import { MathUtils } from 'three';
// 随机生成新的特征点数据
const featurePoints = [];
for ( let i = 0; i < 500; i++ ) {
const x = MathUtils.randFloat( -5000.0, 5000.0 );
const z = MathUtils.randFloat( -5000.0, 5000.0 );
const v = MathUtils.randFloat( 0.0, 1.0 );
featurePoints.push( {
point: [ x, 0.0, y ],
value: v
} );
}
// 更新2D热力图
heatmap2D.updateHeatmap( {
featurePoints: featurePoitns
} );
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
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
← Group组件 Heatmap3D组件 →