unreal-engine-mcp-server 0.4.7 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +26 -0
- package/.env.production +38 -7
- package/.eslintrc.json +0 -54
- package/.eslintrc.override.json +8 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +94 -0
- package/.github/ISSUE_TEMPLATE/config.yml +8 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +56 -0
- package/.github/copilot-instructions.md +478 -45
- package/.github/dependabot.yml +19 -0
- package/.github/labeler.yml +24 -0
- package/.github/labels.yml +70 -0
- package/.github/pull_request_template.md +42 -0
- package/.github/release-drafter-config.yml +51 -0
- package/.github/workflows/auto-merge.yml +38 -0
- package/.github/workflows/ci.yml +38 -0
- package/.github/workflows/dependency-review.yml +17 -0
- package/.github/workflows/gemini-issue-triage.yml +172 -0
- package/.github/workflows/greetings.yml +27 -0
- package/.github/workflows/labeler.yml +17 -0
- package/.github/workflows/links.yml +80 -0
- package/.github/workflows/pr-size-labeler.yml +137 -0
- package/.github/workflows/publish-mcp.yml +13 -7
- package/.github/workflows/release-drafter.yml +23 -0
- package/.github/workflows/release.yml +112 -0
- package/.github/workflows/semantic-pull-request.yml +35 -0
- package/.github/workflows/smoke-test.yml +36 -0
- package/.github/workflows/stale.yml +28 -0
- package/CHANGELOG.md +338 -31
- package/CONTRIBUTING.md +140 -0
- package/GEMINI.md +115 -0
- package/Public/Plugin_setup_guide.mp4 +0 -0
- package/README.md +189 -128
- package/claude_desktop_config_example.json +7 -6
- package/dist/automation/bridge.d.ts +50 -0
- package/dist/automation/bridge.js +452 -0
- package/dist/automation/connection-manager.d.ts +23 -0
- package/dist/automation/connection-manager.js +107 -0
- package/dist/automation/handshake.d.ts +11 -0
- package/dist/automation/handshake.js +89 -0
- package/dist/automation/index.d.ts +3 -0
- package/dist/automation/index.js +3 -0
- package/dist/automation/message-handler.d.ts +12 -0
- package/dist/automation/message-handler.js +149 -0
- package/dist/automation/request-tracker.d.ts +25 -0
- package/dist/automation/request-tracker.js +98 -0
- package/dist/automation/types.d.ts +130 -0
- package/dist/automation/types.js +2 -0
- package/dist/cli.js +32 -5
- package/dist/config.d.ts +26 -0
- package/dist/config.js +59 -0
- package/dist/constants.d.ts +16 -0
- package/dist/constants.js +16 -0
- package/dist/graphql/loaders.d.ts +64 -0
- package/dist/graphql/loaders.js +117 -0
- package/dist/graphql/resolvers.d.ts +268 -0
- package/dist/graphql/resolvers.js +746 -0
- package/dist/graphql/schema.d.ts +5 -0
- package/dist/graphql/schema.js +437 -0
- package/dist/graphql/server.d.ts +26 -0
- package/dist/graphql/server.js +117 -0
- package/dist/graphql/types.d.ts +9 -0
- package/dist/graphql/types.js +2 -0
- package/dist/handlers/resource-handlers.d.ts +20 -0
- package/dist/handlers/resource-handlers.js +180 -0
- package/dist/index.d.ts +33 -18
- package/dist/index.js +130 -619
- package/dist/resources/actors.d.ts +17 -12
- package/dist/resources/actors.js +56 -76
- package/dist/resources/assets.d.ts +6 -14
- package/dist/resources/assets.js +115 -147
- package/dist/resources/levels.d.ts +13 -13
- package/dist/resources/levels.js +25 -34
- package/dist/server/resource-registry.d.ts +20 -0
- package/dist/server/resource-registry.js +37 -0
- package/dist/server/tool-registry.d.ts +23 -0
- package/dist/server/tool-registry.js +322 -0
- package/dist/server-setup.d.ts +20 -0
- package/dist/server-setup.js +71 -0
- package/dist/services/health-monitor.d.ts +34 -0
- package/dist/services/health-monitor.js +105 -0
- package/dist/services/metrics-server.d.ts +11 -0
- package/dist/services/metrics-server.js +105 -0
- package/dist/tools/actors.d.ts +163 -9
- package/dist/tools/actors.js +356 -311
- package/dist/tools/animation.d.ts +135 -4
- package/dist/tools/animation.js +510 -411
- package/dist/tools/assets.d.ts +75 -29
- package/dist/tools/assets.js +265 -284
- package/dist/tools/audio.d.ts +102 -42
- package/dist/tools/audio.js +272 -685
- package/dist/tools/base-tool.d.ts +17 -0
- package/dist/tools/base-tool.js +46 -0
- package/dist/tools/behavior-tree.d.ts +94 -0
- package/dist/tools/behavior-tree.js +39 -0
- package/dist/tools/blueprint.d.ts +208 -126
- package/dist/tools/blueprint.js +685 -832
- package/dist/tools/consolidated-tool-definitions.d.ts +5462 -1781
- package/dist/tools/consolidated-tool-definitions.js +829 -496
- package/dist/tools/consolidated-tool-handlers.d.ts +2 -1
- package/dist/tools/consolidated-tool-handlers.js +198 -1027
- package/dist/tools/debug.d.ts +143 -85
- package/dist/tools/debug.js +234 -180
- package/dist/tools/dynamic-handler-registry.d.ts +13 -0
- package/dist/tools/dynamic-handler-registry.js +23 -0
- package/dist/tools/editor.d.ts +30 -83
- package/dist/tools/editor.js +247 -244
- package/dist/tools/engine.d.ts +10 -4
- package/dist/tools/engine.js +13 -5
- package/dist/tools/environment.d.ts +30 -0
- package/dist/tools/environment.js +267 -0
- package/dist/tools/foliage.d.ts +65 -99
- package/dist/tools/foliage.js +221 -331
- package/dist/tools/handlers/actor-handlers.d.ts +3 -0
- package/dist/tools/handlers/actor-handlers.js +227 -0
- package/dist/tools/handlers/animation-handlers.d.ts +3 -0
- package/dist/tools/handlers/animation-handlers.js +185 -0
- package/dist/tools/handlers/argument-helper.d.ts +16 -0
- package/dist/tools/handlers/argument-helper.js +80 -0
- package/dist/tools/handlers/asset-handlers.d.ts +3 -0
- package/dist/tools/handlers/asset-handlers.js +496 -0
- package/dist/tools/handlers/audio-handlers.d.ts +3 -0
- package/dist/tools/handlers/audio-handlers.js +166 -0
- package/dist/tools/handlers/blueprint-handlers.d.ts +4 -0
- package/dist/tools/handlers/blueprint-handlers.js +358 -0
- package/dist/tools/handlers/common-handlers.d.ts +14 -0
- package/dist/tools/handlers/common-handlers.js +56 -0
- package/dist/tools/handlers/editor-handlers.d.ts +3 -0
- package/dist/tools/handlers/editor-handlers.js +119 -0
- package/dist/tools/handlers/effect-handlers.d.ts +3 -0
- package/dist/tools/handlers/effect-handlers.js +171 -0
- package/dist/tools/handlers/environment-handlers.d.ts +3 -0
- package/dist/tools/handlers/environment-handlers.js +170 -0
- package/dist/tools/handlers/graph-handlers.d.ts +3 -0
- package/dist/tools/handlers/graph-handlers.js +90 -0
- package/dist/tools/handlers/input-handlers.d.ts +3 -0
- package/dist/tools/handlers/input-handlers.js +21 -0
- package/dist/tools/handlers/inspect-handlers.d.ts +3 -0
- package/dist/tools/handlers/inspect-handlers.js +383 -0
- package/dist/tools/handlers/level-handlers.d.ts +3 -0
- package/dist/tools/handlers/level-handlers.js +237 -0
- package/dist/tools/handlers/lighting-handlers.d.ts +3 -0
- package/dist/tools/handlers/lighting-handlers.js +144 -0
- package/dist/tools/handlers/performance-handlers.d.ts +3 -0
- package/dist/tools/handlers/performance-handlers.js +130 -0
- package/dist/tools/handlers/pipeline-handlers.d.ts +3 -0
- package/dist/tools/handlers/pipeline-handlers.js +110 -0
- package/dist/tools/handlers/sequence-handlers.d.ts +3 -0
- package/dist/tools/handlers/sequence-handlers.js +376 -0
- package/dist/tools/handlers/system-handlers.d.ts +4 -0
- package/dist/tools/handlers/system-handlers.js +506 -0
- package/dist/tools/input.d.ts +19 -0
- package/dist/tools/input.js +89 -0
- package/dist/tools/introspection.d.ts +103 -40
- package/dist/tools/introspection.js +425 -568
- package/dist/tools/landscape.d.ts +54 -93
- package/dist/tools/landscape.js +284 -409
- package/dist/tools/level.d.ts +66 -27
- package/dist/tools/level.js +647 -675
- package/dist/tools/lighting.d.ts +77 -38
- package/dist/tools/lighting.js +445 -943
- package/dist/tools/logs.d.ts +3 -3
- package/dist/tools/logs.js +5 -57
- package/dist/tools/materials.d.ts +91 -24
- package/dist/tools/materials.js +194 -118
- package/dist/tools/niagara.d.ts +149 -39
- package/dist/tools/niagara.js +267 -182
- package/dist/tools/performance.d.ts +27 -13
- package/dist/tools/performance.js +203 -122
- package/dist/tools/physics.d.ts +32 -77
- package/dist/tools/physics.js +175 -582
- package/dist/tools/property-dictionary.d.ts +13 -0
- package/dist/tools/property-dictionary.js +82 -0
- package/dist/tools/sequence.d.ts +85 -60
- package/dist/tools/sequence.js +208 -747
- package/dist/tools/tool-definition-utils.d.ts +59 -0
- package/dist/tools/tool-definition-utils.js +35 -0
- package/dist/tools/ui.d.ts +64 -34
- package/dist/tools/ui.js +134 -214
- package/dist/types/automation-responses.d.ts +115 -0
- package/dist/types/automation-responses.js +2 -0
- package/dist/types/env.d.ts +0 -3
- package/dist/types/env.js +0 -7
- package/dist/types/responses.d.ts +249 -0
- package/dist/types/responses.js +2 -0
- package/dist/types/tool-interfaces.d.ts +898 -0
- package/dist/types/tool-interfaces.js +2 -0
- package/dist/types/tool-types.d.ts +183 -19
- package/dist/types/tool-types.js +0 -4
- package/dist/unreal-bridge.d.ts +24 -131
- package/dist/unreal-bridge.js +364 -1506
- package/dist/utils/command-validator.d.ts +9 -0
- package/dist/utils/command-validator.js +68 -0
- package/dist/utils/elicitation.d.ts +1 -1
- package/dist/utils/elicitation.js +12 -15
- package/dist/utils/error-handler.d.ts +2 -51
- package/dist/utils/error-handler.js +11 -87
- package/dist/utils/ini-reader.d.ts +3 -0
- package/dist/utils/ini-reader.js +69 -0
- package/dist/utils/logger.js +9 -6
- package/dist/utils/normalize.d.ts +3 -0
- package/dist/utils/normalize.js +56 -0
- package/dist/utils/path-security.d.ts +2 -0
- package/dist/utils/path-security.js +24 -0
- package/dist/utils/response-factory.d.ts +7 -0
- package/dist/utils/response-factory.js +27 -0
- package/dist/utils/response-validator.d.ts +3 -24
- package/dist/utils/response-validator.js +130 -81
- package/dist/utils/result-helpers.d.ts +4 -5
- package/dist/utils/result-helpers.js +15 -16
- package/dist/utils/safe-json.js +5 -11
- package/dist/utils/unreal-command-queue.d.ts +24 -0
- package/dist/utils/unreal-command-queue.js +120 -0
- package/dist/utils/validation.d.ts +0 -40
- package/dist/utils/validation.js +1 -78
- package/dist/wasm/index.d.ts +70 -0
- package/dist/wasm/index.js +535 -0
- package/docs/GraphQL-API.md +888 -0
- package/docs/Migration-Guide-v0.5.0.md +684 -0
- package/docs/Roadmap.md +53 -0
- package/docs/WebAssembly-Integration.md +628 -0
- package/docs/editor-plugin-extension.md +370 -0
- package/docs/handler-mapping.md +242 -0
- package/docs/native-automation-progress.md +128 -0
- package/docs/testing-guide.md +423 -0
- package/mcp-config-example.json +6 -6
- package/package.json +67 -28
- package/plugins/McpAutomationBridge/Config/FilterPlugin.ini +8 -0
- package/plugins/McpAutomationBridge/McpAutomationBridge.uplugin +64 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/McpAutomationBridge.Build.cs +189 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridgeGlobals.cpp +22 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridgeGlobals.h +30 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridgeHelpers.h +1983 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridgeModule.cpp +72 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridgeSettings.cpp +46 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridgeSubsystem.cpp +581 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_AnimationHandlers.cpp +2394 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_AssetQueryHandlers.cpp +300 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_AssetWorkflowHandlers.cpp +2807 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_AudioHandlers.cpp +1087 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_BehaviorTreeHandlers.cpp +488 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_BlueprintCreationHandlers.cpp +643 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_BlueprintCreationHandlers.h +31 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_BlueprintGraphHandlers.cpp +1184 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_BlueprintHandlers.cpp +5652 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_BlueprintHandlers_List.cpp +152 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_ControlHandlers.cpp +2614 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_DebugHandlers.cpp +42 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_EditorFunctionHandlers.cpp +1237 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_EffectHandlers.cpp +1701 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_EnvironmentHandlers.cpp +2145 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_FoliageHandlers.cpp +954 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_InputHandlers.cpp +209 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_InsightsHandlers.cpp +41 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_LandscapeHandlers.cpp +1164 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_LevelHandlers.cpp +762 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_LightingHandlers.cpp +634 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_LogHandlers.cpp +136 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_MaterialGraphHandlers.cpp +494 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_NiagaraGraphHandlers.cpp +278 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_NiagaraHandlers.cpp +625 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_PerformanceHandlers.cpp +401 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_PipelineHandlers.cpp +67 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_ProcessRequest.cpp +735 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_PropertyHandlers.cpp +2634 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_RenderHandlers.cpp +189 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_SCSHandlers.cpp +917 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_SCSHandlers.h +39 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_SequenceHandlers.cpp +2670 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_SequencerHandlers.cpp +519 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_TestHandlers.cpp +38 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_UiHandlers.cpp +668 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpAutomationBridge_WorldPartitionHandlers.cpp +346 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpBridgeWebSocket.cpp +1330 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpBridgeWebSocket.h +149 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Private/McpConnectionManager.cpp +783 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Public/McpAutomationBridgeSettings.h +115 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Public/McpAutomationBridgeSubsystem.h +796 -0
- package/plugins/McpAutomationBridge/Source/McpAutomationBridge/Public/McpConnectionManager.h +117 -0
- package/scripts/check-unreal-connection.mjs +19 -0
- package/scripts/clean-tmp.js +23 -0
- package/scripts/patch-wasm.js +26 -0
- package/scripts/run-all-tests.mjs +136 -0
- package/scripts/smoke-test.ts +94 -0
- package/scripts/sync-mcp-plugin.js +143 -0
- package/scripts/test-no-plugin-alternates.mjs +113 -0
- package/scripts/validate-server.js +46 -0
- package/scripts/verify-automation-bridge.js +200 -0
- package/server.json +58 -21
- package/src/automation/bridge.ts +558 -0
- package/src/automation/connection-manager.ts +130 -0
- package/src/automation/handshake.ts +99 -0
- package/src/automation/index.ts +2 -0
- package/src/automation/message-handler.ts +167 -0
- package/src/automation/request-tracker.ts +123 -0
- package/src/automation/types.ts +107 -0
- package/src/cli.ts +33 -6
- package/src/config.ts +73 -0
- package/src/constants.ts +19 -0
- package/src/graphql/loaders.ts +244 -0
- package/src/graphql/resolvers.ts +1008 -0
- package/src/graphql/schema.ts +452 -0
- package/src/graphql/server.ts +156 -0
- package/src/graphql/types.ts +10 -0
- package/src/handlers/resource-handlers.ts +186 -0
- package/src/index.ts +166 -664
- package/src/resources/actors.ts +58 -76
- package/src/resources/assets.ts +148 -134
- package/src/resources/levels.ts +28 -33
- package/src/server/resource-registry.ts +47 -0
- package/src/server/tool-registry.ts +354 -0
- package/src/server-setup.ts +114 -0
- package/src/services/health-monitor.ts +132 -0
- package/src/services/metrics-server.ts +142 -0
- package/src/tools/actors.ts +426 -323
- package/src/tools/animation.ts +672 -461
- package/src/tools/assets.ts +364 -289
- package/src/tools/audio.ts +323 -766
- package/src/tools/base-tool.ts +52 -0
- package/src/tools/behavior-tree.ts +45 -0
- package/src/tools/blueprint.ts +792 -970
- package/src/tools/consolidated-tool-definitions.ts +993 -515
- package/src/tools/consolidated-tool-handlers.ts +258 -1146
- package/src/tools/debug.ts +292 -187
- package/src/tools/dynamic-handler-registry.ts +33 -0
- package/src/tools/editor.ts +329 -253
- package/src/tools/engine.ts +14 -3
- package/src/tools/environment.ts +281 -0
- package/src/tools/foliage.ts +330 -392
- package/src/tools/handlers/actor-handlers.ts +265 -0
- package/src/tools/handlers/animation-handlers.ts +237 -0
- package/src/tools/handlers/argument-helper.ts +142 -0
- package/src/tools/handlers/asset-handlers.ts +532 -0
- package/src/tools/handlers/audio-handlers.ts +194 -0
- package/src/tools/handlers/blueprint-handlers.ts +380 -0
- package/src/tools/handlers/common-handlers.ts +87 -0
- package/src/tools/handlers/editor-handlers.ts +123 -0
- package/src/tools/handlers/effect-handlers.ts +220 -0
- package/src/tools/handlers/environment-handlers.ts +183 -0
- package/src/tools/handlers/graph-handlers.ts +116 -0
- package/src/tools/handlers/input-handlers.ts +28 -0
- package/src/tools/handlers/inspect-handlers.ts +450 -0
- package/src/tools/handlers/level-handlers.ts +252 -0
- package/src/tools/handlers/lighting-handlers.ts +147 -0
- package/src/tools/handlers/performance-handlers.ts +132 -0
- package/src/tools/handlers/pipeline-handlers.ts +127 -0
- package/src/tools/handlers/sequence-handlers.ts +415 -0
- package/src/tools/handlers/system-handlers.ts +564 -0
- package/src/tools/input.ts +101 -0
- package/src/tools/introspection.ts +493 -584
- package/src/tools/landscape.ts +418 -507
- package/src/tools/level.ts +786 -708
- package/src/tools/lighting.ts +588 -984
- package/src/tools/logs.ts +9 -57
- package/src/tools/materials.ts +237 -121
- package/src/tools/niagara.ts +335 -168
- package/src/tools/performance.ts +320 -169
- package/src/tools/physics.ts +274 -613
- package/src/tools/property-dictionary.ts +98 -0
- package/src/tools/sequence.ts +276 -820
- package/src/tools/tool-definition-utils.ts +35 -0
- package/src/tools/ui.ts +205 -283
- package/src/types/automation-responses.ts +119 -0
- package/src/types/env.ts +0 -10
- package/src/types/responses.ts +355 -0
- package/src/types/tool-interfaces.ts +250 -0
- package/src/types/tool-types.ts +243 -21
- package/src/unreal-bridge.ts +460 -1550
- package/src/utils/command-validator.ts +76 -0
- package/src/utils/elicitation.ts +10 -7
- package/src/utils/error-handler.ts +14 -90
- package/src/utils/ini-reader.ts +86 -0
- package/src/utils/logger.ts +8 -3
- package/src/utils/normalize.test.ts +162 -0
- package/src/utils/normalize.ts +60 -0
- package/src/utils/path-security.ts +43 -0
- package/src/utils/response-factory.ts +44 -0
- package/src/utils/response-validator.ts +176 -56
- package/src/utils/result-helpers.ts +21 -19
- package/src/utils/safe-json.test.ts +90 -0
- package/src/utils/safe-json.ts +14 -11
- package/src/utils/unreal-command-queue.ts +152 -0
- package/src/utils/validation.test.ts +184 -0
- package/src/utils/validation.ts +4 -1
- package/src/wasm/index.ts +838 -0
- package/test-server.mjs +100 -0
- package/tests/run-unreal-tool-tests.mjs +242 -14
- package/tests/test-animation.mjs +369 -0
- package/tests/test-asset-advanced.mjs +82 -0
- package/tests/test-asset-errors.mjs +35 -0
- package/tests/test-asset-graph.mjs +311 -0
- package/tests/test-audio.mjs +417 -0
- package/tests/test-automation-timeouts.mjs +98 -0
- package/tests/test-behavior-tree.mjs +444 -0
- package/tests/test-blueprint-graph.mjs +410 -0
- package/tests/test-blueprint.mjs +577 -0
- package/tests/test-client-mode.mjs +86 -0
- package/tests/test-console-command.mjs +56 -0
- package/tests/test-control-actor.mjs +425 -0
- package/tests/test-control-editor.mjs +112 -0
- package/tests/test-graphql.mjs +372 -0
- package/tests/test-input.mjs +349 -0
- package/tests/test-inspect.mjs +302 -0
- package/tests/test-landscape.mjs +316 -0
- package/tests/test-lighting.mjs +428 -0
- package/tests/test-manage-asset.mjs +438 -0
- package/tests/test-manage-level.mjs +89 -0
- package/tests/test-materials.mjs +356 -0
- package/tests/test-niagara.mjs +185 -0
- package/tests/test-no-inline-python.mjs +122 -0
- package/tests/test-performance.mjs +539 -0
- package/tests/test-plugin-handshake.mjs +82 -0
- package/tests/test-runner.mjs +933 -0
- package/tests/test-sequence.mjs +104 -0
- package/tests/test-system.mjs +96 -0
- package/tests/test-wasm.mjs +283 -0
- package/tests/test-world-partition.mjs +215 -0
- package/tsconfig.json +3 -3
- package/vitest.config.ts +35 -0
- package/wasm/Cargo.lock +363 -0
- package/wasm/Cargo.toml +42 -0
- package/wasm/LICENSE +21 -0
- package/wasm/README.md +253 -0
- package/wasm/src/dependency_resolver.rs +377 -0
- package/wasm/src/lib.rs +153 -0
- package/wasm/src/property_parser.rs +271 -0
- package/wasm/src/transform_math.rs +396 -0
- package/wasm/tests/integration.rs +109 -0
- package/.github/workflows/smithery-build.yml +0 -29
- package/dist/prompts/index.d.ts +0 -21
- package/dist/prompts/index.js +0 -217
- package/dist/tools/build_environment_advanced.d.ts +0 -65
- package/dist/tools/build_environment_advanced.js +0 -633
- package/dist/tools/rc.d.ts +0 -110
- package/dist/tools/rc.js +0 -437
- package/dist/tools/visual.d.ts +0 -40
- package/dist/tools/visual.js +0 -282
- package/dist/utils/http.d.ts +0 -6
- package/dist/utils/http.js +0 -151
- package/dist/utils/python-output.d.ts +0 -18
- package/dist/utils/python-output.js +0 -290
- package/dist/utils/python.d.ts +0 -2
- package/dist/utils/python.js +0 -4
- package/dist/utils/stdio-redirect.d.ts +0 -2
- package/dist/utils/stdio-redirect.js +0 -20
- package/docs/unreal-tool-test-cases.md +0 -574
- package/smithery.yaml +0 -29
- package/src/prompts/index.ts +0 -249
- package/src/tools/build_environment_advanced.ts +0 -732
- package/src/tools/rc.ts +0 -515
- package/src/tools/visual.ts +0 -281
- package/src/utils/http.ts +0 -187
- package/src/utils/python-output.ts +0 -351
- package/src/utils/python.ts +0 -3
- package/src/utils/stdio-redirect.ts +0 -18
|
@@ -0,0 +1,1164 @@
|
|
|
1
|
+
#include "McpAutomationBridgeGlobals.h"
|
|
2
|
+
#include "McpAutomationBridgeHelpers.h"
|
|
3
|
+
#include "McpAutomationBridgeSubsystem.h"
|
|
4
|
+
#include "Runtime/Launch/Resources/Version.h"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
#if WITH_EDITOR
|
|
8
|
+
#include "Async/Async.h"
|
|
9
|
+
#include "EditorAssetLibrary.h"
|
|
10
|
+
#include "Engine/World.h"
|
|
11
|
+
#include "Landscape.h"
|
|
12
|
+
#include "LandscapeComponent.h"
|
|
13
|
+
#include "LandscapeDataAccess.h"
|
|
14
|
+
#include "LandscapeEdit.h"
|
|
15
|
+
#include "LandscapeEditorObject.h"
|
|
16
|
+
#include "LandscapeEditorUtils.h"
|
|
17
|
+
#include "LandscapeGrassType.h"
|
|
18
|
+
#include "LandscapeInfo.h"
|
|
19
|
+
#include "LandscapeProxy.h"
|
|
20
|
+
#include "LandscapeStreamingProxy.h"
|
|
21
|
+
#include "Materials/Material.h"
|
|
22
|
+
#include "Materials/MaterialInstanceConstant.h"
|
|
23
|
+
#include "Misc/ScopedSlowTask.h"
|
|
24
|
+
#include "UObject/SavePackage.h"
|
|
25
|
+
|
|
26
|
+
#if __has_include("Subsystems/EditorActorSubsystem.h")
|
|
27
|
+
#include "Subsystems/EditorActorSubsystem.h"
|
|
28
|
+
#elif __has_include("EditorActorSubsystem.h")
|
|
29
|
+
#include "EditorActorSubsystem.h"
|
|
30
|
+
#endif
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
bool UMcpAutomationBridgeSubsystem::HandleEditLandscape(
|
|
34
|
+
const FString &RequestId, const FString &Action,
|
|
35
|
+
const TSharedPtr<FJsonObject> &Payload,
|
|
36
|
+
TSharedPtr<FMcpBridgeWebSocket> RequestingSocket) {
|
|
37
|
+
// Dispatch to specific edit operations implemented below
|
|
38
|
+
if (HandleModifyHeightmap(RequestId, Action, Payload, RequestingSocket))
|
|
39
|
+
return true;
|
|
40
|
+
if (HandlePaintLandscapeLayer(RequestId, Action, Payload, RequestingSocket))
|
|
41
|
+
return true;
|
|
42
|
+
if (HandleSculptLandscape(RequestId, Action, Payload, RequestingSocket))
|
|
43
|
+
return true;
|
|
44
|
+
if (HandleSetLandscapeMaterial(RequestId, Action, Payload, RequestingSocket))
|
|
45
|
+
return true;
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
bool UMcpAutomationBridgeSubsystem::HandleCreateLandscape(
|
|
50
|
+
const FString &RequestId, const FString &Action,
|
|
51
|
+
const TSharedPtr<FJsonObject> &Payload,
|
|
52
|
+
TSharedPtr<FMcpBridgeWebSocket> RequestingSocket) {
|
|
53
|
+
const FString Lower = Action.ToLower();
|
|
54
|
+
if (!Lower.Equals(TEXT("create_landscape"), ESearchCase::IgnoreCase)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#if WITH_EDITOR
|
|
59
|
+
if (!Payload.IsValid()) {
|
|
60
|
+
SendAutomationError(RequestingSocket, RequestId,
|
|
61
|
+
TEXT("create_landscape payload missing"),
|
|
62
|
+
TEXT("INVALID_PAYLOAD"));
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Parse inputs (accept multiple shapes)
|
|
67
|
+
double X = 0.0, Y = 0.0, Z = 0.0;
|
|
68
|
+
if (!Payload->TryGetNumberField(TEXT("x"), X) ||
|
|
69
|
+
!Payload->TryGetNumberField(TEXT("y"), Y) ||
|
|
70
|
+
!Payload->TryGetNumberField(TEXT("z"), Z)) {
|
|
71
|
+
// Try location object { x, y, z }
|
|
72
|
+
const TSharedPtr<FJsonObject> *LocObj = nullptr;
|
|
73
|
+
if (Payload->TryGetObjectField(TEXT("location"), LocObj) && LocObj) {
|
|
74
|
+
(*LocObj)->TryGetNumberField(TEXT("x"), X);
|
|
75
|
+
(*LocObj)->TryGetNumberField(TEXT("y"), Y);
|
|
76
|
+
(*LocObj)->TryGetNumberField(TEXT("z"), Z);
|
|
77
|
+
} else {
|
|
78
|
+
// Try location as array [x,y,z]
|
|
79
|
+
const TArray<TSharedPtr<FJsonValue>> *LocArr = nullptr;
|
|
80
|
+
if (Payload->TryGetArrayField(TEXT("location"), LocArr) && LocArr &&
|
|
81
|
+
LocArr->Num() >= 3) {
|
|
82
|
+
X = (*LocArr)[0]->AsNumber();
|
|
83
|
+
Y = (*LocArr)[1]->AsNumber();
|
|
84
|
+
Z = (*LocArr)[2]->AsNumber();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
int32 ComponentsX = 8, ComponentsY = 8;
|
|
90
|
+
bool bHasCX = Payload->TryGetNumberField(TEXT("componentsX"), ComponentsX);
|
|
91
|
+
bool bHasCY = Payload->TryGetNumberField(TEXT("componentsY"), ComponentsY);
|
|
92
|
+
|
|
93
|
+
int32 ComponentCount = 0;
|
|
94
|
+
Payload->TryGetNumberField(TEXT("componentCount"), ComponentCount);
|
|
95
|
+
if (!bHasCX && ComponentCount > 0) {
|
|
96
|
+
ComponentsX = ComponentCount;
|
|
97
|
+
}
|
|
98
|
+
if (!bHasCY && ComponentCount > 0) {
|
|
99
|
+
ComponentsY = ComponentCount;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// If sizeX/sizeY provided (world units), derive a coarse components estimate
|
|
103
|
+
double SizeXUnits = 0.0, SizeYUnits = 0.0;
|
|
104
|
+
if (Payload->TryGetNumberField(TEXT("sizeX"), SizeXUnits) && SizeXUnits > 0 &&
|
|
105
|
+
!bHasCX) {
|
|
106
|
+
ComponentsX =
|
|
107
|
+
FMath::Max(1, static_cast<int32>(FMath::Floor(SizeXUnits / 1000.0)));
|
|
108
|
+
}
|
|
109
|
+
if (Payload->TryGetNumberField(TEXT("sizeY"), SizeYUnits) && SizeYUnits > 0 &&
|
|
110
|
+
!bHasCY) {
|
|
111
|
+
ComponentsY =
|
|
112
|
+
FMath::Max(1, static_cast<int32>(FMath::Floor(SizeYUnits / 1000.0)));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
int32 QuadsPerComponent = 63;
|
|
116
|
+
if (!Payload->TryGetNumberField(TEXT("quadsPerComponent"),
|
|
117
|
+
QuadsPerComponent)) {
|
|
118
|
+
// Accept quadsPerSection synonym from some clients
|
|
119
|
+
Payload->TryGetNumberField(TEXT("quadsPerSection"), QuadsPerComponent);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
int32 SectionsPerComponent = 1;
|
|
123
|
+
Payload->TryGetNumberField(TEXT("sectionsPerComponent"),
|
|
124
|
+
SectionsPerComponent);
|
|
125
|
+
|
|
126
|
+
FString MaterialPath;
|
|
127
|
+
Payload->TryGetStringField(TEXT("materialPath"), MaterialPath);
|
|
128
|
+
if (MaterialPath.IsEmpty()) {
|
|
129
|
+
// Default to simple WorldGridMaterial if none provided to ensure visibility
|
|
130
|
+
MaterialPath = TEXT("/Engine/EngineMaterials/WorldGridMaterial");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ... inside HandleCreateLandscape ...
|
|
134
|
+
if (!GEditor || !GEditor->GetEditorWorldContext().World()) {
|
|
135
|
+
SendAutomationError(RequestingSocket, RequestId,
|
|
136
|
+
TEXT("Editor world not available"),
|
|
137
|
+
TEXT("EDITOR_NOT_AVAILABLE"));
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
FString NameOverride;
|
|
142
|
+
if (!Payload->TryGetStringField(TEXT("name"), NameOverride) ||
|
|
143
|
+
NameOverride.IsEmpty()) {
|
|
144
|
+
Payload->TryGetStringField(TEXT("landscapeName"), NameOverride);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Capture parameters by value for the async task
|
|
148
|
+
const int32 CaptComponentsX = ComponentsX;
|
|
149
|
+
const int32 CaptComponentsY = ComponentsY;
|
|
150
|
+
const int32 CaptQuadsPerComponent = QuadsPerComponent;
|
|
151
|
+
const int32 CaptSectionsPerComponent = SectionsPerComponent;
|
|
152
|
+
const FVector CaptLocation(X, Y, Z);
|
|
153
|
+
const FString CaptMaterialPath = MaterialPath;
|
|
154
|
+
const FString CaptName = NameOverride;
|
|
155
|
+
|
|
156
|
+
// Debug log to confirm name capture
|
|
157
|
+
UE_LOG(LogMcpAutomationBridgeSubsystem, Display,
|
|
158
|
+
TEXT("HandleCreateLandscape: Captured name '%s' (from override '%s')"),
|
|
159
|
+
*CaptName, *NameOverride);
|
|
160
|
+
|
|
161
|
+
TWeakObjectPtr<UMcpAutomationBridgeSubsystem> WeakSubsystem(this);
|
|
162
|
+
|
|
163
|
+
// Execute on Game Thread to ensure thread safety for Actor spawning and
|
|
164
|
+
// Landscape operations
|
|
165
|
+
AsyncTask(ENamedThreads::GameThread, [WeakSubsystem, RequestId,
|
|
166
|
+
RequestingSocket, CaptComponentsX,
|
|
167
|
+
CaptComponentsY, CaptQuadsPerComponent,
|
|
168
|
+
CaptSectionsPerComponent, CaptLocation,
|
|
169
|
+
CaptMaterialPath, CaptName]() {
|
|
170
|
+
UMcpAutomationBridgeSubsystem *Subsystem = WeakSubsystem.Get();
|
|
171
|
+
if (!Subsystem)
|
|
172
|
+
return;
|
|
173
|
+
|
|
174
|
+
if (!GEditor)
|
|
175
|
+
return;
|
|
176
|
+
UWorld *World = GEditor->GetEditorWorldContext().World();
|
|
177
|
+
if (!World)
|
|
178
|
+
return;
|
|
179
|
+
|
|
180
|
+
FActorSpawnParameters SpawnParams;
|
|
181
|
+
SpawnParams.SpawnCollisionHandlingOverride =
|
|
182
|
+
ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
|
183
|
+
ALandscape *Landscape =
|
|
184
|
+
World->SpawnActor<ALandscape>(ALandscape::StaticClass(), CaptLocation,
|
|
185
|
+
FRotator::ZeroRotator, SpawnParams);
|
|
186
|
+
if (!Landscape) {
|
|
187
|
+
Subsystem->SendAutomationError(RequestingSocket, RequestId,
|
|
188
|
+
TEXT("Failed to spawn landscape actor"),
|
|
189
|
+
TEXT("SPAWN_FAILED"));
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (!CaptName.IsEmpty()) {
|
|
194
|
+
Landscape->SetActorLabel(CaptName);
|
|
195
|
+
} else {
|
|
196
|
+
Landscape->SetActorLabel(FString::Printf(
|
|
197
|
+
TEXT("Landscape_%dx%d"), CaptComponentsX, CaptComponentsY));
|
|
198
|
+
}
|
|
199
|
+
Landscape->ComponentSizeQuads = CaptQuadsPerComponent;
|
|
200
|
+
Landscape->SubsectionSizeQuads =
|
|
201
|
+
CaptQuadsPerComponent / CaptSectionsPerComponent;
|
|
202
|
+
Landscape->NumSubsections = CaptSectionsPerComponent;
|
|
203
|
+
|
|
204
|
+
if (!CaptMaterialPath.IsEmpty()) {
|
|
205
|
+
UMaterialInterface *Mat =
|
|
206
|
+
LoadObject<UMaterialInterface>(nullptr, *CaptMaterialPath);
|
|
207
|
+
if (Mat) {
|
|
208
|
+
Landscape->LandscapeMaterial = Mat;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// CRITICAL INITIALIZATION ORDER:
|
|
213
|
+
// 1. Set Landscape GUID first. CreateLandscapeInfo depends on this.
|
|
214
|
+
if (!Landscape->GetLandscapeGuid().IsValid()) {
|
|
215
|
+
Landscape->SetLandscapeGuid(FGuid::NewGuid());
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// 2. Create Landscape Info. This will register itself with the Landscape's
|
|
219
|
+
// GUID.
|
|
220
|
+
Landscape->CreateLandscapeInfo();
|
|
221
|
+
|
|
222
|
+
const int32 VertX = CaptComponentsX * CaptQuadsPerComponent + 1;
|
|
223
|
+
const int32 VertY = CaptComponentsY * CaptQuadsPerComponent + 1;
|
|
224
|
+
|
|
225
|
+
TArray<uint16> HeightArray;
|
|
226
|
+
HeightArray.Init(32768, VertX * VertY);
|
|
227
|
+
|
|
228
|
+
const int32 InMinX = 0;
|
|
229
|
+
const int32 InMinY = 0;
|
|
230
|
+
const int32 InMaxX = CaptComponentsX * CaptQuadsPerComponent;
|
|
231
|
+
const int32 InMaxY = CaptComponentsY * CaptQuadsPerComponent;
|
|
232
|
+
const int32 NumSubsections = CaptSectionsPerComponent;
|
|
233
|
+
const int32 SubsectionSizeQuads =
|
|
234
|
+
CaptQuadsPerComponent / FMath::Max(1, CaptSectionsPerComponent);
|
|
235
|
+
|
|
236
|
+
// 3. Use a valid GUID for Import call, but zero GUID for map keys.
|
|
237
|
+
// Analysis of Landscape.cpp shows:
|
|
238
|
+
// - Import() asserts InGuid.IsValid()
|
|
239
|
+
// - BUT Import() uses FGuid() (zero) to look up data in the maps:
|
|
240
|
+
// InImportHeightData.FindChecked(FinalLayerGuid) where FinalLayerGuid is
|
|
241
|
+
// default constructed.
|
|
242
|
+
const FGuid ImportGuid =
|
|
243
|
+
FGuid::NewGuid(); // Valid GUID for the function call
|
|
244
|
+
const FGuid DataKey; // Zero GUID for the map keys
|
|
245
|
+
|
|
246
|
+
// 3. Populate maps with FGuid() keys because ALandscape::Import uses
|
|
247
|
+
// default GUID to look up data regardless of the GUID passed to the
|
|
248
|
+
// function (which is used for the layer definition itself).
|
|
249
|
+
TMap<FGuid, TArray<uint16>> ImportHeightData;
|
|
250
|
+
ImportHeightData.Add(FGuid(), HeightArray);
|
|
251
|
+
|
|
252
|
+
TMap<FGuid, TArray<FLandscapeImportLayerInfo>> ImportLayerInfos;
|
|
253
|
+
ImportLayerInfos.Add(FGuid(), TArray<FLandscapeImportLayerInfo>());
|
|
254
|
+
|
|
255
|
+
TArray<FLandscapeLayer> EditLayers;
|
|
256
|
+
|
|
257
|
+
// Use a transaction to ensure undo/redo and proper notification
|
|
258
|
+
{
|
|
259
|
+
const FScopedTransaction Transaction(
|
|
260
|
+
FText::FromString(TEXT("Create Landscape")));
|
|
261
|
+
Landscape->Modify();
|
|
262
|
+
|
|
263
|
+
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 7
|
|
264
|
+
// UE 5.7+: The Import() function has a known issue with fresh landscapes.
|
|
265
|
+
// Use CreateDefaultLayer instead to initialize a valid landscape
|
|
266
|
+
// structure. Note: bCanHaveLayersContent is deprecated/removed in 5.7 as
|
|
267
|
+
// all landscapes use edit layers.
|
|
268
|
+
|
|
269
|
+
// Create default edit layer to enable modification
|
|
270
|
+
if (Landscape->GetLayersConst().Num() == 0) {
|
|
271
|
+
Landscape->CreateDefaultLayer();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Explicitly request layer initialization to ensure components are ready
|
|
275
|
+
// Landscape->RequestLayersInitialization(true, true); // Removed to
|
|
276
|
+
// prevent crash: LandscapeEditLayers.cpp confirms this resets init state
|
|
277
|
+
// which is unstable here
|
|
278
|
+
|
|
279
|
+
// Note: We bypass feeding ImportHeightData here because doing so via
|
|
280
|
+
// Import() is what causes the crash in 5.7. A flat empty landscape is
|
|
281
|
+
// created instead.
|
|
282
|
+
|
|
283
|
+
#else
|
|
284
|
+
// UE 5.6 and older: Use standard Import() workflow
|
|
285
|
+
Landscape->Import(FGuid::NewGuid(), 0, 0, CaptComponentsX - 1, CaptComponentsY - 1, CaptSectionsPerComponent, CaptQuadsPerComponent, ImportHeightData, nullptr, ImportLayerInfos, ELandscapeImportAlphamapType::Layered, TArrayView<const FLandscapeLayer>(EditLayers));
|
|
286
|
+
Landscape->CreateDefaultLayer();
|
|
287
|
+
#endif
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Initialize properties AFTER import to avoid conflicts during component
|
|
291
|
+
// creation
|
|
292
|
+
if (CaptName.IsEmpty()) {
|
|
293
|
+
Landscape->SetActorLabel(FString::Printf(
|
|
294
|
+
TEXT("Landscape_%dx%d"), CaptComponentsX, CaptComponentsY));
|
|
295
|
+
} else {
|
|
296
|
+
Landscape->SetActorLabel(CaptName);
|
|
297
|
+
UE_LOG(LogMcpAutomationBridgeSubsystem, Display,
|
|
298
|
+
TEXT("HandleCreateLandscape: Set ActorLabel to '%s'"), *CaptName);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (!CaptMaterialPath.IsEmpty()) {
|
|
302
|
+
UMaterialInterface *Mat =
|
|
303
|
+
LoadObject<UMaterialInterface>(nullptr, *CaptMaterialPath);
|
|
304
|
+
if (Mat) {
|
|
305
|
+
Landscape->LandscapeMaterial = Mat;
|
|
306
|
+
// Re-assign material effectively
|
|
307
|
+
Landscape->PostEditChange();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Register components if Import didn't do it (it usually does re-register)
|
|
312
|
+
if (Landscape->GetRootComponent() &&
|
|
313
|
+
!Landscape->GetRootComponent()->IsRegistered()) {
|
|
314
|
+
Landscape->RegisterAllComponents();
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Register components if Import didn't do it (it usually does re-register)
|
|
318
|
+
if (Landscape->GetRootComponent() &&
|
|
319
|
+
!Landscape->GetRootComponent()->IsRegistered()) {
|
|
320
|
+
Landscape->RegisterAllComponents();
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Only call PostEditChange if the landscape is still valid and not pending
|
|
324
|
+
// kill
|
|
325
|
+
if (IsValid(Landscape)) {
|
|
326
|
+
Landscape->PostEditChange();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
TSharedPtr<FJsonObject> Resp = MakeShared<FJsonObject>();
|
|
330
|
+
Resp->SetBoolField(TEXT("success"), true);
|
|
331
|
+
Resp->SetStringField(TEXT("landscapePath"), Landscape->GetPathName());
|
|
332
|
+
Resp->SetStringField(TEXT("actorLabel"), Landscape->GetActorLabel());
|
|
333
|
+
Resp->SetNumberField(TEXT("componentsX"), CaptComponentsX);
|
|
334
|
+
Resp->SetNumberField(TEXT("componentsY"), CaptComponentsY);
|
|
335
|
+
Resp->SetNumberField(TEXT("quadsPerComponent"), CaptQuadsPerComponent);
|
|
336
|
+
|
|
337
|
+
Subsystem->SendAutomationResponse(RequestingSocket, RequestId, true,
|
|
338
|
+
TEXT("Landscape created successfully"),
|
|
339
|
+
Resp, FString());
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
return true;
|
|
343
|
+
#else
|
|
344
|
+
SendAutomationResponse(RequestingSocket, RequestId, false,
|
|
345
|
+
TEXT("create_landscape requires editor build."),
|
|
346
|
+
nullptr, TEXT("NOT_IMPLEMENTED"));
|
|
347
|
+
return true;
|
|
348
|
+
#endif
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
bool UMcpAutomationBridgeSubsystem::HandleModifyHeightmap(
|
|
352
|
+
const FString &RequestId, const FString &Action,
|
|
353
|
+
const TSharedPtr<FJsonObject> &Payload,
|
|
354
|
+
TSharedPtr<FMcpBridgeWebSocket> RequestingSocket) {
|
|
355
|
+
const FString Lower = Action.ToLower();
|
|
356
|
+
if (!Lower.Equals(TEXT("modify_heightmap"), ESearchCase::IgnoreCase)) {
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
#if WITH_EDITOR
|
|
361
|
+
if (!Payload.IsValid()) {
|
|
362
|
+
SendAutomationError(RequestingSocket, RequestId,
|
|
363
|
+
TEXT("modify_heightmap payload missing"),
|
|
364
|
+
TEXT("INVALID_PAYLOAD"));
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
FString LandscapePath;
|
|
369
|
+
Payload->TryGetStringField(TEXT("landscapePath"), LandscapePath);
|
|
370
|
+
FString LandscapeName;
|
|
371
|
+
Payload->TryGetStringField(TEXT("landscapeName"), LandscapeName);
|
|
372
|
+
|
|
373
|
+
const TArray<TSharedPtr<FJsonValue>> *HeightDataArray = nullptr;
|
|
374
|
+
if (!Payload->TryGetArrayField(TEXT("heightData"), HeightDataArray) ||
|
|
375
|
+
!HeightDataArray || HeightDataArray->Num() == 0) {
|
|
376
|
+
SendAutomationError(RequestingSocket, RequestId,
|
|
377
|
+
TEXT("heightData array required"),
|
|
378
|
+
TEXT("INVALID_ARGUMENT"));
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Copy height data for async task
|
|
383
|
+
TArray<uint16> HeightValues;
|
|
384
|
+
for (const TSharedPtr<FJsonValue> &Val : *HeightDataArray) {
|
|
385
|
+
if (Val.IsValid() && Val->Type == EJson::Number) {
|
|
386
|
+
HeightValues.Add(
|
|
387
|
+
static_cast<uint16>(FMath::Clamp(Val->AsNumber(), 0.0, 65535.0)));
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
TWeakObjectPtr<UMcpAutomationBridgeSubsystem> WeakSubsystem(this);
|
|
392
|
+
|
|
393
|
+
// Dispatch to Game Thread
|
|
394
|
+
AsyncTask(ENamedThreads::GameThread, [WeakSubsystem, RequestId,
|
|
395
|
+
RequestingSocket, LandscapePath,
|
|
396
|
+
LandscapeName,
|
|
397
|
+
HeightValues =
|
|
398
|
+
MoveTemp(HeightValues)]() {
|
|
399
|
+
UMcpAutomationBridgeSubsystem *Subsystem = WeakSubsystem.Get();
|
|
400
|
+
if (!Subsystem)
|
|
401
|
+
return;
|
|
402
|
+
|
|
403
|
+
ALandscape *Landscape = nullptr;
|
|
404
|
+
if (!LandscapePath.IsEmpty()) {
|
|
405
|
+
Landscape = Cast<ALandscape>(
|
|
406
|
+
StaticLoadObject(ALandscape::StaticClass(), nullptr, *LandscapePath));
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Find landscape with fallback to single instance
|
|
410
|
+
if (!Landscape && GEditor) {
|
|
411
|
+
if (UEditorActorSubsystem *ActorSS =
|
|
412
|
+
GEditor->GetEditorSubsystem<UEditorActorSubsystem>()) {
|
|
413
|
+
TArray<AActor *> AllActors = ActorSS->GetAllLevelActors();
|
|
414
|
+
ALandscape *Fallback = nullptr;
|
|
415
|
+
int32 Count = 0;
|
|
416
|
+
|
|
417
|
+
for (AActor *A : AllActors) {
|
|
418
|
+
if (ALandscape *L = Cast<ALandscape>(A)) {
|
|
419
|
+
Count++;
|
|
420
|
+
Fallback = L;
|
|
421
|
+
if (!LandscapeName.IsEmpty() &&
|
|
422
|
+
L->GetActorLabel().Equals(LandscapeName,
|
|
423
|
+
ESearchCase::IgnoreCase)) {
|
|
424
|
+
Landscape = L;
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (!Landscape && Count == 1) {
|
|
431
|
+
Landscape = Fallback;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
if (!Landscape) {
|
|
436
|
+
Subsystem->SendAutomationError(RequestingSocket, RequestId,
|
|
437
|
+
TEXT("Failed to find landscape"),
|
|
438
|
+
TEXT("LOAD_FAILED"));
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
ULandscapeInfo *LandscapeInfo = Landscape->GetLandscapeInfo();
|
|
443
|
+
if (!LandscapeInfo) {
|
|
444
|
+
Subsystem->SendAutomationError(RequestingSocket, RequestId,
|
|
445
|
+
TEXT("Landscape has no info"),
|
|
446
|
+
TEXT("INVALID_LANDSCAPE"));
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
FScopedSlowTask SlowTask(2.0f,
|
|
451
|
+
FText::FromString(TEXT("Modifying heightmap...")));
|
|
452
|
+
SlowTask.MakeDialog();
|
|
453
|
+
|
|
454
|
+
int32 MinX, MinY, MaxX, MaxY;
|
|
455
|
+
if (!LandscapeInfo->GetLandscapeExtent(MinX, MinY, MaxX, MaxY)) {
|
|
456
|
+
Subsystem->SendAutomationError(RequestingSocket, RequestId,
|
|
457
|
+
TEXT("Failed to get landscape extent"),
|
|
458
|
+
TEXT("INVALID_LANDSCAPE"));
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
SlowTask.EnterProgressFrame(
|
|
463
|
+
1.0f, FText::FromString(TEXT("Writing heightmap data")));
|
|
464
|
+
|
|
465
|
+
const int32 SizeX = (MaxX - MinX + 1);
|
|
466
|
+
const int32 SizeY = (MaxY - MinY + 1);
|
|
467
|
+
|
|
468
|
+
if (HeightValues.Num() != SizeX * SizeY) {
|
|
469
|
+
Subsystem->SendAutomationError(
|
|
470
|
+
RequestingSocket, RequestId,
|
|
471
|
+
FString::Printf(TEXT("Height data size mismatch. Expected %d x %d = "
|
|
472
|
+
"%d values, got %d"),
|
|
473
|
+
SizeX, SizeY, SizeX * SizeY, HeightValues.Num()),
|
|
474
|
+
TEXT("INVALID_ARGUMENT"));
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
FLandscapeEditDataInterface LandscapeEdit(LandscapeInfo);
|
|
479
|
+
LandscapeEdit.SetHeightData(MinX, MinY, MaxX, MaxY, HeightValues.GetData(),
|
|
480
|
+
SizeX, true);
|
|
481
|
+
|
|
482
|
+
SlowTask.EnterProgressFrame(
|
|
483
|
+
1.0f, FText::FromString(TEXT("Rebuilding collision")));
|
|
484
|
+
LandscapeEdit.Flush();
|
|
485
|
+
Landscape->PostEditChange();
|
|
486
|
+
|
|
487
|
+
TSharedPtr<FJsonObject> Resp = MakeShared<FJsonObject>();
|
|
488
|
+
Resp->SetBoolField(TEXT("success"), true);
|
|
489
|
+
Resp->SetStringField(TEXT("landscapePath"), LandscapePath);
|
|
490
|
+
Resp->SetNumberField(TEXT("modifiedVertices"), HeightValues.Num());
|
|
491
|
+
|
|
492
|
+
Subsystem->SendAutomationResponse(RequestingSocket, RequestId, true,
|
|
493
|
+
TEXT("Heightmap modified successfully"),
|
|
494
|
+
Resp, FString());
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
return true;
|
|
498
|
+
#else
|
|
499
|
+
SendAutomationResponse(RequestingSocket, RequestId, false,
|
|
500
|
+
TEXT("modify_heightmap requires editor build."),
|
|
501
|
+
nullptr, TEXT("NOT_IMPLEMENTED"));
|
|
502
|
+
return true;
|
|
503
|
+
#endif
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
bool UMcpAutomationBridgeSubsystem::HandlePaintLandscapeLayer(
|
|
507
|
+
const FString &RequestId, const FString &Action,
|
|
508
|
+
const TSharedPtr<FJsonObject> &Payload,
|
|
509
|
+
TSharedPtr<FMcpBridgeWebSocket> RequestingSocket) {
|
|
510
|
+
const FString Lower = Action.ToLower();
|
|
511
|
+
if (!Lower.Equals(TEXT("paint_landscape_layer"), ESearchCase::IgnoreCase)) {
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
#if WITH_EDITOR
|
|
516
|
+
if (!Payload.IsValid()) {
|
|
517
|
+
SendAutomationError(RequestingSocket, RequestId,
|
|
518
|
+
TEXT("paint_landscape_layer payload missing"),
|
|
519
|
+
TEXT("INVALID_PAYLOAD"));
|
|
520
|
+
return true;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
FString LandscapePath;
|
|
524
|
+
Payload->TryGetStringField(TEXT("landscapePath"), LandscapePath);
|
|
525
|
+
FString LandscapeName;
|
|
526
|
+
Payload->TryGetStringField(TEXT("landscapeName"), LandscapeName);
|
|
527
|
+
|
|
528
|
+
FString LayerName;
|
|
529
|
+
if (!Payload->TryGetStringField(TEXT("layerName"), LayerName) ||
|
|
530
|
+
LayerName.IsEmpty()) {
|
|
531
|
+
SendAutomationError(RequestingSocket, RequestId, TEXT("layerName required"),
|
|
532
|
+
TEXT("INVALID_ARGUMENT"));
|
|
533
|
+
return true;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// Paint region (optional - if not specified, paint entire landscape)
|
|
537
|
+
int32 MinX = -1, MinY = -1, MaxX = -1, MaxY = -1;
|
|
538
|
+
const TSharedPtr<FJsonObject> *RegionObj = nullptr;
|
|
539
|
+
if (Payload->TryGetObjectField(TEXT("region"), RegionObj) && RegionObj) {
|
|
540
|
+
(*RegionObj)->TryGetNumberField(TEXT("minX"), MinX);
|
|
541
|
+
(*RegionObj)->TryGetNumberField(TEXT("minY"), MinY);
|
|
542
|
+
(*RegionObj)->TryGetNumberField(TEXT("maxX"), MaxX);
|
|
543
|
+
(*RegionObj)->TryGetNumberField(TEXT("maxY"), MaxY);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
double Strength = 1.0;
|
|
547
|
+
Payload->TryGetNumberField(TEXT("strength"), Strength);
|
|
548
|
+
Strength = FMath::Clamp(Strength, 0.0, 1.0);
|
|
549
|
+
|
|
550
|
+
TWeakObjectPtr<UMcpAutomationBridgeSubsystem> WeakSubsystem(this);
|
|
551
|
+
|
|
552
|
+
AsyncTask(ENamedThreads::GameThread, [WeakSubsystem, RequestId,
|
|
553
|
+
RequestingSocket, LandscapePath,
|
|
554
|
+
LandscapeName, LayerName, MinX, MinY,
|
|
555
|
+
MaxX, MaxY, Strength]() {
|
|
556
|
+
UMcpAutomationBridgeSubsystem *Subsystem = WeakSubsystem.Get();
|
|
557
|
+
if (!Subsystem)
|
|
558
|
+
return;
|
|
559
|
+
|
|
560
|
+
ALandscape *Landscape = nullptr;
|
|
561
|
+
if (!LandscapePath.IsEmpty()) {
|
|
562
|
+
Landscape = Cast<ALandscape>(
|
|
563
|
+
StaticLoadObject(ALandscape::StaticClass(), nullptr, *LandscapePath));
|
|
564
|
+
}
|
|
565
|
+
if (!Landscape && !LandscapeName.IsEmpty()) {
|
|
566
|
+
if (UEditorActorSubsystem *ActorSS =
|
|
567
|
+
GEditor->GetEditorSubsystem<UEditorActorSubsystem>()) {
|
|
568
|
+
TArray<AActor *> AllActors = ActorSS->GetAllLevelActors();
|
|
569
|
+
for (AActor *A : AllActors) {
|
|
570
|
+
if (A && A->IsA<ALandscape>() &&
|
|
571
|
+
A->GetActorLabel().Equals(LandscapeName,
|
|
572
|
+
ESearchCase::IgnoreCase)) {
|
|
573
|
+
Landscape = Cast<ALandscape>(A);
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
if (!Landscape) {
|
|
580
|
+
Subsystem->SendAutomationError(RequestingSocket, RequestId,
|
|
581
|
+
TEXT("Failed to find landscape"),
|
|
582
|
+
TEXT("LOAD_FAILED"));
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
ULandscapeInfo *LandscapeInfo = Landscape->GetLandscapeInfo();
|
|
587
|
+
if (!LandscapeInfo) {
|
|
588
|
+
Subsystem->SendAutomationError(RequestingSocket, RequestId,
|
|
589
|
+
TEXT("Landscape has no info"),
|
|
590
|
+
TEXT("INVALID_LANDSCAPE"));
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
ULandscapeLayerInfoObject *LayerInfo = nullptr;
|
|
595
|
+
for (const FLandscapeInfoLayerSettings &Layer : LandscapeInfo->Layers) {
|
|
596
|
+
if (Layer.LayerName == FName(*LayerName)) {
|
|
597
|
+
LayerInfo = Layer.LayerInfoObj;
|
|
598
|
+
break;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
if (!LayerInfo) {
|
|
603
|
+
Subsystem->SendAutomationError(
|
|
604
|
+
RequestingSocket, RequestId,
|
|
605
|
+
FString::Printf(TEXT("Layer '%s' not found. Create layer first using "
|
|
606
|
+
"landscape editor."),
|
|
607
|
+
*LayerName),
|
|
608
|
+
TEXT("LAYER_NOT_FOUND"));
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
FScopedSlowTask SlowTask(
|
|
613
|
+
1.0f, FText::FromString(TEXT("Painting landscape layer...")));
|
|
614
|
+
SlowTask.MakeDialog();
|
|
615
|
+
|
|
616
|
+
int32 PaintMinX = MinX;
|
|
617
|
+
int32 PaintMinY = MinY;
|
|
618
|
+
int32 PaintMaxX = MaxX;
|
|
619
|
+
int32 PaintMaxY = MaxY;
|
|
620
|
+
if (PaintMinX < 0 || PaintMaxX < 0) {
|
|
621
|
+
LandscapeInfo->GetLandscapeExtent(PaintMinX, PaintMinY, PaintMaxX,
|
|
622
|
+
PaintMaxY);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
FLandscapeEditDataInterface LandscapeEdit(LandscapeInfo);
|
|
626
|
+
const uint8 PaintValue = static_cast<uint8>(Strength * 255.0);
|
|
627
|
+
const int32 RegionSizeX = (PaintMaxX - PaintMinX + 1);
|
|
628
|
+
const int32 RegionSizeY = (PaintMaxY - PaintMinY + 1);
|
|
629
|
+
|
|
630
|
+
TArray<uint8> AlphaData;
|
|
631
|
+
AlphaData.Init(PaintValue, RegionSizeX * RegionSizeY);
|
|
632
|
+
|
|
633
|
+
LandscapeEdit.SetAlphaData(LayerInfo, PaintMinX, PaintMinY, PaintMaxX,
|
|
634
|
+
PaintMaxY, AlphaData.GetData(), RegionSizeX);
|
|
635
|
+
LandscapeEdit.Flush();
|
|
636
|
+
Landscape->PostEditChange();
|
|
637
|
+
|
|
638
|
+
TSharedPtr<FJsonObject> Resp = MakeShared<FJsonObject>();
|
|
639
|
+
Resp->SetBoolField(TEXT("success"), true);
|
|
640
|
+
Resp->SetStringField(TEXT("landscapePath"), LandscapePath);
|
|
641
|
+
Resp->SetStringField(TEXT("layerName"), LayerName);
|
|
642
|
+
Resp->SetNumberField(TEXT("strength"), Strength);
|
|
643
|
+
|
|
644
|
+
Subsystem->SendAutomationResponse(RequestingSocket, RequestId, true,
|
|
645
|
+
TEXT("Layer painted successfully"), Resp,
|
|
646
|
+
FString());
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
return true;
|
|
650
|
+
#else
|
|
651
|
+
SendAutomationResponse(RequestingSocket, RequestId, false,
|
|
652
|
+
TEXT("paint_landscape_layer requires editor build."),
|
|
653
|
+
nullptr, TEXT("NOT_IMPLEMENTED"));
|
|
654
|
+
return true;
|
|
655
|
+
#endif
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
bool UMcpAutomationBridgeSubsystem::HandleSculptLandscape(
|
|
659
|
+
const FString &RequestId, const FString &Action,
|
|
660
|
+
const TSharedPtr<FJsonObject> &Payload,
|
|
661
|
+
TSharedPtr<FMcpBridgeWebSocket> RequestingSocket) {
|
|
662
|
+
const FString Lower = Action.ToLower();
|
|
663
|
+
if (!Lower.Equals(TEXT("sculpt_landscape"), ESearchCase::IgnoreCase)) {
|
|
664
|
+
return false;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
#if WITH_EDITOR
|
|
668
|
+
if (!Payload.IsValid()) {
|
|
669
|
+
SendAutomationError(RequestingSocket, RequestId,
|
|
670
|
+
TEXT("sculpt_landscape payload missing"),
|
|
671
|
+
TEXT("INVALID_PAYLOAD"));
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
FString LandscapePath;
|
|
676
|
+
Payload->TryGetStringField(TEXT("landscapePath"), LandscapePath);
|
|
677
|
+
FString LandscapeName;
|
|
678
|
+
Payload->TryGetStringField(TEXT("landscapeName"), LandscapeName);
|
|
679
|
+
|
|
680
|
+
UE_LOG(LogMcpAutomationBridgeSubsystem, Warning,
|
|
681
|
+
TEXT("HandleSculptLandscape: RequestId=%s Path='%s' Name='%s'"),
|
|
682
|
+
*RequestId, *LandscapePath, *LandscapeName);
|
|
683
|
+
|
|
684
|
+
double LocX = 0, LocY = 0, LocZ = 0;
|
|
685
|
+
const TSharedPtr<FJsonObject> *LocObj = nullptr;
|
|
686
|
+
// Accept both 'location' and 'position' parameter names for consistency
|
|
687
|
+
if (Payload->TryGetObjectField(TEXT("location"), LocObj) && LocObj) {
|
|
688
|
+
(*LocObj)->TryGetNumberField(TEXT("x"), LocX);
|
|
689
|
+
(*LocObj)->TryGetNumberField(TEXT("y"), LocY);
|
|
690
|
+
(*LocObj)->TryGetNumberField(TEXT("z"), LocZ);
|
|
691
|
+
} else if (Payload->TryGetObjectField(TEXT("position"), LocObj) && LocObj) {
|
|
692
|
+
(*LocObj)->TryGetNumberField(TEXT("x"), LocX);
|
|
693
|
+
(*LocObj)->TryGetNumberField(TEXT("y"), LocY);
|
|
694
|
+
(*LocObj)->TryGetNumberField(TEXT("z"), LocZ);
|
|
695
|
+
} else {
|
|
696
|
+
SendAutomationError(
|
|
697
|
+
RequestingSocket, RequestId,
|
|
698
|
+
TEXT("location or position required. Example: {\"location\": {\"x\": "
|
|
699
|
+
"0, \"y\": 0, \"z\": 100}}"),
|
|
700
|
+
TEXT("INVALID_ARGUMENT"));
|
|
701
|
+
return true;
|
|
702
|
+
}
|
|
703
|
+
FVector TargetLocation(LocX, LocY, LocZ);
|
|
704
|
+
|
|
705
|
+
FString ToolMode = TEXT("Raise");
|
|
706
|
+
Payload->TryGetStringField(TEXT("toolMode"), ToolMode);
|
|
707
|
+
|
|
708
|
+
double BrushRadius = 1000.0;
|
|
709
|
+
Payload->TryGetNumberField(TEXT("brushRadius"), BrushRadius);
|
|
710
|
+
|
|
711
|
+
double BrushFalloff = 0.5;
|
|
712
|
+
Payload->TryGetNumberField(TEXT("brushFalloff"), BrushFalloff);
|
|
713
|
+
|
|
714
|
+
double Strength = 0.1;
|
|
715
|
+
Payload->TryGetNumberField(TEXT("strength"), Strength);
|
|
716
|
+
|
|
717
|
+
TWeakObjectPtr<UMcpAutomationBridgeSubsystem> WeakSubsystem(this);
|
|
718
|
+
|
|
719
|
+
AsyncTask(ENamedThreads::GameThread, [WeakSubsystem, RequestId,
|
|
720
|
+
RequestingSocket, LandscapePath,
|
|
721
|
+
LandscapeName, TargetLocation, ToolMode,
|
|
722
|
+
BrushRadius, BrushFalloff, Strength]() {
|
|
723
|
+
UMcpAutomationBridgeSubsystem *Subsystem = WeakSubsystem.Get();
|
|
724
|
+
if (!Subsystem)
|
|
725
|
+
return;
|
|
726
|
+
|
|
727
|
+
ALandscape *Landscape = nullptr;
|
|
728
|
+
if (!LandscapePath.IsEmpty()) {
|
|
729
|
+
Landscape = Cast<ALandscape>(
|
|
730
|
+
StaticLoadObject(ALandscape::StaticClass(), nullptr, *LandscapePath));
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
if (!Landscape && GEditor) {
|
|
734
|
+
if (UEditorActorSubsystem *ActorSS =
|
|
735
|
+
GEditor->GetEditorSubsystem<UEditorActorSubsystem>()) {
|
|
736
|
+
TArray<AActor *> AllActors = ActorSS->GetAllLevelActors();
|
|
737
|
+
ALandscape *Fallback = nullptr;
|
|
738
|
+
int32 LandscapeCount = 0;
|
|
739
|
+
|
|
740
|
+
for (AActor *A : AllActors) {
|
|
741
|
+
if (ALandscape *L = Cast<ALandscape>(A)) {
|
|
742
|
+
LandscapeCount++;
|
|
743
|
+
Fallback = L;
|
|
744
|
+
|
|
745
|
+
if (!LandscapeName.IsEmpty() &&
|
|
746
|
+
L->GetActorLabel().Equals(LandscapeName,
|
|
747
|
+
ESearchCase::IgnoreCase)) {
|
|
748
|
+
Landscape = L;
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
if (!Landscape && LandscapeCount == 1) {
|
|
755
|
+
Landscape = Fallback;
|
|
756
|
+
UE_LOG(LogMcpAutomationBridgeSubsystem, Warning,
|
|
757
|
+
TEXT("HandleSculptLandscape: Exact match for '%s' not found, "
|
|
758
|
+
"using single available Landscape: '%s'"),
|
|
759
|
+
*LandscapeName, *Landscape->GetActorLabel());
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
if (!Landscape) {
|
|
764
|
+
Subsystem->SendAutomationError(RequestingSocket, RequestId,
|
|
765
|
+
TEXT("Failed to find landscape"),
|
|
766
|
+
TEXT("LOAD_FAILED"));
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
ULandscapeInfo *LandscapeInfo = Landscape->GetLandscapeInfo();
|
|
771
|
+
if (!LandscapeInfo) {
|
|
772
|
+
Subsystem->SendAutomationError(RequestingSocket, RequestId,
|
|
773
|
+
TEXT("Landscape has no info"),
|
|
774
|
+
TEXT("INVALID_LANDSCAPE"));
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// Convert World Location to Landscape Local Space
|
|
779
|
+
FVector LocalPos =
|
|
780
|
+
Landscape->GetActorTransform().InverseTransformPosition(TargetLocation);
|
|
781
|
+
int32 CenterX = FMath::RoundToInt(LocalPos.X);
|
|
782
|
+
int32 CenterY = FMath::RoundToInt(LocalPos.Y);
|
|
783
|
+
|
|
784
|
+
// Convert Brush Radius to Vertex Units (assuming uniform scale for
|
|
785
|
+
// simplicity, or use X)
|
|
786
|
+
float ScaleX = Landscape->GetActorScale3D().X;
|
|
787
|
+
int32 RadiusVerts = FMath::Max(1, FMath::RoundToInt(BrushRadius / ScaleX));
|
|
788
|
+
int32 FalloffVerts = FMath::RoundToInt(RadiusVerts * BrushFalloff);
|
|
789
|
+
|
|
790
|
+
int32 MinX = CenterX - RadiusVerts;
|
|
791
|
+
int32 MaxX = CenterX + RadiusVerts;
|
|
792
|
+
int32 MinY = CenterY - RadiusVerts;
|
|
793
|
+
int32 MaxY = CenterY + RadiusVerts;
|
|
794
|
+
|
|
795
|
+
// Clamp to landscape extents
|
|
796
|
+
int32 LMinX, LMinY, LMaxX, LMaxY;
|
|
797
|
+
if (LandscapeInfo->GetLandscapeExtent(LMinX, LMinY, LMaxX, LMaxY)) {
|
|
798
|
+
MinX = FMath::Max(MinX, LMinX);
|
|
799
|
+
MinY = FMath::Max(MinY, LMinY);
|
|
800
|
+
MaxX = FMath::Min(MaxX, LMaxX);
|
|
801
|
+
MaxY = FMath::Min(MaxY, LMaxY);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
if (MinX > MaxX || MinY > MaxY) {
|
|
805
|
+
Subsystem->SendAutomationResponse(RequestingSocket, RequestId, false,
|
|
806
|
+
TEXT("Brush outside landscape bounds"),
|
|
807
|
+
nullptr, TEXT("OUT_OF_BOUNDS"));
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
int32 SizeX = MaxX - MinX + 1;
|
|
812
|
+
int32 SizeY = MaxY - MinY + 1;
|
|
813
|
+
TArray<uint16> HeightData;
|
|
814
|
+
HeightData.SetNumZeroed(SizeX * SizeY);
|
|
815
|
+
|
|
816
|
+
FLandscapeEditDataInterface LandscapeEdit(LandscapeInfo);
|
|
817
|
+
LandscapeEdit.GetHeightData(MinX, MinY, MaxX, MaxY, HeightData.GetData(),
|
|
818
|
+
0);
|
|
819
|
+
|
|
820
|
+
bool bModified = false;
|
|
821
|
+
for (int32 Y = MinY; Y <= MaxY; ++Y) {
|
|
822
|
+
for (int32 X = MinX; X <= MaxX; ++X) {
|
|
823
|
+
float Dist = FMath::Sqrt(FMath::Square((float)(X - CenterX)) +
|
|
824
|
+
FMath::Square((float)(Y - CenterY)));
|
|
825
|
+
if (Dist > RadiusVerts)
|
|
826
|
+
continue;
|
|
827
|
+
|
|
828
|
+
float Alpha = 1.0f;
|
|
829
|
+
if (Dist > (RadiusVerts - FalloffVerts)) {
|
|
830
|
+
Alpha = 1.0f -
|
|
831
|
+
((Dist - (RadiusVerts - FalloffVerts)) / (float)FalloffVerts);
|
|
832
|
+
}
|
|
833
|
+
Alpha = FMath::Clamp(Alpha, 0.0f, 1.0f);
|
|
834
|
+
|
|
835
|
+
int32 Index = (Y - MinY) * SizeX + (X - MinX);
|
|
836
|
+
if (Index < 0 || Index >= HeightData.Num())
|
|
837
|
+
continue;
|
|
838
|
+
|
|
839
|
+
uint16 CurrentHeight = HeightData[Index];
|
|
840
|
+
|
|
841
|
+
float ScaleZ = Landscape->GetActorScale3D().Z;
|
|
842
|
+
float HeightScale =
|
|
843
|
+
128.0f / ScaleZ; // Conversion factor from World Z to uint16
|
|
844
|
+
|
|
845
|
+
float Delta = 0.0f;
|
|
846
|
+
if (ToolMode.Equals(TEXT("Raise"), ESearchCase::IgnoreCase)) {
|
|
847
|
+
Delta = Strength * Alpha * 100.0f *
|
|
848
|
+
HeightScale; // Arbitrary strength multiplier
|
|
849
|
+
} else if (ToolMode.Equals(TEXT("Lower"), ESearchCase::IgnoreCase)) {
|
|
850
|
+
Delta = -Strength * Alpha * 100.0f * HeightScale;
|
|
851
|
+
} else if (ToolMode.Equals(TEXT("Flatten"), ESearchCase::IgnoreCase)) {
|
|
852
|
+
float CurrentVal = (float)CurrentHeight;
|
|
853
|
+
float Target = (TargetLocation.Z - Landscape->GetActorLocation().Z) /
|
|
854
|
+
ScaleZ * 128.0f +
|
|
855
|
+
32768.0f;
|
|
856
|
+
Delta = (Target - CurrentVal) * Strength * Alpha;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
int32 NewHeight =
|
|
860
|
+
FMath::Clamp((int32)(CurrentHeight + Delta), 0, 65535);
|
|
861
|
+
if (NewHeight != CurrentHeight) {
|
|
862
|
+
HeightData[Index] = (uint16)NewHeight;
|
|
863
|
+
bModified = true;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
if (bModified) {
|
|
869
|
+
LandscapeEdit.SetHeightData(MinX, MinY, MaxX, MaxY, HeightData.GetData(),
|
|
870
|
+
0, true);
|
|
871
|
+
LandscapeEdit.Flush();
|
|
872
|
+
Landscape->PostEditChange();
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
TSharedPtr<FJsonObject> Resp = MakeShared<FJsonObject>();
|
|
876
|
+
Resp->SetBoolField(TEXT("success"), true);
|
|
877
|
+
Resp->SetStringField(TEXT("toolMode"), ToolMode);
|
|
878
|
+
Resp->SetNumberField(TEXT("modifiedVertices"),
|
|
879
|
+
bModified ? HeightData.Num() : 0);
|
|
880
|
+
|
|
881
|
+
Subsystem->SendAutomationResponse(RequestingSocket, RequestId, true,
|
|
882
|
+
TEXT("Landscape sculpted"), Resp,
|
|
883
|
+
FString());
|
|
884
|
+
});
|
|
885
|
+
|
|
886
|
+
return true;
|
|
887
|
+
#else
|
|
888
|
+
SendAutomationResponse(RequestingSocket, RequestId, false,
|
|
889
|
+
TEXT("sculpt_landscape requires editor build."),
|
|
890
|
+
nullptr, TEXT("NOT_IMPLEMENTED"));
|
|
891
|
+
return true;
|
|
892
|
+
#endif
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
bool UMcpAutomationBridgeSubsystem::HandleSetLandscapeMaterial(
|
|
896
|
+
const FString &RequestId, const FString &Action,
|
|
897
|
+
const TSharedPtr<FJsonObject> &Payload,
|
|
898
|
+
TSharedPtr<FMcpBridgeWebSocket> RequestingSocket) {
|
|
899
|
+
const FString Lower = Action.ToLower();
|
|
900
|
+
if (!Lower.Equals(TEXT("set_landscape_material"), ESearchCase::IgnoreCase)) {
|
|
901
|
+
return false;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
#if WITH_EDITOR
|
|
905
|
+
if (!Payload.IsValid()) {
|
|
906
|
+
SendAutomationError(RequestingSocket, RequestId,
|
|
907
|
+
TEXT("set_landscape_material payload missing"),
|
|
908
|
+
TEXT("INVALID_PAYLOAD"));
|
|
909
|
+
return true;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
FString LandscapePath;
|
|
913
|
+
Payload->TryGetStringField(TEXT("landscapePath"), LandscapePath);
|
|
914
|
+
FString LandscapeName;
|
|
915
|
+
Payload->TryGetStringField(TEXT("landscapeName"), LandscapeName);
|
|
916
|
+
FString MaterialPath;
|
|
917
|
+
if (!Payload->TryGetStringField(TEXT("materialPath"), MaterialPath) ||
|
|
918
|
+
MaterialPath.IsEmpty()) {
|
|
919
|
+
SendAutomationError(RequestingSocket, RequestId,
|
|
920
|
+
TEXT("materialPath required"),
|
|
921
|
+
TEXT("INVALID_ARGUMENT"));
|
|
922
|
+
return true;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
TWeakObjectPtr<UMcpAutomationBridgeSubsystem> WeakSubsystem(this);
|
|
926
|
+
|
|
927
|
+
AsyncTask(ENamedThreads::GameThread, [WeakSubsystem, RequestId,
|
|
928
|
+
RequestingSocket, LandscapePath,
|
|
929
|
+
LandscapeName, MaterialPath]() {
|
|
930
|
+
UMcpAutomationBridgeSubsystem *Subsystem = WeakSubsystem.Get();
|
|
931
|
+
if (!Subsystem)
|
|
932
|
+
return;
|
|
933
|
+
|
|
934
|
+
ALandscape *Landscape = nullptr;
|
|
935
|
+
if (!LandscapePath.IsEmpty()) {
|
|
936
|
+
Landscape = Cast<ALandscape>(
|
|
937
|
+
StaticLoadObject(ALandscape::StaticClass(), nullptr, *LandscapePath));
|
|
938
|
+
}
|
|
939
|
+
if (!Landscape && !LandscapeName.IsEmpty()) {
|
|
940
|
+
if (UEditorActorSubsystem *ActorSS =
|
|
941
|
+
GEditor->GetEditorSubsystem<UEditorActorSubsystem>()) {
|
|
942
|
+
TArray<AActor *> AllActors = ActorSS->GetAllLevelActors();
|
|
943
|
+
for (AActor *A : AllActors) {
|
|
944
|
+
if (A && A->IsA<ALandscape>() &&
|
|
945
|
+
A->GetActorLabel().Equals(LandscapeName,
|
|
946
|
+
ESearchCase::IgnoreCase)) {
|
|
947
|
+
Landscape = Cast<ALandscape>(A);
|
|
948
|
+
break;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
// Fallback: If no path/name provided (or name not found but let's be
|
|
955
|
+
// generous if no path was given), find first available landscape
|
|
956
|
+
if (!Landscape && LandscapePath.IsEmpty() && LandscapeName.IsEmpty()) {
|
|
957
|
+
if (UEditorActorSubsystem *ActorSS =
|
|
958
|
+
GEditor->GetEditorSubsystem<UEditorActorSubsystem>()) {
|
|
959
|
+
TArray<AActor *> AllActors = ActorSS->GetAllLevelActors();
|
|
960
|
+
for (AActor *A : AllActors) {
|
|
961
|
+
if (ALandscape *L = Cast<ALandscape>(A)) {
|
|
962
|
+
Landscape = L;
|
|
963
|
+
break;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
if (!Landscape) {
|
|
969
|
+
Subsystem->SendAutomationError(
|
|
970
|
+
RequestingSocket, RequestId,
|
|
971
|
+
TEXT("Failed to find landscape and no name provided"),
|
|
972
|
+
TEXT("LOAD_FAILED"));
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
// Use Silent load to avoid engine warnings if path is invalid or type
|
|
977
|
+
// mismatch
|
|
978
|
+
UMaterialInterface *Mat = Cast<UMaterialInterface>(
|
|
979
|
+
StaticLoadObject(UMaterialInterface::StaticClass(), nullptr,
|
|
980
|
+
*MaterialPath, nullptr, LOAD_NoWarn));
|
|
981
|
+
|
|
982
|
+
if (!Mat) {
|
|
983
|
+
// Check existence separately only if load failed, to distinguish error
|
|
984
|
+
// type (optional)
|
|
985
|
+
if (!UEditorAssetLibrary::DoesAssetExist(MaterialPath)) {
|
|
986
|
+
Subsystem->SendAutomationError(
|
|
987
|
+
RequestingSocket, RequestId,
|
|
988
|
+
FString::Printf(TEXT("Material asset not found: %s"),
|
|
989
|
+
*MaterialPath),
|
|
990
|
+
TEXT("ASSET_NOT_FOUND"));
|
|
991
|
+
} else {
|
|
992
|
+
Subsystem->SendAutomationError(
|
|
993
|
+
RequestingSocket, RequestId,
|
|
994
|
+
TEXT("Failed to load material (invalid type?)"),
|
|
995
|
+
TEXT("LOAD_FAILED"));
|
|
996
|
+
}
|
|
997
|
+
return;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
Landscape->LandscapeMaterial = Mat;
|
|
1001
|
+
Landscape->PostEditChange();
|
|
1002
|
+
|
|
1003
|
+
TSharedPtr<FJsonObject> Resp = MakeShared<FJsonObject>();
|
|
1004
|
+
Resp->SetBoolField(TEXT("success"), true);
|
|
1005
|
+
Resp->SetStringField(TEXT("landscapePath"), Landscape->GetPathName());
|
|
1006
|
+
Resp->SetStringField(TEXT("materialPath"), MaterialPath);
|
|
1007
|
+
|
|
1008
|
+
Subsystem->SendAutomationResponse(RequestingSocket, RequestId, true,
|
|
1009
|
+
TEXT("Landscape material set"), Resp,
|
|
1010
|
+
FString());
|
|
1011
|
+
});
|
|
1012
|
+
|
|
1013
|
+
return true;
|
|
1014
|
+
#else
|
|
1015
|
+
SendAutomationResponse(RequestingSocket, RequestId, false,
|
|
1016
|
+
TEXT("set_landscape_material requires editor build."),
|
|
1017
|
+
nullptr, TEXT("NOT_IMPLEMENTED"));
|
|
1018
|
+
return true;
|
|
1019
|
+
#endif
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
bool UMcpAutomationBridgeSubsystem::HandleCreateLandscapeGrassType(
|
|
1023
|
+
const FString &RequestId, const FString &Action,
|
|
1024
|
+
const TSharedPtr<FJsonObject> &Payload,
|
|
1025
|
+
TSharedPtr<FMcpBridgeWebSocket> RequestingSocket) {
|
|
1026
|
+
const FString Lower = Action.ToLower();
|
|
1027
|
+
if (!Lower.Equals(TEXT("create_landscape_grass_type"),
|
|
1028
|
+
ESearchCase::IgnoreCase)) {
|
|
1029
|
+
return false;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
#if WITH_EDITOR
|
|
1033
|
+
if (!Payload.IsValid()) {
|
|
1034
|
+
SendAutomationError(RequestingSocket, RequestId,
|
|
1035
|
+
TEXT("create_landscape_grass_type payload missing"),
|
|
1036
|
+
TEXT("INVALID_PAYLOAD"));
|
|
1037
|
+
return true;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
FString Name;
|
|
1041
|
+
if (!Payload->TryGetStringField(TEXT("name"), Name) || Name.IsEmpty()) {
|
|
1042
|
+
SendAutomationError(RequestingSocket, RequestId, TEXT("name required"),
|
|
1043
|
+
TEXT("INVALID_ARGUMENT"));
|
|
1044
|
+
return true;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
FString MeshPath;
|
|
1048
|
+
if (!Payload->TryGetStringField(TEXT("meshPath"), MeshPath) ||
|
|
1049
|
+
MeshPath.IsEmpty()) {
|
|
1050
|
+
SendAutomationError(RequestingSocket, RequestId, TEXT("meshPath required"),
|
|
1051
|
+
TEXT("INVALID_ARGUMENT"));
|
|
1052
|
+
return true;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
double Density = 1.0;
|
|
1056
|
+
Payload->TryGetNumberField(TEXT("density"), Density);
|
|
1057
|
+
|
|
1058
|
+
double MinScale = 0.8;
|
|
1059
|
+
Payload->TryGetNumberField(TEXT("minScale"), MinScale);
|
|
1060
|
+
|
|
1061
|
+
double MaxScale = 1.2;
|
|
1062
|
+
Payload->TryGetNumberField(TEXT("maxScale"), MaxScale);
|
|
1063
|
+
|
|
1064
|
+
TWeakObjectPtr<UMcpAutomationBridgeSubsystem> WeakSubsystem(this);
|
|
1065
|
+
|
|
1066
|
+
AsyncTask(ENamedThreads::GameThread, [WeakSubsystem, RequestId,
|
|
1067
|
+
RequestingSocket, Name, MeshPath,
|
|
1068
|
+
Density, MinScale, MaxScale]() {
|
|
1069
|
+
UMcpAutomationBridgeSubsystem *Subsystem = WeakSubsystem.Get();
|
|
1070
|
+
if (!Subsystem)
|
|
1071
|
+
return;
|
|
1072
|
+
|
|
1073
|
+
// Use Silent load to avoid engine warnings
|
|
1074
|
+
UStaticMesh *StaticMesh = Cast<UStaticMesh>(StaticLoadObject(
|
|
1075
|
+
UStaticMesh::StaticClass(), nullptr, *MeshPath, nullptr, LOAD_NoWarn));
|
|
1076
|
+
if (!StaticMesh) {
|
|
1077
|
+
Subsystem->SendAutomationError(
|
|
1078
|
+
RequestingSocket, RequestId,
|
|
1079
|
+
FString::Printf(TEXT("Static mesh not found: %s"), *MeshPath),
|
|
1080
|
+
TEXT("ASSET_NOT_FOUND"));
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
FString PackagePath = TEXT("/Game/Landscape");
|
|
1085
|
+
FString AssetName = Name;
|
|
1086
|
+
FString FullPackagePath =
|
|
1087
|
+
FString::Printf(TEXT("%s/%s"), *PackagePath, *AssetName);
|
|
1088
|
+
|
|
1089
|
+
// Check if already exists
|
|
1090
|
+
if (UObject *ExistingAsset = StaticLoadObject(
|
|
1091
|
+
ULandscapeGrassType::StaticClass(), nullptr, *FullPackagePath)) {
|
|
1092
|
+
TSharedPtr<FJsonObject> Resp = MakeShared<FJsonObject>();
|
|
1093
|
+
Resp->SetBoolField(TEXT("success"), true);
|
|
1094
|
+
Resp->SetStringField(TEXT("asset_path"), ExistingAsset->GetPathName());
|
|
1095
|
+
Resp->SetStringField(TEXT("message"), TEXT("Asset already exists"));
|
|
1096
|
+
Subsystem->SendAutomationResponse(
|
|
1097
|
+
RequestingSocket, RequestId, true,
|
|
1098
|
+
TEXT("Landscape grass type already exists"), Resp, FString());
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
UPackage *Package = CreatePackage(*FullPackagePath);
|
|
1103
|
+
ULandscapeGrassType *GrassType = NewObject<ULandscapeGrassType>(
|
|
1104
|
+
Package, FName(*AssetName), RF_Public | RF_Standalone);
|
|
1105
|
+
if (!GrassType) {
|
|
1106
|
+
Subsystem->SendAutomationError(RequestingSocket, RequestId,
|
|
1107
|
+
TEXT("Failed to create grass type asset"),
|
|
1108
|
+
TEXT("CREATION_FAILED"));
|
|
1109
|
+
return;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
FGrassVariety Variety;
|
|
1113
|
+
Variety.GrassMesh = StaticMesh;
|
|
1114
|
+
Variety.GrassDensity.Default = static_cast<float>(Density);
|
|
1115
|
+
|
|
1116
|
+
Variety.ScaleX = FFloatInterval(static_cast<float>(MinScale),
|
|
1117
|
+
static_cast<float>(MaxScale));
|
|
1118
|
+
Variety.ScaleY = FFloatInterval(static_cast<float>(MinScale),
|
|
1119
|
+
static_cast<float>(MaxScale));
|
|
1120
|
+
Variety.ScaleZ = FFloatInterval(static_cast<float>(MinScale),
|
|
1121
|
+
static_cast<float>(MaxScale));
|
|
1122
|
+
|
|
1123
|
+
Variety.RandomRotation = true;
|
|
1124
|
+
Variety.AlignToSurface = true;
|
|
1125
|
+
|
|
1126
|
+
GrassType->GrassVarieties.Add(Variety);
|
|
1127
|
+
|
|
1128
|
+
Package->MarkPackageDirty();
|
|
1129
|
+
FAssetRegistryModule::AssetCreated(GrassType);
|
|
1130
|
+
|
|
1131
|
+
FString PackageFileName = FPackageName::LongPackageNameToFilename(
|
|
1132
|
+
FullPackagePath, FPackageName::GetAssetPackageExtension());
|
|
1133
|
+
FSavePackageArgs SaveArgs;
|
|
1134
|
+
SaveArgs.TopLevelFlags = RF_Public | RF_Standalone;
|
|
1135
|
+
SaveArgs.Error = GError;
|
|
1136
|
+
SaveArgs.SaveFlags = SAVE_NoError;
|
|
1137
|
+
bool bSaved =
|
|
1138
|
+
UPackage::SavePackage(Package, GrassType, *PackageFileName, SaveArgs);
|
|
1139
|
+
|
|
1140
|
+
if (!bSaved) {
|
|
1141
|
+
Subsystem->SendAutomationError(RequestingSocket, RequestId,
|
|
1142
|
+
TEXT("Failed to save grass type asset"),
|
|
1143
|
+
TEXT("SAVE_FAILED"));
|
|
1144
|
+
return;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
TSharedPtr<FJsonObject> Resp = MakeShared<FJsonObject>();
|
|
1148
|
+
Resp->SetBoolField(TEXT("success"), true);
|
|
1149
|
+
Resp->SetStringField(TEXT("asset_path"), GrassType->GetPathName());
|
|
1150
|
+
|
|
1151
|
+
Subsystem->SendAutomationResponse(RequestingSocket, RequestId, true,
|
|
1152
|
+
TEXT("Landscape grass type created"),
|
|
1153
|
+
Resp, FString());
|
|
1154
|
+
});
|
|
1155
|
+
|
|
1156
|
+
return true;
|
|
1157
|
+
#else
|
|
1158
|
+
SendAutomationResponse(
|
|
1159
|
+
RequestingSocket, RequestId, false,
|
|
1160
|
+
TEXT("create_landscape_grass_type requires editor build."), nullptr,
|
|
1161
|
+
TEXT("NOT_IMPLEMENTED"));
|
|
1162
|
+
return true;
|
|
1163
|
+
#endif
|
|
1164
|
+
}
|