-
Notifications
You must be signed in to change notification settings - Fork 0
Explicit vs implicit properties #7
Comments
Even if it was already covered in multiple previous issues, for the sake of clarity this explains why JSON Scenegraph uses explicit properties (like VRML), not implicit properties (like XML). Implicit propertiesThe first main issue with implicit is it requires the 3D engine to guess / keep a list of which node type goes in which property based on the types of the child and the parent. The second main issue is it assumes that a given child node type can only match a single property of the parent: this works with non-ambigous cases like [
"CustomExampleNode": [
{
"Shape": [
{
"Box": [
{
"@size": [1, 2, 3]
}
]
},
{
"Box": [
{
"@size": [1, 2, 3]
}
]
}
],
"Transform": [
{
"@translation": [3, 0, 0],
"Shape": [
{
"Box": [
{
"@size": [1, 2, 3]
}
]
}
]
}
],
"DirectionalLight": [
{
"@color": [1, 1, 0.5]
}
]
}
]
] The XML workaround would have the child nodes specify the container field: [
"CustomExampleNode": [
{
"Shape": [
{
"@containerField": "firstProperty",
"Box": [
{
"@containerField": "geometry",
"@size": [1, 2, 3]
}
]
},
{
"@containerField": "secondProperty",
"Box": [
{
"@containerField": "geometry",
"@size": [1, 2, 3]
}
]
}
],
"Transform": [
{
"@containerField": "firstProperty",
"@translation": [3, 0, 0],
"Shape": [
{
"Box": [
{
"@containerField": "geometry",
"@size": [1, 2, 3]
}
]
}
]
}
],
"DirectionalLight": [
{
"@containerField": "secondProperty",
"@color": [1, 1, 0.5]
}
]
}
]
] It works, but it breaks our "Always write a node the same way given the same properties" principle because: {
"@containerField": "firstProperty",
"Box": [
{
"@size": [1, 2, 3]
}
]
} is not the same as: {
"@containerField": "secondProperty",
"Box": [
{
"@size": [1, 2, 3]
}
]
} despite both represent a Explicit propertiesWith explicit containers, a node given set of properties is always written the same way, regardless of what property contains it, and you don't have to guess which property the nodes belong to. [
{
"$": "CustomExampleNode",
"firstProperty": [
{
"$": "Shape"
"geometry": {
"$": "Box",
"size": [1, 2, 3]
}
},
{
"$": "Transform",
"translation": [3, 0, 0],
"children": [
{
"$": "Shape"
"geometry": {
"$": "Box",
"size": [1, 2, 3]
}
}
]
}
],
"secondProperty": [
{
"$": "Shape"
"geometry": {
"$": "Box",
"size": [1, 2, 3]
}
},
{
"$": "DirectionalLight",
"color": [1, 1, 0.5]
}
]
}
] |
Accessing deep valuesAnother issue with implicit is it makes it more complex to access something deep in the tree. ImplicitIn this example, reading the size of the
[
"CustomExampleNode": [
{
"Shape": [
{
"@containerField": "firstProperty",
"Box": [
{
"@containerField": "geometry",
"@size": [1, 2, 3]
}
]
},
{
"@containerField": "secondProperty",
"Box": [
{
"@containerField": "geometry",
"@size": [1, 2, 3]
}
]
}
],
"Transform": [
{
"@containerField": "firstProperty",
"@translation": [3, 0, 0],
"Shape": [
{
"Sphere": [
{
"@containerField": "geometry",
"@size": [5, 5, 5]
}
]
}
]
}
]
}
]
] ExplicitUsing explicit instead, the path is shorter:
[
{
"$": "CustomExampleNode",
"firstProperty": [
{
"$": "Shape"
"geometry": {
"$": "Box",
"size": [1, 2, 3]
}
},
{
"$": "Transform",
"translation": [3, 0, 0],
"children": [
{
"$": "Shape"
"geometry": {
"$": "Sphere",
"size": [5, 5, 5]
}
}
]
}
],
"secondProperty": [
{
"$": "Shape"
"geometry": {
"$": "Box",
"size": [1, 2, 3]
}
}
]
}
] It also is the same path that VRMLscript would use to access it. |
You might wonder:
The text was updated successfully, but these errors were encountered: