Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ dependencies {
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'


ext.lwjglVersion = "3.2.0"
switch (OperatingSystem.current()) {
case OperatingSystem.WINDOWS:
Expand Down
12 changes: 3 additions & 9 deletions src/main/kotlin/assimp/Importer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/assimp/ImporterPimpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
96 changes: 1 addition & 95 deletions src/main/kotlin/assimp/MemoryIOWrapper.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package assimp

import glm_.*
import gli_.ByteBufferBackedInputStream
import java.io.*
import java.nio.*
import java.io.IOException



const val AI_MEMORYIO_MAGIC_FILENAME = "\$\$\$___magic___\$\$\$"
const val AI_MEMORYIO_MAGIC_FILENAME_LENGTH = 17

Expand Down Expand Up @@ -64,97 +63,4 @@ class MemoryIOSystem : IOSystem{

override fun readBytes(): ByteBuffer = buffer.duplicate().order(ByteOrder.nativeOrder())
}
}

// TODO move this to a different file?
private class ByteBufferBackedInputStream(val buf: ByteBuffer) : InputStream() {

/**
* Reads the next byte of data from the input stream. The value byte is
* returned as an <code>int</code> in the range <code>0</code> to
* <code>255</code>. If no byte is available because the end of the stream
* has been reached, the value <code>-1</code> is returned. This method
* blocks until input data is available, the end of the stream is detected,
* or an exception is thrown.
*
* <p> A subclass must provide an implementation of this method.
*
* @return the next byte of data, or <code>-1</code> if the end of the
* stream is reached.
* @exception IOException if an I/O error occurs.
*/
override fun read(): Int {
return if (!buf.hasRemaining()) {
-1
} else buf.get().toInt() and 0xFF
}

/**
* Reads up to <code>len</code> bytes of data from the input stream into
* an array of bytes. An attempt is made to read as many as
* <code>len</code> bytes, but a smaller number may be read.
* The number of bytes actually read is returned as an integer.
*
* <p> This method blocks until input data is available, end of file is
* detected, or an exception is thrown.
*
* <p> If <code>len</code> is zero, then no bytes are read and
* <code>0</code> is returned; otherwise, there is an attempt to read at
* least one byte. If no byte is available because the stream is at end of
* file, the value <code>-1</code> is returned; otherwise, at least one
* byte is read and stored into <code>b</code>.
*
* <p> The first byte read is stored into element <code>b[off]</code>, the
* next one into <code>b[off+1]</code>, and so on. The number of bytes read
* is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
* bytes actually read; these bytes will be stored in elements
* <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
* leaving elements <code>b[off+</code><i>k</i><code>]</code> through
* <code>b[off+len-1]</code> unaffected.
*
* <p> In every case, elements <code>b[0]</code> through
* <code>b[off]</code> and elements <code>b[off+len]</code> through
* <code>b[b.length-1]</code> are unaffected.
*
* <p> The <code>read(b,</code> <code>off,</code> <code>len)</code> method
* for class <code>InputStream</code> simply calls the method
* <code>read()</code> repeatedly. If the first such call results in an
* <code>IOException</code>, that exception is returned from the call to
* the <code>read(b,</code> <code>off,</code> <code>len)</code> method. If
* any subsequent call to <code>read()</code> results in a
* <code>IOException</code>, the exception is caught and treated as if it
* were end of file; the bytes read up to that point are stored into
* <code>b</code> and the number of bytes read before the exception
* occurred is returned. The default implementation of this method blocks
* until the requested amount of input data <code>len</code> has been read,
* end of file is detected, or an exception is thrown. Subclasses are encouraged
* to provide a more efficient implementation of this method.
*
* @param b the buffer into which the data is read.
* @param off the start offset in array <code>b</code>
* at which the data is written.
* @param len the maximum number of bytes to read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* the stream has been reached.
* @exception IOException If the first byte cannot be read for any reason
* other than end of file, or if the input stream has been closed, or if
* some other I/O error occurs.
* @exception NullPointerException If <code>b</code> is <code>null</code>.
* @exception IndexOutOfBoundsException If <code>off</code> is negative,
* <code>len</code> is negative, or <code>len</code> is greater than
* <code>b.length - off</code>
* @see java.io.InputStream#read()
*/
override fun read(bytes: ByteArray, off: Int, len: Int): Int {
@Suppress("NAME_SHADOWING")
var len = len
if (!buf.hasRemaining()) {
return -1
}

len = Math.min(len, buf.remaining())
buf.get(bytes, off, len)
return len
}
}
2 changes: 2 additions & 0 deletions src/main/kotlin/assimp/PolyTools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/assimp/SGSpatialSort.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SGSpatialSort {

fun prepare()
{
val array = mPositions.toArray() as Array<Entry>
val array = mPositions.toTypedArray()
Arrays.sort(array)
mPositions.clear()
mPositions.addAll(array)
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/assimp/SkeletonMeshBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/assimp/SpatialSort.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class SpatialSort{
}

fun finalize() {
val array = mPositions.toArray() as Array<Entry>
val array = mPositions.toTypedArray()
Arrays.sort(array)
mPositions.clear()
mPositions.addAll(array)
}

fun append(pPositions: List<AiVector3D>,pNumPositions: Int,pElementOffset: Int, pFinalize: Boolean = true)
fun append(pPositions: List<AiVector3D>,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
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/assimp/format/X/ConvertToLHProcess.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 18 additions & 27 deletions src/main/kotlin/assimp/format/X/XFileImporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}

Expand All @@ -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...
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
}
Expand All @@ -261,21 +251,21 @@ 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

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?
Expand Down Expand Up @@ -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++)))
}
}
Expand Down Expand Up @@ -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<Int> = mutableListOf() // from which original point each new vertex stems
val orgPoints: MutableList<Int> = 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<Int>(pf.mIndices.size(), { 0 }); mesh.faces[c]=df
val df = MutableList<Int>(pf.mIndices.size()) { 0 }
mesh.faces[c]=df

// collect vertex data for indices of this face
for (d in 0 until df.size()) {
Expand All @@ -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()
Expand Down Expand Up @@ -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<AiMesh>(pScene.mNumMeshes + meshes.size());
// if( prevArray!=null)
// {
Expand Down
Loading