Skip to content

Add Gizmo component #191

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add Gizmo component #191

wants to merge 2 commits into from

Conversation

marklundin
Copy link
Member

@marklundin marklundin commented Jul 4, 2025

This PR adds a new controlled <Gizmo/> component for modifying an <Entity/> components position, rotation and scale

Usage:

import { Entity } from "@playcanvas/react"
import { Gizmo } from "@playcanvas/react/components"

export function Main() {
  // The selected entity
  const [selected, setSelected] = useState(null)

   // The transform
  const [transform, setTransform] = useState({
    position: [0, 0, 0],
    rotation: [0, 0, 0],
    scale: [1, 1, 1]
  }) 

  return (<>
    <Entity {...transform} onClick={e => seSelected(e)}>
      <Render type="sphere" />
    <Entity/>
    { selected && <Gizmo nodes={[selected]} onCommit={t => setTransform(t)}/> } // Only render the gizmo when something is selected
  </>)
}

TODO:

  • Docs
  • Tests

- Introduced a new Gizmo component that allows users to manipulate nodes in the scene using rotate, scale, and translate modes.
- The component utilizes PlayCanvas's Gizmo classes and integrates with the application context for camera handling.
- Added props for camera, nodes, mode, and a commit callback to handle updates after transformations.
- Included detailed documentation and example usage for the new component.
- Introduced a new changeset file to document the addition of the Gizmo component.
- Updated the components index to export the new Gizmo component alongside existing components.
@marklundin marklundin self-assigned this Jul 4, 2025
@marklundin marklundin added enhancement New feature or request React labels Jul 4, 2025
Copy link

changeset-bot bot commented Jul 4, 2025

🦋 Changeset detected

Latest commit: 679d881

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@playcanvas/react Minor
@playcanvas/blocks Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented Jul 4, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@playcanvas/blocks@191
npm i https://pkg.pr.new/@playcanvas/react@191

commit: 679d881

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request React
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant