in packages/layers/flyline/src/Grid.ts [59:135]
declare onStart: () => void
declare onEnd: () => void
declare onLand: () => void
constructor(config) {
this.conf = { ...confDefault, ...config }
if (this.conf.type === 'empty') {
return this
}
if (this.conf.type !== 'custom') {
if (!this.conf.pointStart) {
console.error('lack of pointStart')
}
if (!this.conf.pointEnd) {
console.error('lack of pointEnd')
}
}
/** @QianXun 头尾调换位置,让飞线的头和color的头一致 */
if (this.conf.pointStart && this.conf.pointEnd) {
this.conf.pointStart = transToVector3(this.conf.pointStart)
this.conf.pointEnd = transToVector3(this.conf.pointEnd)
}
this.onStart = this.conf.onStart
this.onEnd = this.conf.onEnd
this.onLand = this.conf.onLand
if (this.conf.type === 'onPlane') {
this.points = getGrid2Bezier(
this.conf.pointStart,
this.conf.pointEnd,
this.conf.segment,
this.conf.minHeight,
this.conf.maxHeight,
this.conf.baseH,
this.conf.incline
)
} else if (this.conf.type === 'onSphere' || this.conf.type === 'onShpere') {
this.points = getGrid2BezierAddSlerp(
this.conf.pointStart,
this.conf.pointEnd,
this.conf.segment,
this.conf.radius,
this.conf.minHeight,
this.conf.maxHeight
)
} else if (this.conf.type === 'linear') {
this.points = []
for (let i = 0; i < this.conf.segment; i++) {
const p = this.conf.pointStart.clone().lerp(this.conf.pointEnd, i / (this.conf.segment - 1))
this.points[i * 3 + 0] = p.x
this.points[i * 3 + 1] = p.y
this.points[i * 3 + 2] = p.z
}
} else if (this.conf.type === 'sandwich') {
this.points = getGrid2BezierMonotone(
this.conf.pointStart,
this.conf.pointEnd,
this.conf.segment,
this.conf.tension
)
} else if (this.conf.type === 'custom') {
this.points = this.conf.points // 不生成轨道
this.points = dimReduce(this.points)
if (this.points.length / 3 !== this.conf.segment) {
console.warn(`路径长度(${this.points.length / 3})与配置(${this.conf.segment})不符`)
this.conf.segment = this.points.length / 3
}
} else {
console.error('轨道生成器参数错误, type: ', this.conf.type)
}
this.padding = 0
this.pointsBuffer = new this.conf.bufferType(this.points)
this.updateBufferPadding(this.conf.padding)
}