Skip to content

Implement PreviewBody3D node for lightweight object previews#181

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-52172743-f484-44a8-baac-9a378b5c4078
Draft

Implement PreviewBody3D node for lightweight object previews#181
Copilot wants to merge 4 commits intomainfrom
copilot/fix-52172743-f484-44a8-baac-9a378b5c4078

Conversation

Copy link
Contributor

Copilot AI commented Sep 29, 2025

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 Node3D with proper @export properties for editor integration
  • Provides configuration warnings for invalid setups
  • Uses StandardMaterial3D for 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 gdformat and syntax-validated with gdparse
  • 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 existing StaticBody3D or RigidBody3D. 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 PreviewBody3D node 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
Fixes #92

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 3 commits September 29, 2025 13:26
Co-authored-by: krazyjakee <623463+krazyjakee@users.noreply.github.com>
…ntation

Co-authored-by: krazyjakee <623463+krazyjakee@users.noreply.github.com>
Co-authored-by: krazyjakee <623463+krazyjakee@users.noreply.github.com>
Copilot AI changed the title [WIP] PreviewBody3D Implement PreviewBody3D node for lightweight object previews Sep 29, 2025
Copilot AI requested a review from krazyjakee September 29, 2025 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PreviewBody3D

2 participants