File size: 2,526 Bytes
94c52e3
 
3eb6edd
94c52e3
 
d00747b
 
 
94c52e3
d00747b
 
94c52e3
d00747b
 
 
 
 
 
 
 
 
 
 
 
 
 
94c52e3
d00747b
 
 
 
 
94c52e3
 
8c85c78
94c52e3
3eb6edd
 
94c52e3
d01bb30
94c52e3
3eb6edd
 
d00747b
 
 
 
 
 
94c52e3
d00747b
 
 
94c52e3
d00747b
 
 
 
 
 
 
 
94c52e3
d00747b
 
 
 
 
8c85c78
94c52e3
3eb6edd
 
94c52e3
d00747b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from .llm_client import generate_with_hf, generate_with_openai

def synthesize_cpp(parsed: dict, mapping: dict, prompt_context: str = "", model_backend="hf") -> str:
    """
    Converts Unity C# parsed structure into Unreal Engine C++ (header + source).
    Always returns code with clear file markers:
    ---FILE: ClassName.h---
    ---FILE: ClassName.cpp---
    """
    class_name = parsed.get("classes", [{}])[0].get("name", "MyActor")

    prompt = f"""
    You are an expert Unreal Engine C++ developer.
    Translate the following Unity C# class into idiomatic Unreal C++.

    ✅ Follow these rules:
    - Create TWO files with exact markers:
      ---FILE: {class_name}.h---
      (Header file)
      ---FILE: {class_name}.cpp---
      (Implementation file)
    - Use Unreal macros like UCLASS(), UPROPERTY(), and UFUNCTION() appropriately.
    - Include necessary Unreal headers.
    - Ensure code compiles cleanly.
    - Use PascalCase for class and method names.
    - Avoid Unity-specific APIs; map them via given rules.

    Mapping rules:
    {mapping}

    Parsed structure:
    {parsed}

    {prompt_context}
    """

    if model_backend == "openai":
        return generate_with_openai(prompt, model="gpt-4o-mini")
    else:
        return generate_with_hf(prompt, model="mistralai/Mistral-7B-Instruct-v0.3")


def synthesize_blueprint_python(parsed: dict, mapping: dict, model_backend="hf") -> str:
    """
    Generates Unreal Python Editor script that creates a Blueprint equivalent
    of the Unity class (BP_<ClassName>).
    """
    class_name = parsed.get("classes", [{}])[0].get("name", "MyActor")

    prompt = f"""
    You are an Unreal Engine Python scripting expert.
    Convert the given Unity C# class into an Unreal Python Editor script
    that generates a Blueprint Actor named BP_{class_name}.

    Requirements:
    - Use Unreal Python API (unreal module).
    - Create Blueprint under /Game/Blueprints/BP_{class_name}.
    - Add StaticMeshComponent as root.
    - Add float property 'RotationSpeed' exposed to Blueprint.
    - Implement a Tick method to rotate actor: RotationSpeed * DeltaTime.
    - Include import statements and comments for clarity.
    - Output only the full Python script (no explanations).

    Parsed structure:
    {parsed}

    Mapping rules:
    {mapping}
    """

    if model_backend == "openai":
        return generate_with_openai(prompt, model="gpt-4o-mini")
    else:
        return generate_with_hf(prompt, model="mistralai/Mistral-7B-Instruct-v0.3")