예제 #1
0
        public static ScaleRotateTranslate CreateTranslation(double x, double y, double z)
        {
            ScaleRotateTranslate translation = ScaleRotateTranslate.Identity();

            translation.translation = Matrix4X4.CreateTranslation(x, y, z);
            return(translation);
        }
예제 #2
0
		public static ScaleRotateTranslate Identity()
		{
			ScaleRotateTranslate identity = new ScaleRotateTranslate();
			identity.centering = Matrix4X4.Identity;
			identity.scale = Matrix4X4.Identity;
			identity.rotation = Matrix4X4.Identity;
			identity.translation = Matrix4X4.Identity;
			return identity;
		}
예제 #3
0
        public void SetMeshAfterLoad(List <MeshGroup> loadedMeshGroups, CenterPartAfterLoad centerPart, Vector2 bedCenter)
        {
            MeshGroups.Clear();

            if (loadedMeshGroups == null)
            {
                partProcessingInfo.centeredInfoText.Text = string.Format("Sorry! No 3D view available\nfor this file.");
            }
            else
            {
                CreateGlDataForMeshes(loadedMeshGroups);

                AxisAlignedBoundingBox bounds = new AxisAlignedBoundingBox(Vector3.Zero, Vector3.Zero);
                bool first = true;
                foreach (MeshGroup meshGroup in loadedMeshGroups)
                {
                    if (first)
                    {
                        bounds = meshGroup.GetAxisAlignedBoundingBox();
                        first  = false;
                    }
                    else
                    {
                        bounds = AxisAlignedBoundingBox.Union(bounds, meshGroup.GetAxisAlignedBoundingBox());
                    }
                }

                foreach (MeshGroup meshGroup in loadedMeshGroups)
                {
                    // make sure the mesh is centered about the origin so rotations will come from a reasonable place
                    ScaleRotateTranslate centering = ScaleRotateTranslate.Identity();
                    centering.SetCenteringForMeshGroup(meshGroup);
                    meshTransforms.Add(centering);
                    MeshGroups.Add(meshGroup);
                }

                if (centerPart == CenterPartAfterLoad.DO)
                {
                    // make sure the entire load is centered and on the bed
                    Vector3 boundsCenter = (bounds.maxXYZ + bounds.minXYZ) / 2;
                    for (int i = 0; i < MeshGroups.Count; i++)
                    {
                        ScaleRotateTranslate moved = meshTransforms[i];
                        moved.translation *= Matrix4X4.CreateTranslation(-boundsCenter + new Vector3(0, 0, bounds.ZSize / 2) + new Vector3(bedCenter));
                        meshTransforms[i]  = moved;
                    }
                }

                trackballTumbleWidget.TrackBallController = new TrackBallController();
                trackballTumbleWidget.OnBoundsChanged(null);
                trackballTumbleWidget.TrackBallController.Scale = .03;
                trackballTumbleWidget.TrackBallController.Translate(-new Vector3(BedCenter));
                trackballTumbleWidget.TrackBallController.Rotate(Quaternion.FromEulerAngles(new Vector3(0, 0, MathHelper.Tau / 16)));
                trackballTumbleWidget.TrackBallController.Rotate(Quaternion.FromEulerAngles(new Vector3(-MathHelper.Tau * .19, 0, 0)));
            }
        }
예제 #4
0
        public static ScaleRotateTranslate Identity()
        {
            ScaleRotateTranslate identity = new ScaleRotateTranslate();

            identity.centering   = Matrix4X4.Identity;
            identity.scale       = Matrix4X4.Identity;
            identity.rotation    = Matrix4X4.Identity;
            identity.translation = Matrix4X4.Identity;
            return(identity);
        }
예제 #5
0
        public static void FindPositionForPartAndAddToPlate(Mesh meshToAdd, ScaleRotateTranslate meshTransform, List<PlatingMeshData> perMeshInfo, List<Mesh> meshesToAvoid, List<ScaleRotateTranslate> meshTransforms)
        {
            if (meshToAdd == null || meshToAdd.Vertices.Count < 3)
            {
                return;
            }

            meshesToAvoid.Add(meshToAdd);

            PlatingMeshData newMeshInfo = new PlatingMeshData();
            perMeshInfo.Add(newMeshInfo);
            meshTransforms.Add(meshTransform);

            int index = meshesToAvoid.Count-1;
            MoveMeshToOpenPosition(index, perMeshInfo, meshesToAvoid, meshTransforms);

            PlaceMeshOnBed(meshesToAvoid, meshTransforms, index, false);
        }
예제 #6
0
        private void CreateBooleanTestGeometry(GuiWidget drawingWidget, DrawEventArgs e)
        {
            Mesh boxA = PlatonicSolids.CreateCube(40, 40, 40);
			//boxA.Triangulate();
            boxA.Translate(centering);
            Mesh boxB = PlatonicSolids.CreateCube(40, 40, 40);
			//boxB.Triangulate();

            for (int i = 0; i < 3; i++)
            {
                if (Math.Abs(direction[i] + offset[i]) > 10)
                {
                    direction[i] = -direction[i];
                }
            }
            offset += direction;

            boxB.Translate(offset + centering);

            booleanGroup = new MeshGroup();
            booleanGroup.Meshes.Add(PolygonMesh.Csg.CsgOperations.Union(boxA, boxB));
            meshViewerWidget.MeshGroups.Add(booleanGroup);

            groupTransform = ScaleRotateTranslate.Identity();
            meshViewerWidget.MeshGroupTransforms.Add(groupTransform);
        }
예제 #7
0
		public static void FindPositionForGroupAndAddToPlate(MeshGroup meshGroupToAdd, ScaleRotateTranslate meshTransform, List<PlatingMeshGroupData> perMeshInfo, List<MeshGroup> meshesGroupsToAvoid, List<ScaleRotateTranslate> meshTransforms)
		{
			if (meshGroupToAdd == null || meshGroupToAdd.Meshes.Count < 1)
			{
				return;
			}

			// first find the bounds of what is already here.
			AxisAlignedBoundingBox allPlacedMeshBounds = GetAxisAlignedBoundingBox(meshesGroupsToAvoid[0], meshTransforms[0].TotalTransform);
			for (int i = 1; i < meshesGroupsToAvoid.Count; i++)
			{
				AxisAlignedBoundingBox nextMeshBounds = GetAxisAlignedBoundingBox(meshesGroupsToAvoid[i], meshTransforms[i].TotalTransform);
				allPlacedMeshBounds = AxisAlignedBoundingBox.Union(allPlacedMeshBounds, nextMeshBounds);
			}

			meshesGroupsToAvoid.Add(meshGroupToAdd);

			PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();
			perMeshInfo.Add(newMeshInfo);
			meshTransform.SetCenteringForMeshGroup(meshGroupToAdd);
			meshTransforms.Add(meshTransform);

			int meshGroupIndex = meshesGroupsToAvoid.Count - 1;

			// move the part to the total bounds lower left side
			MeshGroup meshGroup = meshesGroupsToAvoid[meshGroupIndex];
			Vector3 meshLowerLeft = GetAxisAlignedBoundingBox(meshGroup, meshTransforms[meshGroupIndex].TotalTransform).minXYZ;
			ScaleRotateTranslate atLowerLeft = meshTransforms[meshGroupIndex];
			atLowerLeft.translation *= Matrix4X4.CreateTranslation(-meshLowerLeft + allPlacedMeshBounds.minXYZ);
			meshTransforms[meshGroupIndex] = atLowerLeft;

			MoveMeshGroupToOpenPosition(meshGroupIndex, perMeshInfo, meshesGroupsToAvoid, meshTransforms);

			PlaceMeshGroupOnBed(meshesGroupsToAvoid, meshTransforms, meshGroupIndex);
		}