Skip to content

fix: render sprite incorrectly when config reusable caused by diff algorithm #45

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

Merged
merged 1 commit into from
Dec 18, 2023

Conversation

RGCHN
Copy link
Contributor

@RGCHN RGCHN commented Dec 17, 2023

Summary by CodeRabbit

  • Bug Fixes

    • Improved the handling of element visibility to ensure consistent updates to the main data array.
  • Refactor

    • Streamlined initialization process by using a direct URL for loading assets.
    • Removed unnecessary variable assignments to enhance code clarity and performance.

Copy link
Contributor

coderabbitai bot commented Dec 17, 2023

Walkthrough

The codebase underwent a refinement where the handling of sprite visibility was improved. A redundant block of code related to sprite size was also cleaned up. In the web demo, a simplification took place with the assignment of a hardcoded URL to a variable and the removal of a now-unnecessary variable assignment, streamlining the initialization process.

Changes

File Path Change Summary
.../sprite/sprite-mesh.ts Improved visibility check for selfData and removed unused code related to selfData.startSize.
.../demo/src/single.ts Changed json variable to use hardcoded URL and removed comp variable assignment.

🐇💻
To code we hop, with care and glee,
Refining lines, for all to see.
Bugs flee the scene, with every change,
In our code garden, ever so strange. 🌿🌟

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 4

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 86e0bce and fe87365.
Files selected for processing (2)
  • packages/effects-core/src/plugins/sprite/sprite-mesh.ts (1 hunks)
  • web-packages/demo/src/single.ts (1 hunks)
Additional comments: 5
packages/effects-core/src/plugins/sprite/sprite-mesh.ts (3)
  • 202-210: The early return when selfData is not visible ensures that invisible sprites do not process further, which is good for performance. However, ensure that when selfData becomes visible again, all necessary data is correctly initialized, as the early return might skip some initialization steps that are only executed when selfData is visible.

  • 200-200: The assignment of uColor now defaults to the values in mainDataArray if selfData.color is not provided. Verify that this change is intentional and that there are no cases where selfData.color being undefined should not default to the previous color in mainDataArray.

  • 194-213: The else block on lines 204-209 sets mainDataArray[uSizeStart + 2] to -1 when selfData is not visible and init is false. This seems to be a way to indicate that the sprite is not to be rendered. Confirm that setting this specific index to -1 is the correct way to handle this case and that it does not interfere with other parts of the rendering logic.

web-packages/demo/src/single.ts (2)
  • 6-6: The json variable is now assigned a hardcoded URL. Confirm that this is intentional and not a placeholder for testing purposes.

  • 9-15: The previous logic for loading a scene with player.loadScene(json) has been removed. Verify that the scene loading is handled elsewhere or if this logic is no longer required.

Comment on lines 9 to 15
(async () => {
try {
const player = createPlayer();

const comp = await player.loadScene(json);
} catch (e) {
console.error('biz', e);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The try block within the async function is empty. This could be an oversight. Either implement the intended logic or remove the async function if it's not needed.


The createPlayer function is defined but not used within the async function. Ensure that it is called appropriately or removed if it's no longer necessary.

Comment on lines 194 to 199
const uSizeStart = start + 4;
const uQuatStart = start + 8;
const uColorStart = start + 12;

if (!selfData.visible && !init) {
mainDataArray[uSizeStart + 2] = -1;

return;
}

const uColor = selfData.color || [mainDataArray[uColorStart], mainDataArray[uColorStart + 1], mainDataArray[uColorStart + 2], mainDataArray[uColorStart + 3]];

// if (selfData.startSize) {
// selfData.transform.scaleBy(1 / selfData.startSize[0], 1 / selfData.startSize[1], 1);
// }

const tempPos = new Vector3();
const tempQuat = new Quaternion();
const tempScale = new Vector3();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variables tempPos, tempQuat, and tempScale are created but only used within the if (selfData.visible) block. Consider moving their declarations inside the block to limit their scope and improve readability.

Comment on lines +200 to +210
const uColor = selfData.color || [mainDataArray[uColorStart], mainDataArray[uColorStart + 1], mainDataArray[uColorStart + 2], mainDataArray[uColorStart + 3]];

selfData.transform.assignWorldTRS(tempPos, tempQuat, tempScale);
if (selfData.visible) {
selfData.transform.assignWorldTRS(tempPos, tempQuat, tempScale);
} else {
if (!init) {
mainDataArray[uSizeStart + 2] = -1;

return;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a potential issue with the logic on lines 202-210. If selfData.visible is false and init is true, the function will continue executing without setting tempPos, tempQuat, and tempScale. This could lead to using uninitialized variables in the subsequent code. Ensure that this case is handled correctly and that there is no possibility of using uninitialized data.

@yiiqii yiiqii merged commit e493738 into dev Dec 18, 2023
@yiiqii yiiqii deleted the fix/diff branch December 18, 2023 01:46
@RGCHN RGCHN restored the fix/diff branch December 18, 2023 08:07
@yiiqii yiiqii deleted the fix/diff branch December 21, 2023 07:06
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