Skip to content

Commit 716d092

Browse files
committed
@JvmOverload on readFile
first postProcess implemented
1 parent b396d33 commit 716d092

File tree

17 files changed

+968
-125
lines changed

17 files changed

+968
-125
lines changed

src/main/kotlin/assimp/AiPostProcessSteps.kt renamed to src/main/kotlin/assimp/AiPostProcessStep.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package assimp
44
* Created by GBarbieri on 02.05.2017.
55
*/
66

7-
enum class AiPostProcessSteps(@JvmField val i: Int) {
7+
enum class AiPostProcessStep(@JvmField val i: Int) {
88

99
/** <hr>Calculates the tangents and bitangents for the imported meshes.
1010
*
@@ -397,7 +397,9 @@ enum class AiPostProcessSteps(@JvmField val i: Int) {
397397
TargetRealtime_MaxQuality(TargetRealtime_Quality.i or FindInstances.i or ValidateDataStructure.i or OptimizeMeshes.i)
398398
}
399399

400-
infix fun Int.has(b: AiPostProcessSteps) = and(b.i) != 0
401-
infix fun Int.hasnt(b: AiPostProcessSteps) = and(b.i) == 0
402-
infix fun Int.or(b: AiPostProcessSteps) = or(b.i)
403-
infix fun Int.wo(b: AiPostProcessSteps) = and(b.i.inv())
400+
infix fun Int.has(b: AiPostProcessStep) = and(b.i) != 0
401+
infix fun Int.hasnt(b: AiPostProcessStep) = and(b.i) == 0
402+
infix fun Int.or(b: AiPostProcessStep) = or(b.i)
403+
infix fun Int.wo(b: AiPostProcessStep) = and(b.i.inv())
404+
405+
typealias AiPostProcessStepsFlags = Int

src/main/kotlin/assimp/Importer.kt

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ import assimp.format.ProgressHandler
4646
import glm_.BYTES
4747
import glm_.i
4848
import glm_.size
49-
import assimp.AiPostProcessSteps as Pps
5049
import java.io.File
5150
import java.net.URI
5251
import java.net.URL
5352
import java.nio.ByteBuffer
5453
import java.nio.file.Path
5554
import java.nio.file.Paths
5655
import kotlin.reflect.KMutableProperty0
56+
import assimp.AiPostProcessStep as Pps
5757

5858
/** CPP-API: The Importer class forms an C++ interface to the functionality of the Open Asset Import Library.
5959
*
@@ -79,11 +79,6 @@ class Importer
7979
*/
8080
constructor() {
8181

82-
companion object {
83-
/** The upper limit for hints. */
84-
val MaxLenHint = 200
85-
}
86-
8782
// Just because we don't want you to know how we're hacking around.
8883
internal val impl = ImporterPimpl() // allocate the pimpl first
8984

@@ -115,7 +110,7 @@ constructor() {
115110
val st = imp.extensionList
116111
var baked = ""
117112
st.forEach {
118-
if (ASSIMP.BUILD.DEBUG && isExtensionSupported(it))
113+
if (ASSIMP.DEBUG && isExtensionSupported(it))
119114
logger.warn { "The file extension $it is already in use" }
120115
baked += "$it "
121116
}
@@ -191,8 +186,9 @@ constructor() {
191186

192187
var ioHandler: IOSystem
193188
get() = impl.ioSystem
194-
195-
set(value) { if(value != null) impl.ioSystem = value}
189+
set(value) {
190+
if (value != null) impl.ioSystem = value
191+
}
196192

197193
/** Checks whether a default progress handler is active
198194
* A default handler is active as long the application doesn't supply its own custom progress handler via
@@ -224,10 +220,13 @@ constructor() {
224220
/** Get the currently set progress handler */
225221
val progressHandler get() = impl.progressHandler
226222

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)
223+
@JvmOverloads
224+
fun readFile(url: URL, flags: AiPostProcessStepsFlags = 0) = readFile(url.toURI(), flags)
225+
@JvmOverloads
226+
fun readFile(uri: URI, flags: AiPostProcessStepsFlags = 0) = readFile(Paths.get(uri), flags)
227+
@JvmOverloads
228+
fun readFile(path: Path, flags: AiPostProcessStepsFlags = 0) = readFile(path.toAbsolutePath().toString(), flags)
229+
fun readFile(file: String, flags: AiPostProcessStepsFlags = 0) = readFile(file, ioHandler, flags)
231230

232231
/** Reads the given file and returns its contents if successful.
233232
*
@@ -246,7 +245,8 @@ constructor() {
246245
*
247246
* @note Assimp is able to determine the file format of a file automatically.
248247
*/
249-
fun readFile(file: String, ioSystem: IOSystem = this.ioHandler, flags: Int = 0): AiScene? {
248+
@JvmOverloads
249+
fun readFile(file: String, ioSystem: IOSystem = this.ioHandler, flags: AiPostProcessStepsFlags = 0): AiScene? {
250250

251251
writeLogOpening(file)
252252

@@ -270,7 +270,7 @@ constructor() {
270270
// }
271271

272272
// Find an worker class which can handle the file
273-
val imp = impl.importer.find { it.canRead(file, ioHandler,false) }
273+
val imp = impl.importer.find { it.canRead(file, ioHandler, false) }
274274

275275
if (imp == null) {
276276
// not so bad yet ... try format auto detection.
@@ -317,7 +317,7 @@ constructor() {
317317
// If successful, apply all active post processing steps to the imported data
318318
if (impl.scene != null) {
319319

320-
if (!ASSIMP.BUILD.NO.VALIDATEDS_PROCESS)
320+
if (!ASSIMP.NO.VALIDATEDS_PROCESS)
321321
// The ValidateDS process is an exception. It is executed first, even before ScenePreprocessor is called.
322322
if (flags has Pps.ValidateDataStructure) {
323323
ValidateDSProcess.executeOnScene(this)
@@ -405,7 +405,7 @@ constructor() {
405405
// In debug builds: run basic flag validation
406406
assert(_validateFlags(flags))
407407
logger.info("Entering post processing pipeline")
408-
if (!ASSIMP.BUILD.NO.VALIDATEDS_PROCESS)
408+
if (!ASSIMP.NO.VALIDATEDS_PROCESS)
409409
/* The ValidateDS process plays an exceptional role. It isn't contained in the global list of post-processing
410410
steps, so we need to call it manually. */
411411
if (flags has Pps.ValidateDataStructure) {
@@ -417,17 +417,17 @@ constructor() {
417417
if (impl.scene == null) return null
418418
}
419419
var flags = flags
420-
if (ASSIMP.BUILD.DEBUG) {
420+
if (ASSIMP.DEBUG) {
421421
if (impl.extraVerbose) {
422-
if (ASSIMP.BUILD.NO.VALIDATEDS_PROCESS)
422+
if (ASSIMP.NO.VALIDATEDS_PROCESS)
423423
logger.error { "Verbose Import is not available due to build settings" }
424424
flags = flags or Pps.ValidateDataStructure
425425
}
426426
} else if (impl.extraVerbose)
427427
logger.warn("Not a debug build, ignoring extra verbose setting")
428428

429429
// std::unique_ptr<Profiler> profiler (GetPropertyInteger(AI_CONFIG_GLOB_MEASURE_TIME, 0)?new Profiler():NULL); TODO
430-
for (a in 0 until impl.postProcessingSteps.size) {
430+
for (a in impl.postProcessingSteps.indices) {
431431
val process = impl.postProcessingSteps[a]
432432
impl.progressHandler.updatePostProcess(a, impl.postProcessingSteps.size)
433433
if (process.isActive(flags)) {
@@ -440,8 +440,8 @@ constructor() {
440440
// }
441441
}
442442
if (impl.scene == null) break
443-
if (ASSIMP.BUILD.DEBUG) {
444-
if (ASSIMP.BUILD.NO.VALIDATEDS_PROCESS) continue
443+
if (ASSIMP.DEBUG) {
444+
if (ASSIMP.NO.VALIDATEDS_PROCESS) continue
445445
// If the extra verbose mode is active, execute the ValidateDataStructureStep again - after each step
446446
if (impl.extraVerbose) {
447447
logger.debug { "Verbose Import: revalidating data structures" }
@@ -468,15 +468,15 @@ constructor() {
468468
if (null == rootProcess) return impl.scene
469469
// In debug builds: run basic flag validation
470470
logger.info { "Entering customized post processing pipeline" }
471-
if (!ASSIMP.BUILD.NO.VALIDATEDS_PROCESS) {
471+
if (!ASSIMP.NO.VALIDATEDS_PROCESS) {
472472
// The ValidateDS process plays an exceptional role. It isn't contained in the global
473473
// list of post-processing steps, so we need to call it manually.
474474
if (requestValidation) {
475475
ValidateDSProcess.executeOnScene(this)
476476
if (impl.scene == null) return null
477477
}
478478
}
479-
if (ASSIMP.BUILD.DEBUG && impl.extraVerbose && ASSIMP.BUILD.NO.VALIDATEDS_PROCESS)
479+
if (ASSIMP.DEBUG && impl.extraVerbose && ASSIMP.NO.VALIDATEDS_PROCESS)
480480
logger.error { "Verbose Import is not available due to build settings" }
481481
else if (impl.extraVerbose)
482482
logger.warn { "Not a debug build, ignoring extra verbose setting" }
@@ -701,7 +701,7 @@ constructor() {
701701
val flags = compileFlags
702702
logger.debug {
703703
var message = "Assimp $versionMajor.$versionMinor.$versionRevision"
704-
if (ASSIMP.BUILD.DEBUG) message += " debug"
704+
if (ASSIMP.DEBUG) message += " debug"
705705
}
706706
}
707707

@@ -724,5 +724,10 @@ constructor() {
724724
for (i in 0 until node.numChildren)
725725
addNodeWeight(scene, node.children[i])
726726
}
727+
728+
companion object {
729+
/** The upper limit for hints. */
730+
val MaxLenHint = 200
731+
}
727732
}
728733

src/main/kotlin/assimp/ImporterPimpl.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package assimp
22

3-
import assimp.format.AiConfig
43
import assimp.format.ProgressHandler
54

65
/** Internal PIMPL implementation for Assimp::Importer */
@@ -100,7 +99,7 @@ class BatchLoader(validate: Boolean = true) {
10099
// force validation in debug builds
101100
var pp = it.flags
102101
if (data.validate)
103-
pp = pp or AiPostProcessSteps.ValidateDataStructure
102+
pp = pp or AiPostProcessStep.ValidateDataStructure
104103

105104
// setup config properties if necessary
106105
data.importer.impl.properties += it.map

src/main/kotlin/assimp/ImporterRegistry.kt

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,45 @@ import assimp.format.stl.StlImporter
1616
* Created by elect on 13/11/2016.
1717
*/
1818

19-
var NO_VALIDATEDS_PROCESS = false
20-
21-
22-
val AI_CONFIG_IMPORT_MD2_KEYFRAME = "IMPORT_MD2_KEYFRAME"
23-
24-
val importerInstanceList
19+
val importerInstanceList: ArrayList<BaseImporter>
2520
get() = ArrayList<BaseImporter>().apply {
26-
with(ASSIMP.BUILD.NO) {
21+
with(ASSIMP.NO) {
2722
// ----------------------------------------------------------------------------
2823
// Add an instance of each worker class here
2924
// (register_new_importers_here)
3025
// ---------------------------------------------------------------------------- {
3126
//if (!assimp.ASSIMP_BUILD_NO_MD2_IMPORTER) add(Md2Importer())
32-
if (!ASSBIN_IMPORTER) add(AssbinLoader())
33-
if (!COLLADA_IMPORTER) add(ColladaLoader())
34-
if (!FBX_IMPORTER) add(FbxImporter())
35-
if (!MD2_IMPORTER) add(Md2Importer())
36-
if (!MD3_IMPORTER) add(Md3Importer())
37-
if (!MD5_IMPORTER) add(Md5Importer())
38-
if (!OBJ_IMPORTER) add(ObjFileImporter())
39-
if (!PLY_IMPORTER) add(PlyLoader())
40-
if (!STL_IMPORTER) add(StlImporter())
41-
if (!X_IMPORTER) add(XFileImporter())
42-
if (!BLEND_IMPORTER) add(BlenderImporter())
43-
}
44-
}
27+
if (!ASSBIN_IMPORTER)
28+
add(AssbinLoader())
29+
30+
if (!COLLADA_IMPORTER)
31+
add(ColladaLoader())
32+
33+
if (!FBX_IMPORTER)
34+
add(FbxImporter())
35+
36+
if (!MD2_IMPORTER)
37+
add(Md2Importer())
4538

46-
fun getPostProcessingStepInstanceList(): List<BaseProcess> = listOf();
39+
if (!MD3_IMPORTER)
40+
add(Md3Importer())
41+
42+
if (!MD5_IMPORTER)
43+
add(Md5Importer())
44+
45+
if (!OBJ_IMPORTER)
46+
add(ObjFileImporter())
47+
48+
if (!PLY_IMPORTER)
49+
add(PlyLoader())
50+
51+
if (!STL_IMPORTER)
52+
add(StlImporter())
53+
54+
if (!X_IMPORTER)
55+
add(XFileImporter())
56+
57+
if (!BLEND_IMPORTER)
58+
add(BlenderImporter())
59+
}
60+
}

0 commit comments

Comments
 (0)