Skip to content

Commit 2b41659

Browse files
Add SKN and CMX parser, add HarmonyMath
1 parent 0610b6c commit 2b41659

File tree

12 files changed

+1097
-0
lines changed

12 files changed

+1097
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ By the default the IFF reader does not attempt to decode any of the chunk data,
5757
* The Sims Online's FAR3 archive are weird... `packingslips.dat` files don't seem to have any name?!
5858
* It looks like floors in The Sims Complete Collection (not in HomeCrafter, heck, not even in The Sims Legacy Collection!) HATES SPR2 that uses any pixel command except 0x06 and 0x03
5959
* I think it is because floors are encoded with the flag 1 (only color channel) and, while Legacy Collection and HomeCrafter does not care about that, Complete Collection does care about it and trips out after encountering an unexpected flag.
60+
* Figuring out how the game handles the SKN <-> CMX <-> BMP relation is confusing...
61+
* The game uses the bitmap in the `skn` file, but it ONLY seems to use it for accessories
62+
* **TODO:** ACTUALLY DOCUMENT THIS ^^^
63+
* The reason why we use `harmonymath` instead of JOML is because we want to use the lib on the browser too, which is why we haphazardly ported some of the JOML classes to Kotlin Multiplatform
64+
* The SKN/CMX parser seems to work fine, it is used for [SneakySims's Website](https://sneakysims.net) for skin rendering preview
65+
6066
### Reading SPR# Images and Converting
6167

6268
```kotlin

harmonymath/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# HarmonyMath
2+
3+
Math libraries for Kotlin Multiplatform.
4+
5+
The classes are mostly straight to Kotlin JOML classes.
6+
7+
For SneakyLib, HarmonyMath is used for quaternions and other 3D model related things, and it is also used in the SneakySims website for 3D skin rendering using WebGL2.

harmonymath/build.gradle.kts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
plugins {
2+
kotlin("multiplatform")
3+
id("maven-publish")
4+
}
5+
6+
group = "net.perfectdreams.harmony.math"
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
kotlin {
13+
jvmToolchain(21)
14+
15+
jvm {
16+
withJava()
17+
}
18+
19+
js(IR) {
20+
browser()
21+
}
22+
23+
sourceSets {
24+
val commonMain by getting {
25+
dependencies {
26+
implementation(kotlin("stdlib-common"))
27+
}
28+
}
29+
30+
val jsMain by getting {
31+
dependencies {
32+
}
33+
}
34+
35+
val jvmTest by getting {
36+
dependencies {
37+
implementation(kotlin("test"))
38+
// https://mvnrepository.com/artifact/org.joml/joml
39+
implementation("org.joml:joml:1.10.8")
40+
}
41+
}
42+
}
43+
}
44+
45+
publishing {
46+
repositories {
47+
maven {
48+
name = "PerfectDreams"
49+
url = uri("https://repo.perfectdreams.net/")
50+
credentials(PasswordCredentials::class)
51+
}
52+
}
53+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package net.perfectdreams.harmony.math
2+
3+
import kotlin.math.PI
4+
import kotlin.math.sqrt
5+
6+
object HarmonyMath {
7+
const val PI_f = PI.toFloat()
8+
const val PI_OVER_2_f = (PI * 0.5).toFloat()
9+
const val PI_TIMES_2_f = PI_f * 2.0f
10+
private const val DEGREES_TO_RADIANS: Double = 0.017453292519943295
11+
12+
fun fma(a: Float, b: Float, c: Float): Float {
13+
return a * b + c
14+
}
15+
16+
fun cosFromSin(sin: Float, angle: Float): Float {
17+
// sin(x)^2 + cos(x)^2 = 1
18+
val cos: Float = sqrt(1.0f - sin * sin)
19+
val a: Float = angle + PI_OVER_2_f
20+
var b: Float = a - (a / PI_TIMES_2_f).toInt() * PI_TIMES_2_f
21+
if (b < 0.0) b = PI_TIMES_2_f + b
22+
if (b >= PI_f) return -cos
23+
return cos
24+
}
25+
26+
fun invsqrt(r: Float): Float {
27+
return 1.0f / sqrt(r)
28+
}
29+
30+
fun toRadians(angdeg: Double): Double {
31+
return angdeg * DEGREES_TO_RADIANS
32+
}
33+
}

0 commit comments

Comments
 (0)