unity2moveit2/scripts/migrate-project-assets.ps1
ayuan9957 fe15edcbd5 Initial commit: Unity-MoveIt2 integrated robotic arm simulation system
- Unity frontend with ROS-TCP-Connector for ROS2 communication
- Docker-based ROS2 Jazzy backend with MoveIt2 integration
- Support for 1-9 DOF manipulators
- UR5 robot configuration and URDF files
- Assembly task feasibility analysis tools
- Comprehensive documentation and deployment guides

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-13 12:08:34 +08:00

210 lines
7.7 KiB
PowerShell

# Migrate Project Assets from Old to New Unity Project
# 从旧Unity项目迁移资源到新项目
param(
[string]$SourceProject = "D:\ros2\DockerRos2Arm-niryo_arm\PickAndPlaceProject",
[string]$TargetProject = "D:\ros2\DockerRos2Arm-niryo_arm\Unity_MoveIt2\NewUnityProject\ROS2_Niryo_Control",
[switch]$MigrateScripts,
[switch]$MigrateURDF,
[switch]$MigratePrefabs,
[switch]$MigrateScenes,
[switch]$MigrateAll
)
Write-Host "=== Migrating Project Assets ===" -ForegroundColor Green
# Check if source project exists
if (-not (Test-Path $SourceProject)) {
Write-Host "Error: Source project not found at $SourceProject" -ForegroundColor Red
exit 1
}
# Check if target project exists
if (-not (Test-Path $TargetProject)) {
Write-Host "Error: Target project not found at $TargetProject" -ForegroundColor Red
exit 1
}
# Function to copy directory with overwrite
function Copy-DirectoryWithOverwrite {
param(
[string]$Source,
[string]$Destination,
[string]$Description
)
if (Test-Path $Source) {
Write-Host "Copying $Description..." -ForegroundColor Yellow
# Create destination directory if it doesn't exist
$destDir = Split-Path $Destination -Parent
if (-not (Test-Path $destDir)) {
New-Item -ItemType Directory -Path $destDir -Force | Out-Null
}
# Copy with overwrite
Copy-Item -Path $Source -Destination $Destination -Recurse -Force
Write-Host "$Description copied successfully" -ForegroundColor Green
} else {
Write-Host "$Description not found at $Source" -ForegroundColor Yellow
}
}
# Function to copy individual files
function Copy-FileWithOverwrite {
param(
[string]$Source,
[string]$Destination,
[string]$Description
)
if (Test-Path $Source) {
Write-Host "Copying $Description..." -ForegroundColor Yellow
# Create destination directory if it doesn't exist
$destDir = Split-Path $Destination -Parent
if (-not (Test-Path $destDir)) {
New-Item -ItemType Directory -Path $destDir -Force | Out-Null
}
Copy-Item -Path $Source -Destination $Destination -Force
Write-Host "$Description copied successfully" -ForegroundColor Green
} else {
Write-Host "$Description not found at $Source" -ForegroundColor Yellow
}
}
# Migrate Scripts
if ($MigrateScripts -or $MigrateAll) {
Write-Host "`n--- Migrating Scripts ---" -ForegroundColor Cyan
# Copy main scripts
$scriptsToMigrate = @(
"TrajectoryPlanner.cs",
"TargetPlacement.cs",
"SourceDestinationPublisher.cs",
"TestData.cs"
)
foreach ($script in $scriptsToMigrate) {
$sourcePath = Join-Path $SourceProject "Assets\Scripts\$script"
$targetPath = Join-Path $TargetProject "Assets\Scripts\Robot\$script"
Copy-FileWithOverwrite -Source $sourcePath -Destination $targetPath -Description "Script: $script"
}
# Copy ROS2Demo scripts
$ros2DemoSource = Join-Path $SourceProject "Assets\Scripts\ROS2Demo"
$ros2DemoTarget = Join-Path $TargetProject "Assets\Scripts\ROS\Demo"
Copy-DirectoryWithOverwrite -Source $ros2DemoSource -Destination $ros2DemoTarget -Description "ROS2 Demo Scripts"
}
# Migrate URDF files
if ($MigrateURDF -or $MigrateAll) {
Write-Host "`n--- Migrating URDF Files ---" -ForegroundColor Cyan
$urdfSource = Join-Path $SourceProject "Assets\URDF\niryo_one"
$urdfTarget = Join-Path $TargetProject "Assets\URDF\niryo_one"
Copy-DirectoryWithOverwrite -Source $urdfSource -Destination $urdfTarget -Description "Niryo One URDF Files"
}
# Migrate Prefabs
if ($MigratePrefabs -or $MigrateAll) {
Write-Host "`n--- Migrating Prefabs ---" -ForegroundColor Cyan
$prefabsSource = Join-Path $SourceProject "Assets\Prefabs"
$prefabsTarget = Join-Path $TargetProject "Assets\Prefabs"
if (Test-Path $prefabsSource) {
Copy-DirectoryWithOverwrite -Source $prefabsSource -Destination $prefabsTarget -Description "Prefabs"
}
}
# Migrate Scenes
if ($MigrateScenes -or $MigrateAll) {
Write-Host "`n--- Migrating Scenes ---" -ForegroundColor Cyan
$scenesToMigrate = @(
"TutorialScene.unity",
"EmptyScene.unity"
)
foreach ($scene in $scenesToMigrate) {
$sourcePath = Join-Path $SourceProject "Assets\Scenes\$scene"
$targetPath = Join-Path $TargetProject "Assets\Scenes\$scene"
Copy-FileWithOverwrite -Source $sourcePath -Destination $targetPath -Description "Scene: $scene"
# Also copy .meta files
$sourceMetaPath = "$sourcePath.meta"
$targetMetaPath = "$targetPath.meta"
Copy-FileWithOverwrite -Source $sourceMetaPath -Destination $targetMetaPath -Description "Scene Meta: $scene.meta"
}
}
# Migrate Materials
Write-Host "`n--- Migrating Materials ---" -ForegroundColor Cyan
$materialsSource = Join-Path $SourceProject "Assets\Materials"
$materialsTarget = Join-Path $TargetProject "Assets\Materials"
if (Test-Path $materialsSource) {
Copy-DirectoryWithOverwrite -Source $materialsSource -Destination $materialsTarget -Description "Materials"
}
# Migrate Resources
Write-Host "`n--- Migrating Resources ---" -ForegroundColor Cyan
$resourcesSource = Join-Path $SourceProject "Assets\Resources"
$resourcesTarget = Join-Path $TargetProject "Assets\Resources"
if (Test-Path $resourcesSource) {
Copy-DirectoryWithOverwrite -Source $resourcesSource -Destination $resourcesTarget -Description "Resources"
}
# Create updated assembly definition for migrated scripts
Write-Host "`n--- Updating Assembly Definitions ---" -ForegroundColor Cyan
$robotAsmdefContent = @"
{
"name": "ROS2NiryoControl.Robot",
"rootNamespace": "ROS2NiryoControl.Robot",
"references": [
"ROS2NiryoControl",
"Unity.Robotics.ROSTCPConnector",
"Unity.Robotics.ROSTCPConnector.Messages",
"Unity.Robotics.UrdfImporter"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
"@
$robotAsmdefPath = Join-Path $TargetProject "Assets\Scripts\Robot\ROS2NiryoControl.Robot.asmdef"
Write-Output $robotAsmdefContent | Out-File -FilePath $robotAsmdefPath -Encoding UTF8
Write-Host "✓ Robot assembly definition created" -ForegroundColor Green
# Create migration summary
Write-Host "`n=== Migration Summary ===" -ForegroundColor Green
Write-Host "Source Project: $SourceProject" -ForegroundColor White
Write-Host "Target Project: $TargetProject" -ForegroundColor White
Write-Host ""
Write-Host "Migrated Components:" -ForegroundColor Yellow
Write-Host "✓ Robot control scripts (TrajectoryPlanner, TargetPlacement, etc.)" -ForegroundColor White
Write-Host "✓ Niryo One URDF files and meshes" -ForegroundColor White
Write-Host "✓ ROS2 demo scripts" -ForegroundColor White
Write-Host "✓ Materials and resources" -ForegroundColor White
Write-Host "✓ Scene files (if available)" -ForegroundColor White
Write-Host "✓ Assembly definitions updated" -ForegroundColor White
Write-Host ""
Write-Host "Next Steps:" -ForegroundColor Yellow
Write-Host "1. Open Unity project and resolve any compilation errors" -ForegroundColor White
Write-Host "2. Update script namespaces if needed" -ForegroundColor White
Write-Host "3. Reconfigure prefab references in scenes" -ForegroundColor White
Write-Host "4. Test robot URDF import and visualization" -ForegroundColor White
Write-Host "5. Configure ROS TCP Endpoint connection" -ForegroundColor White
Write-Host "`nMigration completed successfully!" -ForegroundColor Green