Skip to content

Ai 3d model spawner

AI 3D Model Spawner


Download Latest Version

A SightLab VR demo that lets you generate and interact with 3D models in real time using generative AI: Stability AI, Meshy, Tripo, or an AI-written Blender script. Images for image-to-3D can come from Google Gemini, OpenAI, Stability AI or Meshy, or you can drop in your own picture.

Located in ExampleScripts/AI_3D_Model_Spawner


🧩 What It Does

AI 3D Model Spawner lets participants or researchers spawn objects into a virtual scene on demand by typing a prompt, speaking it (e.g. "a glowing mushroom"), or turning a picture into a 3D model. Models are created through online APIs and placed in the VR environment, where they can be grabbed, moved, scaled and saved. Set USE_AI = False to just drag and drop models and build a scene.

  • 🔤 Text → 3D model, 🖼️ Image → 3D model
  • 🧠 Five generators: Stability AI, Meshy (image or text), Tripo, Blender (experimental)
  • 🎨 Choose the image generator: Gemini, OpenAI, Stability AI or Meshy
  • 🎙️ Push-to-talk speech prompts
  • ⏱️ Every request is timed and logged to benchmarks/generation_log.csv
  • ✋ Grabbing via SightLab; move, rotate, scale, save and reload models

🧠 Choosing a Generator

Choose the generator in the dialog at start-up, set GENERATOR in Config_Global.py, or press V while running to cycle through them.

Generator How it works Typical speed* Approx. cost per model API key(s)
Stability AI (stability) Text → image → Stable Fast 3D Fastest: the 3D step takes about 1 s, plus the image $0.10 (+ image) STABILITY_API_KEY (+ image key)
Meshy Image to 3D (meshy_image) Text → image → Meshy mesh + texture: Meshy 7.1 + Meshy 7, 4K (quality), or T2.5 + N1, 2K (speed) About 100–130 s (quality); about 35 s (speed) 30 credits (quality); 15 (speed) (+ image) MESHY_API_KEY (+ image key)
Meshy Text to 3D (meshy_text) Untextured preview mesh, then the textured model: Meshy 7.1 (quality), or T2.5 + Meshy 6 Lite (speed) Preview first, then the textured model; not yet measured with these settings Not yet measured MESHY_API_KEY
Tripo Image to 3D (tripo_image) Text → image → Tripo image-to-model: v3.1 + detailed texture (quality), or P1 + fast texture (speed) About 95 s (quality) About 60 credits (quality, measured with HD geometry on) (+ image) TRIPO_API_KEY (+ image key)
Tripo Text to 3D (tripo) Direct text → 3D: v3.1 + detailed texture (quality), or P1 + fast texture (speed) About 22 s (speed) About 40 credits ($0.40) (speed) TRIPO_API_KEY
Blender (blender, experimental) An LLM (Claude, OpenAI or Gemini) writes a Blender Python script, and Blender builds and exports the model Depends on the LLM; often 20–60 s LLM tokens only LLM key + Blender installed

Speed or quality: for Meshy and Tripo, set GENERATION_MODE = 'quality' (the default) or 'speed' in Config_Global.py. Each mode is a block of settings you can edit (MESHY_SETTINGS, TRIPO_SETTINGS). Measured with the benchmark log, one or two runs each on a test image or prompt (credits are the 3D provider's; the image step is billed separately):

Generator and settings Model in scene Triangles File size Credits
Meshy Image to 3D, quality: Meshy 7.1 + Meshy 7, 4K, 100,000 polygons about 100–130 s about 100,000 about 17 MB 30
Meshy Image to 3D, quality with PBR turned on about 195–210 s about 100,000 about 40 MB 30
Meshy Image to 3D, Meshy 7.1 + Meshy 7, 4K, PBR, no remesh about 105 s about 1,750,000 76 MB 30
Meshy Image to 3D, speed: T2.5 + N1, 2K, 20,000 polygons about 35 s about 16,000 about 4 MB 15
Tripo Image to 3D, quality: v3.1 + detailed texture, 50,000 faces, with HD geometry on about 95 s about 49,000 about 4 MB 60
Tripo Text to 3D, speed: P1 + fast texture, 5,000 faces about 22 s about 5,000 about 0.7 MB 40

The Tripo quality run had HD geometry turned on ('geometry_quality': 'detailed' in EXTRA), which adds 20 credits. The shipped quality block leaves it off.

PBR is off in both blocks. It adds normal and metallic/roughness maps, but with Meshy 7.1 it roughly doubled the time and the file size, and the extra maps only show on a lit model. Generated models spawn unlit; press B to light the selected one. Set 'ENABLE_PBR': True if you want them.

The quality block uses Meshy 7.1 with REMESH: True, which keeps the triangle count near TARGET_POLYCOUNT (100,000) so the model stays light enough for VR. About 100,000 triangles per model looks smooth at arm's length. A 1.75-million-triangle model dropped the frame rate noticeably, so keep the whole scene under about 1–2 million triangles. Lower TARGET_POLYCOUNT if you spawn many models.

*Meshy and Tripo times are from the example's benchmark log (November 2026), measured from the request until the model appears in the scene. The Stability AI time is the provider's published figure for the 3D step and doesn't include queueing, download or loading into Vizard. Times vary with the object and the provider's load, so measure your own with the benchmark log (see Benchmarks).

Which one to use

  • Stability AI: the fastest option. Good for quick props and stimuli.
  • Meshy Image to 3D: more detailed textured models. Switch to speed for faster, lighter models.
  • Meshy Text to 3D: shows you a shape early, then swaps in the textured model.
  • Tripo: text to 3D with no image step.
  • Blender: best for procedural objects (furniture, buildings, simple machines) at real-world size. It is not suited to organic shapes or photo textures.

Image generator (for stability, meshy_image and tripo_image)

Text prompts are first turned into a picture of the object on a plain background. Set IMAGE_GENERATOR:

Setting Service Notes
'openai' (default) OpenAI, gpt-image-2.6-flare at low quality Requires OpenAI organization verification for GPT Image models
'gemini' Google Gemini, gemini-3.1-flash-lite-image (Nano Banana 2 Lite) Very fast, about $0.03 per image
'stability' Stability AI Stable Image Core $0.03; uses the same key as Stable Fast 3D
'meshy' Meshy Text to Image (nano-banana-2) Uses the same key as Meshy 3D
'auto' The 3D provider's own image model Needs only one API key for Stability or Meshy. Tripo has no image model, so tripo_image uses Gemini

Use your own image instead: press I to pick a .png, .jpg or .webp file, or drag an image onto the Vizard window. The image skips the image step and goes straight to the selected 3D generator. The concept image (generated or dropped) is shown above the placeholder while the model builds.

⚙️ Setup Instructions

1. 📦 Python Libraries

These come with Vizard 8. If any are missing, install them with Vizard's Package Manager:

  • requests, pillow: all generators
  • SpeechRecognition, sounddevice, numpy: speech prompts (USE_SPEECH_RECOGNITION = True)
  • anthropic: only for the Blender generator with BLENDER_LLM = 'claude'

2. 🔑 Get the API Key(s) for Your Generator

You only need the keys for the generator and image generator you use. Each service bills your own account.

Service Key file (in keys/) Where to get a key Used by
Stability AI stability_api_key.txt platform.stability.ai/dashboard/api-keys. Pay-as-you-go credits (1 credit = $0.01) stability generator, IMAGE_GENERATOR = 'stability'
Meshy meshy_api_key.txt meshy.ai/api. The API requires a paid Meshy subscription meshy_image, meshy_text, IMAGE_GENERATOR = 'meshy'
Tripo tripo_api_key.txt platform.tripo3d.ai → API Keys. API credits (1 credit = $0.01, from $1) are bought on the API pricing page, separately from a Tripo Studio subscription. A textured model costs 20–120 credits tripo generator
Google Gemini gemini_api_key.txt aistudio.google.com/app/apikey. Image models need billing enabled IMAGE_GENERATOR = 'gemini', BLENDER_LLM = 'gemini'
OpenAI openai_api_key.txt platform.openai.com/api-keys. GPT Image needs organization verification IMAGE_GENERATOR = 'openai', BLENDER_LLM = 'openai'
Anthropic (Claude) anthropic_api_key.txt console.anthropic.com BLENDER_LLM = 'claude'

💡 For the quickest setup, use Stability AI with IMAGE_GENERATOR = 'auto' (one key), or Meshy with IMAGE_GENERATOR = 'auto' (one key).

3. 📁 Add Your API Keys

Recommended: the keys folder. Open the keys folder in ExampleScripts/AI_3D_Model_Spawner, open the file for your service (for example meshy_api_key.txt), paste in the key on its own, and save. The files are already there and empty. The key is picked up the next time you start the spawner.

The spawner looks for each key in this order (an empty file is skipped):

  1. The example's own keys folder.
  2. An environment variable saved with setx. These are shared with the other SightLab AI examples. Type "cmd" in Windows search, open a command prompt and enter, for example:
setx STABILITY_API_KEY "your-stability-key"
setx MESHY_API_KEY "your-meshy-key"
setx TRIPO_API_KEY "your-tripo-key"
setx GEMINI_API_KEY "your-gemini-key"
setx OPENAI_API_KEY "your-openai-key"
setx ANTHROPIC_API_KEY "your-anthropic-key"
  1. The SightLab Dashboard's keys (ExampleScripts/_dashboard/keys/). Keys you saved in the Dashboard's Options tab work here too, so you don't need to enter them twice.

⚠️ Old keys are skipped automatically: when the spawner starts, it checks each key with the provider using a free call. If a provider rejects a key (for example an old key left in a file after you changed it), the spawner uses the next key it finds and tells you in the console which file or variable to replace. Keep key files private: don't share, upload or commit them.

Check your setup: run Check_AI_Setup.py (open it in Vizard and run it). It lists each key, where it was found, the remaining API credits for Stability AI, Meshy and Tripo, and whether each generator is ready, including Blender. The spawner also prints any missing key in the console at start-up and shows "SETUP NEEDED" on the start screen.

4. 🧱 Blender Setup (only for the Blender generator)

The Blender generator can run Blender two ways (BLENDER_MODE):

Headless ('headless', no window): Blender only needs to be installed.

  1. Install Blender 4.2 or later from blender.org/download, or run winget install -e --id BlenderFoundation.Blender in a command prompt.
  2. Blender is found automatically in C:\Program Files\Blender Foundation\. If you installed it somewhere else, set BLENDER_EXE_PATH in Config_Global.py.

Live in Blender through the MCP add-on ('mcp'): you can watch the object being built in your open Blender.

  1. Download addon.py from github.com/ahujasid/blender-mcp ("MCP for Blender").
  2. In Blender go to Edit > Preferences > Add-ons > Install from Disk, choose addon.py, and enable MCP for Blender.
  3. In the 3D Viewport press N, open the MCP for Blender tab and click Connect. Leave the port at 9876.
  4. Keep Blender open while you use the spawner. The spawner sends the script straight to the add-on on localhost:9876, so you don't need to run the separate MCP server. The same add-on also works with Claude Desktop.

With the default BLENDER_MODE = 'auto', the spawner uses the MCP add-on when Blender is open and connected, and headless Blender otherwise.

The LLM's script is checked before it runs. Only modelling modules (bpy, bmesh, math, mathutils, random, colorsys) may be imported, and file, OS and network access is blocked. If the script fails, the error goes back to the LLM for one fix (BLENDER_FIX_ATTEMPTS). Every script is saved in Resources/blender_scripts/ so you can open or reuse it in Blender.


5. ▶️ How to Run

  1. Run AI_3D_Model_Spawner.py.
  2. Choose the 3D generator and your hardware.
  3. Press N to type a prompt (e.g. a red futuristic drone), or hold C (desktop) or the right grip (VR) and speak, then let go to send.
  4. A pulsing placeholder appears with the current step and elapsed time. With the image generators, the concept image is shown above it. You can grab the placeholder to choose where the model appears.
  5. The model replaces the placeholder. With Meshy Text to 3D, an untextured preview appears first and is swapped for the textured model when it is ready.
  6. Press I or drop an image file to turn a picture into a model.
  7. Press V to switch generator at any time. You can start several requests at once.
  8. Grab models with the trigger buttons or the left mouse button. Press B to toggle lighting on the selected model.
  9. On the Desktop configuration, press F1 at any time to show or hide the full list of controls.
  10. Press spacebar to end.

⌨️ Controls

Key Action
N Type a prompt
Hold C / right grip Speak a prompt (push-to-talk, release to send; stops after SPEECH_MAX_SECONDS)
I / drag an image onto the window Image → 3D
V Next generator
B Lighting on/off for the selected model
Delete / Ctrl+Z Delete the selected model / undo the delete
1 / 2 Save the selected model / load a saved model or scene
Shift+1 Save every model as one scene
F1 Show / hide the list of controls (Desktop configuration)
Spacebar End

Direct Manipulation & Management

You can translate, rotate, scale, select, delete, store, and load models created or dropped at runtime.

Active Selection

  • Next/Prev: ] / [
  • Jump First/Last: { (Shift+[) / } (Shift+])
  • An arrow marks the current selection. All actions below target the active model. You can also left-click a model on the desktop mirror view.

Translate (move): hold to move smoothly (speed: MOVE_STEP_M)

  • X axis: g ( +X ) • G ( −X )
  • Y axis: h ( +Y / up ) • H ( −Y / down )
  • Z axis: j ( +Z / forward ) • J ( −Z / back )

Rotate: hold to rotate smoothly (speed: ROT_STEP_DEG)

  • Yaw (around Y): t / T
  • Pitch (around X): y / Y
  • Roll (around Z): u / U

Scale (uniform)

  • Scale Up / Down: k / m

Delete / Remove

  • Delete the selected model: Delete
  • Delete it and its saved states: Shift+Delete. The saved-state files are moved to saved_models/deleted/, not erased. Scene files are kept.
  • Undo the last delete: Ctrl+Z. The model returns where it was, with its saved states. Up to 20 deletes can be undone.

Drag & Drop Models

  • Drop .osgb, .glb, or .gltf files onto the Vizard window. The model appears in front of the user and becomes the active selection.

💾 Storing & Loading Models

Store (Save) Model State

  • Press 1 to save the selected model's position, rotation, scale and lighting to a timestamped JSON file in saved_models/ (model_state_<time>.json). Each press writes a new file.
  • Press Shift+1 to save every model in the scene to one file (scene_<time>.json), so you can rebuild the whole scene later.
  • Press 2 to load a saved model or a scene.
  • Generated models are saved in Resources/ with the prompt, time and generator in the file name, so a new model never overwrites an earlier one. The JSON files point to these model files, so keep them together.

Load Saved Models

  • Use the accompanying Model Loader (Model_Loader.py) to:
  • Press l to load a saved model or scene, o to load the newest save of every model, c to clear and i to list loaded models.
  • o skips older saves of a model you saved more than once, and skips scene files (load a scene with l).
  • Press b to toggle lighting on the selected model. Each model loads with the lighting it was saved with.
  • Cycle selection ([, ], {, }).
  • Delete the current selection with Delete (Shift+Delete also moves its saved JSON files to saved_models/deleted/), and undo with Ctrl+Z.

Tip: Build a scene for each condition and save it with Shift+1, then load it with 2 or the Model Loader's l. Use 1 to keep a library of single models and placements.

⏱️ Benchmarks

Every request adds a row to benchmarks/generation_log.csv, and a summary is printed in the console, for example:

[Benchmark] meshy_image: image 2.1 s, model in scene 31.4 s, 4,012 tris, 1.8 MB
Column Meaning
speech_s Speech recognition time (spoken prompts)
image_s Time until the concept image was ready
preview_in_scene_s Meshy Text to 3D: untextured preview visible
download_done_s GLB downloaded
model_in_scene_s Final model visible in VR, measured from the request (or from releasing the talk button)
triangles, size_mb, textures Model complexity
settings, credits Model/texture settings used and credits reported by the provider

To compare providers without a headset, run one request from a command prompt (this uses API credits):

"C:\Program Files\WorldViz\Vizard8\bin\python.exe" Check_AI_Setup.py --test stability "a red apple"
"C:\Program Files\WorldViz\Vizard8\bin\python.exe" Check_AI_Setup.py --test meshy_image "a teapot" --image photo.jpg

Config Global Options

The main options in Config_Global.py (see the file for every provider setting):

# ===== AI Model Generation =====
USE_AI = True
GENERATOR = 'stability'          # 'stability', 'meshy_image', 'meshy_text', 'tripo_image', 'tripo', 'blender'
ASK_GENERATOR_AT_START = True    # chooser at start-up ('v' cycles while running)
IMAGE_GENERATOR = 'openai'       # 'openai', 'gemini', 'stability', 'meshy', 'auto'
SHOW_CONCEPT_IMAGE = True

# Stability AI
STABILITY_3D_MODEL = 'fast3d'               # or 'spar3d'

# Meshy and Tripo: one switch picks a block of settings
GENERATION_MODE = 'quality'      # 'quality' or 'speed'
MESHY_SETTINGS = {
    'speed':   {'IMAGE_GEOMETRY_MODEL': 'meshy-t2.5', 'IMAGE_TEXTURE_MODEL': 'meshy-n1',
                'TARGET_POLYCOUNT': 20000, 'REMESH': False, 'ENABLE_PBR': False, 'TEXTURE_RESOLUTION': '2k', ...},
    'quality': {'IMAGE_GEOMETRY_MODEL': 'meshy-7.1', 'IMAGE_TEXTURE_MODEL': 'meshy-7',
                'TARGET_POLYCOUNT': 100000, 'REMESH': True, 'ENABLE_PBR': False, 'TEXTURE_RESOLUTION': '4k', ...},
}
TRIPO_SETTINGS = {
    'speed':   {'MODEL': 'P1-20260311',   'TEXTURE_QUALITY': 'fast',     'PBR': False, 'FACE_LIMIT': 5000, ...},
    'quality': {'MODEL': 'v3.1-20260211', 'TEXTURE_QUALITY': 'detailed', 'PBR': False, 'FACE_LIMIT': 50000, ...},
}

# Blender (experimental)
BLENDER_LLM = 'openai'           # 'openai', 'claude', 'gemini'
OPENAI_LLM_MODEL = 'gpt-6-astra' # OpenAI's most capable model; 'gpt-6.1-sol' is cheaper
OPENAI_REASONING_EFFORT = 'medium'
BLENDER_MODE = 'auto'            # 'auto', 'mcp', 'headless'
BLENDER_EXE_PATH = None

# ===== Model Options =====
MODEL_STARTING_POINT = [0, 1.5, 2]
MODEL_STARTING_POINT_PASSTHROUGH = [0, 1.5, 0.8]
SPAWN_IN_FRONT_OF_VIEW = False
AUTO_SCALE_MODELS = True         # largest side = MODEL_TARGET_SIZE metres
MODEL_TARGET_SIZE = 0.5
FACE_USER_ON_SPAWN = True        # new models turn to face you
MODEL_YAW_OFFSET = {'stability': 180, 'tripo': 180, 'tripo_image': 180}   # models that face away
MODEL_LIGHTING = 'auto'          # 'auto', 'lit', 'unlit'

# ===== Other =====
USE_PASSTHROUGH = False
ENVIRONMENT_MODEL = 'sightlab_resources/environments/RockyCavern.osgb'
USE_GUI = False
USE_SPEECH_RECOGNITION = True
SAVE_DATA = False

🧠 Example Use Cases

Field Idea Example
🧠 Psychology Generate phobic stimuli like a spider, a syringe
🦴 Education Spawn anatomy models: human skull, brain cross-section
➕ Math/Cognition Test symbolic vs object views: 3 apples, a number line
🧪 UX/VR Dev Prototype object-based interactions in VR
🎮 Game Studies On-demand in-scene assets for testing
🏛️ Architecture Blender generator: a park bench, a bookshelf with 4 shelves

💡 Tips

  • Generated models, concept images and Blender scripts are saved in Resources/, Resources/images/ and Resources/blender_scripts/.
  • Generated models are scaled so their largest side is MODEL_TARGET_SIZE (0.5 m). Blender models keep their real-world size, and large ones stand on the floor.
  • Object names are generated from the prompt text for traceability.
  • Short, concrete prompts work best for image-based generators: "a red fire hydrant" rather than a scene description.
  • If a request fails, the placeholder shows "Failed" and the console shows the provider's message (missing key, no credits, prompt rejected).
  • You can also drag and drop .glb, .gltf or .osgb models.