Esempio n. 1
0
        public TriangleShape(Vector3 vertex0, Vector3 vertex1, Vector3 vertex2, MaterialAbstract material)
        {
            Vector3 planeNormal        = Vector3Ex.Cross(vertex1 - vertex0, vertex2 - vertex0).GetNormal();
            double  distanceFromOrigin = Vector3Ex.Dot(vertex0, planeNormal);

            Plane       = new PlaneFloat(new Vector3Float(planeNormal), (float)distanceFromOrigin);
            Material    = material;
            vertices[0] = new Vector3Float(vertex0);
            vertices[1] = new Vector3Float(vertex1);
            vertices[2] = new Vector3Float(vertex2);

            center = new Vector3Float((vertex0 + vertex1 + vertex2) / 3);

            var normalLengths = new [] { Math.Abs(planeNormal.X), Math.Abs(planeNormal.Y), Math.Abs(planeNormal.Z) };

            MajorAxis = (byte)normalLengths.Select((v, i) => new { Axis = i, Value = Math.Abs(v) }).OrderBy(o => o.Value).Last().Axis;

            for (int i = 0; i < 3; i++)
            {
                boundsOnMajorAxis.Left   = Math.Min(vertices[i][xForMajorAxis], boundsOnMajorAxis.Left);
                boundsOnMajorAxis.Right  = Math.Max(vertices[i][xForMajorAxis], boundsOnMajorAxis.Right);
                boundsOnMajorAxis.Bottom = Math.Min(vertices[i][yForMajorAxis], boundsOnMajorAxis.Bottom);
                boundsOnMajorAxis.Top    = Math.Max(vertices[i][yForMajorAxis], boundsOnMajorAxis.Top);
            }

            aabbMinXYZ = vertices[0].ComponentMin(vertices[1]).ComponentMin(vertices[2]);
            aabbMaxXYZ = vertices[0].ComponentMax(vertices[1]).ComponentMax(vertices[2]);
        }
Esempio n. 2
0
		public static IPrimitive Convert(PolygonMesh.Mesh simpleMesh, MaterialAbstract partMaterial = null)
		{
			List<IPrimitive> renderCollection = new List<IPrimitive>();

			if (partMaterial == null)
			{
				partMaterial = new SolidMaterial(new RGBA_Floats(.9, .2, .1), .01, 0.0, 2.0);
			}
			int index = 0;
			Vector3[] triangle = new Vector3[3];
			foreach (PolygonMesh.Face face in simpleMesh.Faces)
			{
				foreach (PolygonMesh.Vertex vertex in face.Vertices())
				{
					triangle[index++] = vertex.Position;
					if (index == 3)
					{
						index = 0;
						renderCollection.Add(new TriangleShape(triangle[0], triangle[1], triangle[2], partMaterial));
					}
				}
			}

			return BoundingVolumeHierarchy.CreateNewHierachy(renderCollection);
		}
Esempio n. 3
0
 public TriangleShapeUv(Vector3Float vertex0, Vector3Float vertex1, Vector3Float vertex2,
                        Vector2Float uv0, Vector2Float uv1, Vector2Float uv2,
                        MaterialAbstract material)
     : base(vertex0.AsVector3(), vertex1.AsVector3(), vertex2.AsVector3(), material)
 {
     this.uv0 = uv0;
     this.uv1 = uv1;
     this.uv2 = uv2;
 }
Esempio n. 4
0
 public TriangleShapeUv(Vector3 vertex0, Vector3 vertex1, Vector3 vertex2,
                        Vector2 uv0, Vector2 uv1, Vector2 uv2,
                        MaterialAbstract material)
     : base(vertex0, vertex1, vertex2, material)
 {
     this.uv0 = new Vector2Float(uv0);
     this.uv1 = new Vector2Float(uv1);
     this.uv2 = new Vector2Float(uv2);
 }
Esempio n. 5
0
 public TriangleShapeUv(Vector3 vertex0, Vector3 vertex1, Vector3 vertex2,
                        Vector2Float uv0, Vector2Float uv1, Vector2Float uv2,
                        MaterialAbstract material,
                        int index)
     : base(vertex0, vertex1, vertex2, material, index)
 {
     this.uv0 = uv0;
     this.uv1 = uv1;
     this.uv2 = uv2;
 }
Esempio n. 6
0
		public static IPrimitive Convert(List<PolygonMesh.MeshGroup> meshGroups, MaterialAbstract partMaterial = null)
		{
			List<IPrimitive> renderCollection = new List<IPrimitive>();
			foreach (MeshGroup meshGroup in meshGroups)
			{
				renderCollection.Add(Convert(meshGroup, partMaterial));
			}

			return BoundingVolumeHierarchy.CreateNewHierachy(renderCollection);
		}
Esempio n. 7
0
        public CylinderShape(double bottomRadius, double topRadius, double height, MaterialAbstract material)
        {
            this.radius    = bottomRadius;
            this.topRadius = topRadius;
            this.height    = height;
            this.Material  = material;

            topPlane    = new Plane(Vector3.UnitZ, height / 2);
            bottomPlane = new Plane(-Vector3.UnitZ, height / 2);
        }
Esempio n. 8
0
        public CylinderShape(double bottomRadius, double topRadius, double height, MaterialAbstract material)
        {
            this.radius = bottomRadius;
            this.topRadius = topRadius;
            this.height = height;
            this.Material = material;

            topPlane = new Plane(Vector3.UnitZ, height/2);
            bottomPlane = new Plane(-Vector3.UnitZ, height/2);
        }
Esempio n. 9
0
        public BoxShape(Vector3 minXYZ, Vector3 maxXYZ, MaterialAbstract material)
        {
            if (maxXYZ.x < minXYZ.x || maxXYZ.y < minXYZ.y || maxXYZ.z < minXYZ.z)
            {
                throw new ArgumentException("All values of min must be less than all values in max.");
            }

            this.minXYZ = minXYZ;
            this.maxXYZ = maxXYZ;
            Material    = material;
        }
Esempio n. 10
0
		public BoxShape(Vector3 minXYZ, Vector3 maxXYZ, MaterialAbstract material)
		{
			if (maxXYZ.x < minXYZ.x || maxXYZ.y < minXYZ.y || maxXYZ.z < minXYZ.z)
			{
				throw new ArgumentException("All values of min must be less than all values in max.");
			}

			this.minXYZ = minXYZ;
			this.maxXYZ = maxXYZ;
			Material = material;
		}
Esempio n. 11
0
        public TriangleShape(Vector3 vertex0, Vector3 vertex1, Vector3 vertex2, MaterialAbstract material)
        {
            Vector3 planeNormal        = Vector3.Cross(vertex1 - vertex0, vertex2 - vertex0).GetNormal();
            double  distanceFromOrigin = Vector3.Dot(vertex0, planeNormal);

            plane       = new Plane(planeNormal, distanceFromOrigin);
            Material    = material;
            vertices[0] = vertex0;
            vertices[1] = vertex1;
            vertices[2] = vertex2;
            center      = (vertex0 + vertex1 + vertex2) / 3;
            if (Math.Abs(planeNormal.x) > Math.Abs(planeNormal.y))
            {
                if (Math.Abs(planeNormal.x) > Math.Abs(planeNormal.z))
                {
                    // mostly facing x axis
                    majorAxis     = 0;
                    xForMajorAxis = 1;
                    yForMajorAxis = 2;
                }
                else if (Math.Abs(planeNormal.y) > Math.Abs(planeNormal.z))
                {
                    // mostly facing z
                    majorAxis     = 2;
                    xForMajorAxis = 0;
                    yForMajorAxis = 1;
                }
            }
            else if (Math.Abs(planeNormal.y) > Math.Abs(planeNormal.z))
            {
                // mostly facing y
                majorAxis     = 1;
                xForMajorAxis = 0;
                yForMajorAxis = 2;
            }
            else
            {
                // mostly facing z
                majorAxis     = 2;
                xForMajorAxis = 0;
                yForMajorAxis = 1;
            }
            for (int i = 0; i < 3; i++)
            {
                boundsOnMajorAxis.Left   = Math.Min(vertices[i][xForMajorAxis], boundsOnMajorAxis.Left);
                boundsOnMajorAxis.Right  = Math.Max(vertices[i][xForMajorAxis], boundsOnMajorAxis.Right);
                boundsOnMajorAxis.Bottom = Math.Min(vertices[i][yForMajorAxis], boundsOnMajorAxis.Bottom);
                boundsOnMajorAxis.Top    = Math.Max(vertices[i][yForMajorAxis], boundsOnMajorAxis.Top);
            }
        }
Esempio n. 12
0
		public TriangleShape(Vector3 vertex0, Vector3 vertex1, Vector3 vertex2, MaterialAbstract material)
		{
			Vector3 planeNormal = Vector3.Cross(vertex1 - vertex0, vertex2 - vertex0).GetNormal();
			double distanceFromOrigin = Vector3.Dot(vertex0, planeNormal);
			plane = new PlaneFloat(new Vector3Float(planeNormal), (float)distanceFromOrigin);
			Material = material;
			vertices[0] = new Vector3Float(vertex0);
			vertices[1] = new Vector3Float(vertex1);
			vertices[2] = new Vector3Float(vertex2);
			center = new Vector3Float((vertex0 + vertex1 + vertex2) / 3);
			if (Math.Abs(planeNormal.x) > Math.Abs(planeNormal.y))
			{
				if (Math.Abs(planeNormal.x) > Math.Abs(planeNormal.z))
				{
					// mostly facing x axis
					majorAxis = 0;
				}
				else if (Math.Abs(planeNormal.y) > Math.Abs(planeNormal.z))
				{
					// mostly facing z
					majorAxis = 2;
				}
			}
			else if (Math.Abs(planeNormal.y) > Math.Abs(planeNormal.z))
			{
				// mostly facing y
				majorAxis = 1;
			}
			else
			{
				// mostly facing z
				majorAxis = 2;
			}
			for (int i = 0; i < 3; i++)
			{
				boundsOnMajorAxis.Left = Math.Min(vertices[i][xForMajorAxis], boundsOnMajorAxis.Left);
				boundsOnMajorAxis.Right = Math.Max(vertices[i][xForMajorAxis], boundsOnMajorAxis.Right);
				boundsOnMajorAxis.Bottom = Math.Min(vertices[i][yForMajorAxis], boundsOnMajorAxis.Bottom);
				boundsOnMajorAxis.Top = Math.Max(vertices[i][yForMajorAxis], boundsOnMajorAxis.Top);
			}
		}
Esempio n. 13
0
		public static IPrimitive Convert(PolygonMesh.MeshGroup meshGroup, MaterialAbstract partMaterial = null)
		{
			List<IPrimitive> renderCollection = new List<IPrimitive>();

			SolidMaterial otherMaterial = new SolidMaterial(new RGBA_Floats(.1, .2, .9), .01, 0.0, 2.0);
			if (partMaterial == null)
			{
				partMaterial = new SolidMaterial(new RGBA_Floats(.9, .2, .1), .01, 0.0, 2.0);
			}
			int index = 0;
			Vector3[] triangle = new Vector3[3];
			foreach (PolygonMesh.Mesh mesh in meshGroup.Meshes)
			{
				int materialIntdex = MeshMaterialData.Get(mesh).MaterialIndex;
				foreach (PolygonMesh.Face face in mesh.Faces)
				{
					foreach (PolygonMesh.Vertex vertex in face.Vertices())
					{
						triangle[index++] = vertex.Position;
						if (index == 3)
						{
							index = 0;
							if (materialIntdex == 1)
							{
								renderCollection.Add(new TriangleShape(triangle[0], triangle[1], triangle[2], partMaterial));
							}
							else
							{
								renderCollection.Add(new TriangleShape(triangle[0], triangle[1], triangle[2], otherMaterial));
							}
						}
					}
				}
			}

			return BoundingVolumeHierarchy.CreateNewHierachy(renderCollection);
		}
Esempio n. 14
0
 public PlaneShape(Vector3 planeNormal, double distanceFromOrigin, MaterialAbstract material)
 {
     plane    = new Plane(planeNormal, distanceFromOrigin);
     Material = material;
 }
Esempio n. 15
0
 public BaseShape()
 {
     Material = new SolidMaterial(new RGBA_Floats(1, 0, 1), 0, 0, 0);
 }
Esempio n. 16
0
 public CylinderShape(double radius, double height, MaterialAbstract material)
     : this(radius, radius, height, material)
 {
 }
Esempio n. 17
0
 public PlaneShape(Vector3 planeNormal, double distanceFromOrigin, MaterialAbstract material)
     : this(new Plane(planeNormal, distanceFromOrigin), material)
 {
 }
Esempio n. 18
0
 public SphereShape(Vector3 position, double radius, MaterialAbstract material)
 {
     this.radius   = radius;
     this.position = position;
     this.Material = material;
 }
Esempio n. 19
0
		public SphereShape(Vector3 position, double radius, MaterialAbstract material)
		{
			this.radius = radius;
			this.position = position;
			this.Material = material;
		}
Esempio n. 20
0
 public BaseShape()
 {
     Material = new SolidMaterial(new ColorF(1, 0, 1), 0, 0, 0);
 }
Esempio n. 21
0
		public PlaneShape(Vector3 planeNormal, double distanceFromOrigin, MaterialAbstract material)
		{
			plane = new Plane(planeNormal, distanceFromOrigin);
			Material = material;
		}
Esempio n. 22
0
		public BaseShape()
		{
			Material = new SolidMaterial(new RGBA_Floats(1, 0, 1), 0, 0, 0);
		}
Esempio n. 23
0
 public TriangleShape(Vector3Float vertex0, Vector3Float vertex1, Vector3Float vertex2, MaterialAbstract material)
     : this(vertex0.AsVector3(), vertex1.AsVector3(), vertex2.AsVector3(), material)
 {
 }
Esempio n. 24
0
 public PlaneShape(Plane plane, MaterialAbstract material)
 {
     Plane    = plane;
     Material = material;
 }
Esempio n. 25
0
 public CylinderShape(double radius, double height, MaterialAbstract material)
     : this(radius, radius, height, material)
 {
 }