static object FromVector3(object obj, DocNode value) { // TODO (Graham): Make a non-boxing version of this? // TODO (Graham): The scalar and n-dimensional support here is non-obvious. Those cases seem like they'd be nearly always mistakes. Better to throw an exception here. var parsedType = value.Type; if (parsedType == DocNodeType.Scalar) // Vector3, 3 => new Vector3(3,3, 3); { float single = value.As <float>(); return(new Vector3(single, single, single)); } // Vector3, [1,2,3] => new Vector2(1,2,3); float x = value[0].As <float>(); float y = x; float z = x; if (value.Count > 1) { y = value[1].As <float>(); z = 0; } if (value.Count > 2) { z = value[2].As <float>(); } return(new Vector3(x, y, z)); }
static object FromVector2(object obj, DocNode value) { // TODO (Graham): Make a non-boxing version of this? // TODO (Graham): The scalar and n-dimensional support here is non-obvious. Those cases seem like they'd be nearly always mistakes. Better to throw an exception here. var parsedType = value.Type; // Parse a scalar float and use that for both components of the vector. // 3 => new Vector2(3,3) if (parsedType == DocNodeType.Scalar) { var single = value.As <float>(); return(new Vector2(single, single)); } // Parse a list of floats and use those as the vector components. // Supports the following conversions: // [1] => Vector2(1,1) // [1,2] => new Vector2(1,2); // [1,2,3,4,5,6] => new Vector2(1,2); float x = value[0].As <float>(); float y = x; if (value.Count > 1) { y = value[1].As <float>(); } return(new Vector2(x, y)); }