Add support for KHR_lights_punctual
This commit is contained in:
@@ -346,7 +346,6 @@ class PBRMaterial : Material {
|
||||
+ p_jointTransforms[j.y] * a_weights.y
|
||||
+ p_jointTransforms[j.z] * a_weights.z
|
||||
+ p_jointTransforms[j.w] * a_weights.w;
|
||||
|
||||
${if (primitiveContext.hasNormalAttribute) """
|
||||
x_normal = normalize(mat3(skinTransform) * x_normal);
|
||||
""".trimIndent() else ""}
|
||||
|
||||
@@ -35,7 +35,15 @@ class GltfNode(val name:String,
|
||||
val rotation: DoubleArray?,
|
||||
val translation: DoubleArray?,
|
||||
val mesh: Int?,
|
||||
val skin: Int?)
|
||||
val skin: Int?,
|
||||
val extensions: GltfNodeExtensions?)
|
||||
|
||||
class KHRLightsPunctualIndex(val light: Int)
|
||||
|
||||
class GltfNodeExtensions(val KHR_lights_punctual: KHRLightsPunctualIndex?) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
class GltfPrimitive(val attributes: LinkedHashMap<String, Int>, val indices: Int?, val mode: Int?, val material: Int) {
|
||||
fun createDrawCommand(gltfFile: GltfFile): GltfDrawCommand {
|
||||
@@ -244,6 +252,14 @@ class GltfChannel(val sampler: Int, val target: GltfChannelTarget)
|
||||
|
||||
class GltfSkin(val inverseBindMatrices: Int, val joints: IntArray, val skeleton: Int)
|
||||
|
||||
|
||||
class KHRLightsPunctualLight(val color: DoubleArray?, val type: String, val intensity: Double?, val range: Double, val spot: KHRLightsPunctualLightSpot?)
|
||||
class KHRLightsPunctualLightSpot(val innerConeAngle: Double?, val outerConeAngle: Double?)
|
||||
|
||||
class KHRLightsPunctual(val lights: List<KHRLightsPunctualLight>)
|
||||
|
||||
class GltfExtensions(val KHR_lights_punctual: KHRLightsPunctual?)
|
||||
|
||||
class GltfFile(
|
||||
val asset: GltfAsset?,
|
||||
val scene: Int?,
|
||||
@@ -258,7 +274,8 @@ class GltfFile(
|
||||
val textures: List<GltfTexture>?,
|
||||
val samplers: List<GltfSampler>?,
|
||||
val animations: List<GltfAnimation>?,
|
||||
val skins: List<GltfSkin>?
|
||||
val skins: List<GltfSkin>?,
|
||||
val extensions: GltfExtensions?
|
||||
) {
|
||||
@Transient
|
||||
lateinit var file: File
|
||||
|
||||
@@ -17,9 +17,9 @@ import kotlin.reflect.KMutableProperty0
|
||||
class SceneAnimation(var channels: List<AnimationChannel>) {
|
||||
|
||||
val duration: Double
|
||||
get() {
|
||||
return channels.maxBy { it.duration }?.duration ?:0.0
|
||||
}
|
||||
get() {
|
||||
return channels.maxBy { it.duration }?.duration ?: 0.0
|
||||
}
|
||||
|
||||
|
||||
fun applyToTargets(input: Double) {
|
||||
@@ -49,6 +49,7 @@ class Vector3Channel(val target: KMutableProperty0<Vector3>,
|
||||
override fun applyToTarget(input: Double) {
|
||||
target.set(keyframer.value(input) ?: default)
|
||||
}
|
||||
|
||||
override val duration: Double
|
||||
get() = keyframer.duration()
|
||||
}
|
||||
@@ -270,6 +271,36 @@ fun GltfFile.buildSceneNodes(): GltfSceneData {
|
||||
val skin = gltfNode.skin?.let { (skins!!)[it] }
|
||||
sceneNode.entities.add(meshes[it].createSceneMesh(skin))
|
||||
}
|
||||
gltfNode.extensions?.let { exts ->
|
||||
exts.KHR_lights_punctual?.let { lightIndex ->
|
||||
extensions?.KHR_lights_punctual?.lights?.get(lightIndex.light)?.let { light ->
|
||||
val sceneLight = when (light.type) {
|
||||
"point" -> {
|
||||
PointLight()
|
||||
}
|
||||
"directional" -> {
|
||||
DirectionalLight().apply {
|
||||
shadows = Shadows.PCF()
|
||||
}
|
||||
}
|
||||
"spot" -> {
|
||||
SpotLight().apply {
|
||||
innerAngle = Math.toDegrees(light.spot!!.innerConeAngle ?: 0.0)
|
||||
outerAngle = Math.toDegrees(light.spot.outerConeAngle ?: Math.PI / 4.0)
|
||||
shadows = Shadows.PCF()
|
||||
}
|
||||
|
||||
}
|
||||
else -> error("unsupported light type ${light.type}")
|
||||
}
|
||||
sceneLight.apply {
|
||||
val lightColor = (light.color ?: doubleArrayOf(1.0, 1.0, 1.0))
|
||||
color = ColorRGBa(lightColor[0], lightColor[1], lightColor[2])
|
||||
}
|
||||
sceneNode.entities.add(sceneLight)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val sceneAnimations = animations?.map { animation ->
|
||||
|
||||
Reference in New Issue
Block a user