Hello, encountered problem with object keys. @JsName("keyName") on fields and @JsExports doesn't work for me or I'm not using them in the right way. More in thread.
✅ 1
Nikolai Sviridov
08/02/2021, 10:11 AM
I'm trying to create a wrapper for three.js class MeshLambertMaterialgithub source line . Here is my code.
Copy code
@file:JsModule("three")
@file:JsNonModule
package wrappers
...
@JsName("MeshLambertMaterial")
external class MeshLambertMaterial(parameters: LambertParameters)
external interface LambertParameters {
@JsName("color")
var color: Long
@JsName("opacity")
var opacity: Float
@JsName("emissive")
var emissive: Long
}
// another file
data class LambertParametersImpl(
override var color: Long,
override var opacity: Float,
override var emissive: Long
) : LambertParameters
Also tried using only data class with JsName.
Nikolai Sviridov
08/02/2021, 10:14 AM
The problem is, when I'm getting 3d object on screen there are following warnings.
Copy code
> THREE.MeshLambertMaterial: '_color_2' is not a property of this material.
> THREE.MeshLambertMaterial: '_opacity' is not a property of this material
... etc
Those warnings coming from github source line, when it iterates over keys.
a
andylamax
08/02/2021, 2:18 PM
It has been my experience that overriding external interfaces still mangle the field and method names. I would approach it like so
Copy code
fun LambertParameters(
color: Long,
opacity: Float,
emissive: Long
) = jsObject<LambertParameters> {
this.color = color
this.opacity = opacity
this.emmisive = emmisive
}