Three Vue3Three Vue3
Guide
Demo
AI Agents
  • English
  • 简体中文
GitHub
Guide
Demo
AI Agents
  • English
  • 简体中文
GitHub
    • Getting Started
    • Scene
    • Parameter Bus
    • SkyBox
    • Model Loader

      • Component Loader
      • Function Loader
    • Popup
    • Callout
    • Movable Element
    • Animation
    • Model Rotator
      • Default Usage
      • Options
      • Methods
    • Picker
    • Fit Camera
    • Mesh

      • Wave Circle Mesh
      • Flow Line Mesh
    • Effect

      • Nature

        • Rain
        • Snow
        • Water
        • Water Pool
        • Sandy Beach
      • Sky & Atmosphere

        • Sky Dome
        • HeightFog
        • Nebula Galaxy
      • Light

        • Bloom
        • Sweep Light
        • Light Gradient
        • Light Pillar
        • Radar Sweep
        • Signal Wave
        • Force Shield
      • Particles & Sprites

        • Fireworks
        • Text Fireworks
        • Glow Sprite
    • GIS

      • Geographic Reference
      • GeoObject
      • GeoJsonLayer
      • Tile Layer

type

Class

ModelRotator spins any THREE.Object3D on its own requestAnimationFrame loop, keeping the animation independent of the scene render loop. Pause, resume, change speed or axis at any time, and call dispose() when the model is removed.

Default Usage

Click me to view the codes
<template>
  <tv-scene class="scene" bg-color="rgb(40, 42, 54)" @created="created"></tv-scene>
</template>

<script lang="ts" setup>
import { onBeforeUnmount } from 'vue'
import { GLTFLoader, ModelRotator } from 'three-vue3'
import type * as THREE from 'three'

let rotator: ModelRotator | undefined
let model: THREE.Group | undefined

const created = async (scene, { camera }) => {
  camera.position.set(0, 1.5, 3)
  camera.lookAt(0, 0, 0)

  model = await GLTFLoader('/models/perseverance-draco.glb', { draco: true })
  model.position.set(0, 0, 0)
  scene.add(model)

  rotator = new ModelRotator(model, {
    axis: 'y',
    speed: 0.5,
    autoStart: true
  })
}

onBeforeUnmount(() => {
  rotator?.dispose()
  rotator = undefined
  if (model) {
    model.parent?.remove(model)
    model = undefined
  }
})
</script>

<style>
.scene {
  margin-top: 10px;
  margin-bottom: 16px;
  width: 100%;
  height: 300px;
}
</style>

Options

NameTypeDefaultDescription
axis'x' | 'y' | 'z''y'optional Rotation axis.
speednumber0.5optional Rotation speed in radians per second.
autoStartbooleantrueoptional Start rotating when the instance is created.

Methods

NameParametersDescription
play() => voidStarts or resumes rotation.
pause() => voidPauses rotation, keeping the current angle.
stop() => voidPauses and resets the rotation to zero.
setSpeed(speed: number) => voidUpdates the rotation speed.
setAxis(axis: 'x' | 'y' | 'z') => voidUpdates the rotation axis.
dispose() => voidStops the loop and releases the animation frame.
Edit this page on GitHub
Last Updated:
Contributors: Shing Rui
Prev
Animation
Next
Picker