From 71dfc6f32d4ed733941899d1d274a8280fb25085 Mon Sep 17 00:00:00 2001 From: Burkhard Mittelbach Date: Tue, 11 Sep 2018 18:19:36 +0200 Subject: [PATCH 1/4] cleaned up a lot of warnings. In theory all warnings should now represent a bug or missing/incomplete feature. I might have missed some. There are about 60 warnings left. Signed-off-by: Burkhard Mittelbach --- src/main/kotlin/assimp/Importer.kt | 12 ++--- src/main/kotlin/assimp/ImporterPimpl.kt | 3 +- src/main/kotlin/assimp/PolyTools.kt | 2 + src/main/kotlin/assimp/SGSpatialSort.kt | 2 +- src/main/kotlin/assimp/SkeletonMeshBuilder.kt | 10 ++--- src/main/kotlin/assimp/SpatialSort.kt | 4 +- .../assimp/format/X/ConvertToLHProcess.kt | 1 - .../kotlin/assimp/format/X/XFileImporter.kt | 45 ++++++++----------- .../kotlin/assimp/format/X/XFileParser.kt | 23 +++++----- src/main/kotlin/assimp/format/X/fast_atof.kt | 41 ++++++++--------- .../assimp/format/assbin/AssbinLoader.kt | 8 ++-- .../assimp/format/assxml/AssxmlExporter.kt | 20 ++++----- .../kotlin/assimp/format/assxml/helpers.kt | 5 --- .../assimp/format/blender/BlenderDNA.kt | 1 + .../kotlin/assimp/format/fbx/fbxConverter.kt | 8 ++-- .../kotlin/assimp/format/md3/Md3Loader.kt | 6 +-- .../kotlin/assimp/format/obj/ObjFileParser.kt | 2 +- .../kotlin/assimp/format/stl/STLLoader.kt | 11 +++-- .../postProcess/ValidateDataStructure.kt | 5 ++- src/main/kotlin/assimp/sceneCombiner.kt | 2 +- src/test/kotlin/X/helpers.kt | 2 +- src/test/kotlin/assimp/anchor.kt | 9 ++-- .../assimp/assxml/implementation_test.kt | 35 +++++++-------- 23 files changed, 118 insertions(+), 139 deletions(-) diff --git a/src/main/kotlin/assimp/Importer.kt b/src/main/kotlin/assimp/Importer.kt index 2a0f4de..c82a6ff 100644 --- a/src/main/kotlin/assimp/Importer.kt +++ b/src/main/kotlin/assimp/Importer.kt @@ -188,13 +188,7 @@ constructor() { var ioHandler: IOSystem get() = impl.ioSystem set(value) { - if (value != null) { // TODO check nullability - impl.ioSystem = value - impl.isDefaultHandler = false - } else { - impl.ioSystem = DefaultIOSystem() - impl.isDefaultHandler = true - } + impl.ioSystem = value } /** Checks whether a default progress handler is active @@ -773,8 +767,8 @@ constructor() { the library version they're using - a log dump is sufficient. */ val flags = compileFlags logger.debug { - var message = "Assimp $versionMajor.$versionMinor.$versionRevision" - if (ASSIMP.DEBUG) message += " debug" + val message = "Assimp $versionMajor.$versionMinor.$versionRevision" + if (ASSIMP.DEBUG) "$message debug" else message } } diff --git a/src/main/kotlin/assimp/ImporterPimpl.kt b/src/main/kotlin/assimp/ImporterPimpl.kt index 4c22379..790d20d 100644 --- a/src/main/kotlin/assimp/ImporterPimpl.kt +++ b/src/main/kotlin/assimp/ImporterPimpl.kt @@ -5,7 +5,8 @@ import assimp.format.ProgressHandler /** Internal PIMPL implementation for Assimp::Importer */ class ImporterPimpl { - var isDefaultHandler = true + val isDefaultHandler + get() = ioSystem is DefaultIOSystem /** Progress handler for feedback. */ var progressHandler: ProgressHandler = DefaultProgressHandler() diff --git a/src/main/kotlin/assimp/PolyTools.kt b/src/main/kotlin/assimp/PolyTools.kt index 3131702..a5272dd 100644 --- a/src/main/kotlin/assimp/PolyTools.kt +++ b/src/main/kotlin/assimp/PolyTools.kt @@ -42,6 +42,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** @file PolyTools.h, various utilities for our dealings with arbitrary polygons */ +@file:Suppress("NOTHING_TO_INLINE") + package assimp import glm_.vec2.Vec2 diff --git a/src/main/kotlin/assimp/SGSpatialSort.kt b/src/main/kotlin/assimp/SGSpatialSort.kt index 7249283..cfe32f0 100644 --- a/src/main/kotlin/assimp/SGSpatialSort.kt +++ b/src/main/kotlin/assimp/SGSpatialSort.kt @@ -17,7 +17,7 @@ class SGSpatialSort { fun prepare() { - val array = mPositions.toArray() as Array + val array = mPositions.toTypedArray() Arrays.sort(array) mPositions.clear() mPositions.addAll(array) diff --git a/src/main/kotlin/assimp/SkeletonMeshBuilder.kt b/src/main/kotlin/assimp/SkeletonMeshBuilder.kt index 69e2224..408060c 100644 --- a/src/main/kotlin/assimp/SkeletonMeshBuilder.kt +++ b/src/main/kotlin/assimp/SkeletonMeshBuilder.kt @@ -73,16 +73,16 @@ constructor(scene: AiScene, root: AiNode? = null, val knobsOnly: Boolean = false init { // nothing to do if there's mesh data already present at the scene - if (scene.numMeshes == 0 && scene.rootNode != null) { - val root = root ?: scene.rootNode + if (scene.numMeshes == 0) { + val r = root ?: scene.rootNode // build some faces around each node - createGeometry(root) + createGeometry(r) // create a mesh to hold all the generated faces scene.numMeshes = 1 scene.meshes = arrayListOf(createMesh()) // and install it at the root node - root.numMeshes = 1 - root.meshes = IntArray(1) + r.numMeshes = 1 + r.meshes = IntArray(1) // create a dummy material for the mesh if (scene.numMaterials == 0){ scene.numMaterials = 1 diff --git a/src/main/kotlin/assimp/SpatialSort.kt b/src/main/kotlin/assimp/SpatialSort.kt index cfbb1ed..720dbbe 100644 --- a/src/main/kotlin/assimp/SpatialSort.kt +++ b/src/main/kotlin/assimp/SpatialSort.kt @@ -20,13 +20,13 @@ class SpatialSort{ } fun finalize() { - val array = mPositions.toArray() as Array + val array = mPositions.toTypedArray() Arrays.sort(array) mPositions.clear() mPositions.addAll(array) } - fun append(pPositions: List,pNumPositions: Int,pElementOffset: Int, pFinalize: Boolean = true) + fun append(pPositions: List,pNumPositions: Int, pElementOffset: Int, pFinalize: Boolean = true) { // store references to all given positions along with their distance to the reference plane val initial = mPositions.size diff --git a/src/main/kotlin/assimp/format/X/ConvertToLHProcess.kt b/src/main/kotlin/assimp/format/X/ConvertToLHProcess.kt index b35318f..bfa00f2 100644 --- a/src/main/kotlin/assimp/format/X/ConvertToLHProcess.kt +++ b/src/main/kotlin/assimp/format/X/ConvertToLHProcess.kt @@ -9,7 +9,6 @@ object MakeLeftHandedProcess { fun Execute(pScene: AiScene) { // Check for an existent root node to proceed - assert(pScene.rootNode != null) debug("MakeLeftHandedProcess: MakeLeftHandedProcess begin") // recursively convert all the nodes diff --git a/src/main/kotlin/assimp/format/X/XFileImporter.kt b/src/main/kotlin/assimp/format/X/XFileImporter.kt index 8f96148..dc300fd 100644 --- a/src/main/kotlin/assimp/format/X/XFileImporter.kt +++ b/src/main/kotlin/assimp/format/X/XFileImporter.kt @@ -40,7 +40,7 @@ class XFileImporter : BaseImporter() { // And create the proper return structures out of it CreateDataRepresentationFromImport(scene, parser.mScene) - if (scene.rootNode == null) + if (scene.rootNode == null) // TODO do we need some other kind of check here instead? This is never true throw Error("XFile is ill-formatted - no content imported.") } @@ -56,11 +56,6 @@ class XFileImporter : BaseImporter() { // read the global meshes that were stored outside of any node if (pData.mGlobalMeshes.size() > 0) { - // create a root node to hold them if there isn't any, yet - if (pScene.rootNode == null) { - pScene.rootNode = AiNode() - pScene.rootNode.name = "\$dummy_node" - } // convert all global meshes and store them in the root node. // If there was one before, the global meshes now suddenly have its transformation matrix... @@ -69,10 +64,6 @@ class XFileImporter : BaseImporter() { CreateMeshes(pScene, pScene.rootNode, pData.mGlobalMeshes) } - if (pScene.rootNode == null) { - throw Error("No root node") - } - // Convert everything to OpenGL space... it's the same operation as the conversion back, so we can reuse the step directly //var convertProcess : MakeLeftHandedProcess = (); MakeLeftHandedProcess.Execute(pScene) @@ -240,15 +231,14 @@ class XFileImporter : BaseImporter() { } // convert all the materials given in the array - for (a in 0 until pMaterials.size()) { - var oldMat = pMaterials[a] + for (oldMatIndex in 0 until pMaterials.size()) { + val oldMat = pMaterials[oldMatIndex] if (oldMat.mIsReference) { // find the material it refers to by name, and store its index - for (a in 0 until pScene.numMaterials) { - var name: String - name = pScene.materials[a].name!! + for (matIndex in 0 until pScene.numMaterials) { + val name = pScene.materials[matIndex].name!! if ((name == oldMat.mName)) { - oldMat.sceneIndex = a + oldMat.sceneIndex = matIndex break } } @@ -261,13 +251,13 @@ class XFileImporter : BaseImporter() { continue } - var mat = AiMaterial() + val mat = AiMaterial() var name: String? name = (oldMat.mName) mat.name = name // Shading model: hardcoded to PHONG, there is no such information in an XFile - // FIX (aramis): If the specular exponent is 0, use gouraud shading. This is a bugfix + // FIX (aramis): If the specular exponent is 0, use gouraud shading. This is oldMatIndex bugfix // for some models in the SDK (e.g. good old tiny.x) var shadeMode = if (oldMat.mSpecularExponent == 0.0f) AiShadingMode.gouraud else AiShadingMode.phong @@ -275,7 +265,7 @@ class XFileImporter : BaseImporter() { mat.shadingModel = shadeMode // material colours // Unclear: there's no ambient colour, but emissive. What to put for ambient? - // Probably nothing at all, let the user select a suitable default. + // Probably nothing at all, let the user select oldMatIndex suitable default. mat.color = AiMaterial.Color() mat.color!!.emissive = oldMat.mEmissive mat.color!!.diffuse = AiColor3D(oldMat.mDiffuse) //Why conversion to 3D? @@ -343,7 +333,7 @@ class XFileImporter : BaseImporter() { } else if (-1 != sz.indexOf("emissive", s) || -1 != sz.indexOf("self", s)) { mat.textures.add(AiMaterial.Texture(file = tex, type = AiTexture.Type.emissive, uvwsrc = (iEM++))) } else { - // Assume it is a diffuse texture + // Assume it is oldMatIndex diffuse texture mat.textures.add(AiMaterial.Texture(file = tex, type = AiTexture.Type.diffuse, uvwsrc = (iDM++))) } } @@ -455,17 +445,18 @@ class XFileImporter : BaseImporter() { // now collect the vertex data of all data streams present in the imported mesh var newIndex = 0 - var orgPoints: MutableList = mutableListOf() // from which original point each new vertex stems + val orgPoints: MutableList = mutableListOf() // from which original point each new vertex stems orgPoints.resize(numVertices, { 0 }) for (c in 0 until faces.size()) { - var f = faces[c] // index of the source face - var pf = sourceMesh.mPosFaces[f] // position source face + val f = faces[c] // index of the source face + val pf = sourceMesh.mPosFaces[f] // position source face // create face. either triangle or triangle fan depending on the index count - var df = mesh.faces[c] // destination face + //var df = mesh.faces[c] // destination face //df.numIndices = pf.mIndices.size(); //3 - df = MutableList(pf.mIndices.size(), { 0 }); mesh.faces[c]=df + val df = MutableList(pf.mIndices.size()) { 0 } + mesh.faces[c]=df // collect vertex data for indices of this face for (d in 0 until df.size()) { @@ -481,7 +472,7 @@ class XFileImporter : BaseImporter() { // texture coord sets for (e in 0 until AI_MAX_NUMBER_OF_TEXTURECOORDS) { if (e < mesh.textureCoords.size && mesh.hasTextureCoords(e)) { - var tex = sourceMesh.mTexCoords[e][pf.mIndices[d]] + val tex = sourceMesh.mTexCoords[e][pf.mIndices[d]] mesh.textureCoords[e][newIndex] = arrayOf(tex.x, 1.0f - tex.y //, 0.0f //Not sure why this is in original C++ code, but not in kotlin port. ).toFloatArray() @@ -547,7 +538,7 @@ class XFileImporter : BaseImporter() { // reallocate scene mesh array to be large enough var prevArray = pScene.meshes - pScene.meshes.reserve(pScene.numMeshes + meshes.size(), {AiMesh()}) + pScene.meshes.reserve(pScene.numMeshes + meshes.size()) { AiMesh() } // pScene.mMeshes = ArrayList(pScene.mNumMeshes + meshes.size()); // if( prevArray!=null) // { diff --git a/src/main/kotlin/assimp/format/X/XFileParser.kt b/src/main/kotlin/assimp/format/X/XFileParser.kt index 40bc208..d5e5911 100644 --- a/src/main/kotlin/assimp/format/X/XFileParser.kt +++ b/src/main/kotlin/assimp/format/X/XFileParser.kt @@ -150,9 +150,9 @@ class XFileParser() { var guid: String = GetNextToken() // read and ignore data members - var running = true + val running = true while (running) { - var s: String = GetNextToken() + val s: String = GetNextToken() if (s == "}") break @@ -230,30 +230,29 @@ class XFileParser() { } fun ParseDataObjectMesh(pMesh: Mesh) { - var name: String - var builder: StringBuilder = StringBuilder() + val builder: StringBuilder = StringBuilder() readHeadOfDataObject(builder) - var numVertices: Int = ReadInt() - pMesh.mPositions.resize(numVertices, { AiVector3D() }) + val numVertices: Int = ReadInt() + pMesh.mPositions.resize(numVertices) { AiVector3D() } for (a in IntRange(0, numVertices - 1)) pMesh.mPositions.set(a, ReadVector3()) - var numPosFaces: Int = ReadInt() - pMesh.mPosFaces.resize(numPosFaces, { Face() }) + val numPosFaces: Int = ReadInt() + pMesh.mPosFaces.resize(numPosFaces) { Face() } for (a in 0 until numPosFaces) { - var numIndices: Int = ReadInt() - var face: Face = pMesh.mPosFaces.get(a) + val numIndices: Int = ReadInt() + val face: Face = pMesh.mPosFaces.get(a) for (b in IntRange(0, numIndices - 1)) { face.mIndices.push_back(ReadInt()) } TestForSeparator() } - var running = true + val running = true while (running) { - var objectName: String = GetNextToken() + val objectName: String = GetNextToken() if (objectName.length == 0) throw Error("Unexpected end of file while parsing mesh structure") diff --git a/src/main/kotlin/assimp/format/X/fast_atof.kt b/src/main/kotlin/assimp/format/X/fast_atof.kt index d42d959..649c3af 100644 --- a/src/main/kotlin/assimp/format/X/fast_atof.kt +++ b/src/main/kotlin/assimp/format/X/fast_atof.kt @@ -123,49 +123,50 @@ fun fast_atoreal_move(_c : Pointer, out : Pointer, check_comma : fun strtoul10_64(_in : Pointer, _out : Pointer>?, max_inout : Pointer? = null) : Long { - var in_ = _in; var out_ = _out - var cur : Int = 0; - var value : Long = 0.toLong(); + var in_ = _in; + val out_ = _out + var cur : Int = 0 + var value : Long = 0.toLong() if ( in_.value < '0' || in_.value > '9' ) - throw RuntimeException("The string \"" + in_.value + "\" cannot be converted into a value."); + throw RuntimeException("The string \"" + in_.value + "\" cannot be converted into a value.") - var running = true; - while ( running ) + + while ( true ) { if ( in_.value < '0' || in_.value > '9' ) - break; + break - var new_value : Long = ( value * 10 ) + ( in_.value - '0' ); + val new_value : Long = (value * 10) + (in_.value - '0') // numeric overflow, we rely on you if ( new_value < value ) { - warn("Converting the string \"" + in_.value + "\" into a value resulted in overflow." ); - return 0; + warn("Converting the string \"" + in_.value + "\" into a value resulted in overflow." ) + return 0 } //throw std::overflow_error(); - value = new_value; + value = new_value - ++in_; - ++cur; + ++in_ + ++cur - if (max_inout!=null && max_inout!!.value == cur) { + if (max_inout!=null && max_inout.value == cur) { if (out_!=null) { /* skip to end */ - while (in_.value >= '0' && in_.value <= '9') - ++in_; - out_.value=in_; + while (in_.value in '0'..'9') + ++in_ + out_.value=in_ } - return value; + return value } } if (out_!=null) - out_.value = in_; + out_.value = in_ if (max_inout != null) - max_inout!!.value = cur; + max_inout.value = cur return value; } \ No newline at end of file diff --git a/src/main/kotlin/assimp/format/assbin/AssbinLoader.kt b/src/main/kotlin/assimp/format/assbin/AssbinLoader.kt index 3f46d8f..70a2dd1 100644 --- a/src/main/kotlin/assimp/format/assbin/AssbinLoader.kt +++ b/src/main/kotlin/assimp/format/assbin/AssbinLoader.kt @@ -28,10 +28,10 @@ class AssbinLoader : BaseImporter() { it.skip(44) // signature - val a = it.int(be) // unsigned int versionMajor - val b = it.int(be) // unsigned int versionMinor - val c = it.int(be) // unsigned int versionRevision - val d = it.int(be) // unsigned int compileFlags + /* unused */ it.int(be) // unsigned int versionMajor + /* unused */ it.int(be) // unsigned int versionMinor + /* unused */ it.int(be) // unsigned int versionRevision + /* unused */ it.int(be) // unsigned int compileFlags shortened = it.short(be).bool compressed = it.short(be).bool diff --git a/src/main/kotlin/assimp/format/assxml/AssxmlExporter.kt b/src/main/kotlin/assimp/format/assxml/AssxmlExporter.kt index 2dbd02f..b3e09f5 100644 --- a/src/main/kotlin/assimp/format/assxml/AssxmlExporter.kt +++ b/src/main/kotlin/assimp/format/assxml/AssxmlExporter.kt @@ -91,19 +91,17 @@ class AssxmlExporter { } fun WriteDump(scene : AiScene, io : StringBuilder, shortened : Boolean) { - var tt=Calendar.getInstance(TimeZone.getTimeZone("GMT")) - var p = SimpleDateFormat("HH:mm:ss").format(tt.time) - assert(p!=null) + val tt=Calendar.getInstance(TimeZone.getTimeZone("GMT")) + val curtime = SimpleDateFormat("HH:mm:ss").format(tt.time)!! // write header - var header=( + val header=( "\n\n\n $cleaned" } } @@ -456,15 +456,15 @@ class ObjFileImporter : BaseImporter() { } } - // TODO this is pretty much a copy past from gli.read(...) and should be added there -private fun loadImageFromMemory(file: IOStream, type: String): Texture { +private var tgaAdded = false +private fun loadImageFromMemory(buffer: ByteBuffer, type: String): Texture { return when(type) { - "dds" -> gli.loadDds(file.readBytes()) - "kmg" -> gli.loadKmg(file.readBytes()) - "ktx" -> gli.loadKtx(file.readBytes()) + "dds" -> gli.loadDds(buffer) + "kmg" -> gli.loadKmg(buffer) + "ktx" -> gli.loadKtx(buffer) "jpeg", "jpg", "png", "gif", "bmp", "wbmp" -> { - val image = ImageIO.read(file.read()) + val image = ImageIO.read(ByteBufferBackedInputStream(buffer)) gli.createTexture(image) } "tga" -> { @@ -472,43 +472,9 @@ private fun loadImageFromMemory(file: IOStream, type: String): Texture { IIORegistry.getDefaultInstance().registerServiceProvider(TgaImageReaderSpi()) tgaAdded = true } - val image = ImageIO.read(file.read()) + val image = ImageIO.read(ByteBufferBackedInputStream(buffer)) gli.createTexture(image) } else -> throw IllegalArgumentException("Type not supported") } -} - - -private var tgaAdded = false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +} \ No newline at end of file