-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy pathhyperballstick-buffer.ts
64 lines (59 loc) · 2.41 KB
/
hyperballstick-buffer.ts
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
/**
* @file Hyperball Stick Buffer
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @private
*/
import { ExtensionFragDepth } from '../globals'
import { calculateMinArray } from '../math/array-utils'
import CylinderGeometryBuffer, { CylinderGeometryBufferDefaultParameters } from './cylindergeometry-buffer'
import HyperballStickImpostorBuffer, { HyperballStickImpostorBufferDefaultParameters } from './hyperballstickimpostor-buffer'
import { BufferData } from './buffer'
export interface HyperballStickBufferData extends BufferData {
position1: Float32Array
position2: Float32Array
color2: Float32Array
radius: Float32Array
radius2: Float32Array
}
const HyperballStickBufferDefaultParameters = Object.assign({
disableImpostor: false
}, CylinderGeometryBufferDefaultParameters, HyperballStickImpostorBufferDefaultParameters)
type HyperballStickBufferParameters = typeof HyperballStickBufferDefaultParameters
/**
* Hyperball stick buffer. Depending on the value {@link ExtensionFragDepth} and
* `params.disableImpostor` the constructor returns either a
* {@link CylinderGeometryBuffer} or a {@link HyperballStickImpostorBuffer}
* @implements {Buffer}
*
* @example
* var hyperballStickBuffer = new HyperballStickBuffer({
* position1: new Float32Array([ 0, 0, 0 ]),
* position2: new Float32Array([ 2, 2, 2 ]),
* color: new Float32Array([ 1, 0, 0 ]),
* color2: new Float32Array([ 0, 1, 0 ]),
* radius: new Float32Array([ 1 ]),
* radius2: new Float32Array([ 2 ])
* });
*/
class HyperballStickBuffer {
/**
* @param {Object} data - attribute object
* @param {Float32Array} data.position1 - from positions
* @param {Float32Array} data.position2 - to positions
* @param {Float32Array} data.color - from colors
* @param {Float32Array} data.color2 - to colors
* @param {Float32Array} data.radius - from radii
* @param {Float32Array} data.radius2 - to radii
* @param {Float32Array} data.picking - picking ids
* @param {BufferParameters} params - parameter object
*/
constructor (data: HyperballStickBufferData, params: Partial<HyperballStickBufferParameters> = {}) {
if (!ExtensionFragDepth || (params && params.disableImpostor)) {
data.radius = calculateMinArray(data.radius, data.radius2)
return new CylinderGeometryBuffer(data, params)
} else {
return new HyperballStickImpostorBuffer(data, params)
}
}
}
export default HyperballStickBuffer