Forráskód Böngészése

Sujith :) ->
1. Basic work is done

Sujith:) 11 órája
szülő
commit
65ddaeeb2e

+ 2 - 2
Assets/LLM/Editor/DataExtractorMenu.cs

@@ -50,10 +50,10 @@ namespace LLM.Editor
             string indentArgument;
             switch (indentChoice)
             {
-                case 0: // Indented
+                case 0: // Compact
                     indentArgument = ""; // Default is compact
                     break;
-                case 1: // Compact
+                case 1: // Indented
                     indentArgument = " --indent 2";
                     break;
                 default: // Cancel or closed dialog

+ 0 - 59
Assets/LLM/source/extract_high_level.py

@@ -222,64 +222,6 @@ def parse_package_manifests(input_dir, output_dir, indent=None):
     else:
         print(f"Warning: {manifest_path} not found.")
 
-def generate_guid_mappers(input_dir, output_dir, indent=None):
-    """
-    Finds all .meta files and generates JSON files mapping GUIDs to asset paths.
-    """
-    print("\n--- Starting Task 4: GUID Mapper Generator ---")
-    assets_dir = input_dir / "Assets"
-    if not assets_dir.is_dir():
-        print(f"Error: 'Assets' directory not found in '{input_dir}'", file=sys.stderr)
-        return
-
-    meta_files = find_files_by_extension(str(assets_dir), '.meta')
-    print(f"Found {len(meta_files)} .meta files to process.")
-
-    asset_type_map = {
-        '.prefab': 'prefabs', '.unity': 'scenes', '.mat': 'materials',
-        '.cs': 'scripts', '.png': 'textures', '.jpg': 'textures',
-        '.jpeg': 'textures', '.asset': 'scriptable_objects',
-    }
-    
-    guid_maps = {value: {} for value in asset_type_map.values()}
-    guid_maps['others'] = {}
-
-    for meta_file_path_str in meta_files:
-        meta_file_path = Path(meta_file_path_str)
-        asset_file_path = Path(meta_file_path_str.rsplit('.meta', 1)[0])
-
-        # THE FIX: Ensure that the corresponding path is a file, not a directory
-        if not asset_file_path.is_file():
-            continue
-
-        guid = None
-        try:
-            with open(meta_file_path, 'r', encoding='utf-8') as f:
-                for line in f:
-                    if line.strip().startswith('guid:'):
-                        guid = line.strip().split(':')[1].strip()
-                        break
-        except Exception as e:
-            print(f"Warning: Could not read or parse guid from {meta_file_path}. {e}", file=sys.stderr)
-            continue
-
-        if guid:
-            asset_ext = asset_file_path.suffix.lower()
-            asset_type = asset_type_map.get(asset_ext, 'others')
-            relative_path = asset_file_path.relative_to(input_dir).as_posix()
-            guid_maps[asset_type][guid] = relative_path
-
-    mappers_dir = output_dir / "GuidMappers"
-    try:
-        mappers_dir.mkdir(parents=True, exist_ok=True)
-        for asset_type, guid_map in guid_maps.items():
-            if guid_map:
-                output_path = mappers_dir / f"{asset_type}.json"
-                write_json(guid_map, output_path, indent=indent)
-        print(f"Successfully created GUID mappers in {mappers_dir}")
-    except OSError as e:
-        print(f"Error: Could not create GUID mapper directory or files. {e}", file=sys.stderr)
-
 def main():
     """
     Main function to run the high-level data extraction process.
@@ -309,7 +251,6 @@ def main():
 
     parse_project_settings(input_dir, high_level_output_dir, indent=args.indent)
     parse_package_manifests(input_dir, high_level_output_dir, indent=args.indent)
-    generate_guid_mappers(input_dir, high_level_output_dir, indent=args.indent)
 
     print("\nHigh-level extraction complete.")
 

+ 75 - 3
Assets/LLM/source/extract_low_level.py

@@ -1,6 +1,7 @@
 import argparse
 import sys
 import json
+import shutil
 from pathlib import Path
 
 # Add the utils directory to the Python path
@@ -13,6 +14,28 @@ from json_utils import write_json
 from yaml_utils import load_unity_yaml, convert_to_plain_python_types
 from hierarchy_utils import HierarchyParser
 
+def copy_scripts(assets_dir, output_assets_dir):
+    """
+    Copies all C# scripts (.cs) to the target directory.
+    """
+    print("\n--- Starting Script Handling ---")
+    cs_files = find_files_by_extension(str(assets_dir), '.cs')
+    print(f"Found {len(cs_files)} C# script files to copy.")
+
+    for script_path_str in cs_files:
+        script_path = Path(script_path_str)
+        relative_path = script_path.relative_to(assets_dir)
+        destination_path = output_assets_dir / relative_path
+        
+        destination_path.parent.mkdir(parents=True, exist_ok=True)
+        
+        try:
+            shutil.copy(script_path, destination_path)
+        except IOError as e:
+            print(f"Error copying {script_path} to {destination_path}: {e}", file=sys.stderr)
+    
+    print("Script copying complete.")
+
 def main():
     """
     Main function to run the low-level data extraction process.
@@ -49,8 +72,9 @@ def main():
 
     # Create the main output folder, named "LowLevel"
     low_level_output_dir = output_dir / "LowLevel"
+    output_assets_dir = low_level_output_dir / "Assets"
     try:
-        low_level_output_dir.mkdir(parents=True, exist_ok=True)
+        output_assets_dir.mkdir(parents=True, exist_ok=True)
         print(f"Output will be saved to: {low_level_output_dir}")
     except OSError as e:
         print(f"Error: Could not create output directory '{low_level_output_dir}'. {e}", file=sys.stderr)
@@ -62,6 +86,10 @@ def main():
         print(f"Error: 'Assets' directory not found in '{input_dir}'.", file=sys.stderr)
         return
 
+    # --- Task 1: Copy C# Scripts ---
+    copy_scripts(assets_dir, output_assets_dir)
+
+    # --- Task 2: Process Scenes and Prefabs ---
     scene_files = find_files_by_extension(str(assets_dir), '.unity')
     prefab_files = find_files_by_extension(str(assets_dir), '.prefab')
     files_to_process = scene_files + prefab_files
@@ -70,7 +98,7 @@ def main():
 
     for file_path_str in files_to_process:
         file_path = Path(file_path_str)
-        print(f"\nProcessing: {file_path.name}")
+        print(f"\nProcessing Scene/Prefab: {file_path.name}")
 
         # --- Deep Parsing for Individual GameObjects ---
         gameobject_list = parse_scene_or_prefab(str(file_path))
@@ -110,7 +138,6 @@ def main():
             parser = HierarchyParser(object_map)
             root_object_ids = parser.get_root_object_ids()
             
-            # Extract just the fileIDs for the root_objects.json file
             root_ids_list = [file_id for file_id, _ in root_object_ids]
 
             if root_ids_list:
@@ -121,6 +148,51 @@ def main():
         except Exception as e:
             print(f"Error during hierarchy parsing for {file_path.name}: {e}", file=sys.stderr)
 
+    # --- Task 3: Process .asset files ---
+    asset_files = find_files_by_extension(str(assets_dir), '.asset')
+    print(f"\nFound {len(asset_files)} .asset files to process.")
+
+    for file_path_str in asset_files:
+        file_path = Path(file_path_str)
+        print(f"\nProcessing Asset: {file_path.name}")
+
+        relative_path = file_path.relative_to(input_dir)
+        asset_output_dir = low_level_output_dir / relative_path
+        try:
+            asset_output_dir.mkdir(parents=True, exist_ok=True)
+        except OSError as e:
+            print(f"Error creating directory {asset_output_dir}: {e}", file=sys.stderr)
+            continue
+
+        try:
+            documents = load_unity_yaml(file_path)
+            if not documents:
+                print(f"Skipped {file_path.name} as it's empty or could not be parsed.")
+                continue
+
+            print(f"Saving {len(documents)} objects from {file_path.name} to {asset_output_dir}")
+            for doc in documents:
+                if not hasattr(doc, 'anchor') or doc.anchor is None:
+                    continue
+                
+                file_id = int(doc.anchor.value)
+                obj_data = convert_to_plain_python_types(doc)
+                
+                final_obj_data = {}
+                for key, value in obj_data.items():
+                    if isinstance(value, dict):
+                        new_value = value.copy()
+                        new_value['fileID'] = file_id
+                        final_obj_data[key] = new_value
+                    else:
+                        final_obj_data[key] = value
+
+                output_json_path = asset_output_dir / f"{file_id}.json"
+                write_json(final_obj_data, output_json_path, indent=args.indent)
+
+        except Exception as e:
+            print(f"Error processing asset file {file_path.name}: {e}", file=sys.stderr)
+
 
     print("\nLow-level extraction complete.")
 

+ 57 - 22
Assets/LLM/source/extract_mid_level.py

@@ -12,27 +12,62 @@ from file_utils import replicate_directory_structure, find_files_by_extension, c
 from json_utils import write_json
 from scene_processor import UnitySceneProcessor
 
-def copy_scripts(assets_dir, output_assets_dir):
+def generate_guid_mappers(input_dir, output_dir, indent=None):
     """
-    Copies all C# scripts (.cs) to the target directory.
+    Finds all .meta files and generates JSON files mapping GUIDs to asset paths.
     """
-    print("\n--- Starting Script Handling ---")
-    cs_files = find_files_by_extension(str(assets_dir), '.cs')
-    print(f"Found {len(cs_files)} C# script files to copy.")
-
-    for script_path_str in cs_files:
-        script_path = Path(script_path_str)
-        relative_path = script_path.relative_to(assets_dir)
-        destination_path = output_assets_dir / relative_path
-        
-        destination_path.parent.mkdir(parents=True, exist_ok=True)
-        
-        try:
-            shutil.copy(script_path, destination_path)
-        except IOError as e:
-            print(f"Error copying {script_path} to {destination_path}: {e}", file=sys.stderr)
+    print("\n--- Starting GUID Mapper Generation ---")
+    assets_dir = input_dir / "Assets"
+    if not assets_dir.is_dir():
+        print(f"Error: 'Assets' directory not found in '{input_dir}'", file=sys.stderr)
+        return
+
+    meta_files = find_files_by_extension(str(assets_dir), '.meta')
+    print(f"Found {len(meta_files)} .meta files to process.")
+
+    asset_type_map = {
+        '.prefab': 'prefabs', '.unity': 'scenes', '.mat': 'materials',
+        '.cs': 'scripts', '.png': 'textures', '.jpg': 'textures',
+        '.jpeg': 'textures', '.asset': 'scriptable_objects',
+    }
     
-    print("Script copying complete.")
+    guid_maps = {value: {} for value in asset_type_map.values()}
+    guid_maps['others'] = {}
+
+    for meta_file_path_str in meta_files:
+        meta_file_path = Path(meta_file_path_str)
+        asset_file_path = Path(meta_file_path_str.rsplit('.meta', 1)[0])
+
+        if not asset_file_path.is_file():
+            continue
+
+        guid = None
+        try:
+            with open(meta_file_path, 'r', encoding='utf-8') as f:
+                for line in f:
+                    if line.strip().startswith('guid:'):
+                        guid = line.strip().split(':')[1].strip()
+                        break
+        except Exception as e:
+            print(f"Warning: Could not read or parse guid from {meta_file_path}. {e}", file=sys.stderr)
+            continue
+
+        if guid:
+            asset_ext = asset_file_path.suffix.lower()
+            asset_type = asset_type_map.get(asset_ext, 'others')
+            relative_path = asset_file_path.relative_to(input_dir).as_posix()
+            guid_maps[asset_type][guid] = relative_path
+
+    mappers_dir = output_dir / "GuidMappers"
+    try:
+        mappers_dir.mkdir(parents=True, exist_ok=True)
+        for asset_type, guid_map in guid_maps.items():
+            if guid_map:
+                output_path = mappers_dir / f"{asset_type}.json"
+                write_json(guid_map, output_path, indent=indent)
+        print(f"Successfully created GUID mappers in {mappers_dir}")
+    except OSError as e:
+        print(f"Error: Could not create GUID mapper directory or files. {e}", file=sys.stderr)
 
 def main():
     """
@@ -89,10 +124,7 @@ def main():
     replicate_directory_structure(str(assets_dir), str(output_assets_dir))
     print("Directory structure replication complete.")
 
-    # --- Task 2: Copy C# Scripts ---
-    copy_scripts(assets_dir, output_assets_dir)
-
-    # --- Task 3: Generate GUID Map ---
+    # --- Task 2: Generate GUID Map ---
     print("\n--- Generating GUID Map ---")
     guid_map = create_guid_to_path_map(str(input_dir))
     guid_map_path = mid_level_output_dir / "guid_map.json"
@@ -104,6 +136,9 @@ def main():
         print(f"Error writing GUID map: {e}", file=sys.stderr)
         sys.exit(1)
 
+    # --- Task 3: Generate Detailed GUID Mappers ---
+    generate_guid_mappers(input_dir, mid_level_output_dir, indent=args.indent)
+
     # --- Task 4: Orchestrate Scene and Prefab Parsing ---
     print("\n--- Starting Scene/Prefab Parsing Orchestration ---")