Skip to content

Align

Calculates a bounding box around its children and aligns them as a group within their parent. The component measures its contents and realigns on every frame unless cacheKey is set.

Usage

vue
<script setup lang="ts">
import { Align, OrbitControls } from '@tresjs/cientos'
import { TresCanvas } from '@tresjs/core'
</script>

<template>
  <TresCanvas clear-color="#222">
    <TresPerspectiveCamera />
    <OrbitControls />

    <TresAxesHelper :scale="2" />

    <Align top right back>
      <TresMesh>
        <TresBoxGeometry />
        <TresMeshNormalMaterial />
      </TresMesh>
    </Align>
  </TresCanvas>
</template>

Props

All props are optional.

PropDescription
topIf true, aligns bounding box bottom to 0 on the y-axis
bottomIf true, aligns bounding box top to 0 on the y-axis.
leftIf true, aligns bounding box right to 0 on the x-axis.
rightIf true, aligns bounding box left to 0 on the x-axis.
frontIf true, aligns bounding box back to 0 on the z-axis.
backIf true, aligns bounding box front to 0 on the z-axis.
disableIf true, disables alignment on all axes.
disableXIf true, disables alignment on the x-axis.
disableYIf true, disables alignment on the y-axis.
disableZIf true, disables alignment on the z-axis.
preciseSee Box3.setFromObject.
onAlignCallback that fires when updating, after measurement.
cacheKeyIf set, component will only update when cacheKey's value changes. If unset, component will update every frame.

OnAlignCallbackProps

ts
export interface OnAlignCallbackProps {
  /** The next parent above <Align /> */
  parent: Object3D
  /** The outmost container group of the <Align /> component */
  container: Object3D
  width: number
  height: number
  depth: number
  boundingBox: Box3
  boundingSphere: Sphere
  center: Vector3
  verticalAlignment: number
  horizontalAlignment: number
  depthAlignment: number
}