-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for virtual filesystems through IOSystem #10
Changes from 5 commits
453817e
31c8fd0
dbe8872
bf4ca5b
9e23faf
d5db2b9
863b1f6
b1e0881
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
.idea/ | ||
.idea/ | ||
out | ||
build | ||
.gradle |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package assimp | ||
|
||
import java.io.* | ||
|
||
class DefaultIOSystem : IOSystem{ | ||
override fun Exists(pFile: String) = File(pFile).exists() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lowercase function names |
||
|
||
override fun Open(pFile: String): IOStream { | ||
var file = File(pFile) | ||
println(File(".").absolutePath) | ||
if(!file.exists()) | ||
throw IOException("File doesn't exist: "+pFile) | ||
|
||
|
||
return FileIOStream(file) | ||
} | ||
|
||
class FileIOStream(val file: File) : IOStream{ | ||
override fun read() = FileInputStream(file) | ||
|
||
override fun reader() = BufferedReader(FileReader(file)) | ||
|
||
override val path: String | ||
get() = file.absolutePath | ||
|
||
override val filename: String | ||
get() = file.name | ||
|
||
override fun parentPath() = file.parentFile.absolutePath | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package assimp | ||
|
||
import java.io.BufferedReader | ||
import java.io.InputStream | ||
import java.io.Reader | ||
|
||
interface IOStream { | ||
val path : String | ||
|
||
val filename: String | ||
|
||
fun read() : InputStream | ||
|
||
fun reader() : BufferedReader | ||
|
||
fun parentPath() : String | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package assimp | ||
|
||
/** Interface to the file system. */ | ||
interface IOSystem { | ||
fun Exists(pFile: String): Boolean | ||
|
||
fun Open(pFile : String): IOStream | ||
|
||
fun Close(ioStream: IOStream) = Unit //unused ? | ||
|
||
fun getOsSeperator() = "/" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separator: java.io.File.separator |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,6 +191,11 @@ constructor() { | |
} | ||
} | ||
|
||
var ioHandler: IOSystem | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the way the original assimp does it though Is there some Kotlin trickery I can use to mirror that into the importers ( probably has to do with var and get() = something something ) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, after playing around myself, you're good on this. |
||
get() = impl.ioSystem | ||
|
||
set(value) { if(value != null) impl.ioSystem = value} | ||
|
||
/** Checks whether a default progress handler is active | ||
* A default handler is active as long the application doesn't supply its own custom progress handler via | ||
* setProgressHandler(). | ||
|
@@ -221,6 +226,8 @@ constructor() { | |
/** Get the currently set progress handler */ | ||
val progressHandler get() = impl.progressHandler | ||
|
||
fun readFile(uri: URI, flags: Int = 0) = readFile(uri.path, flags) | ||
|
||
/** Reads the given file and returns its contents if successful. | ||
* | ||
* If the call succeeds, the contents of the file are returned as a pointer to an AiScene object. The returned data | ||
|
@@ -238,11 +245,10 @@ constructor() { | |
* | ||
* @note Assimp is able to determine the file format of a file automatically. | ||
*/ | ||
fun readFile(file: String, flags: Int = 0) = readFile(file.uri, flags) | ||
//fun readFile(file: URI, flags: Int = 0): AiScene? { | ||
fun readFile(file: String, flags: Int = 0): AiScene? { | ||
|
||
fun readFile(file: URI, flags: Int = 0): AiScene? { | ||
|
||
writeLogOpening(file.path) | ||
writeLogOpening(file) | ||
|
||
// Check whether this Importer instance has already loaded a scene. In this case we need to delete the old one | ||
if (impl.scene != null) { | ||
|
@@ -251,19 +257,20 @@ constructor() { | |
} | ||
|
||
// First check if the file is accessible at all | ||
if (!file.exists()) { | ||
// handled by exception in IOSystem | ||
/*if (!file.exists()) { | ||
impl.errorString = "Unable to open file \"$file\"." | ||
logger.error { impl.errorString } | ||
return null | ||
} | ||
}*/ | ||
|
||
// TODO std::unique_ptr<Profiler> profiler(GetPropertyInteger(AI_CONFIG_GLOB_MEASURE_TIME,0)?new Profiler():NULL); | ||
// if (profiler) { | ||
// profiler->BeginRegion("total"); | ||
// } | ||
|
||
// Find an worker class which can handle the file | ||
val imp = impl.importer.find { it.canRead(file, false) } | ||
val imp = impl.importer.find { it.canRead(file, ioHandler,false) } | ||
|
||
if (imp == null) { | ||
// not so bad yet ... try format auto detection. | ||
|
@@ -300,7 +307,7 @@ constructor() { | |
// profiler->BeginRegion("import"); | ||
// } | ||
|
||
impl.scene = imp.readFile(this, file) | ||
impl.scene = imp.readFile(this, ioHandler, file) | ||
impl.progressHandler.updateFileRead(fileSize, fileSize) | ||
|
||
// if (profiler) { TODO | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any user functions should have this same idea applied