Convert 2D images to 3D GLB models using Fal.ai's sam-3/3d-objects model...
Convert 2D images to 3D GLB models using Fal.ai's sam-3/3d-objects model. This skill handles image validation, upload, 3D generation, and provides React Three Fiber integration examples through a standalone executable script.
imagePath (required): Absolute path to the source imagedescription (required): Original text description - used as segmentation prompt for Fal.aiprompt (optional): Additional guidance for 3D generation (defaults to description)Important: The description is used to guide SAM's auto-segmentation. It should clearly describe
the object in the image (e.g., "blue cube", "red donut", "sports car"). This tells SAM what to extract
from the image. Without a clear prompt, segmentation will fail.
Run the standalone script with JSON arguments:
npx tsx /Users/tomek/projects/kata-workshop-cc/.claude/skills/generate-3d-model/scripts/generate.ts '{
"imagePath": "/Users/tomek/projects/kata-workshop-cc/public/images/generated/image_red_cube_obstacle_20251203_153045.png",
"description": "red cube obstacle"
}'
With optional prompt guidance:
npx tsx /Users/tomek/projects/kata-workshop-cc/.claude/skills/generate-3d-model/scripts/generate.ts '{
"imagePath": "/Users/tomek/projects/kata-workshop-cc/public/images/generated/image_racing_car_20251203_154530.png",
"description": "blue racing car",
"prompt": "racing car with detailed wheels and aerodynamic body"
}'
The script outputs JSON to stdout:
{
"modelPath": "/Users/tomek/projects/kata-workshop-cc/public/3d/generated/model_red_cube_obstacle_20251203_153102.glb",
"imagePath": "/Users/tomek/projects/kata-workshop-cc/public/images/generated/image_red_cube_obstacle_20251203_153045.png",
"description": "red cube obstacle"
}
The model is automatically downloaded and saved to the local filesystem. The modelPath is an absolute path ready to use.
Progress messages are sent to stderr (e.g., "Generating 3D model (this will take 30-60 seconds)...", "Downloading GLB model...").
The script internally:
fal-ai/sam-3/3d-objectsOnce the GLB model is saved, provide this example to the user:
import { useLoader } from '@react-three/fiber'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
function RedCubeObstacle() {
const gltf = useLoader(
GLTFLoader,
'/3d/generated/model_red_cube_obstacle_20251203_153102.glb'
)
return (
<primitive
object={gltf.scene}
position={[0, 0, 0]}
scale={1}
/>
)
}
With physics (Rapier):
import { RigidBody } from '@react-three/rapier'
import { useLoader } from '@react-three/fiber'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
function PhysicsRedCubeObstacle() {
const gltf = useLoader(
GLTFLoader,
'/3d/generated/model_red_cube_obstacle_20251203_153102.glb'
)
return (
<RigidBody type="dynamic" colliders="hull">
<primitive object={gltf.scene} />
</RigidBody>
)
}
If an error occurs, the script:
{"error": "error message"}Common errors:
FAL_KEY not set: User needs to add API key to .envimagePath is required: Missing required field in JSON inputdescription is required: Missing required fieldImage not found or invalid: Image file doesn't exist at specified pathFal.ai API error: API call failed (check network, API key, quotas)npx tsxmodelPath, imagePath, and descriptionFor better 3D conversion quality, the source image should:
If the 3D model quality is poor, suggest to the user:
# Step 1: Generate the 3D model (get URL)
npx tsx .claude/skills/generate-3d-model/scripts/generate.ts '{
"imagePath": "/Users/tomek/projects/kata-workshop-cc/public/images/generated/image_blue_racing_car_20251203_154530.png",
"description": "blue racing car"
}'
Expected output:
{
"modelPath": "https://fal.run/files/abc123/model.glb",
"imagePath": "/Users/tomek/projects/kata-workshop-cc/public/images/generated/image_blue_racing_car_20251203_154530.png",
"description": "blue racing car"
}
npx tsx .claude/skills/generate-3d-model/scripts/generate.ts '{
"imagePath": "/Users/tomek/projects/kata-workshop-cc/public/images/generated/image_racing_car_20251203_154530.png",
"description": "racing car",
"prompt": "sports car with visible wheels and aerodynamic design"
}'
The script is located at: .claude/skills/generate-3d-model/scripts/generate.ts
It imports shared utilities from:
scripts/api/fal.ts - Fal.ai API clientscripts/utils/file-manager.ts - Image validationThis architecture ensures: