-
Notifications
You must be signed in to change notification settings - Fork 168
/
cylinderimpostor-buffer.ts
88 lines (73 loc) · 2.72 KB
/
cylinderimpostor-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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* @file Cylinder Impostor Buffer
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @private
*/
// @ts-ignore: unused import Vector3 required for declaration only
import { Matrix4, Vector3 } from 'three'
import '../shader/CylinderImpostor.vert'
import '../shader/CylinderImpostor.frag'
import MappedAlignedBoxBuffer from './mappedalignedbox-buffer'
import { BufferDefaultParameters, BufferParameters, BufferParameterTypes, BufferTypes } from './buffer'
import { CylinderBufferData } from './cylinder-buffer'
export const CylinderImpostorBufferDefaultParameters = Object.assign({
openEnded: false
}, BufferDefaultParameters)
export type CylinderImpostorBufferParameters = BufferParameters & { openEnded: boolean }
const CylinderImpostorBufferParameterTypes = Object.assign({
openEnded: { updateShader: true }
}, BufferParameterTypes)
/**
* Cylinder impostor buffer.
*
* @example
* var cylinderimpostorBuffer = new CylinderImpostorBuffer({
* position1: new Float32Array([ 0, 0, 0 ]),
* position2: new Float32Array([ 1, 1, 1 ]),
* color: new Float32Array([ 1, 0, 0 ]),
* color2: new Float32Array([ 0, 1, 0 ]),
* radius: new Float32Array([ 1 ])
* });
*/
class CylinderImpostorBuffer extends MappedAlignedBoxBuffer {
parameterTypes = CylinderImpostorBufferParameterTypes
get defaultParameters() { return CylinderImpostorBufferDefaultParameters }
parameters: CylinderImpostorBufferParameters
isImpostor = true
vertexShader = 'CylinderImpostor.vert'
fragmentShader = 'CylinderImpostor.frag'
/**
* make cylinder impostor buffer
* @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 - radii
* @param {Picker} data.picking - picking ids
* @param {BufferParameters} params - parameter object
*/
constructor (data: CylinderBufferData, params: Partial<CylinderImpostorBufferParameters> = {}) {
super(data, params)
this.addUniforms({
'modelViewMatrixInverse': { value: new Matrix4() },
'ortho': { value: 0.0 }
})
this.addAttributes({
'position1': { type: 'v3', value: null },
'position2': { type: 'v3', value: null },
'color2': { type: 'c', value: null },
'radius': { type: 'f', value: null }
})
this.setAttributes(data)
this.makeMapping()
}
getDefines (type?: BufferTypes) {
const defines = MappedAlignedBoxBuffer.prototype.getDefines.call(this, type)
if (!this.parameters.openEnded) {
defines.CAP = 1
}
return defines
}
}
export default CylinderImpostorBuffer