diff --git a/web/src/main/kotlin/world/phantasmal/web/externals/three/three.kt b/web/src/main/kotlin/world/phantasmal/web/externals/three/three.kt index 4b967ef3..2a33842d 100644 --- a/web/src/main/kotlin/world/phantasmal/web/externals/three/three.kt +++ b/web/src/main/kotlin/world/phantasmal/web/externals/three/three.kt @@ -331,7 +331,7 @@ open external class Mesh( val isMesh: Boolean var geometry: BufferGeometry - var material: Any /* Material | Material[] */ + var material: dynamic /* Material | Material[] */ fun translateY(distance: Double): Mesh } @@ -382,7 +382,9 @@ external class Skeleton(bones: Array, boneInverses: Array = defin 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 @@ -612,6 +614,10 @@ external class MeshLambertMaterial( parameters: MeshLambertMaterialParameters = definedExternally, ) : Material +external class LineBasicMaterial : Material { + var linewidth: Int +} + open external class Texture : EventDispatcher { var needsUpdate: Boolean diff --git a/web/src/main/kotlin/world/phantasmal/web/viewer/controllers/ViewerToolbarController.kt b/web/src/main/kotlin/world/phantasmal/web/viewer/controllers/ViewerToolbarController.kt index 65ab50a5..fc4fb75a 100644 --- a/web/src/main/kotlin/world/phantasmal/web/viewer/controllers/ViewerToolbarController.kt +++ b/web/src/main/kotlin/world/phantasmal/web/viewer/controllers/ViewerToolbarController.kt @@ -2,7 +2,10 @@ package world.phantasmal.web.viewer.controllers import mu.KotlinLogging 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.compression.prs.prsDecompress import world.phantasmal.lib.cursor.Cursor @@ -25,6 +28,7 @@ class ViewerToolbarController(private val store: ViewerStore) : Controller() { private val _resultDialogVisible = mutableVal(false) private val _result = mutableVal?>(null) + val showSkeletonEnabled: Val = store.showSkeletonEnabled val showSkeleton: Val = store.showSkeleton val playAnimation: Val = store.animationPlaying val frameRate: Val = store.frameRate diff --git a/web/src/main/kotlin/world/phantasmal/web/viewer/rendering/MeshRenderer.kt b/web/src/main/kotlin/world/phantasmal/web/viewer/rendering/MeshRenderer.kt index e6f4f30c..e04590d5 100644 --- a/web/src/main/kotlin/world/phantasmal/web/viewer/rendering/MeshRenderer.kt +++ b/web/src/main/kotlin/world/phantasmal/web/viewer/rendering/MeshRenderer.kt @@ -50,8 +50,8 @@ class MeshRenderer( )) init { - observe(viewerStore.currentNinjaGeometry) { ninjaObjectOrXvmChanged() } - observe(viewerStore.currentTextures) { ninjaObjectOrXvmChanged() } + observe(viewerStore.currentNinjaGeometry) { ninjaGeometryOrXvmChanged() } + observe(viewerStore.currentTextures) { ninjaGeometryOrXvmChanged() } observe(viewerStore.currentNinjaMotion, ::ninjaMotionChanged) observe(viewerStore.showSkeleton) { skeletonHelper?.visible = it } observe(viewerStore.animationPlaying, ::animationPlayingChanged) @@ -80,7 +80,7 @@ class MeshRenderer( } } - private fun ninjaObjectOrXvmChanged() { + private fun ninjaGeometryOrXvmChanged() { // Remove the previous mesh. obj3d?.let { mesh -> disposeObject3DResources(mesh) @@ -124,7 +124,7 @@ class MeshRenderer( } // 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 resetCamera = !charClassActive || !this.charClassActive this.charClassActive = charClassActive @@ -145,7 +145,7 @@ class MeshRenderer( // Add skeleton. val skeletonHelper = SkeletonHelper(obj3d) skeletonHelper.visible = viewerStore.showSkeleton.value - skeletonHelper.asDynamic().material.lineWidth = 3 + skeletonHelper.material.unsafeCast().linewidth = 3 context.scene.add(skeletonHelper) this.skeletonHelper = skeletonHelper diff --git a/web/src/main/kotlin/world/phantasmal/web/viewer/stores/ViewerStore.kt b/web/src/main/kotlin/world/phantasmal/web/viewer/stores/ViewerStore.kt index a93ce0b7..1dbdfd03 100644 --- a/web/src/main/kotlin/world/phantasmal/web/viewer/stores/ViewerStore.kt +++ b/web/src/main/kotlin/world/phantasmal/web/viewer/stores/ViewerStore.kt @@ -7,8 +7,10 @@ import world.phantasmal.lib.fileFormats.CollisionGeometry import world.phantasmal.lib.fileFormats.RenderGeometry import world.phantasmal.lib.fileFormats.ninja.NinjaObject import world.phantasmal.lib.fileFormats.ninja.NjMotion +import world.phantasmal.lib.fileFormats.ninja.NjObject import world.phantasmal.lib.fileFormats.ninja.XvrTexture 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.mutableListVal import world.phantasmal.observable.value.mutableVal @@ -72,7 +74,10 @@ class ViewerStore( val currentAnimation: Val = _currentAnimation // Settings. - val showSkeleton: Val = _showSkeleton + val showSkeletonEnabled: Val = _currentNinjaGeometry.map { + it is NinjaGeometry.Object && it.obj is NjObject + } + val showSkeleton: Val = showSkeletonEnabled and _showSkeleton val animationPlaying: Val = _animationPlaying val frameRate: Val = _frameRate val frame: Val = _frame diff --git a/web/src/main/kotlin/world/phantasmal/web/viewer/widgets/ViewerToolbar.kt b/web/src/main/kotlin/world/phantasmal/web/viewer/widgets/ViewerToolbar.kt index 36237312..b6c3dedc 100644 --- a/web/src/main/kotlin/world/phantasmal/web/viewer/widgets/ViewerToolbar.kt +++ b/web/src/main/kotlin/world/phantasmal/web/viewer/widgets/ViewerToolbar.kt @@ -23,6 +23,7 @@ class ViewerToolbar(private val ctrl: ViewerToolbarController) : Widget() { ), Checkbox( label = "Show skeleton", + enabled = ctrl.showSkeletonEnabled, checked = ctrl.showSkeleton, onChange = ctrl::setShowSkeleton, ),