
# Build a Realistic Interactive 3D Printer Simulator Create...
Prompt
# Build a Realistic Interactive 3D Printer Simulator Create a polished browser-based 3D printer simulator that prints objects visibly, line by line and layer by layer. Your response must contain **exactly one code block** with one complete `index.html` file. Do not include explanations or text outside the code block. ## Constraints * Use HTML, CSS, JavaScript, and Three.js. * Three.js and OrbitControls may load from a public CDN. * No npm, build tools, React, TypeScript, external assets, textures, models, or extra files. * The result must run by saving it as `index.html` and opening it in a modern desktop browser. * Everything must be implemented inside that single file. * Do not use G-code. * Do not fake printing by revealing, scaling, or raising a finished mesh. * Deposited filament must be generated from the actual animated nozzle path. ## Goal Build a convincing Cartesian FDM 3D printer with: * printer frame, rails, gantry, carriage, hot end, nozzle, and print bed; * mechanically coherent X, Y, and Z movement; * filament spool and visible feed strand; * realistic procedural filament deposition; * slicing preview; * configurable print settings; * live printer telemetry; * heating, homing, printing, pausing, cancellation, and completion; * simulation speeds from `0.25×` to `50×`. Correct printing behavior is more important than decorative detail. ## Printable objects Allow the user to select: 1. `Circle` — cylinder; 2. `Triangle` — equilateral triangular prism; 3. `Square` — square rectangular prism. Each object must be created from individually printed layers. ## Printer mechanics Use either a bed-slinger or gantry design, but its movement must be coherent. Requirements: * the nozzle has a real world-space tip position; * visible printer parts stay synchronized with that position; * the print remains fixed to the bed; * the gantry or nozzle rises after each layer; * components must not detach, drift, teleport, or intersect incorrectly; * the printer starts from a realistic home position. ## Critical nozzle alignment Extrusion must appear to leave the physical nozzle tip and touch the bed or previous layer. Calculate consistently: * bed-top height; * nozzle-tip offset; * current layer height; * extrusion strand center; * active printed surface. The first-layer filament must visibly contact the bed. Later filament must visibly contact the layer below it. The nozzle must not float far above the print or sink through it. ## Procedural slicer Implement a simplified deterministic slicer for the three objects. Generate an ordered list of travel and extrusion segments. Each segment must store: * layer index; * movement type; * start and end coordinates; * distance; * feed rate; * extrusion amount; * cumulative simulated time; * cumulative filament use. For every layer: 1. generate configurable perimeter walls; 2. generate internal infill; 3. order paths sensibly; 4. include non-extruding travel where needed; 5. never extrude across empty space; 6. alternate infill direction between layers. Use enough circle segments for a smooth cylinder. Preserve sharp triangle and square corners. ## Infill Support `0%` to `100%` infill. Infill must modify the actual toolpath: * `0%`: walls only; * low values: widely spaced lines; * medium values: denser lines; * `100%`: nearly solid coverage without severe overlap. Use clipped rectilinear, line, or grid infill. No infill line may extend outside the selected shape. ## Settings Provide controls for: * shape; * width; * depth when applicable; * height; * layer height; * nozzle diameter; * wall count; * infill percentage; * filament diameter; * filament color; * print speed; * travel speed; * animation multiplier from `0.25×` to `50×`; * nozzle target temperature; * bed target temperature. Use reasonable defaults and ranges. Changing geometry settings while idle must regenerate the preview and statistics. Prevent unsafe setting changes during an active print. ## Toolpath preview Before printing, display the actual generated path. Include: * complete-path and single-layer views; * layer slider; * travel-path visibility toggle; * visually distinct walls, infill, and travel; * current layer and total layers; * selected-layer segment count and path length; * total extrusion path length; * estimated filament use; * estimated print time. The preview and print simulation must use the exact same toolpath. ## Filament deposition During an extrusion segment, filament must grow continuously from the segment start toward the moving nozzle. The strand must: * have visible thickness; * use the selected color; * appear rounded or slightly flattened; * follow straight lines, curves, and corners; * remain permanently deposited; * never flicker or disappear when paused; * not stretch incorrectly after speed changes; * never remain attached to the nozzle after deposition. Use efficient procedural geometry. Avoid creating an excessive number of independent meshes. Merge, batch, or reuse geometry where practical. ## First layer Generate and print at least one real first-layer feature: * skirt; * brim; * or purge line. It must be included in the toolpath and physically followed by the nozzle. The first layer may print slower and appear slightly wider than later layers. ## Printer Brain Create a clearly visible `Printer Brain` telemetry panel showing live values from the same state that controls the 3D model: * state; * X, Y, and Z; * nozzle-tip world position; * target position; * current layer and total layers; * current segment and total segments; * movement type; * feed rate; * extruding yes/no; * cumulative extrusion; * deposited path length; * completion percentage; * elapsed simulated time; * remaining time; * nozzle current and target temperature; * bed current and target temperature. Do not show random or disconnected telemetry. ## Thermal and state simulation Support these states: * Idle * Heating * Homing * Printing * Paused * Completed * Cancelled * Error Temperatures must gradually approach their targets. Printing may begin only when the nozzle and bed are close enough to target temperatures. After completion or cancellation, temperatures should cool gradually toward room temperature. ## Motion engine Use one `requestAnimationFrame` loop with delta time. For each segment: * calculate duration from distance and feed rate; * interpolate movement over time; * synchronize all moving printer parts; * progressively deposit filament during extrusion; * finish the exact endpoint before moving to the next segment. Travel moves must be faster than extrusion moves. The simulation must not depend on frame rate. ## Critical `50×` behavior The simulator must work correctly at up to `50×`. A single rendered frame may contain enough simulated time to finish multiple segments. Implement a loop that consumes the available simulated delta across as many segments as necessary. At high speed: * do not skip path sections; * do not lose extrusion; * do not corrupt layers; * keep telemetry synchronized; * remain responsive; * produce the same final print as at `1×`. Do not implement high speed by teleporting directly to the finished object. ## Controls Provide working controls for: * Slice / Regenerate * Start * Pause * Resume * Cancel * Reset * speed multiplier * preview mode * layer selection * travel visibility * camera reset Button availability must match the current state. Pause/resume must preserve exact progress without duplicating filament. Cancel must stop future movement safely. Reset must clear the print and allow another full run. ## Interface Create a polished, responsive industrial-control interface containing: * large 3D viewport; * settings panel; * Printer Brain panel; * preview statistics; * status and progress bar; * active layer; * elapsed and remaining time; * filament estimate; * speed multiplier. The interface must remain usable on a typical desktop display. ## Scene quality Include: * perspective camera; * OrbitControls; * shadows; * ambient and directional lighting; * workshop floor or grid; * believable metal, plastic, glass, bed, nozzle, and filament materials; * responsive resize handling. Provide camera presets: * Perspective * Front * Side * Top * Nozzle close-up Optional details include a rotating spool, cooling fan, belts, lead screws, bed markings, status lights, LCD screen, subtle vibration, and temperature-dependent nozzle glow. ## Validation Validate settings and display readable errors for: * object larger than the bed; * zero, negative, or malformed dimensions; * invalid layer or nozzle sizes; * layer height greater than nozzle diameter; * impossible wall thickness; * missing or empty toolpath. Do not silently fail. ## Architecture Organize the code into clear classes or modules, for example: * `Slicer` * `Toolpath` * `PrinterModel` * `MotionController` * `ExtrusionRenderer` * `ThermalController` * `PreviewRenderer` * `TelemetryUI` * `PrinterSimulator` Avoid one giant unstructured script. ## Performance The application should handle thousands of path segments. Do not: * rebuild the entire scene every frame; * recalculate slicing every frame; * create a separate animation loop per segment; * leak replaced geometry or materials; * duplicate deposited filament after pause/resume; * create hundreds of thousands of separate meshes; * freeze the interface with unnecessary processing. ## Diagnostics Include a diagnostics panel or console assertions checking: 1. first-layer extrusion aligns with the bed; 2. normal extrusion stays inside the selected shape; 3. layer count matches object height and layer height; 4. the toolpath contains travel and extrusion segments; 5. cumulative time and length never decrease; 6. every processed movement reaches its exact endpoint; 7. pause/resume does not duplicate deposited geometry; 8. `50×` deposits the same complete toolpath as `1×`. ## Acceptance criteria The solution succeeds only when: * it runs as one saved HTML file; * the scene resembles a functioning 3D printer; * all three shapes can be sliced and printed; * nozzle movement follows an ordered toolpath; * filament is deposited progressively behind the nozzle; * the nozzle visibly touches the active print surface; * every layer, perimeter, and infill line is genuinely printed; * infill percentage changes actual path density; * preview and printing use the same path; * pause, resume, cancel, reset, and repeated prints work; * speeds through `50×` do not skip extrusion; * Printer Brain coordinates match the visible nozzle; * thermal transitions behave coherently; * the final object matches the configured dimensions; * no major console errors occur. ## Final output Return exactly one `html` code block containing the complete `index.html`. Do not explain the code. Do not omit major requirements because the task is difficult.
A system prompt was added to support web rendering