diff --git a/src/jsMain/kotlin/HTMLInputHelpers.kt b/src/jsMain/kotlin/HTMLInputHelpers.kt
index f6698f4..e2bb325 100644
--- a/src/jsMain/kotlin/HTMLInputHelpers.kt
+++ b/src/jsMain/kotlin/HTMLInputHelpers.kt
@@ -21,7 +21,7 @@ class ArrayOfInputsProperty(private val inputs: Array): ReadOn
inputs.mapIndexed { i,input ->
input.oninput = {
cache[i] = input.valueAsNumber.toFloat()
- null
+ null // Function is required to return a js value
}
}
}
diff --git a/src/jsMain/kotlin/Main.kt b/src/jsMain/kotlin/Main.kt
index 66e1ead..248c0b6 100644
--- a/src/jsMain/kotlin/Main.kt
+++ b/src/jsMain/kotlin/Main.kt
@@ -138,11 +138,9 @@ class WebGLWrapper {
val shininessUniform = webgl.getUniformLocation(shaderProgram, "shininess")
webgl.uniform1f(shininessUniform, shininess.toFloat())
- val pMatrix = Mat4()
- pMatrix.perspective(PI / 3, 16.0 / 9.0, 0.1, 60.0)
+ val pMatrix = Mat4.perspective(PI / 3, 16.0 / 9.0, 0.1, 60.0)
- val vMatrix = Mat4()
- vMatrix.lookAt(Vec3(20,20,20), Vec3(0,0,0), Vec3(0,0,1))
+ val vMatrix = Mat4.lookAt(Vec3(20,20,20), Vec3(0,0,0), Vec3(0,0,1))
val mMatrix = Mat4()
mMatrix.scale(scaleFactor)
diff --git a/src/jsMain/kotlin/ObjLoader.kt b/src/jsMain/kotlin/ObjLoader.kt
index 53a4512..25be5f0 100644
--- a/src/jsMain/kotlin/ObjLoader.kt
+++ b/src/jsMain/kotlin/ObjLoader.kt
@@ -1,7 +1,6 @@
import com.tanelso2.glmatrix.Vec3
import org.khronos.webgl.Float32Array
import org.khronos.webgl.Uint16Array
-import org.khronos.webgl.get
import kotlin.random.Random
class ObjLoader(source: String) {
@@ -75,7 +74,7 @@ class ObjLoader(source: String) {
}
fun getVertexNormals(): Float32Array {
- val floatList = normals.flatMap { listOf(it.array[0], it.array[1], it.array[2]) }
+ val floatList = normals.flatMap { it.list() }
return Float32Array(floatList.toTypedArray())
}
diff --git a/src/jsMain/kotlin/ResourceLoader.kt b/src/jsMain/kotlin/ResourceLoader.kt
index 7b1b78e..e7aadfb 100644
--- a/src/jsMain/kotlin/ResourceLoader.kt
+++ b/src/jsMain/kotlin/ResourceLoader.kt
@@ -1,4 +1,5 @@
import kotlinx.browser.window
+import org.w3c.fetch.*
class ResourceLoader(vararg resourceLocations: String) {
private class ResourceInfo {
@@ -6,11 +7,8 @@ class ResourceLoader(vararg resourceLocations: String) {
var value: String? = null
}
private val resourceMap: MutableMap = HashMap()
- private var fetchParams = js("({})")
+ private val fetchParams = RequestInit(method = "GET", cache = RequestCache.NO_STORE, mode = RequestMode.SAME_ORIGIN)
init {
- fetchParams.method = "GET"
- fetchParams.cache = "no-store"
- fetchParams.mode = "same-origin"
for (loc in resourceLocations) {
resourceMap.put(loc, ResourceInfo())
makeRequest(loc)
diff --git a/src/jsMain/kotlin/com/tanelso2/glmatrix/Mat4.kt b/src/jsMain/kotlin/com/tanelso2/glmatrix/Mat4.kt
index 897741c..9ad08b6 100644
--- a/src/jsMain/kotlin/com/tanelso2/glmatrix/Mat4.kt
+++ b/src/jsMain/kotlin/com/tanelso2/glmatrix/Mat4.kt
@@ -7,6 +7,19 @@ typealias Mat4JS = Float32Array
class Mat4(val array: Mat4JS) {
constructor() : this(Float32Array(mat4.create()))
constructor(a: Array) : this(Float32Array(a))
+ companion object {
+ fun lookAt(eye: Vec3, center: Vec3, up: Vec3): Mat4 {
+ val ret = Mat4()
+ ret.lookAt(eye, center, up)
+ return ret
+ }
+
+ fun perspective(fovy: Number, aspect: Number, near: Number, far: Number): Mat4 {
+ val ret = Mat4()
+ ret.perspective(fovy, aspect, near, far)
+ return ret
+ }
+ }
fun clone(): Mat4 = Mat4(array)
fun identity() {
diff --git a/src/jsMain/kotlin/com/tanelso2/glmatrix/Vec3.kt b/src/jsMain/kotlin/com/tanelso2/glmatrix/Vec3.kt
index 3477504..d2adc0d 100644
--- a/src/jsMain/kotlin/com/tanelso2/glmatrix/Vec3.kt
+++ b/src/jsMain/kotlin/com/tanelso2/glmatrix/Vec3.kt
@@ -1,6 +1,7 @@
package com.tanelso2.glmatrix
import org.khronos.webgl.Float32Array
+import org.khronos.webgl.get
typealias Vec3JS = Float32Array
@@ -27,6 +28,10 @@ class Vec3(val array: Vec3JS) {
vec3.add(ret.array, this.array, other.array)
return ret
}
+
+ fun list(): List {
+ return listOf(array[0], array[1], array[2])
+ }
}
external open class vec3 {