AmbientRun / Ambient

The multiplayer game engine
https://ambient.run
Apache License 2.0
3.79k stars 122 forks source link

importing models does not import scale from blender #848

Open droqen opened 1 year ago

droqen commented 1 year ago

Image of model as viewed in 'Windows 3D Viewer' as well as Blender, Godot: image

Image of model imported into Ambient via model_from_url or prefab_from_url: image

In Blender, the problem is clear: The model's vertices are being imported, but not its transform data.

See import: image

See import with scale set to 1, 1, 1: image

kevzettler commented 1 year ago

can share the model for testing or you can confirm behavior when you import the model in : https://sandbox.babylonjs.com/

and

https://gltf-viewer.donmccurdy.com/

droqen commented 1 year ago

Good point. I've attached a zipped really_tall_lumpy_wall.glb file which renders in the 'correct' way in both those importers but not Ambient:

really_tall_lumpy_wall.zip

And this is a version with transformations applied, tall_noscale.glb (note the texture looks a bit different, it's weird), which works the same in everything:

tall_noscale.zip

FredrikNoren commented 1 year ago

I took a look; the model is processed correctly in the asset pipeline, this is the outputed main.json:

{
    "AQAAAAAAAAAAAAAAAAAAAA": {
        "ambient_core::app::name": "really_tall_lumpy_wall.glb",
        "ambient_core::hierarchy::children": [
            "3_VYN2ucw3IDBOM03tv-bQ"
        ],
        "ambient_core::transform::local_to_parent": [
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0
        ],
        "ambient_core::rendering::local_bounding_aabb": {
            "min": [
                -4.9624176,
                -0.79670465,
                -14.395552
            ],
            "max": [
                5.214872,
                0.78311956,
                13.87838
            ]
        },
        "ambient_core::model::model_skins": []
    },
    "3_VYN2ucw3IDBOM03tv-bQ": {
        "ambient_core::animation::bind_id": "Cube",
        "ambient_core::app::name": "Cube",
        "ambient_core::transform::rotation": [
            0.0,
            0.0,
            0.0,
            1.0
        ],
        "ambient_core::transform::scale": [
            4.590142,
            13.87838,
            0.22796158
        ],
        "ambient_core::transform::translation": [
            0.0,
            0.0,
            0.0
        ],
        "ambient_core::rendering::local_bounding_aabb": {
            "min": [
                -1.0811033,
                -1.0372646,
                -3.4949076
            ],
            "max": [
                1.1361026,
                1.0,
                3.4353137
            ]
        },
        "ambient_core::model::pbr_renderer_primitives_from_url": [
            {
                "mesh": "../meshes/Cube_0_0.mesh",
                "material": "../materials/Material_0.json",
                "lod": 0
            }
        ]
    }
}

The problem might be here: https://github.com/AmbientRun/Ambient/blob/main/crates/model/src/model.rs#L553 (Since it's only got one child this will be processed as a single-entity model).

Path forward:

  1. Create a test case in examples/assets with this model
  2. Set breakpoints and verify if the matrices used on that line are right or not; I don't remember if those are created