Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

"$: Shape" vs "Shape: [" #1

Closed
cecilemuller opened this issue Oct 16, 2014 · 1 comment
Closed

"$: Shape" vs "Shape: [" #1

cecilemuller opened this issue Oct 16, 2014 · 1 comment
Labels

Comments

@cecilemuller
Copy link
Member

This was a question from the X3D mailing-list:

how is
"$": "Shape",

different than
"Shape": [

The "$" doesn't add any information per se.

(Edit: $ used to be named _type at the time)

@cecilemuller
Copy link
Member Author

"Shape": [

Let's say we use the second syntax: it's great when there is only one node of each type, that the container property is obvious and if you don't mind losing the order of the nodes (given the parser might re-order properties alphabetically):

{
    "Group": {
        ...
        "Transform": {
            ...
        },
        "Shape": {
            ...
        }
    }
}

How would you make a Group that contains a Shape, a Transform and another Shape ?
It can't be the following because an Object can't define property Shape twice:

{
    "Group": {
        ...
        "Shape": {
            ...
        },
        "Transform": {
            ...
        },
        "Shape": {
            ...
        }
    }
}

So it would probably end up like this, which is already 5 levels of nesting:

{
    "Group": {
        ...
        "@children": [
            {
                "Shape": {
                    ...
                }
            },
            {
                "Transform": {
                    ...
                }
            },
            {
                "Shape": {
                    ...
                }
            }
        ]
    }
}

If you don't mind losing the order of nodes and if there is only one possibly property where children nodes are meant to be stored, you could group nodes by type:

{
    "Group": {
        ...
        "Shape": [
            {
                ...
            },
            {
                ...
            }
        ],
        "Transform": [
            {
                ...
            }
        ]
    }
}

But if you have a special node with two MFNode properties that both expect Shape/Transform nodes, it would have to specify the container property and you're back to 5 levels of nesting:

{
    "SpecialGroup": {
        ...
        {
            "@someChildren": {
                "Shape": [
                    {
                        ...
                    },
                    {
                        ...
                    }
                ],
                "Transform": [
                    {
                        ...
                    }
                ]
            },
            "@otherChildren": {
                "Shape": [
                    {
                        ...
                    },
                    {
                        ...
                    }
                ],
                "Transform": [
                    {
                        ...
                    }
                ]
            }
        }
    }
}

$

Compare to this structure:

{
    "$": "Group",
    ...
    "children": [
        {
            "$": "Shape"
            ...
        },
        {
            "$": "Transform"
            ...
        },
        {
            "$": "Shape"
            ...
        }
    ]
}

Its advantages:

  • only 3 levels of nesting
  • doesn't lose the order of the nodes
  • doesn't require guessing in which property the subnodes are stored
  • each object is meaningful without knowing the property in which it's contained

@cecilemuller cecilemuller changed the title "_type Shape" vs "Shape {}" "_type: Shape" vs "Shape: [" Oct 16, 2014
@cecilemuller cecilemuller changed the title "_type: Shape" vs "Shape: [" "$: Shape" vs "Shape: [" Dec 21, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant