Add AI-driven 3D scene editing via agent tools and chat panel#3913
Conversation
georgi
left a comment
There was a problem hiding this comment.
Code quality is excellent — the tool bridge pattern, tests, and Anthropic provider changes all look solid. However, this has a non-trivial merge conflict in packages/websocket/src/unified-websocket-runner.ts:
Main was refactored to use isProviderMessageEvent with a different control flow for handling tool calls and streaming (the old onToolCall callback / Phase 1+2 pattern was replaced). The image-content routing logic (extractToolResultImageContent, image-aware tool result handling) needs to be adapted to work with the new architecture.
The conflict can't be auto-resolved — it requires understanding where in the new isProviderMessageEvent flow to insert the image content extraction and routing. The anthropic-provider.ts changes merged cleanly.
To resolve: rebase onto main and port the image-content features to the new streaming pattern in unified-websocket-runner.ts. The extractToolResultImageContent method itself is still valid, just needs to be wired into the new flow.
Generated by Claude Code
Add a Chat tab alongside the Scene outliner in the 3D model editor's left panel, reusing the existing ChatView wired to GlobalChatStore so the assistant can build and edit the scene conversationally. Expose scene operations to the agent via a UI tooling bridge: - model3DToolBridge: a singleton the open editor populates on mount with scene-operation handlers (list/add/select/delete/transform/visibility/ rename/material-color/frame) and clears on unmount. - ui_3d_* frontend tools delegate to the bridge and are registered with FrontendToolRegistry, so they flow through the same manifest + tool-call path as the existing ui_* graph tools (both chat and agent sockets). The tools fail with a clear message when no editor is open. Includes unit tests for tool registration, bridge gating, and delegation. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018KZo7SELSMLZaB47hJ6nmA
b6577d7 to
3e75d6f
Compare
|
Rebased onto The runner no longer owns a Phase 1/2 loop —
Tests added for Generated by Claude Code |
…re_view
Add an on-demand screenshot tool so a vision-capable assistant can visually
inspect the 3D scene, not just its structured graph.
Frontend:
- ui_3d_capture_view renders the live R3F viewport (gl.render + toDataURL)
and returns it as { image_content: { data, mimeType } }.
- CaptureBridge publishes the renderer/scene/camera from inside the Canvas;
the editor's captureView() grabs a PNG on demand.
Backend — image tool-results threaded through the provider agent loop:
- BaseProvider.generateLoop's executeTool may now return string | MessageContent[];
an array is fed straight into the tool Message so vision providers see it.
The legacy inline onToolCall channel and the Claude Agent SDK's text-only MCP
tools collapse image content to its text via the new toolResultToText helper.
- unified-websocket-runner's executeTool returns image MessageContent blocks for
results carrying image_content (extractToolResultImageContent); the persisted/
echoed tool message keeps only the note text so base64 never bloats history.
- anthropic-provider renders MessageContent[] (text + image) inside tool_result
blocks; the image-block conversion is factored into convertImagePart and
reused by the user-message path. Other providers keep the text fallback.
Tests cover the tool contract, the runner's image extraction, toolResultToText,
generateLoop routing array results into the tool message, and the Anthropic
tool_result block conversion.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KZo7SELSMLZaB47hJ6nmA
3e75d6f to
2cb7aba
Compare
Summary
Adds a comprehensive agent-tool interface for the 3D model editor, enabling the AI assistant to programmatically build and modify scenes. Introduces a new chat panel in the editor's left sidebar where users can converse with the assistant to drive scene creation and editing through natural language.
Key Changes
Model3D Tool Bridge (
model3DToolBridge.ts): New module that registers a handler interface (Model3DToolHandler) exposing scene operations (list, add, select, delete, transform, visibility, rename, color, frame). The editor registers its implementation on mount and clears it on unmount, ensuring tools only work when an editor is open.Frontend Tools (
builtin/model3d.ts): Nine newui_3d_*tools registered with theFrontendToolRegistry:ui_3d_list_scene— enumerate all objects with their transforms and propertiesui_3d_add_object— create primitives (box, sphere, plane, cylinder, torus, lights)ui_3d_select_object— drive the transform gizmo and Properties panelui_3d_delete_object— remove objects from the sceneui_3d_set_transform— modify position, rotation (in degrees), and scaleui_3d_set_visibility— show/hide objectsui_3d_rename_object— change object namesui_3d_set_material_color— set mesh material colors via hex stringsui_3d_frame_scene— fit camera to scene boundsModel3DChatPanel (
Model3DChatPanel.tsx): New React component that embedsChatViewin the editor's left sidebar, wired to the sharedGlobalChatStore. Reuses the existing chat infrastructure so the assistant can call the registeredui_3d_*tools. Includes a welcome placeholder with usage hints.Editor Layout Refactor (
Model3DEditor.tsx):TabGroupswitching between "Scene" (existingSceneOutliner) and "Chat" (newModel3DChatPanel)display) to preserve chat connection and scroll state across tab switchesfindObject()(lookup by uuid or name),toNode()(serialize Three.js objects toModel3DSceneNode),uniqueName()(collision-free naming),addPrimitiveObject()(extracted fromhandleAdd)useEffect, using aselectedUuidRefto let stable callbacks read the latest selection without re-registeringTests (
model3dTools.test.ts): Comprehensive test suite covering tool registration, error handling (no editor open), parameter validation, and handler delegation for all nine tools.Integration: Updated
index.tsxandfrontendToolsIpc.tsto import and register the newmodel3dtools module.Notable Implementation Details
Model3DSceneNodeuse degrees for rotation (matching the Properties panel UI), while Three.js internally uses radians. Conversion happens at the handler boundary.selectedUuidRef.current, avoiding re-registration churn as selection changes.https://claude.ai/code/session_018KZo7SELSMLZaB47hJ6nmA