Implement PreviewBody3D node for lightweight object previews
This PR introduces a new PreviewBody3D node that generates lightweight, non-interactive visual representations of existing StaticBody3D or RigidBody3D objects. This addresses the need for placement preview systems in level editors and in-game building mechanics.
Overview
The PreviewBody3D node automatically inherits meshes from a source body and provides customizable visual effects like transparency, color tinting, and wireframe display. It's designed to solve the common problem of manually duplicating and configuring preview objects for placement systems.
Key Features
Automatic Mesh Discovery: Recursively finds and copies all MeshInstance3D nodes from the source body, maintaining their relative transforms and hierarchy.
Flexible Collision Modes:
- None: No collision shapes (default for performance)
- Bounding Box: Single box collision based on combined mesh bounds
- Exact Shapes: Copies all collision shapes from the source
Visual Customization:
- Transparency control (0.0 - 1.0)
- Color tinting with any color
- Optional wireframe overlay mode
Performance Optimized: Preview meshes have physics simulation, shadows, and global illumination disabled for lightweight rendering.
Usage Example
# Create a preview of a building block
var preview = PreviewBody3D.new()
preview.source_body = my_building_block # StaticBody3D with mesh and collision
preview.transparency = 0.5
preview.color_tint = Color.CYAN
preview.collision_mode = 1 # Bounding box collision
add_child(preview)
# Control visibility
preview.show_preview()
preview.hide_preview()
Implementation Details
The node follows established Nodot patterns:
- Extends
Node3Dwith proper@exportproperties for editor integration - Provides configuration warnings for invalid setups
- Uses
StandardMaterial3Dfor consistent material handling - Implements proper cleanup and resource management
- Deferred initialization ensures robust node setup
Quality Assurance
- Comprehensive Testing: 12 unit tests covering all functionality using the VestTest framework
-
Code Standards: Formatted with
gdformatand syntax-validated withgdparse - Documentation: Complete API documentation with usage examples
- Demo Scene: Interactive example showcasing nested meshes and all features
This implementation eliminates the need for manual duplication of mesh/collider nodes and provides guaranteed visual consistency with source objects, making it ideal for placement systems, building mechanics, and interactive visualization tools.
Original prompt
This section details on the original issue you should resolve
<issue_title>PreviewBody3D</issue_title> <issue_description>Summary
Introduce a new node type (e.g.PreviewBody3D) that enables developers to generate a lightweight, non-interactive visual representation of an existingStaticBody3DorRigidBody3D. This representation automatically inherits the meshes (and optionally the collision shapes) from the source object and can be customized with visual effects, such as transparency, wireframe display, and color tinting.
Motivation / Use Case
When designing placement systems (e.g. in level editors or in-game building systems), developers often need to preview how a physical object (static or rigid) will look before it is actually placed in the scene. This involves:
- Matching the mesh/shape of the final body for accurate preview positioning.
- Visually indicating that the preview is a ghost representation (e.g. semi-transparent or tinted).
- Avoiding unnecessary duplication of mesh/collider nodes and duplication of logic.
Currently, this requires manual duplication and shader/material tweaking for each body, which can be repetitive and error-prone.
Proposed Solution
- A
PreviewBody3Dnode that references another body as its source.- On assignment, it scans all child meshes of the source and renders a lightweight copy in preview mode.
- Optionally imports the collision shapes (with a toggle: none, bounding box only, exact shapes).
- Provides built-in preview material settings:
- Global transparency amount.
- Color tint.
- Optional wireframe overlay.
- Excludes physics simulation and collision layers by default (to avoid interfering with gameplay physics).
Benefits
- Quality of Life: Simplifies placement previews for building and editing systems.
- Consistency: Guarantees exact visual match with the target object (no manual syncing).
- Performance: By default, avoids unnecessary collision unless explicitly enabled.
- Flexibility:</issue_description>
Comments on the Issue (you are @copilot in this section)
@krazyjakee https://docs.godotengine.org/en/stable/classes/class_springarm3d.html
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.