Skip to content

Commit a498fec

Browse files
committed
- fixed fucking tests
- md3 relies now on os-indipendent path separator char
1 parent 6d677e1 commit a498fec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+141
-129
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
9090
from javadoc.destinationDir
9191
}
9292

93-
test {
94-
workingDir = "src/test/resources"
95-
}
93+
//test {
94+
// workingDir = "src/test/resources"
95+
//}
9696

9797
artifacts {
9898
archives sourcesJar
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
package assimp
22

33
import java.io.*
4+
import java.nio.file.Files
5+
import java.nio.file.Path
6+
import java.nio.file.Paths
47

5-
class DefaultIOSystem : IOSystem{
8+
class DefaultIOSystem : IOSystem {
69

710
override fun exists(pFile: String) = File(pFile).exists()
811

912
override fun open(pFile: String): IOStream {
10-
val file = File(pFile)
11-
println(File(".").absolutePath)
12-
if(!file.exists())
13+
14+
val path: Path = Paths.get(pFile)
15+
if (!Files.exists(path))
1316
throw IOException("File doesn't exist: $pFile")
1417

1518

16-
return FileIOStream(file)
19+
return FileIOStream(path)
1720
}
1821

19-
class FileIOStream(val file: File) : IOStream{
20-
override fun read() = FileInputStream(file)
22+
class FileIOStream(override val path: Path) : IOStream {
2123

22-
override fun reader() = BufferedReader(FileReader(file))
24+
override fun read() = FileInputStream(path.toFile())
2325

24-
override val path: String
25-
get() = file.absolutePath
26+
override fun reader() = BufferedReader(FileReader(path.toFile()))
2627

2728
override val filename: String
28-
get() = file.name
29+
get() = path.fileName.toString()
2930

30-
override fun parentPath() = file.parentFile.absolutePath
31+
override fun parentPath() = path.parent.toAbsolutePath().toString()
3132
}
3233
}

src/main/kotlin/assimp/IOStream.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package assimp
22

33
import java.io.BufferedReader
44
import java.io.InputStream
5-
import java.io.Reader
5+
import java.nio.file.Path
66

77
interface IOStream {
8-
val path : String
8+
9+
val path : Path
910

1011
val filename: String
1112

src/main/kotlin/assimp/IOSystem.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import java.io.File
44

55
/** Interface to the file system. */
66
interface IOSystem {
7+
78
fun exists(pFile: String): Boolean
89

910
fun open(pFile : String): IOStream
1011

11-
fun close(ioStream: IOStream) = Unit //unused ?
12+
fun close(ioStream: IOStream) = Unit // TODO unused ?
1213

13-
fun getOsSeperator() = File.separator
14+
fun getOsSeperator(): String = File.separator
1415
}

src/main/kotlin/assimp/Importer.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,16 @@ package assimp
4444

4545
import assimp.format.ProgressHandler
4646
import glm_.BYTES
47-
import glm_.bool
4847
import glm_.i
49-
import glm_.mat4x4.Mat4
5048
import glm_.size
5149
import assimp.AiPostProcessSteps as Pps
52-
import uno.kotlin.uri
5350
import java.io.File
54-
import java.io.FileNotFoundException
5551
import java.net.URI
52+
import java.net.URL
5653
import java.nio.ByteBuffer
54+
import java.nio.file.Path
55+
import java.nio.file.Paths
5756
import kotlin.reflect.KMutableProperty0
58-
import kotlin.reflect.KMutableProperty1
5957

6058
/** CPP-API: The Importer class forms an C++ interface to the functionality of the Open Asset Import Library.
6159
*
@@ -226,7 +224,10 @@ constructor() {
226224
/** Get the currently set progress handler */
227225
val progressHandler get() = impl.progressHandler
228226

229-
fun readFile(uri: URI, flags: Int = 0) = readFile(uri.path, flags)
227+
fun readFile(url: URL, flags: Int = 0) = readFile(url.toURI(), flags)
228+
fun readFile(uri: URI, flags: Int = 0) = readFile(Paths.get(uri), flags)
229+
fun readFile(path: Path, flags: Int = 0) = readFile(path.toAbsolutePath().toString(), flags)
230+
fun readFile(file: String, flags: Int = 0) = readFile(file, ioHandler, flags)
230231

231232
/** Reads the given file and returns its contents if successful.
232233
*
@@ -245,9 +246,6 @@ constructor() {
245246
*
246247
* @note Assimp is able to determine the file format of a file automatically.
247248
*/
248-
//fun readFile(file: URI, flags: Int = 0): AiScene? {
249-
fun readFile(file: String, flags: Int = 0) = readFile(file, ioHandler, flags)
250-
251249
fun readFile(file: String, ioSystem: IOSystem = this.ioHandler, flags: Int = 0): AiScene? {
252250

253251
writeLogOpening(file)

src/main/kotlin/assimp/assimp.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package assimp
33
import glm_.mat4x4.Mat4
44
import glm_.vec3.Vec3
55
import mu.KotlinLogging
6+
import java.net.URL
67
import java.nio.ByteBuffer
8+
import java.nio.file.Path
9+
import java.nio.file.Paths
710
import kotlin.math.abs
811

912
val logger = KotlinLogging.logger {}

src/main/kotlin/assimp/format/md3/Md3Loader.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,9 @@ class Md3Importer : BaseImporter() {
385385

386386
// get base path and file name
387387
// todo ... move to PathConverter
388-
filename = this.file.substringAfterLast('/').toLowerCase()
389-
val last = this.file.lastIndexOf('/')
390-
path = if (last == -1) this.file else this.file.substring(0, last + 1)
388+
filename = file.substringAfterLast(File.separatorChar).toLowerCase()
389+
val last = file.lastIndexOf(File.separatorChar)
390+
path = if (last == -1) file else file.substring(0, last + 1)
391391

392392
// Load multi-part model file, if necessary
393393
if (configHandleMP && readMultipartFile()) return
@@ -522,7 +522,7 @@ class Md3Importer : BaseImporter() {
522522
textureCoords.add(mutableListOf())
523523
}
524524

525-
// Fill in all pTriangles
525+
// Fill in all triangles
526526
var iCurrent = 0
527527
for (i in 0 until surfaces.numTriangles) {
528528
mesh.faces.add(MutableList(3, { 0 }))
@@ -749,7 +749,7 @@ class Md3Importer : BaseImporter() {
749749
* @param fill Receives output information */
750750
fun readShader(fill: Q3Shader.ShaderData) {
751751
// Determine Q3 model name from given path
752-
val last = path.substring(0, path.length - 2).lastIndexOf('/')
752+
val last = path.substring(0, path.length - 2).lastIndexOf(File.separatorChar)
753753
val modelFile = path.substring(last + 1, path.length - 1)
754754

755755
// If no specific dir or file is given, use our default search behaviour

src/main/kotlin/assimp/format/obj/ObjFileImporter.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -421,32 +421,34 @@ class ObjFileImporter : BaseImporter() {
421421
val cleaned = name.substring(i) // e.g: .\wal67ar_small.jpg -> wal67ar_small.jpg
422422

423423
if(ioSystem is DefaultIOSystem) {
424+
424425
//If the default io system is in place, we can use the java.io.File api and list directories
425426
//to match files even where case is mangled
426427

427-
val dios = ioSystem as DefaultIOSystem
428-
val actualFile = (dios.open(file) as DefaultIOSystem.FileIOStream).file
428+
val actualFile = (ioSystem.open(file) as DefaultIOSystem.FileIOStream).path.toFile()
429429

430-
if (actualFile.parentFile.listFiles().any { it.name == cleaned }) {
430+
when {
431+
actualFile.parentFile.listFiles().any { it.name == cleaned } -> {
431432

432-
val texFile = actualFile.parentFile.listFiles().first { it.name == cleaned }!!
433-
scene.textures[name] = gli.load(texFile.toPath())
433+
val texFile = actualFile.parentFile.listFiles().first { it.name == cleaned }!!
434+
scene.textures[name] = gli.load(texFile.toPath())
434435

435-
} else if(actualFile.parentFile.listFiles().any { it.name.toUpperCase() == cleaned.toUpperCase() }){
436-
// try case insensitive
437-
val texFile = actualFile.parentFile.listFiles().first { it.name.toUpperCase() == cleaned.toUpperCase() }!!
438-
scene.textures[name] = gli.load(texFile.toPath())
436+
}
437+
actualFile.parentFile.listFiles().any { it.name.toUpperCase() == cleaned.toUpperCase() } -> {
438+
// try case insensitive
439+
val texFile = actualFile.parentFile.listFiles().first { it.name.toUpperCase() == cleaned.toUpperCase() }!!
440+
scene.textures[name] = gli.load(texFile.toPath())
439441

440-
} else {
441-
logger.warn { "OBJ/MTL: Texture image not found --> " + cleaned }
442+
}
443+
else -> logger.warn { "OBJ/MTL: Texture image not found --> $cleaned" }
442444
}
443445
} else {
444446
//no such luck with custom io systems i'm afraid
445447
//TODO gli load from bytebuf ?
446448
}
447449

448450
} else {
449-
logger.warn { "OBJ/MTL: Scene contains --> " + name + " already"}
451+
logger.warn { "OBJ/MTL: Scene contains --> $name already" }
450452
}
451453
}
452454
}

src/test/kotlin/X/BCN_Epileptic.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package X
22

33
import assimp.Importer
4+
import assimp.getResource
45
import io.kotlintest.specs.StringSpec
56

67

@@ -11,7 +12,7 @@ class BCN_Epileptic : StringSpec() {
1112
val BCN_Epileptic = "BCN_Epileptic.X"
1213

1314
BCN_Epileptic {
14-
with(Importer().readFile(x + BCN_Epileptic)!!) {
15+
with(Importer().readFile(getResource("$x/$BCN_Epileptic"))!!) {
1516
println("Node names: ")
1617
printNodeNames(rootNode)
1718
with(rootNode) {

src/test/kotlin/X/Testwuson.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package X
22

33
import assimp.Importer
4+
import assimp.getResource
45
import io.kotlintest.specs.StringSpec
56

67
class Testwuson : StringSpec() {
78
init {
89
val testwuson = "Testwuson.X"
910

1011
testwuson {
11-
with(Importer().readFile(x + testwuson)!!) {
12+
with(Importer().readFile(getResource("$x/$testwuson"))!!) {
1213
with(rootNode) {
1314
X.printNodeNames(rootNode)
1415
}

0 commit comments

Comments
 (0)