コード例 #1
0
            public override int GetHashCode()
            {
                var hashCode = 162377905;
                int p1h      = P1 /*.Rounded(4)*/.GetHashCode();
                int p2h      = P2 /*.Rounded(4)*/.GetHashCode();

                if (p1h < p2h)
                {
                    hashCode = hashCode * -1521134295 + p1h;
                    hashCode = hashCode * -1521134295 + p2h;
                }
                else
                {
                    hashCode = hashCode * -1521134295 + p2h;
                    hashCode = hashCode * -1521134295 + p1h;
                }

                hashCode = hashCode * -1521134295 + EdgeNormal.GetHashCode();
                hashCode = hashCode * -1521134295 + FaceNormal.GetHashCode();

                return(hashCode);
            }
コード例 #2
0
ファイル: AseReader.cs プロジェクト: gleblebedev/toe
		private static Vertex BuildVertex(Float3[] vertices, int index0, FaceNormal[] normals,
		int faceIndex, int vertexAtFace, AseTFace[] tfaces, Color[] c, Float3[] tvertices, Tuple<int, int, int>[] colFaces, Float3 uv)
		{
			Vertex v = new Vertex { Position = vertices[index0] };
			if (normals != null)
			{
				v.Normal = normals[faceIndex].GetNormal(index0);
			}
			if (colFaces != null)
			{
				switch (vertexAtFace)
				{
					case 0:
						v.Color = c[colFaces[faceIndex].Item1];
						break;
					case 1:
						v.Color = c[colFaces[faceIndex].Item2];
						break;
					case 2:
						v.Color = c[colFaces[faceIndex].Item3];
						break;
				}
			}
			else
			{
				v.Color = Color.FromArgb(255, 255, 255, 255);
			}
			v.UV1 = v.UV0 = new Float3(uv.X, 1.0f - uv.Y, uv.Z);
			return v;
		}
コード例 #3
0
ファイル: AseReader.cs プロジェクト: gleblebedev/toe
		private void ParsNormalList(AseParser parser, FaceNormal[] normals)
		{
			int faceIndex = 0;
			int faceVertexIndex = 0;
			parser.Consume("{");
			for (;;)
			{
				var attr = parser.Consume();
				if (attr == null || attr == "}")
				{
					break;
				}
				if (0 == string.Compare(attr, "*MESH_FACENORMAL", StringComparison.InvariantCultureIgnoreCase))
				{
					faceIndex = parser.ConsumeInt();
					var x = parser.ConsumeFloat();
					var y = parser.ConsumeFloat();
					var z = parser.ConsumeFloat();
					normals[faceIndex].A.Normal =
						normals[faceIndex].B.Normal = normals[faceIndex].C.Normal = normals[faceIndex].Normal = new Float3(x, y, z);
					faceVertexIndex = 0;
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_VERTEXNORMAL", StringComparison.InvariantCultureIgnoreCase))
				{
					var index = parser.ConsumeInt();
					var x = parser.ConsumeFloat();
					var y = parser.ConsumeFloat();
					var z = parser.ConsumeFloat();
					Float3 v = new Float3(x, y, z);
					switch (faceVertexIndex)
					{
						case 0:
							normals[faceIndex].A.Index = index;
							normals[faceIndex].A.Normal = v;
							break;
						case 1:
							normals[faceIndex].B.Index = index;
							normals[faceIndex].B.Normal = v;
							break;
						case 2:
							normals[faceIndex].C.Index = index;
							normals[faceIndex].C.Normal = v;
							break;
					}
					++faceVertexIndex;
					continue;
				}
				parser.UnknownLexemError();
			}
		}
コード例 #4
0
ファイル: AseReader.cs プロジェクト: gleblebedev/toe
		private void ParsSubMesh(AseParser parser, Scene scene, Node node)
		{
			var mesh = new SeparateStreamsMesh();
			var submesh = mesh.CreateSubmesh();
			node.Mesh = mesh;
			scene.Geometries.Add(mesh);

			ArrayMeshStream<Float3> vertices = null;
			ListMeshStream<Float3> normalStream = null;
			FaceNormal[] normals = null;
			ArrayMeshStream<Float3> tvertices = null;
			ArrayMeshStream<Color> cols = null;
			AseFace[] faces = null;
			AseTFace[] tfaces = null;
			Tuple<int, int, int>[] colFaces = null;
			//TODO: submesh can have it's own vertex streams
			parser.Consume("{");
			for (;;)
			{
				var attr = parser.Consume();
				if (attr == null || attr == "}")
				{
					break;
				}
				if (0 == string.Compare(attr, "*TIMEVALUE", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_NUMVERTEX", StringComparison.InvariantCultureIgnoreCase))
				{
					vertices = new ArrayMeshStream<Float3>(parser.ConsumeInt(), converterFactory);
					mesh.SetStream(Streams.Position, 0, vertices);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_VERTEX_LIST", StringComparison.InvariantCultureIgnoreCase))
				{
					this.ParseVertexList(parser, vertices);
					continue;
				}
				
				if (0 == string.Compare(attr, "*MESH_NUMTVERTEX", StringComparison.InvariantCultureIgnoreCase))
				{
					tvertices = new ArrayMeshStream<Float3>(parser.ConsumeInt(), converterFactory);
					mesh.SetStream(Streams.TexCoord, 0, tvertices);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_TVERTLIST", StringComparison.InvariantCultureIgnoreCase))
				{
					this.ParseTVertList(parser, tvertices);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_NUMTVFACES", StringComparison.InvariantCultureIgnoreCase))
				{
					tfaces = new AseTFace[parser.ConsumeInt()];
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_TFACELIST", StringComparison.InvariantCultureIgnoreCase))
				{
					this.ParseTFaceList(parser, tfaces);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_NUMCVERTEX", StringComparison.InvariantCultureIgnoreCase))
				{
					cols = new ArrayMeshStream<Color>(parser.ConsumeInt(), converterFactory);
					mesh.SetStream(Streams.Color, 0, cols);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_CVERTLIST", StringComparison.InvariantCultureIgnoreCase))
				{
					this.ParseColList(parser, cols);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_NUMCVFACES", StringComparison.InvariantCultureIgnoreCase))
				{
					colFaces = new Tuple<int, int, int>[parser.ConsumeInt()];
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_CFACELIST", StringComparison.InvariantCultureIgnoreCase))
				{
					this.ParseColFaceList(parser, colFaces);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_NORMALS", StringComparison.InvariantCultureIgnoreCase))
				{
					normals = new FaceNormal[faces.Length];
					this.ParsNormalList(parser, normals);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_NUMFACES", StringComparison.InvariantCultureIgnoreCase))
				{
					faces = new AseFace[parser.ConsumeInt()];
					continue;
				}

				if (0 == string.Compare(attr, "*MESH_FACE_LIST", StringComparison.InvariantCultureIgnoreCase))
				{
					this.ParseFaceList(parser, faces);
					continue;
				}
				parser.UnknownLexemError();
			}
			ListMeshStream<int> positionIndices = null;
			if (vertices != null)
			{
				positionIndices = new ListMeshStream<int>(faces.Length * 3,converterFactory);
				submesh.SetIndexStream(Streams.Position, 0, positionIndices);
			}
			ListMeshStream<int> normalIndices = null;
			if (normals != null)
			{
				normalStream = new ListMeshStream<Float3>(faces.Length * 3, converterFactory);
				mesh.SetStream(Streams.Normal, 0, normalStream);
				normalIndices = new ListMeshStream<int>(faces.Length * 3, converterFactory);
				submesh.SetIndexStream(Streams.Normal, 0, normalIndices);
			}
			ListMeshStream<int> colorIndices = null;
			if (cols != null)
			{
				colorIndices = new ListMeshStream<int>(faces.Length * 3, converterFactory);
				submesh.SetIndexStream(Streams.Color, 0, colorIndices);
			}
			ListMeshStream<int> texCoordIndices = null;
			if (tvertices != null)
			{
				texCoordIndices = new ListMeshStream<int>(faces.Length * 3, converterFactory);
				submesh.SetIndexStream(Streams.TexCoord, 0, texCoordIndices);
			}
			for (int i = 0; i < faces.Length; ++i)
			{
				// -------------------------------------------------- //
				if (positionIndices != null)
				{
					positionIndices.Add(faces[i].A);
				}
				if (normalIndices != null)
				{
					normalIndices.Add(normalStream.Count);
					normalStream.Add(normals[i].A.Normal);
				}
				if (colorIndices != null)
				{
					colorIndices.Add(colFaces[i].Item1);
				}
				if (texCoordIndices != null)
				{
					texCoordIndices.Add(tfaces[i].A);
				}
		
				// -------------------------------------------------- //
				if (positionIndices != null)
				{
					positionIndices.Add(faces[i].C);
				}
				if (normalIndices != null)
				{
					normalIndices.Add(normalStream.Count);
					normalStream.Add(normals[i].C.Normal);
				}
				if (colorIndices != null)
				{
					colorIndices.Add(colFaces[i].Item3);
				}
				if (texCoordIndices != null)
				{
					texCoordIndices.Add(tfaces[i].C);
				}
				// -------------------------------------------------- //
				if (positionIndices != null)
				{
					positionIndices.Add(faces[i].B);
				}
				if (normalIndices != null)
				{
					normalIndices.Add(normalStream.Count);
					normalStream.Add(normals[i].B.Normal);
				}
				if (colorIndices != null)
				{
					colorIndices.Add(colFaces[i].Item2);
				}
				if (texCoordIndices != null)
				{
					texCoordIndices.Add(tfaces[i].B);
				}
				// -------------------------------------------------- //
			}

		}
コード例 #5
0
ファイル: Plane3D.cs プロジェクト: khanhcegvn/TVDCEG
        public double DistancepointtoPlane(XYZ xYZ)
        {
            XYZ xYZ1 = xYZ - Origin;

            return(Math.Abs(xYZ1.DotProduct(FaceNormal) / FaceNormal.GetLength()));
        }