@@ -48,7 +48,6 @@ import assimp.postProcess.ValidateDSProcess
4848import glm_.BYTES
4949import glm_.i
5050import glm_.size
51- import java.io.File
5251import java.net.URI
5352import java.net.URL
5453import java.nio.ByteBuffer
@@ -303,7 +302,7 @@ constructor() {
303302 }
304303
305304 // Get file size for progress handler
306- val fileSize = File (file).length() .i
305+ val fileSize = ioSystem.open (file).length.i
307306
308307 // Dispatch the reading to the worker class for this format
309308 val desc = imp.info
@@ -373,8 +372,7 @@ constructor() {
373372 *
374373 * @note This is a straightforward way to decode models from memory buffers, but it doesn't handle model formats
375374 * that spread their data across multiple files or even directories. Examples include OBJ or MD3, which outsource
376- * parts of their material info into external scripts. If you need full functionality, provide a custom IOSystem
377- * to make Assimp find these files and use the regular readFile() API.
375+ * parts of their material info into external scripts. If you need full functionality you can use [readFilesFromMemory]
378376 */
379377 fun readFileFromMemory (buffer : ByteBuffer , flags : Int , hint : String = ""): AiScene ? {
380378 if (buffer.size == 0 || hint.length > MaxLenHint ) {
@@ -385,16 +383,81 @@ constructor() {
385383 // prevent deletion of previous IOSystem
386384 val io = impl.ioSystem
387385
388- ioHandler = MemoryIOSystem (buffer)
389-
390386 val fileName = " $AI_MEMORYIO_MAGIC_FILENAME .$hint "
387+ ioHandler = MemoryIOSystem (fileName to buffer)
388+
389+ readFile(fileName, flags)
390+
391+ impl.ioSystem = io
392+
393+ return impl.scene
394+ }
395+
396+ /* *Reads the given file from a memory buffer and returns its contents if successful.
397+ *
398+ * If the call succeeds, the contents of the file are returned as a pointer to an AiScene object. The returned data
399+ * is intended to be read-only, the importer object keeps ownership of the data and will destroy it upon
400+ * destruction. If the import fails, null is returned.
401+ * A human-readable error description can be retrieved by accessing errorString. The previous scene will be deleted
402+ * during this call.
403+ * Calling this method doesn't affect the active IOSystem.
404+ *
405+ * @param fileName name of the base file
406+ * @param files a map containing the names and all the files required to read the scene (base file, materials,
407+ * textures, etc).
408+ * @param flags Optional post processing steps to be executed after a successful import. Provide a bitwise
409+ * combination of the AiPostProcessSteps flags. If you wish to inspect the imported scene first in order to
410+ * fine-tune your post-processing setup, consider to use applyPostProcessing().
411+ * @return A pointer to the imported data, null if the import failed.
412+ * The pointer to the scene remains in possession of the Importer instance. Use getOrphanedScene() to take
413+ * ownership of it.
414+ */
415+ fun readFilesFromMemory (fileName : String , files : Map <String , ByteBuffer >, flags : Int ): AiScene ? {
416+
417+ for ((name, buffer) in files) {
418+ if (buffer.size == 0 ){
419+ impl.errorString = " buffer $name is empty"
420+ return null
421+ }
422+ }
423+ if (! files.containsKey(fileName)){
424+ impl.errorString = " fileName ($fileName ) not in files"
425+ return null
426+ }
427+
428+ val io = impl.ioSystem
429+
430+ ioHandler = MemoryIOSystem (files)
431+
391432 readFile(fileName, flags)
392433
393434 impl.ioSystem = io
394435
395436 return impl.scene
396437 }
397438
439+ /* *Reads the given file from a memory buffer and returns its contents if successful.
440+ *
441+ * If the call succeeds, the contents of the file are returned as a pointer to an AiScene object. The returned data
442+ * is intended to be read-only, the importer object keeps ownership of the data and will destroy it upon
443+ * destruction. If the import fails, null is returned.
444+ * A human-readable error description can be retrieved by accessing errorString. The previous scene will be deleted
445+ * during this call.
446+ * Calling this method doesn't affect the active IOSystem.
447+ *
448+ * @param fileName name of the base file
449+ * @param flags Optional post processing steps to be executed after a successful import. Provide a bitwise
450+ * combination of the AiPostProcessSteps flags. If you wish to inspect the imported scene first in order to
451+ * fine-tune your post-processing setup, consider to use applyPostProcessing().
452+ * @param files the files required to read the scene (base file, materials, textures, etc) as a pair with their name.
453+ * @return A pointer to the imported data, null if the import failed.
454+ * The pointer to the scene remains in possession of the Importer instance. Use getOrphanedScene() to take
455+ * ownership of it.
456+ */
457+ fun readFilesFromMemory (fileName : String , vararg files : Pair <String , ByteBuffer >, flags : Int = 0): AiScene ? {
458+ return readFilesFromMemory(fileName, files.toMap(), flags)
459+ }
460+
398461 /* * Apply post-processing to an already-imported scene.
399462 *
400463 * This is strictly equivalent to calling readFile() with the same flags. However, you can use this separate
0 commit comments