Skip to content

Conversation

Licini
Copy link
Contributor

@Licini Licini commented May 27, 2025

Not done @tomvanmele just for you to compare, if you run this

from compas.scene import Scene
from compas.geometry import Box
from compas import json_dumps

scene = Scene()

box = Box(1, 1, 1)
obj1 = scene.add(box, name="BoxObj1")
obj2 = scene.add(box, name="BoxObj2", parent=obj1)

print(scene)

json_str = json_dumps(scene, pretty=True)
print(json_str)

You will get serialization like:

└── <TreeNode: Scene>
    └── BoxObj1
        └── BoxObj2
{
    "data": {
        "attributes": {},
        "datastore": {
            "86a97961-b36e-461e-a77f-eddaf07ae697": {
                "data": {
                    "frame": {
                        "point": [
                            0.0,
                            0.0,
                            0.0
                        ],
                        "xaxis": [
                            1.0,
                            0.0,
                            0.0
                        ],
                        "yaxis": [
                            0.0,
                            1.0,
                            0.0
                        ]
                    },
                    "xsize": 1.0,
                    "ysize": 1.0,
                    "zsize": 1.0
                },
                "dtype": "compas.geometry/Box",
                "guid": "86a97961-b36e-461e-a77f-eddaf07ae697"
            }
        },
        "name": "Scene",
        "tree": {
            "data": {
                "attributes": {},
                "root": {
                    "children": [
                        {
                            "children": [
                                {
                                    "color": null,
                                    "item": "86a97961-b36e-461e-a77f-eddaf07ae697",
                                    "name": "BoxObj2",
                                    "opacity": 1.0,
                                    "show": true,
                                    "transformation": null
                                }
                            ],
                            "color": null,
                            "item": "86a97961-b36e-461e-a77f-eddaf07ae697",
                            "name": "BoxObj1",
                            "opacity": 1.0,
                            "show": true,
                            "transformation": null
                        }
                    ],
                    "name": "Scene"
                }
            },
            "dtype": "compas.datastructures/Tree",
            "guid": "1d28f541-1e02-40b0-acf5-977319d71237",
            "inheritance": []
        }
    },
    "dtype": "compas.scene/Scene",
    "guid": "ac425fa8-2a6d-4fd1-9036-77cf97a8716e",
    "inheritance": []
}

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.

1 participant