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
    • 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
          • Default Usage
          • Options
          • Class usage
      • Particles & Sprites

        • Fireworks
        • Text Fireworks
        • Glow Sprite
    • GIS

      • Geographic Reference
      • GeoObject
      • GeoJsonLayer
      • Tile Layer

type

Class

ForceShield is a hexagonal force field that wraps a sphere. A tri-planar hex grid, a fresnel rim, layered flow noise and a per-cell flicker build the surface; a noise threshold dissolves the shell so it can drop and raise itself, and the dissolve edge glows while it travels.

hit(point) fires an impact ring from a world-space contact and drains health, blending the surface towards red as life falls. The shield animates from its own clock, so the dissolve and the impact rings need no per-frame code.

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 * as THREE from 'three'
import { ForceShield } from 'three-vue3'

let effect: ForceShield | undefined
let timer: ReturnType<typeof setInterval> | undefined
let removeListener: (() => void) | undefined

const created = (scene, { camera, controls }) => {
  if (!camera || !controls) return

  camera.position.set(0, 0.8, 4.6)
  camera.lookAt(0, 0, 0)

  effect = new ForceShield({ radius: 1.8, hitDamage: 3 })
  scene.add(effect)

  // Clicking the field fires an impact where the ray hits it.
  const raycaster = new THREE.Raycaster()
  const pointer = new THREE.Vector2()

  const handlePointerDown = (event: PointerEvent) => {
    const canvas = controls.domElement
    const rect = canvas.getBoundingClientRect()
    pointer.set(
      ((event.clientX - rect.left) / rect.width) * 2 - 1,
      -((event.clientY - rect.top) / rect.height) * 2 + 1
    )
    raycaster.setFromCamera(pointer, camera)
    effect?.hit(raycaster.intersectObject(effect)[0]?.point)
  }

  controls.domElement.addEventListener('pointerdown', handlePointerDown)
  removeListener = () => {
    controls.domElement.removeEventListener('pointerdown', handlePointerDown)
  }

  // Automatic impacts keep the demo moving; the shield resets once depleted.
  timer = window.setInterval(() => {
    if (!effect) return
    effect.hit()
    if (effect.life < 0.6) effect.life = 1
  }, 1400)
}

onBeforeUnmount(() => {
  removeListener?.()
  removeListener = undefined
  if (timer) {
    window.clearInterval(timer)
    timer = undefined
  }
  effect?.dispose()
  effect = undefined
})
</script>

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

Options

NameTypeDefaultDescription
radiusnumber1.8optional Sphere radius.
activebooleantrueoptional Whether the shield is raised or dissolved.
revealnumber—optional Freeze the dissolve at this progress (0 visible, 1 dissolved).
revealSpeednumber3.5optional Speed of the automatic dissolve animation.
colorColorRepresentation0x26aeffoptional Base shield color.
opacitynumber0.76optional Overall surface opacity.
hexScalenumber3optional Hex grid tiling.
hexOpacitynumber0.13optional Hex cell brightness.
showHexbooleantrueoptional Draw the hexagonal cell grid.
edgeWidthnumber0.06optional Hex seam width.
fresnelPowernumber1.8optional Fresnel falloff exponent.
fresnelStrengthnumber1.75optional Fresnel edge brightness.
fadeStartnumber0optional Y below which the shield fades to the ground; -1 disables it.
flashSpeednumber0.6optional Cell flicker speed.
flashIntensitynumber0.11optional Cell flicker brightness.
noiseScalenumber1.3optional Dissolve noise scale.
noiseEdgeColorColorRepresentation0x26aeffoptional Color of the dissolve edge.
noiseEdgeWidthnumber0.02optional Width of the dissolve edge.
noiseEdgeIntensitynumber10optional Brightness of the dissolve edge.
noiseEdgeSmoothnessnumber0.5optional Sharpness of the dissolve edge.
flowScalenumber2.4optional Flow noise scale.
flowSpeednumber1.13optional Flow noise speed.
flowIntensitynumber4optional Flow noise brightness.
hitRingSpeednumber1.75optional Speed of the impact ring.
hitRingWidthnumber0.12optional Thickness of the impact ring.
hitMaxRadiusnumber0.85optional Maximum angular radius of the impact ring.
hitDurationnumber1.8optional Seconds an impact stays visible.
hitIntensitynumber4.1optional Brightness of the impact.
hitImpactRadiusnumber0.3optional Angular radius of the contact highlight.
hitDamagenumber5optional Health removed per hit, in percent.
lifenumber1optional Initial shield health (1 intact, 0 depleted).

Class usage

import * as THREE from 'three'
import { ForceShield } from 'three-vue3'

const shield = new ForceShield({ radius: 1.8 })
scene.add(shield)

// The dissolve and impact rings advance from the shield's own clock.
// Dissolve out, then raise it again:
shield.setActive(false)
shield.setActive(true)

// Fire an impact at a world-space point:
shield.hit(new THREE.Vector3(1, 0.6, 1.2))

// On teardown:
shield.dispose()
Edit this page on GitHub
Last Updated:
Contributors: Shing Rui
Prev
Signal Wave