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

Cleanup code in css3d_molecules example #25587

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/css3d_molecules.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,7 @@

//

bond = document.createElement( 'div' );
bond.className = 'bond';
bond.style.height = bondLength + 'px';

const joint = new THREE.Object3D( bond );
const joint = new THREE.Object3D();
Copy link
Collaborator

Choose a reason for hiding this comment

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

As far as I can tell, passing an HTML element in an Object3D constructor doesn't do anything.

Good catch! However, bond is later used in the code to create another instance of CSS3DObject. And it's not right that multiple objects share the same DOM element. So please restore the bond creation and just remove the parameter from the ctor call of Object3D.

Copy link
Contributor Author

@Methuselah96 Methuselah96 Mar 1, 2023

Choose a reason for hiding this comment

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

🤦 Indeed. I moved the creation of the new bond element closer to its usage if that's okay.

joint.position.copy( start );
joint.position.lerp( end, 0.5 );

Expand All @@ -384,6 +380,10 @@
joint.matrixAutoUpdate = false;
joint.updateMatrix();

bond = document.createElement( 'div' );
bond.className = 'bond';
bond.style.height = bondLength + 'px';

object = new CSS3DObject( bond );
object.rotation.y = Math.PI / 2;

Expand Down