-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: display items in hand of entities #293
Conversation
also add missing left item elements to zombies
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
WalkthroughThis pull request updates the rendering and entity management logic. In the code, the scaling calculations and bone rotations are adjusted for different display contexts, and a new method for adding item models is introduced. The JSON files defining entity and armor models now have updated identifiers, including swapped bone names and revised item pivot values. New entities ("husk" and "zombie") are also added into the definitions while exports for these models have been removed from a separate module. Additionally, item identification is made more robust by using a fallback property in the item UV retrieval logic. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Entities
participant EntityMesh
participant Bone
Caller->>Entities: call addItemModel(entityMesh, hand, item)
Entities->>EntityMesh: traverse to remove existing item in specified hand
alt Item provided
Entities->>Bone: retrieve appropriate bone for hand
Entities->>Bone: attach retrieved item mesh
Entities->>Bone: apply rotations and scaling (block vs. non-block)
else No item provided
Entities->>EntityMesh: finish without adding an item
end
sequenceDiagram
participant Caller
participant getItemUv
participant Item
participant UVResolver
Caller->>getItemUv: call getItemUv(item)
getItemUv->>Item: check for item.itemId
alt item.itemId exists
getItemUv->>UVResolver: retrieve UV via itemId
else
getItemUv->>Item: check for item.blockId
alt item.blockId exists
getItemUv->>UVResolver: retrieve UV via blockId
else
getItemUv->>Item: use item.name as fallback
getItemUv->>UVResolver: retrieve UV via item.name
end
end
UVResolver-->>getItemUv: return UV coordinates
getItemUv-->>Caller: return result
Possibly related PRs
Suggested labels
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
renderer/viewer/lib/entities.ts (2)
508-514
: Avoid code duplication in scaling logic.The conditional scaling for
'ground'
and'thirdperson'
is duplicated in multiple sections. Consider extracting it into a helper function to follow DRY principles.
559-565
: Repeated scaling logic.This block replicates the same scale checks as lines 508-514. Consolidating these conditions into a shared method would streamline maintenance and readability.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
renderer/viewer/lib/entity/models/zombie.obj
is excluded by!**/*.obj
📒 Files selected for processing (5)
renderer/viewer/lib/entities.ts
(9 hunks)renderer/viewer/lib/entity/armorModels.json
(6 hunks)renderer/viewer/lib/entity/entities.json
(15 hunks)renderer/viewer/lib/entity/exportedModels.js
(0 hunks)src/index.ts
(1 hunks)
💤 Files with no reviewable changes (1)
- renderer/viewer/lib/entity/exportedModels.js
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build-and-deploy
🔇 Additional comments (19)
renderer/viewer/lib/entity/armorModels.json (6)
87-98
: Naming and pivot check for the left arm segment.Renaming
"rightarm"
to"leftarm"
matches the pivot shift from[ -5, 10, 0 ]
to[ 5, 10, 0 ]
, ensuring correct mirroring. No issues found.
100-112
: Naming and pivot check for the right arm segment.Renaming
"leftarm"
to"rightarm"
aligns properly with the pivot change. Looks consistent with the updated conventions.
136-147
: Naming the left leg segment.This block renames
"rightleg"
to"leftleg"
alongside its pivot. The structure is coherent and adheres to the swapped naming approach.
149-161
: Renaming the right leg segment.Renaming
"leftleg"
to"rightleg"
and reversing the pivot coordinates is consistent with the other swapped segments.
172-183
: Renaming the left leg segment in the feet section.This also reaffirms the naming swap for legs. No mismatch detected in pivot or UV usage.
185-197
: Renaming the right leg segment in the feet section.Renaming
"leftleg"
to"rightleg"
is properly reflected in the pivot. No further modifications needed.src/index.ts (1)
179-179
: Fallback to item.name for better item identification.The expression
item.itemId ?? item.blockId ?? item.name
enhances robustness by usingitem.name
if neitheritemId
norblockId
is present. Ensureitem.name
is always defined or handle the case where it may be missing.renderer/viewer/lib/entities.ts (2)
717-718
: Integrating held items for left and right hands.These calls to
addItemModel(...)
for each hand correctly delegate item rendering. No functional issues noted.
972-1009
: Implementation review of the new addItemModel method.
- The cleanup logic (
additionalCleanup
) correctly disposes textures, preventing memory leaks.- Rotations and scales for blocks vs. standard items are well-differentiated.
- Code is modular and easy to extend if new contexts or transformations are needed.
Overall, the method is well-structured and follows best practices.
renderer/viewer/lib/entity/entities.json (10)
44-45
: Bone name swapping corrects model orientation for items.The arm bones have been renamed, swapping "rightarm" and "leftarm" to correct the model orientation. This is an important change to ensure items will display correctly in each hand according to Minecraft's coordinate system.
Also applies to: 63-64
52-52
: Item pivot coordinates adjusted for proper item positioning.The pivot points for item bones have been significantly changed (from higher Y values to negative values with different offsets). These adjustments are essential for properly positioning held items in the entity's hands.
Also applies to: 70-70
72-73
: Bone name swapping ensures consistency with arm changes.The leg bones have also been renamed to maintain consistency with the arm bone naming convention changes. This ensures a coherent model structure and consistent application of transformations.
Also applies to: 74-77
772-773
: Item attachment points added for drowned entity.The drowned entity now has proper item bone definitions with correctly positioned pivot points. This enables the entity to hold items in both hands, which supports the PR objective of displaying items held by different entity types.
1655-2182
: New husk entity definition adds support for item display.A complete definition for the husk entity has been added with proper bone structure, animations, and item attachment points. This implementation is thorough and includes all necessary components for proper item display.
3717-3719
: Skeleton entity item pivot adjustment aligns with other entities.The skeleton entity's item pivot points have been adjusted to match the new standard positioning used across other entities. This consistency ensures items will be displayed correctly regardless of entity type.
Also applies to: 3732-3734
4542-4544
: Stray entity item pivot adjustment maintains consistency.The stray entity (a skeleton variant) has the same item pivot adjustments, maintaining consistency across all skeleton-type entities. This approach ensures that rendering behavior is predictable across similar entity types.
Also applies to: 4557-4559
5577-6104
: Comprehensive zombie entity implementation with proper item support.A complete zombie entity definition has been added with all necessary animations, controllers, and properly positioned item attachment points. The implementation is thorough and supports the display of items in both hands.
6174-6175
: Item attachment points for zombified piglin ensure consistent behavior.The zombified piglin entity has been updated with properly positioned item attachment points, ensuring consistent item display behavior across all zombie-type entities.
Also applies to: 6189-6190
3717-3719
: Verify item placement across all supported entities in-game.While the coordinate adjustments appear consistent and well-implemented across all entity types, it would be beneficial to verify the actual in-game appearance to ensure items are properly positioned in all animation states (walking, attacking, etc.).
Consider testing various item types (weapons, tools, blocks) with each supported entity to ensure proper positioning and orientation in all animation states.
Also applies to: 3732-3734, 4542-4544, 4557-4559, 5630-5649, 5645-5649, 6174-6175, 6189-6190
This is very cool, however since we support holding item display it makes so much sense to finish support for players, also will try to look into with a few days if you need help there. |
so bad didnt find time to finish it:( hope to revisit in future |
User description
This adds the base functionality of displaying items in the hands of different entities. Currently supported ones:
Right now players are not supported as they do not use the inbuilt model format and the used library does not seem to have a concept of holding items. :/
In order to support Zombies the model was used from prismarine-viewer (and adjusted to fix the items) and the .obj version removed (which had the arms in a non-default position anyways. The "zombie stance" and other entity movements need to be done via some form of animation controller)also add missing left item elements to zombies
PR Type
Enhancement, Bug fix
Description
Added functionality to display items in the hands of entities.
addItemModel
method for handling item meshes.Fixed left/right inversion issues for Armor Stands and other entities.
Replaced
.obj
models for Zombies with JSON-based models for better compatibility.Adjusted scaling and positioning for items in different contexts (e.g., ground, third-person).
Changes walkthrough 📝
entities.ts
Enhance entity item handling and fix inversions
renderer/viewer/lib/entities.ts
addItemModel
method to handle item meshes for entities.exportedModels.js
Remove outdated Zombie and Husk models
renderer/viewer/lib/entity/exportedModels.js
.obj
models for Zombies and Husks.entities.json
Add JSON models and improve animations
renderer/viewer/lib/entity/entities.json
zombie.obj
Remove outdated Zombie `.obj` model
renderer/viewer/lib/entity/models/zombie.obj
.obj
model for Zombies.index.ts
Improve item UV retrieval logic
src/index.ts
getItemUv
to handle missingitemId
orblockId
.armorModels.json
Fix arm and leg naming and pivots
renderer/viewer/lib/entity/armorModels.json
Summary by CodeRabbit
New Features
Bug Fixes
Refactor