"Show skeleton" checkbox is now disabled when the current viewer model doesn't have a skeleton.

This commit is contained in:
Daan Vanden Bosch 2021-04-08 21:04:51 +02:00
parent 5be29df0ac
commit e4cbc38d4a
5 changed files with 25 additions and 9 deletions

View File

@ -331,7 +331,7 @@ open external class Mesh(
val isMesh: Boolean val isMesh: Boolean
var geometry: BufferGeometry var geometry: BufferGeometry
var material: Any /* Material | Material[] */ var material: dynamic /* Material | Material[] */
fun translateY(distance: Double): Mesh fun translateY(distance: Double): Mesh
} }
@ -382,7 +382,9 @@ external class Skeleton(bones: Array<Bone>, boneInverses: Array<Matrix4> = defin
external class SkeletonHelper(`object`: Object3D) : LineSegments external class SkeletonHelper(`object`: Object3D) : LineSegments
open external class Line : Object3D open external class Line : Object3D {
var material: dynamic /* Material | Material[] */
}
open external class LineSegments : Line open external class LineSegments : Line
@ -612,6 +614,10 @@ external class MeshLambertMaterial(
parameters: MeshLambertMaterialParameters = definedExternally, parameters: MeshLambertMaterialParameters = definedExternally,
) : Material ) : Material
external class LineBasicMaterial : Material {
var linewidth: Int
}
open external class Texture : EventDispatcher { open external class Texture : EventDispatcher {
var needsUpdate: Boolean var needsUpdate: Boolean

View File

@ -2,7 +2,10 @@ package world.phantasmal.web.viewer.controllers
import mu.KotlinLogging import mu.KotlinLogging
import org.w3c.files.File import org.w3c.files.File
import world.phantasmal.core.* import world.phantasmal.core.Failure
import world.phantasmal.core.PwResult
import world.phantasmal.core.Severity
import world.phantasmal.core.Success
import world.phantasmal.lib.Endianness import world.phantasmal.lib.Endianness
import world.phantasmal.lib.compression.prs.prsDecompress import world.phantasmal.lib.compression.prs.prsDecompress
import world.phantasmal.lib.cursor.Cursor import world.phantasmal.lib.cursor.Cursor
@ -25,6 +28,7 @@ class ViewerToolbarController(private val store: ViewerStore) : Controller() {
private val _resultDialogVisible = mutableVal(false) private val _resultDialogVisible = mutableVal(false)
private val _result = mutableVal<PwResult<*>?>(null) private val _result = mutableVal<PwResult<*>?>(null)
val showSkeletonEnabled: Val<Boolean> = store.showSkeletonEnabled
val showSkeleton: Val<Boolean> = store.showSkeleton val showSkeleton: Val<Boolean> = store.showSkeleton
val playAnimation: Val<Boolean> = store.animationPlaying val playAnimation: Val<Boolean> = store.animationPlaying
val frameRate: Val<Int> = store.frameRate val frameRate: Val<Int> = store.frameRate

View File

@ -50,8 +50,8 @@ class MeshRenderer(
)) ))
init { init {
observe(viewerStore.currentNinjaGeometry) { ninjaObjectOrXvmChanged() } observe(viewerStore.currentNinjaGeometry) { ninjaGeometryOrXvmChanged() }
observe(viewerStore.currentTextures) { ninjaObjectOrXvmChanged() } observe(viewerStore.currentTextures) { ninjaGeometryOrXvmChanged() }
observe(viewerStore.currentNinjaMotion, ::ninjaMotionChanged) observe(viewerStore.currentNinjaMotion, ::ninjaMotionChanged)
observe(viewerStore.showSkeleton) { skeletonHelper?.visible = it } observe(viewerStore.showSkeleton) { skeletonHelper?.visible = it }
observe(viewerStore.animationPlaying, ::animationPlayingChanged) observe(viewerStore.animationPlaying, ::animationPlayingChanged)
@ -80,7 +80,7 @@ class MeshRenderer(
} }
} }
private fun ninjaObjectOrXvmChanged() { private fun ninjaGeometryOrXvmChanged() {
// Remove the previous mesh. // Remove the previous mesh.
obj3d?.let { mesh -> obj3d?.let { mesh ->
disposeObject3DResources(mesh) disposeObject3DResources(mesh)
@ -124,7 +124,7 @@ class MeshRenderer(
} }
// Determine whether camera needs to be reset. Resets should always happen when the // Determine whether camera needs to be reset. Resets should always happen when the
// Ninja object changes except when we're switching between character class models. // Ninja geometry changes except when we're switching between character class models.
val charClassActive = viewerStore.currentCharacterClass.value != null val charClassActive = viewerStore.currentCharacterClass.value != null
val resetCamera = !charClassActive || !this.charClassActive val resetCamera = !charClassActive || !this.charClassActive
this.charClassActive = charClassActive this.charClassActive = charClassActive
@ -145,7 +145,7 @@ class MeshRenderer(
// Add skeleton. // Add skeleton.
val skeletonHelper = SkeletonHelper(obj3d) val skeletonHelper = SkeletonHelper(obj3d)
skeletonHelper.visible = viewerStore.showSkeleton.value skeletonHelper.visible = viewerStore.showSkeleton.value
skeletonHelper.asDynamic().material.lineWidth = 3 skeletonHelper.material.unsafeCast<LineBasicMaterial>().linewidth = 3
context.scene.add(skeletonHelper) context.scene.add(skeletonHelper)
this.skeletonHelper = skeletonHelper this.skeletonHelper = skeletonHelper

View File

@ -7,8 +7,10 @@ import world.phantasmal.lib.fileFormats.CollisionGeometry
import world.phantasmal.lib.fileFormats.RenderGeometry import world.phantasmal.lib.fileFormats.RenderGeometry
import world.phantasmal.lib.fileFormats.ninja.NinjaObject import world.phantasmal.lib.fileFormats.ninja.NinjaObject
import world.phantasmal.lib.fileFormats.ninja.NjMotion import world.phantasmal.lib.fileFormats.ninja.NjMotion
import world.phantasmal.lib.fileFormats.ninja.NjObject
import world.phantasmal.lib.fileFormats.ninja.XvrTexture import world.phantasmal.lib.fileFormats.ninja.XvrTexture
import world.phantasmal.observable.value.Val import world.phantasmal.observable.value.Val
import world.phantasmal.observable.value.and
import world.phantasmal.observable.value.list.ListVal import world.phantasmal.observable.value.list.ListVal
import world.phantasmal.observable.value.list.mutableListVal import world.phantasmal.observable.value.list.mutableListVal
import world.phantasmal.observable.value.mutableVal import world.phantasmal.observable.value.mutableVal
@ -72,7 +74,10 @@ class ViewerStore(
val currentAnimation: Val<AnimationModel?> = _currentAnimation val currentAnimation: Val<AnimationModel?> = _currentAnimation
// Settings. // Settings.
val showSkeleton: Val<Boolean> = _showSkeleton val showSkeletonEnabled: Val<Boolean> = _currentNinjaGeometry.map {
it is NinjaGeometry.Object && it.obj is NjObject
}
val showSkeleton: Val<Boolean> = showSkeletonEnabled and _showSkeleton
val animationPlaying: Val<Boolean> = _animationPlaying val animationPlaying: Val<Boolean> = _animationPlaying
val frameRate: Val<Int> = _frameRate val frameRate: Val<Int> = _frameRate
val frame: Val<Int> = _frame val frame: Val<Int> = _frame

View File

@ -23,6 +23,7 @@ class ViewerToolbar(private val ctrl: ViewerToolbarController) : Widget() {
), ),
Checkbox( Checkbox(
label = "Show skeleton", label = "Show skeleton",
enabled = ctrl.showSkeletonEnabled,
checked = ctrl.showSkeleton, checked = ctrl.showSkeleton,
onChange = ctrl::setShowSkeleton, onChange = ctrl::setShowSkeleton,
), ),