-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25d45d2
commit 8503aec
Showing
6 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* @file Icosahedron Buffer | ||
* @private | ||
*/ | ||
|
||
import { IcosahedronGeometry, Vector3, Matrix4 } from 'three' | ||
|
||
import { BufferRegistry } from '../globals' | ||
import GeometryBuffer from './geometry-buffer' | ||
import { BufferData, BufferParameters } from './buffer' | ||
|
||
const scale = new Vector3() | ||
const target = new Vector3() | ||
const up = new Vector3() | ||
const eye = new Vector3(0, 0, 0) | ||
|
||
export interface IcosahedronBufferData extends BufferData { | ||
heightAxis: Float32Array | ||
depthAxis: Float32Array | ||
size: Float32Array | ||
} | ||
|
||
/** | ||
* Icosahedron buffer. Draws Icosahedrons. | ||
* | ||
* @example | ||
* var icosahedronBuffer = new IcosahedronBuffer({ | ||
* position: new Float32Array([ 0, 3, 0, -2, 0, 0 ]), | ||
* color: new Float32Array([ 1, 0, 1, 0, 1, 0 ]), | ||
* size: new Float32Array([ 2, 1.5 ]), | ||
* heightAxis: new Float32Array([ 0, 1, 1, 0, 2, 0 ]), | ||
* depthAxis: new Float32Array([ 1, 0, 1, 0, 0, 2 ]) | ||
* }) | ||
*/ | ||
class IcosahedronBuffer extends GeometryBuffer { | ||
updateNormals = true | ||
|
||
_heightAxis: Float32Array | ||
_depthAxis: Float32Array | ||
_size: Float32Array | ||
|
||
constructor (data: IcosahedronBufferData, params: Partial<BufferParameters> = {}) { | ||
super(data, params, new IcosahedronGeometry(1, 0)) | ||
|
||
this.setAttributes(data, true) | ||
} | ||
|
||
applyPositionTransform (matrix: Matrix4, i: number, i3: number) { | ||
target.fromArray(this._heightAxis as any, i3) | ||
up.fromArray(this._depthAxis as any, i3) | ||
matrix.lookAt(eye, target, up) | ||
|
||
scale.set(this._size[ i ], up.length(), target.length()) | ||
matrix.scale(scale) | ||
} | ||
|
||
setAttributes (data: Partial<IcosahedronBufferData> = {}, initNormals?: boolean) { | ||
if (data.size) this._size = data.size | ||
if (data.heightAxis) this._heightAxis = data.heightAxis | ||
if (data.depthAxis) this._depthAxis = data.depthAxis | ||
|
||
super.setAttributes(data, initNormals) | ||
} | ||
} | ||
|
||
BufferRegistry.add('icosahedron', IcosahedronBuffer) | ||
|
||
export default IcosahedronBuffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters