bolajiev commited on
Commit
f0a5709
·
1 Parent(s): 5f02e75

Add 5 new shapes: capsule, ring, circle, tube, roundedBox (+ FEWSHOT examples)

Browse files
Files changed (3) hide show
  1. compiler.py +20 -0
  2. llm.py +41 -1
  3. scene.py +11 -0
compiler.py CHANGED
@@ -45,6 +45,25 @@ def geometry_js(o: Obj) -> str:
45
  }
46
  if s in poly:
47
  return f"new THREE.{poly[s]}({g('radius', 0.6)}, 0)"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  return "new THREE.BoxGeometry(1, 1, 1)"
49
 
50
 
@@ -207,6 +226,7 @@ TEMPLATE = """<!DOCTYPE html>
207
  import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
208
  import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
209
  import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
 
210
 
211
  const scene = new THREE.Scene();
212
  scene.background = new THREE.Color('__BG__');
 
45
  }
46
  if s in poly:
47
  return f"new THREE.{poly[s]}({g('radius', 0.6)}, 0)"
48
+ if s == "capsule":
49
+ return f"new THREE.CapsuleGeometry({g('radius', 0.4)}, {g('length', 1.0)}, 8, 16)"
50
+ if s == "ring":
51
+ return f"new THREE.RingGeometry({g('innerRadius', 0.3)}, {g('outerRadius', 0.6)}, 32)"
52
+ if s == "circle":
53
+ return f"new THREE.CircleGeometry({g('radius', 0.6)}, 32)"
54
+ if s == "tube":
55
+ r = g('radius', 0.1)
56
+ return (
57
+ f"(()=>{{ const _c=new THREE.CatmullRomCurve3(["
58
+ f"new THREE.Vector3(-0.4,-0.6,0),"
59
+ f"new THREE.Vector3(0.4,-0.2,0),"
60
+ f"new THREE.Vector3(-0.4,0.2,0),"
61
+ f"new THREE.Vector3(0.4,0.6,0)"
62
+ f"]); return new THREE.TubeGeometry(_c,64,{r},12,false); }})()"
63
+ )
64
+ if s == "roundedBox":
65
+ return (f"new RoundedBoxGeometry({g('width', 1.0)}, {g('height', 1.0)}, "
66
+ f"{g('depth', 1.0)}, 4, {g('radius', 0.1)})")
67
  return "new THREE.BoxGeometry(1, 1, 1)"
68
 
69
 
 
226
  import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
227
  import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
228
  import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
229
+ import { RoundedBoxGeometry } from 'three/addons/geometries/RoundedBoxGeometry.js';
230
 
231
  const scene = new THREE.Scene();
232
  scene.background = new THREE.Color('__BG__');
llm.py CHANGED
@@ -29,7 +29,7 @@ Schema:
29
  "background": "#RRGGBB",
30
  "objects": [
31
  {
32
- "shape": "box|sphere|cylinder|cone|torus|torusKnot|plane|tetrahedron|icosahedron|dodecahedron|octahedron",
33
  "position": [x, y, z],
34
  "rotation": [x, y, z], // radians, optional
35
  "scale": [x, y, z], // optional
@@ -127,6 +127,46 @@ FEWSHOT = [
127
  ],
128
  "animation": {"type": "rotate", "speed": 0.5, "axis": "y"},
129
  })},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  ]
131
 
132
  _tok = None
 
29
  "background": "#RRGGBB",
30
  "objects": [
31
  {
32
+ "shape": "box|sphere|cylinder|cone|torus|torusKnot|plane|tetrahedron|icosahedron|dodecahedron|octahedron|capsule|ring|circle|tube|roundedBox",
33
  "position": [x, y, z],
34
  "rotation": [x, y, z], // radians, optional
35
  "scale": [x, y, z], // optional
 
127
  ],
128
  "animation": {"type": "rotate", "speed": 0.5, "axis": "y"},
129
  })},
130
+ {"role": "user", "content": "a cute capsule character with a rounded body"},
131
+ {"role": "assistant", "content": json.dumps({
132
+ "background": "#0d1b2a",
133
+ "objects": [
134
+ {"shape": "capsule", "color": "#ff6b6b", "emissive": "#330000", "material": "standard",
135
+ "metalness": 0.1, "roughness": 0.5, "position": [0, 0, 0],
136
+ "params": {"radius": 0.35, "length": 0.6}},
137
+ {"shape": "sphere", "color": "#ffe8cc", "material": "standard",
138
+ "metalness": 0.0, "roughness": 0.8, "position": [0, 0.72, 0],
139
+ "params": {"radius": 0.28}},
140
+ ],
141
+ "lights": [
142
+ {"type": "ambient", "intensity": 0.5},
143
+ {"type": "directional", "intensity": 1.3, "position": [5, 8, 6]},
144
+ ],
145
+ "animation": {"type": "float", "speed": 1.0, "axis": "y"},
146
+ })},
147
+ {"role": "user", "content": "a stack of soft rounded boxes"},
148
+ {"role": "assistant", "content": json.dumps({
149
+ "background": "#0b0e14",
150
+ "objects": [{
151
+ "type": "stack", "axis": "y", "gap": 0.08,
152
+ "children": [
153
+ {"shape": "roundedBox", "color": "#ff9f43", "material": "standard",
154
+ "metalness": 0.1, "roughness": 0.4,
155
+ "params": {"width": 1.2, "height": 0.4, "depth": 1.2, "radius": 0.12}},
156
+ {"shape": "roundedBox", "color": "#ee5a24", "material": "standard",
157
+ "metalness": 0.1, "roughness": 0.4,
158
+ "params": {"width": 1.0, "height": 0.4, "depth": 1.0, "radius": 0.12}},
159
+ {"shape": "roundedBox", "color": "#c0392b", "material": "standard",
160
+ "metalness": 0.1, "roughness": 0.4,
161
+ "params": {"width": 0.8, "height": 0.4, "depth": 0.8, "radius": 0.12}},
162
+ ],
163
+ }],
164
+ "lights": [
165
+ {"type": "ambient", "intensity": 0.5},
166
+ {"type": "directional", "intensity": 1.3, "position": [5, 8, 6]},
167
+ ],
168
+ "animation": {"type": "rotate", "speed": 0.8, "axis": "y"},
169
+ })},
170
  ]
171
 
172
  _tok = None
scene.py CHANGED
@@ -19,6 +19,7 @@ log = logging.getLogger(__name__)
19
  SHAPES = {
20
  "box", "sphere", "cylinder", "cone", "torus", "torusKnot", "plane",
21
  "tetrahedron", "icosahedron", "dodecahedron", "octahedron",
 
22
  }
23
  MATERIALS = {"standard", "basic", "phong", "wireframe"}
24
  LIGHT_TYPES = {"ambient", "directional", "point"}
@@ -51,6 +52,16 @@ def _shape_extent(shape: str, params: Dict[str, float]) -> tuple:
51
  return (d, d, d)
52
  if shape == "plane":
53
  return (p("width", 5.0), 0.01, p("height", 5.0))
 
 
 
 
 
 
 
 
 
 
54
  return (1.0, 1.0, 1.0)
55
 
56
 
 
19
  SHAPES = {
20
  "box", "sphere", "cylinder", "cone", "torus", "torusKnot", "plane",
21
  "tetrahedron", "icosahedron", "dodecahedron", "octahedron",
22
+ "capsule", "ring", "circle", "tube", "roundedBox",
23
  }
24
  MATERIALS = {"standard", "basic", "phong", "wireframe"}
25
  LIGHT_TYPES = {"ambient", "directional", "point"}
 
52
  return (d, d, d)
53
  if shape == "plane":
54
  return (p("width", 5.0), 0.01, p("height", 5.0))
55
+ if shape == "capsule":
56
+ d = p("radius", 0.4) * 2
57
+ return (d, p("length", 1.0) + d, d)
58
+ if shape in ("ring", "circle"):
59
+ r = p("outerRadius", p("radius", 0.6)) * 2
60
+ return (r, 0.01, r)
61
+ if shape == "tube":
62
+ return (1.0, 1.5, 1.0)
63
+ if shape == "roundedBox":
64
+ return (p("width", 1.0), p("height", 1.0), p("depth", 1.0))
65
  return (1.0, 1.0, 1.0)
66
 
67