5.4.0

Align

Calculate and align children within their parent using bounding boxes.

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

<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.

PropDescriptionDefault
topIf true, aligns bounding box bottom to 0 on the y-axisfalse
bottomIf true, aligns bounding box top to 0 on the y-axis.false
leftIf true, aligns bounding box right to 0 on the x-axis.false
rightIf true, aligns bounding box left to 0 on the x-axis.false
frontIf true, aligns bounding box back to 0 on the z-axis.false
backIf true, aligns bounding box front to 0 on the z-axis.false
disableIf true, disables alignment on all axes.false
disableXIf true, disables alignment on the x-axis.false
disableYIf true, disables alignment on the y-axis.false
disableZIf true, disables alignment on the z-axis.false
preciseSee Box3.setFromObject.true
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.undefined

AlignCallbackOptions

export interface AlignCallbackOptions {
  /** 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
}