Skip to content

feat(graphics-3d): primitives, camera, lights and the draw3D sync system - #45

Open
Tchips46 wants to merge 2 commits into
mainfrom
feat/graphics-3d-packages
Open

Tchips46 wants to merge 2 commits into
mainfrom
feat/graphics-3d-packages

Conversation

@Tchips46

Copy link
Copy Markdown
Member

What does this PR do?

Closes #26. Adds the @nanoforge/graphics-3d package: a beginner gets a lit, visible 3D object by adding components and the provided draw3D system, without writing any Three.js.

  • Components: Box3D, Sphere3D, Plane3D (one color each, @preset color), Camera3D, Light3D (ambient / directional / point), and Object3DComponent, which shows any Three.js object, e.g. an InstancedMesh.
  • draw3D: creates each component's Three.js object in ctx.graphics.scene, keeps it up to date, and removes it, disposing its geometries, materials and textures, when the component or the entity goes. Applies Position3D / Rotation3D / Scale3D from basics-3d to every object, Object3DComponent included.
  • Defaults: a scene without a light gets a default one, removed once a light is added. With no active Camera3D, the library's own camera is shown.
  • Shared mapping: toObject3D (object-3d.ts) turns a component's params into its Three.js object. It depends only on Three.js and also takes plain { name: "Box3D", … } objects, so the editor's 3D Scene screen can reuse it.
  • Dependencies: @nanoforge-dev/graphics-3d and three added to the core catalog.

2D and 3D build apart

graphics-2d and graphics-3d both type ctx.graphics, differently, so one TS program can't load both (TS2717). A game never does, but this repo compiled every package together. Now:

  • tsconfig.json builds everything except graphics-3d, which builds in tsconfig.3d.json; build runs both.
  • Specs: Vitest projects 2d and 3d. 3D specs live in test/3d/ and import test/ecs.ts (the ECS helpers, no engine typings) instead of test/helpers.ts, which loads graphics-2d's typings.
  • draw3D uses ctx.graphics directly, like draw2D, with no cast.
  • New pnpm run typecheck (tsc on both spec configs, packages included, without skipLibCheck), run by lint. Vitest's typecheck only checks *.spec-d.ts files and there are none, so until now no type error reached CI. A package that imports both graphics libs now fails lint.
  • AGENTS.md and the new-ecs-package skill say where a new 3D package and its specs go.

@Tchips46 Tchips46 self-assigned this Nov 26, 2026
@Tchips46
Tchips46 requested a review from Exeloo November 26, 2026 10:37
@Exeloo
Exeloo added this pull request to stack #46 November 26, 2026 22:43
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

Successfully merging this pull request may close these issues.

graphics-3d package: primitives, camera, lights and the 3D sync system

1 participant