Skip to content
On this page

SphereGeometry

SphereGeometry is a component for a sphere with a given radius.

Incomplete spheres can be created through the use of different values of phiStart, phiLength, thetaStart and thetaLength.

Any modifications to the properties will update the underlying THREE.BufferGeometry.

Example

Click me to view the example code
vue
<template>
  <div style="width: 100vh; height: 100vh;">
    <Renderer :antialias="true">
      <PerspectiveCamera :position="[5, 5, 5]" :up="[0, 0, 1]">
        <OrbitControls />
      </PerspectiveCamera>
      <Scene background="#f9f9f9">
        <Mesh>
          <MeshNormalMaterial />
          <SphereGeometry :radius="2" :width-segments="24" :height-segments="24" />
        </Mesh>
        <AmbientLight />
      </Scene>
    </Renderer>
  </div>
</template>

<script setup lang="ts">
import { Renderer, Scene } from "@janvorisek/drie";
import { PerspectiveCamera, OrbitControls } from "@janvorisek/drie";
import { Mesh, SphereGeometry, MeshNormalMaterial } from "@janvorisek/drie";
</script>

Props

Prop nameDescriptionTypeDefault
name Name of the geometry.string""
radius Sphere radius.number1
widthSegments Number of horizontal segments.
Minimum value is 3.
number32
heightSegmentsNumber of vertical segments.
Minimum value is 2
number16
phiStart Specify horizontal starting angle.number0
phiLength Specify horizontal sweep angle size.number2 * Math.PI
thetaStart Specify vertical starting anglenumber0
thetaLength Specify vertical sweep angle sizenumberMath.PI

Expose

three

You can access the managed THREE.BufferGeometry instance using the exposed three property.

Example code

template
<SphereGeometry ref="geometry" />
ts
const geometry = ref(null);

onMounted(() => {
  // Do something with the THREE.BufferGeometry instance
  const threeGeometry = geometry.value.three;
});

Released under the MIT License.