Skip to content

Improve Gizmo API docs #7620

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

Merged
merged 1 commit into from
Apr 27, 2025
Merged
Show file tree
Hide file tree
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
36 changes: 33 additions & 3 deletions src/extras/gizmo/rotate-gizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,36 @@ const FACING_THRESHOLD = 0.9;
const GUIDE_ANGLE_COLOR = new Color(0, 0, 0, 0.3);

/**
* Rotation gizmo.
* The RotateGizmo provides interactive 3D manipulation handles for rotating/reorienting
* {@link Entity}s in a {@link Scene}. It creates a visual widget with a draggable ring for each
* axis of rotation, plus a fourth ring for rotation in the camera's view plane, allowing precise
* control over object orientation through direct manipulation. The gizmo's visual appearance can
* be customized away from the defaults as required.
*
* Note that the gizmo can be driven by both mouse+keyboard and touch input.
*
* ```javascript
* // Create a layer for rendering all gizmos
* const gizmoLayer = pc.Gizmo.createLayer(app);
*
* // Create a rotate gizmo
* const gizmo = new pc.RotateGizmo(cameraComponent, gizmoLayer);
*
* // Create an entity to attach the gizmo to
* const entity = new pc.Entity();
* entity.addComponent('render', {
* type: 'box'
* });
* app.root.addChild(entity);
*
* // Attach the gizmo to the entity
* gizmo.attach([entity]);
* ```
*
* Relevant Engine API examples:
*
* - [Rotate Gizmo](https://playcanvas.github.io/#/gizmos/transform-rotate)
* - [Editor](https://playcanvas.github.io/#/misc/editor)
*
* @category Gizmo
*/
Expand Down Expand Up @@ -142,10 +171,11 @@ class RotateGizmo extends TransformGizmo {
orbitRotation = false;

/**
* Creates a new RotateGizmo object.
* Creates a new RotateGizmo object. Use {@link Gizmo.createLayer} to create the layer
* required to display the gizmo.
*
* @param {CameraComponent} camera - The camera component.
* @param {Layer} layer - The render layer.
* @param {Layer} layer - The layer responsible for rendering the gizmo.
* @example
* const gizmo = new pc.RotateGizmo(camera, layer);
*/
Expand Down
36 changes: 33 additions & 3 deletions src/extras/gizmo/scale-gizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,36 @@ const tmpQ1 = new Quat();
const GLANCE_EPSILON = 0.98;

/**
* Scaling gizmo.
* The ScaleGizmo provides interactive 3D manipulation handles for scaling/resizing
* {@link Entity}s in a {@link Scene}. It creates a visual widget with box-tipped lines along the
* X, Y and Z axes, planes at their intersections, and a center box, allowing precise control over
* object scaling through direct manipulation. The gizmo's visual appearance can be customized
* away from the defaults as required.
*
* Note that the gizmo can be driven by both mouse+keyboard and touch input.
*
* ```javascript
* // Create a layer for rendering all gizmos
* const gizmoLayer = pc.Gizmo.createLayer(app);
*
* // Create a scale gizmo
* const gizmo = new pc.ScaleGizmo(cameraComponent, gizmoLayer);
*
* // Create an entity to attach the gizmo to
* const entity = new pc.Entity();
* entity.addComponent('render', {
* type: 'box'
* });
* app.root.addChild(entity);
*
* // Attach the gizmo to the entity
* gizmo.attach([entity]);
* ```
*
* Relevant Engine API examples:
*
* - [Scale Gizmo](https://playcanvas.github.io/#/gizmos/transform-scale)
* - [Editor](https://playcanvas.github.io/#/misc/editor)
*
* @category Gizmo
*/
Expand Down Expand Up @@ -124,10 +153,11 @@ class ScaleGizmo extends TransformGizmo {
lowerBoundScale = new Vec3(-Infinity, -Infinity, -Infinity);

/**
* Creates a new ScaleGizmo object.
* Creates a new ScaleGizmo object. Use {@link Gizmo.createLayer} to create the layer
* required to display the gizmo.
*
* @param {CameraComponent} camera - The camera component.
* @param {Layer} layer - The render layer.
* @param {Layer} layer - The layer responsible for rendering the gizmo.
* @example
* const gizmo = new pc.ScaleGizmo(camera, layer);
*/
Expand Down
36 changes: 33 additions & 3 deletions src/extras/gizmo/translate-gizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,36 @@ const tmpQ1 = new Quat();
const GLANCE_EPSILON = 0.98;

/**
* Translation gizmo.
* The TranslateGizmo provides interactive 3D manipulation handles for translating/moving
* {@link Entity}s in a {@link Scene}. It creates a visual widget with arrows along the X, Y
* and Z axes, planes at their intersections, and a center sphere, allowing precise control over
* object positioning through direct manipulation. The gizmo's visual appearance can be customized
* away from the defaults as required.
*
* Note that the gizmo can be driven by both mouse+keyboard and touch input.
*
* ```javascript
* // Create a layer for rendering all gizmos
* const gizmoLayer = pc.Gizmo.createLayer(app);
*
* // Create a translate gizmo
* const gizmo = new pc.TranslateGizmo(cameraComponent, gizmoLayer);
*
* // Create an entity to attach the gizmo to
* const entity = new pc.Entity();
* entity.addComponent('render', {
* type: 'box'
* });
* app.root.addChild(entity);
*
* // Attach the gizmo to the entity
* gizmo.attach([entity]);
* ```
*
* Relevant Engine API examples:
*
* - [Translate Gizmo](https://playcanvas.github.io/#/gizmos/transform-translate)
* - [Editor](https://playcanvas.github.io/#/misc/editor)
*
* @category Gizmo
*/
Expand Down Expand Up @@ -121,10 +150,11 @@ class TranslateGizmo extends TransformGizmo {
flipShapes = true;

/**
* Creates a new TranslateGizmo object.
* Creates a new TranslateGizmo object. Use {@link Gizmo.createLayer} to create the layer
* required to display the gizmo.
*
* @param {CameraComponent} camera - The camera component.
* @param {Layer} layer - The render layer.
* @param {Layer} layer - The layer responsible for rendering the gizmo.
* @example
* const gizmo = new pc.TranslateGizmo(camera, layer);
*/
Expand Down