diff --git a/Assets/BundleAdustment.meta b/Assets/BundleAdustment.meta index 406cb35..6bd2f55 100644 --- a/Assets/BundleAdustment.meta +++ b/Assets/BundleAdustment.meta @@ -1,9 +1,10 @@ fileFormatVersion: 2 guid: b520f7f53d7044d4d9100d2292ce070a folderAsset: yes -timeCreated: 1483993478 +timeCreated: 1507413892 licenseType: Free DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/BundleAdustment/BundleAdjuster.cs b/Assets/BundleAdustment/BundleAdjuster.cs index 055abed..0ec6a6f 100644 --- a/Assets/BundleAdustment/BundleAdjuster.cs +++ b/Assets/BundleAdustment/BundleAdjuster.cs @@ -7,9 +7,9 @@ public class BundleAdjuster : MonoBehaviour { Vector3[][] rayDirections; KabschSolver solver = new KabschSolver(); - Vector3[] inPoints, refPoints; + Vector4[] inPoints; Vector3[] refPoints; void Start () { - inPoints = new Vector3[features.Length]; + inPoints = new Vector4[features.Length]; refPoints = new Vector3[features.Length]; rayDirections = new Vector3[2][]; @@ -33,8 +33,10 @@ void Update() { //Take the abs of the times so they can't intersect behind the camera timeLineOne = Mathf.Abs(timeLineOne); timeLineTwo = Mathf.Abs(timeLineTwo); - inPoints[i] = Vector3.LerpUnclamped(cameras[0].position, cameras[0].TransformPoint(rayDirections[0][i]), timeLineOne); + Vector3 tempInPoint = Vector3.LerpUnclamped(cameras[0].position, cameras[0].TransformPoint(rayDirections[0][i]), timeLineOne); refPoints[i] = Vector3.LerpUnclamped(cameras[1].position, cameras[1].TransformPoint(rayDirections[1][i]), timeLineTwo); + inPoints[i] = new Vector4(tempInPoint.x, tempInPoint.y, tempInPoint.z, 1f);//(tempInPoint-refPoints[i]).sqrMagnitude); + Debug.DrawLine(inPoints[i], refPoints[i], Color.red); } diff --git a/Assets/BundleAdustment/MonocularTo3DAdjustment.unity b/Assets/BundleAdustment/MonocularTo3DAdjustment.unity index d6a43dd..8fd42ab 100644 --- a/Assets/BundleAdustment/MonocularTo3DAdjustment.unity +++ b/Assets/BundleAdustment/MonocularTo3DAdjustment.unity @@ -77,15 +77,17 @@ LightmapSettings: m_PVRDirectSampleCount: 32 m_PVRSampleCount: 500 m_PVRBounces: 2 - m_PVRFiltering: 0 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 m_PVRFilteringMode: 1 m_PVRCulling: 1 m_PVRFilteringGaussRadiusDirect: 1 m_PVRFilteringGaussRadiusIndirect: 5 m_PVRFilteringGaussRadiusAO: 2 - m_PVRFilteringAtrousColorSigma: 1 - m_PVRFilteringAtrousNormalSigma: 1 - m_PVRFilteringAtrousPositionSigma: 1 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 m_LightingDataAsset: {fileID: 0} m_UseShadowmask: 0 --- !u!196 &4 @@ -107,6 +109,8 @@ NavMeshSettings: manualTileSize: 0 tileSize: 256 accuratePlacement: 0 + debug: + m_Flags: 0 m_NavMeshData: {fileID: 0} --- !u!1 &153165801 GameObject: @@ -134,6 +138,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -149,6 +154,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -203,6 +209,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -218,6 +225,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -272,6 +280,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -287,6 +296,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -341,6 +351,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -356,6 +367,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -441,20 +453,6 @@ Light: m_Lightmapping: 4 m_AreaSize: {x: 1, y: 1} m_BounceIntensity: 1 - m_FalloffTable: - m_Table[0]: 0 - m_Table[1]: 0 - m_Table[2]: 0 - m_Table[3]: 0 - m_Table[4]: 0 - m_Table[5]: 0 - m_Table[6]: 0 - m_Table[7]: 0 - m_Table[8]: 0 - m_Table[9]: 0 - m_Table[10]: 0 - m_Table[11]: 0 - m_Table[12]: 0 m_ColorTemperature: 6570 m_UseColorTemperature: 0 m_ShadowRadius: 0 @@ -521,6 +519,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -536,6 +535,7 @@ MeshRenderer: m_PreserveUVs: 0 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -583,6 +583,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -598,6 +599,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -652,6 +654,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -667,6 +670,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -755,11 +759,11 @@ Camera: m_TargetEye: 3 m_HDR: 0 m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 m_ForceIntoRT: 0 m_OcclusionCulling: 1 m_StereoConvergence: 10 m_StereoSeparation: 0.022 - m_StereoMirrorMode: 0 --- !u!1 &1364872344 GameObject: m_ObjectHideFlags: 0 @@ -786,6 +790,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -801,6 +806,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -855,6 +861,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -870,6 +877,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -937,6 +945,7 @@ MonoBehaviour: - {fileID: 634320946} - {fileID: 1008528448} aligningCamera: {fileID: 1275341411} + useLinearEstimate: 1 --- !u!4 &1486378348 Transform: m_ObjectHideFlags: 0 @@ -977,6 +986,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -992,6 +1002,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -1046,6 +1057,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -1061,6 +1073,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 diff --git a/Assets/BundleAdustment/SpatialBundleAdjuster.cs b/Assets/BundleAdustment/SpatialBundleAdjuster.cs index 0e1c93f..691b8de 100644 --- a/Assets/BundleAdustment/SpatialBundleAdjuster.cs +++ b/Assets/BundleAdustment/SpatialBundleAdjuster.cs @@ -3,16 +3,17 @@ public class SpatialBundleAdjuster : MonoBehaviour { public Transform[] features; public Transform aligningCamera; + [Tooltip("This makes the convergence much faster if there are no outliers.\n\nTurning this off switches to a slower, more outlier robust formulation.")] public bool useLinearEstimate = true; Vector3[] rayDirections; KabschSolver solver = new KabschSolver(); - Vector3[] inPoints, refPoints; + Vector3[] inPoints; Vector4[] refPoints; float previousCost = 1000f; void Start() { rayDirections = new Vector3[features.Length]; inPoints = new Vector3[features.Length]; - refPoints = new Vector3[features.Length]; + refPoints = new Vector4[features.Length]; for (int i = 0; i < features.Length; i++) { refPoints[i] = features[i].position; @@ -27,9 +28,13 @@ void Update() { float currentCost = 0f; for (int i = 0; i < features.Length; i++) { - refPoints[i] = features[i].position; inPoints[i] = Constraints.ConstrainToSegment(features[i].position, aligningCamera.position, aligningCamera.TransformPoint(rayDirections[i]*6f)); - currentCost += Vector3.Distance(refPoints[i], inPoints[i]); + refPoints[i] = new Vector4(features[i].position.x, features[i].position.y, features[i].position.z, 1f); + + refPoints[i].w = useLinearEstimate ? 1f : Mathf.Min(1f, 1f / (Mathf.Pow((features[i].position - aligningCamera.position).magnitude * 10f, 2f) + + Mathf.Pow((features[i].position - inPoints[i] ).magnitude * 50f, 2f))); + + currentCost += Vector3.Distance(refPoints[i], inPoints[i]) * refPoints[i].w; Debug.DrawLine(aligningCamera.position, aligningCamera.TransformPoint(rayDirections[i])); Debug.DrawLine(features[i].position, inPoints[i], Color.red); } diff --git a/Assets/BundleAdustment/StereoBundleAdjuster.cs b/Assets/BundleAdustment/StereoBundleAdjuster.cs index 37eb2da..dcfd0d9 100644 --- a/Assets/BundleAdustment/StereoBundleAdjuster.cs +++ b/Assets/BundleAdustment/StereoBundleAdjuster.cs @@ -8,10 +8,10 @@ public class StereoBundleAdjuster : MonoBehaviour { Vector3[][] rayDirections; KabschSolver solver = new KabschSolver(); - Vector3[] inPoints, refPoints; + Vector4[] inPoints; Vector3[] refPoints; void Start() { - inPoints = new Vector3[features.Length * 4]; + inPoints = new Vector4[features.Length * 4]; refPoints = new Vector3[features.Length * 4]; rayDirections = new Vector3[4][]; @@ -39,7 +39,7 @@ void Update() { Displacement(cameras[(cameraIndex / 2) ].position, cameras[(cameraIndex / 2) ].TransformPoint(rayDirections[(cameraIndex / 2) ][i]), cameras[(cameraIndex % 2) + 2].position, cameras[(cameraIndex % 2) + 2].TransformPoint(rayDirections[(cameraIndex % 2) + 2][i]), out pointLineOne, out pointLineTwo); - inPoints [(i * cameras.Length) + cameraIndex] = pointLineOne; + inPoints[(i * cameras.Length) + cameraIndex] = new Vector4(pointLineOne.x, pointLineOne.y, pointLineOne.z, 1f);// / (pointLineOne - pointLineTwo).sqrMagnitude); refPoints[(i * cameras.Length) + cameraIndex] = pointLineTwo; Debug.DrawLine(pointLineOne, pointLineTwo, Color.red); diff --git a/Assets/Control/BangBangController.cs b/Assets/Control/BangBangController.cs index 31ec3de..ea01372 100644 --- a/Assets/Control/BangBangController.cs +++ b/Assets/Control/BangBangController.cs @@ -31,7 +31,7 @@ bool bangBangController(float currentPosition, float currentVelocity, float targ (currentVelocity >= 0f && currentPosition - target < -0.5f * Mathf.Pow(currentVelocity, 2f) / maxForceDividedByMass); } - int bangBangControllerWithZero(float currentPosition, float currentVelocity, float target, float maxForceDividedByMass, float epsilon = 0.0001f) { + int bangBangControllerWithZero(float currentPosition, float currentVelocity, float target, float maxForceDividedByMass, float epsilon = 0.01f) { float disparity = currentPosition - target; float parabola = 0.5f * Mathf.Pow(currentVelocity, 2f) / maxForceDividedByMass; if ((currentVelocity < 0f && disparity + epsilon <= parabola) || diff --git a/Assets/Control/BangBangController.unity b/Assets/Control/BangBangController.unity index 7a227b3..ecb2443 100644 --- a/Assets/Control/BangBangController.unity +++ b/Assets/Control/BangBangController.unity @@ -77,15 +77,17 @@ LightmapSettings: m_PVRDirectSampleCount: 32 m_PVRSampleCount: 500 m_PVRBounces: 2 - m_PVRFiltering: 0 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 m_PVRFilteringMode: 1 m_PVRCulling: 1 m_PVRFilteringGaussRadiusDirect: 1 m_PVRFilteringGaussRadiusIndirect: 5 m_PVRFilteringGaussRadiusAO: 2 - m_PVRFilteringAtrousColorSigma: 1 - m_PVRFilteringAtrousNormalSigma: 1 - m_PVRFilteringAtrousPositionSigma: 1 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 m_LightingDataAsset: {fileID: 0} m_UseShadowmask: 1 --- !u!196 &4 @@ -107,6 +109,8 @@ NavMeshSettings: manualTileSize: 0 tileSize: 256 accuratePlacement: 0 + debug: + m_Flags: 0 m_NavMeshData: {fileID: 0} --- !u!1 &795589225 GameObject: @@ -179,11 +183,11 @@ Camera: m_TargetEye: 3 m_HDR: 1 m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 m_ForceIntoRT: 0 m_OcclusionCulling: 1 m_StereoConvergence: 10 m_StereoSeparation: 0.022 - m_StereoMirrorMode: 0 --- !u!4 &795589230 Transform: m_ObjectHideFlags: 0 @@ -223,6 +227,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -238,6 +243,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -325,6 +331,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -340,6 +347,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -378,6 +386,7 @@ ParticleSystemRenderer: m_Enabled: 1 m_CastShadows: 0 m_ReceiveShadows: 0 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 0 m_ReflectionProbeUsage: 0 @@ -394,6 +403,7 @@ ParticleSystemRenderer: m_PreserveUVs: 0 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 0 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -429,6 +439,7 @@ ParticleSystem: serializedVersion: 5 lengthInSec: 5 simulationSpeed: 1 + stopAction: 0 looping: 1 prewarm: 0 playOnAwake: 1 @@ -479,7 +490,7 @@ ParticleSystem: moveWithTransform: 1 moveWithCustomTransform: {fileID: 0} scalingMode: 1 - randomSeed: -157952272 + randomSeed: -1831808020 InitialModule: serializedVersion: 3 enabled: 1 @@ -932,11 +943,11 @@ ParticleSystem: m_Rotation: {x: 0, y: 0, z: 0} m_Scale: {x: 1, y: 1, z: 1} placementMode: 0 + m_MeshMaterialIndex: 0 + m_MeshNormalOffset: 0 m_Mesh: {fileID: 0} m_MeshRenderer: {fileID: 0} m_SkinnedMeshRenderer: {fileID: 0} - m_MeshMaterialIndex: 0 - m_MeshNormalOffset: 0 m_UseMeshMaterialIndex: 0 m_UseMeshColors: 1 alignToDirection: 0 @@ -1658,6 +1669,47 @@ ParticleSystem: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 + speedModifier: + serializedVersion: 2 + minMaxState: 0 + scalar: 1 + minScalar: 1 + maxCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + - serializedVersion: 2 + time: 1 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + minCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + - serializedVersion: 2 + time: 1 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 inWorldSpace: 0 InheritVelocityModule: enabled: 0 @@ -2001,7 +2053,50 @@ ParticleSystem: m_RotationOrder: 4 separateAxis: 0 inWorldSpace: 0 + multiplyDragByParticleSize: 1 + multiplyDragByParticleVelocity: 1 dampen: 1 + drag: + serializedVersion: 2 + minMaxState: 0 + scalar: 0 + minScalar: 0 + maxCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + - serializedVersion: 2 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + minCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + - serializedVersion: 2 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 NoiseModule: enabled: 0 strength: @@ -2909,7 +3004,8 @@ ParticleSystem: serializedVersion: 2 enabled: 0 subEmitters: - - emitter: {fileID: 0} + - serializedVersion: 2 + emitter: {fileID: 0} type: 0 properties: 0 LightsModule: @@ -3005,6 +3101,7 @@ ParticleSystem: maxLights: 20 TrailModule: enabled: 0 + mode: 0 ratio: 1 lifetime: serializedVersion: 2 @@ -3049,12 +3146,14 @@ ParticleSystem: m_RotationOrder: 4 minVertexDistance: 0.2 textureMode: 0 + ribbonCount: 1 worldSpace: 0 dieWithParticles: 1 sizeAffectsWidth: 1 sizeAffectsLifetime: 0 inheritParticleColor: 1 generateLightingData: 0 + splitSubEmitterRibbons: 0 colorOverLifetime: serializedVersion: 2 minMaxState: 0 @@ -3289,6 +3388,7 @@ ParticleSystem: m_Mode: 0 m_NumColorKeys: 2 m_NumAlphaKeys: 2 + colorLabel0: Color vector0_0: serializedVersion: 2 minMaxState: 0 @@ -3330,6 +3430,7 @@ ParticleSystem: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 + vectorLabel0_0: X vector0_1: serializedVersion: 2 minMaxState: 0 @@ -3371,6 +3472,7 @@ ParticleSystem: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 + vectorLabel0_1: Y vector0_2: serializedVersion: 2 minMaxState: 0 @@ -3412,6 +3514,7 @@ ParticleSystem: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 + vectorLabel0_2: Z vector0_3: serializedVersion: 2 minMaxState: 0 @@ -3453,6 +3556,7 @@ ParticleSystem: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 + vectorLabel0_3: W mode1: 0 vectorComponentCount1: 4 color1: @@ -3518,6 +3622,7 @@ ParticleSystem: m_Mode: 0 m_NumColorKeys: 2 m_NumAlphaKeys: 2 + colorLabel1: Color vector1_0: serializedVersion: 2 minMaxState: 0 @@ -3559,6 +3664,7 @@ ParticleSystem: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 + vectorLabel1_0: X vector1_1: serializedVersion: 2 minMaxState: 0 @@ -3600,6 +3706,7 @@ ParticleSystem: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 + vectorLabel1_1: Y vector1_2: serializedVersion: 2 minMaxState: 0 @@ -3641,6 +3748,7 @@ ParticleSystem: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 + vectorLabel1_2: Z vector1_3: serializedVersion: 2 minMaxState: 0 @@ -3682,6 +3790,7 @@ ParticleSystem: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 + vectorLabel1_3: W --- !u!1 &1182410624 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Kabsch/Kabsch.cs b/Assets/Kabsch/Kabsch.cs index c100255..b0b0227 100644 --- a/Assets/Kabsch/Kabsch.cs +++ b/Assets/Kabsch/Kabsch.cs @@ -3,13 +3,13 @@ public class Kabsch : MonoBehaviour { public Transform[] inPoints; public Transform[] referencePoints; - Vector3[] points, refPoints; + Vector3[] points; Vector4[] refPoints; KabschSolver solver = new KabschSolver(); //Set up the Input Points void Start() { points = new Vector3[inPoints.Length]; - refPoints = new Vector3[inPoints.Length]; + refPoints = new Vector4[inPoints.Length]; for (int i = 0; i < inPoints.Length; i++) { points[i] = inPoints[i].position; } @@ -18,7 +18,7 @@ void Start() { //Calculate the Kabsch Transform and Apply it to the input points void Update() { for (int i = 0; i < inPoints.Length; i++) { - refPoints[i] = referencePoints[i].position; + refPoints[i] = new Vector4(referencePoints[i].position.x, referencePoints[i].position.y, referencePoints[i].position.z, referencePoints[i].localScale.x); } Matrix4x4 kabschTransform = solver.SolveKabsch(points, refPoints); @@ -34,17 +34,20 @@ public class KabschSolver { Vector3[] QuatBasis = new Vector3[3]; Vector3[] DataCovariance = new Vector3[3]; Quaternion OptimalRotation = Quaternion.identity; - public Matrix4x4 SolveKabsch(Vector3[] inPoints, Vector3[] refPoints, bool solveRotation = true) { + public Matrix4x4 SolveKabsch(Vector3[] inPoints, Vector4[] refPoints, bool solveRotation = true) { if (inPoints.Length != refPoints.Length) { return Matrix4x4.identity; } //Calculate the centroid offset and construct the centroid-shifted point matrices Vector3 inCentroid = Vector3.zero; Vector3 refCentroid = Vector3.zero; + float inTotal = 0f, refTotal = 0f; for (int i = 0; i < inPoints.Length; i++) { - inCentroid += inPoints[i]; - refCentroid += refPoints[i]; + inCentroid += new Vector3(inPoints[i].x, inPoints[i].y, inPoints[i].z) * refPoints[i].w; + inTotal += refPoints[i].w; + refCentroid += new Vector3(refPoints[i].x, refPoints[i].y, refPoints[i].z) * refPoints[i].w; + refTotal += refPoints[i].w; } - inCentroid /= inPoints.Length; - refCentroid /= refPoints.Length; + inCentroid /= inTotal; + refCentroid /= refTotal; //Calculate the 3x3 covariance matrix, and the optimal rotation if (solveRotation) { @@ -71,25 +74,25 @@ void extractRotation(Vector3[] A, ref Quaternion q) { Vector3.Dot(QuatBasis[1], A[1]) + Vector3.Dot(QuatBasis[2], A[2]) + 0.000000001f)); - float w = Mathf.Clamp(omega.magnitude * Mathf.Rad2Deg, -20f, 20f); //How aggressive each iteration should be + float w = omega.magnitude; if (w < 0.000000001f) break; - q = Quaternion.AngleAxis(w, (1f / w) * omega) * q; + q = Quaternion.AngleAxis(w * Mathf.Rad2Deg, omega / w) * q; q = Quaternion.Lerp(q, q, 0f); //Normalizes the Quaternion; critical for error suppression Profiler.EndSample(); } } //Calculate Covariance Matrices -------------------------------------------------- - public static Vector3[] TransposeMultSubtract(Vector3[] vec1, Vector3[] vec2, Vector3 vec1Centroid, Vector3 vec2Centroid, Vector3[] covariance) { + public static Vector3[] TransposeMultSubtract(Vector3[] vec1, Vector4[] vec2, Vector3 vec1Centroid, Vector3 vec2Centroid, Vector3[] covariance) { Profiler.BeginSample("Calculate Covariance Matrix"); for (int i = 0; i < 3; i++) { //i is the row in this matrix covariance[i] = Vector3.zero; } for (int k = 0; k < vec1.Length; k++) {//k is the column in this matrix - Vector3 left = vec1[k] - vec1Centroid; - Vector3 right = vec2[k] - vec2Centroid; + Vector3 left = (vec1[k] - vec1Centroid) * vec2[k].w; + Vector3 right = (new Vector3(vec2[k].x, vec2[k].y, vec2[k].z) - vec2Centroid) * Mathf.Abs(vec2[k].w); covariance[0][0] += left[0]*right[0]; covariance[1][0] += left[1]*right[0]; diff --git a/Assets/Verlet/Softbody/SoftBody.unity b/Assets/Verlet/Softbody/SoftBody.unity index a4f16f4..2fdb902 100644 --- a/Assets/Verlet/Softbody/SoftBody.unity +++ b/Assets/Verlet/Softbody/SoftBody.unity @@ -77,15 +77,17 @@ LightmapSettings: m_PVRDirectSampleCount: 32 m_PVRSampleCount: 500 m_PVRBounces: 2 - m_PVRFiltering: 0 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 m_PVRFilteringMode: 1 m_PVRCulling: 1 m_PVRFilteringGaussRadiusDirect: 1 m_PVRFilteringGaussRadiusIndirect: 5 m_PVRFilteringGaussRadiusAO: 2 - m_PVRFilteringAtrousColorSigma: 1 - m_PVRFilteringAtrousNormalSigma: 1 - m_PVRFilteringAtrousPositionSigma: 1 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 m_LightingDataAsset: {fileID: 0} m_UseShadowmask: 0 --- !u!196 &4 @@ -107,6 +109,8 @@ NavMeshSettings: manualTileSize: 0 tileSize: 256 accuratePlacement: 0 + debug: + m_Flags: 0 m_NavMeshData: {fileID: 0} --- !u!1 &50703606 GameObject: @@ -179,11 +183,11 @@ Camera: m_TargetEye: 3 m_HDR: 0 m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 m_ForceIntoRT: 0 m_OcclusionCulling: 1 m_StereoConvergence: 10 m_StereoSeparation: 0.022 - m_StereoMirrorMode: 0 --- !u!4 &50703611 Transform: m_ObjectHideFlags: 0 @@ -245,20 +249,6 @@ Light: m_Lightmapping: 4 m_AreaSize: {x: 1, y: 1} m_BounceIntensity: 1 - m_FalloffTable: - m_Table[0]: 0 - m_Table[1]: 0 - m_Table[2]: 0 - m_Table[3]: 0 - m_Table[4]: 0 - m_Table[5]: 0 - m_Table[6]: 0 - m_Table[7]: 0 - m_Table[8]: 0 - m_Table[9]: 0 - m_Table[10]: 0 - m_Table[11]: 0 - m_Table[12]: 0 m_ColorTemperature: 6570 m_UseColorTemperature: 0 m_ShadowRadius: 0 @@ -324,6 +314,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -339,6 +330,7 @@ MeshRenderer: m_PreserveUVs: 0 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -403,6 +395,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -418,6 +411,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -432,7 +426,7 @@ MeshFilter: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 736096482} - m_Mesh: {fileID: 4300000, guid: d67cfaa06d1673d43b8fd05a2e3d6d5b, type: 2} + m_Mesh: {fileID: 4300000, guid: e9c5d9695343e1045b3b33c628a3152f, type: 2} --- !u!4 &736096486 Transform: m_ObjectHideFlags: 0 @@ -472,6 +466,7 @@ MeshRenderer: m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 + m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -487,6 +482,7 @@ MeshRenderer: m_PreserveUVs: 1 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 + m_StitchLightmapSeams: 0 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 @@ -604,20 +600,6 @@ Light: m_Lightmapping: 4 m_AreaSize: {x: 1, y: 1} m_BounceIntensity: 1 - m_FalloffTable: - m_Table[0]: 0 - m_Table[1]: 0 - m_Table[2]: 0 - m_Table[3]: 0 - m_Table[4]: 0 - m_Table[5]: 0 - m_Table[6]: 0 - m_Table[7]: 0 - m_Table[8]: 0 - m_Table[9]: 0 - m_Table[10]: 0 - m_Table[11]: 0 - m_Table[12]: 0 m_ColorTemperature: 6570 m_UseColorTemperature: 0 m_ShadowRadius: 0 diff --git a/Assets/Verlet/Softbody/Softbody.cs b/Assets/Verlet/Softbody/Softbody.cs index ca343cd..524742e 100644 --- a/Assets/Verlet/Softbody/Softbody.cs +++ b/Assets/Verlet/Softbody/Softbody.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System; +using UnityEngine; using System.Collections.Generic; [RequireComponent(typeof(MeshFilter))] @@ -16,6 +17,7 @@ public class Softbody : MonoBehaviour { protected Mesh bodyMesh; protected Vector3[] originalVerts; protected Vector3[] bodyVerts; + protected Vector4[] kabschVerts; protected Vector3[] prevBodyVerts; protected Vector4[] accumulatedDisplacements; protected int[] bodyTriangles; @@ -34,6 +36,7 @@ void Start() { bodyMesh = Instantiate(filter.mesh); bodyMesh.MarkDynamic(); bodyVerts = bodyMesh.vertices; + kabschVerts = Array.ConvertAll(bodyVerts, (p => new Vector4(p.x, p.y, p.z, 1f))); originalVerts = bodyMesh.vertices; bodyTriangles = bodyMesh.triangles; bodyNormals = bodyMesh.normals; @@ -62,7 +65,7 @@ void Update() { } //Physics - float currentDeltaTime = Mathf.Clamp(Time.deltaTime, 0.01f, previousDeltaTime * 1.4f); + float currentDeltaTime = Mathf.Clamp(Time.smoothDeltaTime, 0.01f, previousDeltaTime * 1.4f); Verlet.Integrate(bodyVerts, prevBodyVerts, scaledGravity, currentDeltaTime, previousDeltaTime); previousDeltaTime = currentDeltaTime; @@ -83,14 +86,15 @@ void Update() { Vector3 groundPlanePos = groundPlane.position; Vector3 groundPlaneNormal = -groundPlane.forward; for (int j = 0; j < bodyVerts.Length; j++) { - if (Vector3.Dot(bodyVerts[j]-groundPlanePos, groundPlaneNormal) < 0f) { + if (Vector3.Dot(bodyVerts[j] - groundPlanePos, groundPlaneNormal) < 0f) { bodyVerts[j] = Vector3.ProjectOnPlane(bodyVerts[j] - groundPlanePos, groundPlaneNormal) + groundPlanePos; bodyVerts[j] -= Vector3.ProjectOnPlane(bodyVerts[j] - prevBodyVerts[j], groundPlaneNormal) * 0.3f; } } //Calculate the the position and rotation of the body - Matrix4x4 toWorldSpace = kabschSolver.SolveKabsch(originalVerts, bodyVerts, transformFollowsRotation); + for (int i = 0; i < bodyVerts.Length; i++) { kabschVerts[i] = new Vector4(bodyVerts[i].x, bodyVerts[i].y, bodyVerts[i].z, 1f); }; + Matrix4x4 toWorldSpace = kabschSolver.SolveKabsch(originalVerts, kabschVerts, transformFollowsRotation); transform.position = toWorldSpace.GetVector3(); transform.rotation = toWorldSpace.GetQuaternion(); diff --git a/Assets/Verlet/Softbody/VerletCloth.cs b/Assets/Verlet/Softbody/VerletCloth.cs index 8891e38..bc35dd6 100644 --- a/Assets/Verlet/Softbody/VerletCloth.cs +++ b/Assets/Verlet/Softbody/VerletCloth.cs @@ -33,8 +33,8 @@ void Start() { void Update() { //Physics - Verlet.Integrate(clothVerts, prevClothVerts, scaledGravity, Time.deltaTime, previousDeltaTime); - previousDeltaTime = Time.deltaTime; + Verlet.Integrate(clothVerts, prevClothVerts, scaledGravity, Time.smoothDeltaTime, previousDeltaTime); + previousDeltaTime = Time.smoothDeltaTime; //Anchor the Top Corner of the Cloth clothVerts[0] = prevClothVerts[0] = anchor1.position; diff --git a/Assets/Verlet/Softbody/VolumeApproximation/VolumeExpander.cs b/Assets/Verlet/Softbody/VolumeApproximation/VolumeExpander.cs index 2dd87c4..563c846 100644 --- a/Assets/Verlet/Softbody/VolumeApproximation/VolumeExpander.cs +++ b/Assets/Verlet/Softbody/VolumeApproximation/VolumeExpander.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System; +using UnityEngine; using System.Collections.Generic; [RequireComponent(typeof(MeshFilter))] @@ -14,6 +15,7 @@ public class VolumeExpander : MonoBehaviour { protected Mesh bodyMesh; protected Vector3[] originalVerts; protected Vector3[] bodyVerts; + protected Vector4[] kabschVerts; protected Vector4[] accumulatedDisplacements; protected int[] bodyTriangles; protected Vector3[] bodyNormals; @@ -30,6 +32,7 @@ void Start() { bodyMesh = Instantiate(filter.mesh); bodyMesh.MarkDynamic(); bodyVerts = bodyMesh.vertices; + kabschVerts = Array.ConvertAll(bodyVerts, (p => new Vector4(p.x, p.y, p.z, 1f))); originalVerts = bodyMesh.vertices; bodyTriangles = bodyMesh.triangles; bodyNormals = bodyMesh.normals; @@ -70,7 +73,8 @@ void Update() { } //Calculate the the position and rotation of the body - Matrix4x4 toWorldSpace = kabschSolver.SolveKabsch(originalVerts, bodyVerts); + for (int i = 0; i < bodyVerts.Length; i++) { kabschVerts[i] = new Vector4(bodyVerts[i].x, bodyVerts[i].y, bodyVerts[i].z, 1f); }; + Matrix4x4 toWorldSpace = kabschSolver.SolveKabsch(originalVerts, Array.ConvertAll(bodyVerts, (p => (Vector4)p))); transform.position = toWorldSpace.GetVector3(); transform.rotation = toWorldSpace.GetQuaternion(); diff --git a/Assets/Verlet/Verlet.cs b/Assets/Verlet/Verlet.cs index af6ba08..2e5bf3e 100644 --- a/Assets/Verlet/Verlet.cs +++ b/Assets/Verlet/Verlet.cs @@ -3,13 +3,13 @@ public static class Verlet { //Particle Verlet Integration - public static void Integrate(Vector3[] curPoints, Vector3[] prevPoints, Vector3 gravity, float deltaTime = 1f, float prevDeltaTime = 1f) { + public static void Integrate(Vector3[] curPoints, Vector3[] prevPoints, Vector3 gravity, float deltaTime = 0.01f, float prevDeltaTime = 0.01f) { for (int i = 0; i < curPoints.Length; i++) { //Grab State from Previous Frame Vector3 tempPos = curPoints[i]; //Integrate Position - curPoints[i] += (curPoints[i] - prevPoints[i]) * (deltaTime / prevDeltaTime) + (gravity * deltaTime * deltaTime); + curPoints[i] += ((curPoints[i] - prevPoints[i]) * (deltaTime / prevDeltaTime)) + (gravity * deltaTime * deltaTime); //Store State from Previous Frame prevPoints[i] = tempPos; diff --git a/Packages/manifest.json b/Packages/manifest.json new file mode 100644 index 0000000..526aca6 --- /dev/null +++ b/Packages/manifest.json @@ -0,0 +1,4 @@ +{ + "dependencies": { + } +} diff --git a/Packages/manifest.json.meta b/Packages/manifest.json.meta new file mode 100644 index 0000000..d0c5dd1 --- /dev/null +++ b/Packages/manifest.json.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 0a2b85a2f5156eb418cb5766ff9aaed5 +timeCreated: 1507411810 +licenseType: Free +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/DynamicsManager.asset b/ProjectSettings/DynamicsManager.asset index 19700a8..03a4403 100644 --- a/ProjectSettings/DynamicsManager.asset +++ b/ProjectSettings/DynamicsManager.asset @@ -3,7 +3,7 @@ --- !u!55 &1 PhysicsManager: m_ObjectHideFlags: 0 - serializedVersion: 3 + serializedVersion: 7 m_Gravity: {x: 0, y: -9.81, z: 0} m_DefaultMaterial: {fileID: 0} m_BounceThreshold: 2 @@ -14,6 +14,16 @@ PhysicsManager: m_QueriesHitBackfaces: 0 m_QueriesHitTriggers: 1 m_EnableAdaptiveForce: 0 - m_EnablePCM: 0 + m_ClothInterCollisionDistance: 0 + m_ClothInterCollisionStiffness: 0 + m_ContactsGeneration: 0 m_LayerCollisionMatrix: fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff m_AutoSimulation: 1 + m_AutoSyncTransforms: 1 + m_ClothInterCollisionSettingsToggle: 0 + m_ContactPairsMode: 0 + m_BroadphaseType: 0 + m_WorldBounds: + m_Center: {x: 0, y: 0, z: 0} + m_Extent: {x: 250, y: 250, z: 250} + m_WorldSubdivisions: 8 diff --git a/ProjectSettings/Physics2DSettings.asset b/ProjectSettings/Physics2DSettings.asset index 26949ff..dad62a3 100644 --- a/ProjectSettings/Physics2DSettings.asset +++ b/ProjectSettings/Physics2DSettings.asset @@ -24,6 +24,7 @@ Physics2DSettings: m_QueriesStartInColliders: 1 m_ChangeStopsCallbacks: 0 m_CallbacksOnDisable: 1 + m_AutoSyncTransforms: 1 m_AlwaysShowColliders: 0 m_ShowColliderSleep: 1 m_ShowColliderContacts: 0 diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 012159d..b1a0a9a 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1 +1 @@ -m_EditorVersion: 2017.1.0p5 +m_EditorVersion: 2017.3.0b3