-
Notifications
You must be signed in to change notification settings - Fork 167
/
shape-component.ts
63 lines (53 loc) · 1.75 KB
/
shape-component.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
/**
* @file Shape Component
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @private
*/
import { ComponentRegistry } from '../globals'
import Component, { ComponentParameters } from './component'
import Stage from '../stage/stage'
import Shape from '../geometry/shape'
type ShapeRepresentationType = 'buffer'
/**
* Component wrapping a {@link Shape} object
*
* @example
* // get a shape component by adding a shape object to the stage
* var shape = new NGL.Shape( "shape" );
* shape.addSphere( [ 0, 0, 0 ], [ 1, 0, 0 ], 1.5 );
* var shapeComponent = stage.addComponentFromObject( shape );
* shapeComponent.addRepresentation( "buffer" );
*/
class ShapeComponent extends Component {
constructor (stage: Stage, readonly shape: Shape, params: Partial<ComponentParameters> = {}) {
super(stage, shape, Object.assign({ name: shape.name }, params))
}
/**
* Component type
* @type {String}
*/
get type () { return 'shape' }
/**
* Add a new shape representation to the component
* @param {String} type - the name of the representation, one of:
* buffer.
* @param {BufferRepresentationParameters} params - representation parameters
* @return {RepresentationComponent} the created representation wrapped into
* a representation component object
*/
addRepresentation (type: ShapeRepresentationType, params: { [k: string]: any } = {}) {
return this._addRepresentation(type, this.shape, params)
}
getBoxUntransformed () {
return this.shape.boundingBox
}
getCenterUntransformed () {
return this.shape.center
}
dispose () {
this.shape.dispose()
super.dispose()
}
}
ComponentRegistry.add('shape', ShapeComponent)
export default ShapeComponent