Skip to content

Conversation

@Byongho96
Copy link
Contributor

@Byongho96 Byongho96 commented Nov 25, 2024

This PR addresses issues with the Audio class's clone and copy methods.

Description

The Object3D's clone method, inherited by Audio, creates a new instance without passing additional parameters. This causes errors when cloning an Audio object, as the listener is mandatory for its creation.

Proposed Solution
The clone method has been overridden to align with the expected behavior: reusing the existing listener when creating a new Audio instance.

The copy method has been overridden to correctly handle properties specific to the Audio class, ensuring all relevant data is properly transferred.

Exception Handling for sourceType

  • 'buffer':
    The play method regenerates the source internally using context.createBufferSource.
  • 'audioNode', 'mediaNode', or 'mediaStreamNode':
    These source types are single-use and cannot be reused across multiple connections. A warning is logged, and these sources are excluded from the copy process to prevent misuse.

Demo of the feature with buffer souce
before

bandicam.2024-11-25.16-47-06-294.mp4

after

bandicam.2024-11-25.14-39-19-931.mp4

@github-actions
Copy link

github-actions bot commented Nov 25, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 339.14
78.99
339.14
78.99
+0 B
+0 B
WebGPU 483.15
134.15
483.15
134.15
+0 B
+0 B
WebGPU Nodes 482.62
134.06
482.62
134.06
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 464.62
111.98
464.62
111.98
+0 B
+0 B
WebGPU 552.28
149.51
552.28
149.51
+0 B
+0 B
WebGPU Nodes 508.16
139.22
508.16
139.22
+0 B
+0 B

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 25, 2024

I have always hesitated with adding clone() and copy() to audio classes since you are never able to copy the exact same state of the audio to another object.

Granted, the derived methods from Object3D are not useful right now so it seems the proposed versions of the PR are an improvement.

@mrdoob
Copy link
Owner

mrdoob commented Nov 26, 2024

Granted, the derived methods from Object3D are not useful right now so it seems the proposed versions of the PR are an improvement.

+1

@Mugen87 Mugen87 added this to the r171 milestone Nov 26, 2024
@Mugen87 Mugen87 merged commit de7c7c8 into mrdoob:dev Nov 26, 2024
12 checks passed
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.

3 participants