/// <summary> /// Converts a VtValue to a SerializedProperty, to reconstruct the USD scene in Unity. /// </summary> static public void VtValueToProp(SerializedProperty prop, pxr.VtValue val) { switch (prop.propertyType) { case SerializedPropertyType.AnimationCurve: // TODO: needs to be broken down into atoms. throw new System.NotImplementedException(); case SerializedPropertyType.ArraySize: //prop.intValue = (int)val; break; case SerializedPropertyType.Boolean: prop.boolValue = (bool)val; break; case SerializedPropertyType.Bounds: prop.boundsValue = UnityTypeConverter.BoundsFromVtArray(val); break; case SerializedPropertyType.BoundsInt: // TODO: add this to UnityTypeConverter. var bnds = UnityTypeConverter.BoundsFromVtArray(val); var center = new Vector3Int((int)bnds.center.x, (int)bnds.center.y, (int)bnds.center.z); var size = new Vector3Int((int)bnds.size.x, (int)bnds.size.y, (int)bnds.size.z); prop.boundsIntValue = new BoundsInt(center, size); break; case SerializedPropertyType.Character: prop.intValue = (int)val; break; case SerializedPropertyType.Color: prop.colorValue = UnityTypeConverter.Vec4fToColor(val); break; case SerializedPropertyType.Enum: prop.enumValueIndex = (int)val; break; case SerializedPropertyType.ExposedReference: // TODO. //prop.exposedReferenceValue; throw new System.NotImplementedException(); case SerializedPropertyType.FixedBufferSize: //prop.fixedBufferSize = (int)val; // TODO. throw new System.NotImplementedException(); case SerializedPropertyType.Float: prop.floatValue = (float)val; break; case SerializedPropertyType.Generic: throw new System.Exception(); case SerializedPropertyType.Gradient: // TODO: gradientValue accessor is not public. wat? throw new System.NotImplementedException(); case SerializedPropertyType.Integer: prop.intValue = (int)val; break; case SerializedPropertyType.LayerMask: prop.intValue = (int)val; break; case SerializedPropertyType.ObjectReference: /* * var v2i = (pxr.GfVec2i)val; * if (v2i[0] == 0 && v2i[1] == 0) { * break; * } * Debug.Log("FileID: " + v2i[0] + " PathID: " + v2i[1]); */ if (val.IsEmpty()) { break; } string strValue = pxr.UsdCs.VtValueTostring(val); if (string.IsNullOrEmpty(strValue)) { break; } string[] names = strValue.Split(':'); int pathId = int.Parse(names[0]); var guid = names[1]; int fileId = int.Parse(names[2]); string assetPath = AssetDatabase.GUIDToAssetPath(guid); Object[] objs = AssetDatabase.LoadAllAssetsAtPath(assetPath); Object obj = objs[pathId]; Debug.Log("pathId: " + pathId + " fileId: " + fileId + " guid: " + guid.ToString() + " obj: " + obj.ToString()); //break; /* TODO: * string expectedName = names[2]; * if (objs[index].name != expectedName) { * Debug.LogWarning("Expected name '" + expectedName + "' but found '" + objs[index].name + "'"); * } */ prop.FindPropertyRelative("m_PathID").intValue = pathId; prop.FindPropertyRelative("m_FileID").intValue = fileId; prop.objectReferenceValue = obj; break; case SerializedPropertyType.Quaternion: prop.quaternionValue = UnityTypeConverter.QuatfToQuaternion(val); break; case SerializedPropertyType.Rect: prop.rectValue = UnityTypeConverter.Vec4fToRect(val); break; case SerializedPropertyType.RectInt: var rect = UnityTypeConverter.Vec4fToRect(val); prop.rectIntValue = new RectInt((int)rect.xMin, (int)rect.yMin, (int)rect.width, (int)rect.height); break; case SerializedPropertyType.String: var s = (string)val; if (s == null) { break; } prop.stringValue = (string)val; break; case SerializedPropertyType.Vector2: prop.vector2Value = UnityTypeConverter.Vec2fToVector2(val); break; case SerializedPropertyType.Vector2Int: // TODO: add this to UnityTypeConverter. var v2 = (pxr.GfVec2i)val; prop.vector2IntValue = new Vector2Int(v2[0], v2[1]); break; case SerializedPropertyType.Vector3: prop.vector3Value = UnityTypeConverter.Vec3fToVector3(val); break; case SerializedPropertyType.Vector3Int: // TODO: add this to UnityTypeConverter. var v3 = (pxr.GfVec3i)val; prop.vector3IntValue = new Vector3Int(v3[0], v3[1], v3[2]); break; case SerializedPropertyType.Vector4: prop.vector4Value = UnityTypeConverter.Vec4fToVector4(val); break; } }