How vinhhien112/img2obj works
Purpose and Entry Points
img2obj is a local Codex plugin that turns a reference image into a quality-gated procedural Three.js asset: a structured sculpt specification plus generated TypeScript factory code. Plugin discovery begins at .codex-plugin/plugin.json; the unified Python CLI is scripts/sculpt.py. The Codex-facing workflow and modeling guidance live in skills/object-to-threejs-procedural/SKILL.md.
Reference Intake and Feasibility
Reference images are assessed before modeling for visibility, separation, complexity, and usable views. scripts/new_pre_spec_assessment.py creates the assessment, while scripts/probe_reference_image.py extracts image evidence and scripts/visual_feature_gate.py enforces visual-feature readiness. This boundary prevents unsupported or ambiguous references from silently becoming geometry plans.
ObjectSculptSpec Contract
The central artifact is an ObjectSculptSpec, which records hierarchy, parts, geometry intent, materials, pivots, sockets, critical features, phase status, and review requirements. Its contract and validation are implemented in scripts/sculpt_contract.py and scripts/validate_sculpt_spec.py; spec creation/migration is handled by scripts/new_sculpt_spec.py and scripts/migrate_sculpt_spec.py. All later stages consume this structured plan rather than infer directly from pixels.
Pass-Orchestrated Production Workflow
Model creation advances through controlled phases—blockout, form, lookdev, and interaction—rather than generating a finished asset in one step. scripts/sculpt_pass_orchestrator.py controls transitions and dependencies; scripts/sculpt_checkpoint.py persists phase checkpoints; scripts/sculpt_user_approval.py gates promotion on explicit approval. The workflow uses state and module abstractions in scripts/sculpt_module_state.py and scripts/sculpt_modules.py.
Procedural Geometry and Generated Output
The generator emits code-only Three.js construction logic intended for a separate browser/Three.js project. Core geometry construction is in scripts/sculpt_geometry.py, with TypeScript factory emission in scripts/generate_threejs_factory.py. Specialized procedural domains are deliberately separated: scripts/sculpt_tree_generator.py, scripts/sculpt_landform_generator.py, and scripts/sculpt_special_geometry_typescript.py. Generated code is the integration boundary; this repository does not host the runtime renderer/application.
Materials, Style, and Reference-Derived PBR
Style classification and material intent are captured before look development through scripts/sculpt_style.py and scripts/sculpt_perception.py. scripts/extract_reference_pbr.py can derive palette and PBR-oriented evidence from the source image. Capability-specific guidance for glass, fur, fabric, emissive effects, vegetation, and hard surfaces is maintained under skills/object-to-threejs-procedural/references/patterns/.
Visual Review and Correction Loop
The quality system compares rendered browser screenshots against the active reference, emphasizing both overall identity and critical recognizable features. Review artifacts are organized by scripts/sculpt_image_io.py and scripts/make_visual_comparison_sheet.py; review decisions and corrections flow through scripts/sculpt_module_review.py and scripts/sculpt_corrections.py. AI image/vision access is an external dependency for source cleanup, planned views, and acceptance judgment; local Python scripts package evidence but do not independently determine visual similarity.
Runtime and Infrastructure Boundaries
The control plane is Python 3.10+ CLI tooling and Codex plugin/skill instructions. Output targets TypeScript and Three.js in an external browser project, where rendering, screenshots, controls, and animation execute. No database, server, or hosted service is represented in the repository; external AI vision is required for final visual review.
Components 20
Plugin Interface
- Plugin manifest
.codex-plugin/plugin.json - Codex workflow guidance
skills/object-to-threejs-procedural/SKILL.md - Unified sculpt CLI
scripts/sculpt.py
Reference & Spec
- Pre-spec assessment
scripts/new_pre_spec_assessment.py - Reference image probe
scripts/probe_reference_image.py - Visual feature gate · Rejects ambiguous references before planning.
scripts/visual_feature_gate.py - ObjectSculptSpec · Records parts, geometry, materials, pivots, sockets, features, and review state.
scripts/sculpt_contract.py - Spec creation & migration
scripts/new_sculpt_spec.py - Spec validation
scripts/validate_sculpt_spec.py - Style & PBR evidence
scripts/sculpt_style.py
Pass Control
- Pass orchestrator · Advances blockout, form, lookdev, and interaction phases.
scripts/sculpt_pass_orchestrator.py - Checkpoints & module state
scripts/sculpt_checkpoint.py - User approval gate
scripts/sculpt_user_approval.py
Generation & Review
- Procedural geometry
scripts/sculpt_geometry.py - Specialized generators · Separate tree, landform, and special geometry generation.
scripts/sculpt_tree_generator.py - Three.js factory emitter
scripts/generate_threejs_factory.py - Generated TypeScript factory · Code-only output consumed by a separate browser project.
- Visual review & corrections · Packages comparison evidence and routes review corrections.
scripts/make_visual_comparison_sheet.py
Other components
- External AI vision · Provides source cleanup, view planning, and visual acceptance judgment.
- External browser / Three.js runtime · Renders generated assets, screenshots, controls, and animation.
Connections 25
- Plugin manifest → Codex workflow guidance: discovers
- Codex workflow guidance → Unified sculpt CLI: guides
- Unified sculpt CLI → Pre-spec assessment: starts
- Pre-spec assessment → Reference image probe: collects evidence
- Reference image probe → Visual feature gate: supplies evidence
- Visual feature gate → Spec creation & migration: permits planning
- Spec creation & migration → ObjectSculptSpec: creates or migrates
- ObjectSculptSpec → Spec validation: validated against
- Reference image probe → Style & PBR evidence: informs
- Style & PBR evidence → ObjectSculptSpec: adds material intent
- Spec validation → Pass orchestrator: authorizes
- Pass orchestrator → Checkpoints & module state: persists phase state
- Checkpoints & module state → User approval gate: requests promotion
- User approval gate → Pass orchestrator: approves next phase
- Pass orchestrator → Procedural geometry: drives implementation
- ObjectSculptSpec → Procedural geometry: defines construction
- Procedural geometry → Specialized generators: uses when applicable
- Procedural geometry → Three.js factory emitter: provides construction logic
- Specialized generators → Three.js factory emitter: contributes code
- Three.js factory emitter → Generated TypeScript factory: emits
- Generated TypeScript factory → External browser / Three.js runtime: integrates into
- External browser / Three.js runtime → Visual review & corrections: provides screenshots
- Visual review & corrections → External AI vision: requests judgment
- External AI vision → Visual review & corrections: returns acceptance feedback
- Visual review & corrections → Pass orchestrator: sends corrections