I want to have two custom properties in my schema, that have a fallback value if they are not defined, or if their value is below 0.0
this is the schema:
schema: {
url: { type: 'string'},
key: { type: 'string'},
intensity: {
// default is -100 to trigger fallback
default: -100,
parse: function (value) {
if (value >= 0.0) {
return value
}
return -100
}
}
}
The property that is giving me issues is the intensity property. If it is defined in the a-entity
<a-entity io3d-data3d="key: mykey; lightMapIntensity: 1.0" shadow="receive: true"></a-entity>
the value is properly used by the component, but when I open the a-frame 3d editor and click on the entity - I get this error:
this does not happen, if the attributes are not set in a-entity
.
Am I doing something wrong when using custom properties? Is there a way to define optional properties, that have undefined or null as a default value?
Custom Property Type:
https://aframe.io/docs/0.6.0/core/component.html#custom-property-type
The a-frame inspector tries to round up the values using the toFixed(decimalPlaces)
function.
The passed values in the component are strings, and as far as i know, toFixed()
does not work with strings, at least not in my experiments, nor in the documentation.
A simple solution is to return a parsed value:
if (value >= 0.0) {
return parseFloat(value);
}
Although when comparing strings with floats, it is doing some additional parsing, You may want to parse the value before the check:
value = parseFloat(value);
if (value >= 0.0) {
return value);
}