# Class: Shape

轮廓组件的基类。
为元素添加*该组件的子类*可以创建一个可用于交互的轮廓。

> 💡 只要创建了轮廓，在点击该物体时就可以触发事件：
> + touch-shape: 点击物体事件，回调参数为[IShapeTouchEvent](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeTouchEvent)；
> + drag-shape: 拖拽物体事件，回调参数为[IShapeDragEvent](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeDragEvent)；
> + untouch-shape: 松开物体事件，回调参数为[IShapeTouchEvent](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeTouchEvent)；
>
> 绑定事件的方法可参考以下代码：
>
> ``` <xr-node sphere-shape bind:touch-shape="handleTouchShape"></xr-node> ```

> 💡 如果想要将轮廓可视化来确认轮廓大小，可以在同一个元素下添加[ShapeGizmos](ShapeGizmos)组件，或在标签上添加`shape-gizmo`属性（对MeshShape不起作用）。

**`abstract`**

## Type parameters

| Name | Type |
| :------ | :------ |
| `T` | extends [`IShapeData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeData) = `any` |

## Hierarchy

- [`Component`](Component)

  ↳ **`Shape`**

  ↳↳ [`SphereShape`](SphereShape)

  ↳↳ [`MeshShape`](MeshShape)

  ↳↳ [`CapsuleShape`](CapsuleShape)

  ↳↳ [`CubeShape`](CubeShape)

## Table of contents

### Constructors

- constructor

### Events

- onAdd
- onRelease
- onRemove
- onTick
- onUpdate

### Properties

- implType
- priority
- schema
- shadowRoot
- EVENTS

### Accessors

- el
- scene
- type
- version

### Methods

- getBasicImpl
- getData
- getGLTFRootShape
- getShadowShapes
- initDelegates
- resetListeners
- setAsShadow
- setData
- setDataOne

## Constructors

### constructor

• **new Shape**()

#### Type parameters

| Name | Type |
| :------ | :------ |
| `T` | extends [`IShapeData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeData) = `any` |

#### Inherited from

[Component](Component).[constructor](Component#constructor)

## Events

### onAdd

▸ **onAdd**(`parent`, `data`): `void`

所挂载的`element`被挂载到场景时触发的回调。

#### Parameters

| Name | Type |
| :------ | :------ |
| `parent` | [`Element`](Element) |
| `data` | `T` |

#### Returns

`void`

#### Inherited from

[Component](Component).[onAdd](Component#onAdd)

___

### onRelease

▸ **onRelease**(`data`): `void`

从被挂载的`element`上被移除，或是`element`被销毁时，触发的回调。
一般用于释放持有的资源。

#### Parameters

| Name | Type |
| :------ | :------ |
| `data` | [`IShapeData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeData) |

#### Returns

`void`

#### Inherited from

[Component](Component).[onRelease](Component#onRelease)

___

### onRemove

▸ **onRemove**(`parent`, `data`): `void`

所挂载的`element`从父节点`parent`被移除时，或者自己从`element`上被移除时，触发的回调。
一般用于消除功能的运作。
**如果一个组件的元素直接被销毁了，那这个组件就不会经历onRemove而是直接进入onRelease。**

#### Parameters

| Name | Type |
| :------ | :------ |
| `parent` | [`Element`](Element) |
| `data` | [`IShapeData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeData) |

#### Returns

`void`

#### Inherited from

[Component](Component).[onRemove](Component#onRemove)

___

### onTick

▸ **onTick**(`dateTime`, `data`): `void`

渲染每帧触发的回调。

#### Parameters

| Name | Type |
| :------ | :------ |
| `dateTime` | `number` |
| `data` | `T` |

#### Returns

`void`

#### Inherited from

[Component](Component).[onTick](Component#onTick)

___

### onUpdate

▸ **onUpdate**(`data`, `preData`): `void`

数据更新时触发的回调。

#### Parameters

| Name | Type |
| :------ | :------ |
| `data` | `T` |
| `preData` | `T` |

#### Returns

`void`

#### Inherited from

[Component](Component).[onUpdate](Component#onUpdate)

## Properties

### implType

• **implType**: `ShapeImplType`

___

### priority

• `Readonly` **priority**: `number` = `400`

自定义组件的更新优先级。

#### Overrides

[Component](Component).[priority](Component#priority)

___

### schema

• `Readonly` **schema**: [`IComponentSchema`](/miniprogram/dev/reference/xr-frame/api/interfaces/IComponentSchema) = `{}`

自定义组件的`schema`。

#### Inherited from

[Component](Component).[schema](Component#schema)

___

### shadowRoot

• `Optional` **shadowRoot**: `GLTFAbstractShape`

___

### EVENTS

▪ `Static` **EVENTS**: `string`[]

#### Overrides

[Component](Component).[EVENTS](Component#EVENTS)

## Accessors

### el

• `get` **el**(): [`Element`](Element)

挂载的元素。

#### Returns

[`Element`](Element)

___

### scene

• `get` **scene**(): [`Scene`](Scene)

当前场景。

#### Returns

[`Scene`](Scene)

___

### type

• `get` **type**(): [`EShapeType`](/miniprogram/dev/reference/xr-frame/api/enums/EShapeType)

#### Returns

[`EShapeType`](/miniprogram/dev/reference/xr-frame/api/enums/EShapeType)

___

### version

• `get` **version**(): `number`

当前版本，每次有数据更新都会增加，可以用作和其他组件合作的依据。

#### Returns

`number`

## Methods

### getBasicImpl

▸ **getBasicImpl**(): `BasicShape`

#### Returns

`BasicShape`

___

### getData

▸ **getData**(`key`): [`IShapeData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeData)[`T`]

获取一个当前值。

#### Type parameters

| Name | Type |
| :------ | :------ |
| `T` | extends keyof [`IShapeData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeData) |

#### Parameters

| Name | Type |
| :------ | :------ |
| `key` | `T` |

#### Returns

[`IShapeData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeData)[`T`]

#### Inherited from

[Component](Component).[getData](Component#getData)

___

### getGLTFRootShape

▸ **getGLTFRootShape**(): [`Shape`](Shape)

#### Returns

[`Shape`](Shape)

___

### getShadowShapes

▸ **getShadowShapes**(): [`Shape`](Shape)[]

#### Returns

[`Shape`](Shape)[]

___

### initDelegates

▸ **initDelegates**(`el`): `void`

#### Parameters

| Name | Type |
| :------ | :------ |
| `el` | [`Element`](Element) |

#### Returns

`void`

___

### resetListeners

▸ **resetListeners**(): `void`

#### Returns

`void`

___

### setAsShadow

▸ **setAsShadow**(`root`, `transform`): `void`

#### Parameters

| Name | Type |
| :------ | :------ |
| `root` | `GLTFAbstractShape` |
| `transform` | `TQS` |

#### Returns

`void`

___

### setData

▸ **setData**(`data`): `void`

不通过`xml`而是直接设置`data`，注意值的类型需要和`schema`中一致。

#### Parameters

| Name | Type |
| :------ | :------ |
| `data` | `Partial` |

#### Returns

`void`

#### Inherited from

[Component](Component).[setData](Component#setData)

___

### setDataOne

▸ **setDataOne**(`key`, `value`): `void`

设置一个数据。

#### Type parameters

| Name | Type |
| :------ | :------ |
| `T` | extends keyof [`IShapeData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeData) |

#### Parameters

| Name | Type |
| :------ | :------ |
| `key` | `T` |
| `value` | [`IShapeData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeData)[`T`] |

#### Returns

`void`

#### Inherited from

[Component](Component).[setDataOne](Component#setDataOne)
