Skip to content

Update XR library snippets for the May 19 release#918

Draft
devbridie wants to merge 11 commits into
mainfrom
jxr-io
Draft

Update XR library snippets for the May 19 release#918
devbridie wants to merge 11 commits into
mainfrom
jxr-io

Conversation

@devbridie
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the Android XR samples to align with recent API changes, including renaming 'DepthMap' to 'Depth' and 'ExrImage' to 'ImageBasedLightingAsset', and transitioning to 'SPATIAL' tracking modes. It also introduces a comprehensive set of Glimmer component samples and replaces the '.movable()' modifier with '.transformingMovable()'. Feedback identifies several issues in the 'SpatialGltfModel' sample, such as a potential null pointer exception, redundant imports, and conflicting 'LaunchedEffect' blocks that overwrite material overrides. Additionally, the reviewer noted a performance regression where material caching was removed and a duplicated documentation tag in the focus samples.

Comment on lines +71 to +72
node?.localPose =
Pose(node.localPose.translation, rotation)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Accessing node.localPose directly is unsafe because node is nullable (returned by find). This will cause a NullPointerException if the node is not found. Use a null-safe block to perform the update.

        node?.let {
            it.localPose = Pose(it.localPose.translation, rotation)
        }

Comment on lines +22 to +25
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

These imports are redundant as they are already present in the file (lines 27-30). Please remove the duplicates to keep the import section clean.

// Create and apply the custom material once the session is ready and the target node is available.
LaunchedEffect(node) {
val material = pbrMaterial ?: KhronosPbrMaterial.create(
val material = KhronosPbrMaterial.create(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The material is being re-created every time this LaunchedEffect runs, bypassing the pbrMaterial cache defined at line 78. This is less efficient than the previous implementation. Consider restoring the caching logic.

Suggested change
val material = KhronosPbrMaterial.create(
val material = pbrMaterial ?: KhronosPbrMaterial.create(

}

// [START androidxr_compose_SpatialGltfModelTexture]
LaunchedEffect(node) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This LaunchedEffect conflicts with the one starting at line 81. Both effects use node as a key and call setMaterialOverride. Since they run concurrently, the second one will overwrite the first, making the base color factor set in the first block ineffective. Consider merging these snippets or clarifying their usage.


// [START xr_glimmer_focus_activity]

// [START xr_glimmer_focus_activity]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The snippet tag [START xr_glimmer_focus_activity] is duplicated (see line 32). Please remove the redundant tag to ensure correct documentation generation.

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