Skip to content
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

Complexed entity for sheep #205

Open
wants to merge 7 commits into
base: next
Choose a base branch
from
Open

Conversation

Valery-a
Copy link

@Valery-a Valery-a commented Sep 15, 2024

Summary by CodeRabbit

  • New Features
    • Introduced support for a new sheep entity with enhanced visual adjustments including custom scaling, positioning, and rotation.
    • Expanded available 3D assets by adding a new sheep coat model for improved visual variety.

Copy link

codesandbox bot commented Sep 15, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@zardoy
Copy link
Owner

zardoy commented Sep 28, 2024

/update

Copy link

coderabbitai bot commented Feb 23, 2025

Walkthrough

The changes add support for a new "sheep" entity in the EntityMesh class. New methods handle material application, scaling, positioning, and head rotation specifically for sheep models. In the constructor, a check now directs the handling of sheep entities via a new handleSheep method, bypassing the default logic. Additionally, the sheep coat model is now exported from exportedModels.js, updating the available imports.

Changes

File Summary of Changes
renderer/viewer/lib/entity/EntityMesh.ts Added new sheep entity support including methods: handleSheep, applyMaterialToMesh, applyEntityScaleAndPosition, applyHeadRotation, and updated the constructor to conditionally handle sheep entities over other types.
renderer/viewer/lib/entity/.../exportedModels.js Added a new export statement for the sheepCoat model to allow its import from this module.

Sequence Diagram(s)

sequenceDiagram
    participant EM as EntityMesh
    participant Loader as OBJLoader
    participant MeshProc as Mesh Processing

    Note over EM: Sheep entity workflow
    EM ->> EM: Check entity type ("sheep")
    EM ->> EM: Call handleSheep(objLoader, "sheep", overrides)
    EM ->> MeshProc: applyMaterialToMesh(mesh, material)
    EM ->> MeshProc: applyEntityScaleAndPosition(mesh1, mesh2, "sheep")
    EM ->> MeshProc: applyHeadRotation(mesh, rotation)
    MeshProc -->> EM: Configured sheep mesh
Loading

Poem

I hopped through the code with glee, 🐇
Where sheep now roam wild and free,
Their coats and scales, a digital art,
Each function plays its clever part,
In bytes and hops, we sing with heart!
Cheers to a code field of new starts!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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/entity/EntityMesh.ts (2)

439-507: Extract common rotation logic and constants.

Consider the following improvements:

  1. There's code duplication in head rotation logic between applyHeadRotation and applyMaterialAndTransform.
  2. The magic number 180 in rotation calculations should be extracted as a constant.
+const DEGREES_TO_RADIANS = Math.PI / 180;
+
+private applyHeadRotationToMesh(mesh: THREE.Object3D, rotation: { x?: number; y?: number; z?: number }): void {
+  mesh.rotation.x -= (rotation.x ?? 0) * DEGREES_TO_RADIANS;
+  mesh.rotation.y -= (rotation.y ?? 0) * DEGREES_TO_RADIANS;
+  mesh.rotation.z -= (rotation.z ?? 0) * DEGREES_TO_RADIANS;
+}
+
 private applyHeadRotation(mesh: THREE.Object3D, rotation: { x?: number; y?: number; z?: number }): void {
-  mesh.rotation.x -= (rotation.x ?? 0) * Math.PI / 180;
-  mesh.rotation.y -= (rotation.y ?? 0) * Math.PI / 180;
-  mesh.rotation.z -= (rotation.z ?? 0) * Math.PI / 180;
+  this.applyHeadRotationToMesh(mesh, rotation);
 }

Update applyMaterialAndTransform to use the common method:

 if (child.name === 'Head' && overrides.rotation?.head) {
-  child.rotation.x -= (overrides.rotation.head.x ?? 0) * Math.PI / 180;
-  child.rotation.y -= (overrides.rotation.head.y ?? 0) * Math.PI / 180;
-  child.rotation.z -= (overrides.rotation.head.z ?? 0) * Math.PI / 180;
+  this.applyHeadRotationToMesh(child, overrides.rotation.head);
 }

467-487: Make sheep colors configurable through overrides.

The colors for sheep and coat materials are hardcoded. Consider making them configurable through the overrides parameter to support different sheep colors.

 interface EntityOverrides {
   textures?: Record<string, string>
   rotation?: Record<string, { x?: number; y?: number; z?: number }>
+  colors?: {
+    sheep?: number
+    sheepCoat?: number
+  }
 }

 private handleSheep(objLoader: OBJLoader, originalType: string, overrides: EntityOverrides): THREE.Object3D {
   const sheepObj = objLoader.parse(sheep)
-  const sheepMaterial = new THREE.MeshLambertMaterial({ color: 0xff_ff_ff })
+  const sheepMaterial = new THREE.MeshLambertMaterial({ color: overrides.colors?.sheep ?? 0xff_ff_ff })
   this.applyMaterialToMesh(sheepObj, sheepMaterial)

   const sheepCoatObj = objLoader.parse(sheepCoat)
-  const sheepCoatMaterial = new THREE.MeshLambertMaterial({ color: 0xff_d7_00 })
+  const sheepCoatMaterial = new THREE.MeshLambertMaterial({ color: overrides.colors?.sheepCoat ?? 0xff_d7_00 })
   this.applyMaterialToMesh(sheepCoatObj, sheepCoatMaterial)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 78d923d and 9bb4329.

⛔ Files ignored due to path filters (2)
  • renderer/viewer/lib/entity/models/sheep.obj is excluded by !**/*.obj
  • renderer/viewer/lib/entity/models/sheepCoat.obj is excluded by !**/*.obj
📒 Files selected for processing (2)
  • renderer/viewer/lib/entity/EntityMesh.ts (5 hunks)
  • renderer/viewer/lib/entity/exportedModels.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-and-deploy
🔇 Additional comments (4)
renderer/viewer/lib/entity/exportedModels.js (1)

26-26: LGTM!

The new sheepCoat export follows the established pattern and maintains alphabetical order.

renderer/viewer/lib/entity/EntityMesh.ts (3)

13-13: LGTM!

The new imports for sheep models are correctly added.


410-412: LGTM!

The scale values for arrow and sheep entities are appropriately set.


526-530: LGTM!

The sheep-specific handling in the constructor follows the existing pattern and appropriately returns early after handling.

@zardoy
Copy link
Owner

zardoy commented Feb 23, 2025

/deploy

Copy link

Deployed to Vercel Preview: https://prismarine-em82ljayk-zaro.vercel.app
Playground
Storybook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants