@pixi/3d
    Preparing search index...

    Class Geometry3D

    A mesh's vertex and index data: positions plus optional normals, UVs, tangents, colours and skinning data, in separate buffers or interleaved in one

    Only positions are required. Inputs can be raw Float32Array data or pixi Attributes, including the quantized integer formats glTF files use (KHR_mesh_quantization). getAttributeData reads any attribute back as floats, however it is stored.

    The first time a geometry is drawn it's copied into buffers shared with other geometries, so later edits to its data don't show. Build a new geometry for a new shape, call unload after an occasional edit, or make it Geometry3DOptions#dynamic if you rewrite it every frame.

    const geometry = new Geometry3D({
    positions: new Float32Array([
    -1, -1, 0,
    1, -1, 0,
    0, 1, 0,
    ]),
    indices: new Uint16Array([0, 1, 2]),
    });

    Geometry3DOptions For the constructor options

    Hierarchy (View Summary)

    Index
    bounds3D: Box

    The geometry's local bounding box, used for picking and for a mesh's local bounds

    Culling tests Geometry3D#boundsSphere instead.

    const size = geometry.bounds3D.getSize();
    
    boundsSphere: Sphere

    The sphere around Geometry3D#bounds3D, which frustum culling tests

    Computed once, at construction, so later edits to the positions or to bounds3D don't reach culling.

    const radius = geometry.boundsSphere.radius;
    
    dynamic: boolean

    Whether the geometry stays out of the shared buffers; see Geometry3DOptions#dynamic

    hasMorphNormals: boolean

    Whether the morph targets bend the normals as well as the positions; see Geometry3DOptions#morphTargets

    morphTargetCount: number = 0

    Count of morph targets; a mesh drawing the geometry takes one weight per target

    const weights = new Float32Array(geometry.morphTargetCount);
    
    defaultOptions: Geometry3DOptions = ...

    Defaults for every new Geometry3D

    Each primitive, such as SphereGeometry, copies these into its own defaultOptions when its module loads, so changing one of them here later doesn't reach the primitives; set theirs instead.

    Geometry3D.defaultOptions.quantizeNormals = false;
    
    • get attributeKey(): string
      Advanced

      The attribute names and formats, ignoring strides, offsets and buffers

      Geometries with the same key are packed into the same shared buffers. A geometry with positions, normals and UVs has the key aNormal:snorm16x4|aPosition:float32x3|aUV:float32x2|.

      Returns string

    • get indices(): Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

      The index data

      Returns Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

      const triangleCount = geometry.indices.length / 3;
      
    • set indices(
          value: Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>,
      ): void

      Sets the index data

      Parameters

      • value: Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

        New indices, three per triangle for triangle-list

      Returns void

    • get normals(): TypedArray | undefined

      The normal data as stored, or undefined when the geometry has no normals

      With Geometry3DOptions#quantizeNormals (the default) it's an Int16Array with four values per vertex; on an interleaved geometry, the whole interleaved buffer as a Uint8Array. To read normals as floats, three per vertex, use getAttributeData.

      Returns TypedArray | undefined

      const normals = getAttributeData(geometry, 'aNormal', 3);
      const normal = new Vector3().fromArray(normals, vertexIndex * 3);
    • set normals(value: TypedArray): void

      Sets the normal data; ignored when the geometry has no normals

      Parameters

      • value: TypedArray

        New data, in the format the normals are stored in

      Returns void

    • get positions(): TypedArray

      The position data as stored

      A Float32Array, unless the geometry was built from quantized positions; on an interleaved geometry, the whole interleaved buffer as a Uint8Array. On a dynamic geometry that isn't interleaved, write through it and update its buffer. To read positions as floats, three per vertex, use getAttributeData.

      Returns TypedArray

      const trail = new Geometry3D({ positions: new Float32Array(64 * 3), dynamic: true });

      trail.positions.set(points);
      trail.attributes.aPosition.buffer.update();
    • set positions(value: TypedArray): void

      Sets the position data

      Parameters

      • value: TypedArray

        New data, covering at least as many vertices as before

      Returns void

    • get tangents(): TypedArray | undefined

      The tangent data as stored, or undefined when the geometry has no tangents

      With Geometry3DOptions#quantizeTangents (the default) it is an Int16Array with four values per vertex. Read tangents as floats, four per vertex, with getAttributeData.

      Returns TypedArray | undefined

    • set tangents(value: TypedArray): void

      Sets the tangent data; ignored when the geometry has no tangents

      Parameters

      • value: TypedArray

        New data, in the format the tangents are stored in

      Returns void

    • get uvs(): TypedArray | undefined

      The UV data as stored, or undefined when the geometry has no UVs

      Read them as floats, two per vertex, with getAttributeData.

      Returns TypedArray | undefined

    • set uvs(value: TypedArray): void

      Sets the UV data; ignored when the geometry has no UVs

      Parameters

      • value: TypedArray

        New data, covering every vertex

      Returns void

    • get vertexCount(): number

      Number of vertices

      Returns number

      const colors = new Float32Array(geometry.vertexCount * 4);
      
    • get EMPTY(): Geometry3D
      Advanced

      A shared geometry with no vertices, which a Mesh3D holds until it's given a geometry

      A mesh on it draws nothing and compiles no shader. Assign it to a mesh's geometry to stop the mesh drawing; to hide a mesh for a while, visible = false is cheaper to toggle. Only Mesh3D takes it: a BatchedMesh3D slot in a pass needs a real geometry.

      Its destroy does nothing, as with pixi's Texture.EMPTY, so destroying a mesh with geometry: true can't free it from under other meshes.

      Returns Geometry3D

      if (mesh.geometry === Geometry3D.EMPTY) mesh.geometry = new SphereGeometry();
      
    • Frees the geometry for good

      Its own buffers are destroyed only with destroyBuffers, since other geometries may share them. Calling it again does nothing.

      Parameters

      • OptionaldestroyBuffers: boolean

        Whether to destroy the geometry's own buffers as well

      Returns void

      view.root.removeChild(mesh);
      mesh.geometry.destroy(true);

      Geometry3D.unload To hand back the GPU memory but keep the geometry usable.

    • Unloads this geometry from the GPU, keeping its CPU data so it can be rebuilt

      A dynamic geometry frees its own GPU buffers; any other leaves its place in the shared buffers, which never shrink, for later geometries. The next render that draws it uploads it again, and the image comes out the same: a geometry out of the scene comes back when its mesh does, one still drawn on the next frame. A BatchedMesh3D slot that draws it also needs invalidate. Safe to call more than once, and does nothing after Geometry3D.destroy.

      Returns void

      view.root.removeChild(mesh);
      mesh.geometry.unload(); // adding the mesh again uploads it again

      Geometry3D.destroy To free the geometry for good.