Skip to content

Conversation

@willeastcott
Copy link
Contributor

@willeastcott willeastcott commented Jan 9, 2026

Fixes #1457

This PR bundles the PlayCanvas engine directly into editor.js using ES module imports instead of relying on a globally injected pc namespace. This improves tree-shaking potential (although we will probably need to retain the whole engine to be bundled for plugin writers) and aligns the editor with modern module practices.

One very nice benefit is that we now get full Intellisense in VS Code for the Engine API.

Changes

Build Configuration

  • Modified rollup.config.mjs to bundle playcanvas into editor.js (removed from externals)
  • launch.js continues to use an externally injected engine

Global Engine Exposure

  • Added src/editor/pc-global.ts to expose the engine API as window.pc for editor extensions/plugins
  • Imported early in index.ts and blank.ts entry points

ES Module Migration

  • Converted ~40 files from global pc.* access to explicit ES module imports from playcanvas
  • Files updated include viewport, gizmos, camera controls, asset handling, inspectors, and more

Constants Cleanup

  • Removed duplicated engine constants from src/core/constants.ts
  • Re-exported LAYERID_*, GAMMA_*, CURVE_*, and ANIM_* constants from playcanvas

Deprecated API Updates

  • SHADOW_VSM8SHADOW_VSM_16F
  • SHADOW_VSM32SHADOW_VSM_32F
  • SHADOW_PCF1SHADOW_PCF1_32F
  • SHADOW_PCF3SHADOW_PCF3_32F
  • SHADOW_PCF5SHADOW_PCF5_32F

Bug Fixes

  • Removed pc.app = app assignment (ES module namespaces are immutable; engine sets this internally)
  • Fixed validateEnginePath to use in operator instead of hasOwnProperty (ES module namespace objects have null prototype)

Notes

  • UMD format retained for editor.js - ESM migration can follow in a subsequent PR

  • The engine is automatically set via AppBase constructor, so manual pc.app assignment was redundant

  • I confirm I have read the contributing guidelines

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR modernizes the editor by bundling the PlayCanvas engine directly into editor.js using ES module imports, removing the dependency on a globally injected pc namespace. This improves tree-shaking potential and aligns the codebase with modern module practices while maintaining backward compatibility for plugins through global exposure.

Key Changes:

  • Bundle playcanvas into editor.js while keeping it external for launch.js
  • Add ES module imports across ~40 files replacing global pc.* access
  • Update deprecated shadow constants to their modern equivalents

Reviewed changes

Copilot reviewed 70 out of 71 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/editor/pc-global.ts New file exposing engine API globally for plugins
rollup.config.mjs Configure playcanvas as external for launch.js only
types.d.ts Update comment about pc loading
src/core/constants.ts Re-export engine constants, remove duplicates
src/common/utils.ts Fix validateEnginePath to use in operator
src/editor/viewport/*.ts Convert to ES module imports
src/editor/viewport/gizmo/*.ts Convert to ES module imports
src/editor/viewport/camera/*.ts Convert to ES module imports
src/editor/inspector/components/*.ts Update deprecated shadow constants
src/editor/inspector/assets/*.ts Replace pc.app with editor.call
src/editor/templates/*.ts Import guid from playcanvas
src/editor/entities/*.ts Import engine classes
src/editor/assets/*.ts Import engine classes
src/common/*.ts Import engine classes
src/editor/index.ts Import pc-global early
src/editor/blank.ts Import pc-global early

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@willeastcott willeastcott changed the title Bundle engine Bundle PlayCanvas Engine into Editor Jan 9, 2026
Comment on lines +1 to +4
import * as pc from 'playcanvas';

// Expose engine API globally for plugins/extensions
(window as any).pc = pc;
Copy link
Contributor

Choose a reason for hiding this comment

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

This typing should explicitly extend the window interface and not cast as any

Comment on lines +23 to 24
// pc (bundled in editor, injected in HTML for launch page)
declare var pc: typeof import('playcanvas');
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be removed and scoped to just the launcher

Comment on lines +480 to +482
let obj: any = pc;
for (let i = 0; i < parts.length; i++) {
if (!obj.hasOwnProperty(parts[i]) && obj[parts[i]] === undefined) {
if (!(parts[i] in obj) && obj[parts[i]] === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should try not casting to any - use exact typing since we have it available

Comment on lines +4 to +35
export {
// Layer IDs
LAYERID_WORLD,
LAYERID_DEPTH,
LAYERID_SKYBOX,
LAYERID_IMMEDIATE,
LAYERID_UI,
// Gamma correction modes
GAMMA_NONE,
GAMMA_SRGB,
// Curve types
CURVE_LINEAR,
CURVE_SMOOTHSTEP,
CURVE_SPLINE,
CURVE_STEP,
// Anim constants
ANIM_INTERRUPTION_NONE,
ANIM_INTERRUPTION_PREV,
ANIM_INTERRUPTION_NEXT,
ANIM_INTERRUPTION_PREV_NEXT,
ANIM_INTERRUPTION_NEXT_PREV,
ANIM_GREATER_THAN,
ANIM_LESS_THAN,
ANIM_GREATER_THAN_EQUAL_TO,
ANIM_LESS_THAN_EQUAL_TO,
ANIM_EQUAL_TO,
ANIM_NOT_EQUAL_TO,
ANIM_PARAMETER_INTEGER,
ANIM_PARAMETER_FLOAT,
ANIM_PARAMETER_BOOLEAN,
ANIM_PARAMETER_TRIGGER
} from 'playcanvas';
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to rexport - just use the values directly. Any backwards compatible constants should be explicitly defined in this file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor interface engine bundling

3 participants