Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
c31c3ae
Trying to fix flying rigidbodies and improve the performance by passi…
Sylsatra Nov 29, 2025
48fe73c
Bump mod version to 0.0.9 and change the JNI shared bufer mathces the…
Sylsatra Nov 29, 2025
f4a1ef2
Bump mod version to 0.0.10 and reduce the worker heap size
Sylsatra Nov 29, 2025
8ee3116
Try pushing into a new branch cuz new-physics brand is weird
Sylsatra Nov 29, 2025
7bc0dfd
A desperate attempt to figure out why the zip is missing many jars
Sylsatra Nov 29, 2025
587c606
A desperate attempt to figure out why the zip is missing many jars - 2
Sylsatra Nov 29, 2025
9b5ef34
Send help
Sylsatra Nov 29, 2025
a42d3b0
Send help 2
Sylsatra Nov 29, 2025
1353fdd
Correcting the math: NewState = OldState * WorldInv * Physics
Sylsatra Nov 29, 2025
962268d
Fixed Compilation error
Sylsatra Nov 29, 2025
79862ab
Switch the coordinate sytem from Right to Left
Sylsatra Nov 29, 2025
39aaafd
Fixed double scalling in PhysicsScene
Sylsatra Nov 30, 2025
7c3b74a
Apply C InvZ
Sylsatra Nov 30, 2025
3f0d9c3
Invert Ignore Mask and removed InvZ from PhysicsWorld
Sylsatra Nov 30, 2025
12b4319
Reverted deleting some chunks
Sylsatra Nov 30, 2025
c79f2fe
Delete logs_51071426239 directory
Sylsatra Nov 30, 2025
a26df22
Fixed the uninitialized transforms
Sylsatra Nov 30, 2025
1188060
Fixed the uninitialized transforms
Sylsatra Nov 30, 2025
fd897cb
Fixed the Matrix Accumulation Bug
Sylsatra Nov 30, 2025
5560892
Changed rotation construction & added z-rotation flip
Sylsatra Nov 30, 2025
7c6ee2f
Revert RigidBodyComponent to its original logic
Sylsatra Nov 30, 2025
fc34b6d
Added missing translation in PhysicMotionState constructor
Sylsatra Nov 30, 2025
cc18b01
Fixed wrong origin
Sylsatra Nov 30, 2025
db7fa29
Reverted RigidBodyComponent to use accumulation logic (again)
Sylsatra Nov 30, 2025
f2ab302
Correct Joint Initialization
Sylsatra Nov 30, 2025
f492e8d
Fixed compilation errors
Sylsatra Nov 30, 2025
b997bd5
Tried Unifing The Coordinate System
Sylsatra Nov 30, 2025
2c3f93f
Tried Unifing The Coordinate System Again
Sylsatra Nov 30, 2025
f13296f
Removed Double Negation -Y
Sylsatra Nov 30, 2025
2206fa0
Changed the handling of transform_buffer
Sylsatra Nov 30, 2025
7e1c908
Fixed mismatched Y
Sylsatra Nov 30, 2025
1aab2e0
Added loggings to inspect
Sylsatra Nov 30, 2025
993c0c7
Added more loggings to inspect
Sylsatra Nov 30, 2025
2bed2f8
Fixed problem with identity
Sylsatra Nov 30, 2025
180ebbf
Fixed Transform buffer index misalignment
Sylsatra Nov 30, 2025
ad4b908
Apply angular limits
Sylsatra Nov 30, 2025
a491b41
Even more logs
Sylsatra Nov 30, 2025
fcdcfaf
Stabilize hair/skirts
Sylsatra Nov 30, 2025
5b77161
Stabilize hair/skirts again
Sylsatra Nov 30, 2025
f93a675
Use Euler convention in PhysicsWorld
Sylsatra Nov 30, 2025
8177088
Fix Rigidbody orientation order
Sylsatra Nov 30, 2025
209c7ad
Bump PHYSICS_MAX_SUB_STEP_COUNT from 1 to 10
Sylsatra Dec 1, 2025
12092f1
Even more logs
Sylsatra Dec 1, 2025
df6750f
change the PHYSICS bone
Sylsatra Dec 1, 2025
2df45d8
Why the bangs are flying away :(
Sylsatra Dec 1, 2025
cac0337
Snap back if flew too far
Sylsatra Dec 1, 2025
e494bf7
Oopsie
Sylsatra Dec 1, 2025
a07b1f0
simplifying physics
Sylsatra Dec 1, 2025
c9b9923
Even more loggings
Sylsatra Dec 1, 2025
a021262
More Natural Hair
Sylsatra Dec 1, 2025
70b0c73
More Natural Hair and Skirt
Sylsatra Dec 1, 2025
769117e
More Logging
Sylsatra Dec 1, 2025
cab026d
Ajust skirt physics
Sylsatra Dec 1, 2025
4ae2e7e
Try to fix the skirt
Sylsatra Dec 1, 2025
8fb70cc
More loggings
Sylsatra Dec 1, 2025
81a0ee9
Fix the math
Sylsatra Dec 1, 2025
b4fd6f7
Move skirt end to PHYSICS_PLUS_BONE
Sylsatra Dec 2, 2025
dc30c95
Try a different physics
Sylsatra Dec 2, 2025
da0ce6c
Fixed compiling errors
Sylsatra Dec 3, 2025
60134f2
Implement reseting exloding
Sylsatra Dec 3, 2025
b5449f9
Tightened the angular limits and softened springs
Sylsatra Dec 3, 2025
c56571b
Tightened the angular limits and softened springs for Skirt_B and Ski…
Sylsatra Dec 3, 2025
b7f0bb2
Tightened the angular limits and softened springs for even smaller parts
Sylsatra Dec 3, 2025
22c0235
Fix B/C rings
Sylsatra Dec 4, 2025
9c26a22
Widened B/C limits
Sylsatra Dec 4, 2025
7815db3
Fix skirt flying upward
Sylsatra Dec 4, 2025
1371fc2
Relaxing B/C
Sylsatra Dec 4, 2025
60cf7f7
Implemented D-specific angular limits
Sylsatra Dec 4, 2025
d7ccffd
Implemented D-ring angular limits
Sylsatra Dec 4, 2025
6a08708
Change the Y of spring
Sylsatra Dec 4, 2025
0cac816
Change skirt ring joint rotations to identity
Sylsatra Dec 4, 2025
95b8d1e
Remove self skirt collision
Sylsatra Dec 4, 2025
5d2cd45
Tether all skirt bodies to bones
Sylsatra Dec 4, 2025
1dcb22d
Add a missing brace
Sylsatra Dec 4, 2025
468f682
Changed the skirt B/C joints
Sylsatra Dec 4, 2025
7826e60
More logs
Sylsatra Dec 4, 2025
f2a04ce
More logs
Sylsatra Dec 4, 2025
93fcaea
Skirt dont collide with weapon
Sylsatra Dec 4, 2025
79d6dad
Disable collisionMask
Sylsatra Dec 4, 2025
ebd0e04
Tighten the D ring
Sylsatra Dec 4, 2025
0d2d28a
accessories follow the bone
Sylsatra Dec 4, 2025
c155444
Temporarily remove the physics from the skirt
Sylsatra Dec 4, 2025
1a8dbc8
Disable linear springs for B/C skirt
Sylsatra Dec 4, 2025
65924b5
Added an extra clamp for B/C skirt joints
Sylsatra Dec 5, 2025
dd44b07
Matching KAIMyEntity-C
Sylsatra Dec 21, 2025
91f1d92
Fix Mixin Error
Sylsatra Dec 21, 2025
7f8fd0f
Fix Physic
Sylsatra Dec 21, 2025
2454207
Fix Physic
Sylsatra Dec 22, 2025
99bc2d7
Fix Physic
Sylsatra Dec 22, 2025
1e69af8
Fix Physic and Animation
Sylsatra Dec 22, 2025
7848929
Fix Physic and Animation
Sylsatra Dec 23, 2025
8260794
Fix Physic and Animation
Sylsatra Dec 23, 2025
1b0042d
Fix Physic and Animation
Sylsatra Dec 23, 2025
034e18a
Revert + Fix
Sylsatra Dec 23, 2025
3a7aba4
Revert + Fix
Sylsatra Dec 23, 2025
29e9e19
Revert + Fix
Sylsatra Dec 23, 2025
0a41b50
Try again
Sylsatra Jan 2, 2026
551cb9c
Animation Masking API
Sylsatra Jan 2, 2026
d521eba
Animation Masking API -> Capability
Sylsatra Jan 2, 2026
63ad08a
Fix Held Item and Skirt Vibration
Sylsatra Jan 2, 2026
b5d7d98
Revert & Fix Skirt Vibration
Sylsatra Jan 3, 2026
3865543
Fix held item rendering
Sylsatra Jan 3, 2026
9784860
Held Item Scale
Sylsatra Jan 3, 2026
8abdd10
Correct Held Item Path
Sylsatra Jan 3, 2026
3b0d1c5
Fix mistake with PlayerEntity
Sylsatra Jan 3, 2026
bd522e0
Try to allign hand held item
Sylsatra Jan 3, 2026
65b850b
Try to allign hand held item - Again
Sylsatra Jan 3, 2026
52714f9
physics collision filtering + linked-body collision disabling
Sylsatra Jan 3, 2026
7b65d47
Revert + Improve collision filtering correctness
Sylsatra Jan 4, 2026
1d01cb8
Revert + Fix Config to apply correct item scale + Update the joint ro…
Sylsatra Jan 4, 2026
4912e4c
Revert + Update the config & UI to support Held Item
Sylsatra Jan 4, 2026
731dc36
Try to improve RigidBodies to minimize vibration
Sylsatra Jan 4, 2026
b4916f6
Reverted the mask inversion
Sylsatra Jan 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: bazel-contrib/setup-bazel@0.14.0
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
disk-cache: true
repository-cache: true
- name: build
run: |
Expand All @@ -39,20 +39,24 @@ jobs:
--verbose_failures \
//blazerod/model:test \
//blazerod/render:test
- name: collect artifacts
run: |
mkdir -p artifacts
BAZEL_BIN=$(bazel info bazel-bin --config opt)
cp "$BAZEL_BIN/mod/mod_fabric.jar" artifacts/
cp "$BAZEL_BIN/mod/mod_neoforge.jar" artifacts/
cp "$BAZEL_BIN/blazerod/blazerod_fabric.jar" artifacts/
cp "$BAZEL_BIN/blazerod/blazerod_neoforge.jar" artifacts/
cp "$BAZEL_BIN/blazerod/model/model-base/model-base.jar" artifacts/
cp "$BAZEL_BIN/blazerod/model/model-formats/model-formats.jar" artifacts/
cp "$BAZEL_BIN/blazerod/model/model-gltf/model-gltf.jar" artifacts/
cp "$BAZEL_BIN/blazerod/model/model-pmd/model-pmd.jar" artifacts/
cp "$BAZEL_BIN/blazerod/model/model-pmx/model-pmx.jar" artifacts/
cp "$BAZEL_BIN/blazerod/model/model-vmd/model-vmd.jar" artifacts/
cp "$BAZEL_BIN/blazerod/model/model-assimp/model-assimp-merged.jar" artifacts/
cp "$BAZEL_BIN/blazerod/example/ball_block/ball_block.jar" artifacts/
- name: capture build artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts-bazel
path: |
bazel-bin/mod/mod_fabric.jar
bazel-bin/mod/mod_neoforge.jar
bazel-bin/blazerod/blazerod_fabric.jar
bazel-bin/blazerod/blazerod_neoforge.jar
bazel-bin/blazerod/model/model-base/model-base.jar
bazel-bin/blazerod/model/model-formats/model-formats.jar
bazel-bin/blazerod/model/model-gltf/model-gltf.jar
bazel-bin/blazerod/model/model-pmd/model-pmd.jar
bazel-bin/blazerod/model/model-pmx/model-pmx.jar
bazel-bin/blazerod/model/model-vmd/model-vmd.jar
bazel-bin/blazerod/model/model-assimp/model-assimp-merged.jar
bazel-bin/blazerod/example/ball_block/ball_block.jar
path: artifacts/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ compile_commands.json
.bazelbsp
bazel-*
external

#KAIMyEntity-C
KAIMyEntity-C/
1 change: 1 addition & 0 deletions KAIMyEntity-C
Submodule KAIMyEntity-C added at ef7d09
75 changes: 63 additions & 12 deletions blazerod/model/model-pmx/PmxLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,10 @@ class PmxLoader : ModelFileLoader {
shape = loadShapeType(buffer.get()),
shapeSize = loadVector3f(buffer).mul(MMD_SCALE),
shapePosition = loadVector3f(buffer).transformPosition(),
shapeRotation = loadVector3f(buffer).also { it.y *= -1 },
shapeRotation = loadVector3f(buffer).also {
it.y *= -1
it.z *= -1
},
mass = buffer.getFloat(),
moveAttenuation = buffer.getFloat(),
rotationDamping = buffer.getFloat(),
Expand Down Expand Up @@ -1060,7 +1063,10 @@ class PmxLoader : ModelFileLoader {
val rigidBodyIndexA = loadRigidBodyIndex(buffer)
val rigidBodyIndexB = loadRigidBodyIndex(buffer)
val position = loadVector3f(buffer).transformPosition()
val rotation = loadVector3f(buffer).also { it.y *= -1 }
val rotation = loadVector3f(buffer).also {
it.y *= -1
it.z *= -1
}

val positionMinimumOrig = loadVector3f(buffer).transformPosition()
val positionMaximumOrig = loadVector3f(buffer).transformPosition()
Expand All @@ -1069,10 +1075,18 @@ class PmxLoader : ModelFileLoader {

val rotationMinimumOrig = loadVector3f(buffer)
val rotationMaximumOrig = loadVector3f(buffer)
val rotationMinimum = Vector3f(-rotationMaximumOrig.x, rotationMinimumOrig.y, rotationMinimumOrig.z)
val rotationMaximum = Vector3f(-rotationMinimumOrig.x, rotationMaximumOrig.y, rotationMaximumOrig.z)
val rotationMinimum = Vector3f(
rotationMinimumOrig.x,
-rotationMaximumOrig.y,
-rotationMaximumOrig.z,
)
val rotationMaximum = Vector3f(
rotationMaximumOrig.x,
-rotationMinimumOrig.y,
-rotationMinimumOrig.z,
)
val positionSpring = loadVector3f(buffer)
val rotationSpring = loadVector3f(buffer).also { it.x *= -1 }
val rotationSpring = loadVector3f(buffer)

PmxJoint(
nameLocal = nameLocal,
Expand Down Expand Up @@ -1166,15 +1180,56 @@ class PmxLoader : ModelFileLoader {
)
)
}

boneToRigidBodyMap[index]?.forEach { index ->
add(
NodeComponent.RigidBodyComponent(
rigidBodyId = RigidBodyId(modelId, index),
rigidBody = rigidBodies[index].let { rigidBody ->
val enableNameBasedOverrides = false
val basePhysicsMode = when (rigidBody.physicsMode) {
PmxRigidBody.PhysicsMode.FOLLOW_BONE -> RigidBody.PhysicsMode.FOLLOW_BONE
PmxRigidBody.PhysicsMode.PHYSICS -> RigidBody.PhysicsMode.PHYSICS
PmxRigidBody.PhysicsMode.PHYSICS_PLUS_BONE -> RigidBody.PhysicsMode.PHYSICS_PLUS_BONE
}

val nameLocal = rigidBody.nameLocal
val adjustedPhysicsMode = if (enableNameBasedOverrides) {
when {
nameLocal.startsWith("Skirt_D_") ->
RigidBody.PhysicsMode.FOLLOW_BONE
nameLocal.startsWith("Ribbon_Braid_") -> basePhysicsMode
nameLocal.startsWith("Ribbon_") ||
nameLocal.startsWith("Pocket Watch_") ||
nameLocal.startsWith("Strap_") ->
RigidBody.PhysicsMode.FOLLOW_BONE
nameLocal.startsWith("Skirt_") &&
basePhysicsMode == RigidBody.PhysicsMode.PHYSICS ->
RigidBody.PhysicsMode.PHYSICS_PLUS_BONE
else -> basePhysicsMode
}
} else {
basePhysicsMode
}

val baseGroup = 1 shl rigidBody.groupId
val collisionMask = rigidBody.nonCollisionGroup and 0xFFFF
val defaultMask = collisionMask
println(
"PHYSDBG RB_GROUP " +
"idx=$index " +
"name=${rigidBody.nameLocal} " +
"groupId=${rigidBody.groupId} " +
"nonColl=${rigidBody.nonCollisionGroup} " +
"baseGroup=$baseGroup " +
"defaultMask=$defaultMask " +
"finalMask=$collisionMask",
)

RigidBody(
name = rigidBody.nameLocal.takeIf(String::isNotBlank),
collisionGroup = rigidBody.groupId,
collisionMask = rigidBody.nonCollisionGroup,
collisionGroup = baseGroup,
collisionMask = collisionMask,
shape = when (rigidBody.shape) {
PmxRigidBody.ShapeType.SPHERE -> RigidBody.ShapeType.SPHERE
PmxRigidBody.ShapeType.BOX -> RigidBody.ShapeType.BOX
Expand All @@ -1188,11 +1243,7 @@ class PmxLoader : ModelFileLoader {
rotationDamping = rigidBody.rotationDamping,
repulsion = rigidBody.repulsion,
frictionForce = rigidBody.frictionForce,
physicsMode = when (rigidBody.physicsMode) {
PmxRigidBody.PhysicsMode.FOLLOW_BONE -> RigidBody.PhysicsMode.FOLLOW_BONE
PmxRigidBody.PhysicsMode.PHYSICS -> RigidBody.PhysicsMode.PHYSICS
PmxRigidBody.PhysicsMode.PHYSICS_PLUS_BONE -> RigidBody.PhysicsMode.PHYSICS_PLUS_BONE
},
physicsMode = adjustedPhysicsMode,
)
},
)
Expand Down
8 changes: 8 additions & 0 deletions blazerod/render/api/animation/AnimationItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ interface AnimationItemInstance {
interface Factory {
fun of(animation: AnimationItem): AnimationItemInstance
}
}

interface MaskableAnimationItemInstance {
fun applyMasked(
instance: ModelInstance,
pendingValues: AnimationItemPendingValues,
allowedNodeIndices: BooleanArray,
)
}
2 changes: 2 additions & 0 deletions blazerod/render/api/resource/ModelInstance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import java.util.function.Consumer
interface ModelInstance : RefCount {
val scene: RenderScene

fun copyNodeWorldTransform(nodeIndex: Int, dest: Matrix4f)

fun clearTransform()
fun setTransformMatrix(nodeIndex: Int, transformId: TransformId, matrix: Matrix4f)
fun setTransformMatrix(nodeIndex: Int, transformId: TransformId, updater: Consumer<NodeTransform.Matrix>)
Expand Down
3 changes: 3 additions & 0 deletions blazerod/render/api/resource/RenderScene.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import top.fifthlight.blazerod.api.refcount.RefCount
import top.fifthlight.blazerod.model.Camera
import top.fifthlight.blazerod.model.HumanoidTag
import top.fifthlight.blazerod.model.NodeId
import top.fifthlight.blazerod.model.NodeTransformView

interface RenderScene : RefCount {
val rootNode: RenderNode
Expand All @@ -12,6 +13,8 @@ interface RenderScene : RefCount {
val expressionGroups: List<RenderExpressionGroup>
val cameras: List<Camera>

val renderTransform: NodeTransformView?

val ikTargetData: List<IkTargetData>
val nodeIdMap: Map<NodeId, RenderNode>
val nodeNameMap: Map<String, RenderNode>
Expand Down
19 changes: 19 additions & 0 deletions blazerod/render/main/animation/AnimationChannelItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import top.fifthlight.blazerod.runtime.resource.CameraTransformImpl
sealed class AnimationChannelItem<T : Any, D, P : Any>(
val channel: AnimationChannel<T, D>,
) {
open val targetNodeIndex: Int? = null

@Suppress("UNCHECKED_CAST")
fun applyUnsafe(instance: ModelInstanceImpl, pendingValue: Any) {
(this as AnimationChannelItem<Any, Any, Any>).apply(instance, pendingValue)
}

abstract fun createPendingValue(): P

// run on client thread
Expand All @@ -28,6 +35,8 @@ sealed class AnimationChannelItem<T : Any, D, P : Any>(
private val transformId: TransformId,
channel: AnimationChannel<Vector3f, Unit>,
) : AnimationChannelItem<Vector3f, Unit, Vector3f>(channel) {
override val targetNodeIndex: Int = index

init {
require(channel.type == AnimationChannel.Type.Translation) { "Unmatched animation channel: want translation, but got ${channel.type}" }
}
Expand All @@ -50,6 +59,8 @@ sealed class AnimationChannelItem<T : Any, D, P : Any>(
private val transformId: TransformId,
channel: AnimationChannel<Vector3f, Unit>,
) : AnimationChannelItem<Vector3f, Unit, Vector3f>(channel) {
override val targetNodeIndex: Int = index

init {
require(channel.type == AnimationChannel.Type.Scale) { "Unmatched animation channel: want scale, but got ${channel.type}" }
}
Expand All @@ -72,6 +83,8 @@ sealed class AnimationChannelItem<T : Any, D, P : Any>(
private val transformId: TransformId,
channel: AnimationChannel<Quaternionf, Unit>,
) : AnimationChannelItem<Quaternionf, Unit, Quaternionf>(channel) {
override val targetNodeIndex: Int = index

init {
require(channel.type == AnimationChannel.Type.Rotation) { "Unmatched animation channel: want rotation, but got ${channel.type}" }
}
Expand All @@ -95,6 +108,8 @@ sealed class AnimationChannelItem<T : Any, D, P : Any>(
private val transformId: TransformId,
channel: AnimationChannel<Vector3f, Unit>,
) : AnimationChannelItem<Vector3f, Unit, Vector3f>(channel) {
override val targetNodeIndex: Int = index

init {
require(channel.type == AnimationChannel.Type.BedrockTranslation) { "Unmatched animation channel: want translation, but got ${channel.type}" }
}
Expand All @@ -117,6 +132,8 @@ sealed class AnimationChannelItem<T : Any, D, P : Any>(
private val transformId: TransformId,
channel: AnimationChannel<Vector3f, Unit>,
) : AnimationChannelItem<Vector3f, Unit, Vector3f>(channel) {
override val targetNodeIndex: Int = index

init {
require(channel.type == AnimationChannel.Type.BedrockScale) { "Unmatched animation channel: want scale, but got ${channel.type}" }
}
Expand All @@ -139,6 +156,8 @@ sealed class AnimationChannelItem<T : Any, D, P : Any>(
private val transformId: TransformId,
channel: AnimationChannel<Quaternionf, Unit>,
) : AnimationChannelItem<Quaternionf, Unit, Quaternionf>(channel) {
override val targetNodeIndex: Int = index

init {
require(channel.type == AnimationChannel.Type.BedrockRotation) { "Unmatched animation channel: want rotation, but got ${channel.type}" }
}
Expand Down
41 changes: 37 additions & 4 deletions blazerod/render/main/animation/AnimationItemImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package top.fifthlight.blazerod.animation
import top.fifthlight.blazerod.api.animation.AnimationItem
import top.fifthlight.blazerod.api.animation.AnimationItemInstance
import top.fifthlight.blazerod.api.animation.AnimationItemPendingValues
import top.fifthlight.blazerod.api.animation.MaskableAnimationItemInstance
import top.fifthlight.blazerod.api.resource.ModelInstance
import top.fifthlight.blazerod.api.resource.RenderScene
import top.fifthlight.blazerod.model.animation.Animation
Expand Down Expand Up @@ -40,7 +41,7 @@ class AnimationItemPendingValuesImpl(animationItem: AnimationItemImpl) : Animati
}

@ActualImpl(AnimationItemInstance::class)
class AnimationItemInstanceImpl(val animationItem: AnimationItemImpl) : AnimationItemInstance {
class AnimationItemInstanceImpl(val animationItem: AnimationItemImpl) : AnimationItemInstance, MaskableAnimationItemInstance {
@ActualConstructor("of")
constructor(animationItem: AnimationItem) : this(animationItem as AnimationItemImpl)

Expand Down Expand Up @@ -76,10 +77,42 @@ class AnimationItemInstanceImpl(val animationItem: AnimationItemImpl) : Animatio
pendingValues.pendingValues[index].let { pendingValue ->
channel.applyUnsafe(instance, pendingValue)
}
if (!pendingValues.applied) {
pendingValues.applied = true
pendingStack.addLast(pendingValues)
}
if (!pendingValues.applied) {
pendingValues.applied = true
pendingStack.addLast(pendingValues)
}
}

override fun applyMasked(
instance: ModelInstance,
pendingValues: AnimationItemPendingValues,
allowedNodeIndices: BooleanArray,
) {
val instance = instance as ModelInstanceImpl
val pendingValues = pendingValues as AnimationItemPendingValuesImpl

animationItem.channels.forEachIndexed { index, channel ->
val targetNodeIndex = channel.targetNodeIndex
if (targetNodeIndex == null || targetNodeIndex !in allowedNodeIndices.indices || !allowedNodeIndices[targetNodeIndex]) {
return@forEachIndexed
}

pendingValues.pendingValues[index].let { pendingValue ->
channel.applyUnsafe(instance, pendingValue)
}
}
if (!pendingValues.applied) {
pendingValues.applied = true
pendingStack.addLast(pendingValues)
}
}

fun recyclePendingValues(pendingValues: AnimationItemPendingValues) {
val pendingValues = pendingValues as? AnimationItemPendingValuesImpl ?: return
if (!pendingValues.applied) {
pendingValues.applied = true
pendingStack.addLast(pendingValues)
}
}
}
4 changes: 4 additions & 0 deletions blazerod/render/main/physics/PhysicsLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ private PhysicsLibrary() {

public native static void stepPhysicsWorld(long physicsWorld, float deltaTime, int maxSubSteps, float fixedTimeStep);

public native static void resetRigidBody(long physicsWorld, int rigidBodyIndex,
float px, float py, float pz,
float qx, float qy, float qz, float qw);

public native static void destroyPhysicsWorld(long physicsWorld);

public static boolean isPhysicsAvailable() {
Expand Down
1 change: 1 addition & 0 deletions blazerod/render/main/physics/PhysicsScene.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package top.fifthlight.blazerod.physics

import org.joml.Vector3fc
import top.fifthlight.blazerod.model.RigidBody
import top.fifthlight.blazerod.model.util.MMD_SCALE
import top.fifthlight.blazerod.runtime.resource.RenderPhysicsJoint
import java.lang.ref.Reference
import java.nio.ByteBuffer
Expand Down
Loading