loadFromMemory

@JvmStatic
fun loadFromMemory(data: ByteBuffer, hint: String): GaussianSplattingResource

Loads a GaussianSplattingResource directly from in-memory data.

Use this when the resource bytes are already held in a direct ByteBuffer (for example, mapped from a file you opened yourself, downloaded over the network, or unpacked from a custom asset container) and you want to avoid copying them into a temporary file or byte[] first.

WARNING:

  • This method is blocking. While it can be called on the main thread, large resources may cause jank or even ANR.

  • Prefer invoking from a background thread or coroutine, e.g. withContext(Dispatchers.IO) { GaussianSplattingResource.loadFromMemory(buf, "spz") }.

Usage

val buffer: ByteBuffer = ByteBuffer.allocateDirect(bytes.size).apply {
put(bytes)
flip()
}
val resource = withContext(Dispatchers.IO) {
GaussianSplattingResource.loadFromMemory(buffer, "spz")
}

Buffer Requirements

  • data must be a direct ByteBuffer (e.g. obtained via ByteBuffer.allocateDirect(...) or by memory-mapping a file).

  • The bytes between the buffer's current position and limit are treated as the resource content (i.e. data.remaining() bytes starting at data.position()). The buffer's position/limit/mark are not modified by this call.

  • The buffer must remain valid (not unmapped/freed) until this method returns.

Return

The loaded GaussianSplattingResource.

Parameters

data

A direct ByteBuffer containing the Gaussian splatting data (.ply or .spz).

hint

The format hint for parsing; only "ply" and "spz" are supported.

Throws

If loading fails due to invalid data, unsupported format, or if data is not a direct buffer / has no remaining content.