API

Class Geometry

Class used to store geometry data (vertex buffers + index buffer)

Implements

Index
  • Creates a new geometry

    Parameters

    • id: string

      defines the unique ID

    • Optionalscene: Scene

      defines the hosting scene

    • OptionalvertexData: VertexData

      defines the VertexData used to get geometry data

    • updatable: boolean = false

      defines if geometry must be updatable (false by default)

    • mesh: Nullable<Mesh> = null

      defines the mesh that will be associated with the geometry

    • totalVertices: Nullable<number> = null

      defines the total number of vertices (optional)

    Returns Geometry

delayLoadingFile: Nullable<string>

Gets the file containing the data to load when running in delay load state

delayLoadState: number = Constants.DELAYLOADSTATE_NONE

Gets the delay loading state of the geometry (none by default which means not delayed)

id: string

Gets or sets the ID of the geometry

onGeometryUpdated: (geometry: Geometry, kind?: string) => void

Callback called when the geometry is updated

uniqueId: number

Gets or sets the unique ID of the geometry

useBoundingInfoFromGeometry: boolean = false

If set to true (false by default), the bounding info applied to the meshes sharing this geometry will be the bounding info defined at the class level and won't be computed based on the vertex positions (which is what we get when useBoundingInfoFromGeometry = false)

  • get boundingBias(): Vector2

    Gets or sets the Bias Vector to apply on the bounding elements (box/sphere), the max extend is computed as v += v * bias.x + bias.y, the min is computed as v -= v * bias.x + bias.y

    Returns Vector2

  • set boundingBias(value: Vector2): void

    Gets or sets the Bias Vector to apply on the bounding elements (box/sphere), the max extend is computed as v += v * bias.x + bias.y, the min is computed as v -= v * bias.x + bias.y

    Parameters

    Returns void

  • Release any memory retained by the cached data on the Geometry.

    Call this function to reduce memory footprint of the mesh. Vertex buffers will not store CPU data anymore (this will prevent picking, collisions or physics to work correctly)

    Returns void

  • Copies the requested vertex data kind into the given vertex data map. Float data is constructed if the map doesn't have the data.

    Parameters

    • kind: string

      defines the data kind (Position, normal, etc...)

    • vertexData: { [kind: string]: Float32Array<ArrayBufferLike> }

      defines the map that stores the resulting data

    Returns void

  • Gets a specific vertex data attached to this geometry. Float data is constructed if the vertex buffer data cannot be returned directly.

    Parameters

    • kind: string

      defines the data kind (Position, normal, etc...)

    • OptionalcopyWhenShared: boolean

      defines if the returned array must be cloned upon returning it if the current geometry is shared between multiple meshes

    • OptionalforceCopy: boolean

      defines a boolean indicating that the returned array must be cloned upon returning it

    Returns Nullable<FloatArray>

    a float array containing vertex data

  • Returns a boolean defining if the vertex data for the requested kind is updatable

    Parameters

    • kind: string

      defines the data kind (Position, normal, etc...)

    Returns boolean

    true if the vertex buffer with the specified kind is updatable

  • Load the geometry if it was flagged as delay loaded

    Parameters

    • scene: Scene

      defines the hosting scene

    • OptionalonLoaded: () => void

      defines a callback called when the geometry is loaded

    Returns void

  • Release the associated resources for a specific mesh

    Parameters

    • mesh: Mesh

      defines the source mesh

    • OptionalshouldDispose: boolean

      defines if the geometry must be disposed if there is no more mesh pointing to it

    Returns void

  • Serialize the current geometry info (and not the vertices data) into a JSON object

    Returns any

    a JSON representation of the current geometry data (without the vertices data)

  • Affects all geometry data in one call

    Parameters

    • vertexData: VertexData

      defines the geometry data

    • Optionalupdatable: boolean

      defines if the geometry must be flagged as updatable (false as default)

    Returns void

  • Sets the index buffer for this geometry.

    Parameters

    • indexBuffer: DataBuffer

      Defines the index buffer to use for this geometry

    • totalVertices: number

      Defines the total number of vertices used by the buffer

    • totalIndices: number

      Defines the total number of indices in the index buffer

    • is32Bits: Nullable<boolean> = null

      Defines if the indices are 32 bits. If null (default), the value is guessed from the number of vertices

    Returns void

  • Creates a new index buffer

    Parameters

    • indices: IndicesArray

      defines the indices to store in the index buffer

    • totalVertices: Nullable<number> = null

      defines the total number of vertices (could be null)

    • updatable: boolean = false

      defines if the index buffer must be flagged as updatable (false by default)

    • dontForceSubMeshRecreation: boolean = false

      defines a boolean indicating that we don't want to force the recreation of sub-meshes if we don't have to (false by default)

    Returns void

  • Affect a vertex buffer to the geometry. the vertexBuffer.getKind() function is used to determine where to store the data

    Parameters

    • buffer: VertexBuffer

      defines the vertex buffer to use

    • totalVertices: Nullable<number> = null

      defines the total number of vertices for position kind (could be null)

    • disposeExistingBuffer: boolean = true

      disposes the existing buffer, if any (default: true)

    Returns void

  • Set specific vertex data

    Parameters

    • kind: string

      defines the data kind (Position, normal, etc...)

    • data: FloatArray

      defines the vertex data to use

    • updatable: boolean = false

      defines if the vertex must be flagged as updatable (false as default)

    • Optionalstride: number

      defines the stride to use (0 by default). This value is deduced from the kind value if not specified

    Returns void

  • Update index buffer

    Parameters

    • indices: IndicesArray

      defines the indices to store in the index buffer

    • Optionaloffset: number

      defines the offset in the target buffer where to store the data

    • gpuMemoryOnly: boolean = false

      defines a boolean indicating that only the GPU memory must be updated leaving the CPU version of the indices unchanged (false by default)

    Returns void

  • Update a specific vertex buffer This function will create a new buffer if the current one is not updatable

    Parameters

    • kind: string

      defines the data kind (Position, normal, etc...)

    • data: FloatArray

      defines the data to use

    • updateExtends: boolean = false

      defines if the geometry extends must be recomputed (false by default)

    Returns void

  • Update a specific vertex buffer This function will directly update the underlying DataBuffer according to the passed numeric array or Float32Array It will do nothing if the buffer is not updatable

    Parameters

    • kind: string

      defines the data kind (Position, normal, etc...)

    • data: DataArray

      defines the data to use

    • offset: number

      defines the offset in the target buffer where to store the data

    • useBytes: boolean = false

      set to true if the offset is in bytes

    Returns void

  • Create a new geometry from persisted data (Using .babylon file format)

    Parameters

    • parsedVertexData: any

      defines the persisted data

    • scene: Scene

      defines the hosting scene

    • rootUrl: string

      defines the root url to use to load assets (like delayed data)

    Returns Nullable<Geometry>

    the new geometry object