ai-game-prompt.ts 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import type { SceneObject } from "./types";
  2. export function generateGameAIPrompt(
  3. userPrompt: string,
  4. objects: SceneObject[] = [],
  5. previousPrompts: string[] = [],
  6. ): string {
  7. const simplifiedObjects = objects.map((obj) => ({
  8. id: obj.id,
  9. name: obj.name,
  10. type: obj.type,
  11. position: obj.position,
  12. rotation: obj.rotation,
  13. scale: obj.scale,
  14. material: obj.material,
  15. physics: obj.physics,
  16. lightType: obj.lightType,
  17. intensity: obj.intensity,
  18. damage: obj.damage,
  19. shapeData: obj.shapeData,
  20. meshData: obj.meshData,
  21. }));
  22. return `You are an AI assistant that helps users create and modify 3D scenes.
  23. The user has given you this instruction: "${userPrompt}".
  24. You have access to these functions:
  25. - addObject(type): Creates a new object of type "box", "sphere", "cylinder", "cone", "torus", "plane", "light", "capsule", "extrude", "tetrahedron", "octahedron", "dodecahedron", "icosahedron", "knot", "tube", "shape", "mesh"
  26. - createCustomObject(type, properties): Creates a new object with custom properties. Properties can include:
  27. * name: string
  28. * position: [x, y, z]
  29. * rotation: [x, y, z] (For plane objects, default rotation is [-1.5708, 0, 0])
  30. * scale: [x, y, z] (For plane objects, Z scale is always 1)
  31. * material: { color, metalness, roughness, emissive, emissiveIntensity }
  32. * physics: { mass, isStatic, restitution, friction, colliderType }
  33. * damage: { amount, enabled }
  34. * lightType: "ambient", "directional", "point", or "spot"
  35. * intensity: number
  36. * distance: number
  37. * decay: number
  38. * angle: number
  39. * penumbra: number
  40. * shapeData: { points: [x,y][], holes?: [x,y][][] }
  41. * meshData: { vertices: number[], indices: number[], normals?: number[], uvs?: number[] }
  42. - updateObjectTransform(id, {position, rotation, scale}): Updates an object's transform
  43. - updateObjectMaterial(id, {color, metalness, roughness, emissive, emissiveIntensity}): Updates material
  44. - updateObjectPhysics(id, {mass, isStatic, restitution, friction, colliderType}): Updates physics
  45. - updateDamage(id, {amount, enabled}): Updates damage properties
  46. - selectObject(id): Selects an object
  47. - setTransformMode(mode): Sets transform mode to "select", "translate", "rotate", or "scale"
  48. Current objects in the scene:
  49. ${JSON.stringify(simplifiedObjects, null, 2)}
  50. Previous user instructions:
  51. ${previousPrompts.map((p) => `- "${p}"`).join("\n")}
  52. Respond with a series of JSON objects, one per line (JSONL format). Each JSON object should have a "function" property and "args" property.
  53. Example:
  54. {"function": "createCustomObject", "args": ["box", {"name": "Large Red Box", "position": [0, 1, 0], "scale": [2, 2, 2], "material": {"color": "#ff0000"}, "physics": {"mass": 5, "isStatic": false, "restitution": 0.5}}]}
  55. {"function": "updateObjectTransform", "args": ["object-id", {"position": [0, -1, 0], "scale": [10, 1, 10]}]}
  56. IMPORTANT CONSTRAINTS:
  57. 1. For plane objects, the Z scale must always be 1.
  58. 2. For plane objects, the default rotation is [-1.5708, 0, 0] to make them horizontal.
  59. 3. Only use the functions listed above.
  60. 4. Your response must be valid JSONL format with one JSON object per line. Do not include any explanations.
  61. 5. Do not wrap your response in an array. Each line should be a separate, complete JSON object.
  62. 6. Each JSON object MUST have exactly this format: {"function": "functionName", "args": [arg1, arg2, ...]}
  63. 7. Do not use JavaScript expressions like Math.PI in your JSON. Use the actual numeric values instead.`;
  64. }