rewin123 / space_editor

bevy prefab editor
MIT License
386 stars 49 forks source link

Translation added each frame to subscene when inside the editor #305

Closed PiergiorgioZagaria closed 6 months ago

PiergiorgioZagaria commented 6 months ago

Describe the bug When importing a subscene, like for example a platform with a rigidbody, when modifying either the position or rotation, the subscene keeps moving by that transform when inside the editor, but stops when running the game

To Reproduce

https://github.com/rewin123/space_editor/assets/75474806/e6e555e6-f596-4429-b8a8-eaf70f73b6d1

Compiled with the following code:

use bevy::prelude::*;
use space_editor::prelude::*;

fn main() {
    App::default()
        .add_plugins((DefaultPlugins, SpaceEditorPlugin))
        .add_systems(Startup, simple_editor_setup)
        .run();
}

And the following dependencies:

[dependencies]
space_editor = { git = "https://github.com/rewin123/space_editor.git" }

[dependencies.bevy]
version = "0.13"
default-features = false
features = [
  "multi-threaded", # Run with multithreading
  "bevy_asset",     # Assets management
  "bevy_scene", # Scenes management
  "bevy_pbr",  # 3D (physically-based) rendering
  "bevy_gltf", # GLTF 3D assets format support
  "ktx2",      # Preferred format for GPU textures
  "zstd",      # ZSTD compression support in KTX2 files
  "asset_processor", # Asset processing
  "file_watcher",    # Asset hot-reloading
  "wayland",         # (Linux) Support Wayland windowing system
  "dynamic_linking",  # Dynamic linking for faster compile-times
  "embedded_watcher", # Hot-reloading for Bevy's internal/builtin assets
]

Expected behavior Setting the transform of the subscene shouldn't mae it move in the editor

Screenshots I uploaded the video as an example

Desktop (please complete the following information):

naomijub commented 6 months ago

We are a bit stalled this couple of months, and we'll take a look as soon as we have time. If you have an idea where this happens, you are welcomed to create a PR and ask for our support

rewin123 commented 6 months ago

I have little time to fix the bugs. I already tried to replicate the bug on a simple cube model on main branch, but everything worked correctly for me. Perhaps the problem is probably that conflicts with hot reload or I didn't cover some kind of data in your model when converting it to bevy scene. Would you feel comfortable sharing the 3d model from the video?

PiergiorgioZagaria commented 6 months ago

assets.tar.gz

Here it is. It's not mine, it comes from this github project (kenney.nl FPS starter kit for godot). I wanted to try and rewrite it in bevy

rewin123 commented 6 months ago

I was able to reproduce! I didn't immediately notice that you were using the "Open sub-scene" button. If our interface is confusing, canonically in space_editor you should use the leftmost button on the top panel to reopen saved editor scenes. That's exactly what opens the prefab.

image

rewin123 commented 6 months ago

"Open subscene" is designed to open gltf with skeletal animation and perceives the opened object as a model, which has a center of coordinates zero. But the bug with infinite rotation is certainly a bug and I will try to fix it!

PiergiorgioZagaria commented 6 months ago

How do you add a prefab to another scene then? That's what I wanted to do.

Like for example, I add the rigidbody and collider to the platform, make it a scene, and then import it a bunch of times in the main_game scene. This way I don't have to set the collider all the time I create a new platform.

Do I need to spawn it from code?

rewin123 commented 6 months ago

There are three paths we have in version 0.5.

  1. From the code
    commands
        .spawn(PrefabBundle::new("scenes/Scene0.scn.ron"))
        .insert(Name::new("Prefab"));
  2. We can add a PrefabLoader component to the entity and specify a asset path to existed prefab image
  3. Open subscene is also the way to solve this problem, after I fix the bug. But we have a number of improvements to these mechanics specifically in v0.6 branch
rewin123 commented 6 months ago

Additionally, you can use "Clone" for entities. For example, if you set the path once for a subprefab or colliders, you can easily reproduce it. It allows you to clone an entity and all its children and all its components. It is available either through the context menu in the Hierarchy panel or by holding Alt and pulling the gizmo in the entity move mode. You can even clone multiple entities with Alt+Shift

rewin123 commented 6 months ago

I figured out the cause of the problem. bevy_xpbd glitches if rigidbody has some parent and starts to continuously shift/rotate by the parent's transform value. As far as I remember everything worked in the old version of bevy_xpbd and this is some new changes or I don't remember well, but in any case I need to create a mechanism to load prefabs without creating additional parents. It is not difficult and it will take me hopefully only two days. I'll add it to the 0.6 branch and post here when I'm done and check that there are no more problems with the new mechanism for rigidbody.

EDIT Never mind, I found my code that fixed the hierarchy bug for the old version of bevy_xpbd and it just conflicted with the new version of bevy_xpbd where everything works. Will fix soon

rewin123 commented 6 months ago

@PiergiorgioZagaria Looks working for me #306

PiergiorgioZagaria commented 6 months ago

Works for me too, just tested the branch :+1: . Do I close the issue or wait until it's merged?

rewin123 commented 6 months ago

I will merge ang close. Thanks for bug report and help!