Browse Source

umrechnungsfehler gefunden, Pointcloud läuft, Mesh needs help

DESKTOP-101\vive-admin 6 years ago
parent
commit
c71ed9c620

BIN
VR Raumrekonstuktion/.vs/VR Raumrekonstuktion/v15/Server/sqlite3/storage.ide


BIN
VR Raumrekonstuktion/.vs/VR Raumrekonstuktion/v15/Server/sqlite3/storage.ide-shm


BIN
VR Raumrekonstuktion/.vs/VR Raumrekonstuktion/v15/Server/sqlite3/storage.ide-wal


+ 136 - 209
VR Raumrekonstuktion/Assets/Mine/RoomScanner.unity

@@ -177,13 +177,141 @@ Transform:
   m_PrefabParentObject: {fileID: 0}
   m_PrefabInternal: {fileID: 0}
   m_GameObject: {fileID: 220569630}
-  m_LocalRotation: {x: 0.032578476, y: 0.66771525, z: -0.029272415, w: 0.74312735}
-  m_LocalPosition: {x: -2.016286, y: 1.9781535, z: -0.28876197}
+  m_LocalRotation: {x: -0.025515229, y: 0.6984783, z: 0.024935886, w: 0.7147414}
+  m_LocalPosition: {x: 0.48169038, y: 0.9608829, z: 0.14466369}
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_Children: []
   m_Father: {fileID: 0}
   m_RootOrder: 3
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!43 &462263946
+Mesh:
+  m_ObjectHideFlags: 0
+  m_PrefabParentObject: {fileID: 0}
+  m_PrefabInternal: {fileID: 0}
+  m_Name: 
+  serializedVersion: 8
+  m_SubMeshes:
+  - serializedVersion: 2
+    firstByte: 0
+    indexCount: 24
+    topology: 0
+    firstVertex: 0
+    vertexCount: 8
+    localAABB:
+      m_Center: {x: 0, y: 0.01, z: 0}
+      m_Extent: {x: 1.65, y: 0, z: 1.275}
+  m_Shapes:
+    vertices: []
+    shapes: []
+    channels: []
+    fullWeights: []
+  m_BindPose: []
+  m_BoneNameHashes: 
+  m_RootBoneNameHash: 0
+  m_MeshCompression: 0
+  m_IsReadable: 1
+  m_KeepVertices: 1
+  m_KeepIndices: 1
+  m_IndexBuffer: 000004000100010004000500010005000200020005000600020006000300030006000700030007000000000007000400
+  m_Skin: []
+  m_VertexData:
+    m_CurrentChannels: 13
+    m_VertexCount: 8
+    m_Channels:
+    - stream: 0
+      offset: 0
+      format: 0
+      dimension: 3
+    - stream: 0
+      offset: 0
+      format: 0
+      dimension: 0
+    - stream: 0
+      offset: 12
+      format: 0
+      dimension: 4
+    - stream: 0
+      offset: 28
+      format: 0
+      dimension: 2
+    - stream: 0
+      offset: 0
+      format: 0
+      dimension: 0
+    - stream: 0
+      offset: 0
+      format: 0
+      dimension: 0
+    - stream: 0
+      offset: 0
+      format: 0
+      dimension: 0
+    - stream: 0
+      offset: 0
+      format: 0
+      dimension: 0
+    m_DataSize: 288
+    _typelessdata: 0000c03f0ad7233c000090bf000000000000803f0000803f0000803f00000000000000000000c0bf0ad7233c000090bf000000000000803f0000803f0000803f0000803f000000000000c0bf0ad7233c0000903f000000000000803f0000803f0000803f00000000000000000000c03f0ad7233c0000903f000000000000803f0000803f0000803f0000803f000000003333d33f0ad7233c3333a3bf000000000000803f0000803f00000000000000000000803f3333d3bf0ad7233c3333a3bf000000000000803f0000803f000000000000803f0000803f3333d3bf0ad7233c3333a33f000000000000803f0000803f00000000000000000000803f3333d33f0ad7233c3333a33f000000000000803f0000803f000000000000803f0000803f
+  m_CompressedMesh:
+    m_Vertices:
+      m_NumItems: 0
+      m_Range: 0
+      m_Start: 0
+      m_Data: 
+      m_BitSize: 0
+    m_UV:
+      m_NumItems: 0
+      m_Range: 0
+      m_Start: 0
+      m_Data: 
+      m_BitSize: 0
+    m_Normals:
+      m_NumItems: 0
+      m_Range: 0
+      m_Start: 0
+      m_Data: 
+      m_BitSize: 0
+    m_Tangents:
+      m_NumItems: 0
+      m_Range: 0
+      m_Start: 0
+      m_Data: 
+      m_BitSize: 0
+    m_Weights:
+      m_NumItems: 0
+      m_Data: 
+      m_BitSize: 0
+    m_NormalSigns:
+      m_NumItems: 0
+      m_Data: 
+      m_BitSize: 0
+    m_TangentSigns:
+      m_NumItems: 0
+      m_Data: 
+      m_BitSize: 0
+    m_FloatColors:
+      m_NumItems: 0
+      m_Range: 0
+      m_Start: 0
+      m_Data: 
+      m_BitSize: 0
+    m_BoneIndices:
+      m_NumItems: 0
+      m_Data: 
+      m_BitSize: 0
+    m_Triangles:
+      m_NumItems: 0
+      m_Data: 
+      m_BitSize: 0
+    m_UVInfo: 0
+  m_LocalAABB:
+    m_Center: {x: 0, y: 0.01, z: 0}
+    m_Extent: {x: 1.65, y: 0, z: 1.275}
+  m_MeshUsageFlags: 0
+  m_BakedConvexCollisionMesh: 
+  m_BakedTriangleCollisionMesh: 
+  m_MeshOptimized: 0
 --- !u!1 &556086614
 GameObject:
   m_ObjectHideFlags: 0
@@ -264,6 +392,7 @@ MonoBehaviour:
   accuracy: 10000
   maxDistance: 100
   _particleSystem: {fileID: 1495567582}
+  cameraTexture: {fileID: 0}
 --- !u!114 &556086619
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -319,21 +448,21 @@ Prefab:
       objectReference: {fileID: 0}
     - target: {fileID: 420908, guid: 4d293c8e162f3874b982baadd71153d2, type: 2}
       propertyPath: m_RootOrder
-      value: 5
+      value: 4
       objectReference: {fileID: 0}
     - target: {fileID: 2348914, guid: 4d293c8e162f3874b982baadd71153d2, type: 2}
       propertyPath: m_Materials.Array.data[0]
       value: 
-      objectReference: {fileID: 602215439}
+      objectReference: {fileID: 821483890}
     - target: {fileID: 3380982, guid: 4d293c8e162f3874b982baadd71153d2, type: 2}
       propertyPath: m_Mesh
       value: 
-      objectReference: {fileID: 1176316842}
+      objectReference: {fileID: 462263946}
     m_RemovedComponents:
     - {fileID: 11420968, guid: 4d293c8e162f3874b982baadd71153d2, type: 2}
   m_ParentPrefab: {fileID: 100100000, guid: 4d293c8e162f3874b982baadd71153d2, type: 2}
   m_IsPrefabParent: 0
---- !u!21 &602215439
+--- !u!21 &821483890
 Material:
   serializedVersion: 6
   m_ObjectHideFlags: 0
@@ -583,134 +712,6 @@ Transform:
   m_PrefabParentObject: {fileID: 4167320887417124, guid: dd48a1ee4e4a0cc4d91b8f857658878a,
     type: 2}
   m_PrefabInternal: {fileID: 899486547}
---- !u!43 &1176316842
-Mesh:
-  m_ObjectHideFlags: 0
-  m_PrefabParentObject: {fileID: 0}
-  m_PrefabInternal: {fileID: 0}
-  m_Name: 
-  serializedVersion: 8
-  m_SubMeshes:
-  - serializedVersion: 2
-    firstByte: 0
-    indexCount: 24
-    topology: 0
-    firstVertex: 0
-    vertexCount: 8
-    localAABB:
-      m_Center: {x: 0, y: 0.01, z: 0}
-      m_Extent: {x: 1.65, y: 0, z: 1.275}
-  m_Shapes:
-    vertices: []
-    shapes: []
-    channels: []
-    fullWeights: []
-  m_BindPose: []
-  m_BoneNameHashes: 
-  m_RootBoneNameHash: 0
-  m_MeshCompression: 0
-  m_IsReadable: 1
-  m_KeepVertices: 1
-  m_KeepIndices: 1
-  m_IndexBuffer: 000004000100010004000500010005000200020005000600020006000300030006000700030007000000000007000400
-  m_Skin: []
-  m_VertexData:
-    m_CurrentChannels: 13
-    m_VertexCount: 8
-    m_Channels:
-    - stream: 0
-      offset: 0
-      format: 0
-      dimension: 3
-    - stream: 0
-      offset: 0
-      format: 0
-      dimension: 0
-    - stream: 0
-      offset: 12
-      format: 0
-      dimension: 4
-    - stream: 0
-      offset: 28
-      format: 0
-      dimension: 2
-    - stream: 0
-      offset: 0
-      format: 0
-      dimension: 0
-    - stream: 0
-      offset: 0
-      format: 0
-      dimension: 0
-    - stream: 0
-      offset: 0
-      format: 0
-      dimension: 0
-    - stream: 0
-      offset: 0
-      format: 0
-      dimension: 0
-    m_DataSize: 288
-    _typelessdata: 0000c03f0ad7233c000090bf000000000000803f0000803f0000803f00000000000000000000c0bf0ad7233c000090bf000000000000803f0000803f0000803f0000803f000000000000c0bf0ad7233c0000903f000000000000803f0000803f0000803f00000000000000000000c03f0ad7233c0000903f000000000000803f0000803f0000803f0000803f000000003333d33f0ad7233c3333a3bf000000000000803f0000803f00000000000000000000803f3333d3bf0ad7233c3333a3bf000000000000803f0000803f000000000000803f0000803f3333d3bf0ad7233c3333a33f000000000000803f0000803f00000000000000000000803f3333d33f0ad7233c3333a33f000000000000803f0000803f000000000000803f0000803f
-  m_CompressedMesh:
-    m_Vertices:
-      m_NumItems: 0
-      m_Range: 0
-      m_Start: 0
-      m_Data: 
-      m_BitSize: 0
-    m_UV:
-      m_NumItems: 0
-      m_Range: 0
-      m_Start: 0
-      m_Data: 
-      m_BitSize: 0
-    m_Normals:
-      m_NumItems: 0
-      m_Range: 0
-      m_Start: 0
-      m_Data: 
-      m_BitSize: 0
-    m_Tangents:
-      m_NumItems: 0
-      m_Range: 0
-      m_Start: 0
-      m_Data: 
-      m_BitSize: 0
-    m_Weights:
-      m_NumItems: 0
-      m_Data: 
-      m_BitSize: 0
-    m_NormalSigns:
-      m_NumItems: 0
-      m_Data: 
-      m_BitSize: 0
-    m_TangentSigns:
-      m_NumItems: 0
-      m_Data: 
-      m_BitSize: 0
-    m_FloatColors:
-      m_NumItems: 0
-      m_Range: 0
-      m_Start: 0
-      m_Data: 
-      m_BitSize: 0
-    m_BoneIndices:
-      m_NumItems: 0
-      m_Data: 
-      m_BitSize: 0
-    m_Triangles:
-      m_NumItems: 0
-      m_Data: 
-      m_BitSize: 0
-    m_UVInfo: 0
-  m_LocalAABB:
-    m_Center: {x: 0, y: 0.01, z: 0}
-    m_Extent: {x: 1.65, y: 0, z: 1.275}
-  m_MeshUsageFlags: 0
-  m_BakedConvexCollisionMesh: 
-  m_BakedTriangleCollisionMesh: 
-  m_MeshOptimized: 0
 --- !u!1 &1495567580
 GameObject:
   m_ObjectHideFlags: 0
@@ -4162,83 +4163,9 @@ Transform:
   m_PrefabInternal: {fileID: 0}
   m_GameObject: {fileID: 1495567580}
   m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
-  m_LocalPosition: {x: 0, y: 2, z: 0}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_Children: []
   m_Father: {fileID: 0}
   m_RootOrder: 1
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
---- !u!1 &1744478526
-GameObject:
-  m_ObjectHideFlags: 0
-  m_PrefabParentObject: {fileID: 0}
-  m_PrefabInternal: {fileID: 0}
-  serializedVersion: 5
-  m_Component:
-  - component: {fileID: 1744478529}
-  - component: {fileID: 1744478528}
-  - component: {fileID: 1744478527}
-  m_Layer: 0
-  m_Name: MeshGenerator
-  m_TagString: Untagged
-  m_Icon: {fileID: 0}
-  m_NavMeshLayer: 0
-  m_StaticEditorFlags: 0
-  m_IsActive: 1
---- !u!218 &1744478527
-Terrain:
-  m_ObjectHideFlags: 0
-  m_PrefabParentObject: {fileID: 0}
-  m_PrefabInternal: {fileID: 0}
-  m_GameObject: {fileID: 1744478526}
-  m_Enabled: 1
-  serializedVersion: 3
-  m_TerrainData: {fileID: 0}
-  m_TreeDistance: 5000
-  m_TreeBillboardDistance: 50
-  m_TreeCrossFadeLength: 5
-  m_TreeMaximumFullLODCount: 50
-  m_DetailObjectDistance: 80
-  m_DetailObjectDensity: 1
-  m_HeightmapPixelError: 5
-  m_SplatMapDistance: 1000
-  m_HeightmapMaximumLOD: 0
-  m_CastShadows: 1
-  m_DrawHeightmap: 1
-  m_DrawTreesAndFoliage: 1
-  m_ReflectionProbeUsage: 1
-  m_MaterialType: 0
-  m_LegacySpecular:
-    serializedVersion: 2
-    rgba: 4286545791
-  m_LegacyShininess: 0.078125
-  m_MaterialTemplate: {fileID: 0}
-  m_BakeLightProbesForTrees: 1
-  m_ScaleInLightmap: 1
-  m_LightmapParameters: {fileID: 15203, guid: 0000000000000000f000000000000000, type: 0}
---- !u!114 &1744478528
-MonoBehaviour:
-  m_ObjectHideFlags: 0
-  m_PrefabParentObject: {fileID: 0}
-  m_PrefabInternal: {fileID: 0}
-  m_GameObject: {fileID: 1744478526}
-  m_Enabled: 1
-  m_EditorHideFlags: 0
-  m_Script: {fileID: 11500000, guid: c75424bc70a09a946bdd91a695cc8aca, type: 3}
-  m_Name: 
-  m_EditorClassIdentifier: 
-  terrain: {fileID: 0}
-  theTerrainData: {fileID: 0}
---- !u!4 &1744478529
-Transform:
-  m_ObjectHideFlags: 0
-  m_PrefabParentObject: {fileID: 0}
-  m_PrefabInternal: {fileID: 0}
-  m_GameObject: {fileID: 1744478526}
-  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
-  m_LocalPosition: {x: 0.4387468, y: -1.002064, z: 1.0448035}
-  m_LocalScale: {x: 1, y: 1, z: 1}
-  m_Children: []
-  m_Father: {fileID: 0}
-  m_RootOrder: 4
-  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

+ 84 - 64
VR Raumrekonstuktion/Assets/Mine/Scripts/PointCloudAggregator.cs

@@ -4,7 +4,8 @@ using Windows.Kinect;
 
 
 public class PointCloudAggregator : MonoBehaviour {
-
+	int minY = 0;
+	int maxY = 0;
 	public float accuracy = 1000f;
 	public float maxDistance = 15f;
 
@@ -24,12 +25,9 @@ public class PointCloudAggregator : MonoBehaviour {
 	private CameraSpacePoint[] cameraSpacePoints;
 
 	private ColorSpacePoint[] colorSpacePoints;
-	private Texture2D cameraTexture;
+	public Texture2D cameraTexture;
 	private Color[] cameraColor;
 
-	private Vector2 maxVals;
-	private Vector2 minVals;
-
 	Dictionary<Vector2Int, ColorHeight> data = new Dictionary<Vector2Int, ColorHeight>();
 
 	Dictionary<Vector3, Color> data2 = new Dictionary<Vector3, Color>();
@@ -82,46 +80,50 @@ public class PointCloudAggregator : MonoBehaviour {
 
 			cameraColor = new Color[depthWidth * depthHeight];
 		}
-		maxVals = Vector2.negativeInfinity;
-		minVals = Vector2.positiveInfinity;
 	}
 	
 	// Update is called once per frame
 	void Update () {
+		
 		if (Input.GetKeyDown(KeyCode.Space))
 		{
 			Debug.Log("Snapshot");
-			NewSnapshot(true);
+			NewSnapshot();
 			Debug.Log("Data set not has: " + data.Count + " entries");
 		}
-        if (Input.GetKeyDown(KeyCode.Y))
-        {
-            Debug.Log("Snapshot");
-            NewSnapshot(false);
-            Debug.Log("Data set not has: " + data.Count + " entries");
-        }
-
-        if (Input.GetKeyDown(KeyCode.C))
+
+
+		if (Input.GetKeyDown(KeyCode.C))
 		{
 			Debug.Log("Cloud!");
 			Debug.Log(data.Count);
 			ShowAsPointCloud();
 		}
 
-        if (Input.GetKeyDown(KeyCode.A))
-        {
-            Debug.Log("Cloud2!");
-            Debug.Log(data.Count);
-            ShowAsPointCloud2();
-        }
-    }
+		if (Input.GetKeyDown(KeyCode.A))
+		{
+			Debug.Log("Cloud2!");
+			Debug.Log(data.Count);
+			ShowAsPointCloud2();
+		}
+
+		if (Input.GetKeyDown(KeyCode.R))
+		{
+			Debug.Log("Cleared!");
+			data = new Dictionary<Vector2Int, ColorHeight>();
+			data2 = new Dictionary<Vector3, Color>();
+		}
+	}
 
-	void NewSnapshot(bool normal)
+	void NewSnapshot()
 	{
 		Vector3 currentPoint;
 		Vector2Int floorPosition;
 		ushort[] rawdata = _MultiManager.GetDepthData();
 
+		Color? tempCol;
+		Color validCol;
+
 		cameraTexture = _MultiManager.GetColorTexture();
 		_Mapper.MapDepthFrameToCameraSpace(rawdata, cameraSpacePoints);
 		_Mapper.MapDepthFrameToColorSpace(rawdata, colorSpacePoints);
@@ -129,7 +131,9 @@ public class PointCloudAggregator : MonoBehaviour {
 		{
 			
 			currentPoint = KinectPointToVector3(cameraSpacePoints[i]);
-			currentPoint = transform.InverseTransformPoint(currentPoint);
+			currentPoint = transform.TransformPoint(currentPoint);
+
+			
 
 			float x = (Mathf.Clamp(currentPoint.x, -maxDistance, maxDistance ));
 			float y = (Mathf.Clamp(currentPoint.z, -maxDistance, maxDistance ));
@@ -145,32 +149,35 @@ public class PointCloudAggregator : MonoBehaviour {
 			{
 				continue;
 			}
-            
+			
 			floorPosition = new Vector2Int(Mathf.RoundToInt(x),Mathf.RoundToInt(y));
 
-			minVals = Vector2.Min(floorPosition, minVals);
-			maxVals = Vector2.Max(floorPosition, maxVals);
-            if (!normal)
-            {
-                data2[currentPoint] = GetColorAtIndex(i);
-            }
-            else
-            {
-
-                if (data.ContainsKey(floorPosition))
-                {
-                    ColorHeight values = data[floorPosition];
-                    values.UpdateInfo(currentPoint.y, GetColorAtIndex(i));
-                    data[floorPosition] = values;
-                }
-                else
-                {
-
-                    data[floorPosition] = new ColorHeight(currentPoint.y, GetColorAtIndex(i));
-                }
-            }
-		}
+			tempCol = GetColorAtIndex(i);
+
+			if (tempCol == null)
+			{
+				continue;
+			}
+			else {
+				validCol = (Color)tempCol;
+			}
+			data2[currentPoint] = validCol;
+
 
+			if (data.ContainsKey(floorPosition))
+			{
+				ColorHeight values = data[floorPosition];
+				values.UpdateInfo(currentPoint.y, validCol);
+				data[floorPosition] = values;
+			}
+			else
+			{
+
+				data[floorPosition] = new ColorHeight(currentPoint.y, validCol);
+			}
+			
+		}
+	   
 	}
 
 	Vector3 KinectPointToVector3(CameraSpacePoint point)
@@ -178,9 +185,22 @@ public class PointCloudAggregator : MonoBehaviour {
 		return new Vector3(point.X, point.Y, point.Z);
 	}
 
-	Color GetColorAtIndex(int index)
+	Color? GetColorAtIndex(int index)
 	{
-		Color result = cameraTexture.GetPixel(Mathf.RoundToInt(colorSpacePoints[index].X), Mathf.RoundToInt(colorSpacePoints[index].Y));
+		int x = Mathf.RoundToInt(colorSpacePoints[index].X);
+		int y = Mathf.RoundToInt(colorSpacePoints[index].Y);
+
+	  
+
+		
+		if(y < 0 || y > cameraTexture.height)
+		{
+			return null;
+		}
+
+		
+
+		Color result = cameraTexture.GetPixel(x,y);
 		return result;
 	}
 
@@ -203,19 +223,19 @@ public class PointCloudAggregator : MonoBehaviour {
 	}
 
 
-    void ShowAsPointCloud2()
-    {
-        particles = new ParticleSystem.Particle[data2.Count];
-
-        int i = 0;
-        foreach (Vector3 pos in data2.Keys)
-        {
-            particles[i].position = pos;
-            particles[i].startColor = data2[pos];
-            particles[i].startSize = 0.02f;
-            i++;
-        }
-        _particleSystem.SetParticles(particles, particles.Length);
-    }
+	void ShowAsPointCloud2()
+	{
+		particles = new ParticleSystem.Particle[data2.Count];
+
+		int i = 0;
+		foreach (Vector3 pos in data2.Keys)
+		{
+			particles[i].position = pos;
+			particles[i].startColor = data2[pos];
+			particles[i].startSize = 0.02f;
+			i++;
+		}
+		_particleSystem.SetParticles(particles, particles.Length);
+	}
 
 }