コード例 #1
0
ファイル: Image.cs プロジェクト: KurtLoeffler/EnvyEngine
		public void OnUpdate()
		{
			if (mesh)
			{
				mesh.Dispose();
			}

			Rect rect = rectTransform.rect;
			positionVboData[0] = new Vector3f((float)rect.min.X, (float)rect.min.Y, 0);
			positionVboData[1] = new Vector3f((float)rect.min.X, (float)rect.max.Y, 0);
			positionVboData[2] = new Vector3f((float)rect.max.X, (float)rect.max.Y, 0);
			positionVboData[3] = new Vector3f((float)rect.max.X, (float)rect.min.Y, 0);
			
			mesh = new Mesh();

			mesh.AddBuffer<VertexBufferObject3f>("vertex");
			mesh.SetBuffer3f("vertex", positionVboData);

			mesh.AddBuffer<VertexBufferObject3f>("normal");
			mesh.SetBuffer3f("normal", normalVboData);

			mesh.AddBuffer<VertexBufferObject2f>("uv0");
			mesh.SetBuffer2f("uv0", uvVboData);

			mesh.SetIndices(indicesVboData, 0, Graphics.PrimitiveType.Triangles);

			MeshRenderer meshRenderer = sceneObject.GetModule<MeshRenderer>();
			if (meshRenderer)
			{
				meshRenderer.mesh = mesh;
			}
		}
コード例 #2
0
ファイル: StaticText.cs プロジェクト: KurtLoeffler/EnvyEngine
		public void OnUpdate()
		{
			//base.OnInitialize();

			string text = "Test text! "+Engine.current.deltaTime;
			Font font = new Font("Verdana", 12, FontStyle.Regular, GraphicsUnit.Point);
			Bitmap measureBitmap = new Bitmap(2, 2);
			Bitmap bitmap = null;

			System.Drawing.Graphics measureGraphics = System.Drawing.Graphics.FromImage(measureBitmap);
			measureGraphics.PageUnit = GraphicsUnit.Pixel;
			measureGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
			measureGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

			SizeF size = measureGraphics.MeasureString(text, font);
			measureGraphics.Dispose();
			measureBitmap.Dispose();

			bitmap = new Bitmap((int)size.Width, (int)size.Height);

			System.Drawing.Graphics drawGraphics = System.Drawing.Graphics.FromImage(bitmap);
			drawGraphics.PageUnit = GraphicsUnit.Pixel;
			drawGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
			drawGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
			drawGraphics.Clear(System.Drawing.Color.FromArgb(255, 0, 0, 0));
			drawGraphics.DrawString(text, font, new SolidBrush(System.Drawing.Color.White), 0, 0);
			drawGraphics.Dispose();

			if (texture)
			{
				texture.Dispose();
			}

			texture = new Texture2D(bitmap, false, Texture2D.MemoryResidence.GPU);

			bitmap.Dispose();

			if (mesh)
			{
				mesh.Dispose();
			}

			positionVboData[0] = new Vector3f(0, 0, 0);
			positionVboData[1] = new Vector3f(0, texture.height, 0);
			positionVboData[2] = new Vector3f(texture.width, texture.height, 0);
			positionVboData[3] = new Vector3f(texture.width, 0, 0);
			
			mesh = new Mesh();

			mesh.AddBuffer<VertexBufferObject3f>("vertex");
			mesh.SetBuffer3f("vertex", positionVboData);

			mesh.AddBuffer<VertexBufferObject3f>("normal");
			mesh.SetBuffer3f("normal", normalVboData);

			mesh.AddBuffer<VertexBufferObject2f>("uv0");
			mesh.SetBuffer2f("uv0", uvVboData);

			mesh.SetIndices(indicesVboData, 0, Graphics.PrimitiveType.Triangles);

			MeshRenderer meshRenderer = sceneObject.GetModule<MeshRenderer>();
			if (meshRenderer)
			{
				MaterialProperties properties = new MaterialProperties();
				MaterialPropertyTexture2D texProperty = properties.AddProperty<MaterialPropertyTexture2D>("colorTexture");
				texProperty.value = texture;
				meshRenderer.mesh = mesh;
				meshRenderer.overrideProperties = properties;
			}

		}
コード例 #3
0
ファイル: PolyMesh.cs プロジェクト: KurtLoeffler/EnvyEngine
        public Mesh ToMesh(IEnumerable<int> faceList, List<int> triangleToFaceMap)
		{
			List<Vector3f> vertices = new List<Vector3f>();
			List<Vector3f> normals = new List<Vector3f>();
			List<Vector2f> uvs = new List<Vector2f>();
			List<uint> triangles = new List<uint>();
			List<uint> edges = new List<uint>();
			
            if (faceList == null)
			{
				faceList = Enumerable.Range(0, geometry.Faces.Count).Select(i => i);
            }

			foreach (var faceIndex in faceList)
			{
                PlanktonFace face = geometry.Faces[faceIndex];
				if (face.IsUnused)
				{
					continue;
				}

				int startVertexIndex = vertices.Count;
				int[] halfedgeIndices = geometry.Faces.GetHalfedges(faceIndex);
				
                for (int h = 0; h < halfedgeIndices.Length; h++)
				{
					int halfEdgeIndex = halfedgeIndices[h];
					int vertexIndex = geometry.Halfedges[halfEdgeIndex].StartVertex;
					PlanktonVertex vertex = geometry.Vertices[vertexIndex];
					PlanktonVertex end = geometry.Vertices[vertexIndex];

					//if (vertex.IsUnused)
					//{
					//	continue;
					//}
					
					Vector3f normal = (Vector3f)GetHalfedgeNormal(halfEdgeIndex);

					Vector3f position = vertex.ToXYZ().ToVector3f();
					vertices.Add(position);
					normals.Add(normal);
					uvs.Add(new Vector2f(position.X, position.Y));

					int pairIndex = geometry.Halfedges.GetPairHalfedge(halfEdgeIndex);

					bool makeEdge = halfEdgeIndex%2 == 0 || geometry.Halfedges[halfEdgeIndex].AdjacentFace == -1 || geometry.Halfedges[pairIndex].AdjacentFace == -1;

					if (makeEdge)
					{
						edges.Add((uint)(vertices.Count-1));
						int nextIndex = vertices.Count;
						if (h == halfedgeIndices.Length-1)
						{
							nextIndex = startVertexIndex;
                        }
                        edges.Add((uint)nextIndex);
					}
				}

				for (int h = 0; h < halfedgeIndices.Length; h++)
				{
					if (h < 3)
					{
						if (triangleToFaceMap != null)
						{
							if (h == 2)
							{
								triangleToFaceMap.Add(faceIndex);
							}
						}
						
						triangles.Add((uint)(startVertexIndex+h));
					}
					else
					{
						if (triangleToFaceMap != null)
						{
							triangleToFaceMap.Add(faceIndex);
						}

						triangles.Add((uint)startVertexIndex);
						triangles.Add((uint)(startVertexIndex+(h-1)));
						triangles.Add((uint)(startVertexIndex+h));
					}
				}
			}

			Mesh mesh = new Mesh();

			mesh.AddBuffer<VertexBufferObject3f>("vertex");
			mesh.SetBuffer3f("vertex", vertices.ToArray());

			mesh.AddBuffer<VertexBufferObject3f>("normal");
			mesh.SetBuffer3f("normal", normals.ToArray());

			mesh.AddBuffer<VertexBufferObject2f>("uv0");
			mesh.SetBuffer2f("uv0", uvs.ToArray());

			mesh.SetIndices(triangles.ToArray(), 0, Graphics.PrimitiveType.Triangles);
			mesh.SetIndices(edges.ToArray(), 1, Graphics.PrimitiveType.Lines);

			return mesh;
		}