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

Ability to change z-index or z position to control stacking order #9

Open
shenghan97 opened this issue Apr 26, 2022 · 1 comment
Open

Comments

@shenghan97
Copy link

Hi!

Is it possible to change the layering order of different objects while using react three fiber? I change the z position of the object but once the useCircle hook takes into effect, the object gets snapped to z-0 again.

I tried arranging objects by changing the line order in jsx but it's not editable and not reliable - sometimes it produces artifacts.

Is there anything in use-p2 or p2.js like z-index in CSS where I can manually set the position on z-axis?

Thank you!

@isaac-mason
Copy link
Member

You can pass the body ref to a group, then change the relative position of the mesh in that group

e.g.

function Box() {
  const [ref] = useBox(() => ({ mass: 0, position: [0, -2] }))
  return (
    <group ref={ref}>
      <mesh position-z={1}>
        <boxGeometry />
      </mesh>
    </group>
  )
}

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

No branches or pull requests

2 participants